source: mainline/boot/arch/sparc64/src/ofw.c

Last change on this file was 28a5ebd, checked in by Martin Decky <martin@…>, 5 years ago

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * Copyright (c) 2006 Jakub Jermar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/**
31 * @file
32 * @brief Architecture dependent parts of OpenFirmware interface.
33 */
34
35#include <arch/arch.h>
36#include <arch/ofw.h>
37#include <genarch/ofw.h>
38#include <stddef.h>
39#include <stdint.h>
40#include <printf.h>
41#include <halt.h>
42#include <putchar.h>
43#include <str.h>
44
45void putuchar(char32_t ch)
46{
47 if (ch == '\n')
48 ofw_putchar('\r');
49
50 if (ascii_check(ch))
51 ofw_putchar(ch);
52 else
53 ofw_putchar('?');
54}
55
56/** Start all CPUs represented by following siblings of the given node.
57 *
58 * Except for the current CPU.
59 *
60 * @param child The first child of the OFW tree node whose children
61 * represent CPUs to be woken up.
62 * @param current_mid MID of the current CPU, the current CPU will
63 * (of course) not be woken up.
64 * @param physmem_start Starting address of the physical memory.
65 *
66 * @return Number of CPUs which have the same parent node as
67 * "child".
68 *
69 */
70static size_t wake_cpus_in_node(phandle child, uint64_t current_mid,
71 uintptr_t physmem_start)
72{
73 size_t cpus;
74
75 for (cpus = 0; (child != 0) && (child != (phandle) -1);
76 child = ofw_get_peer_node(child), cpus++) {
77 char type_name[OFW_TREE_PROPERTY_MAX_VALUELEN];
78
79 if (ofw_get_property(child, "device_type", type_name,
80 OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
81 type_name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
82
83 if (str_cmp(type_name, "cpu") == 0) {
84 uint32_t mid;
85
86 /*
87 * "upa-portid" for US, "portid" for US-III,
88 * "cpuid" for US-IV
89 */
90 if ((ofw_get_property(child, "upa-portid", &mid, sizeof(mid)) <= 0) &&
91 (ofw_get_property(child, "portid", &mid, sizeof(mid)) <= 0) &&
92 (ofw_get_property(child, "cpuid", &mid, sizeof(mid)) <= 0))
93 continue;
94
95 if (current_mid != mid) {
96 /*
97 * Start secondary processor.
98 */
99 (void) ofw_call("SUNW,start-cpu", 3, 1,
100 NULL, child, KERNEL_ADDRESS,
101 physmem_start | AP_PROCESSOR);
102 }
103 }
104 }
105 }
106
107 return cpus;
108}
109
110/** Find out the current CPU's MID and wake up all AP processors.
111 *
112 */
113void ofw_cpu(uint16_t mid_mask, uintptr_t physmem_start)
114{
115 /* Get the current CPU MID */
116 uint64_t current_mid;
117
118 asm volatile (
119 "ldxa [%[zero]] %[asi], %[current_mid]\n"
120 : [current_mid] "=r" (current_mid)
121 : [zero] "r" (0),
122 [asi] "i" (ASI_ICBUS_CONFIG)
123 );
124
125 current_mid >>= ICBUS_CONFIG_MID_SHIFT;
126 current_mid &= mid_mask;
127
128 /* Wake up the CPUs */
129
130 phandle cpus_parent = ofw_find_device("/ssm@0,0");
131 if ((cpus_parent == 0) || (cpus_parent == (phandle) -1))
132 cpus_parent = ofw_find_device("/");
133
134 phandle node = ofw_get_child_node(cpus_parent);
135 size_t cpus = wake_cpus_in_node(node, current_mid, physmem_start);
136
137 while ((node != 0) && (node != (phandle) -1)) {
138 char name[OFW_TREE_PROPERTY_MAX_VALUELEN];
139
140 if (ofw_get_property(node, "name", name,
141 OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
142 name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
143
144 if (str_cmp(name, "cmp") == 0) {
145 phandle subnode = ofw_get_child_node(node);
146 cpus += wake_cpus_in_node(subnode,
147 current_mid, physmem_start);
148 }
149 }
150
151 node = ofw_get_peer_node(node);
152 }
153
154 if (cpus == 0)
155 printf("Warning: Unable to get CPU properties.\n");
156}
157
158/** Get physical memory starting address.
159 *
160 * @return Physical memory starting address.
161 *
162 */
163uintptr_t ofw_get_physmem_start(void)
164{
165 uint32_t memreg[4];
166 if ((ofw_ret_t) ofw_get_property(ofw_memory, "reg", &memreg,
167 sizeof(memreg)) <= 0) {
168 printf("Error: Unable to get physical memory starting address, halting.\n");
169 halt();
170 }
171
172 return ((((uintptr_t) memreg[0]) << 32) | memreg[1]);
173}
Note: See TracBrowser for help on using the repository browser.