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
54 * Have to match translation table entries to main table entries by counter
55 * hence the mpc_record variable .... can't see a less disgusting way of
58 struct mpc_config_translation {
59 unsigned char mpc_type;
60 unsigned char trans_len;
61 unsigned char trans_type;
62 unsigned char trans_quad;
63 unsigned char trans_global;
64 unsigned char trans_local;
65 unsigned short trans_reserved;
69 static int mpc_record;
70 static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY]
73 static inline int generate_logical_apicid(int quad, int phys_apicid)
75 return (quad << 4) + (phys_apicid ? phys_apicid << 1 : 1);
79 static inline int mpc_apic_id(struct mpc_config_processor *m,
80 struct mpc_config_translation *translation_record)
82 int quad = translation_record->trans_quad;
83 int logical_apicid = generate_logical_apicid(quad, m->mpc_apicid);
85 printk(KERN_DEBUG "Processor #%d %u:%u APIC version %d (quad %d, apic %d)\n",
87 (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
88 (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
89 m->mpc_apicver, quad, logical_apicid);
90 return logical_apicid;
93 int mp_bus_id_to_node[MAX_MP_BUSSES];
95 int mp_bus_id_to_local[MAX_MP_BUSSES];
97 static void mpc_oem_bus_info(struct mpc_config_bus *m, char *name,
98 struct mpc_config_translation *translation)
100 int quad = translation->trans_quad;
101 int local = translation->trans_local;
103 mp_bus_id_to_node[m->mpc_busid] = quad;
104 mp_bus_id_to_local[m->mpc_busid] = local;
105 printk(KERN_INFO "Bus #%d is %s (node %d)\n",
106 m->mpc_busid, name, quad);
109 int quad_local_to_mp_bus_id [NR_CPUS/4][4];
110 static void mpc_oem_pci_bus(struct mpc_config_bus *m,
111 struct mpc_config_translation *translation)
113 int quad = translation->trans_quad;
114 int local = translation->trans_local;
116 quad_local_to_mp_bus_id[quad][local] = m->mpc_busid;
121 static void __cpuinit MP_processor_info(struct mpc_config_processor *m)
124 char *bootup_cpu = "";
126 if (!(m->mpc_cpuflag & CPU_ENABLED)) {
130 #ifdef CONFIG_X86_NUMAQ
132 apicid = mpc_apic_id(m, translation_table[mpc_record]);
134 apicid = m->mpc_apicid;
136 apicid = m->mpc_apicid;
138 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
139 bootup_cpu = " (Bootup-CPU)";
140 boot_cpu_physical_apicid = m->mpc_apicid;
143 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
144 generic_processor_info(apicid, m->mpc_apicver);
147 #ifdef CONFIG_X86_IO_APIC
148 static void __init MP_bus_info(struct mpc_config_bus *m)
151 memcpy(str, m->mpc_bustype, 6);
154 #ifdef CONFIG_X86_NUMAQ
156 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
158 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
161 #if MAX_MP_BUSSES < 256
162 if (m->mpc_busid >= MAX_MP_BUSSES) {
163 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
164 " is too large, max. supported is %d\n",
165 m->mpc_busid, str, MAX_MP_BUSSES - 1);
170 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
171 set_bit(m->mpc_busid, mp_bus_not_pci);
172 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
173 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
175 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
176 #ifdef CONFIG_X86_NUMAQ
178 mpc_oem_pci_bus(m, translation_table[mpc_record]);
180 clear_bit(m->mpc_busid, mp_bus_not_pci);
181 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
182 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
183 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
184 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
185 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
186 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
189 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
193 #ifdef CONFIG_X86_IO_APIC
195 static int bad_ioapic(unsigned long address)
197 if (nr_ioapics >= MAX_IO_APICS) {
198 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
199 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
200 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
203 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
204 " found in table, skipping!\n");
210 static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
212 if (!(m->mpc_flags & MPC_APIC_USABLE))
215 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
216 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
218 if (bad_ioapic(m->mpc_apicaddr))
221 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
222 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
223 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
224 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
225 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
229 static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
231 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
232 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
233 m->mpc_irqtype, m->mpc_irqflag & 3,
234 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
235 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
238 static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
240 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
241 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
242 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
243 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
244 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
247 static void __init assign_to_mp_irq(struct mpc_config_intsrc *m,
248 struct mp_config_intsrc *mp_irq)
250 mp_irq->mp_dstapic = m->mpc_dstapic;
251 mp_irq->mp_type = m->mpc_type;
252 mp_irq->mp_irqtype = m->mpc_irqtype;
253 mp_irq->mp_irqflag = m->mpc_irqflag;
254 mp_irq->mp_srcbus = m->mpc_srcbus;
255 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
256 mp_irq->mp_dstirq = m->mpc_dstirq;
259 static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
260 struct mpc_config_intsrc *m)
262 m->mpc_dstapic = mp_irq->mp_dstapic;
263 m->mpc_type = mp_irq->mp_type;
264 m->mpc_irqtype = mp_irq->mp_irqtype;
265 m->mpc_irqflag = mp_irq->mp_irqflag;
266 m->mpc_srcbus = mp_irq->mp_srcbus;
267 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
268 m->mpc_dstirq = mp_irq->mp_dstirq;
271 static int __init mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
272 struct mpc_config_intsrc *m)
274 if (mp_irq->mp_dstapic != m->mpc_dstapic)
276 if (mp_irq->mp_type != m->mpc_type)
278 if (mp_irq->mp_irqtype != m->mpc_irqtype)
280 if (mp_irq->mp_irqflag != m->mpc_irqflag)
282 if (mp_irq->mp_srcbus != m->mpc_srcbus)
284 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
286 if (mp_irq->mp_dstirq != m->mpc_dstirq)
292 static void __init MP_intsrc_info(struct mpc_config_intsrc *m)
296 print_MP_intsrc_info(m);
298 for (i = 0; i < mp_irq_entries; i++) {
299 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
303 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
304 if (++mp_irq_entries == MAX_IRQ_SOURCES)
305 panic("Max # of irq sources exceeded!!\n");
310 static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
312 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
313 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
314 m->mpc_irqtype, m->mpc_irqflag & 3,
315 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
316 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
319 #ifdef CONFIG_X86_NUMAQ
320 static void __init MP_translation_info(struct mpc_config_translation *m)
323 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
324 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
327 if (mpc_record >= MAX_MPC_ENTRY)
328 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
330 translation_table[mpc_record] = m; /* stash this for later */
331 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
332 node_set_online(m->trans_quad);
336 * Read/parse the MPC oem tables
339 static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
340 unsigned short oemsize)
342 int count = sizeof(*oemtable); /* the header size */
343 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
346 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
348 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
350 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
351 oemtable->oem_signature[0], oemtable->oem_signature[1],
352 oemtable->oem_signature[2], oemtable->oem_signature[3]);
355 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
356 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
359 while (count < oemtable->oem_length) {
363 struct mpc_config_translation *m =
364 (struct mpc_config_translation *)oemptr;
365 MP_translation_info(m);
366 oemptr += sizeof(*m);
374 "Unrecognised OEM table entry type! - %d\n",
382 void numaq_mps_oem_check(struct mp_config_table *mpc, char *oem,
385 if (strncmp(oem, "IBM NUMA", 8))
386 printk("Warning! Not a NUMA-Q system!\n");
391 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
394 #endif /* CONFIG_X86_NUMAQ */
400 static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
404 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
405 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
406 mpc->mpc_signature[0], mpc->mpc_signature[1],
407 mpc->mpc_signature[2], mpc->mpc_signature[3]);
410 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
411 printk(KERN_ERR "MPTABLE: checksum error!\n");
414 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
415 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
419 if (!mpc->mpc_lapic) {
420 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
423 memcpy(oem, mpc->mpc_oem, 8);
425 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
427 memcpy(str, mpc->mpc_productid, 12);
430 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
432 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
437 static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
442 int count = sizeof(*mpc);
443 unsigned char *mpt = ((unsigned char *)mpc) + count;
445 if (!smp_check_mpc(mpc, oem, str))
450 * need to make sure summit and es7000's mps_oem_check is safe to be
451 * called early via genericarch 's mps_oem_check
454 #ifdef CONFIG_X86_NUMAQ
455 numaq_mps_oem_check(mpc, oem, str);
458 mps_oem_check(mpc, oem, str);
461 /* save the local APIC address, it might be non-default */
463 mp_lapic_addr = mpc->mpc_lapic;
469 * Now process the configuration blocks.
471 #ifdef CONFIG_X86_NUMAQ
474 while (count < mpc->mpc_length) {
478 struct mpc_config_processor *m =
479 (struct mpc_config_processor *)mpt;
480 /* ACPI may have already provided this data */
482 MP_processor_info(m);
489 struct mpc_config_bus *m =
490 (struct mpc_config_bus *)mpt;
491 #ifdef CONFIG_X86_IO_APIC
500 #ifdef CONFIG_X86_IO_APIC
501 struct mpc_config_ioapic *m =
502 (struct mpc_config_ioapic *)mpt;
505 mpt += sizeof(struct mpc_config_ioapic);
506 count += sizeof(struct mpc_config_ioapic);
511 #ifdef CONFIG_X86_IO_APIC
512 struct mpc_config_intsrc *m =
513 (struct mpc_config_intsrc *)mpt;
517 mpt += sizeof(struct mpc_config_intsrc);
518 count += sizeof(struct mpc_config_intsrc);
523 struct mpc_config_lintsrc *m =
524 (struct mpc_config_lintsrc *)mpt;
532 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
533 printk(KERN_ERR "type %x\n", *mpt);
534 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
535 1, mpc, mpc->mpc_length, 1);
536 count = mpc->mpc_length;
539 #ifdef CONFIG_X86_NUMAQ
544 #ifdef CONFIG_X86_GENERICARCH
545 generic_bigsmp_probe();
548 setup_apic_routing();
550 printk(KERN_ERR "MPTABLE: no processors registered!\n");
551 return num_processors;
554 #ifdef CONFIG_X86_IO_APIC
556 static int __init ELCR_trigger(unsigned int irq)
560 port = 0x4d0 + (irq >> 3);
561 return (inb(port) >> (irq & 7)) & 1;
564 static void __init construct_default_ioirq_mptable(int mpc_default_type)
566 struct mpc_config_intsrc intsrc;
568 int ELCR_fallback = 0;
570 intsrc.mpc_type = MP_INTSRC;
571 intsrc.mpc_irqflag = 0; /* conforming */
572 intsrc.mpc_srcbus = 0;
573 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
575 intsrc.mpc_irqtype = mp_INT;
578 * If true, we have an ISA/PCI system with no IRQ entries
579 * in the MP table. To prevent the PCI interrupts from being set up
580 * incorrectly, we try to use the ELCR. The sanity check to see if
581 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
582 * never be level sensitive, so we simply see if the ELCR agrees.
583 * If it does, we assume it's valid.
585 if (mpc_default_type == 5) {
586 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
587 "falling back to ELCR\n");
589 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
591 printk(KERN_ERR "ELCR contains invalid data... "
595 "Using ELCR to identify PCI interrupts\n");
600 for (i = 0; i < 16; i++) {
601 switch (mpc_default_type) {
603 if (i == 0 || i == 13)
604 continue; /* IRQ0 & IRQ13 not connected */
608 continue; /* IRQ2 is never connected */
613 * If the ELCR indicates a level-sensitive interrupt, we
614 * copy that information over to the MP table in the
615 * irqflag field (level sensitive, active high polarity).
618 intsrc.mpc_irqflag = 13;
620 intsrc.mpc_irqflag = 0;
623 intsrc.mpc_srcbusirq = i;
624 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
625 MP_intsrc_info(&intsrc);
628 intsrc.mpc_irqtype = mp_ExtINT;
629 intsrc.mpc_srcbusirq = 0;
630 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
631 MP_intsrc_info(&intsrc);
635 static void construct_ioapic_table(int mpc_default_type)
637 struct mpc_config_ioapic ioapic;
638 struct mpc_config_bus bus;
640 bus.mpc_type = MP_BUS;
642 switch (mpc_default_type) {
644 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
649 memcpy(bus.mpc_bustype, "ISA ", 6);
654 memcpy(bus.mpc_bustype, "EISA ", 6);
658 memcpy(bus.mpc_bustype, "MCA ", 6);
661 if (mpc_default_type > 4) {
663 memcpy(bus.mpc_bustype, "PCI ", 6);
667 ioapic.mpc_type = MP_IOAPIC;
668 ioapic.mpc_apicid = 2;
669 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
670 ioapic.mpc_flags = MPC_APIC_USABLE;
671 ioapic.mpc_apicaddr = 0xFEC00000;
672 MP_ioapic_info(&ioapic);
675 * We set up most of the low 16 IO-APIC pins according to MPS rules.
677 construct_default_ioirq_mptable(mpc_default_type);
680 static inline void construct_ioapic_table(int mpc_default_type) { }
683 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
685 struct mpc_config_processor processor;
686 struct mpc_config_lintsrc lintsrc;
687 int linttypes[2] = { mp_ExtINT, mp_NMI };
691 * local APIC has default address
693 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
696 * 2 CPUs, numbered 0 & 1.
698 processor.mpc_type = MP_PROCESSOR;
699 /* Either an integrated APIC or a discrete 82489DX. */
700 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
701 processor.mpc_cpuflag = CPU_ENABLED;
702 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
703 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
704 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
705 processor.mpc_reserved[0] = 0;
706 processor.mpc_reserved[1] = 0;
707 for (i = 0; i < 2; i++) {
708 processor.mpc_apicid = i;
709 MP_processor_info(&processor);
712 construct_ioapic_table(mpc_default_type);
714 lintsrc.mpc_type = MP_LINTSRC;
715 lintsrc.mpc_irqflag = 0; /* conforming */
716 lintsrc.mpc_srcbusid = 0;
717 lintsrc.mpc_srcbusirq = 0;
718 lintsrc.mpc_destapic = MP_APIC_ALL;
719 for (i = 0; i < 2; i++) {
720 lintsrc.mpc_irqtype = linttypes[i];
721 lintsrc.mpc_destapiclint = i;
722 MP_lintsrc_info(&lintsrc);
726 static struct intel_mp_floating *mpf_found;
729 * Scan the memory blocks for an SMP configuration block.
731 static void __init __get_smp_config(unsigned early)
733 struct intel_mp_floating *mpf = mpf_found;
735 if (acpi_lapic && early)
738 * ACPI supports both logical (e.g. Hyper-Threading) and physical
739 * processors, where MPS only supports physical.
741 if (acpi_lapic && acpi_ioapic) {
742 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
745 } else if (acpi_lapic)
746 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
747 "configuration information\n");
749 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
750 mpf->mpf_specification);
751 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
752 if (mpf->mpf_feature2 & (1 << 7)) {
753 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
756 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
761 * Now see if we need to read further.
763 if (mpf->mpf_feature1 != 0) {
766 * local APIC has default address
768 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
772 printk(KERN_INFO "Default MP configuration #%d\n",
774 construct_default_ISA_mptable(mpf->mpf_feature1);
776 } else if (mpf->mpf_physptr) {
779 * Read the physical hardware table. Anything here will
780 * override the defaults.
782 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
783 #ifdef CONFIG_X86_LOCAL_APIC
784 smp_found_config = 0;
787 "BIOS bug, MP table errors detected!...\n");
788 printk(KERN_ERR "... disabling SMP support. "
789 "(tell your hw vendor)\n");
795 #ifdef CONFIG_X86_IO_APIC
797 * If there are no explicit MP IRQ entries, then we are
798 * broken. We set up most of the low 16 IO-APIC pins to
799 * ISA defaults and hope it will work.
801 if (!mp_irq_entries) {
802 struct mpc_config_bus bus;
804 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
805 "using default mptable. "
806 "(tell your hw vendor)\n");
808 bus.mpc_type = MP_BUS;
810 memcpy(bus.mpc_bustype, "ISA ", 6);
813 construct_default_ioirq_mptable(0);
820 printk(KERN_INFO "Processors: %d\n", num_processors);
822 * Only use the first configuration found.
826 void __init early_get_smp_config(void)
831 void __init get_smp_config(void)
836 static int __init smp_scan_config(unsigned long base, unsigned long length,
839 unsigned int *bp = phys_to_virt(base);
840 struct intel_mp_floating *mpf;
842 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
843 BUILD_BUG_ON(sizeof(*mpf) != 16);
846 mpf = (struct intel_mp_floating *)bp;
847 if ((*bp == SMP_MAGIC_IDENT) &&
848 (mpf->mpf_length == 1) &&
849 !mpf_checksum((unsigned char *)bp, 16) &&
850 ((mpf->mpf_specification == 1)
851 || (mpf->mpf_specification == 4))) {
852 #ifdef CONFIG_X86_LOCAL_APIC
853 smp_found_config = 1;
857 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
858 mpf, virt_to_phys(mpf));
862 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
864 if (mpf->mpf_physptr) {
865 unsigned long size = PAGE_SIZE;
868 * We cannot access to MPC table to compute
869 * table size yet, as only few megabytes from
870 * the bottom is mapped now.
871 * PC-9800's MPC table places on the very last
872 * of physical memory; so that simply reserving
873 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
874 * in reserve_bootmem.
876 unsigned long end = max_low_pfn * PAGE_SIZE;
877 if (mpf->mpf_physptr + size > end)
878 size = end - mpf->mpf_physptr;
880 reserve_bootmem_generic(mpf->mpf_physptr, size,
892 static void __init __find_smp_config(unsigned reserve)
894 unsigned int address;
897 * FIXME: Linux assumes you have 640K of base ram..
898 * this continues the error...
900 * 1) Scan the bottom 1K for a signature
901 * 2) Scan the top 1K of base RAM
902 * 3) Scan the 64K of bios
904 if (smp_scan_config(0x0, 0x400, reserve) ||
905 smp_scan_config(639 * 0x400, 0x400, reserve) ||
906 smp_scan_config(0xF0000, 0x10000, reserve))
909 * If it is an SMP machine we should know now, unless the
910 * configuration is in an EISA/MCA bus machine with an
911 * extended bios data area.
913 * there is a real-mode segmented pointer pointing to the
914 * 4K EBDA area at 0x40E, calculate and scan it here.
916 * NOTE! There are Linux loaders that will corrupt the EBDA
917 * area, and as such this kind of SMP config may be less
918 * trustworthy, simply because the SMP table may have been
919 * stomped on during early boot. These loaders are buggy and
922 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
925 address = get_bios_ebda();
927 smp_scan_config(address, 0x400, reserve);
930 void __init early_find_smp_config(void)
932 __find_smp_config(0);
935 void __init find_smp_config(void)
937 __find_smp_config(1);
940 #ifdef CONFIG_X86_IO_APIC
941 static u8 __initdata irq_used[MAX_IRQ_SOURCES];
943 static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
947 if (m->mpc_irqtype != mp_INT)
950 if (m->mpc_irqflag != 0x0f)
955 for (i = 0; i < mp_irq_entries; i++) {
956 if (mp_irqs[i].mp_irqtype != mp_INT)
959 if (mp_irqs[i].mp_irqflag != 0x0f)
962 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
964 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
967 /* already claimed */
978 #define SPARE_SLOT_NUM 20
980 static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
983 static int __init replace_intsrc_all(struct mp_config_table *mpc,
984 unsigned long mpc_new_phys,
985 unsigned long mpc_new_length)
987 #ifdef CONFIG_X86_IO_APIC
992 int count = sizeof(*mpc);
993 unsigned char *mpt = ((unsigned char *)mpc) + count;
995 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
996 while (count < mpc->mpc_length) {
1000 struct mpc_config_processor *m =
1001 (struct mpc_config_processor *)mpt;
1003 count += sizeof(*m);
1008 struct mpc_config_bus *m =
1009 (struct mpc_config_bus *)mpt;
1011 count += sizeof(*m);
1016 mpt += sizeof(struct mpc_config_ioapic);
1017 count += sizeof(struct mpc_config_ioapic);
1022 #ifdef CONFIG_X86_IO_APIC
1023 struct mpc_config_intsrc *m =
1024 (struct mpc_config_intsrc *)mpt;
1026 printk(KERN_INFO "OLD ");
1027 print_MP_intsrc_info(m);
1028 i = get_MP_intsrc_index(m);
1030 assign_to_mpc_intsrc(&mp_irqs[i], m);
1031 printk(KERN_INFO "NEW ");
1032 print_mp_irq_info(&mp_irqs[i]);
1034 /* legacy, do nothing */
1035 } else if (nr_m_spare < SPARE_SLOT_NUM) {
1037 * not found (-1), or duplicated (-2)
1038 * are invalid entries,
1039 * we need to use the slot later
1041 m_spare[nr_m_spare] = m;
1045 mpt += sizeof(struct mpc_config_intsrc);
1046 count += sizeof(struct mpc_config_intsrc);
1051 struct mpc_config_lintsrc *m =
1052 (struct mpc_config_lintsrc *)mpt;
1054 count += sizeof(*m);
1059 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
1060 printk(KERN_ERR "type %x\n", *mpt);
1061 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
1062 1, mpc, mpc->mpc_length, 1);
1067 #ifdef CONFIG_X86_IO_APIC
1068 for (i = 0; i < mp_irq_entries; i++) {
1072 if (mp_irqs[i].mp_irqtype != mp_INT)
1075 if (mp_irqs[i].mp_irqflag != 0x0f)
1078 if (nr_m_spare > 0) {
1079 printk(KERN_INFO "*NEW* found ");
1081 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1082 m_spare[nr_m_spare] = NULL;
1084 struct mpc_config_intsrc *m =
1085 (struct mpc_config_intsrc *)mpt;
1086 count += sizeof(struct mpc_config_intsrc);
1087 if (!mpc_new_phys) {
1088 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1090 if (count <= mpc_new_length)
1091 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1093 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1097 assign_to_mpc_intsrc(&mp_irqs[i], m);
1098 mpc->mpc_length = count;
1099 mpt += sizeof(struct mpc_config_intsrc);
1101 print_mp_irq_info(&mp_irqs[i]);
1105 /* update checksum */
1106 mpc->mpc_checksum = 0;
1107 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1113 static int __initdata enable_update_mptable;
1115 static int __init update_mptable_setup(char *str)
1117 enable_update_mptable = 1;
1120 early_param("update_mptable", update_mptable_setup);
1122 static unsigned long __initdata mpc_new_phys;
1123 static unsigned long mpc_new_length __initdata = 4096;
1125 /* alloc_mptable or alloc_mptable=4k */
1126 static int __initdata alloc_mptable;
1127 static int __init parse_alloc_mptable_opt(char *p)
1129 enable_update_mptable = 1;
1133 mpc_new_length = memparse(p, &p);
1136 early_param("alloc_mptable", parse_alloc_mptable_opt);
1138 void __init early_reserve_e820_mpc_new(void)
1140 if (enable_update_mptable && alloc_mptable) {
1142 #ifdef CONFIG_X86_TRAMPOLINE
1143 startt = TRAMPOLINE_BASE;
1145 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1149 static int __init update_mp_table(void)
1153 struct intel_mp_floating *mpf;
1154 struct mp_config_table *mpc;
1155 struct mp_config_table *mpc_new;
1157 if (!enable_update_mptable)
1165 * Now see if we need to go further.
1167 if (mpf->mpf_feature1 != 0)
1170 if (!mpf->mpf_physptr)
1173 mpc = phys_to_virt(mpf->mpf_physptr);
1175 if (!smp_check_mpc(mpc, oem, str))
1178 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1179 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1181 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1183 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1187 if (!mpc_new_phys) {
1188 unsigned char old, new;
1189 /* check if we can change the postion */
1190 mpc->mpc_checksum = 0;
1191 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1192 mpc->mpc_checksum = 0xff;
1193 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1195 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1198 printk(KERN_INFO "use in-positon replacing\n");
1200 mpf->mpf_physptr = mpc_new_phys;
1201 mpc_new = phys_to_virt(mpc_new_phys);
1202 memcpy(mpc_new, mpc, mpc->mpc_length);
1204 /* check if we can modify that */
1205 if (mpc_new_phys - mpf->mpf_physptr) {
1206 struct intel_mp_floating *mpf_new;
1207 /* steal 16 bytes from [0, 1k) */
1208 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1209 mpf_new = phys_to_virt(0x400 - 16);
1210 memcpy(mpf_new, mpf, 16);
1212 mpf->mpf_physptr = mpc_new_phys;
1214 mpf->mpf_checksum = 0;
1215 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1216 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1220 * only replace the one with mp_INT and
1221 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1222 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1223 * may need pci=routeirq for all coverage
1225 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1230 late_initcall(update_mp_table);