Rev 1903 | Rev 2089 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1903 | jermar | 1 | /* |
| 2071 | jermar | 2 | * Copyright (c) 2006 Jakub Jermar |
| 1903 | jermar | 3 | * All rights reserved. |
| 4 | * |
||
| 5 | * Redistribution and use in source and binary forms, with or without |
||
| 6 | * modification, are permitted provided that the following conditions |
||
| 7 | * are met: |
||
| 8 | * |
||
| 9 | * - Redistributions of source code must retain the above copyright |
||
| 10 | * notice, this list of conditions and the following disclaimer. |
||
| 11 | * - Redistributions in binary form must reproduce the above copyright |
||
| 12 | * notice, this list of conditions and the following disclaimer in the |
||
| 13 | * documentation and/or other materials provided with the distribution. |
||
| 14 | * - The name of the author may not be used to endorse or promote products |
||
| 15 | * derived from this software without specific prior written permission. |
||
| 16 | * |
||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 27 | */ |
||
| 28 | |||
| 29 | /** @addtogroup sparc64 |
||
| 30 | * @{ |
||
| 31 | */ |
||
| 32 | /** @file |
||
| 33 | */ |
||
| 34 | |||
| 35 | #include <smp/smp.h> |
||
| 36 | #include <genarch/ofw/ofw_tree.h> |
||
| 37 | #include <cpu.h> |
||
| 38 | #include <arch/cpu.h> |
||
| 39 | #include <arch.h> |
||
| 40 | #include <config.h> |
||
| 41 | #include <macros.h> |
||
| 42 | #include <arch/types.h> |
||
| 43 | #include <synch/synch.h> |
||
| 44 | #include <synch/waitq.h> |
||
| 45 | #include <typedefs.h> |
||
| 46 | #include <print.h> |
||
| 47 | |||
| 48 | /** |
||
| 49 | * This global variable is used to pick-up application processors |
||
| 50 | * from their active loop in start.S. When a processor looping in |
||
| 51 | * start.S sees that this variable contains its MID, it can |
||
| 52 | * proceed with its initialization. |
||
| 53 | * |
||
| 54 | * This variable is modified only by the bootstrap processor. |
||
| 55 | * Other processors access it read-only. |
||
| 56 | */ |
||
| 57 | volatile uint64_t waking_up_mid = (uint64_t) -1; |
||
| 58 | |||
| 59 | /** Determine number of processors. */ |
||
| 60 | void smp_init(void) |
||
| 61 | { |
||
| 62 | ofw_tree_node_t *node; |
||
| 63 | count_t cnt = 0; |
||
| 64 | |||
| 65 | node = ofw_tree_find_child_by_device_type(ofw_tree_lookup("/"), "cpu"); |
||
| 66 | while (node) { |
||
| 67 | cnt++; |
||
| 68 | node = ofw_tree_find_peer_by_device_type(node, "cpu"); |
||
| 69 | } |
||
| 70 | |||
| 71 | config.cpu_count = max(1, cnt); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** Wake application processors up. */ |
||
| 75 | void kmp(void *arg) |
||
| 76 | { |
||
| 77 | ofw_tree_node_t *node; |
||
| 78 | int i; |
||
| 79 | |||
| 80 | node = ofw_tree_find_child_by_device_type(ofw_tree_lookup("/"), "cpu"); |
||
| 81 | for (i = 0; node; node = ofw_tree_find_peer_by_device_type(node, "cpu"), i++) { |
||
| 82 | uint32_t mid; |
||
| 83 | ofw_tree_property_t *prop; |
||
| 84 | |||
| 85 | prop = ofw_tree_getprop(node, "upa-portid"); |
||
| 86 | if (!prop || !prop->value) |
||
| 87 | continue; |
||
| 88 | |||
| 89 | mid = *((uint32_t *) prop->value); |
||
| 90 | if (CPU->arch.mid == mid) { |
||
| 91 | /* |
||
| 92 | * Skip the current CPU. |
||
| 93 | */ |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | |||
| 97 | /* |
||
| 98 | * Processor with ID == mid can proceed with its initialization. |
||
| 99 | */ |
||
| 100 | waking_up_mid = mid; |
||
| 101 | |||
| 102 | if (waitq_sleep_timeout(&ap_completion_wq, 1000000, SYNCH_FLAGS_NONE) == ESYNCH_TIMEOUT) |
||
| 103 | printf("%s: waiting for processor (mid = %d) timed out\n", |
||
| 104 | __FUNCTION__, mid); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | /** @} |
||
| 109 | */ |