2 * Intel Multiprocessor Specification 1.1 and 1.4
3 * compliant MP-table parsing routines.
5 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
6 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
7 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
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>
22 #include <asm/mpspec.h>
23 #include <asm/pgalloc.h>
24 #include <asm/io_apic.h>
25 #include <asm/proto.h>
27 #include <asm/bios_ebda.h>
29 #include <asm/trampoline.h>
31 #include <mach_apic.h>
33 #include <mach_apicdef.h>
34 #include <mach_mpparse.h>
38 * Checksum an MP configuration block.
41 static int __init mpf_checksum(unsigned char *mp, int len)
51 #ifdef CONFIG_X86_NUMAQ
53 * Have to match translation table entries to main table entries by counter
54 * hence the mpc_record variable .... can't see a less disgusting way of
58 static int mpc_record;
59 static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
63 static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
66 char *bootup_cpu = "";
68 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
72 #ifdef CONFIG_X86_NUMAQ
73 apicid = mpc_apic_id(m, translation_table[mpc_record]);
75 apicid = m->mpc_apicid;
77 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
78 bootup_cpu = " (Bootup-CPU)";
79 boot_cpu_physical_apicid = m->mpc_apicid;
82 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
83 generic_processor_info(apicid, m->mpc_apicver);
86 #ifdef CONFIG_X86_IO_APIC
87 static void __init MP_bus_info(struct mpc_config_bus *m)
90 memcpy(str, m->mpc_bustype, 6);
93 #ifdef CONFIG_X86_NUMAQ
94 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
96 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
99 #if MAX_MP_BUSSES < 256
100 if (m->mpc_busid >= MAX_MP_BUSSES) {
101 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
102 " is too large, max. supported is %d\n",
103 m->mpc_busid, str, MAX_MP_BUSSES - 1);
108 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
109 set_bit(m->mpc_busid, mp_bus_not_pci);
110 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
111 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
113 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
114 #ifdef CONFIG_X86_NUMAQ
115 mpc_oem_pci_bus(m, translation_table[mpc_record]);
117 clear_bit(m->mpc_busid, mp_bus_not_pci);
118 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
119 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
120 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
121 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
122 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
123 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
126 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
130 #ifdef CONFIG_X86_IO_APIC
132 static int bad_ioapic(unsigned long address)
134 if (nr_ioapics >= MAX_IO_APICS) {
135 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
136 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
137 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
140 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
141 " found in table, skipping!\n");
147 static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
149 if (!(m->mpc_flags & MPC_APIC_USABLE))
152 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
153 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
155 if (bad_ioapic(m->mpc_apicaddr))
158 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
159 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
160 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
161 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
162 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
166 static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
168 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
169 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
170 m->mpc_irqtype, m->mpc_irqflag & 3,
171 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
172 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
175 static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
177 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
178 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
179 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
180 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
181 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
184 static void assign_to_mp_irq(struct mpc_config_intsrc *m,
185 struct mp_config_intsrc *mp_irq)
187 mp_irq->mp_dstapic = m->mpc_dstapic;
188 mp_irq->mp_type = m->mpc_type;
189 mp_irq->mp_irqtype = m->mpc_irqtype;
190 mp_irq->mp_irqflag = m->mpc_irqflag;
191 mp_irq->mp_srcbus = m->mpc_srcbus;
192 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
193 mp_irq->mp_dstirq = m->mpc_dstirq;
196 static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
197 struct mpc_config_intsrc *m)
199 m->mpc_dstapic = mp_irq->mp_dstapic;
200 m->mpc_type = mp_irq->mp_type;
201 m->mpc_irqtype = mp_irq->mp_irqtype;
202 m->mpc_irqflag = mp_irq->mp_irqflag;
203 m->mpc_srcbus = mp_irq->mp_srcbus;
204 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
205 m->mpc_dstirq = mp_irq->mp_dstirq;
208 static int mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
209 struct mpc_config_intsrc *m)
211 if (mp_irq->mp_dstapic != m->mpc_dstapic)
213 if (mp_irq->mp_type != m->mpc_type)
215 if (mp_irq->mp_irqtype != m->mpc_irqtype)
217 if (mp_irq->mp_irqflag != m->mpc_irqflag)
219 if (mp_irq->mp_srcbus != m->mpc_srcbus)
221 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
223 if (mp_irq->mp_dstirq != m->mpc_dstirq)
229 void MP_intsrc_info(struct mpc_config_intsrc *m)
233 print_MP_intsrc_info(m);
235 for (i = 0; i < mp_irq_entries; i++) {
236 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
240 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
241 if (++mp_irq_entries == MAX_IRQ_SOURCES)
242 panic("Max # of irq sources exceeded!!\n");
247 static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
249 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
250 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
251 m->mpc_irqtype, m->mpc_irqflag & 3,
252 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
253 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
256 #ifdef CONFIG_X86_NUMAQ
257 static void __init MP_translation_info(struct mpc_config_translation *m)
260 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
261 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
264 if (mpc_record >= MAX_MPC_ENTRY)
265 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
267 translation_table[mpc_record] = m; /* stash this for later */
268 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
269 node_set_online(m->trans_quad);
273 * Read/parse the MPC oem tables
276 static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
277 unsigned short oemsize)
279 int count = sizeof(*oemtable); /* the header size */
280 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
283 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
285 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
287 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
288 oemtable->oem_signature[0], oemtable->oem_signature[1],
289 oemtable->oem_signature[2], oemtable->oem_signature[3]);
292 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
293 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
296 while (count < oemtable->oem_length) {
300 struct mpc_config_translation *m =
301 (struct mpc_config_translation *)oemptr;
302 MP_translation_info(m);
303 oemptr += sizeof(*m);
311 "Unrecognised OEM table entry type! - %d\n",
319 static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
322 if (strncmp(oem, "IBM NUMA", 8))
323 printk("Warning! May not be a NUMA-Q system!\n");
325 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
328 #endif /* CONFIG_X86_NUMAQ */
334 static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
338 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
339 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
340 mpc->mpc_signature[0], mpc->mpc_signature[1],
341 mpc->mpc_signature[2], mpc->mpc_signature[3]);
344 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
345 printk(KERN_ERR "MPTABLE: checksum error!\n");
348 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
349 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
353 if (!mpc->mpc_lapic) {
354 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
357 memcpy(oem, mpc->mpc_oem, 8);
359 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
361 memcpy(str, mpc->mpc_productid, 12);
364 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
366 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
371 static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
376 int count = sizeof(*mpc);
377 unsigned char *mpt = ((unsigned char *)mpc) + count;
379 if (!smp_check_mpc(mpc, oem, str))
383 mps_oem_check(mpc, oem, str);
386 /* save the local APIC address, it might be non-default */
388 mp_lapic_addr = mpc->mpc_lapic;
394 * Now process the configuration blocks.
396 #ifdef CONFIG_X86_NUMAQ
399 while (count < mpc->mpc_length) {
403 struct mpc_config_processor *m =
404 (struct mpc_config_processor *)mpt;
405 /* ACPI may have already provided this data */
407 MP_processor_info(m);
414 struct mpc_config_bus *m =
415 (struct mpc_config_bus *)mpt;
416 #ifdef CONFIG_X86_IO_APIC
425 #ifdef CONFIG_X86_IO_APIC
426 struct mpc_config_ioapic *m =
427 (struct mpc_config_ioapic *)mpt;
430 mpt += sizeof(struct mpc_config_ioapic);
431 count += sizeof(struct mpc_config_ioapic);
436 #ifdef CONFIG_X86_IO_APIC
437 struct mpc_config_intsrc *m =
438 (struct mpc_config_intsrc *)mpt;
442 mpt += sizeof(struct mpc_config_intsrc);
443 count += sizeof(struct mpc_config_intsrc);
448 struct mpc_config_lintsrc *m =
449 (struct mpc_config_lintsrc *)mpt;
457 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
458 printk(KERN_ERR "type %x\n", *mpt);
459 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
460 1, mpc, mpc->mpc_length, 1);
461 count = mpc->mpc_length;
464 #ifdef CONFIG_X86_NUMAQ
468 setup_apic_routing();
470 printk(KERN_ERR "MPTABLE: no processors registered!\n");
471 return num_processors;
474 #ifdef CONFIG_X86_IO_APIC
476 static int __init ELCR_trigger(unsigned int irq)
480 port = 0x4d0 + (irq >> 3);
481 return (inb(port) >> (irq & 7)) & 1;
484 static void __init construct_default_ioirq_mptable(int mpc_default_type)
486 struct mpc_config_intsrc intsrc;
488 int ELCR_fallback = 0;
490 intsrc.mpc_type = MP_INTSRC;
491 intsrc.mpc_irqflag = 0; /* conforming */
492 intsrc.mpc_srcbus = 0;
493 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
495 intsrc.mpc_irqtype = mp_INT;
498 * If true, we have an ISA/PCI system with no IRQ entries
499 * in the MP table. To prevent the PCI interrupts from being set up
500 * incorrectly, we try to use the ELCR. The sanity check to see if
501 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
502 * never be level sensitive, so we simply see if the ELCR agrees.
503 * If it does, we assume it's valid.
505 if (mpc_default_type == 5) {
506 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
507 "falling back to ELCR\n");
509 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
511 printk(KERN_ERR "ELCR contains invalid data... "
515 "Using ELCR to identify PCI interrupts\n");
520 for (i = 0; i < 16; i++) {
521 switch (mpc_default_type) {
523 if (i == 0 || i == 13)
524 continue; /* IRQ0 & IRQ13 not connected */
528 continue; /* IRQ2 is never connected */
533 * If the ELCR indicates a level-sensitive interrupt, we
534 * copy that information over to the MP table in the
535 * irqflag field (level sensitive, active high polarity).
538 intsrc.mpc_irqflag = 13;
540 intsrc.mpc_irqflag = 0;
543 intsrc.mpc_srcbusirq = i;
544 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
545 MP_intsrc_info(&intsrc);
548 intsrc.mpc_irqtype = mp_ExtINT;
549 intsrc.mpc_srcbusirq = 0;
550 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
551 MP_intsrc_info(&intsrc);
555 static void construct_ioapic_table(int mpc_default_type)
557 struct mpc_config_ioapic ioapic;
558 struct mpc_config_bus bus;
560 bus.mpc_type = MP_BUS;
562 switch (mpc_default_type) {
564 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
569 memcpy(bus.mpc_bustype, "ISA ", 6);
574 memcpy(bus.mpc_bustype, "EISA ", 6);
578 memcpy(bus.mpc_bustype, "MCA ", 6);
581 if (mpc_default_type > 4) {
583 memcpy(bus.mpc_bustype, "PCI ", 6);
587 ioapic.mpc_type = MP_IOAPIC;
588 ioapic.mpc_apicid = 2;
589 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
590 ioapic.mpc_flags = MPC_APIC_USABLE;
591 ioapic.mpc_apicaddr = 0xFEC00000;
592 MP_ioapic_info(&ioapic);
595 * We set up most of the low 16 IO-APIC pins according to MPS rules.
597 construct_default_ioirq_mptable(mpc_default_type);
600 static inline void construct_ioapic_table(int mpc_default_type) { }
603 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
605 struct mpc_config_processor processor;
606 struct mpc_config_lintsrc lintsrc;
607 int linttypes[2] = { mp_ExtINT, mp_NMI };
611 * local APIC has default address
613 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
616 * 2 CPUs, numbered 0 & 1.
618 processor.mpc_type = MP_PROCESSOR;
619 /* Either an integrated APIC or a discrete 82489DX. */
620 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
621 processor.mpc_cpuflag = CPU_ENABLED;
622 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
623 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
624 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
625 processor.mpc_reserved[0] = 0;
626 processor.mpc_reserved[1] = 0;
627 for (i = 0; i < 2; i++) {
628 processor.mpc_apicid = i;
629 MP_processor_info(&processor);
632 construct_ioapic_table(mpc_default_type);
634 lintsrc.mpc_type = MP_LINTSRC;
635 lintsrc.mpc_irqflag = 0; /* conforming */
636 lintsrc.mpc_srcbusid = 0;
637 lintsrc.mpc_srcbusirq = 0;
638 lintsrc.mpc_destapic = MP_APIC_ALL;
639 for (i = 0; i < 2; i++) {
640 lintsrc.mpc_irqtype = linttypes[i];
641 lintsrc.mpc_destapiclint = i;
642 MP_lintsrc_info(&lintsrc);
646 static struct intel_mp_floating *mpf_found;
649 * Scan the memory blocks for an SMP configuration block.
651 static void __init __get_smp_config(unsigned early)
653 struct intel_mp_floating *mpf = mpf_found;
655 if (acpi_lapic && early)
658 * ACPI supports both logical (e.g. Hyper-Threading) and physical
659 * processors, where MPS only supports physical.
661 if (acpi_lapic && acpi_ioapic) {
662 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
665 } else if (acpi_lapic)
666 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
667 "configuration information\n");
669 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
670 mpf->mpf_specification);
671 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
672 if (mpf->mpf_feature2 & (1 << 7)) {
673 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
676 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
681 * Now see if we need to read further.
683 if (mpf->mpf_feature1 != 0) {
686 * local APIC has default address
688 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
692 printk(KERN_INFO "Default MP configuration #%d\n",
694 construct_default_ISA_mptable(mpf->mpf_feature1);
696 } else if (mpf->mpf_physptr) {
699 * Read the physical hardware table. Anything here will
700 * override the defaults.
702 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
703 #ifdef CONFIG_X86_LOCAL_APIC
704 smp_found_config = 0;
707 "BIOS bug, MP table errors detected!...\n");
708 printk(KERN_ERR "... disabling SMP support. "
709 "(tell your hw vendor)\n");
715 #ifdef CONFIG_X86_IO_APIC
717 * If there are no explicit MP IRQ entries, then we are
718 * broken. We set up most of the low 16 IO-APIC pins to
719 * ISA defaults and hope it will work.
721 if (!mp_irq_entries) {
722 struct mpc_config_bus bus;
724 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
725 "using default mptable. "
726 "(tell your hw vendor)\n");
728 bus.mpc_type = MP_BUS;
730 memcpy(bus.mpc_bustype, "ISA ", 6);
733 construct_default_ioirq_mptable(0);
740 printk(KERN_INFO "Processors: %d\n", num_processors);
742 * Only use the first configuration found.
746 void __init early_get_smp_config(void)
751 void __init get_smp_config(void)
756 static int __init smp_scan_config(unsigned long base, unsigned long length,
759 unsigned int *bp = phys_to_virt(base);
760 struct intel_mp_floating *mpf;
762 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
763 BUILD_BUG_ON(sizeof(*mpf) != 16);
766 mpf = (struct intel_mp_floating *)bp;
767 if ((*bp == SMP_MAGIC_IDENT) &&
768 (mpf->mpf_length == 1) &&
769 !mpf_checksum((unsigned char *)bp, 16) &&
770 ((mpf->mpf_specification == 1)
771 || (mpf->mpf_specification == 4))) {
772 #ifdef CONFIG_X86_LOCAL_APIC
773 smp_found_config = 1;
777 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
778 mpf, virt_to_phys(mpf));
779 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
781 if (mpf->mpf_physptr) {
783 * We cannot access to MPC table to compute
784 * table size yet, as only few megabytes from
785 * the bottom is mapped now.
786 * PC-9800's MPC table places on the very last
787 * of physical memory; so that simply reserving
788 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
789 * in reserve_bootmem.
791 unsigned long size = PAGE_SIZE;
792 unsigned long end = max_low_pfn * PAGE_SIZE;
793 if (mpf->mpf_physptr + size > end)
794 size = end - mpf->mpf_physptr;
795 reserve_bootmem(mpf->mpf_physptr, size,
803 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
804 if (mpf->mpf_physptr)
805 reserve_bootmem_generic(mpf->mpf_physptr,
816 static void __init __find_smp_config(unsigned reserve)
818 unsigned int address;
821 * FIXME: Linux assumes you have 640K of base ram..
822 * this continues the error...
824 * 1) Scan the bottom 1K for a signature
825 * 2) Scan the top 1K of base RAM
826 * 3) Scan the 64K of bios
828 if (smp_scan_config(0x0, 0x400, reserve) ||
829 smp_scan_config(639 * 0x400, 0x400, reserve) ||
830 smp_scan_config(0xF0000, 0x10000, reserve))
833 * If it is an SMP machine we should know now, unless the
834 * configuration is in an EISA/MCA bus machine with an
835 * extended bios data area.
837 * there is a real-mode segmented pointer pointing to the
838 * 4K EBDA area at 0x40E, calculate and scan it here.
840 * NOTE! There are Linux loaders that will corrupt the EBDA
841 * area, and as such this kind of SMP config may be less
842 * trustworthy, simply because the SMP table may have been
843 * stomped on during early boot. These loaders are buggy and
846 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
849 address = get_bios_ebda();
851 smp_scan_config(address, 0x400, reserve);
854 void __init early_find_smp_config(void)
856 __find_smp_config(0);
859 void __init find_smp_config(void)
861 __find_smp_config(1);
864 #ifdef CONFIG_X86_IO_APIC
865 static u8 __initdata irq_used[MAX_IRQ_SOURCES];
867 static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
871 if (m->mpc_irqtype != mp_INT)
874 if (m->mpc_irqflag != 0x0f)
879 for (i = 0; i < mp_irq_entries; i++) {
880 if (mp_irqs[i].mp_irqtype != mp_INT)
883 if (mp_irqs[i].mp_irqflag != 0x0f)
886 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
888 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
891 /* already claimed */
902 #define SPARE_SLOT_NUM 20
904 static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
907 static int __init replace_intsrc_all(struct mp_config_table *mpc,
908 unsigned long mpc_new_phys,
909 unsigned long mpc_new_length)
911 #ifdef CONFIG_X86_IO_APIC
916 int count = sizeof(*mpc);
917 unsigned char *mpt = ((unsigned char *)mpc) + count;
919 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
920 while (count < mpc->mpc_length) {
924 struct mpc_config_processor *m =
925 (struct mpc_config_processor *)mpt;
932 struct mpc_config_bus *m =
933 (struct mpc_config_bus *)mpt;
940 mpt += sizeof(struct mpc_config_ioapic);
941 count += sizeof(struct mpc_config_ioapic);
946 #ifdef CONFIG_X86_IO_APIC
947 struct mpc_config_intsrc *m =
948 (struct mpc_config_intsrc *)mpt;
950 printk(KERN_INFO "OLD ");
951 print_MP_intsrc_info(m);
952 i = get_MP_intsrc_index(m);
954 assign_to_mpc_intsrc(&mp_irqs[i], m);
955 printk(KERN_INFO "NEW ");
956 print_mp_irq_info(&mp_irqs[i]);
958 /* legacy, do nothing */
959 } else if (nr_m_spare < SPARE_SLOT_NUM) {
961 * not found (-1), or duplicated (-2)
962 * are invalid entries,
963 * we need to use the slot later
965 m_spare[nr_m_spare] = m;
969 mpt += sizeof(struct mpc_config_intsrc);
970 count += sizeof(struct mpc_config_intsrc);
975 struct mpc_config_lintsrc *m =
976 (struct mpc_config_lintsrc *)mpt;
983 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
984 printk(KERN_ERR "type %x\n", *mpt);
985 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
986 1, mpc, mpc->mpc_length, 1);
991 #ifdef CONFIG_X86_IO_APIC
992 for (i = 0; i < mp_irq_entries; i++) {
996 if (mp_irqs[i].mp_irqtype != mp_INT)
999 if (mp_irqs[i].mp_irqflag != 0x0f)
1002 if (nr_m_spare > 0) {
1003 printk(KERN_INFO "*NEW* found ");
1005 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1006 m_spare[nr_m_spare] = NULL;
1008 struct mpc_config_intsrc *m =
1009 (struct mpc_config_intsrc *)mpt;
1010 count += sizeof(struct mpc_config_intsrc);
1011 if (!mpc_new_phys) {
1012 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1014 if (count <= mpc_new_length)
1015 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1017 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1021 assign_to_mpc_intsrc(&mp_irqs[i], m);
1022 mpc->mpc_length = count;
1023 mpt += sizeof(struct mpc_config_intsrc);
1025 print_mp_irq_info(&mp_irqs[i]);
1029 /* update checksum */
1030 mpc->mpc_checksum = 0;
1031 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1037 int __initdata enable_update_mptable;
1039 static int __init update_mptable_setup(char *str)
1041 enable_update_mptable = 1;
1044 early_param("update_mptable", update_mptable_setup);
1046 static unsigned long __initdata mpc_new_phys;
1047 static unsigned long mpc_new_length __initdata = 4096;
1049 /* alloc_mptable or alloc_mptable=4k */
1050 static int __initdata alloc_mptable;
1051 static int __init parse_alloc_mptable_opt(char *p)
1053 enable_update_mptable = 1;
1057 mpc_new_length = memparse(p, &p);
1060 early_param("alloc_mptable", parse_alloc_mptable_opt);
1062 void __init early_reserve_e820_mpc_new(void)
1064 if (enable_update_mptable && alloc_mptable) {
1066 #ifdef CONFIG_X86_TRAMPOLINE
1067 startt = TRAMPOLINE_BASE;
1069 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1073 static int __init update_mp_table(void)
1077 struct intel_mp_floating *mpf;
1078 struct mp_config_table *mpc;
1079 struct mp_config_table *mpc_new;
1081 if (!enable_update_mptable)
1089 * Now see if we need to go further.
1091 if (mpf->mpf_feature1 != 0)
1094 if (!mpf->mpf_physptr)
1097 mpc = phys_to_virt(mpf->mpf_physptr);
1099 if (!smp_check_mpc(mpc, oem, str))
1102 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1103 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1105 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1107 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1111 if (!mpc_new_phys) {
1112 unsigned char old, new;
1113 /* check if we can change the postion */
1114 mpc->mpc_checksum = 0;
1115 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1116 mpc->mpc_checksum = 0xff;
1117 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1119 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1122 printk(KERN_INFO "use in-positon replacing\n");
1124 mpf->mpf_physptr = mpc_new_phys;
1125 mpc_new = phys_to_virt(mpc_new_phys);
1126 memcpy(mpc_new, mpc, mpc->mpc_length);
1128 /* check if we can modify that */
1129 if (mpc_new_phys - mpf->mpf_physptr) {
1130 struct intel_mp_floating *mpf_new;
1131 /* steal 16 bytes from [0, 1k) */
1132 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1133 mpf_new = phys_to_virt(0x400 - 16);
1134 memcpy(mpf_new, mpf, 16);
1136 mpf->mpf_physptr = mpc_new_phys;
1138 mpf->mpf_checksum = 0;
1139 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1140 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1144 * only replace the one with mp_INT and
1145 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1146 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1147 * may need pci=routeirq for all coverage
1149 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1154 late_initcall(update_mp_table);