[3c1dec0] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 Martin Decky
|
---|
| 3 | * Copyright (c) 2006 Jakub Jermar
|
---|
[3c1dec0] | 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 | */
|
---|
[63cda71] | 29 |
|
---|
| 30 | /**
|
---|
| 31 | * @file
|
---|
[e731b0d] | 32 | * @brief Architecture dependent parts of OpenFirmware interface.
|
---|
[63cda71] | 33 | */
|
---|
| 34 |
|
---|
[4872160] | 35 | #include <arch/arch.h>
|
---|
| 36 | #include <arch/ofw.h>
|
---|
| 37 | #include <genarch/ofw.h>
|
---|
[de1712e] | 38 | #include <stddef.h>
|
---|
[7a99507] | 39 | #include <stdint.h>
|
---|
[ce8725be] | 40 | #include <printf.h>
|
---|
[4872160] | 41 | #include <halt.h>
|
---|
| 42 | #include <putchar.h>
|
---|
| 43 | #include <str.h>
|
---|
[3c1dec0] | 44 |
|
---|
[28a5ebd] | 45 | void putuchar(char32_t ch)
|
---|
[2e672fd] | 46 | {
|
---|
[4872160] | 47 | if (ch == '\n')
|
---|
| 48 | ofw_putchar('\r');
|
---|
[a35b458] | 49 |
|
---|
[4872160] | 50 | if (ascii_check(ch))
|
---|
| 51 | ofw_putchar(ch);
|
---|
| 52 | else
|
---|
[ed88c8e] | 53 | ofw_putchar('?');
|
---|
[c34f98f] | 54 | }
|
---|
[b7b5f83] | 55 |
|
---|
[4872160] | 56 | /** Start all CPUs represented by following siblings of the given node.
|
---|
| 57 | *
|
---|
| 58 | * Except for the current CPU.
|
---|
[965dc18] | 59 | *
|
---|
[e731b0d] | 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 | *
|
---|
[965dc18] | 69 | */
|
---|
[4872160] | 70 | static size_t wake_cpus_in_node(phandle child, uint64_t current_mid,
|
---|
[e731b0d] | 71 | uintptr_t physmem_start)
|
---|
[9a5b556] | 72 | {
|
---|
[4872160] | 73 | size_t cpus;
|
---|
[a35b458] | 74 |
|
---|
[4872160] | 75 | for (cpus = 0; (child != 0) && (child != (phandle) -1);
|
---|
[965dc18] | 76 | child = ofw_get_peer_node(child), cpus++) {
|
---|
[ed5ad30] | 77 | char type_name[OFW_TREE_PROPERTY_MAX_VALUELEN];
|
---|
[a35b458] | 78 |
|
---|
[965dc18] | 79 | if (ofw_get_property(child, "device_type", type_name,
|
---|
[ed5ad30] | 80 | OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
|
---|
| 81 | type_name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
|
---|
[a35b458] | 82 |
|
---|
[4872160] | 83 | if (str_cmp(type_name, "cpu") == 0) {
|
---|
[45b26dad] | 84 | uint32_t mid;
|
---|
[a35b458] | 85 |
|
---|
[965dc18] | 86 | /*
|
---|
| 87 | * "upa-portid" for US, "portid" for US-III,
|
---|
| 88 | * "cpuid" for US-IV
|
---|
| 89 | */
|
---|
[3bacee1] | 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))
|
---|
[9a5b556] | 93 | continue;
|
---|
[a35b458] | 94 |
|
---|
[45b26dad] | 95 | if (current_mid != mid) {
|
---|
| 96 | /*
|
---|
| 97 | * Start secondary processor.
|
---|
| 98 | */
|
---|
[1eb154f] | 99 | (void) ofw_call("SUNW,start-cpu", 3, 1,
|
---|
[4872160] | 100 | NULL, child, KERNEL_ADDRESS,
|
---|
[e731b0d] | 101 | physmem_start | AP_PROCESSOR);
|
---|
[45b26dad] | 102 | }
|
---|
[9a5b556] | 103 | }
|
---|
| 104 | }
|
---|
[45b26dad] | 105 | }
|
---|
[a35b458] | 106 |
|
---|
[a9ac978] | 107 | return cpus;
|
---|
[9a5b556] | 108 | }
|
---|
[f2ea5d8] | 109 |
|
---|
[4872160] | 110 | /** Find out the current CPU's MID and wake up all AP processors.
|
---|
| 111 | *
|
---|
[965dc18] | 112 | */
|
---|
[4872160] | 113 | void ofw_cpu(uint16_t mid_mask, uintptr_t physmem_start)
|
---|
[965dc18] | 114 | {
|
---|
[e731b0d] | 115 | /* Get the current CPU MID */
|
---|
[965dc18] | 116 | uint64_t current_mid;
|
---|
[a35b458] | 117 |
|
---|
[e731b0d] | 118 | asm volatile (
|
---|
[3bacee1] | 119 | "ldxa [%[zero]] %[asi], %[current_mid]\n"
|
---|
| 120 | : [current_mid] "=r" (current_mid)
|
---|
| 121 | : [zero] "r" (0),
|
---|
| 122 | [asi] "i" (ASI_ICBUS_CONFIG)
|
---|
[e731b0d] | 123 | );
|
---|
[a35b458] | 124 |
|
---|
[965dc18] | 125 | current_mid >>= ICBUS_CONFIG_MID_SHIFT;
|
---|
| 126 | current_mid &= mid_mask;
|
---|
[a35b458] | 127 |
|
---|
[e731b0d] | 128 | /* Wake up the CPUs */
|
---|
[a35b458] | 129 |
|
---|
[e731b0d] | 130 | phandle cpus_parent = ofw_find_device("/ssm@0,0");
|
---|
[4872160] | 131 | if ((cpus_parent == 0) || (cpus_parent == (phandle) -1))
|
---|
[965dc18] | 132 | cpus_parent = ofw_find_device("/");
|
---|
[a35b458] | 133 |
|
---|
[e731b0d] | 134 | phandle node = ofw_get_child_node(cpus_parent);
|
---|
[4872160] | 135 | size_t cpus = wake_cpus_in_node(node, current_mid, physmem_start);
|
---|
[a35b458] | 136 |
|
---|
[4872160] | 137 | while ((node != 0) && (node != (phandle) -1)) {
|
---|
[ed5ad30] | 138 | char name[OFW_TREE_PROPERTY_MAX_VALUELEN];
|
---|
[a35b458] | 139 |
|
---|
[965dc18] | 140 | if (ofw_get_property(node, "name", name,
|
---|
[ed5ad30] | 141 | OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
|
---|
| 142 | name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
|
---|
[a35b458] | 143 |
|
---|
[4872160] | 144 | if (str_cmp(name, "cmp") == 0) {
|
---|
[e731b0d] | 145 | phandle subnode = ofw_get_child_node(node);
|
---|
[965dc18] | 146 | cpus += wake_cpus_in_node(subnode,
|
---|
[4872160] | 147 | current_mid, physmem_start);
|
---|
[965dc18] | 148 | }
|
---|
| 149 | }
|
---|
[a35b458] | 150 |
|
---|
[965dc18] | 151 | node = ofw_get_peer_node(node);
|
---|
| 152 | }
|
---|
[a35b458] | 153 |
|
---|
[4872160] | 154 | if (cpus == 0)
|
---|
| 155 | printf("Warning: Unable to get CPU properties.\n");
|
---|
[965dc18] | 156 | }
|
---|
| 157 |
|
---|
[f2ea5d8] | 158 | /** Get physical memory starting address.
|
---|
| 159 | *
|
---|
[4872160] | 160 | * @return Physical memory starting address.
|
---|
[f2ea5d8] | 161 | *
|
---|
| 162 | */
|
---|
[4872160] | 163 | uintptr_t ofw_get_physmem_start(void)
|
---|
[f2ea5d8] | 164 | {
|
---|
| 165 | uint32_t memreg[4];
|
---|
[4872160] | 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 | }
|
---|
[a35b458] | 171 |
|
---|
[4872160] | 172 | return ((((uintptr_t) memreg[0]) << 32) | memreg[1]);
|
---|
[f2ea5d8] | 173 | }
|
---|