x86: clean up output resulting from update_mptable option
[linux-2.6/next.git] / arch / x86 / kernel / mpparse.c
blob47673e02ae58110709fce90ef77da2a4d5f63b64
1 /*
2 * Intel Multiprocessor Specification 1.1 and 1.4
3 * compliant MP-table parsing routines.
5 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
6 * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com>
7 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
8 */
10 #include <linux/mm.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/bootmem.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/mc146818rtc.h>
16 #include <linux/bitops.h>
17 #include <linux/acpi.h>
18 #include <linux/module.h>
19 #include <linux/smp.h>
21 #include <asm/mtrr.h>
22 #include <asm/mpspec.h>
23 #include <asm/pgalloc.h>
24 #include <asm/io_apic.h>
25 #include <asm/proto.h>
26 #include <asm/bios_ebda.h>
27 #include <asm/e820.h>
28 #include <asm/trampoline.h>
29 #include <asm/setup.h>
30 #include <asm/smp.h>
32 #include <asm/apic.h>
34 * Checksum an MP configuration block.
37 static int __init mpf_checksum(unsigned char *mp, int len)
39 int sum = 0;
41 while (len--)
42 sum += *mp++;
44 return sum & 0xFF;
47 static void __init MP_processor_info(struct mpc_cpu *m)
49 int apicid;
50 char *bootup_cpu = "";
52 if (!(m->cpuflag & CPU_ENABLED)) {
53 disabled_cpus++;
54 return;
57 if (x86_quirks->mpc_apic_id)
58 apicid = x86_quirks->mpc_apic_id(m);
59 else
60 apicid = m->apicid;
62 if (m->cpuflag & CPU_BOOTPROCESSOR) {
63 bootup_cpu = " (Bootup-CPU)";
64 boot_cpu_physical_apicid = m->apicid;
67 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
68 generic_processor_info(apicid, m->apicver);
71 #ifdef CONFIG_X86_IO_APIC
72 static void __init MP_bus_info(struct mpc_bus *m)
74 char str[7];
75 memcpy(str, m->bustype, 6);
76 str[6] = 0;
78 if (x86_quirks->mpc_oem_bus_info)
79 x86_quirks->mpc_oem_bus_info(m, str);
80 else
81 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
83 #if MAX_MP_BUSSES < 256
84 if (m->busid >= MAX_MP_BUSSES) {
85 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
86 " is too large, max. supported is %d\n",
87 m->busid, str, MAX_MP_BUSSES - 1);
88 return;
90 #endif
92 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
93 set_bit(m->busid, mp_bus_not_pci);
94 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
95 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
96 #endif
97 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
98 if (x86_quirks->mpc_oem_pci_bus)
99 x86_quirks->mpc_oem_pci_bus(m);
101 clear_bit(m->busid, mp_bus_not_pci);
102 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
103 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
104 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
105 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
106 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
107 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
108 #endif
109 } else
110 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
112 #endif
114 #ifdef CONFIG_X86_IO_APIC
116 static int bad_ioapic(unsigned long address)
118 if (nr_ioapics >= MAX_IO_APICS) {
119 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
120 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
121 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
123 if (!address) {
124 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
125 " found in table, skipping!\n");
126 return 1;
128 return 0;
131 static void __init MP_ioapic_info(struct mpc_ioapic *m)
133 if (!(m->flags & MPC_APIC_USABLE))
134 return;
136 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
137 m->apicid, m->apicver, m->apicaddr);
139 if (bad_ioapic(m->apicaddr))
140 return;
142 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
143 mp_ioapics[nr_ioapics].apicid = m->apicid;
144 mp_ioapics[nr_ioapics].type = m->type;
145 mp_ioapics[nr_ioapics].apicver = m->apicver;
146 mp_ioapics[nr_ioapics].flags = m->flags;
147 nr_ioapics++;
150 static void print_MP_intsrc_info(struct mpc_intsrc *m)
152 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
153 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
154 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
155 m->srcbusirq, m->dstapic, m->dstirq);
158 static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
160 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
161 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
162 mp_irq->irqtype, mp_irq->irqflag & 3,
163 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
164 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
167 static void __init assign_to_mp_irq(struct mpc_intsrc *m,
168 struct mpc_intsrc *mp_irq)
170 mp_irq->dstapic = m->dstapic;
171 mp_irq->type = m->type;
172 mp_irq->irqtype = m->irqtype;
173 mp_irq->irqflag = m->irqflag;
174 mp_irq->srcbus = m->srcbus;
175 mp_irq->srcbusirq = m->srcbusirq;
176 mp_irq->dstirq = m->dstirq;
179 static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
180 struct mpc_intsrc *m)
182 m->dstapic = mp_irq->dstapic;
183 m->type = mp_irq->type;
184 m->irqtype = mp_irq->irqtype;
185 m->irqflag = mp_irq->irqflag;
186 m->srcbus = mp_irq->srcbus;
187 m->srcbusirq = mp_irq->srcbusirq;
188 m->dstirq = mp_irq->dstirq;
191 static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
192 struct mpc_intsrc *m)
194 if (mp_irq->dstapic != m->dstapic)
195 return 1;
196 if (mp_irq->type != m->type)
197 return 2;
198 if (mp_irq->irqtype != m->irqtype)
199 return 3;
200 if (mp_irq->irqflag != m->irqflag)
201 return 4;
202 if (mp_irq->srcbus != m->srcbus)
203 return 5;
204 if (mp_irq->srcbusirq != m->srcbusirq)
205 return 6;
206 if (mp_irq->dstirq != m->dstirq)
207 return 7;
209 return 0;
212 static void __init MP_intsrc_info(struct mpc_intsrc *m)
214 int i;
216 print_MP_intsrc_info(m);
218 for (i = 0; i < mp_irq_entries; i++) {
219 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
220 return;
223 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
224 if (++mp_irq_entries == MAX_IRQ_SOURCES)
225 panic("Max # of irq sources exceeded!!\n");
228 #endif
230 static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
232 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
233 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
234 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
235 m->srcbusirq, m->destapic, m->destapiclint);
239 * Read/parse the MPC
242 static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
245 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
246 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
247 mpc->signature[0], mpc->signature[1],
248 mpc->signature[2], mpc->signature[3]);
249 return 0;
251 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
252 printk(KERN_ERR "MPTABLE: checksum error!\n");
253 return 0;
255 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
256 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
257 mpc->spec);
258 return 0;
260 if (!mpc->lapic) {
261 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
262 return 0;
264 memcpy(oem, mpc->oem, 8);
265 oem[8] = 0;
266 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
268 memcpy(str, mpc->productid, 12);
269 str[12] = 0;
271 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
273 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
275 return 1;
278 static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
280 char str[16];
281 char oem[10];
283 int count = sizeof(*mpc);
284 unsigned char *mpt = ((unsigned char *)mpc) + count;
286 if (!smp_check_mpc(mpc, oem, str))
287 return 0;
289 #ifdef CONFIG_X86_32
290 generic_mps_oem_check(mpc, oem, str);
291 #endif
292 /* save the local APIC address, it might be non-default */
293 if (!acpi_lapic)
294 mp_lapic_addr = mpc->lapic;
296 if (early)
297 return 1;
299 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
300 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
301 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
305 * Now process the configuration blocks.
307 if (x86_quirks->mpc_record)
308 *x86_quirks->mpc_record = 0;
310 while (count < mpc->length) {
311 switch (*mpt) {
312 case MP_PROCESSOR:
314 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
315 /* ACPI may have already provided this data */
316 if (!acpi_lapic)
317 MP_processor_info(m);
318 mpt += sizeof(*m);
319 count += sizeof(*m);
320 break;
322 case MP_BUS:
324 struct mpc_bus *m = (struct mpc_bus *)mpt;
325 #ifdef CONFIG_X86_IO_APIC
326 MP_bus_info(m);
327 #endif
328 mpt += sizeof(*m);
329 count += sizeof(*m);
330 break;
332 case MP_IOAPIC:
334 #ifdef CONFIG_X86_IO_APIC
335 struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
336 MP_ioapic_info(m);
337 #endif
338 mpt += sizeof(struct mpc_ioapic);
339 count += sizeof(struct mpc_ioapic);
340 break;
342 case MP_INTSRC:
344 #ifdef CONFIG_X86_IO_APIC
345 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
347 MP_intsrc_info(m);
348 #endif
349 mpt += sizeof(struct mpc_intsrc);
350 count += sizeof(struct mpc_intsrc);
351 break;
353 case MP_LINTSRC:
355 struct mpc_lintsrc *m =
356 (struct mpc_lintsrc *)mpt;
357 MP_lintsrc_info(m);
358 mpt += sizeof(*m);
359 count += sizeof(*m);
360 break;
362 default:
363 /* wrong mptable */
364 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
365 printk(KERN_ERR "type %x\n", *mpt);
366 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
367 1, mpc, mpc->length, 1);
368 count = mpc->length;
369 break;
371 if (x86_quirks->mpc_record)
372 (*x86_quirks->mpc_record)++;
375 #ifdef CONFIG_X86_BIGSMP
376 generic_bigsmp_probe();
377 #endif
379 if (apic->setup_apic_routing)
380 apic->setup_apic_routing();
382 if (!num_processors)
383 printk(KERN_ERR "MPTABLE: no processors registered!\n");
384 return num_processors;
387 #ifdef CONFIG_X86_IO_APIC
389 static int __init ELCR_trigger(unsigned int irq)
391 unsigned int port;
393 port = 0x4d0 + (irq >> 3);
394 return (inb(port) >> (irq & 7)) & 1;
397 static void __init construct_default_ioirq_mptable(int mpc_default_type)
399 struct mpc_intsrc intsrc;
400 int i;
401 int ELCR_fallback = 0;
403 intsrc.type = MP_INTSRC;
404 intsrc.irqflag = 0; /* conforming */
405 intsrc.srcbus = 0;
406 intsrc.dstapic = mp_ioapics[0].apicid;
408 intsrc.irqtype = mp_INT;
411 * If true, we have an ISA/PCI system with no IRQ entries
412 * in the MP table. To prevent the PCI interrupts from being set up
413 * incorrectly, we try to use the ELCR. The sanity check to see if
414 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
415 * never be level sensitive, so we simply see if the ELCR agrees.
416 * If it does, we assume it's valid.
418 if (mpc_default_type == 5) {
419 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
420 "falling back to ELCR\n");
422 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
423 ELCR_trigger(13))
424 printk(KERN_ERR "ELCR contains invalid data... "
425 "not using ELCR\n");
426 else {
427 printk(KERN_INFO
428 "Using ELCR to identify PCI interrupts\n");
429 ELCR_fallback = 1;
433 for (i = 0; i < 16; i++) {
434 switch (mpc_default_type) {
435 case 2:
436 if (i == 0 || i == 13)
437 continue; /* IRQ0 & IRQ13 not connected */
438 /* fall through */
439 default:
440 if (i == 2)
441 continue; /* IRQ2 is never connected */
444 if (ELCR_fallback) {
446 * If the ELCR indicates a level-sensitive interrupt, we
447 * copy that information over to the MP table in the
448 * irqflag field (level sensitive, active high polarity).
450 if (ELCR_trigger(i))
451 intsrc.irqflag = 13;
452 else
453 intsrc.irqflag = 0;
456 intsrc.srcbusirq = i;
457 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
458 MP_intsrc_info(&intsrc);
461 intsrc.irqtype = mp_ExtINT;
462 intsrc.srcbusirq = 0;
463 intsrc.dstirq = 0; /* 8259A to INTIN0 */
464 MP_intsrc_info(&intsrc);
468 static void __init construct_ioapic_table(int mpc_default_type)
470 struct mpc_ioapic ioapic;
471 struct mpc_bus bus;
473 bus.type = MP_BUS;
474 bus.busid = 0;
475 switch (mpc_default_type) {
476 default:
477 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
478 mpc_default_type);
479 /* fall through */
480 case 1:
481 case 5:
482 memcpy(bus.bustype, "ISA ", 6);
483 break;
484 case 2:
485 case 6:
486 case 3:
487 memcpy(bus.bustype, "EISA ", 6);
488 break;
489 case 4:
490 case 7:
491 memcpy(bus.bustype, "MCA ", 6);
493 MP_bus_info(&bus);
494 if (mpc_default_type > 4) {
495 bus.busid = 1;
496 memcpy(bus.bustype, "PCI ", 6);
497 MP_bus_info(&bus);
500 ioapic.type = MP_IOAPIC;
501 ioapic.apicid = 2;
502 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
503 ioapic.flags = MPC_APIC_USABLE;
504 ioapic.apicaddr = 0xFEC00000;
505 MP_ioapic_info(&ioapic);
508 * We set up most of the low 16 IO-APIC pins according to MPS rules.
510 construct_default_ioirq_mptable(mpc_default_type);
512 #else
513 static inline void __init construct_ioapic_table(int mpc_default_type) { }
514 #endif
516 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
518 struct mpc_cpu processor;
519 struct mpc_lintsrc lintsrc;
520 int linttypes[2] = { mp_ExtINT, mp_NMI };
521 int i;
524 * local APIC has default address
526 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
529 * 2 CPUs, numbered 0 & 1.
531 processor.type = MP_PROCESSOR;
532 /* Either an integrated APIC or a discrete 82489DX. */
533 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
534 processor.cpuflag = CPU_ENABLED;
535 processor.cpufeature = (boot_cpu_data.x86 << 8) |
536 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
537 processor.featureflag = boot_cpu_data.x86_capability[0];
538 processor.reserved[0] = 0;
539 processor.reserved[1] = 0;
540 for (i = 0; i < 2; i++) {
541 processor.apicid = i;
542 MP_processor_info(&processor);
545 construct_ioapic_table(mpc_default_type);
547 lintsrc.type = MP_LINTSRC;
548 lintsrc.irqflag = 0; /* conforming */
549 lintsrc.srcbusid = 0;
550 lintsrc.srcbusirq = 0;
551 lintsrc.destapic = MP_APIC_ALL;
552 for (i = 0; i < 2; i++) {
553 lintsrc.irqtype = linttypes[i];
554 lintsrc.destapiclint = i;
555 MP_lintsrc_info(&lintsrc);
559 static struct mpf_intel *mpf_found;
561 static unsigned long __init get_mpc_size(unsigned long physptr)
563 struct mpc_table *mpc;
564 unsigned long size;
566 mpc = early_ioremap(physptr, PAGE_SIZE);
567 size = mpc->length;
568 early_iounmap(mpc, PAGE_SIZE);
569 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
571 return size;
575 * Scan the memory blocks for an SMP configuration block.
577 static void __init __get_smp_config(unsigned int early)
579 struct mpf_intel *mpf = mpf_found;
581 if (!mpf)
582 return;
584 if (acpi_lapic && early)
585 return;
588 * MPS doesn't support hyperthreading, aka only have
589 * thread 0 apic id in MPS table
591 if (acpi_lapic && acpi_ioapic)
592 return;
594 if (x86_quirks->mach_get_smp_config) {
595 if (x86_quirks->mach_get_smp_config(early))
596 return;
599 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
600 mpf->specification);
601 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
602 if (mpf->feature2 & (1 << 7)) {
603 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
604 pic_mode = 1;
605 } else {
606 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
607 pic_mode = 0;
609 #endif
611 * Now see if we need to read further.
613 if (mpf->feature1 != 0) {
614 if (early) {
616 * local APIC has default address
618 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
619 return;
622 printk(KERN_INFO "Default MP configuration #%d\n",
623 mpf->feature1);
624 construct_default_ISA_mptable(mpf->feature1);
626 } else if (mpf->physptr) {
627 struct mpc_table *mpc;
628 unsigned long size;
630 size = get_mpc_size(mpf->physptr);
631 mpc = early_ioremap(mpf->physptr, size);
633 * Read the physical hardware table. Anything here will
634 * override the defaults.
636 if (!smp_read_mpc(mpc, early)) {
637 #ifdef CONFIG_X86_LOCAL_APIC
638 smp_found_config = 0;
639 #endif
640 printk(KERN_ERR
641 "BIOS bug, MP table errors detected!...\n");
642 printk(KERN_ERR "... disabling SMP support. "
643 "(tell your hw vendor)\n");
644 early_iounmap(mpc, size);
645 return;
647 early_iounmap(mpc, size);
649 if (early)
650 return;
651 #ifdef CONFIG_X86_IO_APIC
653 * If there are no explicit MP IRQ entries, then we are
654 * broken. We set up most of the low 16 IO-APIC pins to
655 * ISA defaults and hope it will work.
657 if (!mp_irq_entries) {
658 struct mpc_bus bus;
660 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
661 "using default mptable. "
662 "(tell your hw vendor)\n");
664 bus.type = MP_BUS;
665 bus.busid = 0;
666 memcpy(bus.bustype, "ISA ", 6);
667 MP_bus_info(&bus);
669 construct_default_ioirq_mptable(0);
671 #endif
672 } else
673 BUG();
675 if (!early)
676 printk(KERN_INFO "Processors: %d\n", num_processors);
678 * Only use the first configuration found.
682 void __init early_get_smp_config(void)
684 __get_smp_config(1);
687 void __init get_smp_config(void)
689 __get_smp_config(0);
692 static int __init smp_scan_config(unsigned long base, unsigned long length,
693 unsigned reserve)
695 unsigned int *bp = phys_to_virt(base);
696 struct mpf_intel *mpf;
698 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
699 bp, length);
700 BUILD_BUG_ON(sizeof(*mpf) != 16);
702 while (length > 0) {
703 mpf = (struct mpf_intel *)bp;
704 if ((*bp == SMP_MAGIC_IDENT) &&
705 (mpf->length == 1) &&
706 !mpf_checksum((unsigned char *)bp, 16) &&
707 ((mpf->specification == 1)
708 || (mpf->specification == 4))) {
709 #ifdef CONFIG_X86_LOCAL_APIC
710 smp_found_config = 1;
711 #endif
712 mpf_found = mpf;
714 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
715 mpf, (u64)virt_to_phys(mpf));
717 if (!reserve)
718 return 1;
719 reserve_bootmem_generic(virt_to_phys(mpf), sizeof(*mpf),
720 BOOTMEM_DEFAULT);
721 if (mpf->physptr) {
722 unsigned long size = get_mpc_size(mpf->physptr);
723 #ifdef CONFIG_X86_32
725 * We cannot access to MPC table to compute
726 * table size yet, as only few megabytes from
727 * the bottom is mapped now.
728 * PC-9800's MPC table places on the very last
729 * of physical memory; so that simply reserving
730 * PAGE_SIZE from mpf->physptr yields BUG()
731 * in reserve_bootmem.
732 * also need to make sure physptr is below than
733 * max_low_pfn
734 * we don't need reserve the area above max_low_pfn
736 unsigned long end = max_low_pfn * PAGE_SIZE;
738 if (mpf->physptr < end) {
739 if (mpf->physptr + size > end)
740 size = end - mpf->physptr;
741 reserve_bootmem_generic(mpf->physptr, size,
742 BOOTMEM_DEFAULT);
744 #else
745 reserve_bootmem_generic(mpf->physptr, size,
746 BOOTMEM_DEFAULT);
747 #endif
750 return 1;
752 bp += 4;
753 length -= 16;
755 return 0;
758 static void __init __find_smp_config(unsigned int reserve)
760 unsigned int address;
762 if (x86_quirks->mach_find_smp_config) {
763 if (x86_quirks->mach_find_smp_config(reserve))
764 return;
767 * FIXME: Linux assumes you have 640K of base ram..
768 * this continues the error...
770 * 1) Scan the bottom 1K for a signature
771 * 2) Scan the top 1K of base RAM
772 * 3) Scan the 64K of bios
774 if (smp_scan_config(0x0, 0x400, reserve) ||
775 smp_scan_config(639 * 0x400, 0x400, reserve) ||
776 smp_scan_config(0xF0000, 0x10000, reserve))
777 return;
779 * If it is an SMP machine we should know now, unless the
780 * configuration is in an EISA/MCA bus machine with an
781 * extended bios data area.
783 * there is a real-mode segmented pointer pointing to the
784 * 4K EBDA area at 0x40E, calculate and scan it here.
786 * NOTE! There are Linux loaders that will corrupt the EBDA
787 * area, and as such this kind of SMP config may be less
788 * trustworthy, simply because the SMP table may have been
789 * stomped on during early boot. These loaders are buggy and
790 * should be fixed.
792 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
795 address = get_bios_ebda();
796 if (address)
797 smp_scan_config(address, 0x400, reserve);
800 void __init early_find_smp_config(void)
802 __find_smp_config(0);
805 void __init find_smp_config(void)
807 __find_smp_config(1);
810 #ifdef CONFIG_X86_IO_APIC
811 static u8 __initdata irq_used[MAX_IRQ_SOURCES];
813 static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
815 int i;
817 if (m->irqtype != mp_INT)
818 return 0;
820 if (m->irqflag != 0x0f)
821 return 0;
823 /* not legacy */
825 for (i = 0; i < mp_irq_entries; i++) {
826 if (mp_irqs[i].irqtype != mp_INT)
827 continue;
829 if (mp_irqs[i].irqflag != 0x0f)
830 continue;
832 if (mp_irqs[i].srcbus != m->srcbus)
833 continue;
834 if (mp_irqs[i].srcbusirq != m->srcbusirq)
835 continue;
836 if (irq_used[i]) {
837 /* already claimed */
838 return -2;
840 irq_used[i] = 1;
841 return i;
844 /* not found */
845 return -1;
848 #define SPARE_SLOT_NUM 20
850 static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
851 #endif
853 static int __init replace_intsrc_all(struct mpc_table *mpc,
854 unsigned long mpc_new_phys,
855 unsigned long mpc_new_length)
857 #ifdef CONFIG_X86_IO_APIC
858 int i;
859 int nr_m_spare = 0;
860 #endif
862 int count = sizeof(*mpc);
863 unsigned char *mpt = ((unsigned char *)mpc) + count;
865 printk(KERN_INFO "mpc_length %x\n", mpc->length);
866 while (count < mpc->length) {
867 switch (*mpt) {
868 case MP_PROCESSOR:
870 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
871 mpt += sizeof(*m);
872 count += sizeof(*m);
873 break;
875 case MP_BUS:
877 struct mpc_bus *m = (struct mpc_bus *)mpt;
878 mpt += sizeof(*m);
879 count += sizeof(*m);
880 break;
882 case MP_IOAPIC:
884 mpt += sizeof(struct mpc_ioapic);
885 count += sizeof(struct mpc_ioapic);
886 break;
888 case MP_INTSRC:
890 #ifdef CONFIG_X86_IO_APIC
891 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
893 apic_printk(APIC_VERBOSE, "OLD ");
894 print_MP_intsrc_info(m);
895 i = get_MP_intsrc_index(m);
896 if (i > 0) {
897 assign_to_mpc_intsrc(&mp_irqs[i], m);
898 apic_printk(APIC_VERBOSE, "NEW ");
899 print_mp_irq_info(&mp_irqs[i]);
900 } else if (!i) {
901 /* legacy, do nothing */
902 } else if (nr_m_spare < SPARE_SLOT_NUM) {
904 * not found (-1), or duplicated (-2)
905 * are invalid entries,
906 * we need to use the slot later
908 m_spare[nr_m_spare] = m;
909 nr_m_spare++;
911 #endif
912 mpt += sizeof(struct mpc_intsrc);
913 count += sizeof(struct mpc_intsrc);
914 break;
916 case MP_LINTSRC:
918 struct mpc_lintsrc *m =
919 (struct mpc_lintsrc *)mpt;
920 mpt += sizeof(*m);
921 count += sizeof(*m);
922 break;
924 default:
925 /* wrong mptable */
926 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
927 printk(KERN_ERR "type %x\n", *mpt);
928 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
929 1, mpc, mpc->length, 1);
930 goto out;
934 #ifdef CONFIG_X86_IO_APIC
935 for (i = 0; i < mp_irq_entries; i++) {
936 if (irq_used[i])
937 continue;
939 if (mp_irqs[i].irqtype != mp_INT)
940 continue;
942 if (mp_irqs[i].irqflag != 0x0f)
943 continue;
945 if (nr_m_spare > 0) {
946 apic_printk(APIC_VERBOSE, "*NEW* found\n");
947 nr_m_spare--;
948 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
949 m_spare[nr_m_spare] = NULL;
950 } else {
951 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
952 count += sizeof(struct mpc_intsrc);
953 if (!mpc_new_phys) {
954 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
955 } else {
956 if (count <= mpc_new_length)
957 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
958 else {
959 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
960 goto out;
963 assign_to_mpc_intsrc(&mp_irqs[i], m);
964 mpc->length = count;
965 mpt += sizeof(struct mpc_intsrc);
967 print_mp_irq_info(&mp_irqs[i]);
969 #endif
970 out:
971 /* update checksum */
972 mpc->checksum = 0;
973 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
975 return 0;
978 static int __initdata enable_update_mptable;
980 static int __init update_mptable_setup(char *str)
982 enable_update_mptable = 1;
983 return 0;
985 early_param("update_mptable", update_mptable_setup);
987 static unsigned long __initdata mpc_new_phys;
988 static unsigned long mpc_new_length __initdata = 4096;
990 /* alloc_mptable or alloc_mptable=4k */
991 static int __initdata alloc_mptable;
992 static int __init parse_alloc_mptable_opt(char *p)
994 enable_update_mptable = 1;
995 alloc_mptable = 1;
996 if (!p)
997 return 0;
998 mpc_new_length = memparse(p, &p);
999 return 0;
1001 early_param("alloc_mptable", parse_alloc_mptable_opt);
1003 void __init early_reserve_e820_mpc_new(void)
1005 if (enable_update_mptable && alloc_mptable) {
1006 u64 startt = 0;
1007 #ifdef CONFIG_X86_TRAMPOLINE
1008 startt = TRAMPOLINE_BASE;
1009 #endif
1010 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1014 static int __init update_mp_table(void)
1016 char str[16];
1017 char oem[10];
1018 struct mpf_intel *mpf;
1019 struct mpc_table *mpc, *mpc_new;
1021 if (!enable_update_mptable)
1022 return 0;
1024 mpf = mpf_found;
1025 if (!mpf)
1026 return 0;
1029 * Now see if we need to go further.
1031 if (mpf->feature1 != 0)
1032 return 0;
1034 if (!mpf->physptr)
1035 return 0;
1037 mpc = phys_to_virt(mpf->physptr);
1039 if (!smp_check_mpc(mpc, oem, str))
1040 return 0;
1042 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
1043 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
1045 if (mpc_new_phys && mpc->length > mpc_new_length) {
1046 mpc_new_phys = 0;
1047 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1048 mpc_new_length);
1051 if (!mpc_new_phys) {
1052 unsigned char old, new;
1053 /* check if we can change the postion */
1054 mpc->checksum = 0;
1055 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1056 mpc->checksum = 0xff;
1057 new = mpf_checksum((unsigned char *)mpc, mpc->length);
1058 if (old == new) {
1059 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1060 return 0;
1062 printk(KERN_INFO "use in-positon replacing\n");
1063 } else {
1064 mpf->physptr = mpc_new_phys;
1065 mpc_new = phys_to_virt(mpc_new_phys);
1066 memcpy(mpc_new, mpc, mpc->length);
1067 mpc = mpc_new;
1068 /* check if we can modify that */
1069 if (mpc_new_phys - mpf->physptr) {
1070 struct mpf_intel *mpf_new;
1071 /* steal 16 bytes from [0, 1k) */
1072 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1073 mpf_new = phys_to_virt(0x400 - 16);
1074 memcpy(mpf_new, mpf, 16);
1075 mpf = mpf_new;
1076 mpf->physptr = mpc_new_phys;
1078 mpf->checksum = 0;
1079 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1080 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
1084 * only replace the one with mp_INT and
1085 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1086 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1087 * may need pci=routeirq for all coverage
1089 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1091 return 0;
1094 late_initcall(update_mp_table);