x86: Unify 3 similar ways of saving mp_irqs info
[deliverable/linux.git] / arch / x86 / kernel / mpparse.c
CommitLineData
1da177e4 1/*
11113f84 2 * Intel Multiprocessor Specification 1.1 and 1.4
1da177e4
LT
3 * compliant MP-table parsing routines.
4 *
87c6fe26 5 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
8f47e163 6 * (c) 1998, 1999, 2000, 2009 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>
72d7c3b3 14#include <linux/memblock.h>
1da177e4
LT
15#include <linux/kernel_stat.h>
16#include <linux/mc146818rtc.h>
17#include <linux/bitops.h>
85bdddec
AS
18#include <linux/acpi.h>
19#include <linux/module.h>
103ceffb 20#include <linux/smp.h>
629e15d2 21#include <linux/pci.h>
1da177e4 22
1da177e4
LT
23#include <asm/mtrr.h>
24#include <asm/mpspec.h>
85bdddec 25#include <asm/pgalloc.h>
1da177e4 26#include <asm/io_apic.h>
85bdddec 27#include <asm/proto.h>
ce3fe6b2 28#include <asm/bios_ebda.h>
2944e16b
YL
29#include <asm/e820.h>
30#include <asm/trampoline.h>
3c9cb6de 31#include <asm/setup.h>
4884d8e6 32#include <asm/smp.h>
1da177e4 33
7b6aa335 34#include <asm/apic.h>
1da177e4
LT
35/*
36 * Checksum an MP configuration block.
37 */
38
39static int __init mpf_checksum(unsigned char *mp, int len)
40{
41 int sum = 0;
42
43 while (len--)
44 sum += *mp++;
45
46 return sum & 0xFF;
47}
48
fd6c6661
TG
49int __init default_mpc_apic_id(struct mpc_cpu *m)
50{
51 return m->apicid;
52}
53
f4f21b71 54static void __init MP_processor_info(struct mpc_cpu *m)
c853c676
AS
55{
56 int apicid;
746f2244 57 char *bootup_cpu = "";
c853c676 58
c4563826 59 if (!(m->cpuflag & CPU_ENABLED)) {
7b1292e2 60 disabled_cpus++;
1da177e4 61 return;
7b1292e2 62 }
64898a8b 63
fd6c6661 64 apicid = x86_init.mpparse.mpc_apic_id(m);
64898a8b 65
c4563826 66 if (m->cpuflag & CPU_BOOTPROCESSOR) {
746f2244 67 bootup_cpu = " (Bootup-CPU)";
c4563826 68 boot_cpu_physical_apicid = m->apicid;
1da177e4
LT
69 }
70
c4563826
JSR
71 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
72 generic_processor_info(apicid, m->apicver);
1da177e4
LT
73}
74
85cc35fa 75#ifdef CONFIG_X86_IO_APIC
90e1c696 76void __init default_mpc_oem_bus_info(struct mpc_bus *m, char *str)
1da177e4 77{
d4c715fa 78 memcpy(str, m->bustype, 6);
1da177e4 79 str[6] = 0;
90e1c696
TG
80 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
81}
1da177e4 82
90e1c696
TG
83static void __init MP_bus_info(struct mpc_bus *m)
84{
85 char str[7];
1da177e4 86
90e1c696 87 x86_init.mpparse.mpc_oem_bus_info(m, str);
1da177e4 88
5e4edbb7 89#if MAX_MP_BUSSES < 256
d4c715fa 90 if (m->busid >= MAX_MP_BUSSES) {
c0ec31ad 91 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
4ef81297 92 " is too large, max. supported is %d\n",
d4c715fa 93 m->busid, str, MAX_MP_BUSSES - 1);
c0ec31ad
RD
94 return;
95 }
5e4edbb7 96#endif
c0ec31ad 97
f8924e77 98 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
d4c715fa 99 set_bit(m->busid, mp_bus_not_pci);
103ceffb 100#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
d4c715fa 101 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
f8924e77
AS
102#endif
103 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
52fdb568
TG
104 if (x86_init.mpparse.mpc_oem_pci_bus)
105 x86_init.mpparse.mpc_oem_pci_bus(m);
64898a8b 106
d4c715fa 107 clear_bit(m->busid, mp_bus_not_pci);
103ceffb 108#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
d4c715fa 109 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
4ef81297 110 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
d4c715fa 111 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
4ef81297 112 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
d4c715fa 113 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
c0a282c2 114#endif
f8924e77
AS
115 } else
116 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
1da177e4 117}
61048c63 118
2b85b5fb 119static void __init MP_ioapic_info(struct mpc_ioapic *m)
1da177e4 120{
5df82c7d 121 if (!(m->flags & MPC_APIC_USABLE))
1da177e4
LT
122 return;
123
64883ab0 124 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
5df82c7d 125 m->apicid, m->apicver, m->apicaddr);
857033a6 126
a4384df3 127 mp_register_ioapic(m->apicid, m->apicaddr, gsi_top);
1da177e4
LT
128}
129
540d4e72 130static void print_MP_intsrc_info(struct mpc_intsrc *m)
1da177e4 131{
eeb0d7d1 132 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
1da177e4 133 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
e253b396
JSR
134 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
135 m->srcbusirq, m->dstapic, m->dstirq);
2944e16b
YL
136}
137
c2c21745 138static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
2944e16b 139{
eeb0d7d1 140 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
2944e16b 141 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
c2c21745
JSR
142 mp_irq->irqtype, mp_irq->irqflag & 3,
143 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
144 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
2944e16b
YL
145}
146
c2c21745 147static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
540d4e72 148 struct mpc_intsrc *m)
2944e16b 149{
c2c21745
JSR
150 m->dstapic = mp_irq->dstapic;
151 m->type = mp_irq->type;
152 m->irqtype = mp_irq->irqtype;
153 m->irqflag = mp_irq->irqflag;
154 m->srcbus = mp_irq->srcbus;
155 m->srcbusirq = mp_irq->srcbusirq;
156 m->dstirq = mp_irq->dstirq;
2944e16b 157}
a6830278
JSR
158#else /* CONFIG_X86_IO_APIC */
159static inline void __init MP_bus_info(struct mpc_bus *m) {}
160static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
a6830278 161#endif /* CONFIG_X86_IO_APIC */
1da177e4 162
61048c63 163
8fb2952b 164static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
1da177e4 165{
eeb0d7d1 166 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
1da177e4 167 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
b5ced7cd
JSR
168 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
169 m->srcbusirq, m->destapic, m->destapiclint);
1da177e4
LT
170}
171
1da177e4
LT
172/*
173 * Read/parse the MPC
174 */
175
f29521e4 176static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
1da177e4 177{
1da177e4 178
6c65da50 179 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
e950bea8 180 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
6c65da50
JSR
181 mpc->signature[0], mpc->signature[1],
182 mpc->signature[2], mpc->signature[3]);
1da177e4
LT
183 return 0;
184 }
6c65da50 185 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
e950bea8 186 printk(KERN_ERR "MPTABLE: checksum error!\n");
1da177e4
LT
187 return 0;
188 }
6c65da50 189 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
e950bea8 190 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
6c65da50 191 mpc->spec);
1da177e4
LT
192 return 0;
193 }
6c65da50 194 if (!mpc->lapic) {
e950bea8 195 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
1da177e4
LT
196 return 0;
197 }
6c65da50 198 memcpy(oem, mpc->oem, 8);
4ef81297 199 oem[8] = 0;
11a62a05 200 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
1da177e4 201
6c65da50 202 memcpy(str, mpc->productid, 12);
4ef81297 203 str[12] = 0;
1da177e4 204
11a62a05 205 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
1da177e4 206
6c65da50 207 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
1da177e4 208
2944e16b
YL
209 return 1;
210}
211
a6830278
JSR
212static void skip_entry(unsigned char **ptr, int *count, int size)
213{
214 *ptr += size;
215 *count += size;
216}
217
5a5737ea
JSR
218static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
219{
220 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
221 "type %x\n", *mpt);
222 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
223 1, mpc, mpc->length, 1);
224}
225
72302142
TG
226void __init default_smp_read_mpc_oem(struct mpc_table *mpc) { }
227
f29521e4 228static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
2944e16b
YL
229{
230 char str[16];
231 char oem[10];
232
233 int count = sizeof(*mpc);
234 unsigned char *mpt = ((unsigned char *)mpc) + count;
235
236 if (!smp_check_mpc(mpc, oem, str))
237 return 0;
238
239#ifdef CONFIG_X86_32
9c764247 240 generic_mps_oem_check(mpc, oem, str);
2944e16b 241#endif
f1157141 242 /* Initialize the lapic mapping */
1da177e4 243 if (!acpi_lapic)
f1157141 244 register_lapic_address(mpc->lapic);
1da177e4 245
888032cd
AS
246 if (early)
247 return 1;
248
72302142
TG
249 if (mpc->oemptr)
250 x86_init.mpparse.smp_read_mpc_oem(mpc);
64898a8b 251
1da177e4 252 /*
4ef81297 253 * Now process the configuration blocks.
1da177e4 254 */
f4848472 255 x86_init.mpparse.mpc_record(0);
64898a8b 256
6c65da50 257 while (count < mpc->length) {
4ef81297
AS
258 switch (*mpt) {
259 case MP_PROCESSOR:
a6830278
JSR
260 /* ACPI may have already provided this data */
261 if (!acpi_lapic)
c58603e8 262 MP_processor_info((struct mpc_cpu *)mpt);
a6830278
JSR
263 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
264 break;
4ef81297 265 case MP_BUS:
c58603e8 266 MP_bus_info((struct mpc_bus *)mpt);
a6830278
JSR
267 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
268 break;
4ef81297 269 case MP_IOAPIC:
c58603e8 270 MP_ioapic_info((struct mpc_ioapic *)mpt);
a6830278
JSR
271 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
272 break;
4ef81297 273 case MP_INTSRC:
2d8009ba 274 mp_save_irq((struct mpc_intsrc *)mpt);
a6830278
JSR
275 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
276 break;
4ef81297 277 case MP_LINTSRC:
c58603e8 278 MP_lintsrc_info((struct mpc_lintsrc *)mpt);
a6830278
JSR
279 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
280 break;
4ef81297 281 default:
711554db 282 /* wrong mptable */
5a5737ea 283 smp_dump_mptable(mpc, mpt);
6c65da50 284 count = mpc->length;
711554db 285 break;
1da177e4 286 }
f4848472 287 x86_init.mpparse.mpc_record(1);
1da177e4 288 }
e0da3364 289
1da177e4 290 if (!num_processors)
e950bea8 291 printk(KERN_ERR "MPTABLE: no processors registered!\n");
1da177e4
LT
292 return num_processors;
293}
294
61048c63
AS
295#ifdef CONFIG_X86_IO_APIC
296
1da177e4
LT
297static int __init ELCR_trigger(unsigned int irq)
298{
299 unsigned int port;
300
301 port = 0x4d0 + (irq >> 3);
302 return (inb(port) >> (irq & 7)) & 1;
303}
304
305static void __init construct_default_ioirq_mptable(int mpc_default_type)
306{
540d4e72 307 struct mpc_intsrc intsrc;
1da177e4
LT
308 int i;
309 int ELCR_fallback = 0;
310
e253b396
JSR
311 intsrc.type = MP_INTSRC;
312 intsrc.irqflag = 0; /* conforming */
313 intsrc.srcbus = 0;
b5ba7e6d 314 intsrc.dstapic = mp_ioapics[0].apicid;
1da177e4 315
e253b396 316 intsrc.irqtype = mp_INT;
1da177e4
LT
317
318 /*
319 * If true, we have an ISA/PCI system with no IRQ entries
320 * in the MP table. To prevent the PCI interrupts from being set up
321 * incorrectly, we try to use the ELCR. The sanity check to see if
322 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
323 * never be level sensitive, so we simply see if the ELCR agrees.
324 * If it does, we assume it's valid.
325 */
326 if (mpc_default_type == 5) {
62441bf1
AS
327 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
328 "falling back to ELCR\n");
1da177e4 329
62441bf1
AS
330 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
331 ELCR_trigger(13))
332 printk(KERN_ERR "ELCR contains invalid data... "
333 "not using ELCR\n");
1da177e4 334 else {
4ef81297
AS
335 printk(KERN_INFO
336 "Using ELCR to identify PCI interrupts\n");
1da177e4
LT
337 ELCR_fallback = 1;
338 }
339 }
340
341 for (i = 0; i < 16; i++) {
342 switch (mpc_default_type) {
343 case 2:
344 if (i == 0 || i == 13)
345 continue; /* IRQ0 & IRQ13 not connected */
346 /* fall through */
347 default:
348 if (i == 2)
349 continue; /* IRQ2 is never connected */
350 }
351
352 if (ELCR_fallback) {
353 /*
354 * If the ELCR indicates a level-sensitive interrupt, we
355 * copy that information over to the MP table in the
356 * irqflag field (level sensitive, active high polarity).
357 */
358 if (ELCR_trigger(i))
e253b396 359 intsrc.irqflag = 13;
1da177e4 360 else
e253b396 361 intsrc.irqflag = 0;
1da177e4
LT
362 }
363
e253b396
JSR
364 intsrc.srcbusirq = i;
365 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
2d8009ba 366 mp_save_irq(&intsrc);
1da177e4
LT
367 }
368
e253b396
JSR
369 intsrc.irqtype = mp_ExtINT;
370 intsrc.srcbusirq = 0;
371 intsrc.dstirq = 0; /* 8259A to INTIN0 */
2d8009ba 372 mp_save_irq(&intsrc);
1da177e4
LT
373}
374
61048c63 375
39e00fe2 376static void __init construct_ioapic_table(int mpc_default_type)
1da177e4 377{
2b85b5fb 378 struct mpc_ioapic ioapic;
00fb8606 379 struct mpc_bus bus;
1da177e4 380
d4c715fa
JSR
381 bus.type = MP_BUS;
382 bus.busid = 0;
1da177e4 383 switch (mpc_default_type) {
4ef81297 384 default:
62441bf1 385 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
4ef81297
AS
386 mpc_default_type);
387 /* fall through */
388 case 1:
389 case 5:
d4c715fa 390 memcpy(bus.bustype, "ISA ", 6);
4ef81297
AS
391 break;
392 case 2:
393 case 6:
394 case 3:
d4c715fa 395 memcpy(bus.bustype, "EISA ", 6);
4ef81297
AS
396 break;
397 case 4:
398 case 7:
d4c715fa 399 memcpy(bus.bustype, "MCA ", 6);
1da177e4
LT
400 }
401 MP_bus_info(&bus);
402 if (mpc_default_type > 4) {
d4c715fa
JSR
403 bus.busid = 1;
404 memcpy(bus.bustype, "PCI ", 6);
1da177e4
LT
405 MP_bus_info(&bus);
406 }
407
8f3e1df4
CG
408 ioapic.type = MP_IOAPIC;
409 ioapic.apicid = 2;
410 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
411 ioapic.flags = MPC_APIC_USABLE;
412 ioapic.apicaddr = IO_APIC_DEFAULT_PHYS_BASE;
1da177e4
LT
413 MP_ioapic_info(&ioapic);
414
415 /*
416 * We set up most of the low 16 IO-APIC pins according to MPS rules.
417 */
418 construct_default_ioirq_mptable(mpc_default_type);
85cc35fa
TG
419}
420#else
39e00fe2 421static inline void __init construct_ioapic_table(int mpc_default_type) { }
61048c63 422#endif
85cc35fa
TG
423
424static inline void __init construct_default_ISA_mptable(int mpc_default_type)
425{
f4f21b71 426 struct mpc_cpu processor;
8fb2952b 427 struct mpc_lintsrc lintsrc;
85cc35fa
TG
428 int linttypes[2] = { mp_ExtINT, mp_NMI };
429 int i;
430
431 /*
432 * local APIC has default address
433 */
434 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
435
436 /*
437 * 2 CPUs, numbered 0 & 1.
438 */
c4563826 439 processor.type = MP_PROCESSOR;
85cc35fa 440 /* Either an integrated APIC or a discrete 82489DX. */
c4563826
JSR
441 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
442 processor.cpuflag = CPU_ENABLED;
443 processor.cpufeature = (boot_cpu_data.x86 << 8) |
85cc35fa 444 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
c4563826
JSR
445 processor.featureflag = boot_cpu_data.x86_capability[0];
446 processor.reserved[0] = 0;
447 processor.reserved[1] = 0;
85cc35fa 448 for (i = 0; i < 2; i++) {
c4563826 449 processor.apicid = i;
85cc35fa
TG
450 MP_processor_info(&processor);
451 }
452
453 construct_ioapic_table(mpc_default_type);
454
b5ced7cd
JSR
455 lintsrc.type = MP_LINTSRC;
456 lintsrc.irqflag = 0; /* conforming */
457 lintsrc.srcbusid = 0;
458 lintsrc.srcbusirq = 0;
459 lintsrc.destapic = MP_APIC_ALL;
1da177e4 460 for (i = 0; i < 2; i++) {
b5ced7cd
JSR
461 lintsrc.irqtype = linttypes[i];
462 lintsrc.destapiclint = i;
1da177e4
LT
463 MP_lintsrc_info(&lintsrc);
464 }
465}
466
41401db6 467static struct mpf_intel *mpf_found;
1da177e4 468
8d4dd919
YL
469static unsigned long __init get_mpc_size(unsigned long physptr)
470{
471 struct mpc_table *mpc;
472 unsigned long size;
473
474 mpc = early_ioremap(physptr, PAGE_SIZE);
475 size = mpc->length;
476 early_iounmap(mpc, PAGE_SIZE);
477 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
478
479 return size;
480}
481
0b3ba0c3
JSR
482static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
483{
484 struct mpc_table *mpc;
485 unsigned long size;
486
487 size = get_mpc_size(mpf->physptr);
488 mpc = early_ioremap(mpf->physptr, size);
489 /*
490 * Read the physical hardware table. Anything here will
491 * override the defaults.
492 */
493 if (!smp_read_mpc(mpc, early)) {
494#ifdef CONFIG_X86_LOCAL_APIC
495 smp_found_config = 0;
496#endif
497 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
498 "... disabling SMP support. (tell your hw vendor)\n");
499 early_iounmap(mpc, size);
500 return -1;
501 }
502 early_iounmap(mpc, size);
503
504 if (early)
505 return -1;
506
507#ifdef CONFIG_X86_IO_APIC
508 /*
509 * If there are no explicit MP IRQ entries, then we are
510 * broken. We set up most of the low 16 IO-APIC pins to
511 * ISA defaults and hope it will work.
512 */
513 if (!mp_irq_entries) {
514 struct mpc_bus bus;
515
516 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
517 "using default mptable. (tell your hw vendor)\n");
518
519 bus.type = MP_BUS;
520 bus.busid = 0;
521 memcpy(bus.bustype, "ISA ", 6);
522 MP_bus_info(&bus);
523
524 construct_default_ioirq_mptable(0);
525 }
526#endif
527
528 return 0;
529}
530
1da177e4
LT
531/*
532 * Scan the memory blocks for an SMP configuration block.
533 */
b3f1b617 534void __init default_get_smp_config(unsigned int early)
1da177e4 535{
41401db6 536 struct mpf_intel *mpf = mpf_found;
1da177e4 537
69b88afa
YL
538 if (!mpf)
539 return;
540
888032cd
AS
541 if (acpi_lapic && early)
542 return;
69b88afa 543
1da177e4 544 /*
69b88afa
YL
545 * MPS doesn't support hyperthreading, aka only have
546 * thread 0 apic id in MPS table
1da177e4 547 */
69b88afa 548 if (acpi_lapic && acpi_ioapic)
1da177e4 549 return;
1da177e4 550
4ef81297 551 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
1eb1b3b6 552 mpf->specification);
b3e24164 553#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
1eb1b3b6 554 if (mpf->feature2 & (1 << 7)) {
1da177e4
LT
555 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
556 pic_mode = 1;
557 } else {
558 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
559 pic_mode = 0;
560 }
4421b1c8 561#endif
1da177e4
LT
562 /*
563 * Now see if we need to read further.
564 */
1eb1b3b6 565 if (mpf->feature1 != 0) {
888032cd
AS
566 if (early) {
567 /*
568 * local APIC has default address
569 */
570 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
571 return;
572 }
1da177e4 573
4ef81297 574 printk(KERN_INFO "Default MP configuration #%d\n",
1eb1b3b6
JSR
575 mpf->feature1);
576 construct_default_ISA_mptable(mpf->feature1);
1da177e4 577
1eb1b3b6 578 } else if (mpf->physptr) {
0b3ba0c3 579 if (check_physptr(mpf, early))
1da177e4 580 return;
1da177e4
LT
581 } else
582 BUG();
583
888032cd
AS
584 if (!early)
585 printk(KERN_INFO "Processors: %d\n", num_processors);
1da177e4
LT
586 /*
587 * Only use the first configuration found.
588 */
589}
590
b24c2a92 591static void __init smp_reserve_memory(struct mpf_intel *mpf)
a6830278
JSR
592{
593 unsigned long size = get_mpc_size(mpf->physptr);
a6830278 594
72d7c3b3 595 memblock_x86_reserve_range(mpf->physptr, mpf->physptr+size, "* MP-table mpc");
a6830278
JSR
596}
597
b24c2a92 598static int __init smp_scan_config(unsigned long base, unsigned long length)
1da177e4 599{
92fd4b7a 600 unsigned int *bp = phys_to_virt(base);
41401db6 601 struct mpf_intel *mpf;
b24c2a92 602 unsigned long mem;
1da177e4 603
eeb0d7d1
RH
604 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
605 bp, length);
5d47a271 606 BUILD_BUG_ON(sizeof(*mpf) != 16);
1da177e4
LT
607
608 while (length > 0) {
41401db6 609 mpf = (struct mpf_intel *)bp;
1da177e4 610 if ((*bp == SMP_MAGIC_IDENT) &&
1eb1b3b6 611 (mpf->length == 1) &&
4ef81297 612 !mpf_checksum((unsigned char *)bp, 16) &&
1eb1b3b6
JSR
613 ((mpf->specification == 1)
614 || (mpf->specification == 4))) {
bab4b27c 615#ifdef CONFIG_X86_LOCAL_APIC
1da177e4 616 smp_found_config = 1;
bab4b27c 617#endif
92fd4b7a 618 mpf_found = mpf;
b1f006b6 619
ba1511bf
JSR
620 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
621 mpf, (u64)virt_to_phys(mpf));
b1f006b6 622
b24c2a92 623 mem = virt_to_phys(mpf);
72d7c3b3 624 memblock_x86_reserve_range(mem, mem + sizeof(*mpf), "* MP-table mpf");
a6830278 625 if (mpf->physptr)
b24c2a92 626 smp_reserve_memory(mpf);
1da177e4 627
d2dbf343 628 return 1;
1da177e4
LT
629 }
630 bp += 4;
631 length -= 16;
632 }
633 return 0;
634}
635
b24c2a92 636void __init default_find_smp_config(void)
1da177e4
LT
637{
638 unsigned int address;
639
640 /*
641 * FIXME: Linux assumes you have 640K of base ram..
642 * this continues the error...
643 *
644 * 1) Scan the bottom 1K for a signature
645 * 2) Scan the top 1K of base RAM
646 * 3) Scan the 64K of bios
647 */
b24c2a92
YL
648 if (smp_scan_config(0x0, 0x400) ||
649 smp_scan_config(639 * 0x400, 0x400) ||
650 smp_scan_config(0xF0000, 0x10000))
1da177e4
LT
651 return;
652 /*
653 * If it is an SMP machine we should know now, unless the
654 * configuration is in an EISA/MCA bus machine with an
655 * extended bios data area.
656 *
657 * there is a real-mode segmented pointer pointing to the
658 * 4K EBDA area at 0x40E, calculate and scan it here.
659 *
660 * NOTE! There are Linux loaders that will corrupt the EBDA
661 * area, and as such this kind of SMP config may be less
662 * trustworthy, simply because the SMP table may have been
663 * stomped on during early boot. These loaders are buggy and
664 * should be fixed.
665 *
666 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
667 */
668
669 address = get_bios_ebda();
670 if (address)
b24c2a92 671 smp_scan_config(address, 0x400);
888032cd
AS
672}
673
2944e16b
YL
674#ifdef CONFIG_X86_IO_APIC
675static u8 __initdata irq_used[MAX_IRQ_SOURCES];
676
540d4e72 677static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
2944e16b
YL
678{
679 int i;
680
e253b396 681 if (m->irqtype != mp_INT)
2944e16b
YL
682 return 0;
683
e253b396 684 if (m->irqflag != 0x0f)
2944e16b
YL
685 return 0;
686
687 /* not legacy */
688
689 for (i = 0; i < mp_irq_entries; i++) {
c2c21745 690 if (mp_irqs[i].irqtype != mp_INT)
2944e16b
YL
691 continue;
692
c2c21745 693 if (mp_irqs[i].irqflag != 0x0f)
2944e16b
YL
694 continue;
695
c2c21745 696 if (mp_irqs[i].srcbus != m->srcbus)
2944e16b 697 continue;
c2c21745 698 if (mp_irqs[i].srcbusirq != m->srcbusirq)
2944e16b
YL
699 continue;
700 if (irq_used[i]) {
701 /* already claimed */
702 return -2;
703 }
704 irq_used[i] = 1;
705 return i;
706 }
707
708 /* not found */
709 return -1;
710}
711
712#define SPARE_SLOT_NUM 20
713
540d4e72 714static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
a6830278 715
57592224 716static void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
a6830278
JSR
717{
718 int i;
719
720 apic_printk(APIC_VERBOSE, "OLD ");
721 print_MP_intsrc_info(m);
722
723 i = get_MP_intsrc_index(m);
724 if (i > 0) {
725 assign_to_mpc_intsrc(&mp_irqs[i], m);
726 apic_printk(APIC_VERBOSE, "NEW ");
727 print_mp_irq_info(&mp_irqs[i]);
728 return;
729 }
730 if (!i) {
731 /* legacy, do nothing */
732 return;
733 }
734 if (*nr_m_spare < SPARE_SLOT_NUM) {
735 /*
736 * not found (-1), or duplicated (-2) are invalid entries,
737 * we need to use the slot later
738 */
739 m_spare[*nr_m_spare] = m;
740 *nr_m_spare += 1;
741 }
742}
743#else /* CONFIG_X86_IO_APIC */
57592224
RM
744static
745inline void __init check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
a6830278
JSR
746#endif /* CONFIG_X86_IO_APIC */
747
ee214558
YL
748static int
749check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length, int count)
a6830278 750{
ee214558
YL
751 int ret = 0;
752
753 if (!mpc_new_phys || count <= mpc_new_length) {
754 WARN(1, "update_mptable: No spare slots (length: %x)\n", count);
755 return -1;
a6830278
JSR
756 }
757
ee214558 758 return ret;
a6830278 759}
2944e16b 760
f29521e4 761static int __init replace_intsrc_all(struct mpc_table *mpc,
2944e16b
YL
762 unsigned long mpc_new_phys,
763 unsigned long mpc_new_length)
764{
765#ifdef CONFIG_X86_IO_APIC
766 int i;
2944e16b 767#endif
2944e16b 768 int count = sizeof(*mpc);
a6830278 769 int nr_m_spare = 0;
2944e16b
YL
770 unsigned char *mpt = ((unsigned char *)mpc) + count;
771
6c65da50
JSR
772 printk(KERN_INFO "mpc_length %x\n", mpc->length);
773 while (count < mpc->length) {
2944e16b
YL
774 switch (*mpt) {
775 case MP_PROCESSOR:
a6830278
JSR
776 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
777 break;
2944e16b 778 case MP_BUS:
a6830278
JSR
779 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
780 break;
2944e16b 781 case MP_IOAPIC:
a6830278
JSR
782 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
783 break;
2944e16b 784 case MP_INTSRC:
c58603e8 785 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
a6830278
JSR
786 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
787 break;
2944e16b 788 case MP_LINTSRC:
a6830278
JSR
789 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
790 break;
2944e16b
YL
791 default:
792 /* wrong mptable */
5a5737ea 793 smp_dump_mptable(mpc, mpt);
2944e16b
YL
794 goto out;
795 }
796 }
797
798#ifdef CONFIG_X86_IO_APIC
799 for (i = 0; i < mp_irq_entries; i++) {
800 if (irq_used[i])
801 continue;
802
c2c21745 803 if (mp_irqs[i].irqtype != mp_INT)
2944e16b
YL
804 continue;
805
c2c21745 806 if (mp_irqs[i].irqflag != 0x0f)
2944e16b
YL
807 continue;
808
809 if (nr_m_spare > 0) {
82034d6f 810 apic_printk(APIC_VERBOSE, "*NEW* found\n");
2944e16b
YL
811 nr_m_spare--;
812 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
813 m_spare[nr_m_spare] = NULL;
814 } else {
540d4e72
JSR
815 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
816 count += sizeof(struct mpc_intsrc);
ee214558 817 if (check_slot(mpc_new_phys, mpc_new_length, count) < 0)
a6830278 818 goto out;
2944e16b 819 assign_to_mpc_intsrc(&mp_irqs[i], m);
6c65da50 820 mpc->length = count;
540d4e72 821 mpt += sizeof(struct mpc_intsrc);
2944e16b
YL
822 }
823 print_mp_irq_info(&mp_irqs[i]);
824 }
825#endif
826out:
827 /* update checksum */
6c65da50
JSR
828 mpc->checksum = 0;
829 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
2944e16b
YL
830
831 return 0;
832}
833
f1bdb523 834int enable_update_mptable;
fcfa146e 835
2944e16b
YL
836static int __init update_mptable_setup(char *str)
837{
838 enable_update_mptable = 1;
629e15d2
YL
839#ifdef CONFIG_PCI
840 pci_routeirq = 1;
841#endif
2944e16b
YL
842 return 0;
843}
844early_param("update_mptable", update_mptable_setup);
845
846static unsigned long __initdata mpc_new_phys;
847static unsigned long mpc_new_length __initdata = 4096;
848
849/* alloc_mptable or alloc_mptable=4k */
850static int __initdata alloc_mptable;
851static int __init parse_alloc_mptable_opt(char *p)
852{
853 enable_update_mptable = 1;
629e15d2
YL
854#ifdef CONFIG_PCI
855 pci_routeirq = 1;
856#endif
2944e16b
YL
857 alloc_mptable = 1;
858 if (!p)
859 return 0;
860 mpc_new_length = memparse(p, &p);
861 return 0;
862}
863early_param("alloc_mptable", parse_alloc_mptable_opt);
864
865void __init early_reserve_e820_mpc_new(void)
866{
867 if (enable_update_mptable && alloc_mptable) {
868 u64 startt = 0;
2944e16b
YL
869 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
870 }
871}
872
873static int __init update_mp_table(void)
874{
875 char str[16];
876 char oem[10];
41401db6 877 struct mpf_intel *mpf;
f29521e4 878 struct mpc_table *mpc, *mpc_new;
2944e16b
YL
879
880 if (!enable_update_mptable)
881 return 0;
882
883 mpf = mpf_found;
884 if (!mpf)
885 return 0;
886
887 /*
888 * Now see if we need to go further.
889 */
1eb1b3b6 890 if (mpf->feature1 != 0)
2944e16b
YL
891 return 0;
892
1eb1b3b6 893 if (!mpf->physptr)
2944e16b
YL
894 return 0;
895
1eb1b3b6 896 mpc = phys_to_virt(mpf->physptr);
2944e16b
YL
897
898 if (!smp_check_mpc(mpc, oem, str))
899 return 0;
900
ba1511bf 901 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
1eb1b3b6 902 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
2944e16b 903
6c65da50 904 if (mpc_new_phys && mpc->length > mpc_new_length) {
2944e16b
YL
905 mpc_new_phys = 0;
906 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
907 mpc_new_length);
908 }
909
910 if (!mpc_new_phys) {
911 unsigned char old, new;
912 /* check if we can change the postion */
6c65da50
JSR
913 mpc->checksum = 0;
914 old = mpf_checksum((unsigned char *)mpc, mpc->length);
915 mpc->checksum = 0xff;
916 new = mpf_checksum((unsigned char *)mpc, mpc->length);
2944e16b
YL
917 if (old == new) {
918 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
919 return 0;
920 }
921 printk(KERN_INFO "use in-positon replacing\n");
922 } else {
1eb1b3b6 923 mpf->physptr = mpc_new_phys;
2944e16b 924 mpc_new = phys_to_virt(mpc_new_phys);
6c65da50 925 memcpy(mpc_new, mpc, mpc->length);
2944e16b
YL
926 mpc = mpc_new;
927 /* check if we can modify that */
1eb1b3b6 928 if (mpc_new_phys - mpf->physptr) {
41401db6 929 struct mpf_intel *mpf_new;
2944e16b
YL
930 /* steal 16 bytes from [0, 1k) */
931 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
932 mpf_new = phys_to_virt(0x400 - 16);
933 memcpy(mpf_new, mpf, 16);
934 mpf = mpf_new;
1eb1b3b6 935 mpf->physptr = mpc_new_phys;
2944e16b 936 }
1eb1b3b6
JSR
937 mpf->checksum = 0;
938 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
939 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
2944e16b
YL
940 }
941
942 /*
943 * only replace the one with mp_INT and
944 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
945 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
946 * may need pci=routeirq for all coverage
947 */
948 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
949
950 return 0;
951}
952
953late_initcall(update_mp_table);
This page took 0.557203 seconds and 5 git commands to generate.