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
74 apicid = mpc_apic_id(m, translation_table[mpc_record]);
76 apicid = m->mpc_apicid;
78 apicid = m->mpc_apicid;
80 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
81 bootup_cpu = " (Bootup-CPU)";
82 boot_cpu_physical_apicid = m->mpc_apicid;
85 printk(KERN_INFO "Processor #%d%s\n", m->mpc_apicid, bootup_cpu);
86 generic_processor_info(apicid, m->mpc_apicver);
89 #ifdef CONFIG_X86_IO_APIC
90 static void __init MP_bus_info(struct mpc_config_bus *m)
93 memcpy(str, m->mpc_bustype, 6);
96 #ifdef CONFIG_X86_NUMAQ
98 mpc_oem_bus_info(m, str, translation_table[mpc_record]);
100 printk(KERN_INFO "Bus #%d is %s\n", m->mpc_busid, str);
103 #if MAX_MP_BUSSES < 256
104 if (m->mpc_busid >= MAX_MP_BUSSES) {
105 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
106 " is too large, max. supported is %d\n",
107 m->mpc_busid, str, MAX_MP_BUSSES - 1);
112 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
113 set_bit(m->mpc_busid, mp_bus_not_pci);
114 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
115 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
117 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
118 #ifdef CONFIG_X86_NUMAQ
120 mpc_oem_pci_bus(m, translation_table[mpc_record]);
122 clear_bit(m->mpc_busid, mp_bus_not_pci);
123 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
124 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
125 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
126 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
127 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
128 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
131 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
135 #ifdef CONFIG_X86_IO_APIC
137 static int bad_ioapic(unsigned long address)
139 if (nr_ioapics >= MAX_IO_APICS) {
140 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
141 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
142 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
145 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
146 " found in table, skipping!\n");
152 static void __init MP_ioapic_info(struct mpc_config_ioapic *m)
154 if (!(m->mpc_flags & MPC_APIC_USABLE))
157 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
158 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
160 if (bad_ioapic(m->mpc_apicaddr))
163 mp_ioapics[nr_ioapics].mp_apicaddr = m->mpc_apicaddr;
164 mp_ioapics[nr_ioapics].mp_apicid = m->mpc_apicid;
165 mp_ioapics[nr_ioapics].mp_type = m->mpc_type;
166 mp_ioapics[nr_ioapics].mp_apicver = m->mpc_apicver;
167 mp_ioapics[nr_ioapics].mp_flags = m->mpc_flags;
171 static void print_MP_intsrc_info(struct mpc_config_intsrc *m)
173 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
174 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
175 m->mpc_irqtype, m->mpc_irqflag & 3,
176 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
177 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
180 static void __init print_mp_irq_info(struct mp_config_intsrc *mp_irq)
182 printk(KERN_CONT "Int: type %d, pol %d, trig %d, bus %02x,"
183 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
184 mp_irq->mp_irqtype, mp_irq->mp_irqflag & 3,
185 (mp_irq->mp_irqflag >> 2) & 3, mp_irq->mp_srcbus,
186 mp_irq->mp_srcbusirq, mp_irq->mp_dstapic, mp_irq->mp_dstirq);
189 static void assign_to_mp_irq(struct mpc_config_intsrc *m,
190 struct mp_config_intsrc *mp_irq)
192 mp_irq->mp_dstapic = m->mpc_dstapic;
193 mp_irq->mp_type = m->mpc_type;
194 mp_irq->mp_irqtype = m->mpc_irqtype;
195 mp_irq->mp_irqflag = m->mpc_irqflag;
196 mp_irq->mp_srcbus = m->mpc_srcbus;
197 mp_irq->mp_srcbusirq = m->mpc_srcbusirq;
198 mp_irq->mp_dstirq = m->mpc_dstirq;
201 static void __init assign_to_mpc_intsrc(struct mp_config_intsrc *mp_irq,
202 struct mpc_config_intsrc *m)
204 m->mpc_dstapic = mp_irq->mp_dstapic;
205 m->mpc_type = mp_irq->mp_type;
206 m->mpc_irqtype = mp_irq->mp_irqtype;
207 m->mpc_irqflag = mp_irq->mp_irqflag;
208 m->mpc_srcbus = mp_irq->mp_srcbus;
209 m->mpc_srcbusirq = mp_irq->mp_srcbusirq;
210 m->mpc_dstirq = mp_irq->mp_dstirq;
213 static int mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc *mp_irq,
214 struct mpc_config_intsrc *m)
216 if (mp_irq->mp_dstapic != m->mpc_dstapic)
218 if (mp_irq->mp_type != m->mpc_type)
220 if (mp_irq->mp_irqtype != m->mpc_irqtype)
222 if (mp_irq->mp_irqflag != m->mpc_irqflag)
224 if (mp_irq->mp_srcbus != m->mpc_srcbus)
226 if (mp_irq->mp_srcbusirq != m->mpc_srcbusirq)
228 if (mp_irq->mp_dstirq != m->mpc_dstirq)
234 void MP_intsrc_info(struct mpc_config_intsrc *m)
238 print_MP_intsrc_info(m);
240 for (i = 0; i < mp_irq_entries; i++) {
241 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
245 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
246 if (++mp_irq_entries == MAX_IRQ_SOURCES)
247 panic("Max # of irq sources exceeded!!\n");
252 static void __init MP_lintsrc_info(struct mpc_config_lintsrc *m)
254 printk(KERN_INFO "Lint: type %d, pol %d, trig %d, bus %02x,"
255 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
256 m->mpc_irqtype, m->mpc_irqflag & 3,
257 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbusid,
258 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
261 #ifdef CONFIG_X86_NUMAQ
262 static void __init MP_translation_info(struct mpc_config_translation *m)
265 "Translation: record %d, type %d, quad %d, global %d, local %d\n",
266 mpc_record, m->trans_type, m->trans_quad, m->trans_global,
269 if (mpc_record >= MAX_MPC_ENTRY)
270 printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
272 translation_table[mpc_record] = m; /* stash this for later */
273 if (m->trans_quad < MAX_NUMNODES && !node_online(m->trans_quad))
274 node_set_online(m->trans_quad);
278 * Read/parse the MPC oem tables
281 static void __init smp_read_mpc_oem(struct mp_config_oemtable *oemtable,
282 unsigned short oemsize)
284 int count = sizeof(*oemtable); /* the header size */
285 unsigned char *oemptr = ((unsigned char *)oemtable) + count;
288 printk(KERN_INFO "Found an OEM MPC table at %8p - parsing it ... \n",
290 if (memcmp(oemtable->oem_signature, MPC_OEM_SIGNATURE, 4)) {
292 "SMP mpc oemtable: bad signature [%c%c%c%c]!\n",
293 oemtable->oem_signature[0], oemtable->oem_signature[1],
294 oemtable->oem_signature[2], oemtable->oem_signature[3]);
297 if (mpf_checksum((unsigned char *)oemtable, oemtable->oem_length)) {
298 printk(KERN_WARNING "SMP oem mptable: checksum error!\n");
301 while (count < oemtable->oem_length) {
305 struct mpc_config_translation *m =
306 (struct mpc_config_translation *)oemptr;
307 MP_translation_info(m);
308 oemptr += sizeof(*m);
316 "Unrecognised OEM table entry type! - %d\n",
324 static inline void mps_oem_check(struct mp_config_table *mpc, char *oem,
327 if (strncmp(oem, "IBM NUMA", 8))
328 printk("Warning! May not be a NUMA-Q system!\n");
333 smp_read_mpc_oem((struct mp_config_oemtable *)mpc->mpc_oemptr,
336 #endif /* CONFIG_X86_NUMAQ */
342 static int __init smp_check_mpc(struct mp_config_table *mpc, char *oem,
346 if (memcmp(mpc->mpc_signature, MPC_SIGNATURE, 4)) {
347 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
348 mpc->mpc_signature[0], mpc->mpc_signature[1],
349 mpc->mpc_signature[2], mpc->mpc_signature[3]);
352 if (mpf_checksum((unsigned char *)mpc, mpc->mpc_length)) {
353 printk(KERN_ERR "MPTABLE: checksum error!\n");
356 if (mpc->mpc_spec != 0x01 && mpc->mpc_spec != 0x04) {
357 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
361 if (!mpc->mpc_lapic) {
362 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
365 memcpy(oem, mpc->mpc_oem, 8);
367 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
369 memcpy(str, mpc->mpc_productid, 12);
372 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
374 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->mpc_lapic);
379 static int __init smp_read_mpc(struct mp_config_table *mpc, unsigned early)
384 int count = sizeof(*mpc);
385 unsigned char *mpt = ((unsigned char *)mpc) + count;
387 if (!smp_check_mpc(mpc, oem, str))
391 mps_oem_check(mpc, oem, str);
394 /* save the local APIC address, it might be non-default */
396 mp_lapic_addr = mpc->mpc_lapic;
402 * Now process the configuration blocks.
404 #ifdef CONFIG_X86_NUMAQ
407 while (count < mpc->mpc_length) {
411 struct mpc_config_processor *m =
412 (struct mpc_config_processor *)mpt;
413 /* ACPI may have already provided this data */
415 MP_processor_info(m);
422 struct mpc_config_bus *m =
423 (struct mpc_config_bus *)mpt;
424 #ifdef CONFIG_X86_IO_APIC
433 #ifdef CONFIG_X86_IO_APIC
434 struct mpc_config_ioapic *m =
435 (struct mpc_config_ioapic *)mpt;
438 mpt += sizeof(struct mpc_config_ioapic);
439 count += sizeof(struct mpc_config_ioapic);
444 #ifdef CONFIG_X86_IO_APIC
445 struct mpc_config_intsrc *m =
446 (struct mpc_config_intsrc *)mpt;
450 mpt += sizeof(struct mpc_config_intsrc);
451 count += sizeof(struct mpc_config_intsrc);
456 struct mpc_config_lintsrc *m =
457 (struct mpc_config_lintsrc *)mpt;
465 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
466 printk(KERN_ERR "type %x\n", *mpt);
467 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
468 1, mpc, mpc->mpc_length, 1);
469 count = mpc->mpc_length;
472 #ifdef CONFIG_X86_NUMAQ
477 #ifdef CONFIG_X86_GENERICARCH
478 generic_bigsmp_probe();
481 setup_apic_routing();
483 printk(KERN_ERR "MPTABLE: no processors registered!\n");
484 return num_processors;
487 #ifdef CONFIG_X86_IO_APIC
489 static int __init ELCR_trigger(unsigned int irq)
493 port = 0x4d0 + (irq >> 3);
494 return (inb(port) >> (irq & 7)) & 1;
497 static void __init construct_default_ioirq_mptable(int mpc_default_type)
499 struct mpc_config_intsrc intsrc;
501 int ELCR_fallback = 0;
503 intsrc.mpc_type = MP_INTSRC;
504 intsrc.mpc_irqflag = 0; /* conforming */
505 intsrc.mpc_srcbus = 0;
506 intsrc.mpc_dstapic = mp_ioapics[0].mp_apicid;
508 intsrc.mpc_irqtype = mp_INT;
511 * If true, we have an ISA/PCI system with no IRQ entries
512 * in the MP table. To prevent the PCI interrupts from being set up
513 * incorrectly, we try to use the ELCR. The sanity check to see if
514 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
515 * never be level sensitive, so we simply see if the ELCR agrees.
516 * If it does, we assume it's valid.
518 if (mpc_default_type == 5) {
519 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
520 "falling back to ELCR\n");
522 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
524 printk(KERN_ERR "ELCR contains invalid data... "
528 "Using ELCR to identify PCI interrupts\n");
533 for (i = 0; i < 16; i++) {
534 switch (mpc_default_type) {
536 if (i == 0 || i == 13)
537 continue; /* IRQ0 & IRQ13 not connected */
541 continue; /* IRQ2 is never connected */
546 * If the ELCR indicates a level-sensitive interrupt, we
547 * copy that information over to the MP table in the
548 * irqflag field (level sensitive, active high polarity).
551 intsrc.mpc_irqflag = 13;
553 intsrc.mpc_irqflag = 0;
556 intsrc.mpc_srcbusirq = i;
557 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
558 MP_intsrc_info(&intsrc);
561 intsrc.mpc_irqtype = mp_ExtINT;
562 intsrc.mpc_srcbusirq = 0;
563 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
564 MP_intsrc_info(&intsrc);
568 static void construct_ioapic_table(int mpc_default_type)
570 struct mpc_config_ioapic ioapic;
571 struct mpc_config_bus bus;
573 bus.mpc_type = MP_BUS;
575 switch (mpc_default_type) {
577 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
582 memcpy(bus.mpc_bustype, "ISA ", 6);
587 memcpy(bus.mpc_bustype, "EISA ", 6);
591 memcpy(bus.mpc_bustype, "MCA ", 6);
594 if (mpc_default_type > 4) {
596 memcpy(bus.mpc_bustype, "PCI ", 6);
600 ioapic.mpc_type = MP_IOAPIC;
601 ioapic.mpc_apicid = 2;
602 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
603 ioapic.mpc_flags = MPC_APIC_USABLE;
604 ioapic.mpc_apicaddr = 0xFEC00000;
605 MP_ioapic_info(&ioapic);
608 * We set up most of the low 16 IO-APIC pins according to MPS rules.
610 construct_default_ioirq_mptable(mpc_default_type);
613 static inline void construct_ioapic_table(int mpc_default_type) { }
616 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
618 struct mpc_config_processor processor;
619 struct mpc_config_lintsrc lintsrc;
620 int linttypes[2] = { mp_ExtINT, mp_NMI };
624 * local APIC has default address
626 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
629 * 2 CPUs, numbered 0 & 1.
631 processor.mpc_type = MP_PROCESSOR;
632 /* Either an integrated APIC or a discrete 82489DX. */
633 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
634 processor.mpc_cpuflag = CPU_ENABLED;
635 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
636 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
637 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
638 processor.mpc_reserved[0] = 0;
639 processor.mpc_reserved[1] = 0;
640 for (i = 0; i < 2; i++) {
641 processor.mpc_apicid = i;
642 MP_processor_info(&processor);
645 construct_ioapic_table(mpc_default_type);
647 lintsrc.mpc_type = MP_LINTSRC;
648 lintsrc.mpc_irqflag = 0; /* conforming */
649 lintsrc.mpc_srcbusid = 0;
650 lintsrc.mpc_srcbusirq = 0;
651 lintsrc.mpc_destapic = MP_APIC_ALL;
652 for (i = 0; i < 2; i++) {
653 lintsrc.mpc_irqtype = linttypes[i];
654 lintsrc.mpc_destapiclint = i;
655 MP_lintsrc_info(&lintsrc);
659 static struct intel_mp_floating *mpf_found;
662 * Scan the memory blocks for an SMP configuration block.
664 static void __init __get_smp_config(unsigned early)
666 struct intel_mp_floating *mpf = mpf_found;
668 if (acpi_lapic && early)
671 * ACPI supports both logical (e.g. Hyper-Threading) and physical
672 * processors, where MPS only supports physical.
674 if (acpi_lapic && acpi_ioapic) {
675 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
678 } else if (acpi_lapic)
679 printk(KERN_INFO "Using ACPI for processor (LAPIC) "
680 "configuration information\n");
682 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
683 mpf->mpf_specification);
684 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
685 if (mpf->mpf_feature2 & (1 << 7)) {
686 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
689 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
694 * Now see if we need to read further.
696 if (mpf->mpf_feature1 != 0) {
699 * local APIC has default address
701 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
705 printk(KERN_INFO "Default MP configuration #%d\n",
707 construct_default_ISA_mptable(mpf->mpf_feature1);
709 } else if (mpf->mpf_physptr) {
712 * Read the physical hardware table. Anything here will
713 * override the defaults.
715 if (!smp_read_mpc(phys_to_virt(mpf->mpf_physptr), early)) {
716 #ifdef CONFIG_X86_LOCAL_APIC
717 smp_found_config = 0;
720 "BIOS bug, MP table errors detected!...\n");
721 printk(KERN_ERR "... disabling SMP support. "
722 "(tell your hw vendor)\n");
728 #ifdef CONFIG_X86_IO_APIC
730 * If there are no explicit MP IRQ entries, then we are
731 * broken. We set up most of the low 16 IO-APIC pins to
732 * ISA defaults and hope it will work.
734 if (!mp_irq_entries) {
735 struct mpc_config_bus bus;
737 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
738 "using default mptable. "
739 "(tell your hw vendor)\n");
741 bus.mpc_type = MP_BUS;
743 memcpy(bus.mpc_bustype, "ISA ", 6);
746 construct_default_ioirq_mptable(0);
753 printk(KERN_INFO "Processors: %d\n", num_processors);
755 * Only use the first configuration found.
759 void __init early_get_smp_config(void)
764 void __init get_smp_config(void)
769 static int __init smp_scan_config(unsigned long base, unsigned long length,
772 unsigned int *bp = phys_to_virt(base);
773 struct intel_mp_floating *mpf;
775 printk(KERN_DEBUG "Scan SMP from %p for %ld bytes.\n", bp, length);
776 BUILD_BUG_ON(sizeof(*mpf) != 16);
779 mpf = (struct intel_mp_floating *)bp;
780 if ((*bp == SMP_MAGIC_IDENT) &&
781 (mpf->mpf_length == 1) &&
782 !mpf_checksum((unsigned char *)bp, 16) &&
783 ((mpf->mpf_specification == 1)
784 || (mpf->mpf_specification == 4))) {
785 #ifdef CONFIG_X86_LOCAL_APIC
786 smp_found_config = 1;
790 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
791 mpf, virt_to_phys(mpf));
792 reserve_bootmem(virt_to_phys(mpf), PAGE_SIZE,
794 if (mpf->mpf_physptr) {
796 * We cannot access to MPC table to compute
797 * table size yet, as only few megabytes from
798 * the bottom is mapped now.
799 * PC-9800's MPC table places on the very last
800 * of physical memory; so that simply reserving
801 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
802 * in reserve_bootmem.
804 unsigned long size = PAGE_SIZE;
805 unsigned long end = max_low_pfn * PAGE_SIZE;
806 if (mpf->mpf_physptr + size > end)
807 size = end - mpf->mpf_physptr;
808 reserve_bootmem(mpf->mpf_physptr, size,
816 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
817 if (mpf->mpf_physptr)
818 reserve_bootmem_generic(mpf->mpf_physptr,
829 static void __init __find_smp_config(unsigned reserve)
831 unsigned int address;
834 * FIXME: Linux assumes you have 640K of base ram..
835 * this continues the error...
837 * 1) Scan the bottom 1K for a signature
838 * 2) Scan the top 1K of base RAM
839 * 3) Scan the 64K of bios
841 if (smp_scan_config(0x0, 0x400, reserve) ||
842 smp_scan_config(639 * 0x400, 0x400, reserve) ||
843 smp_scan_config(0xF0000, 0x10000, reserve))
846 * If it is an SMP machine we should know now, unless the
847 * configuration is in an EISA/MCA bus machine with an
848 * extended bios data area.
850 * there is a real-mode segmented pointer pointing to the
851 * 4K EBDA area at 0x40E, calculate and scan it here.
853 * NOTE! There are Linux loaders that will corrupt the EBDA
854 * area, and as such this kind of SMP config may be less
855 * trustworthy, simply because the SMP table may have been
856 * stomped on during early boot. These loaders are buggy and
859 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
862 address = get_bios_ebda();
864 smp_scan_config(address, 0x400, reserve);
867 void __init early_find_smp_config(void)
869 __find_smp_config(0);
872 void __init find_smp_config(void)
874 __find_smp_config(1);
877 #ifdef CONFIG_X86_IO_APIC
878 static u8 __initdata irq_used[MAX_IRQ_SOURCES];
880 static int __init get_MP_intsrc_index(struct mpc_config_intsrc *m)
884 if (m->mpc_irqtype != mp_INT)
887 if (m->mpc_irqflag != 0x0f)
892 for (i = 0; i < mp_irq_entries; i++) {
893 if (mp_irqs[i].mp_irqtype != mp_INT)
896 if (mp_irqs[i].mp_irqflag != 0x0f)
899 if (mp_irqs[i].mp_srcbus != m->mpc_srcbus)
901 if (mp_irqs[i].mp_srcbusirq != m->mpc_srcbusirq)
904 /* already claimed */
915 #define SPARE_SLOT_NUM 20
917 static struct mpc_config_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
920 static int __init replace_intsrc_all(struct mp_config_table *mpc,
921 unsigned long mpc_new_phys,
922 unsigned long mpc_new_length)
924 #ifdef CONFIG_X86_IO_APIC
929 int count = sizeof(*mpc);
930 unsigned char *mpt = ((unsigned char *)mpc) + count;
932 printk(KERN_INFO "mpc_length %x\n", mpc->mpc_length);
933 while (count < mpc->mpc_length) {
937 struct mpc_config_processor *m =
938 (struct mpc_config_processor *)mpt;
945 struct mpc_config_bus *m =
946 (struct mpc_config_bus *)mpt;
953 mpt += sizeof(struct mpc_config_ioapic);
954 count += sizeof(struct mpc_config_ioapic);
959 #ifdef CONFIG_X86_IO_APIC
960 struct mpc_config_intsrc *m =
961 (struct mpc_config_intsrc *)mpt;
963 printk(KERN_INFO "OLD ");
964 print_MP_intsrc_info(m);
965 i = get_MP_intsrc_index(m);
967 assign_to_mpc_intsrc(&mp_irqs[i], m);
968 printk(KERN_INFO "NEW ");
969 print_mp_irq_info(&mp_irqs[i]);
971 /* legacy, do nothing */
972 } else if (nr_m_spare < SPARE_SLOT_NUM) {
974 * not found (-1), or duplicated (-2)
975 * are invalid entries,
976 * we need to use the slot later
978 m_spare[nr_m_spare] = m;
982 mpt += sizeof(struct mpc_config_intsrc);
983 count += sizeof(struct mpc_config_intsrc);
988 struct mpc_config_lintsrc *m =
989 (struct mpc_config_lintsrc *)mpt;
996 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
997 printk(KERN_ERR "type %x\n", *mpt);
998 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
999 1, mpc, mpc->mpc_length, 1);
1004 #ifdef CONFIG_X86_IO_APIC
1005 for (i = 0; i < mp_irq_entries; i++) {
1009 if (mp_irqs[i].mp_irqtype != mp_INT)
1012 if (mp_irqs[i].mp_irqflag != 0x0f)
1015 if (nr_m_spare > 0) {
1016 printk(KERN_INFO "*NEW* found ");
1018 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
1019 m_spare[nr_m_spare] = NULL;
1021 struct mpc_config_intsrc *m =
1022 (struct mpc_config_intsrc *)mpt;
1023 count += sizeof(struct mpc_config_intsrc);
1024 if (!mpc_new_phys) {
1025 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
1027 if (count <= mpc_new_length)
1028 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
1030 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
1034 assign_to_mpc_intsrc(&mp_irqs[i], m);
1035 mpc->mpc_length = count;
1036 mpt += sizeof(struct mpc_config_intsrc);
1038 print_mp_irq_info(&mp_irqs[i]);
1042 /* update checksum */
1043 mpc->mpc_checksum = 0;
1044 mpc->mpc_checksum -= mpf_checksum((unsigned char *)mpc,
1050 int __initdata enable_update_mptable;
1052 static int __init update_mptable_setup(char *str)
1054 enable_update_mptable = 1;
1057 early_param("update_mptable", update_mptable_setup);
1059 static unsigned long __initdata mpc_new_phys;
1060 static unsigned long mpc_new_length __initdata = 4096;
1062 /* alloc_mptable or alloc_mptable=4k */
1063 static int __initdata alloc_mptable;
1064 static int __init parse_alloc_mptable_opt(char *p)
1066 enable_update_mptable = 1;
1070 mpc_new_length = memparse(p, &p);
1073 early_param("alloc_mptable", parse_alloc_mptable_opt);
1075 void __init early_reserve_e820_mpc_new(void)
1077 if (enable_update_mptable && alloc_mptable) {
1079 #ifdef CONFIG_X86_TRAMPOLINE
1080 startt = TRAMPOLINE_BASE;
1082 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1086 static int __init update_mp_table(void)
1090 struct intel_mp_floating *mpf;
1091 struct mp_config_table *mpc;
1092 struct mp_config_table *mpc_new;
1094 if (!enable_update_mptable)
1102 * Now see if we need to go further.
1104 if (mpf->mpf_feature1 != 0)
1107 if (!mpf->mpf_physptr)
1110 mpc = phys_to_virt(mpf->mpf_physptr);
1112 if (!smp_check_mpc(mpc, oem, str))
1115 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1116 printk(KERN_INFO "mpf_physptr: %x\n", mpf->mpf_physptr);
1118 if (mpc_new_phys && mpc->mpc_length > mpc_new_length) {
1120 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1124 if (!mpc_new_phys) {
1125 unsigned char old, new;
1126 /* check if we can change the postion */
1127 mpc->mpc_checksum = 0;
1128 old = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1129 mpc->mpc_checksum = 0xff;
1130 new = mpf_checksum((unsigned char *)mpc, mpc->mpc_length);
1132 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1135 printk(KERN_INFO "use in-positon replacing\n");
1137 mpf->mpf_physptr = mpc_new_phys;
1138 mpc_new = phys_to_virt(mpc_new_phys);
1139 memcpy(mpc_new, mpc, mpc->mpc_length);
1141 /* check if we can modify that */
1142 if (mpc_new_phys - mpf->mpf_physptr) {
1143 struct intel_mp_floating *mpf_new;
1144 /* steal 16 bytes from [0, 1k) */
1145 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1146 mpf_new = phys_to_virt(0x400 - 16);
1147 memcpy(mpf_new, mpf, 16);
1149 mpf->mpf_physptr = mpc_new_phys;
1151 mpf->mpf_checksum = 0;
1152 mpf->mpf_checksum -= mpf_checksum((unsigned char *)mpf, 16);
1153 printk(KERN_INFO "mpf_physptr new: %x\n", mpf->mpf_physptr);
1157 * only replace the one with mp_INT and
1158 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1159 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1160 * may need pci=routeirq for all coverage
1162 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1167 late_initcall(update_mp_table);