Rev 28 | Rev 30 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 28 | Rev 29 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 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 | #ifdef __SMP__ |
29 | #ifdef __SMP__ |
30 | 30 | ||
31 | #include <arch/pm.h> |
31 | #include <arch/pm.h> |
32 | #include <config.h> |
32 | #include <config.h> |
33 | #include <print.h> |
33 | #include <print.h> |
34 | #include <panic.h> |
34 | #include <panic.h> |
35 | #include <arch/smp/mp.h> |
35 | #include <arch/smp/mp.h> |
36 | #include <arch/smp/ap.h> |
36 | #include <arch/smp/ap.h> |
37 | #include <arch/smp/apic.h> |
37 | #include <arch/smp/apic.h> |
38 | #include <func.h> |
38 | #include <func.h> |
39 | #include <arch/types.h> |
39 | #include <arch/types.h> |
40 | #include <typedefs.h> |
40 | #include <typedefs.h> |
41 | #include <synch/waitq.h> |
41 | #include <synch/waitq.h> |
42 | #include <time/delay.h> |
42 | #include <time/delay.h> |
43 | #include <mm/heap.h> |
43 | #include <mm/heap.h> |
44 | #include <mm/page.h> |
44 | #include <mm/page.h> |
45 | #include <mm/frame.h> |
45 | #include <mm/frame.h> |
46 | #include <cpu.h> |
46 | #include <cpu.h> |
47 | #include <arch/i8259.h> |
47 | #include <arch/i8259.h> |
48 | #include <arch/asm.h> |
48 | #include <arch/asm.h> |
- | 49 | #include <arch/acpi/madt.h> |
|
49 | 50 | ||
50 | /* |
51 | /* |
51 | * Multi-Processor Specification detection code. |
52 | * Multi-Processor Specification detection code. |
52 | */ |
53 | */ |
53 | 54 | ||
54 | #define FS_SIGNATURE 0x5f504d5f |
55 | #define FS_SIGNATURE 0x5f504d5f |
55 | #define CT_SIGNATURE 0x504d4350 |
56 | #define CT_SIGNATURE 0x504d4350 |
56 | 57 | ||
57 | int mp_fs_check(__u8 *base); |
58 | int mp_fs_check(__u8 *base); |
58 | int mp_ct_check(void); |
59 | int mp_ct_check(void); |
59 | 60 | ||
60 | int configure_via_ct(void); |
61 | int configure_via_ct(void); |
61 | int configure_via_default(__u8 n); |
62 | int configure_via_default(__u8 n); |
62 | 63 | ||
63 | int ct_processor_entry(struct __processor_entry *pr); |
64 | int ct_processor_entry(struct __processor_entry *pr); |
64 | void ct_bus_entry(struct __bus_entry *bus); |
65 | void ct_bus_entry(struct __bus_entry *bus); |
65 | void ct_io_apic_entry(struct __io_apic_entry *ioa); |
66 | void ct_io_apic_entry(struct __io_apic_entry *ioa); |
66 | void ct_io_intr_entry(struct __io_intr_entry *iointr); |
67 | void ct_io_intr_entry(struct __io_intr_entry *iointr); |
67 | void ct_l_intr_entry(struct __l_intr_entry *lintr); |
68 | void ct_l_intr_entry(struct __l_intr_entry *lintr); |
68 | 69 | ||
69 | void ct_extended_entries(void); |
70 | void ct_extended_entries(void); |
70 | 71 | ||
71 | static struct __mpfs *fs; |
72 | static struct __mpfs *fs; |
72 | static struct __mpct *ct; |
73 | static struct __mpct *ct; |
73 | 74 | ||
74 | struct __processor_entry *processor_entries = NULL; |
75 | struct __processor_entry *processor_entries = NULL; |
75 | struct __bus_entry *bus_entries = NULL; |
76 | struct __bus_entry *bus_entries = NULL; |
76 | struct __io_apic_entry *io_apic_entries = NULL; |
77 | struct __io_apic_entry *io_apic_entries = NULL; |
77 | struct __io_intr_entry *io_intr_entries = NULL; |
78 | struct __io_intr_entry *io_intr_entries = NULL; |
78 | struct __l_intr_entry *l_intr_entries = NULL; |
79 | struct __l_intr_entry *l_intr_entries = NULL; |
79 | 80 | ||
80 | int processor_entry_cnt = 0; |
81 | int processor_entry_cnt = 0; |
81 | int bus_entry_cnt = 0; |
82 | int bus_entry_cnt = 0; |
82 | int io_apic_entry_cnt = 0; |
83 | int io_apic_entry_cnt = 0; |
83 | int io_intr_entry_cnt = 0; |
84 | int io_intr_entry_cnt = 0; |
84 | int l_intr_entry_cnt = 0; |
85 | int l_intr_entry_cnt = 0; |
85 | 86 | ||
86 | waitq_t ap_completion_wq; |
87 | waitq_t ap_completion_wq; |
87 | waitq_t kmp_completion_wq; |
88 | waitq_t kmp_completion_wq; |
88 | 89 | ||
89 | /* |
90 | /* |
90 | * Used to check the integrity of the MP Floating Structure. |
91 | * Used to check the integrity of the MP Floating Structure. |
91 | */ |
92 | */ |
92 | int mp_fs_check(__u8 *base) |
93 | int mp_fs_check(__u8 *base) |
93 | { |
94 | { |
94 | int i; |
95 | int i; |
95 | __u8 sum; |
96 | __u8 sum; |
96 | 97 | ||
97 | for (i = 0, sum = 0; i < 16; i++) |
98 | for (i = 0, sum = 0; i < 16; i++) |
98 | sum += base[i]; |
99 | sum += base[i]; |
99 | 100 | ||
100 | return !sum; |
101 | return !sum; |
101 | } |
102 | } |
102 | 103 | ||
103 | /* |
104 | /* |
104 | * Used to check the integrity of the MP Configuration Table. |
105 | * Used to check the integrity of the MP Configuration Table. |
105 | */ |
106 | */ |
106 | int mp_ct_check(void) |
107 | int mp_ct_check(void) |
107 | { |
108 | { |
108 | __u8 *base = (__u8 *) ct; |
109 | __u8 *base = (__u8 *) ct; |
109 | __u8 *ext = base + ct->base_table_length; |
110 | __u8 *ext = base + ct->base_table_length; |
110 | __u8 sum; |
111 | __u8 sum; |
111 | int i; |
112 | int i; |
112 | 113 | ||
113 | /* count the checksum for the base table */ |
114 | /* count the checksum for the base table */ |
114 | for (i=0,sum=0; i < ct->base_table_length; i++) |
115 | for (i=0,sum=0; i < ct->base_table_length; i++) |
115 | sum += base[i]; |
116 | sum += base[i]; |
116 | 117 | ||
117 | if (sum) |
118 | if (sum) |
118 | return 0; |
119 | return 0; |
119 | 120 | ||
120 | /* count the checksum for the extended table */ |
121 | /* count the checksum for the extended table */ |
121 | for (i=0,sum=0; i < ct->ext_table_length; i++) |
122 | for (i=0,sum=0; i < ct->ext_table_length; i++) |
122 | sum += ext[i]; |
123 | sum += ext[i]; |
123 | 124 | ||
124 | return sum == ct->ext_table_checksum; |
125 | return sum == ct->ext_table_checksum; |
125 | } |
126 | } |
126 | 127 | ||
127 | void mp_init(void) |
128 | void mp_init(void) |
128 | { |
129 | { |
129 | __address addr, frame; |
130 | __address addr, frame; |
130 | int cnt, n; |
131 | int cnt, n; |
131 | 132 | ||
132 | 133 | ||
133 | /* |
134 | /* |
134 | * First place to search the MP Floating Pointer Structure is the Extended |
135 | * First place to search the MP Floating Pointer Structure is the Extended |
135 | * BIOS Data Area. We have to read EBDA segment address from the BIOS Data |
136 | * BIOS Data Area. We have to read EBDA segment address from the BIOS Data |
136 | * Area. Unfortunatelly, this memory is in page 0, which has intentionally no |
137 | * Area. Unfortunatelly, this memory is in page 0, which has intentionally no |
137 | * mapping. |
138 | * mapping. |
138 | */ |
139 | */ |
139 | frame = frame_alloc(FRAME_KA); |
140 | frame = frame_alloc(FRAME_KA); |
140 | map_page_to_frame(frame,0,PAGE_CACHEABLE,0); |
141 | map_page_to_frame(frame,0,PAGE_CACHEABLE,0); |
141 | addr = *((__u16 *) (frame + 0x40e)) * 16; |
142 | addr = *((__u16 *) (frame + 0x40e)) * 16; |
142 | map_page_to_frame(frame,frame,PAGE_CACHEABLE,0); |
143 | map_page_to_frame(frame,frame,PAGE_CACHEABLE,0); |
143 | frame_free(frame); |
144 | frame_free(frame); |
144 | 145 | ||
145 | /* |
146 | /* |
146 | * EBDA can be undefined. In that case addr would be 0. |
147 | * EBDA can be undefined. In that case addr would be 0. |
147 | */ |
148 | */ |
148 | if (addr >= 0x1000) { |
149 | if (addr >= 0x1000) { |
149 | cnt = 1024; |
150 | cnt = 1024; |
150 | while (addr = __u32_search(addr,cnt,FS_SIGNATURE)) { |
151 | while (addr = __u32_search(addr,cnt,FS_SIGNATURE)) { |
151 | if (mp_fs_check((__u8 *) addr)) |
152 | if (mp_fs_check((__u8 *) addr)) |
152 | goto fs_found; |
153 | goto fs_found; |
153 | addr++; |
154 | addr++; |
154 | cnt--; |
155 | cnt--; |
155 | } |
156 | } |
156 | } |
157 | } |
157 | 158 | ||
158 | /* |
159 | /* |
159 | * Second place where the MP Floating Pointer Structure may live is the last |
160 | * Second place where the MP Floating Pointer Structure may live is the last |
160 | * kilobyte of base memory. |
161 | * kilobyte of base memory. |
161 | */ |
162 | */ |
162 | addr = 639*1024; |
163 | addr = 639*1024; |
163 | cnt = 1024; |
164 | cnt = 1024; |
164 | while (addr = __u32_search(addr,cnt,FS_SIGNATURE)) { |
165 | while (addr = __u32_search(addr,cnt,FS_SIGNATURE)) { |
165 | if (mp_fs_check((__u8 *) addr)) |
166 | if (mp_fs_check((__u8 *) addr)) |
166 | goto fs_found; |
167 | goto fs_found; |
167 | addr++; |
168 | addr++; |
168 | cnt--; |
169 | cnt--; |
169 | } |
170 | } |
170 | 171 | ||
171 | /* |
172 | /* |
172 | * As the last resort, MP Floating Pointer Structure is searched in the BIOS |
173 | * As the last resort, MP Floating Pointer Structure is searched in the BIOS |
173 | * ROM. |
174 | * ROM. |
174 | */ |
175 | */ |
175 | addr = 0xf0000; |
176 | addr = 0xf0000; |
176 | cnt = 64*1024; |
177 | cnt = 64*1024; |
177 | while (addr = __u32_search(addr,cnt,FS_SIGNATURE)) { |
178 | while (addr = __u32_search(addr,cnt,FS_SIGNATURE)) { |
178 | if (mp_fs_check((__u8 *) addr)) |
179 | if (mp_fs_check((__u8 *) addr)) |
179 | goto fs_found; |
180 | goto fs_found; |
180 | addr++; |
181 | addr++; |
181 | cnt--; |
182 | cnt--; |
182 | } |
183 | } |
183 | 184 | ||
184 | return; |
185 | return; |
185 | 186 | ||
186 | fs_found: |
187 | fs_found: |
187 | printf("%L: MP Floating Pointer Structure\n", addr); |
188 | printf("%L: MP Floating Pointer Structure\n", addr); |
188 | 189 | ||
189 | fs = (struct __mpfs *) addr; |
190 | fs = (struct __mpfs *) addr; |
190 | frame_not_free((__address) fs); |
191 | frame_not_free((__address) fs); |
191 | 192 | ||
192 | if (fs->config_type == 0 && fs->configuration_table) { |
193 | if (fs->config_type == 0 && fs->configuration_table) { |
193 | if (fs->mpfib2 >> 7) { |
194 | if (fs->mpfib2 >> 7) { |
194 | printf("mp_init: PIC mode not supported\n"); |
195 | printf("mp_init: PIC mode not supported\n"); |
195 | return; |
196 | return; |
196 | } |
197 | } |
197 | 198 | ||
198 | ct = fs->configuration_table; |
199 | ct = fs->configuration_table; |
199 | frame_not_free((__address) ct); |
200 | frame_not_free((__address) ct); |
200 | config.cpu_count = configure_via_ct(); |
201 | config.cpu_count = configure_via_ct(); |
201 | } |
202 | } |
202 | else |
203 | else |
203 | config.cpu_count = configure_via_default(fs->config_type); |
204 | config.cpu_count = configure_via_default(fs->config_type); |
204 | 205 | ||
205 | if (config.cpu_count > 1) { |
206 | if (config.cpu_count > 1) { |
206 | map_page_to_frame((__address) l_apic, (__address) l_apic, PAGE_NOT_CACHEABLE, 0); |
207 | map_page_to_frame((__address) l_apic, (__address) l_apic, PAGE_NOT_CACHEABLE, 0); |
207 | } |
208 | } |
208 | 209 | ||
209 | 210 | ||
210 | /* |
211 | /* |
211 | * Must be initialized outside the kmp thread, since it is waited |
212 | * Must be initialized outside the kmp thread, since it is waited |
212 | * on before the kmp thread is created. |
213 | * on before the kmp thread is created. |
213 | */ |
214 | */ |
214 | waitq_initialize(&kmp_completion_wq); |
215 | waitq_initialize(&kmp_completion_wq); |
215 | return; |
216 | return; |
216 | } |
217 | } |
217 | 218 | ||
218 | int configure_via_ct(void) |
219 | int configure_via_ct(void) |
219 | { |
220 | { |
220 | __u8 *cur; |
221 | __u8 *cur; |
221 | int i, cnt; |
222 | int i, cnt; |
222 | 223 | ||
223 | if (ct->signature != CT_SIGNATURE) { |
224 | if (ct->signature != CT_SIGNATURE) { |
224 | printf("configure_via_ct: bad ct->signature\n"); |
225 | printf("configure_via_ct: bad ct->signature\n"); |
225 | return 1; |
226 | return 1; |
226 | } |
227 | } |
227 | if (!mp_ct_check()) { |
228 | if (!mp_ct_check()) { |
228 | printf("configure_via_ct: bad ct checksum\n"); |
229 | printf("configure_via_ct: bad ct checksum\n"); |
229 | return 1; |
230 | return 1; |
230 | } |
231 | } |
231 | if (ct->oem_table) { |
232 | if (ct->oem_table) { |
232 | printf("configure_via_ct: ct->oem_table not supported\n"); |
233 | printf("configure_via_ct: ct->oem_table not supported\n"); |
233 | return 1; |
234 | return 1; |
234 | } |
235 | } |
235 | 236 | ||
236 | l_apic = ct->l_apic; |
237 | l_apic = ct->l_apic; |
237 | 238 | ||
238 | cnt = 0; |
239 | cnt = 0; |
239 | cur = &ct->base_table[0]; |
240 | cur = &ct->base_table[0]; |
240 | for (i=0; i < ct->entry_count; i++) { |
241 | for (i=0; i < ct->entry_count; i++) { |
241 | switch (*cur) { |
242 | switch (*cur) { |
242 | /* Processor entry */ |
243 | /* Processor entry */ |
243 | case 0: |
244 | case 0: |
244 | processor_entries = processor_entries ? processor_entries : (struct __processor_entry *) cur; |
245 | processor_entries = processor_entries ? processor_entries : (struct __processor_entry *) cur; |
245 | processor_entry_cnt++; |
246 | processor_entry_cnt++; |
246 | cnt += ct_processor_entry((struct __processor_entry *) cur); |
247 | cnt += ct_processor_entry((struct __processor_entry *) cur); |
247 | cur += 20; |
248 | cur += 20; |
248 | break; |
249 | break; |
249 | 250 | ||
250 | /* Bus entry */ |
251 | /* Bus entry */ |
251 | case 1: |
252 | case 1: |
252 | bus_entries = bus_entries ? bus_entries : (struct __bus_entry *) cur; |
253 | bus_entries = bus_entries ? bus_entries : (struct __bus_entry *) cur; |
253 | bus_entry_cnt++; |
254 | bus_entry_cnt++; |
254 | ct_bus_entry((struct __bus_entry *) cur); |
255 | ct_bus_entry((struct __bus_entry *) cur); |
255 | cur += 8; |
256 | cur += 8; |
256 | break; |
257 | break; |
257 | 258 | ||
258 | /* I/O Apic */ |
259 | /* I/O Apic */ |
259 | case 2: |
260 | case 2: |
260 | io_apic_entries = io_apic_entries ? io_apic_entries : (struct __io_apic_entry *) cur; |
261 | io_apic_entries = io_apic_entries ? io_apic_entries : (struct __io_apic_entry *) cur; |
261 | io_apic_entry_cnt++; |
262 | io_apic_entry_cnt++; |
262 | ct_io_apic_entry((struct __io_apic_entry *) cur); |
263 | ct_io_apic_entry((struct __io_apic_entry *) cur); |
263 | cur += 8; |
264 | cur += 8; |
264 | break; |
265 | break; |
265 | 266 | ||
266 | /* I/O Interrupt Assignment */ |
267 | /* I/O Interrupt Assignment */ |
267 | case 3: |
268 | case 3: |
268 | io_intr_entries = io_intr_entries ? io_intr_entries : (struct __io_intr_entry *) cur; |
269 | io_intr_entries = io_intr_entries ? io_intr_entries : (struct __io_intr_entry *) cur; |
269 | io_intr_entry_cnt++; |
270 | io_intr_entry_cnt++; |
270 | ct_io_intr_entry((struct __io_intr_entry *) cur); |
271 | ct_io_intr_entry((struct __io_intr_entry *) cur); |
271 | cur += 8; |
272 | cur += 8; |
272 | break; |
273 | break; |
273 | 274 | ||
274 | /* Local Interrupt Assignment */ |
275 | /* Local Interrupt Assignment */ |
275 | case 4: |
276 | case 4: |
276 | l_intr_entries = l_intr_entries ? l_intr_entries : (struct __l_intr_entry *) cur; |
277 | l_intr_entries = l_intr_entries ? l_intr_entries : (struct __l_intr_entry *) cur; |
277 | l_intr_entry_cnt++; |
278 | l_intr_entry_cnt++; |
278 | ct_l_intr_entry((struct __l_intr_entry *) cur); |
279 | ct_l_intr_entry((struct __l_intr_entry *) cur); |
279 | cur += 8; |
280 | cur += 8; |
280 | break; |
281 | break; |
281 | 282 | ||
282 | default: |
283 | default: |
283 | /* |
284 | /* |
284 | * Something is wrong. Fallback to UP mode. |
285 | * Something is wrong. Fallback to UP mode. |
285 | */ |
286 | */ |
286 | 287 | ||
287 | printf("configure_via_ct: ct badness\n"); |
288 | printf("configure_via_ct: ct badness\n"); |
288 | return 1; |
289 | return 1; |
289 | } |
290 | } |
290 | } |
291 | } |
291 | 292 | ||
292 | /* |
293 | /* |
293 | * Process extended entries. |
294 | * Process extended entries. |
294 | */ |
295 | */ |
295 | ct_extended_entries(); |
296 | ct_extended_entries(); |
296 | return cnt; |
297 | return cnt; |
297 | } |
298 | } |
298 | 299 | ||
299 | int configure_via_default(__u8 n) |
300 | int configure_via_default(__u8 n) |
300 | { |
301 | { |
301 | /* |
302 | /* |
302 | * Not yet implemented. |
303 | * Not yet implemented. |
303 | */ |
304 | */ |
304 | printf("configure_via_default: not supported\n"); |
305 | printf("configure_via_default: not supported\n"); |
305 | return 1; |
306 | return 1; |
306 | } |
307 | } |
307 | 308 | ||
308 | 309 | ||
309 | int ct_processor_entry(struct __processor_entry *pr) |
310 | int ct_processor_entry(struct __processor_entry *pr) |
310 | { |
311 | { |
311 | /* |
312 | /* |
312 | * Ignore processors which are not marked enabled. |
313 | * Ignore processors which are not marked enabled. |
313 | */ |
314 | */ |
314 | if ((pr->cpu_flags & (1<<0)) == 0) |
315 | if ((pr->cpu_flags & (1<<0)) == 0) |
315 | return 0; |
316 | return 0; |
316 | 317 | ||
317 | apic_id_mask |= (1<<pr->l_apic_id); |
318 | apic_id_mask |= (1<<pr->l_apic_id); |
318 | return 1; |
319 | return 1; |
319 | } |
320 | } |
320 | 321 | ||
321 | void ct_bus_entry(struct __bus_entry *bus) |
322 | void ct_bus_entry(struct __bus_entry *bus) |
322 | { |
323 | { |
323 | #ifdef MPCT_VERBOSE |
324 | #ifdef MPCT_VERBOSE |
324 | char buf[7]; |
325 | char buf[7]; |
325 | memcopy((__address) bus->bus_type, (__address) buf,6); |
326 | memcopy((__address) bus->bus_type, (__address) buf,6); |
326 | buf[6] = 0; |
327 | buf[6] = 0; |
327 | printf("bus%d: %s\n", bus->bus_id, buf); |
328 | printf("bus%d: %s\n", bus->bus_id, buf); |
328 | #endif |
329 | #endif |
329 | } |
330 | } |
330 | 331 | ||
331 | void ct_io_apic_entry(struct __io_apic_entry *ioa) |
332 | void ct_io_apic_entry(struct __io_apic_entry *ioa) |
332 | { |
333 | { |
333 | static int io_apic_count = 0; |
334 | static int io_apic_count = 0; |
334 | 335 | ||
335 | /* this ioapic is marked unusable */ |
336 | /* this ioapic is marked unusable */ |
336 | if (ioa->io_apic_flags & 1 == 0) |
337 | if (ioa->io_apic_flags & 1 == 0) |
337 | return; |
338 | return; |
338 | 339 | ||
339 | if (io_apic_count++ > 0) { |
340 | if (io_apic_count++ > 0) { |
340 | /* |
341 | /* |
341 | * Multiple IO APIC's are currently not supported. |
342 | * Multiple IO APIC's are currently not supported. |
342 | */ |
343 | */ |
343 | return; |
344 | return; |
344 | } |
345 | } |
345 | 346 | ||
346 | map_page_to_frame((__address) ioa->io_apic, (__address) ioa->io_apic, PAGE_NOT_CACHEABLE, 0); |
347 | map_page_to_frame((__address) ioa->io_apic, (__address) ioa->io_apic, PAGE_NOT_CACHEABLE, 0); |
347 | 348 | ||
348 | io_apic = ioa->io_apic; |
349 | io_apic = ioa->io_apic; |
349 | } |
350 | } |
350 | 351 | ||
351 | //#define MPCT_VERBOSE |
352 | //#define MPCT_VERBOSE |
352 | void ct_io_intr_entry(struct __io_intr_entry *iointr) |
353 | void ct_io_intr_entry(struct __io_intr_entry *iointr) |
353 | { |
354 | { |
354 | #ifdef MPCT_VERBOSE |
355 | #ifdef MPCT_VERBOSE |
355 | switch (iointr->intr_type) { |
356 | switch (iointr->intr_type) { |
356 | case 0: printf("INT"); break; |
357 | case 0: printf("INT"); break; |
357 | case 1: printf("NMI"); break; |
358 | case 1: printf("NMI"); break; |
358 | case 2: printf("SMI"); break; |
359 | case 2: printf("SMI"); break; |
359 | case 3: printf("ExtINT"); break; |
360 | case 3: printf("ExtINT"); break; |
360 | } |
361 | } |
361 | putchar(','); |
362 | putchar(','); |
362 | switch (iointr->poel&3) { |
363 | switch (iointr->poel&3) { |
363 | case 0: printf("bus-like"); break; |
364 | case 0: printf("bus-like"); break; |
364 | case 1: printf("active high"); break; |
365 | case 1: printf("active high"); break; |
365 | case 2: printf("reserved"); break; |
366 | case 2: printf("reserved"); break; |
366 | case 3: printf("active low"); break; |
367 | case 3: printf("active low"); break; |
367 | } |
368 | } |
368 | putchar(','); |
369 | putchar(','); |
369 | switch ((iointr->poel>>2)&3) { |
370 | switch ((iointr->poel>>2)&3) { |
370 | case 0: printf("bus-like"); break; |
371 | case 0: printf("bus-like"); break; |
371 | case 1: printf("edge-triggered"); break; |
372 | case 1: printf("edge-triggered"); break; |
372 | case 2: printf("reserved"); break; |
373 | case 2: printf("reserved"); break; |
373 | case 3: printf("level-triggered"); break; |
374 | case 3: printf("level-triggered"); break; |
374 | } |
375 | } |
375 | putchar(','); |
376 | putchar(','); |
376 | printf("bus%d,irq%d", iointr->src_bus_id, iointr->src_bus_irq); |
377 | printf("bus%d,irq%d", iointr->src_bus_id, iointr->src_bus_irq); |
377 | putchar(','); |
378 | putchar(','); |
378 | printf("io_apic%d,pin%d", iointr->dst_io_apic_id, iointr->dst_io_apic_pin); |
379 | printf("io_apic%d,pin%d", iointr->dst_io_apic_id, iointr->dst_io_apic_pin); |
379 | putchar('\n'); |
380 | putchar('\n'); |
380 | #endif |
381 | #endif |
381 | } |
382 | } |
382 | 383 | ||
383 | void ct_l_intr_entry(struct __l_intr_entry *lintr) |
384 | void ct_l_intr_entry(struct __l_intr_entry *lintr) |
384 | { |
385 | { |
385 | #ifdef MPCT_VERBOSE |
386 | #ifdef MPCT_VERBOSE |
386 | switch (lintr->intr_type) { |
387 | switch (lintr->intr_type) { |
387 | case 0: printf("INT"); break; |
388 | case 0: printf("INT"); break; |
388 | case 1: printf("NMI"); break; |
389 | case 1: printf("NMI"); break; |
389 | case 2: printf("SMI"); break; |
390 | case 2: printf("SMI"); break; |
390 | case 3: printf("ExtINT"); break; |
391 | case 3: printf("ExtINT"); break; |
391 | } |
392 | } |
392 | putchar(','); |
393 | putchar(','); |
393 | switch (lintr->poel&3) { |
394 | switch (lintr->poel&3) { |
394 | case 0: printf("bus-like"); break; |
395 | case 0: printf("bus-like"); break; |
395 | case 1: printf("active high"); break; |
396 | case 1: printf("active high"); break; |
396 | case 2: printf("reserved"); break; |
397 | case 2: printf("reserved"); break; |
397 | case 3: printf("active low"); break; |
398 | case 3: printf("active low"); break; |
398 | } |
399 | } |
399 | putchar(','); |
400 | putchar(','); |
400 | switch ((lintr->poel>>2)&3) { |
401 | switch ((lintr->poel>>2)&3) { |
401 | case 0: printf("bus-like"); break; |
402 | case 0: printf("bus-like"); break; |
402 | case 1: printf("edge-triggered"); break; |
403 | case 1: printf("edge-triggered"); break; |
403 | case 2: printf("reserved"); break; |
404 | case 2: printf("reserved"); break; |
404 | case 3: printf("level-triggered"); break; |
405 | case 3: printf("level-triggered"); break; |
405 | } |
406 | } |
406 | putchar(','); |
407 | putchar(','); |
407 | printf("bus%d,irq%d", lintr->src_bus_id, lintr->src_bus_irq); |
408 | printf("bus%d,irq%d", lintr->src_bus_id, lintr->src_bus_irq); |
408 | putchar(','); |
409 | putchar(','); |
409 | printf("l_apic%d,pin%d", lintr->dst_l_apic_id, lintr->dst_l_apic_pin); |
410 | printf("l_apic%d,pin%d", lintr->dst_l_apic_id, lintr->dst_l_apic_pin); |
410 | putchar('\n'); |
411 | putchar('\n'); |
411 | #endif |
412 | #endif |
412 | } |
413 | } |
413 | 414 | ||
414 | void ct_extended_entries(void) |
415 | void ct_extended_entries(void) |
415 | { |
416 | { |
416 | __u8 *ext = (__u8 *) ct + ct->base_table_length; |
417 | __u8 *ext = (__u8 *) ct + ct->base_table_length; |
417 | __u8 *cur; |
418 | __u8 *cur; |
418 | 419 | ||
419 | for (cur = ext; cur < ext + ct->ext_table_length; cur += cur[CT_EXT_ENTRY_LEN]) { |
420 | for (cur = ext; cur < ext + ct->ext_table_length; cur += cur[CT_EXT_ENTRY_LEN]) { |
420 | switch (cur[CT_EXT_ENTRY_TYPE]) { |
421 | switch (cur[CT_EXT_ENTRY_TYPE]) { |
421 | default: |
422 | default: |
422 | printf("%X: skipping MP Configuration Table extended entry type %d\n", cur, cur[CT_EXT_ENTRY_TYPE]); |
423 | printf("%X: skipping MP Configuration Table extended entry type %d\n", cur, cur[CT_EXT_ENTRY_TYPE]); |
423 | break; |
424 | break; |
424 | } |
425 | } |
425 | } |
426 | } |
426 | } |
427 | } |
427 | 428 | ||
428 | /* |
429 | /* |
429 | * Kernel thread for bringing up application processors. It becomes clear |
430 | * Kernel thread for bringing up application processors. It becomes clear |
430 | * that we need an arrangement like this (AP's being initialized by a kernel |
431 | * that we need an arrangement like this (AP's being initialized by a kernel |
431 | * thread), for a thread has its dedicated stack. (The stack used during the |
432 | * thread), for a thread has its dedicated stack. (The stack used during the |
432 | * BSP initialization (prior the very first call to scheduler()) will be used |
433 | * BSP initialization (prior the very first call to scheduler()) will be used |
433 | * as an initialization stack for each AP.) |
434 | * as an initialization stack for each AP.) |
434 | */ |
435 | */ |
435 | void kmp(void *arg) |
436 | void kmp(void *arg) |
436 | { |
437 | { |
437 | struct __processor_entry *pr; |
438 | struct __processor_entry *pr; |
438 | __address src, dst; |
439 | __address src, dst; |
439 | __address frame; |
440 | __address frame; |
440 | int i; |
441 | int i; |
441 | 442 | ||
442 | waitq_initialize(&ap_completion_wq); |
443 | waitq_initialize(&ap_completion_wq); |
443 | 444 | ||
444 | /* |
445 | /* |
445 | * Processor entries immediately follow the configuration table header. |
446 | * Processor entries immediately follow the configuration table header. |
446 | */ |
447 | */ |
447 | pr = processor_entries; |
448 | pr = processor_entries; |
448 | 449 | ||
449 | /* |
450 | /* |
450 | * Grab a frame and map its address to page 0. This is a hack which |
451 | * Grab a frame and map its address to page 0. This is a hack which |
451 | * accesses data in frame 0. Note that page 0 is not present because |
452 | * accesses data in frame 0. Note that page 0 is not present because |
452 | * of nil reference bug catching. |
453 | * of nil reference bug catching. |
453 | */ |
454 | */ |
454 | frame = frame_alloc(FRAME_KA); |
455 | frame = frame_alloc(FRAME_KA); |
455 | map_page_to_frame(frame,0,PAGE_CACHEABLE,0); |
456 | map_page_to_frame(frame,0,PAGE_CACHEABLE,0); |
456 | 457 | ||
457 | /* |
458 | /* |
458 | * Set the warm-reset vector to the real-mode address of 4K-aligned ap_boot() |
459 | * Set the warm-reset vector to the real-mode address of 4K-aligned ap_boot() |
459 | */ |
460 | */ |
460 | *((__u16 *) (frame + 0x467+0)) = ((__address) ap_boot) >> 4; /* segment */ |
461 | *((__u16 *) (frame + 0x467+0)) = ((__address) ap_boot) >> 4; /* segment */ |
461 | *((__u16 *) (frame + 0x467+2)) = 0x0; /* offset */ |
462 | *((__u16 *) (frame + 0x467+2)) = 0x0; /* offset */ |
462 | 463 | ||
463 | /* |
464 | /* |
464 | * Give back the borrowed frame and restore identity mapping for it. |
465 | * Give back the borrowed frame and restore identity mapping for it. |
465 | */ |
466 | */ |
466 | map_page_to_frame(frame,frame,PAGE_CACHEABLE,0); |
467 | map_page_to_frame(frame,frame,PAGE_CACHEABLE,0); |
467 | frame_free(frame); |
468 | frame_free(frame); |
468 | 469 | ||
469 | /* |
470 | /* |
470 | * Save 0xa to address 0xf of the CMOS RAM. |
471 | * Save 0xa to address 0xf of the CMOS RAM. |
471 | * BIOS will not do the POST after the INIT signal. |
472 | * BIOS will not do the POST after the INIT signal. |
472 | */ |
473 | */ |
473 | outb(0x70,0xf); |
474 | outb(0x70,0xf); |
474 | outb(0x71,0xa); |
475 | outb(0x71,0xa); |
475 | 476 | ||
476 | cpu_priority_high(); |
477 | cpu_priority_high(); |
477 | 478 | ||
478 | pic_disable_irqs(0xffff); |
479 | pic_disable_irqs(0xffff); |
479 | apic_init(); |
480 | apic_init(); |
480 | 481 | ||
481 | for (i = 0; i < processor_entry_cnt; i++) { |
482 | for (i = 0; i < processor_entry_cnt; i++) { |
482 | struct descriptor *gdt_new; |
483 | struct descriptor *gdt_new; |
483 | 484 | ||
484 | /* |
485 | /* |
485 | * Skip processors marked unusable. |
486 | * Skip processors marked unusable. |
486 | */ |
487 | */ |
487 | if (pr[i].cpu_flags & (1<<0) == 0) |
488 | if (pr[i].cpu_flags & (1<<0) == 0) |
488 | continue; |
489 | continue; |
489 | 490 | ||
490 | /* |
491 | /* |
491 | * The bootstrap processor is already up. |
492 | * The bootstrap processor is already up. |
492 | */ |
493 | */ |
493 | if (pr[i].cpu_flags & (1<<1)) |
494 | if (pr[i].cpu_flags & (1<<1)) |
494 | continue; |
495 | continue; |
495 | 496 | ||
496 | if (pr[i].l_apic_id == l_apic_id()) { |
497 | if (pr[i].l_apic_id == l_apic_id()) { |
497 | printf("%L: bad processor entry #%d, will not send IPI to myself\n", &pr[i], i); |
498 | printf("%L: bad processor entry #%d, will not send IPI to myself\n", &pr[i], i); |
498 | continue; |
499 | continue; |
499 | } |
500 | } |
500 | 501 | ||
501 | /* |
502 | /* |
502 | * Prepare new GDT for CPU in question. |
503 | * Prepare new GDT for CPU in question. |
503 | */ |
504 | */ |
504 | if (!(gdt_new = (struct descriptor *) malloc(GDT_ITEMS*sizeof(struct descriptor)))) |
505 | if (!(gdt_new = (struct descriptor *) malloc(GDT_ITEMS*sizeof(struct descriptor)))) |
505 | panic(PANIC "couldn't allocate memory for GDT\n"); |
506 | panic(PANIC "couldn't allocate memory for GDT\n"); |
506 | 507 | ||
507 | memcopy(gdt, gdt_new, GDT_ITEMS*sizeof(struct descriptor)); |
508 | memcopy(gdt, gdt_new, GDT_ITEMS*sizeof(struct descriptor)); |
508 | gdtr.base = (__address) gdt_new; |
509 | gdtr.base = (__address) gdt_new; |
509 | 510 | ||
510 | if (l_apic_send_init_ipi(pr[i].l_apic_id)) { |
511 | if (l_apic_send_init_ipi(pr[i].l_apic_id)) { |
511 | /* |
512 | /* |
512 | * There may be just one AP being initialized at |
513 | * There may be just one AP being initialized at |
513 | * the time. After it comes completely up, it is |
514 | * the time. After it comes completely up, it is |
514 | * supposed to wake us up. |
515 | * supposed to wake us up. |
515 | */ |
516 | */ |
516 | waitq_sleep(&ap_completion_wq); |
517 | waitq_sleep(&ap_completion_wq); |
517 | cpu_priority_high(); |
518 | cpu_priority_high(); |
518 | } |
519 | } |
519 | else { |
520 | else { |
520 | printf("INIT IPI for l_apic%d failed\n", pr[i].l_apic_id); |
521 | printf("INIT IPI for l_apic%d failed\n", pr[i].l_apic_id); |
521 | } |
522 | } |
522 | } |
523 | } |
523 | 524 | ||
524 | /* |
525 | /* |
525 | * Wakeup the kinit thread so that |
526 | * Wakeup the kinit thread so that |
526 | * system initialization can go on. |
527 | * system initialization can go on. |
527 | */ |
528 | */ |
528 | waitq_wakeup(&kmp_completion_wq, WAKEUP_FIRST); |
529 | waitq_wakeup(&kmp_completion_wq, WAKEUP_FIRST); |
529 | } |
530 | } |
530 | 531 | ||
531 | int mp_irq_to_pin(int irq) |
532 | int mp_irq_to_pin(int irq) |
532 | { |
533 | { |
533 | int i; |
534 | int i; |
534 | 535 | ||
535 | for(i=0;i<io_intr_entry_cnt;i++) { |
536 | for(i=0;i<io_intr_entry_cnt;i++) { |
536 | if (io_intr_entries[i].src_bus_irq == irq && io_intr_entries[i].intr_type == 0) |
537 | if (io_intr_entries[i].src_bus_irq == irq && io_intr_entries[i].intr_type == 0) |
537 | return io_intr_entries[i].dst_io_apic_pin; |
538 | return io_intr_entries[i].dst_io_apic_pin; |
538 | } |
539 | } |
539 | 540 | ||
540 | return -1; |
541 | return -1; |
541 | } |
542 | } |
542 | 543 | ||
543 | #endif /* __SMP__ */ |
544 | #endif /* __SMP__ */ |
544 | 545 |