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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since de1712e was de1712e, checked in by Martin Decky <martin@…>, 8 years ago

boot: rename typedefs.h to stddef.h

  • 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 <printf.h>
40#include <halt.h>
41#include <putchar.h>
42#include <str.h>
43
44void putchar(const wchar_t ch)
45{
46 if (ch == '\n')
47 ofw_putchar('\r');
48
49 if (ascii_check(ch))
50 ofw_putchar(ch);
51 else
52 ofw_putchar(U_SPECIAL);
53}
54
55/** Start all CPUs represented by following siblings of the given node.
56 *
57 * Except for the current CPU.
58 *
59 * @param child The first child of the OFW tree node whose children
60 * represent CPUs to be woken up.
61 * @param current_mid MID of the current CPU, the current CPU will
62 * (of course) not be woken up.
63 * @param physmem_start Starting address of the physical memory.
64 *
65 * @return Number of CPUs which have the same parent node as
66 * "child".
67 *
68 */
69static size_t wake_cpus_in_node(phandle child, uint64_t current_mid,
70 uintptr_t physmem_start)
71{
72 size_t cpus;
73
74 for (cpus = 0; (child != 0) && (child != (phandle) -1);
75 child = ofw_get_peer_node(child), cpus++) {
76 char type_name[OFW_TREE_PROPERTY_MAX_VALUELEN];
77
78 if (ofw_get_property(child, "device_type", type_name,
79 OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
80 type_name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
81
82 if (str_cmp(type_name, "cpu") == 0) {
83 uint32_t mid;
84
85 /*
86 * "upa-portid" for US, "portid" for US-III,
87 * "cpuid" for US-IV
88 */
89 if ((ofw_get_property(child, "upa-portid", &mid, sizeof(mid)) <= 0)
90 && (ofw_get_property(child, "portid", &mid, sizeof(mid)) <= 0)
91 && (ofw_get_property(child, "cpuid", &mid, sizeof(mid)) <= 0))
92 continue;
93
94 if (current_mid != mid) {
95 /*
96 * Start secondary processor.
97 */
98 (void) ofw_call("SUNW,start-cpu", 3, 1,
99 NULL, child, KERNEL_ADDRESS,
100 physmem_start | AP_PROCESSOR);
101 }
102 }
103 }
104 }
105
106 return cpus;
107}
108
109/** Find out the current CPU's MID and wake up all AP processors.
110 *
111 */
112void ofw_cpu(uint16_t mid_mask, uintptr_t physmem_start)
113{
114 /* Get the current CPU MID */
115 uint64_t current_mid;
116
117 asm volatile (
118 "ldxa [%[zero]] %[asi], %[current_mid]\n"
119 : [current_mid] "=r" (current_mid)
120 : [zero] "r" (0),
121 [asi] "i" (ASI_ICBUS_CONFIG)
122 );
123
124 current_mid >>= ICBUS_CONFIG_MID_SHIFT;
125 current_mid &= mid_mask;
126
127 /* Wake up the CPUs */
128
129 phandle cpus_parent = ofw_find_device("/ssm@0,0");
130 if ((cpus_parent == 0) || (cpus_parent == (phandle) -1))
131 cpus_parent = ofw_find_device("/");
132
133 phandle node = ofw_get_child_node(cpus_parent);
134 size_t cpus = wake_cpus_in_node(node, current_mid, physmem_start);
135
136 while ((node != 0) && (node != (phandle) -1)) {
137 char name[OFW_TREE_PROPERTY_MAX_VALUELEN];
138
139 if (ofw_get_property(node, "name", name,
140 OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
141 name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
142
143 if (str_cmp(name, "cmp") == 0) {
144 phandle subnode = ofw_get_child_node(node);
145 cpus += wake_cpus_in_node(subnode,
146 current_mid, physmem_start);
147 }
148 }
149
150 node = ofw_get_peer_node(node);
151 }
152
153 if (cpus == 0)
154 printf("Warning: Unable to get CPU properties.\n");
155}
156
157/** Get physical memory starting address.
158 *
159 * @return Physical memory starting address.
160 *
161 */
162uintptr_t ofw_get_physmem_start(void)
163{
164 uint32_t memreg[4];
165 if ((ofw_ret_t) ofw_get_property(ofw_memory, "reg", &memreg,
166 sizeof(memreg)) <= 0) {
167 printf("Error: Unable to get physical memory starting address, halting.\n");
168 halt();
169 }
170
171 return ((((uintptr_t) memreg[0]) << 32) | memreg[1]);
172}
Note: See TracBrowser for help on using the repository browser.