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 <mach_apic.h>
31 #include <mach_apicdef.h>
32 #include <mach_mpparse.h>
36 * Checksum an MP configuration block.
39 static int __init mpf_checksum(unsigned char *mp, int len)
49 #ifdef CONFIG_X86_NUMAQ
51 * Have to match translation table entries to main table entries by counter
52 * hence the mpc_record variable .... can't see a less disgusting way of
56 static int mpc_record;
57 static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
61 static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
64 char *bootup_cpu = "";
66 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
70 #ifdef CONFIG_X86_NUMAQ
71 apicid = mpc_apic_id(m, translation_table[mpc_record]);
73 apicid = m->mpc_apicid;
75 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
76 bootup_cpu = " (Bootup-CPU)";
77 boot_cpu_physical_apicid = m->mpc_apicid;
80 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
81 generic_processor_info(apicid, m->mpc_apicver);
84 static void __init MP_bus_info(struct mpc_config_bus *m)
87 memcpy(str, m->mpc_bustype, 6);
90 #ifdef CONFIG_X86_NUMAQ
91 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
93 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
96 #if MAX_MP_BUSSES < 256
97 if (m->mpc_busid >= MAX_MP_BUSSES) {
98 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
99 " is too large, max. supported is %d\n",
100 m->mpc_busid, str, MAX_MP_BUSSES - 1);
105 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
106 set_bit(m->mpc_busid, mp_bus_not_pci);
107 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
108 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
110 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
111 #ifdef CONFIG_X86_NUMAQ
112 mpc_oem_pci_bus(m, translation_table[mpc_record]);
114 clear_bit(m->mpc_busid, mp_bus_not_pci);
115 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
116 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
117 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
118 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
119 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
120 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
123 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
126 #ifdef CONFIG_X86_IO_APIC
128 static int bad_ioapic(unsigned long address)
130 if (nr_ioapics >= MAX_IO_APICS) {
131 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
132 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
133 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
136 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
137 " found in table, skipping!\n");
143 static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
145 if (!(m->mpc_flags & MPC_APIC_USABLE))
148 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
149 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
151 if (bad_ioapic(m->mpc_apicaddr))
154 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
155 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
156 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
157 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
158 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
162 static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
164 printk(KERN_INFO "Int: type %d, pol %d, trig %d, bus %02x,"
165 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
166 m->mpc_irqtype, m->mpc_irqflag & 3,
167 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
168 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
169 mp_irqs[mp_irq_entries].mp_dstapic = m->mpc_dstapic;
170 mp_irqs[mp_irq_entries].mp_type = m->mpc_type;
171 mp_irqs[mp_irq_entries].mp_irqtype = m->mpc_irqtype;
172 mp_irqs[mp_irq_entries].mp_irqflag = m->mpc_irqflag;
173 mp_irqs[mp_irq_entries].mp_srcbus = m->mpc_srcbus;
174 mp_irqs[mp_irq_entries].mp_srcbusirq = m->mpc_srcbusirq;
175 mp_irqs[mp_irq_entries].mp_dstirq = m->mpc_dstirq;
176 if (++mp_irq_entries == MAX_IRQ_SOURCES)
177 panic("Max # of irq sources exceeded!!\n");
182 static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
184 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
185 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
186 m->mpc_irqtype, m->mpc_irqflag & 3,
187 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
188 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
191 #ifdef CONFIG_X86_NUMAQ
192 static void __init MP_translation_info(struct mpc_config_translation *m)
195 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
196 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
199 if (mpc_record >= MAX_MPC_ENTRY)
200 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
202 translation_table[mpc_record] = m; /* stash this for later */
203 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
204 node_set_online(m->trans_quad);
208 * Read/parse the MPC oem tables
211 static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
212 unsigned short oemsize)
214 int count = sizeof(*oemtable); /* the header size */
215 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
218 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
220 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
222 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
223 oemtable->oem_signature[0], oemtable->oem_signature[1],
224 oemtable->oem_signature[2], oemtable->oem_signature[3]);
227 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
228 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
231 while (count < oemtable->oem_length) {
235 struct mpc_config_translation *m =
236 (struct mpc_config_translation *)oemptr;
237 MP_translation_info(m);
238 oemptr += sizeof(*m);
246 "Unrecognised OEM table entry type! - %d\n",
254 static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
257 if (strncmp(oem, "IBM NUMA", 8))
258 printk("Warning! May not be a NUMA-Q system!\n");
260 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
263 #endif /* CONFIG_X86_NUMAQ */
269 static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
273 int count = sizeof(*mpc);
274 unsigned char *mpt = ((unsigned char *)mpc) + count;
276 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
277 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
278 mpc->mpc_signature[0], mpc->mpc_signature[1],
279 mpc->mpc_signature[2], mpc->mpc_signature[3]);
282 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
283 printk(KERN_ERR "MPTABLE: checksum error!\n");
286 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
287 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
291 if (!mpc->mpc_lapic) {
292 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
295 memcpy(oem, mpc->mpc_oem, 8);
297 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
299 memcpy(str, mpc->mpc_productid, 12);
303 mps_oem_check(mpc, oem, str);
305 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
307 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
309 /* save the local APIC address, it might be non-default */
311 mp_lapic_addr = mpc->mpc_lapic;
317 * Now process the configuration blocks.
319 #ifdef CONFIG_X86_NUMAQ
322 while (count < mpc->mpc_length) {
326 struct mpc_config_processor *m =
327 (struct mpc_config_processor *)mpt;
328 /* ACPI may have already provided this data */
330 MP_processor_info(m);
337 struct mpc_config_bus *m =
338 (struct mpc_config_bus *)mpt;
346 #ifdef CONFIG_X86_IO_APIC
347 struct mpc_config_ioapic *m =
348 (struct mpc_config_ioapic *)mpt;
351 mpt += sizeof(struct mpc_config_ioapic);
352 count += sizeof(struct mpc_config_ioapic);
357 #ifdef CONFIG_X86_IO_APIC
358 struct mpc_config_intsrc *m =
359 (struct mpc_config_intsrc *)mpt;
363 mpt += sizeof(struct mpc_config_intsrc);
364 count += sizeof(struct mpc_config_intsrc);
369 struct mpc_config_lintsrc *m =
370 (struct mpc_config_lintsrc *)mpt;
378 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
379 printk(KERN_ERR "type %x\n", *mpt);
380 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
381 1, mpc, mpc->mpc_length, 1);
382 count = mpc->mpc_length;
385 #ifdef CONFIG_X86_NUMAQ
389 setup_apic_routing();
391 printk(KERN_ERR "MPTABLE: no processors registered!\n");
392 return num_processors;
395 #ifdef CONFIG_X86_IO_APIC
397 static int __init ELCR_trigger(unsigned int irq)
401 port = 0x4d0 + (irq >> 3);
402 return (inb(port) >> (irq & 7)) & 1;
405 static void __init construct_default_ioirq_mptable(int mpc_default_type)
407 struct mpc_config_intsrc intsrc;
409 int ELCR_fallback = 0;
411 intsrc.mpc_type = MP_INTSRC;
412 intsrc.mpc_irqflag = 0; /* conforming */
413 intsrc.mpc_srcbus = 0;
414 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
416 intsrc.mpc_irqtype = mp_INT;
419 * If true, we have an ISA/PCI system with no IRQ entries
420 * in the MP table. To prevent the PCI interrupts from being set up
421 * incorrectly, we try to use the ELCR. The sanity check to see if
422 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
423 * never be level sensitive, so we simply see if the ELCR agrees.
424 * If it does, we assume it's valid.
426 if (mpc_default_type == 5) {
427 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
428 "falling back to ELCR\n");
430 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
432 printk(KERN_ERR "ELCR contains invalid data... "
436 "Using ELCR to identify PCI interrupts\n");
441 for (i = 0; i < 16; i++) {
442 switch (mpc_default_type) {
444 if (i == 0 || i == 13)
445 continue; /* IRQ0 & IRQ13 not connected */
449 continue; /* IRQ2 is never connected */
454 * If the ELCR indicates a level-sensitive interrupt, we
455 * copy that information over to the MP table in the
456 * irqflag field (level sensitive, active high polarity).
459 intsrc.mpc_irqflag = 13;
461 intsrc.mpc_irqflag = 0;
464 intsrc.mpc_srcbusirq = i;
465 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
466 MP_intsrc_info(&intsrc);
469 intsrc.mpc_irqtype = mp_ExtINT;
470 intsrc.mpc_srcbusirq = 0;
471 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
472 MP_intsrc_info(&intsrc);
477 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
479 struct mpc_config_processor processor;
480 struct mpc_config_bus bus;
481 #ifdef CONFIG_X86_IO_APIC
482 struct mpc_config_ioapic ioapic;
484 struct mpc_config_lintsrc lintsrc;
485 int linttypes[2] = { mp_ExtINT, mp_NMI };
489 * local APIC has default address
491 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
494 * 2 CPUs, numbered 0 & 1.
496 processor.mpc_type = MP_PROCESSOR;
497 /* Either an integrated APIC or a discrete 82489DX. */
498 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
499 processor.mpc_cpuflag = CPU_ENABLED;
500 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
501 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
502 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
503 processor.mpc_reserved[0] = 0;
504 processor.mpc_reserved[1] = 0;
505 for (i = 0; i < 2; i++) {
506 processor.mpc_apicid = i;
507 MP_processor_info(&processor);
510 bus.mpc_type = MP_BUS;
512 switch (mpc_default_type) {
514 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
519 memcpy(bus.mpc_bustype, "ISA ", 6);
524 memcpy(bus.mpc_bustype, "EISA ", 6);
528 memcpy(bus.mpc_bustype, "MCA ", 6);
531 if (mpc_default_type > 4) {
533 memcpy(bus.mpc_bustype, "PCI ", 6);
537 #ifdef CONFIG_X86_IO_APIC
538 ioapic.mpc_type = MP_IOAPIC;
539 ioapic.mpc_apicid = 2;
540 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
541 ioapic.mpc_flags = MPC_APIC_USABLE;
542 ioapic.mpc_apicaddr = 0xFEC00000;
543 MP_ioapic_info(&ioapic);
546 * We set up most of the low 16 IO-APIC pins according to MPS rules.
548 construct_default_ioirq_mptable(mpc_default_type);
550 lintsrc.mpc_type = MP_LINTSRC;
551 lintsrc.mpc_irqflag = 0; /* conforming */
552 lintsrc.mpc_srcbusid = 0;
553 lintsrc.mpc_srcbusirq = 0;
554 lintsrc.mpc_destapic = MP_APIC_ALL;
555 for (i = 0; i < 2; i++) {
556 lintsrc.mpc_irqtype = linttypes[i];
557 lintsrc.mpc_destapiclint = i;
558 MP_lintsrc_info(&lintsrc);
562 static struct intel_mp_floating *mpf_found;
565 * Scan the memory blocks for an SMP configuration block.
567 static void __init __get_smp_config(unsigned early)
569 struct intel_mp_floating *mpf = mpf_found;
571 if (acpi_lapic && early)
574 * ACPI supports both logical (e.g. Hyper-Threading) and physical
575 * processors, where MPS only supports physical.
577 if (acpi_lapic && acpi_ioapic) {
578 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
581 } else if (acpi_lapic)
582 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
583 "configuration information\n");
585 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
586 mpf->mpf_specification);
587 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
588 if (mpf->mpf_feature2 & (1 << 7)) {
589 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
592 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
597 * Now see if we need to read further.
599 if (mpf->mpf_feature1 != 0) {
602 * local APIC has default address
604 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
608 printk(KERN_INFO "Default MP configuration #%d\n",
610 construct_default_ISA_mptable(mpf->mpf_feature1);
612 } else if (mpf->mpf_physptr) {
615 * Read the physical hardware table. Anything here will
616 * override the defaults.
618 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
619 #ifdef CONFIG_X86_LOCAL_APIC
620 smp_found_config = 0;
623 "BIOS bug, MP table errors detected!...\n");
624 printk(KERN_ERR "... disabling SMP support. "
625 "(tell your hw vendor)\n");
631 #ifdef CONFIG_X86_IO_APIC
633 * If there are no explicit MP IRQ entries, then we are
634 * broken. We set up most of the low 16 IO-APIC pins to
635 * ISA defaults and hope it will work.
637 if (!mp_irq_entries) {
638 struct mpc_config_bus bus;
640 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
641 "using default mptable. "
642 "(tell your hw vendor)\n");
644 bus.mpc_type = MP_BUS;
646 memcpy(bus.mpc_bustype, "ISA ", 6);
649 construct_default_ioirq_mptable(0);
656 printk(KERN_INFO "Processors: %d\n", num_processors);
658 * Only use the first configuration found.
662 void __init early_get_smp_config(void)
667 void __init get_smp_config(void)
672 static int __init smp_scan_config(unsigned long base, unsigned long length,
675 unsigned int *bp = phys_to_virt(base);
676 struct intel_mp_floating *mpf;
678 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
679 BUILD_BUG_ON(sizeof(*mpf) != 16);
682 mpf = (struct intel_mp_floating *)bp;
683 if ((*bp == SMP_MAGIC_IDENT) &&
684 (mpf->mpf_length == 1) &&
685 !mpf_checksum((unsigned char *)bp, 16) &&
686 ((mpf->mpf_specification == 1)
687 || (mpf->mpf_specification == 4))) {
688 #ifdef CONFIG_X86_LOCAL_APIC
689 smp_found_config = 1;
693 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
694 mpf, virt_to_phys(mpf));
695 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
697 if (mpf->mpf_physptr) {
699 * We cannot access to MPC table to compute
700 * table size yet, as only few megabytes from
701 * the bottom is mapped now.
702 * PC-9800's MPC table places on the very last
703 * of physical memory; so that simply reserving
704 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
705 * in reserve_bootmem.
707 unsigned long size = PAGE_SIZE;
708 unsigned long end = max_low_pfn * PAGE_SIZE;
709 if (mpf->mpf_physptr + size > end)
710 size = end - mpf->mpf_physptr;
711 reserve_bootmem(mpf->mpf_physptr, size,
719 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
720 if (mpf->mpf_physptr)
721 reserve_bootmem_generic(mpf->mpf_physptr,
732 static void __init __find_smp_config(unsigned reserve)
734 unsigned int address;
737 * FIXME: Linux assumes you have 640K of base ram..
738 * this continues the error...
740 * 1) Scan the bottom 1K for a signature
741 * 2) Scan the top 1K of base RAM
742 * 3) Scan the 64K of bios
744 if (smp_scan_config(0x0, 0x400, reserve) ||
745 smp_scan_config(639 * 0x400, 0x400, reserve) ||
746 smp_scan_config(0xF0000, 0x10000, reserve))
749 * If it is an SMP machine we should know now, unless the
750 * configuration is in an EISA/MCA bus machine with an
751 * extended bios data area.
753 * there is a real-mode segmented pointer pointing to the
754 * 4K EBDA area at 0x40E, calculate and scan it here.
756 * NOTE! There are Linux loaders that will corrupt the EBDA
757 * area, and as such this kind of SMP config may be less
758 * trustworthy, simply because the SMP table may have been
759 * stomped on during early boot. These loaders are buggy and
762 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
765 address = get_bios_ebda();
767 smp_scan_config(address, 0x400, reserve);
770 void __init early_find_smp_config(void)
772 __find_smp_config(0);
775 void __init find_smp_config(void)
777 __find_smp_config(1);