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);
114 #ifdef CONFIG_X86_IO_APIC
116 static int bad_ioapic(unsigned long address)
118 if (nr_ioapics >= MAX_IO_APICS) {
119 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
120 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
121 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
124 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
125 " found in table, skipping!\n");
131 static void __init MP_ioapic_info(struct mpc_ioapic *m)
133 if (!(m->flags & MPC_APIC_USABLE))
136 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
137 m->apicid, m->apicver, m->apicaddr);
139 if (bad_ioapic(m->apicaddr))
142 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
143 mp_ioapics[nr_ioapics].apicid = m->apicid;
144 mp_ioapics[nr_ioapics].type = m->type;
145 mp_ioapics[nr_ioapics].apicver = m->apicver;
146 mp_ioapics[nr_ioapics].flags = m->flags;
150 static void print_MP_intsrc_info(struct mpc_intsrc *m)
152 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
153 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
154 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
155 m->srcbusirq, m->dstapic, m->dstirq);
158 static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
160 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
161 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
162 mp_irq->irqtype, mp_irq->irqflag & 3,
163 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
164 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
167 static void __init assign_to_mp_irq(struct mpc_intsrc *m,
168 struct mpc_intsrc *mp_irq)
170 mp_irq->dstapic = m->dstapic;
171 mp_irq->type = m->type;
172 mp_irq->irqtype = m->irqtype;
173 mp_irq->irqflag = m->irqflag;
174 mp_irq->srcbus = m->srcbus;
175 mp_irq->srcbusirq = m->srcbusirq;
176 mp_irq->dstirq = m->dstirq;
179 static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
180 struct mpc_intsrc *m)
182 m->dstapic = mp_irq->dstapic;
183 m->type = mp_irq->type;
184 m->irqtype = mp_irq->irqtype;
185 m->irqflag = mp_irq->irqflag;
186 m->srcbus = mp_irq->srcbus;
187 m->srcbusirq = mp_irq->srcbusirq;
188 m->dstirq = mp_irq->dstirq;
191 static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
192 struct mpc_intsrc *m)
194 if (mp_irq->dstapic != m->dstapic)
196 if (mp_irq->type != m->type)
198 if (mp_irq->irqtype != m->irqtype)
200 if (mp_irq->irqflag != m->irqflag)
202 if (mp_irq->srcbus != m->srcbus)
204 if (mp_irq->srcbusirq != m->srcbusirq)
206 if (mp_irq->dstirq != m->dstirq)
212 static void __init MP_intsrc_info(struct mpc_intsrc *m)
216 print_MP_intsrc_info(m);
218 for (i = 0; i < mp_irq_entries; i++) {
219 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
223 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
224 if (++mp_irq_entries == MAX_IRQ_SOURCES)
225 panic("Max # of irq sources exceeded!!\n");
230 static void __init MP_lintsrc_info(struct mpc_lintsrc *m)
232 apic_printk(APIC_VERBOSE, "Lint: type %d, pol %d, trig %d, bus %02x,"
233 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
234 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbusid,
235 m->srcbusirq, m->destapic, m->destapiclint);
242 static int __init smp_check_mpc(struct mpc_table *mpc, char *oem, char *str)
245 if (memcmp(mpc->signature, MPC_SIGNATURE, 4)) {
246 printk(KERN_ERR "MPTABLE: bad signature [%c%c%c%c]!\n",
247 mpc->signature[0], mpc->signature[1],
248 mpc->signature[2], mpc->signature[3]);
251 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
252 printk(KERN_ERR "MPTABLE: checksum error!\n");
255 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
256 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
261 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
264 memcpy(oem, mpc->oem, 8);
266 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
268 memcpy(str, mpc->productid, 12);
271 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
273 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
278 static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
283 int count = sizeof(*mpc);
284 unsigned char *mpt = ((unsigned char *)mpc) + count;
286 if (!smp_check_mpc(mpc, oem, str))
290 generic_mps_oem_check(mpc, oem, str);
292 /* save the local APIC address, it might be non-default */
294 mp_lapic_addr = mpc->lapic;
299 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
300 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
301 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
305 * Now process the configuration blocks.
307 if (x86_quirks->mpc_record)
308 *x86_quirks->mpc_record = 0;
310 while (count < mpc->length) {
314 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
315 /* ACPI may have already provided this data */
317 MP_processor_info(m);
324 struct mpc_bus *m = (struct mpc_bus *)mpt;
325 #ifdef CONFIG_X86_IO_APIC
334 #ifdef CONFIG_X86_IO_APIC
335 struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
338 mpt += sizeof(struct mpc_ioapic);
339 count += sizeof(struct mpc_ioapic);
344 #ifdef CONFIG_X86_IO_APIC
345 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
349 mpt += sizeof(struct mpc_intsrc);
350 count += sizeof(struct mpc_intsrc);
355 struct mpc_lintsrc *m =
356 (struct mpc_lintsrc *)mpt;
364 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
365 printk(KERN_ERR "type %x\n", *mpt);
366 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
367 1, mpc, mpc->length, 1);
371 if (x86_quirks->mpc_record)
372 (*x86_quirks->mpc_record)++;
375 #ifdef CONFIG_X86_BIGSMP
376 generic_bigsmp_probe();
379 if (apic->setup_apic_routing)
380 apic->setup_apic_routing();
383 printk(KERN_ERR "MPTABLE: no processors registered!\n");
384 return num_processors;
387 #ifdef CONFIG_X86_IO_APIC
389 static int __init ELCR_trigger(unsigned int irq)
393 port = 0x4d0 + (irq >> 3);
394 return (inb(port) >> (irq & 7)) & 1;
397 static void __init construct_default_ioirq_mptable(int mpc_default_type)
399 struct mpc_intsrc intsrc;
401 int ELCR_fallback = 0;
403 intsrc.type = MP_INTSRC;
404 intsrc.irqflag = 0; /* conforming */
406 intsrc.dstapic = mp_ioapics[0].apicid;
408 intsrc.irqtype = mp_INT;
411 * If true, we have an ISA/PCI system with no IRQ entries
412 * in the MP table. To prevent the PCI interrupts from being set up
413 * incorrectly, we try to use the ELCR. The sanity check to see if
414 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
415 * never be level sensitive, so we simply see if the ELCR agrees.
416 * If it does, we assume it's valid.
418 if (mpc_default_type == 5) {
419 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
420 "falling back to ELCR\n");
422 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
424 printk(KERN_ERR "ELCR contains invalid data... "
428 "Using ELCR to identify PCI interrupts\n");
433 for (i = 0; i < 16; i++) {
434 switch (mpc_default_type) {
436 if (i == 0 || i == 13)
437 continue; /* IRQ0 & IRQ13 not connected */
441 continue; /* IRQ2 is never connected */
446 * If the ELCR indicates a level-sensitive interrupt, we
447 * copy that information over to the MP table in the
448 * irqflag field (level sensitive, active high polarity).
456 intsrc.srcbusirq = i;
457 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
458 MP_intsrc_info(&intsrc);
461 intsrc.irqtype = mp_ExtINT;
462 intsrc.srcbusirq = 0;
463 intsrc.dstirq = 0; /* 8259A to INTIN0 */
464 MP_intsrc_info(&intsrc);
468 static void __init construct_ioapic_table(int mpc_default_type)
470 struct mpc_ioapic ioapic;
475 switch (mpc_default_type) {
477 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
482 memcpy(bus.bustype, "ISA ", 6);
487 memcpy(bus.bustype, "EISA ", 6);
491 memcpy(bus.bustype, "MCA ", 6);
494 if (mpc_default_type > 4) {
496 memcpy(bus.bustype, "PCI ", 6);
500 ioapic.type = MP_IOAPIC;
502 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
503 ioapic.flags = MPC_APIC_USABLE;
504 ioapic.apicaddr = 0xFEC00000;
505 MP_ioapic_info(&ioapic);
508 * We set up most of the low 16 IO-APIC pins according to MPS rules.
510 construct_default_ioirq_mptable(mpc_default_type);
513 static inline void __init construct_ioapic_table(int mpc_default_type) { }
516 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
518 struct mpc_cpu processor;
519 struct mpc_lintsrc lintsrc;
520 int linttypes[2] = { mp_ExtINT, mp_NMI };
524 * local APIC has default address
526 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
529 * 2 CPUs, numbered 0 & 1.
531 processor.type = MP_PROCESSOR;
532 /* Either an integrated APIC or a discrete 82489DX. */
533 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
534 processor.cpuflag = CPU_ENABLED;
535 processor.cpufeature = (boot_cpu_data.x86 << 8) |
536 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
537 processor.featureflag = boot_cpu_data.x86_capability[0];
538 processor.reserved[0] = 0;
539 processor.reserved[1] = 0;
540 for (i = 0; i < 2; i++) {
541 processor.apicid = i;
542 MP_processor_info(&processor);
545 construct_ioapic_table(mpc_default_type);
547 lintsrc.type = MP_LINTSRC;
548 lintsrc.irqflag = 0; /* conforming */
549 lintsrc.srcbusid = 0;
550 lintsrc.srcbusirq = 0;
551 lintsrc.destapic = MP_APIC_ALL;
552 for (i = 0; i < 2; i++) {
553 lintsrc.irqtype = linttypes[i];
554 lintsrc.destapiclint = i;
555 MP_lintsrc_info(&lintsrc);
559 static struct mpf_intel *mpf_found;
562 * Scan the memory blocks for an SMP configuration block.
564 static void __init __get_smp_config(unsigned int early)
566 struct mpf_intel *mpf = mpf_found;
571 if (acpi_lapic && early)
575 * MPS doesn't support hyperthreading, aka only have
576 * thread 0 apic id in MPS table
578 if (acpi_lapic && acpi_ioapic)
581 if (x86_quirks->mach_get_smp_config) {
582 if (x86_quirks->mach_get_smp_config(early))
586 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
588 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
589 if (mpf->feature2 & (1 << 7)) {
590 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
593 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
598 * Now see if we need to read further.
600 if (mpf->feature1 != 0) {
603 * local APIC has default address
605 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
609 printk(KERN_INFO "Default MP configuration #%d\n",
611 construct_default_ISA_mptable(mpf->feature1);
613 } else if (mpf->physptr) {
616 * Read the physical hardware table. Anything here will
617 * override the defaults.
619 if (!smp_read_mpc(phys_to_virt(mpf->physptr), early)) {
620 #ifdef CONFIG_X86_LOCAL_APIC
621 smp_found_config = 0;
624 "BIOS bug, MP table errors detected!...\n");
625 printk(KERN_ERR "... disabling SMP support. "
626 "(tell your hw vendor)\n");
632 #ifdef CONFIG_X86_IO_APIC
634 * If there are no explicit MP IRQ entries, then we are
635 * broken. We set up most of the low 16 IO-APIC pins to
636 * ISA defaults and hope it will work.
638 if (!mp_irq_entries) {
641 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
642 "using default mptable. "
643 "(tell your hw vendor)\n");
647 memcpy(bus.bustype, "ISA ", 6);
650 construct_default_ioirq_mptable(0);
657 printk(KERN_INFO "Processors: %d\n", num_processors);
659 * Only use the first configuration found.
663 void __init early_get_smp_config(void)
668 void __init get_smp_config(void)
673 static int __init smp_scan_config(unsigned long base, unsigned long length,
676 unsigned int *bp = phys_to_virt(base);
677 struct mpf_intel *mpf;
679 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
681 BUILD_BUG_ON(sizeof(*mpf) != 16);
684 mpf = (struct mpf_intel *)bp;
685 if ((*bp == SMP_MAGIC_IDENT) &&
686 (mpf->length == 1) &&
687 !mpf_checksum((unsigned char *)bp, 16) &&
688 ((mpf->specification == 1)
689 || (mpf->specification == 4))) {
690 #ifdef CONFIG_X86_LOCAL_APIC
691 smp_found_config = 1;
695 printk(KERN_INFO "found SMP MP-table at [%p] %llx\n",
696 mpf, (u64)virt_to_phys(mpf));
700 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
703 unsigned long size = PAGE_SIZE;
706 * We cannot access to MPC table to compute
707 * table size yet, as only few megabytes from
708 * the bottom is mapped now.
709 * PC-9800's MPC table places on the very last
710 * of physical memory; so that simply reserving
711 * PAGE_SIZE from mpf->physptr yields BUG()
712 * in reserve_bootmem.
713 * also need to make sure physptr is below than
715 * we don't need reserve the area above max_low_pfn
717 unsigned long end = max_low_pfn * PAGE_SIZE;
719 if (mpf->physptr < end) {
720 if (mpf->physptr + size > end)
721 size = end - mpf->physptr;
722 reserve_bootmem_generic(mpf->physptr, size,
726 reserve_bootmem_generic(mpf->physptr, size,
739 static void __init __find_smp_config(unsigned int reserve)
741 unsigned int address;
743 if (x86_quirks->mach_find_smp_config) {
744 if (x86_quirks->mach_find_smp_config(reserve))
748 * FIXME: Linux assumes you have 640K of base ram..
749 * this continues the error...
751 * 1) Scan the bottom 1K for a signature
752 * 2) Scan the top 1K of base RAM
753 * 3) Scan the 64K of bios
755 if (smp_scan_config(0x0, 0x400, reserve) ||
756 smp_scan_config(639 * 0x400, 0x400, reserve) ||
757 smp_scan_config(0xF0000, 0x10000, reserve))
760 * If it is an SMP machine we should know now, unless the
761 * configuration is in an EISA/MCA bus machine with an
762 * extended bios data area.
764 * there is a real-mode segmented pointer pointing to the
765 * 4K EBDA area at 0x40E, calculate and scan it here.
767 * NOTE! There are Linux loaders that will corrupt the EBDA
768 * area, and as such this kind of SMP config may be less
769 * trustworthy, simply because the SMP table may have been
770 * stomped on during early boot. These loaders are buggy and
773 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
776 address = get_bios_ebda();
778 smp_scan_config(address, 0x400, reserve);
781 void __init early_find_smp_config(void)
783 __find_smp_config(0);
786 void __init find_smp_config(void)
788 __find_smp_config(1);
791 #ifdef CONFIG_X86_IO_APIC
792 static u8 __initdata irq_used[MAX_IRQ_SOURCES];
794 static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
798 if (m->irqtype != mp_INT)
801 if (m->irqflag != 0x0f)
806 for (i = 0; i < mp_irq_entries; i++) {
807 if (mp_irqs[i].irqtype != mp_INT)
810 if (mp_irqs[i].irqflag != 0x0f)
813 if (mp_irqs[i].srcbus != m->srcbus)
815 if (mp_irqs[i].srcbusirq != m->srcbusirq)
818 /* already claimed */
829 #define SPARE_SLOT_NUM 20
831 static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
834 static int __init replace_intsrc_all(struct mpc_table *mpc,
835 unsigned long mpc_new_phys,
836 unsigned long mpc_new_length)
838 #ifdef CONFIG_X86_IO_APIC
843 int count = sizeof(*mpc);
844 unsigned char *mpt = ((unsigned char *)mpc) + count;
846 printk(KERN_INFO "mpc_length %x\n", mpc->length);
847 while (count < mpc->length) {
851 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
858 struct mpc_bus *m = (struct mpc_bus *)mpt;
865 mpt += sizeof(struct mpc_ioapic);
866 count += sizeof(struct mpc_ioapic);
871 #ifdef CONFIG_X86_IO_APIC
872 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
874 printk(KERN_INFO "OLD ");
875 print_MP_intsrc_info(m);
876 i = get_MP_intsrc_index(m);
878 assign_to_mpc_intsrc(&mp_irqs[i], m);
879 printk(KERN_INFO "NEW ");
880 print_mp_irq_info(&mp_irqs[i]);
882 /* legacy, do nothing */
883 } else if (nr_m_spare < SPARE_SLOT_NUM) {
885 * not found (-1), or duplicated (-2)
886 * are invalid entries,
887 * we need to use the slot later
889 m_spare[nr_m_spare] = m;
893 mpt += sizeof(struct mpc_intsrc);
894 count += sizeof(struct mpc_intsrc);
899 struct mpc_lintsrc *m =
900 (struct mpc_lintsrc *)mpt;
907 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
908 printk(KERN_ERR "type %x\n", *mpt);
909 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
910 1, mpc, mpc->length, 1);
915 #ifdef CONFIG_X86_IO_APIC
916 for (i = 0; i < mp_irq_entries; i++) {
920 if (mp_irqs[i].irqtype != mp_INT)
923 if (mp_irqs[i].irqflag != 0x0f)
926 if (nr_m_spare > 0) {
927 printk(KERN_INFO "*NEW* found ");
929 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
930 m_spare[nr_m_spare] = NULL;
932 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
933 count += sizeof(struct mpc_intsrc);
935 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
937 if (count <= mpc_new_length)
938 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
940 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
944 assign_to_mpc_intsrc(&mp_irqs[i], m);
946 mpt += sizeof(struct mpc_intsrc);
948 print_mp_irq_info(&mp_irqs[i]);
952 /* update checksum */
954 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
959 static int __initdata enable_update_mptable;
961 static int __init update_mptable_setup(char *str)
963 enable_update_mptable = 1;
966 early_param("update_mptable", update_mptable_setup);
968 static unsigned long __initdata mpc_new_phys;
969 static unsigned long mpc_new_length __initdata = 4096;
971 /* alloc_mptable or alloc_mptable=4k */
972 static int __initdata alloc_mptable;
973 static int __init parse_alloc_mptable_opt(char *p)
975 enable_update_mptable = 1;
979 mpc_new_length = memparse(p, &p);
982 early_param("alloc_mptable", parse_alloc_mptable_opt);
984 void __init early_reserve_e820_mpc_new(void)
986 if (enable_update_mptable && alloc_mptable) {
988 #ifdef CONFIG_X86_TRAMPOLINE
989 startt = TRAMPOLINE_BASE;
991 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
995 static int __init update_mp_table(void)
999 struct mpf_intel *mpf;
1000 struct mpc_table *mpc, *mpc_new;
1002 if (!enable_update_mptable)
1010 * Now see if we need to go further.
1012 if (mpf->feature1 != 0)
1018 mpc = phys_to_virt(mpf->physptr);
1020 if (!smp_check_mpc(mpc, oem, str))
1023 printk(KERN_INFO "mpf: %llx\n", (u64)virt_to_phys(mpf));
1024 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
1026 if (mpc_new_phys && mpc->length > mpc_new_length) {
1028 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1032 if (!mpc_new_phys) {
1033 unsigned char old, new;
1034 /* check if we can change the postion */
1036 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1037 mpc->checksum = 0xff;
1038 new = mpf_checksum((unsigned char *)mpc, mpc->length);
1040 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1043 printk(KERN_INFO "use in-positon replacing\n");
1045 mpf->physptr = mpc_new_phys;
1046 mpc_new = phys_to_virt(mpc_new_phys);
1047 memcpy(mpc_new, mpc, mpc->length);
1049 /* check if we can modify that */
1050 if (mpc_new_phys - mpf->physptr) {
1051 struct mpf_intel *mpf_new;
1052 /* steal 16 bytes from [0, 1k) */
1053 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1054 mpf_new = phys_to_virt(0x400 - 16);
1055 memcpy(mpf_new, mpf, 16);
1057 mpf->physptr = mpc_new_phys;
1060 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1061 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
1065 * only replace the one with mp_INT and
1066 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1067 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1068 * may need pci=routeirq for all coverage
1070 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1075 late_initcall(update_mp_table);