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