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 * Various Linux-internal data structures created from the
39 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
40 int mp_bus_id_to_type[MAX_MP_BUSSES];
43 DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
46 * Checksum an MP configuration block.
49 static int __init mpf_checksum(unsigned char *mp, int len)
59 #ifdef CONFIG_X86_NUMAQ
61 * Have to match translation table entries to main table entries by counter
62 * hence the mpc_record variable .... can't see a less disgusting way of
66 static int mpc_record;
67 static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
71 static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
74 char *bootup_cpu = "";
76 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
80 #ifdef CONFIG_X86_NUMAQ
81 apicid = mpc_apic_id(m, translation_table[mpc_record]);
83 apicid = m->mpc_apicid;
85 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
86 bootup_cpu = " (Bootup-CPU)";
87 boot_cpu_physical_apicid = m->mpc_apicid;
90 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
91 generic_processor_info(apicid, m->mpc_apicver);
94 static void __init MP_bus_info(struct mpc_config_bus *m)
97 memcpy(str, m->mpc_bustype, 6);
100 #ifdef CONFIG_X86_NUMAQ
101 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
103 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
106 #if MAX_MP_BUSSES < 256
107 if (m->mpc_busid >= MAX_MP_BUSSES) {
108 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
109 " is too large, max. supported is %d\n",
110 m->mpc_busid, str, MAX_MP_BUSSES - 1);
115 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
116 set_bit(m->mpc_busid, mp_bus_not_pci);
117 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
118 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
120 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
121 #ifdef CONFIG_X86_NUMAQ
122 mpc_oem_pci_bus(m, translation_table[mpc_record]);
124 clear_bit(m->mpc_busid, mp_bus_not_pci);
125 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
126 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
127 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
128 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
129 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
130 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
133 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
136 #ifdef CONFIG_X86_IO_APIC
138 static int bad_ioapic(unsigned long address)
140 if (nr_ioapics >= MAX_IO_APICS) {
141 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
142 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
143 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
146 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
147 " found in table, skipping!\n");
153 static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
155 if (!(m->mpc_flags & MPC_APIC_USABLE))
158 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
159 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
161 if (bad_ioapic(m->mpc_apicaddr))
164 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
165 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
166 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
167 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
168 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
172 static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
174 printk(KERN_INFO "Int: type %d, pol %d, trig %d, bus %02x,"
175 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
176 m->mpc_irqtype, m->mpc_irqflag & 3,
177 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
178 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
179 mp_irqs[mp_irq_entries].mp_dstapic = m->mpc_dstapic;
180 mp_irqs[mp_irq_entries].mp_type = m->mpc_type;
181 mp_irqs[mp_irq_entries].mp_irqtype = m->mpc_irqtype;
182 mp_irqs[mp_irq_entries].mp_irqflag = m->mpc_irqflag;
183 mp_irqs[mp_irq_entries].mp_srcbus = m->mpc_srcbus;
184 mp_irqs[mp_irq_entries].mp_srcbusirq = m->mpc_srcbusirq;
185 mp_irqs[mp_irq_entries].mp_dstirq = m->mpc_dstirq;
186 if (++mp_irq_entries == MAX_IRQ_SOURCES)
187 panic("Max # of irq sources exceeded!!\n");
192 static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
194 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
195 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
196 m->mpc_irqtype, m->mpc_irqflag & 3,
197 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
198 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
201 #ifdef CONFIG_X86_NUMAQ
202 static void __init MP_translation_info(struct mpc_config_translation *m)
205 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
206 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
209 if (mpc_record >= MAX_MPC_ENTRY)
210 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
212 translation_table[mpc_record] = m; /* stash this for later */
213 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
214 node_set_online(m->trans_quad);
218 * Read/parse the MPC oem tables
221 static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
222 unsigned short oemsize)
224 int count = sizeof(*oemtable); /* the header size */
225 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
228 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
230 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
232 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
233 oemtable->oem_signature[0], oemtable->oem_signature[1],
234 oemtable->oem_signature[2], oemtable->oem_signature[3]);
237 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
238 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
241 while (count < oemtable->oem_length) {
245 struct mpc_config_translation *m =
246 (struct mpc_config_translation *)oemptr;
247 MP_translation_info(m);
248 oemptr += sizeof(*m);
256 "Unrecognised OEM table entry type! - %d\n",
264 static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
267 if (strncmp(oem, "IBM NUMA", 8))
268 printk("Warning! May not be a NUMA-Q system!\n");
270 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
273 #endif /* CONFIG_X86_NUMAQ */
279 static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
283 int count = sizeof(*mpc);
284 unsigned char *mpt = ((unsigned char *)mpc) + count;
286 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
287 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
288 mpc->mpc_signature[0], mpc->mpc_signature[1],
289 mpc->mpc_signature[2], mpc->mpc_signature[3]);
292 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
293 printk(KERN_ERR "MPTABLE: checksum error!\n");
296 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
297 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
301 if (!mpc->mpc_lapic) {
302 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
305 memcpy(oem, mpc->mpc_oem, 8);
307 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
309 memcpy(str, mpc->mpc_productid, 12);
313 mps_oem_check(mpc, oem, str);
315 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
317 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
319 /* save the local APIC address, it might be non-default */
321 mp_lapic_addr = mpc->mpc_lapic;
327 * Now process the configuration blocks.
329 #ifdef CONFIG_X86_NUMAQ
332 while (count < mpc->mpc_length) {
336 struct mpc_config_processor *m =
337 (struct mpc_config_processor *)mpt;
338 /* ACPI may have already provided this data */
340 MP_processor_info(m);
347 struct mpc_config_bus *m =
348 (struct mpc_config_bus *)mpt;
356 #ifdef CONFIG_X86_IO_APIC
357 struct mpc_config_ioapic *m =
358 (struct mpc_config_ioapic *)mpt;
361 mpt += sizeof(struct mpc_config_ioapic);
362 count += sizeof(struct mpc_config_ioapic);
367 #ifdef CONFIG_X86_IO_APIC
368 struct mpc_config_intsrc *m =
369 (struct mpc_config_intsrc *)mpt;
373 mpt += sizeof(struct mpc_config_intsrc);
374 count += sizeof(struct mpc_config_intsrc);
379 struct mpc_config_lintsrc *m =
380 (struct mpc_config_lintsrc *)mpt;
388 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
389 printk(KERN_ERR "type %x\n", *mpt);
390 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
391 1, mpc, mpc->mpc_length, 1);
392 count = mpc->mpc_length;
395 #ifdef CONFIG_X86_NUMAQ
399 setup_apic_routing();
401 printk(KERN_ERR "MPTABLE: no processors registered!\n");
402 return num_processors;
405 #ifdef CONFIG_X86_IO_APIC
407 static int __init ELCR_trigger(unsigned int irq)
411 port = 0x4d0 + (irq >> 3);
412 return (inb(port) >> (irq & 7)) & 1;
415 static void __init construct_default_ioirq_mptable(int mpc_default_type)
417 struct mpc_config_intsrc intsrc;
419 int ELCR_fallback = 0;
421 intsrc.mpc_type = MP_INTSRC;
422 intsrc.mpc_irqflag = 0; /* conforming */
423 intsrc.mpc_srcbus = 0;
424 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
426 intsrc.mpc_irqtype = mp_INT;
429 * If true, we have an ISA/PCI system with no IRQ entries
430 * in the MP table. To prevent the PCI interrupts from being set up
431 * incorrectly, we try to use the ELCR. The sanity check to see if
432 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
433 * never be level sensitive, so we simply see if the ELCR agrees.
434 * If it does, we assume it's valid.
436 if (mpc_default_type == 5) {
437 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
438 "falling back to ELCR\n");
440 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
442 printk(KERN_ERR "ELCR contains invalid data... "
446 "Using ELCR to identify PCI interrupts\n");
451 for (i = 0; i < 16; i++) {
452 switch (mpc_default_type) {
454 if (i == 0 || i == 13)
455 continue; /* IRQ0 & IRQ13 not connected */
459 continue; /* IRQ2 is never connected */
464 * If the ELCR indicates a level-sensitive interrupt, we
465 * copy that information over to the MP table in the
466 * irqflag field (level sensitive, active high polarity).
469 intsrc.mpc_irqflag = 13;
471 intsrc.mpc_irqflag = 0;
474 intsrc.mpc_srcbusirq = i;
475 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
476 MP_intsrc_info(&intsrc);
479 intsrc.mpc_irqtype = mp_ExtINT;
480 intsrc.mpc_srcbusirq = 0;
481 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
482 MP_intsrc_info(&intsrc);
487 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
489 struct mpc_config_processor processor;
490 struct mpc_config_bus bus;
491 #ifdef CONFIG_X86_IO_APIC
492 struct mpc_config_ioapic ioapic;
494 struct mpc_config_lintsrc lintsrc;
495 int linttypes[2] = { mp_ExtINT, mp_NMI };
499 * local APIC has default address
501 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
504 * 2 CPUs, numbered 0 & 1.
506 processor.mpc_type = MP_PROCESSOR;
507 /* Either an integrated APIC or a discrete 82489DX. */
508 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
509 processor.mpc_cpuflag = CPU_ENABLED;
510 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
511 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
512 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
513 processor.mpc_reserved[0] = 0;
514 processor.mpc_reserved[1] = 0;
515 for (i = 0; i < 2; i++) {
516 processor.mpc_apicid = i;
517 MP_processor_info(&processor);
520 bus.mpc_type = MP_BUS;
522 switch (mpc_default_type) {
524 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
529 memcpy(bus.mpc_bustype, "ISA ", 6);
534 memcpy(bus.mpc_bustype, "EISA ", 6);
538 memcpy(bus.mpc_bustype, "MCA ", 6);
541 if (mpc_default_type > 4) {
543 memcpy(bus.mpc_bustype, "PCI ", 6);
547 #ifdef CONFIG_X86_IO_APIC
548 ioapic.mpc_type = MP_IOAPIC;
549 ioapic.mpc_apicid = 2;
550 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
551 ioapic.mpc_flags = MPC_APIC_USABLE;
552 ioapic.mpc_apicaddr = 0xFEC00000;
553 MP_ioapic_info(&ioapic);
556 * We set up most of the low 16 IO-APIC pins according to MPS rules.
558 construct_default_ioirq_mptable(mpc_default_type);
560 lintsrc.mpc_type = MP_LINTSRC;
561 lintsrc.mpc_irqflag = 0; /* conforming */
562 lintsrc.mpc_srcbusid = 0;
563 lintsrc.mpc_srcbusirq = 0;
564 lintsrc.mpc_destapic = MP_APIC_ALL;
565 for (i = 0; i < 2; i++) {
566 lintsrc.mpc_irqtype = linttypes[i];
567 lintsrc.mpc_destapiclint = i;
568 MP_lintsrc_info(&lintsrc);
572 static struct intel_mp_floating *mpf_found;
575 * Scan the memory blocks for an SMP configuration block.
577 static void __init __get_smp_config(unsigned early)
579 struct intel_mp_floating *mpf = mpf_found;
581 if (acpi_lapic && early)
584 * ACPI supports both logical (e.g. Hyper-Threading) and physical
585 * processors, where MPS only supports physical.
587 if (acpi_lapic && acpi_ioapic) {
588 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
591 } else if (acpi_lapic)
592 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
593 "configuration information\n");
595 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
596 mpf->mpf_specification);
597 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
598 if (mpf->mpf_feature2 & (1 << 7)) {
599 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
602 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
607 * Now see if we need to read further.
609 if (mpf->mpf_feature1 != 0) {
612 * local APIC has default address
614 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
618 printk(KERN_INFO "Default MP configuration #%d\n",
620 construct_default_ISA_mptable(mpf->mpf_feature1);
622 } else if (mpf->mpf_physptr) {
625 * Read the physical hardware table. Anything here will
626 * override the defaults.
628 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
629 #ifdef CONFIG_X86_LOCAL_APIC
630 smp_found_config = 0;
633 "BIOS bug, MP table errors detected!...\n");
634 printk(KERN_ERR "... disabling SMP support. "
635 "(tell your hw vendor)\n");
641 #ifdef CONFIG_X86_IO_APIC
643 * If there are no explicit MP IRQ entries, then we are
644 * broken. We set up most of the low 16 IO-APIC pins to
645 * ISA defaults and hope it will work.
647 if (!mp_irq_entries) {
648 struct mpc_config_bus bus;
650 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
651 "using default mptable. "
652 "(tell your hw vendor)\n");
654 bus.mpc_type = MP_BUS;
656 memcpy(bus.mpc_bustype, "ISA ", 6);
659 construct_default_ioirq_mptable(0);
666 printk(KERN_INFO "Processors: %d\n", num_processors);
668 * Only use the first configuration found.
672 void __init early_get_smp_config(void)
677 void __init get_smp_config(void)
682 static int __init smp_scan_config(unsigned long base, unsigned long length,
685 unsigned int *bp = phys_to_virt(base);
686 struct intel_mp_floating *mpf;
688 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
689 BUILD_BUG_ON(sizeof(*mpf) != 16);
692 mpf = (struct intel_mp_floating *)bp;
693 if ((*bp == SMP_MAGIC_IDENT) &&
694 (mpf->mpf_length == 1) &&
695 !mpf_checksum((unsigned char *)bp, 16) &&
696 ((mpf->mpf_specification == 1)
697 || (mpf->mpf_specification == 4))) {
698 #ifdef CONFIG_X86_LOCAL_APIC
699 smp_found_config = 1;
703 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
704 mpf, virt_to_phys(mpf));
705 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
707 if (mpf->mpf_physptr) {
709 * We cannot access to MPC table to compute
710 * table size yet, as only few megabytes from
711 * the bottom is mapped now.
712 * PC-9800's MPC table places on the very last
713 * of physical memory; so that simply reserving
714 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
715 * in reserve_bootmem.
717 unsigned long size = PAGE_SIZE;
718 unsigned long end = max_low_pfn * PAGE_SIZE;
719 if (mpf->mpf_physptr + size > end)
720 size = end - mpf->mpf_physptr;
721 reserve_bootmem(mpf->mpf_physptr, size,
729 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
730 if (mpf->mpf_physptr)
731 reserve_bootmem_generic(mpf->mpf_physptr,
742 static void __init __find_smp_config(unsigned reserve)
744 unsigned int address;
747 * FIXME: Linux assumes you have 640K of base ram..
748 * this continues the error...
750 * 1) Scan the bottom 1K for a signature
751 * 2) Scan the top 1K of base RAM
752 * 3) Scan the 64K of bios
754 if (smp_scan_config(0x0, 0x400, reserve) ||
755 smp_scan_config(639 * 0x400, 0x400, reserve) ||
756 smp_scan_config(0xF0000, 0x10000, reserve))
759 * If it is an SMP machine we should know now, unless the
760 * configuration is in an EISA/MCA bus machine with an
761 * extended bios data area.
763 * there is a real-mode segmented pointer pointing to the
764 * 4K EBDA area at 0x40E, calculate and scan it here.
766 * NOTE! There are Linux loaders that will corrupt the EBDA
767 * area, and as such this kind of SMP config may be less
768 * trustworthy, simply because the SMP table may have been
769 * stomped on during early boot. These loaders are buggy and
772 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
775 address = get_bios_ebda();
777 smp_scan_config(address, 0x400, reserve);
780 void __init early_find_smp_config(void)
782 __find_smp_config(0);
785 void __init find_smp_config(void)
787 __find_smp_config(1);