]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
11113f84 | 2 | * Intel Multiprocessor Specification 1.1 and 1.4 |
1da177e4 LT |
3 | * compliant MP-table parsing routines. |
4 | * | |
5 | * (c) 1995 Alan Cox, Building #3 <alan@redhat.com> | |
6 | * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com> | |
85bdddec | 7 | * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de> |
1da177e4 LT |
8 | */ |
9 | ||
10 | #include <linux/mm.h> | |
1da177e4 | 11 | #include <linux/init.h> |
1da177e4 | 12 | #include <linux/delay.h> |
1da177e4 | 13 | #include <linux/bootmem.h> |
1da177e4 LT |
14 | #include <linux/kernel_stat.h> |
15 | #include <linux/mc146818rtc.h> | |
16 | #include <linux/bitops.h> | |
85bdddec AS |
17 | #include <linux/acpi.h> |
18 | #include <linux/module.h> | |
1da177e4 LT |
19 | |
20 | #include <asm/smp.h> | |
1da177e4 LT |
21 | #include <asm/mtrr.h> |
22 | #include <asm/mpspec.h> | |
85bdddec | 23 | #include <asm/pgalloc.h> |
1da177e4 | 24 | #include <asm/io_apic.h> |
85bdddec AS |
25 | #include <asm/proto.h> |
26 | #include <asm/acpi.h> | |
ce3fe6b2 | 27 | #include <asm/bios_ebda.h> |
2944e16b YL |
28 | #include <asm/e820.h> |
29 | #include <asm/trampoline.h> | |
1da177e4 LT |
30 | |
31 | #include <mach_apic.h> | |
85bdddec | 32 | #ifdef CONFIG_X86_32 |
874c4fe3 | 33 | #include <mach_apicdef.h> |
1da177e4 | 34 | #include <mach_mpparse.h> |
85bdddec | 35 | #endif |
1da177e4 | 36 | |
1da177e4 LT |
37 | /* |
38 | * Checksum an MP configuration block. | |
39 | */ | |
40 | ||
41 | static int __init mpf_checksum(unsigned char *mp, int len) | |
42 | { | |
43 | int sum = 0; | |
44 | ||
45 | while (len--) | |
46 | sum += *mp++; | |
47 | ||
48 | return sum & 0xFF; | |
49 | } | |
50 | ||
86420506 | 51 | #ifdef CONFIG_X86_NUMAQ |
d49c4288 | 52 | int found_numaq; |
1da177e4 LT |
53 | /* |
54 | * Have to match translation table entries to main table entries by counter | |
55 | * hence the mpc_record variable .... can't see a less disgusting way of | |
56 | * doing this .... | |
57 | */ | |
d49c4288 YL |
58 | struct mpc_config_translation { |
59 | unsigned char mpc_type; | |
60 | unsigned char trans_len; | |
61 | unsigned char trans_type; | |
62 | unsigned char trans_quad; | |
63 | unsigned char trans_global; | |
64 | unsigned char trans_local; | |
65 | unsigned short trans_reserved; | |
66 | }; | |
67 | ||
1da177e4 | 68 | |
4ef81297 AS |
69 | static int mpc_record; |
70 | static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY] | |
71 | __cpuinitdata; | |
d49c4288 YL |
72 | |
73 | static inline int generate_logical_apicid(int quad, int phys_apicid) | |
74 | { | |
75 | return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1); | |
76 | } | |
77 | ||
78 | ||
79 | static inline int mpc_apic_id(struct mpc_config_processor *m, | |
80 | struct mpc_config_translation *translation_record) | |
81 | { | |
82 | int quad = translation_record->trans_quad; | |
83 | int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid); | |
84 | ||
85 | printk(KERN_DEBUG "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n", | |
86 | m->mpc_apicid, | |
87 | (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8, | |
88 | (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4, | |
89 | m->mpc_apicver, quad, logical_apicid); | |
90 | return logical_apicid; | |
91 | } | |
92 | ||
93 | int mp_bus_id_to_node[MAX_MP_BUSSES]; | |
94 | ||
95 | int mp_bus_id_to_local[MAX_MP_BUSSES]; | |
96 | ||
97 | static void mpc_oem_bus_info(struct mpc_config_bus *m, char *name, | |
98 | struct mpc_config_translation *translation) | |
99 | { | |
100 | int quad = translation->trans_quad; | |
101 | int local = translation->trans_local; | |
102 | ||
103 | mp_bus_id_to_node[m->mpc_busid] = quad; | |
104 | mp_bus_id_to_local[m->mpc_busid] = local; | |
105 | printk(KERN_INFO "Bus #%d is %s (node %d)\n", | |
106 | m->mpc_busid, name, quad); | |
107 | } | |
108 | ||
109 | int quad_local_to_mp_bus_id [NR_CPUS/4][4]; | |
110 | static void mpc_oem_pci_bus(struct mpc_config_bus *m, | |
111 | struct mpc_config_translation *translation) | |
112 | { | |
113 | int quad = translation->trans_quad; | |
114 | int local = translation->trans_local; | |
115 | ||
116 | quad_local_to_mp_bus_id[quad][local] = m->mpc_busid; | |
117 | } | |
118 | ||
86420506 | 119 | #endif |
1da177e4 | 120 | |
c853c676 AS |
121 | static void __cpuinit MP_processor_info(struct mpc_config_processor *m) |
122 | { | |
123 | int apicid; | |
746f2244 | 124 | char *bootup_cpu = ""; |
c853c676 | 125 | |
7b1292e2 GC |
126 | if (!(m->mpc_cpuflag & CPU_ENABLED)) { |
127 | disabled_cpus++; | |
1da177e4 | 128 | return; |
7b1292e2 | 129 | } |
4655c7de | 130 | #ifdef CONFIG_X86_NUMAQ |
ab530e1f YL |
131 | if (found_numaq) |
132 | apicid = mpc_apic_id(m, translation_table[mpc_record]); | |
133 | else | |
134 | apicid = m->mpc_apicid; | |
4655c7de | 135 | #else |
4655c7de AS |
136 | apicid = m->mpc_apicid; |
137 | #endif | |
1da177e4 | 138 | if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) { |
746f2244 | 139 | bootup_cpu = " (Bootup-CPU)"; |
1da177e4 | 140 | boot_cpu_physical_apicid = m->mpc_apicid; |
1da177e4 LT |
141 | } |
142 | ||
746f2244 | 143 | printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu); |
c853c676 | 144 | generic_processor_info(apicid, m->mpc_apicver); |
1da177e4 LT |
145 | } |
146 | ||
85cc35fa | 147 | #ifdef CONFIG_X86_IO_APIC |
4ef81297 | 148 | static void __init MP_bus_info(struct mpc_config_bus *m) |
1da177e4 LT |
149 | { |
150 | char str[7]; | |
1da177e4 LT |
151 | memcpy(str, m->mpc_bustype, 6); |
152 | str[6] = 0; | |
153 | ||
0ec153af | 154 | #ifdef CONFIG_X86_NUMAQ |
ab530e1f YL |
155 | if (found_numaq) |
156 | mpc_oem_bus_info(m, str, translation_table[mpc_record]); | |
0ec153af | 157 | #else |
11a62a05 | 158 | printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str); |
0ec153af | 159 | #endif |
1da177e4 | 160 | |
5e4edbb7 | 161 | #if MAX_MP_BUSSES < 256 |
c0ec31ad RD |
162 | if (m->mpc_busid >= MAX_MP_BUSSES) { |
163 | printk(KERN_WARNING "MP table busid value (%d) for bustype %s " | |
4ef81297 AS |
164 | " is too large, max. supported is %d\n", |
165 | m->mpc_busid, str, MAX_MP_BUSSES - 1); | |
c0ec31ad RD |
166 | return; |
167 | } | |
5e4edbb7 | 168 | #endif |
c0ec31ad | 169 | |
f8924e77 AS |
170 | if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) { |
171 | set_bit(m->mpc_busid, mp_bus_not_pci); | |
172 | #if defined(CONFIG_EISA) || defined (CONFIG_MCA) | |
173 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA; | |
174 | #endif | |
175 | } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) { | |
d285e338 | 176 | #ifdef CONFIG_X86_NUMAQ |
ab530e1f YL |
177 | if (found_numaq) |
178 | mpc_oem_pci_bus(m, translation_table[mpc_record]); | |
d285e338 | 179 | #endif |
a6333c3c | 180 | clear_bit(m->mpc_busid, mp_bus_not_pci); |
c0a282c2 AS |
181 | #if defined(CONFIG_EISA) || defined (CONFIG_MCA) |
182 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI; | |
4ef81297 | 183 | } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) { |
9e0a2de2 | 184 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA; |
4ef81297 | 185 | } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) { |
1da177e4 | 186 | mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA; |
c0a282c2 | 187 | #endif |
f8924e77 AS |
188 | } else |
189 | printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str); | |
1da177e4 | 190 | } |
85cc35fa | 191 | #endif |
1da177e4 | 192 | |
61048c63 AS |
193 | #ifdef CONFIG_X86_IO_APIC |
194 | ||
857033a6 AS |
195 | static int bad_ioapic(unsigned long address) |
196 | { | |
197 | if (nr_ioapics >= MAX_IO_APICS) { | |
198 | printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded " | |
199 | "(found %d)\n", MAX_IO_APICS, nr_ioapics); | |
200 | panic("Recompile kernel with bigger MAX_IO_APICS!\n"); | |
201 | } | |
202 | if (!address) { | |
203 | printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address" | |
204 | " found in table, skipping!\n"); | |
205 | return 1; | |
206 | } | |
207 | return 0; | |
208 | } | |
209 | ||
4ef81297 | 210 | static void __init MP_ioapic_info(struct mpc_config_ioapic *m) |
1da177e4 LT |
211 | { |
212 | if (!(m->mpc_flags & MPC_APIC_USABLE)) | |
213 | return; | |
214 | ||
64883ab0 | 215 | printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n", |
4ef81297 | 216 | m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr); |
857033a6 AS |
217 | |
218 | if (bad_ioapic(m->mpc_apicaddr)) | |
1da177e4 | 219 | return; |
857033a6 | 220 | |
ec2cd0a2 AS |
221 | mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr; |
222 | mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid; | |
223 | mp_ioapics[nr_ioapics].mp_type = m->mpc_type; | |
224 | mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver; | |
225 | mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags; | |
1da177e4 LT |
226 | nr_ioapics++; |
227 | } | |
228 | ||
2944e16b | 229 | static void print_MP_intsrc_info(struct mpc_config_intsrc *m) |
1da177e4 | 230 | { |
2944e16b | 231 | printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x," |
1da177e4 | 232 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", |
4ef81297 AS |
233 | m->mpc_irqtype, m->mpc_irqflag & 3, |
234 | (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus, | |
235 | m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq); | |
2944e16b YL |
236 | } |
237 | ||
238 | static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq) | |
239 | { | |
240 | printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x," | |
241 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", | |
242 | mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3, | |
243 | (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus, | |
244 | mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq); | |
245 | } | |
246 | ||
247 | static void assign_to_mp_irq(struct mpc_config_intsrc *m, | |
248 | struct mp_config_intsrc *mp_irq) | |
249 | { | |
250 | mp_irq->mp_dstapic = m->mpc_dstapic; | |
251 | mp_irq->mp_type = m->mpc_type; | |
252 | mp_irq->mp_irqtype = m->mpc_irqtype; | |
253 | mp_irq->mp_irqflag = m->mpc_irqflag; | |
254 | mp_irq->mp_srcbus = m->mpc_srcbus; | |
255 | mp_irq->mp_srcbusirq = m->mpc_srcbusirq; | |
256 | mp_irq->mp_dstirq = m->mpc_dstirq; | |
257 | } | |
258 | ||
259 | static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq, | |
260 | struct mpc_config_intsrc *m) | |
261 | { | |
262 | m->mpc_dstapic = mp_irq->mp_dstapic; | |
263 | m->mpc_type = mp_irq->mp_type; | |
264 | m->mpc_irqtype = mp_irq->mp_irqtype; | |
265 | m->mpc_irqflag = mp_irq->mp_irqflag; | |
266 | m->mpc_srcbus = mp_irq->mp_srcbus; | |
267 | m->mpc_srcbusirq = mp_irq->mp_srcbusirq; | |
268 | m->mpc_dstirq = mp_irq->mp_dstirq; | |
269 | } | |
270 | ||
271 | static int mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq, | |
272 | struct mpc_config_intsrc *m) | |
273 | { | |
274 | if (mp_irq->mp_dstapic != m->mpc_dstapic) | |
275 | return 1; | |
276 | if (mp_irq->mp_type != m->mpc_type) | |
277 | return 2; | |
278 | if (mp_irq->mp_irqtype != m->mpc_irqtype) | |
279 | return 3; | |
280 | if (mp_irq->mp_irqflag != m->mpc_irqflag) | |
281 | return 4; | |
282 | if (mp_irq->mp_srcbus != m->mpc_srcbus) | |
283 | return 5; | |
284 | if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq) | |
285 | return 6; | |
286 | if (mp_irq->mp_dstirq != m->mpc_dstirq) | |
287 | return 7; | |
288 | ||
289 | return 0; | |
290 | } | |
291 | ||
292 | void MP_intsrc_info(struct mpc_config_intsrc *m) | |
293 | { | |
294 | int i; | |
295 | ||
296 | print_MP_intsrc_info(m); | |
297 | ||
298 | for (i = 0; i < mp_irq_entries; i++) { | |
299 | if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m)) | |
300 | return; | |
301 | } | |
302 | ||
303 | assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]); | |
1da177e4 LT |
304 | if (++mp_irq_entries == MAX_IRQ_SOURCES) |
305 | panic("Max # of irq sources exceeded!!\n"); | |
306 | } | |
307 | ||
61048c63 AS |
308 | #endif |
309 | ||
4ef81297 | 310 | static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m) |
1da177e4 | 311 | { |
11a62a05 | 312 | printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x," |
1da177e4 | 313 | " IRQ %02x, APIC ID %x, APIC LINT %02x\n", |
4ef81297 AS |
314 | m->mpc_irqtype, m->mpc_irqflag & 3, |
315 | (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid, | |
316 | m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint); | |
1da177e4 LT |
317 | } |
318 | ||
319 | #ifdef CONFIG_X86_NUMAQ | |
4ef81297 | 320 | static void __init MP_translation_info(struct mpc_config_translation *m) |
1da177e4 | 321 | { |
4ef81297 AS |
322 | printk(KERN_INFO |
323 | "Translation: record %d, type %d, quad %d, global %d, local %d\n", | |
324 | mpc_record, m->trans_type, m->trans_quad, m->trans_global, | |
325 | m->trans_local); | |
1da177e4 | 326 | |
4ef81297 | 327 | if (mpc_record >= MAX_MPC_ENTRY) |
1da177e4 LT |
328 | printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n"); |
329 | else | |
4ef81297 | 330 | translation_table[mpc_record] = m; /* stash this for later */ |
1da177e4 LT |
331 | if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad)) |
332 | node_set_online(m->trans_quad); | |
333 | } | |
334 | ||
335 | /* | |
336 | * Read/parse the MPC oem tables | |
337 | */ | |
338 | ||
4ef81297 AS |
339 | static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable, |
340 | unsigned short oemsize) | |
1da177e4 | 341 | { |
4ef81297 AS |
342 | int count = sizeof(*oemtable); /* the header size */ |
343 | unsigned char *oemptr = ((unsigned char *)oemtable) + count; | |
344 | ||
1da177e4 | 345 | mpc_record = 0; |
4ef81297 AS |
346 | printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n", |
347 | oemtable); | |
348 | if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) { | |
349 | printk(KERN_WARNING | |
350 | "SMP mpc oemtable: bad signature [%c%c%c%c]!\n", | |
351 | oemtable->oem_signature[0], oemtable->oem_signature[1], | |
352 | oemtable->oem_signature[2], oemtable->oem_signature[3]); | |
1da177e4 LT |
353 | return; |
354 | } | |
4ef81297 | 355 | if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) { |
1da177e4 LT |
356 | printk(KERN_WARNING "SMP oem mptable: checksum error!\n"); |
357 | return; | |
358 | } | |
359 | while (count < oemtable->oem_length) { | |
360 | switch (*oemptr) { | |
4ef81297 | 361 | case MP_TRANSLATION: |
1da177e4 | 362 | { |
4ef81297 AS |
363 | struct mpc_config_translation *m = |
364 | (struct mpc_config_translation *)oemptr; | |
1da177e4 LT |
365 | MP_translation_info(m); |
366 | oemptr += sizeof(*m); | |
367 | count += sizeof(*m); | |
368 | ++mpc_record; | |
369 | break; | |
370 | } | |
4ef81297 | 371 | default: |
1da177e4 | 372 | { |
4ef81297 AS |
373 | printk(KERN_WARNING |
374 | "Unrecognised OEM table entry type! - %d\n", | |
375 | (int)*oemptr); | |
1da177e4 LT |
376 | return; |
377 | } | |
378 | } | |
4ef81297 | 379 | } |
1da177e4 LT |
380 | } |
381 | ||
d49c4288 | 382 | void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem, |
4ef81297 | 383 | char *productid) |
1da177e4 LT |
384 | { |
385 | if (strncmp(oem, "IBM NUMA", 8)) | |
d49c4288 | 386 | printk("Warning! Not a NUMA-Q system!\n"); |
ab530e1f YL |
387 | else |
388 | found_numaq = 1; | |
389 | ||
1da177e4 | 390 | if (mpc->mpc_oemptr) |
4ef81297 AS |
391 | smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr, |
392 | mpc->mpc_oemsize); | |
1da177e4 | 393 | } |
4ef81297 | 394 | #endif /* CONFIG_X86_NUMAQ */ |
1da177e4 LT |
395 | |
396 | /* | |
397 | * Read/parse the MPC | |
398 | */ | |
399 | ||
2944e16b YL |
400 | static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem, |
401 | char *str) | |
1da177e4 | 402 | { |
1da177e4 | 403 | |
4ef81297 | 404 | if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) { |
e950bea8 AS |
405 | printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n", |
406 | mpc->mpc_signature[0], mpc->mpc_signature[1], | |
407 | mpc->mpc_signature[2], mpc->mpc_signature[3]); | |
1da177e4 LT |
408 | return 0; |
409 | } | |
4ef81297 | 410 | if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) { |
e950bea8 | 411 | printk(KERN_ERR "MPTABLE: checksum error!\n"); |
1da177e4 LT |
412 | return 0; |
413 | } | |
4ef81297 | 414 | if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) { |
e950bea8 | 415 | printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n", |
4ef81297 | 416 | mpc->mpc_spec); |
1da177e4 LT |
417 | return 0; |
418 | } | |
419 | if (!mpc->mpc_lapic) { | |
e950bea8 | 420 | printk(KERN_ERR "MPTABLE: null local APIC address!\n"); |
1da177e4 LT |
421 | return 0; |
422 | } | |
4ef81297 AS |
423 | memcpy(oem, mpc->mpc_oem, 8); |
424 | oem[8] = 0; | |
11a62a05 | 425 | printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem); |
1da177e4 | 426 | |
4ef81297 AS |
427 | memcpy(str, mpc->mpc_productid, 12); |
428 | str[12] = 0; | |
1da177e4 | 429 | |
11a62a05 | 430 | printk(KERN_INFO "MPTABLE: Product ID: %s\n", str); |
1da177e4 | 431 | |
e950bea8 | 432 | printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic); |
1da177e4 | 433 | |
2944e16b YL |
434 | return 1; |
435 | } | |
436 | ||
437 | static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early) | |
438 | { | |
439 | char str[16]; | |
440 | char oem[10]; | |
441 | ||
442 | int count = sizeof(*mpc); | |
443 | unsigned char *mpt = ((unsigned char *)mpc) + count; | |
444 | ||
445 | if (!smp_check_mpc(mpc, oem, str)) | |
446 | return 0; | |
447 | ||
448 | #ifdef CONFIG_X86_32 | |
d49c4288 YL |
449 | /* |
450 | * need to make sure summit and es7000's mps_oem_check is safe to be | |
451 | * called early via genericarch 's mps_oem_check | |
452 | */ | |
453 | if (early) { | |
454 | #ifdef CONFIG_X86_NUMAQ | |
455 | numaq_mps_oem_check(mpc, oem, str); | |
456 | #endif | |
457 | } else | |
458 | mps_oem_check(mpc, oem, str); | |
2944e16b YL |
459 | #endif |
460 | ||
e950bea8 | 461 | /* save the local APIC address, it might be non-default */ |
1da177e4 LT |
462 | if (!acpi_lapic) |
463 | mp_lapic_addr = mpc->mpc_lapic; | |
464 | ||
888032cd AS |
465 | if (early) |
466 | return 1; | |
467 | ||
1da177e4 | 468 | /* |
4ef81297 | 469 | * Now process the configuration blocks. |
1da177e4 | 470 | */ |
86420506 | 471 | #ifdef CONFIG_X86_NUMAQ |
1da177e4 | 472 | mpc_record = 0; |
86420506 | 473 | #endif |
1da177e4 | 474 | while (count < mpc->mpc_length) { |
4ef81297 AS |
475 | switch (*mpt) { |
476 | case MP_PROCESSOR: | |
1da177e4 | 477 | { |
4ef81297 AS |
478 | struct mpc_config_processor *m = |
479 | (struct mpc_config_processor *)mpt; | |
1da177e4 LT |
480 | /* ACPI may have already provided this data */ |
481 | if (!acpi_lapic) | |
482 | MP_processor_info(m); | |
483 | mpt += sizeof(*m); | |
484 | count += sizeof(*m); | |
485 | break; | |
486 | } | |
4ef81297 | 487 | case MP_BUS: |
1da177e4 | 488 | { |
4ef81297 AS |
489 | struct mpc_config_bus *m = |
490 | (struct mpc_config_bus *)mpt; | |
85cc35fa | 491 | #ifdef CONFIG_X86_IO_APIC |
1da177e4 | 492 | MP_bus_info(m); |
85cc35fa | 493 | #endif |
1da177e4 LT |
494 | mpt += sizeof(*m); |
495 | count += sizeof(*m); | |
496 | break; | |
497 | } | |
4ef81297 | 498 | case MP_IOAPIC: |
1da177e4 | 499 | { |
61048c63 | 500 | #ifdef CONFIG_X86_IO_APIC |
4ef81297 AS |
501 | struct mpc_config_ioapic *m = |
502 | (struct mpc_config_ioapic *)mpt; | |
1da177e4 | 503 | MP_ioapic_info(m); |
61048c63 | 504 | #endif |
4ef81297 AS |
505 | mpt += sizeof(struct mpc_config_ioapic); |
506 | count += sizeof(struct mpc_config_ioapic); | |
1da177e4 LT |
507 | break; |
508 | } | |
4ef81297 | 509 | case MP_INTSRC: |
1da177e4 | 510 | { |
61048c63 | 511 | #ifdef CONFIG_X86_IO_APIC |
4ef81297 AS |
512 | struct mpc_config_intsrc *m = |
513 | (struct mpc_config_intsrc *)mpt; | |
1da177e4 LT |
514 | |
515 | MP_intsrc_info(m); | |
61048c63 | 516 | #endif |
4ef81297 AS |
517 | mpt += sizeof(struct mpc_config_intsrc); |
518 | count += sizeof(struct mpc_config_intsrc); | |
1da177e4 LT |
519 | break; |
520 | } | |
4ef81297 | 521 | case MP_LINTSRC: |
1da177e4 | 522 | { |
4ef81297 AS |
523 | struct mpc_config_lintsrc *m = |
524 | (struct mpc_config_lintsrc *)mpt; | |
1da177e4 | 525 | MP_lintsrc_info(m); |
4ef81297 AS |
526 | mpt += sizeof(*m); |
527 | count += sizeof(*m); | |
1da177e4 LT |
528 | break; |
529 | } | |
4ef81297 | 530 | default: |
711554db YL |
531 | /* wrong mptable */ |
532 | printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"); | |
533 | printk(KERN_ERR "type %x\n", *mpt); | |
534 | print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16, | |
535 | 1, mpc, mpc->mpc_length, 1); | |
536 | count = mpc->mpc_length; | |
537 | break; | |
1da177e4 | 538 | } |
86420506 | 539 | #ifdef CONFIG_X86_NUMAQ |
1da177e4 | 540 | ++mpc_record; |
86420506 | 541 | #endif |
1da177e4 | 542 | } |
e0da3364 YL |
543 | |
544 | #ifdef CONFIG_X86_GENERICARCH | |
545 | generic_bigsmp_probe(); | |
546 | #endif | |
547 | ||
3c43f039 | 548 | setup_apic_routing(); |
1da177e4 | 549 | if (!num_processors) |
e950bea8 | 550 | printk(KERN_ERR "MPTABLE: no processors registered!\n"); |
1da177e4 LT |
551 | return num_processors; |
552 | } | |
553 | ||
61048c63 AS |
554 | #ifdef CONFIG_X86_IO_APIC |
555 | ||
1da177e4 LT |
556 | static int __init ELCR_trigger(unsigned int irq) |
557 | { | |
558 | unsigned int port; | |
559 | ||
560 | port = 0x4d0 + (irq >> 3); | |
561 | return (inb(port) >> (irq & 7)) & 1; | |
562 | } | |
563 | ||
564 | static void __init construct_default_ioirq_mptable(int mpc_default_type) | |
565 | { | |
566 | struct mpc_config_intsrc intsrc; | |
567 | int i; | |
568 | int ELCR_fallback = 0; | |
569 | ||
570 | intsrc.mpc_type = MP_INTSRC; | |
4ef81297 | 571 | intsrc.mpc_irqflag = 0; /* conforming */ |
1da177e4 | 572 | intsrc.mpc_srcbus = 0; |
ec2cd0a2 | 573 | intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid; |
1da177e4 LT |
574 | |
575 | intsrc.mpc_irqtype = mp_INT; | |
576 | ||
577 | /* | |
578 | * If true, we have an ISA/PCI system with no IRQ entries | |
579 | * in the MP table. To prevent the PCI interrupts from being set up | |
580 | * incorrectly, we try to use the ELCR. The sanity check to see if | |
581 | * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can | |
582 | * never be level sensitive, so we simply see if the ELCR agrees. | |
583 | * If it does, we assume it's valid. | |
584 | */ | |
585 | if (mpc_default_type == 5) { | |
62441bf1 AS |
586 | printk(KERN_INFO "ISA/PCI bus type with no IRQ information... " |
587 | "falling back to ELCR\n"); | |
1da177e4 | 588 | |
62441bf1 AS |
589 | if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || |
590 | ELCR_trigger(13)) | |
591 | printk(KERN_ERR "ELCR contains invalid data... " | |
592 | "not using ELCR\n"); | |
1da177e4 | 593 | else { |
4ef81297 AS |
594 | printk(KERN_INFO |
595 | "Using ELCR to identify PCI interrupts\n"); | |
1da177e4 LT |
596 | ELCR_fallback = 1; |
597 | } | |
598 | } | |
599 | ||
600 | for (i = 0; i < 16; i++) { | |
601 | switch (mpc_default_type) { | |
602 | case 2: | |
603 | if (i == 0 || i == 13) | |
604 | continue; /* IRQ0 & IRQ13 not connected */ | |
605 | /* fall through */ | |
606 | default: | |
607 | if (i == 2) | |
608 | continue; /* IRQ2 is never connected */ | |
609 | } | |
610 | ||
611 | if (ELCR_fallback) { | |
612 | /* | |
613 | * If the ELCR indicates a level-sensitive interrupt, we | |
614 | * copy that information over to the MP table in the | |
615 | * irqflag field (level sensitive, active high polarity). | |
616 | */ | |
617 | if (ELCR_trigger(i)) | |
618 | intsrc.mpc_irqflag = 13; | |
619 | else | |
620 | intsrc.mpc_irqflag = 0; | |
621 | } | |
622 | ||
623 | intsrc.mpc_srcbusirq = i; | |
4ef81297 | 624 | intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */ |
1da177e4 LT |
625 | MP_intsrc_info(&intsrc); |
626 | } | |
627 | ||
628 | intsrc.mpc_irqtype = mp_ExtINT; | |
629 | intsrc.mpc_srcbusirq = 0; | |
4ef81297 | 630 | intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */ |
1da177e4 LT |
631 | MP_intsrc_info(&intsrc); |
632 | } | |
633 | ||
61048c63 | 634 | |
85cc35fa | 635 | static void construct_ioapic_table(int mpc_default_type) |
1da177e4 | 636 | { |
1da177e4 | 637 | struct mpc_config_ioapic ioapic; |
85cc35fa | 638 | struct mpc_config_bus bus; |
1da177e4 LT |
639 | |
640 | bus.mpc_type = MP_BUS; | |
641 | bus.mpc_busid = 0; | |
642 | switch (mpc_default_type) { | |
4ef81297 | 643 | default: |
62441bf1 | 644 | printk(KERN_ERR "???\nUnknown standard configuration %d\n", |
4ef81297 AS |
645 | mpc_default_type); |
646 | /* fall through */ | |
647 | case 1: | |
648 | case 5: | |
649 | memcpy(bus.mpc_bustype, "ISA ", 6); | |
650 | break; | |
651 | case 2: | |
652 | case 6: | |
653 | case 3: | |
654 | memcpy(bus.mpc_bustype, "EISA ", 6); | |
655 | break; | |
656 | case 4: | |
657 | case 7: | |
658 | memcpy(bus.mpc_bustype, "MCA ", 6); | |
1da177e4 LT |
659 | } |
660 | MP_bus_info(&bus); | |
661 | if (mpc_default_type > 4) { | |
662 | bus.mpc_busid = 1; | |
663 | memcpy(bus.mpc_bustype, "PCI ", 6); | |
664 | MP_bus_info(&bus); | |
665 | } | |
666 | ||
667 | ioapic.mpc_type = MP_IOAPIC; | |
668 | ioapic.mpc_apicid = 2; | |
669 | ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01; | |
670 | ioapic.mpc_flags = MPC_APIC_USABLE; | |
671 | ioapic.mpc_apicaddr = 0xFEC00000; | |
672 | MP_ioapic_info(&ioapic); | |
673 | ||
674 | /* | |
675 | * We set up most of the low 16 IO-APIC pins according to MPS rules. | |
676 | */ | |
677 | construct_default_ioirq_mptable(mpc_default_type); | |
85cc35fa TG |
678 | } |
679 | #else | |
680 | static inline void construct_ioapic_table(int mpc_default_type) { } | |
61048c63 | 681 | #endif |
85cc35fa TG |
682 | |
683 | static inline void __init construct_default_ISA_mptable(int mpc_default_type) | |
684 | { | |
685 | struct mpc_config_processor processor; | |
686 | struct mpc_config_lintsrc lintsrc; | |
687 | int linttypes[2] = { mp_ExtINT, mp_NMI }; | |
688 | int i; | |
689 | ||
690 | /* | |
691 | * local APIC has default address | |
692 | */ | |
693 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; | |
694 | ||
695 | /* | |
696 | * 2 CPUs, numbered 0 & 1. | |
697 | */ | |
698 | processor.mpc_type = MP_PROCESSOR; | |
699 | /* Either an integrated APIC or a discrete 82489DX. */ | |
700 | processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01; | |
701 | processor.mpc_cpuflag = CPU_ENABLED; | |
702 | processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) | | |
703 | (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask; | |
704 | processor.mpc_featureflag = boot_cpu_data.x86_capability[0]; | |
705 | processor.mpc_reserved[0] = 0; | |
706 | processor.mpc_reserved[1] = 0; | |
707 | for (i = 0; i < 2; i++) { | |
708 | processor.mpc_apicid = i; | |
709 | MP_processor_info(&processor); | |
710 | } | |
711 | ||
712 | construct_ioapic_table(mpc_default_type); | |
713 | ||
1da177e4 | 714 | lintsrc.mpc_type = MP_LINTSRC; |
4ef81297 | 715 | lintsrc.mpc_irqflag = 0; /* conforming */ |
1da177e4 LT |
716 | lintsrc.mpc_srcbusid = 0; |
717 | lintsrc.mpc_srcbusirq = 0; | |
718 | lintsrc.mpc_destapic = MP_APIC_ALL; | |
719 | for (i = 0; i < 2; i++) { | |
720 | lintsrc.mpc_irqtype = linttypes[i]; | |
721 | lintsrc.mpc_destapiclint = i; | |
722 | MP_lintsrc_info(&lintsrc); | |
723 | } | |
724 | } | |
725 | ||
726 | static struct intel_mp_floating *mpf_found; | |
727 | ||
728 | /* | |
729 | * Scan the memory blocks for an SMP configuration block. | |
730 | */ | |
888032cd | 731 | static void __init __get_smp_config(unsigned early) |
1da177e4 LT |
732 | { |
733 | struct intel_mp_floating *mpf = mpf_found; | |
734 | ||
888032cd AS |
735 | if (acpi_lapic && early) |
736 | return; | |
1da177e4 | 737 | /* |
4ef81297 | 738 | * ACPI supports both logical (e.g. Hyper-Threading) and physical |
1da177e4 LT |
739 | * processors, where MPS only supports physical. |
740 | */ | |
741 | if (acpi_lapic && acpi_ioapic) { | |
4421b1c8 AS |
742 | printk(KERN_INFO "Using ACPI (MADT) for SMP configuration " |
743 | "information\n"); | |
1da177e4 | 744 | return; |
4ef81297 | 745 | } else if (acpi_lapic) |
4421b1c8 AS |
746 | printk(KERN_INFO "Using ACPI for processor (LAPIC) " |
747 | "configuration information\n"); | |
1da177e4 | 748 | |
4ef81297 AS |
749 | printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n", |
750 | mpf->mpf_specification); | |
b3e24164 | 751 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32) |
4ef81297 | 752 | if (mpf->mpf_feature2 & (1 << 7)) { |
1da177e4 LT |
753 | printk(KERN_INFO " IMCR and PIC compatibility mode.\n"); |
754 | pic_mode = 1; | |
755 | } else { | |
756 | printk(KERN_INFO " Virtual Wire compatibility mode.\n"); | |
757 | pic_mode = 0; | |
758 | } | |
4421b1c8 | 759 | #endif |
1da177e4 LT |
760 | /* |
761 | * Now see if we need to read further. | |
762 | */ | |
763 | if (mpf->mpf_feature1 != 0) { | |
888032cd AS |
764 | if (early) { |
765 | /* | |
766 | * local APIC has default address | |
767 | */ | |
768 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; | |
769 | return; | |
770 | } | |
1da177e4 | 771 | |
4ef81297 AS |
772 | printk(KERN_INFO "Default MP configuration #%d\n", |
773 | mpf->mpf_feature1); | |
1da177e4 LT |
774 | construct_default_ISA_mptable(mpf->mpf_feature1); |
775 | ||
776 | } else if (mpf->mpf_physptr) { | |
777 | ||
778 | /* | |
779 | * Read the physical hardware table. Anything here will | |
780 | * override the defaults. | |
781 | */ | |
888032cd | 782 | if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) { |
bab4b27c | 783 | #ifdef CONFIG_X86_LOCAL_APIC |
1da177e4 | 784 | smp_found_config = 0; |
bab4b27c | 785 | #endif |
4ef81297 AS |
786 | printk(KERN_ERR |
787 | "BIOS bug, MP table errors detected!...\n"); | |
4421b1c8 AS |
788 | printk(KERN_ERR "... disabling SMP support. " |
789 | "(tell your hw vendor)\n"); | |
1da177e4 LT |
790 | return; |
791 | } | |
61048c63 | 792 | |
888032cd AS |
793 | if (early) |
794 | return; | |
61048c63 | 795 | #ifdef CONFIG_X86_IO_APIC |
1da177e4 LT |
796 | /* |
797 | * If there are no explicit MP IRQ entries, then we are | |
798 | * broken. We set up most of the low 16 IO-APIC pins to | |
799 | * ISA defaults and hope it will work. | |
800 | */ | |
801 | if (!mp_irq_entries) { | |
802 | struct mpc_config_bus bus; | |
803 | ||
4421b1c8 AS |
804 | printk(KERN_ERR "BIOS bug, no explicit IRQ entries, " |
805 | "using default mptable. " | |
806 | "(tell your hw vendor)\n"); | |
1da177e4 LT |
807 | |
808 | bus.mpc_type = MP_BUS; | |
809 | bus.mpc_busid = 0; | |
810 | memcpy(bus.mpc_bustype, "ISA ", 6); | |
811 | MP_bus_info(&bus); | |
812 | ||
813 | construct_default_ioirq_mptable(0); | |
814 | } | |
61048c63 | 815 | #endif |
1da177e4 LT |
816 | } else |
817 | BUG(); | |
818 | ||
888032cd AS |
819 | if (!early) |
820 | printk(KERN_INFO "Processors: %d\n", num_processors); | |
1da177e4 LT |
821 | /* |
822 | * Only use the first configuration found. | |
823 | */ | |
824 | } | |
825 | ||
888032cd AS |
826 | void __init early_get_smp_config(void) |
827 | { | |
828 | __get_smp_config(1); | |
829 | } | |
830 | ||
831 | void __init get_smp_config(void) | |
832 | { | |
833 | __get_smp_config(0); | |
834 | } | |
835 | ||
836 | static int __init smp_scan_config(unsigned long base, unsigned long length, | |
837 | unsigned reserve) | |
1da177e4 | 838 | { |
92fd4b7a | 839 | unsigned int *bp = phys_to_virt(base); |
1da177e4 LT |
840 | struct intel_mp_floating *mpf; |
841 | ||
11a62a05 | 842 | printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length); |
5d47a271 | 843 | BUILD_BUG_ON(sizeof(*mpf) != 16); |
1da177e4 LT |
844 | |
845 | while (length > 0) { | |
846 | mpf = (struct intel_mp_floating *)bp; | |
847 | if ((*bp == SMP_MAGIC_IDENT) && | |
4ef81297 AS |
848 | (mpf->mpf_length == 1) && |
849 | !mpf_checksum((unsigned char *)bp, 16) && | |
850 | ((mpf->mpf_specification == 1) | |
851 | || (mpf->mpf_specification == 4))) { | |
bab4b27c | 852 | #ifdef CONFIG_X86_LOCAL_APIC |
1da177e4 | 853 | smp_found_config = 1; |
bab4b27c | 854 | #endif |
92fd4b7a AS |
855 | mpf_found = mpf; |
856 | #ifdef CONFIG_X86_32 | |
e91a3b43 | 857 | printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n", |
4ef81297 | 858 | mpf, virt_to_phys(mpf)); |
72a7fe39 BW |
859 | reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE, |
860 | BOOTMEM_DEFAULT); | |
1da177e4 LT |
861 | if (mpf->mpf_physptr) { |
862 | /* | |
863 | * We cannot access to MPC table to compute | |
864 | * table size yet, as only few megabytes from | |
865 | * the bottom is mapped now. | |
866 | * PC-9800's MPC table places on the very last | |
867 | * of physical memory; so that simply reserving | |
868 | * PAGE_SIZE from mpg->mpf_physptr yields BUG() | |
869 | * in reserve_bootmem. | |
870 | */ | |
871 | unsigned long size = PAGE_SIZE; | |
872 | unsigned long end = max_low_pfn * PAGE_SIZE; | |
873 | if (mpf->mpf_physptr + size > end) | |
874 | size = end - mpf->mpf_physptr; | |
72a7fe39 BW |
875 | reserve_bootmem(mpf->mpf_physptr, size, |
876 | BOOTMEM_DEFAULT); | |
1da177e4 LT |
877 | } |
878 | ||
92fd4b7a AS |
879 | #else |
880 | if (!reserve) | |
881 | return 1; | |
882 | ||
8b2ef1d7 BW |
883 | reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE, |
884 | BOOTMEM_DEFAULT); | |
92fd4b7a AS |
885 | if (mpf->mpf_physptr) |
886 | reserve_bootmem_generic(mpf->mpf_physptr, | |
8b2ef1d7 | 887 | PAGE_SIZE, BOOTMEM_DEFAULT); |
92fd4b7a AS |
888 | #endif |
889 | return 1; | |
1da177e4 LT |
890 | } |
891 | bp += 4; | |
892 | length -= 16; | |
893 | } | |
894 | return 0; | |
895 | } | |
896 | ||
888032cd | 897 | static void __init __find_smp_config(unsigned reserve) |
1da177e4 LT |
898 | { |
899 | unsigned int address; | |
900 | ||
901 | /* | |
902 | * FIXME: Linux assumes you have 640K of base ram.. | |
903 | * this continues the error... | |
904 | * | |
905 | * 1) Scan the bottom 1K for a signature | |
906 | * 2) Scan the top 1K of base RAM | |
907 | * 3) Scan the 64K of bios | |
908 | */ | |
888032cd AS |
909 | if (smp_scan_config(0x0, 0x400, reserve) || |
910 | smp_scan_config(639 * 0x400, 0x400, reserve) || | |
911 | smp_scan_config(0xF0000, 0x10000, reserve)) | |
1da177e4 LT |
912 | return; |
913 | /* | |
914 | * If it is an SMP machine we should know now, unless the | |
915 | * configuration is in an EISA/MCA bus machine with an | |
916 | * extended bios data area. | |
917 | * | |
918 | * there is a real-mode segmented pointer pointing to the | |
919 | * 4K EBDA area at 0x40E, calculate and scan it here. | |
920 | * | |
921 | * NOTE! There are Linux loaders that will corrupt the EBDA | |
922 | * area, and as such this kind of SMP config may be less | |
923 | * trustworthy, simply because the SMP table may have been | |
924 | * stomped on during early boot. These loaders are buggy and | |
925 | * should be fixed. | |
926 | * | |
927 | * MP1.4 SPEC states to only scan first 1K of 4K EBDA. | |
928 | */ | |
929 | ||
930 | address = get_bios_ebda(); | |
931 | if (address) | |
888032cd AS |
932 | smp_scan_config(address, 0x400, reserve); |
933 | } | |
934 | ||
935 | void __init early_find_smp_config(void) | |
936 | { | |
937 | __find_smp_config(0); | |
938 | } | |
939 | ||
940 | void __init find_smp_config(void) | |
941 | { | |
942 | __find_smp_config(1); | |
1da177e4 | 943 | } |
2944e16b YL |
944 | |
945 | #ifdef CONFIG_X86_IO_APIC | |
946 | static u8 __initdata irq_used[MAX_IRQ_SOURCES]; | |
947 | ||
948 | static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m) | |
949 | { | |
950 | int i; | |
951 | ||
952 | if (m->mpc_irqtype != mp_INT) | |
953 | return 0; | |
954 | ||
955 | if (m->mpc_irqflag != 0x0f) | |
956 | return 0; | |
957 | ||
958 | /* not legacy */ | |
959 | ||
960 | for (i = 0; i < mp_irq_entries; i++) { | |
961 | if (mp_irqs[i].mp_irqtype != mp_INT) | |
962 | continue; | |
963 | ||
964 | if (mp_irqs[i].mp_irqflag != 0x0f) | |
965 | continue; | |
966 | ||
967 | if (mp_irqs[i].mp_srcbus != m->mpc_srcbus) | |
968 | continue; | |
969 | if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq) | |
970 | continue; | |
971 | if (irq_used[i]) { | |
972 | /* already claimed */ | |
973 | return -2; | |
974 | } | |
975 | irq_used[i] = 1; | |
976 | return i; | |
977 | } | |
978 | ||
979 | /* not found */ | |
980 | return -1; | |
981 | } | |
982 | ||
983 | #define SPARE_SLOT_NUM 20 | |
984 | ||
985 | static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM]; | |
986 | #endif | |
987 | ||
988 | static int __init replace_intsrc_all(struct mp_config_table *mpc, | |
989 | unsigned long mpc_new_phys, | |
990 | unsigned long mpc_new_length) | |
991 | { | |
992 | #ifdef CONFIG_X86_IO_APIC | |
993 | int i; | |
994 | int nr_m_spare = 0; | |
995 | #endif | |
996 | ||
997 | int count = sizeof(*mpc); | |
998 | unsigned char *mpt = ((unsigned char *)mpc) + count; | |
999 | ||
1000 | printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length); | |
1001 | while (count < mpc->mpc_length) { | |
1002 | switch (*mpt) { | |
1003 | case MP_PROCESSOR: | |
1004 | { | |
1005 | struct mpc_config_processor *m = | |
1006 | (struct mpc_config_processor *)mpt; | |
1007 | mpt += sizeof(*m); | |
1008 | count += sizeof(*m); | |
1009 | break; | |
1010 | } | |
1011 | case MP_BUS: | |
1012 | { | |
1013 | struct mpc_config_bus *m = | |
1014 | (struct mpc_config_bus *)mpt; | |
1015 | mpt += sizeof(*m); | |
1016 | count += sizeof(*m); | |
1017 | break; | |
1018 | } | |
1019 | case MP_IOAPIC: | |
1020 | { | |
1021 | mpt += sizeof(struct mpc_config_ioapic); | |
1022 | count += sizeof(struct mpc_config_ioapic); | |
1023 | break; | |
1024 | } | |
1025 | case MP_INTSRC: | |
1026 | { | |
1027 | #ifdef CONFIG_X86_IO_APIC | |
1028 | struct mpc_config_intsrc *m = | |
1029 | (struct mpc_config_intsrc *)mpt; | |
1030 | ||
1031 | printk(KERN_INFO "OLD "); | |
1032 | print_MP_intsrc_info(m); | |
1033 | i = get_MP_intsrc_index(m); | |
1034 | if (i > 0) { | |
1035 | assign_to_mpc_intsrc(&mp_irqs[i], m); | |
1036 | printk(KERN_INFO "NEW "); | |
1037 | print_mp_irq_info(&mp_irqs[i]); | |
1038 | } else if (!i) { | |
1039 | /* legacy, do nothing */ | |
1040 | } else if (nr_m_spare < SPARE_SLOT_NUM) { | |
1041 | /* | |
1042 | * not found (-1), or duplicated (-2) | |
1043 | * are invalid entries, | |
1044 | * we need to use the slot later | |
1045 | */ | |
1046 | m_spare[nr_m_spare] = m; | |
1047 | nr_m_spare++; | |
1048 | } | |
1049 | #endif | |
1050 | mpt += sizeof(struct mpc_config_intsrc); | |
1051 | count += sizeof(struct mpc_config_intsrc); | |
1052 | break; | |
1053 | } | |
1054 | case MP_LINTSRC: | |
1055 | { | |
1056 | struct mpc_config_lintsrc *m = | |
1057 | (struct mpc_config_lintsrc *)mpt; | |
1058 | mpt += sizeof(*m); | |
1059 | count += sizeof(*m); | |
1060 | break; | |
1061 | } | |
1062 | default: | |
1063 | /* wrong mptable */ | |
1064 | printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"); | |
1065 | printk(KERN_ERR "type %x\n", *mpt); | |
1066 | print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16, | |
1067 | 1, mpc, mpc->mpc_length, 1); | |
1068 | goto out; | |
1069 | } | |
1070 | } | |
1071 | ||
1072 | #ifdef CONFIG_X86_IO_APIC | |
1073 | for (i = 0; i < mp_irq_entries; i++) { | |
1074 | if (irq_used[i]) | |
1075 | continue; | |
1076 | ||
1077 | if (mp_irqs[i].mp_irqtype != mp_INT) | |
1078 | continue; | |
1079 | ||
1080 | if (mp_irqs[i].mp_irqflag != 0x0f) | |
1081 | continue; | |
1082 | ||
1083 | if (nr_m_spare > 0) { | |
1084 | printk(KERN_INFO "*NEW* found "); | |
1085 | nr_m_spare--; | |
1086 | assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]); | |
1087 | m_spare[nr_m_spare] = NULL; | |
1088 | } else { | |
1089 | struct mpc_config_intsrc *m = | |
1090 | (struct mpc_config_intsrc *)mpt; | |
1091 | count += sizeof(struct mpc_config_intsrc); | |
1092 | if (!mpc_new_phys) { | |
1093 | printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count); | |
1094 | } else { | |
1095 | if (count <= mpc_new_length) | |
1096 | printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count); | |
1097 | else { | |
1098 | printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length); | |
1099 | goto out; | |
1100 | } | |
1101 | } | |
1102 | assign_to_mpc_intsrc(&mp_irqs[i], m); | |
1103 | mpc->mpc_length = count; | |
1104 | mpt += sizeof(struct mpc_config_intsrc); | |
1105 | } | |
1106 | print_mp_irq_info(&mp_irqs[i]); | |
1107 | } | |
1108 | #endif | |
1109 | out: | |
1110 | /* update checksum */ | |
1111 | mpc->mpc_checksum = 0; | |
1112 | mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc, | |
1113 | mpc->mpc_length); | |
1114 | ||
1115 | return 0; | |
1116 | } | |
1117 | ||
1118 | int __initdata enable_update_mptable; | |
1119 | ||
1120 | static int __init update_mptable_setup(char *str) | |
1121 | { | |
1122 | enable_update_mptable = 1; | |
1123 | return 0; | |
1124 | } | |
1125 | early_param("update_mptable", update_mptable_setup); | |
1126 | ||
1127 | static unsigned long __initdata mpc_new_phys; | |
1128 | static unsigned long mpc_new_length __initdata = 4096; | |
1129 | ||
1130 | /* alloc_mptable or alloc_mptable=4k */ | |
1131 | static int __initdata alloc_mptable; | |
1132 | static int __init parse_alloc_mptable_opt(char *p) | |
1133 | { | |
1134 | enable_update_mptable = 1; | |
1135 | alloc_mptable = 1; | |
1136 | if (!p) | |
1137 | return 0; | |
1138 | mpc_new_length = memparse(p, &p); | |
1139 | return 0; | |
1140 | } | |
1141 | early_param("alloc_mptable", parse_alloc_mptable_opt); | |
1142 | ||
1143 | void __init early_reserve_e820_mpc_new(void) | |
1144 | { | |
1145 | if (enable_update_mptable && alloc_mptable) { | |
1146 | u64 startt = 0; | |
1147 | #ifdef CONFIG_X86_TRAMPOLINE | |
1148 | startt = TRAMPOLINE_BASE; | |
1149 | #endif | |
1150 | mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4); | |
1151 | } | |
1152 | } | |
1153 | ||
1154 | static int __init update_mp_table(void) | |
1155 | { | |
1156 | char str[16]; | |
1157 | char oem[10]; | |
1158 | struct intel_mp_floating *mpf; | |
1159 | struct mp_config_table *mpc; | |
1160 | struct mp_config_table *mpc_new; | |
1161 | ||
1162 | if (!enable_update_mptable) | |
1163 | return 0; | |
1164 | ||
1165 | mpf = mpf_found; | |
1166 | if (!mpf) | |
1167 | return 0; | |
1168 | ||
1169 | /* | |
1170 | * Now see if we need to go further. | |
1171 | */ | |
1172 | if (mpf->mpf_feature1 != 0) | |
1173 | return 0; | |
1174 | ||
1175 | if (!mpf->mpf_physptr) | |
1176 | return 0; | |
1177 | ||
1178 | mpc = phys_to_virt(mpf->mpf_physptr); | |
1179 | ||
1180 | if (!smp_check_mpc(mpc, oem, str)) | |
1181 | return 0; | |
1182 | ||
1183 | printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf)); | |
1184 | printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr); | |
1185 | ||
1186 | if (mpc_new_phys && mpc->mpc_length > mpc_new_length) { | |
1187 | mpc_new_phys = 0; | |
1188 | printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n", | |
1189 | mpc_new_length); | |
1190 | } | |
1191 | ||
1192 | if (!mpc_new_phys) { | |
1193 | unsigned char old, new; | |
1194 | /* check if we can change the postion */ | |
1195 | mpc->mpc_checksum = 0; | |
1196 | old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length); | |
1197 | mpc->mpc_checksum = 0xff; | |
1198 | new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length); | |
1199 | if (old == new) { | |
1200 | printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n"); | |
1201 | return 0; | |
1202 | } | |
1203 | printk(KERN_INFO "use in-positon replacing\n"); | |
1204 | } else { | |
1205 | mpf->mpf_physptr = mpc_new_phys; | |
1206 | mpc_new = phys_to_virt(mpc_new_phys); | |
1207 | memcpy(mpc_new, mpc, mpc->mpc_length); | |
1208 | mpc = mpc_new; | |
1209 | /* check if we can modify that */ | |
1210 | if (mpc_new_phys - mpf->mpf_physptr) { | |
1211 | struct intel_mp_floating *mpf_new; | |
1212 | /* steal 16 bytes from [0, 1k) */ | |
1213 | printk(KERN_INFO "mpf new: %x\n", 0x400 - 16); | |
1214 | mpf_new = phys_to_virt(0x400 - 16); | |
1215 | memcpy(mpf_new, mpf, 16); | |
1216 | mpf = mpf_new; | |
1217 | mpf->mpf_physptr = mpc_new_phys; | |
1218 | } | |
1219 | mpf->mpf_checksum = 0; | |
1220 | mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16); | |
1221 | printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr); | |
1222 | } | |
1223 | ||
1224 | /* | |
1225 | * only replace the one with mp_INT and | |
1226 | * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, | |
1227 | * already in mp_irqs , stored by ... and mp_config_acpi_gsi, | |
1228 | * may need pci=routeirq for all coverage | |
1229 | */ | |
1230 | replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length); | |
1231 | ||
1232 | return 0; | |
1233 | } | |
1234 | ||
1235 | late_initcall(update_mp_table); |