2 * Intel Multiprocessor Specification 1.1 and 1.4
3 * compliant MP-table parsing routines.
5 * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
6 * (c) 1998, 1999, 2000, 2009 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>
19 #include <linux/smp.h>
22 #include <asm/mpspec.h>
23 #include <asm/pgalloc.h>
24 #include <asm/io_apic.h>
25 #include <asm/proto.h>
26 #include <asm/bios_ebda.h>
28 #include <asm/trampoline.h>
29 #include <asm/setup.h>
34 * Checksum an MP configuration block.
37 static int __init mpf_checksum(unsigned char *mp, int len)
47 static void __init MP_processor_info(struct mpc_cpu *m)
50 char *bootup_cpu = "";
52 if (!(m->cpuflag & CPU_ENABLED)) {
57 if (x86_quirks->mpc_apic_id)
58 apicid = x86_quirks->mpc_apic_id(m);
62 if (m->cpuflag & CPU_BOOTPROCESSOR) {
63 bootup_cpu = " (Bootup-CPU)";
64 boot_cpu_physical_apicid = m->apicid;
67 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
68 generic_processor_info(apicid, m->apicver);
71 #ifdef CONFIG_X86_IO_APIC
72 static void __init MP_bus_info(struct mpc_bus *m)
75 memcpy(str, m->bustype, 6);
78 if (x86_quirks->mpc_oem_bus_info)
79 x86_quirks->mpc_oem_bus_info(m, str);
81 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
83 #if MAX_MP_BUSSES < 256
84 if (m->busid >= MAX_MP_BUSSES) {
85 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
86 " is too large, max. supported is %d\n",
87 m->busid, str, MAX_MP_BUSSES - 1);
92 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
93 set_bit(m->busid, mp_bus_not_pci);
94 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
95 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
97 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
98 if (x86_quirks->mpc_oem_pci_bus)
99 x86_quirks->mpc_oem_pci_bus(m);
101 clear_bit(m->busid, mp_bus_not_pci);
102 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
103 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
104 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
105 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
106 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
107 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
110 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
113 static int bad_ioapic(unsigned long address)
115 if (nr_ioapics >= MAX_IO_APICS) {
116 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
117 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
118 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
121 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
122 " found in table, skipping!\n");
128 static void __init MP_ioapic_info(struct mpc_ioapic *m)
130 if (!(m->flags & MPC_APIC_USABLE))
133 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
134 m->apicid, m->apicver, m->apicaddr);
136 if (bad_ioapic(m->apicaddr))
139 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
140 mp_ioapics[nr_ioapics].apicid = m->apicid;
141 mp_ioapics[nr_ioapics].type = m->type;
142 mp_ioapics[nr_ioapics].apicver = m->apicver;
143 mp_ioapics[nr_ioapics].flags = m->flags;
147 static void print_MP_intsrc_info(struct mpc_intsrc *m)
149 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
150 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
151 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
152 m->srcbusirq, m->dstapic, m->dstirq);
155 static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
157 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
158 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
159 mp_irq->irqtype, mp_irq->irqflag & 3,
160 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
161 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
164 static void __init assign_to_mp_irq(struct mpc_intsrc *m,
165 struct mpc_intsrc *mp_irq)
167 mp_irq->dstapic = m->dstapic;
168 mp_irq->type = m->type;
169 mp_irq->irqtype = m->irqtype;
170 mp_irq->irqflag = m->irqflag;
171 mp_irq->srcbus = m->srcbus;
172 mp_irq->srcbusirq = m->srcbusirq;
173 mp_irq->dstirq = m->dstirq;
176 static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
177 struct mpc_intsrc *m)
179 m->dstapic = mp_irq->dstapic;
180 m->type = mp_irq->type;
181 m->irqtype = mp_irq->irqtype;
182 m->irqflag = mp_irq->irqflag;
183 m->srcbus = mp_irq->srcbus;
184 m->srcbusirq = mp_irq->srcbusirq;
185 m->dstirq = mp_irq->dstirq;
188 static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
189 struct mpc_intsrc *m)
191 if (mp_irq->dstapic != m->dstapic)
193 if (mp_irq->type != m->type)
195 if (mp_irq->irqtype != m->irqtype)
197 if (mp_irq->irqflag != m->irqflag)
199 if (mp_irq->srcbus != m->srcbus)
201 if (mp_irq->srcbusirq != m->srcbusirq)
203 if (mp_irq->dstirq != m->dstirq)
209 static void __init MP_intsrc_info(struct mpc_intsrc *m)
213 print_MP_intsrc_info(m);
215 for (i = 0; i < mp_irq_entries; i++) {
216 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
220 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
221 if (++mp_irq_entries == MAX_IRQ_SOURCES)
222 panic("Max # of irq sources exceeded!!\n");
224 #else /* CONFIG_X86_IO_APIC */
225 static inline void __init MP_bus_info(struct mpc_bus *m) {}
226 static inline void __init MP_ioapic_info(struct mpc_ioapic *m) {}
227 static inline void __init MP_intsrc_info(struct mpc_intsrc *m) {}
228 #endif /* CONFIG_X86_IO_APIC */
231 static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
233 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
234 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
235 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
236 m->srcbusirq, m->destapic, m->destapiclint);
243 static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
246 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
247 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
248 mpc->signature[0], mpc->signature[1],
249 mpc->signature[2], mpc->signature[3]);
252 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
253 printk(KERN_ERR "MPTABLE: checksum error!\n");
256 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
257 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
262 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
265 memcpy(oem, mpc->oem, 8);
267 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
269 memcpy(str, mpc->productid, 12);
272 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
274 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
279 static void skip_entry(unsigned char **ptr, int *count, int size)
285 static void __init smp_dump_mptable(struct mpc_table *mpc, unsigned char *mpt)
287 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n"
289 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
290 1, mpc, mpc->length, 1);
293 static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
298 int count = sizeof(*mpc);
299 unsigned char *mpt = ((unsigned char *)mpc) + count;
301 if (!smp_check_mpc(mpc, oem, str))
305 generic_mps_oem_check(mpc, oem, str);
307 /* save the local APIC address, it might be non-default */
309 mp_lapic_addr = mpc->lapic;
314 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
315 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
316 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
320 * Now process the configuration blocks.
322 if (x86_quirks->mpc_record)
323 *x86_quirks->mpc_record = 0;
325 while (count < mpc->length) {
328 /* ACPI may have already provided this data */
330 MP_processor_info((struct mpc_cpu *)mpt);
331 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
334 MP_bus_info((struct mpc_bus *)mpt);
335 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
338 MP_ioapic_info((struct mpc_ioapic *)mpt);
339 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
342 MP_intsrc_info((struct mpc_intsrc *)mpt);
343 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
346 MP_lintsrc_info((struct mpc_lintsrc *)mpt);
347 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
351 smp_dump_mptable(mpc, mpt);
355 if (x86_quirks->mpc_record)
356 (*x86_quirks->mpc_record)++;
359 #ifdef CONFIG_X86_BIGSMP
360 generic_bigsmp_probe();
363 if (apic->setup_apic_routing)
364 apic->setup_apic_routing();
367 printk(KERN_ERR "MPTABLE: no processors registered!\n");
368 return num_processors;
371 #ifdef CONFIG_X86_IO_APIC
373 static int __init ELCR_trigger(unsigned int irq)
377 port = 0x4d0 + (irq >> 3);
378 return (inb(port) >> (irq & 7)) & 1;
381 static void __init construct_default_ioirq_mptable(int mpc_default_type)
383 struct mpc_intsrc intsrc;
385 int ELCR_fallback = 0;
387 intsrc.type = MP_INTSRC;
388 intsrc.irqflag = 0; /* conforming */
390 intsrc.dstapic = mp_ioapics[0].apicid;
392 intsrc.irqtype = mp_INT;
395 * If true, we have an ISA/PCI system with no IRQ entries
396 * in the MP table. To prevent the PCI interrupts from being set up
397 * incorrectly, we try to use the ELCR. The sanity check to see if
398 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
399 * never be level sensitive, so we simply see if the ELCR agrees.
400 * If it does, we assume it's valid.
402 if (mpc_default_type == 5) {
403 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
404 "falling back to ELCR\n");
406 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
408 printk(KERN_ERR "ELCR contains invalid data... "
412 "Using ELCR to identify PCI interrupts\n");
417 for (i = 0; i < 16; i++) {
418 switch (mpc_default_type) {
420 if (i == 0 || i == 13)
421 continue; /* IRQ0 & IRQ13 not connected */
425 continue; /* IRQ2 is never connected */
430 * If the ELCR indicates a level-sensitive interrupt, we
431 * copy that information over to the MP table in the
432 * irqflag field (level sensitive, active high polarity).
440 intsrc.srcbusirq = i;
441 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
442 MP_intsrc_info(&intsrc);
445 intsrc.irqtype = mp_ExtINT;
446 intsrc.srcbusirq = 0;
447 intsrc.dstirq = 0; /* 8259A to INTIN0 */
448 MP_intsrc_info(&intsrc);
452 static void __init construct_ioapic_table(int mpc_default_type)
454 struct mpc_ioapic ioapic;
459 switch (mpc_default_type) {
461 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
466 memcpy(bus.bustype, "ISA ", 6);
471 memcpy(bus.bustype, "EISA ", 6);
475 memcpy(bus.bustype, "MCA ", 6);
478 if (mpc_default_type > 4) {
480 memcpy(bus.bustype, "PCI ", 6);
484 ioapic.type = MP_IOAPIC;
486 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
487 ioapic.flags = MPC_APIC_USABLE;
488 ioapic.apicaddr = 0xFEC00000;
489 MP_ioapic_info(&ioapic);
492 * We set up most of the low 16 IO-APIC pins according to MPS rules.
494 construct_default_ioirq_mptable(mpc_default_type);
497 static inline void __init construct_ioapic_table(int mpc_default_type) { }
500 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
502 struct mpc_cpu processor;
503 struct mpc_lintsrc lintsrc;
504 int linttypes[2] = { mp_ExtINT, mp_NMI };
508 * local APIC has default address
510 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
513 * 2 CPUs, numbered 0 & 1.
515 processor.type = MP_PROCESSOR;
516 /* Either an integrated APIC or a discrete 82489DX. */
517 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
518 processor.cpuflag = CPU_ENABLED;
519 processor.cpufeature = (boot_cpu_data.x86 << 8) |
520 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
521 processor.featureflag = boot_cpu_data.x86_capability[0];
522 processor.reserved[0] = 0;
523 processor.reserved[1] = 0;
524 for (i = 0; i < 2; i++) {
525 processor.apicid = i;
526 MP_processor_info(&processor);
529 construct_ioapic_table(mpc_default_type);
531 lintsrc.type = MP_LINTSRC;
532 lintsrc.irqflag = 0; /* conforming */
533 lintsrc.srcbusid = 0;
534 lintsrc.srcbusirq = 0;
535 lintsrc.destapic = MP_APIC_ALL;
536 for (i = 0; i < 2; i++) {
537 lintsrc.irqtype = linttypes[i];
538 lintsrc.destapiclint = i;
539 MP_lintsrc_info(&lintsrc);
543 static struct mpf_intel *mpf_found;
545 static unsigned long __init get_mpc_size(unsigned long physptr)
547 struct mpc_table *mpc;
550 mpc = early_ioremap(physptr, PAGE_SIZE);
552 early_iounmap(mpc, PAGE_SIZE);
553 apic_printk(APIC_VERBOSE, " mpc: %lx-%lx\n", physptr, physptr + size);
558 static int __init check_physptr(struct mpf_intel *mpf, unsigned int early)
560 struct mpc_table *mpc;
563 size = get_mpc_size(mpf->physptr);
564 mpc = early_ioremap(mpf->physptr, size);
566 * Read the physical hardware table. Anything here will
567 * override the defaults.
569 if (!smp_read_mpc(mpc, early)) {
570 #ifdef CONFIG_X86_LOCAL_APIC
571 smp_found_config = 0;
573 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n"
574 "... disabling SMP support. (tell your hw vendor)\n");
575 early_iounmap(mpc, size);
578 early_iounmap(mpc, size);
583 #ifdef CONFIG_X86_IO_APIC
585 * If there are no explicit MP IRQ entries, then we are
586 * broken. We set up most of the low 16 IO-APIC pins to
587 * ISA defaults and hope it will work.
589 if (!mp_irq_entries) {
592 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
593 "using default mptable. (tell your hw vendor)\n");
597 memcpy(bus.bustype, "ISA ", 6);
600 construct_default_ioirq_mptable(0);
608 * Scan the memory blocks for an SMP configuration block.
610 static void __init __get_smp_config(unsigned int early)
612 struct mpf_intel *mpf = mpf_found;
617 if (acpi_lapic && early)
621 * MPS doesn't support hyperthreading, aka only have
622 * thread 0 apic id in MPS table
624 if (acpi_lapic && acpi_ioapic)
627 if (x86_quirks->mach_get_smp_config) {
628 if (x86_quirks->mach_get_smp_config(early))
632 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
634 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
635 if (mpf->feature2 & (1 << 7)) {
636 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
639 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
644 * Now see if we need to read further.
646 if (mpf->feature1 != 0) {
649 * local APIC has default address
651 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
655 printk(KERN_INFO "Default MP configuration #%d\n",
657 construct_default_ISA_mptable(mpf->feature1);
659 } else if (mpf->physptr) {
660 if (check_physptr(mpf, early))
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 void smp_reserve_bootmem(struct mpf_intel *mpf)
684 unsigned long size = get_mpc_size(mpf->physptr);
687 * We cannot access to MPC table to compute table size yet,
688 * as only few megabytes from the bottom is mapped now.
689 * PC-9800's MPC table places on the very last of physical
690 * memory; so that simply reserving PAGE_SIZE from mpf->physptr
691 * yields BUG() in reserve_bootmem.
692 * also need to make sure physptr is below than max_low_pfn
693 * we don't need reserve the area above max_low_pfn
695 unsigned long end = max_low_pfn * PAGE_SIZE;
697 if (mpf->physptr < end) {
698 if (mpf->physptr + size > end)
699 size = end - mpf->physptr;
700 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
703 reserve_bootmem_generic(mpf->physptr, size, BOOTMEM_DEFAULT);
707 static int __init smp_scan_config(unsigned long base, unsigned long length,
710 unsigned int *bp = phys_to_virt(base);
711 struct mpf_intel *mpf;
713 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
715 BUILD_BUG_ON(sizeof(*mpf) != 16);
718 mpf = (struct mpf_intel *)bp;
719 if ((*bp == SMP_MAGIC_IDENT) &&
720 (mpf->length == 1) &&
721 !mpf_checksum((unsigned char *)bp, 16) &&
722 ((mpf->specification == 1)
723 || (mpf->specification == 4))) {
724 #ifdef CONFIG_X86_LOCAL_APIC
725 smp_found_config = 1;
729 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
730 mpf, (u64)virt_to_phys(mpf));
734 reserve_bootmem_generic(virt_to_phys(mpf), sizeof(*mpf),
737 smp_reserve_bootmem(mpf);
747 static void __init __find_smp_config(unsigned int reserve)
749 unsigned int address;
751 if (x86_quirks->mach_find_smp_config) {
752 if (x86_quirks->mach_find_smp_config(reserve))
756 * FIXME: Linux assumes you have 640K of base ram..
757 * this continues the error...
759 * 1) Scan the bottom 1K for a signature
760 * 2) Scan the top 1K of base RAM
761 * 3) Scan the 64K of bios
763 if (smp_scan_config(0x0, 0x400, reserve) ||
764 smp_scan_config(639 * 0x400, 0x400, reserve) ||
765 smp_scan_config(0xF0000, 0x10000, reserve))
768 * If it is an SMP machine we should know now, unless the
769 * configuration is in an EISA/MCA bus machine with an
770 * extended bios data area.
772 * there is a real-mode segmented pointer pointing to the
773 * 4K EBDA area at 0x40E, calculate and scan it here.
775 * NOTE! There are Linux loaders that will corrupt the EBDA
776 * area, and as such this kind of SMP config may be less
777 * trustworthy, simply because the SMP table may have been
778 * stomped on during early boot. These loaders are buggy and
781 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
784 address = get_bios_ebda();
786 smp_scan_config(address, 0x400, reserve);
789 void __init early_find_smp_config(void)
791 __find_smp_config(0);
794 void __init find_smp_config(void)
796 __find_smp_config(1);
799 #ifdef CONFIG_X86_IO_APIC
800 static u8 __initdata irq_used[MAX_IRQ_SOURCES];
802 static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
806 if (m->irqtype != mp_INT)
809 if (m->irqflag != 0x0f)
814 for (i = 0; i < mp_irq_entries; i++) {
815 if (mp_irqs[i].irqtype != mp_INT)
818 if (mp_irqs[i].irqflag != 0x0f)
821 if (mp_irqs[i].srcbus != m->srcbus)
823 if (mp_irqs[i].srcbusirq != m->srcbusirq)
826 /* already claimed */
837 #define SPARE_SLOT_NUM 20
839 static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
841 static void check_irq_src(struct mpc_intsrc *m, int *nr_m_spare)
845 apic_printk(APIC_VERBOSE, "OLD ");
846 print_MP_intsrc_info(m);
848 i = get_MP_intsrc_index(m);
850 assign_to_mpc_intsrc(&mp_irqs[i], m);
851 apic_printk(APIC_VERBOSE, "NEW ");
852 print_mp_irq_info(&mp_irqs[i]);
856 /* legacy, do nothing */
859 if (*nr_m_spare < SPARE_SLOT_NUM) {
861 * not found (-1), or duplicated (-2) are invalid entries,
862 * we need to use the slot later
864 m_spare[*nr_m_spare] = m;
868 #else /* CONFIG_X86_IO_APIC */
869 static inline void check_irq_src(struct mpc_intsrc *m, int *nr_m_spare) {}
870 #endif /* CONFIG_X86_IO_APIC */
872 static int check_slot(unsigned long mpc_new_phys, unsigned long mpc_new_length,
876 pr_info("No spare slots, try to append...take your risk, "
877 "new mpc_length %x\n", count);
879 if (count <= mpc_new_length)
880 pr_info("No spare slots, try to append..., "
881 "new mpc_length %x\n", count);
883 pr_err("mpc_new_length %lx is too small\n",
892 static int __init replace_intsrc_all(struct mpc_table *mpc,
893 unsigned long mpc_new_phys,
894 unsigned long mpc_new_length)
896 #ifdef CONFIG_X86_IO_APIC
899 int count = sizeof(*mpc);
901 unsigned char *mpt = ((unsigned char *)mpc) + count;
903 printk(KERN_INFO "mpc_length %x\n", mpc->length);
904 while (count < mpc->length) {
907 skip_entry(&mpt, &count, sizeof(struct mpc_cpu));
910 skip_entry(&mpt, &count, sizeof(struct mpc_bus));
913 skip_entry(&mpt, &count, sizeof(struct mpc_ioapic));
916 check_irq_src((struct mpc_intsrc *)mpt, &nr_m_spare);
917 skip_entry(&mpt, &count, sizeof(struct mpc_intsrc));
920 skip_entry(&mpt, &count, sizeof(struct mpc_lintsrc));
924 smp_dump_mptable(mpc, mpt);
929 #ifdef CONFIG_X86_IO_APIC
930 for (i = 0; i < mp_irq_entries; i++) {
934 if (mp_irqs[i].irqtype != mp_INT)
937 if (mp_irqs[i].irqflag != 0x0f)
940 if (nr_m_spare > 0) {
941 apic_printk(APIC_VERBOSE, "*NEW* found\n");
943 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
944 m_spare[nr_m_spare] = NULL;
946 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
947 count += sizeof(struct mpc_intsrc);
948 if (!check_slot(mpc_new_phys, mpc_new_length, count))
950 assign_to_mpc_intsrc(&mp_irqs[i], m);
952 mpt += sizeof(struct mpc_intsrc);
954 print_mp_irq_info(&mp_irqs[i]);
958 /* update checksum */
960 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
965 static int __initdata enable_update_mptable;
967 static int __init update_mptable_setup(char *str)
969 enable_update_mptable = 1;
972 early_param("update_mptable", update_mptable_setup);
974 static unsigned long __initdata mpc_new_phys;
975 static unsigned long mpc_new_length __initdata = 4096;
977 /* alloc_mptable or alloc_mptable=4k */
978 static int __initdata alloc_mptable;
979 static int __init parse_alloc_mptable_opt(char *p)
981 enable_update_mptable = 1;
985 mpc_new_length = memparse(p, &p);
988 early_param("alloc_mptable", parse_alloc_mptable_opt);
990 void __init early_reserve_e820_mpc_new(void)
992 if (enable_update_mptable && alloc_mptable) {
994 #ifdef CONFIG_X86_TRAMPOLINE
995 startt = TRAMPOLINE_BASE;
997 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
1001 static int __init update_mp_table(void)
1005 struct mpf_intel *mpf;
1006 struct mpc_table *mpc, *mpc_new;
1008 if (!enable_update_mptable)
1016 * Now see if we need to go further.
1018 if (mpf->feature1 != 0)
1024 mpc = phys_to_virt(mpf->physptr);
1026 if (!smp_check_mpc(mpc, oem, str))
1029 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
1030 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
1032 if (mpc_new_phys && mpc->length > mpc_new_length) {
1034 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1038 if (!mpc_new_phys) {
1039 unsigned char old, new;
1040 /* check if we can change the postion */
1042 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1043 mpc->checksum = 0xff;
1044 new = mpf_checksum((unsigned char *)mpc, mpc->length);
1046 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1049 printk(KERN_INFO "use in-positon replacing\n");
1051 mpf->physptr = mpc_new_phys;
1052 mpc_new = phys_to_virt(mpc_new_phys);
1053 memcpy(mpc_new, mpc, mpc->length);
1055 /* check if we can modify that */
1056 if (mpc_new_phys - mpf->physptr) {
1057 struct mpf_intel *mpf_new;
1058 /* steal 16 bytes from [0, 1k) */
1059 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1060 mpf_new = phys_to_virt(0x400 - 16);
1061 memcpy(mpf_new, mpf, 16);
1063 mpf->physptr = mpc_new_phys;
1066 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1067 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
1071 * only replace the one with mp_INT and
1072 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1073 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1074 * may need pci=routeirq for all coverage
1076 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1081 late_initcall(update_mp_table);