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/memblock.h>
15 #include <linux/kernel_stat.h>
16 #include <linux/mc146818rtc.h>
17 #include <linux/bitops.h>
18 #include <linux/acpi.h>
19 #include <linux/module.h>
20 #include <linux/smp.h>
21 #include <linux/pci.h>
24 #include <asm/mpspec.h>
25 #include <asm/pgalloc.h>
26 #include <asm/io_apic.h>
27 #include <asm/proto.h>
28 #include <asm/bios_ebda.h>
30 #include <asm/trampoline.h>
31 #include <asm/setup.h>
36 * Checksum an MP configuration block.
39 static int __init
mpf_checksum(unsigned char *mp
, int len
)
49 int __init
default_mpc_apic_id(struct mpc_cpu
*m
)
54 static void __init
MP_processor_info(struct mpc_cpu
*m
)
57 char *bootup_cpu
= "";
59 if (!(m
->cpuflag
& CPU_ENABLED
)) {
64 apicid
= x86_init
.mpparse
.mpc_apic_id(m
);
66 if (m
->cpuflag
& CPU_BOOTPROCESSOR
) {
67 bootup_cpu
= " (Bootup-CPU)";
68 boot_cpu_physical_apicid
= m
->apicid
;
71 printk(KERN_INFO
"Processor #%d%s\n", m
->apicid
, bootup_cpu
);
72 generic_processor_info(apicid
, m
->apicver
);
75 #ifdef CONFIG_X86_IO_APIC
76 void __init
default_mpc_oem_bus_info(struct mpc_bus
*m
, char *str
)
78 memcpy(str
, m
->bustype
, 6);
80 apic_printk(APIC_VERBOSE
, "Bus #%d is %s\n", m
->busid
, str
);
83 static void __init
MP_bus_info(struct mpc_bus
*m
)
87 x86_init
.mpparse
.mpc_oem_bus_info(m
, str
);
89 #if MAX_MP_BUSSES < 256
90 if (m
->busid
>= MAX_MP_BUSSES
) {
91 printk(KERN_WARNING
"MP table busid value (%d) for bustype %s "
92 " is too large, max. supported is %d\n",
93 m
->busid
, str
, MAX_MP_BUSSES
- 1);
98 if (strncmp(str
, BUSTYPE_ISA
, sizeof(BUSTYPE_ISA
) - 1) == 0) {
99 set_bit(m
->busid
, mp_bus_not_pci
);
100 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
101 mp_bus_id_to_type
[m
->busid
] = MP_BUS_ISA
;
103 } else if (strncmp(str
, BUSTYPE_PCI
, sizeof(BUSTYPE_PCI
) - 1) == 0) {
104 if (x86_init
.mpparse
.mpc_oem_pci_bus
)
105 x86_init
.mpparse
.mpc_oem_pci_bus(m
);
107 clear_bit(m
->busid
, mp_bus_not_pci
);
108 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
109 mp_bus_id_to_type
[m
->busid
] = MP_BUS_PCI
;
110 } else if (strncmp(str
, BUSTYPE_EISA
, sizeof(BUSTYPE_EISA
) - 1) == 0) {
111 mp_bus_id_to_type
[m
->busid
] = MP_BUS_EISA
;
112 } else if (strncmp(str
, BUSTYPE_MCA
, sizeof(BUSTYPE_MCA
) - 1) == 0) {
113 mp_bus_id_to_type
[m
->busid
] = MP_BUS_MCA
;
116 printk(KERN_WARNING
"Unknown bustype %s - ignoring\n", str
);
119 static void __init
MP_ioapic_info(struct mpc_ioapic
*m
)
121 if (!(m
->flags
& MPC_APIC_USABLE
))
124 printk(KERN_INFO
"I/O APIC #%d Version %d at 0x%X.\n",
125 m
->apicid
, m
->apicver
, m
->apicaddr
);
127 mp_register_ioapic(m
->apicid
, m
->apicaddr
, gsi_top
);
130 static void print_MP_intsrc_info(struct mpc_intsrc
*m
)
132 apic_printk(APIC_VERBOSE
, "Int: type %d, pol %d, trig %d, bus %02x,"
133 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
134 m
->irqtype
, m
->irqflag
& 3, (m
->irqflag
>> 2) & 3, m
->srcbus
,
135 m
->srcbusirq
, m
->dstapic
, m
->dstirq
);
138 static void __init
print_mp_irq_info(struct mpc_intsrc
*mp_irq
)
140 apic_printk(APIC_VERBOSE
, "Int: type %d, pol %d, trig %d, bus %02x,"
141 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
142 mp_irq
->irqtype
, mp_irq
->irqflag
& 3,
143 (mp_irq
->irqflag
>> 2) & 3, mp_irq
->srcbus
,
144 mp_irq
->srcbusirq
, mp_irq
->dstapic
, mp_irq
->dstirq
);
147 static void __init
assign_to_mp_irq(struct mpc_intsrc
*m
,
148 struct mpc_intsrc
*mp_irq
)
150 mp_irq
->dstapic
= m
->dstapic
;
151 mp_irq
->type
= m
->type
;
152 mp_irq
->irqtype
= m
->irqtype
;
153 mp_irq
->irqflag
= m
->irqflag
;
154 mp_irq
->srcbus
= m
->srcbus
;
155 mp_irq
->srcbusirq
= m
->srcbusirq
;
156 mp_irq
->dstirq
= m
->dstirq
;
159 static void __init
assign_to_mpc_intsrc(struct mpc_intsrc
*mp_irq
,
160 struct mpc_intsrc
*m
)
162 m
->dstapic
= mp_irq
->dstapic
;
163 m
->type
= mp_irq
->type
;
164 m
->irqtype
= mp_irq
->irqtype
;
165 m
->irqflag
= mp_irq
->irqflag
;
166 m
->srcbus
= mp_irq
->srcbus
;
167 m
->srcbusirq
= mp_irq
->srcbusirq
;
168 m
->dstirq
= mp_irq
->dstirq
;
171 static int __init
mp_irq_mpc_intsrc_cmp(struct mpc_intsrc
*mp_irq
,
172 struct mpc_intsrc
*m
)
174 if (mp_irq
->dstapic
!= m
->dstapic
)
176 if (mp_irq
->type
!= m
->type
)
178 if (mp_irq
->irqtype
!= m
->irqtype
)
180 if (mp_irq
->irqflag
!= m
->irqflag
)
182 if (mp_irq
->srcbus
!= m
->srcbus
)
184 if (mp_irq
->srcbusirq
!= m
->srcbusirq
)
186 if (mp_irq
->dstirq
!= m
->dstirq
)
192 static void __init
MP_intsrc_info(struct mpc_intsrc
*m
)
196 print_MP_intsrc_info(m
);
198 for (i
= 0; i
< mp_irq_entries
; i
++) {
199 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs
[i
], m
))
203 assign_to_mp_irq(m
, &mp_irqs
[mp_irq_entries
]);
204 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
205 panic("Max # of irq sources exceeded!!\n");
207 #else /* CONFIG_X86_IO_APIC */
208 static inline void __init
MP_bus_info(struct mpc_bus
*m
) {}
209 static inline void __init
MP_ioapic_info(struct mpc_ioapic
*m
) {}
210 static inline void __init
MP_intsrc_info(struct mpc_intsrc
*m
) {}
211 #endif /* CONFIG_X86_IO_APIC */
214 static void __init
MP_lintsrc_info(struct mpc_lintsrc
*m
)
216 apic_printk(APIC_VERBOSE
, "Lint: type %d, pol %d, trig %d, bus %02x,"
217 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
218 m
->irqtype
, m
->irqflag
& 3, (m
->irqflag
>> 2) & 3, m
->srcbusid
,
219 m
->srcbusirq
, m
->destapic
, m
->destapiclint
);
226 static int __init
smp_check_mpc(struct mpc_table
*mpc
, char *oem
, char *str
)
229 if (memcmp(mpc
->signature
, MPC_SIGNATURE
, 4)) {
230 printk(KERN_ERR
"MPTABLE: bad signature [%c%c%c%c]!\n",
231 mpc
->signature
[0], mpc
->signature
[1],
232 mpc
->signature
[2], mpc
->signature
[3]);
235 if (mpf_checksum((unsigned char *)mpc
, mpc
->length
)) {
236 printk(KERN_ERR
"MPTABLE: checksum error!\n");
239 if (mpc
->spec
!= 0x01 && mpc
->spec
!= 0x04) {
240 printk(KERN_ERR
"MPTABLE: bad table version (%d)!!\n",
245 printk(KERN_ERR
"MPTABLE: null local APIC address!\n");
248 memcpy(oem
, mpc
->oem
, 8);
250 printk(KERN_INFO
"MPTABLE: OEM ID: %s\n", oem
);
252 memcpy(str
, mpc
->productid
, 12);
255 printk(KERN_INFO
"MPTABLE: Product ID: %s\n", str
);
257 printk(KERN_INFO
"MPTABLE: APIC at: 0x%X\n", mpc
->lapic
);
262 static void skip_entry(unsigned char **ptr
, int *count
, int size
)
268 static void __init
smp_dump_mptable(struct mpc_table
*mpc
, unsigned char *mpt
)
270 printk(KERN_ERR
"Your mptable is wrong, contact your HW vendor!\n"
272 print_hex_dump(KERN_ERR
, " ", DUMP_PREFIX_ADDRESS
, 16,
273 1, mpc
, mpc
->length
, 1);
276 void __init
default_smp_read_mpc_oem(struct mpc_table
*mpc
) { }
278 static void __init
smp_register_lapic_address(unsigned long address
)
280 mp_lapic_addr
= address
;
282 set_fixmap_nocache(FIX_APIC_BASE
, address
);
283 if (boot_cpu_physical_apicid
== -1U) {
284 boot_cpu_physical_apicid
= read_apic_id();
285 apic_version
[boot_cpu_physical_apicid
] =
286 GET_APIC_VERSION(apic_read(APIC_LVR
));
290 static int __init
smp_read_mpc(struct mpc_table
*mpc
, unsigned early
)
295 int count
= sizeof(*mpc
);
296 unsigned char *mpt
= ((unsigned char *)mpc
) + count
;
298 if (!smp_check_mpc(mpc
, oem
, str
))
302 generic_mps_oem_check(mpc
, oem
, str
);
304 /* save the local APIC address, it might be non-default */
306 mp_lapic_addr
= mpc
->lapic
;
311 /* Initialize the lapic mapping */
313 smp_register_lapic_address(mpc
->lapic
);
316 x86_init
.mpparse
.smp_read_mpc_oem(mpc
);
319 * Now process the configuration blocks.
321 x86_init
.mpparse
.mpc_record(0);
323 while (count
< mpc
->length
) {
326 /* ACPI may have already provided this data */
328 MP_processor_info((struct mpc_cpu
*)mpt
);
329 skip_entry(&mpt
, &count
, sizeof(struct mpc_cpu
));
332 MP_bus_info((struct mpc_bus
*)mpt
);
333 skip_entry(&mpt
, &count
, sizeof(struct mpc_bus
));
336 MP_ioapic_info((struct mpc_ioapic
*)mpt
);
337 skip_entry(&mpt
, &count
, sizeof(struct mpc_ioapic
));
340 MP_intsrc_info((struct mpc_intsrc
*)mpt
);
341 skip_entry(&mpt
, &count
, sizeof(struct mpc_intsrc
));
344 MP_lintsrc_info((struct mpc_lintsrc
*)mpt
);
345 skip_entry(&mpt
, &count
, sizeof(struct mpc_lintsrc
));
349 smp_dump_mptable(mpc
, mpt
);
353 x86_init
.mpparse
.mpc_record(1);
357 printk(KERN_ERR
"MPTABLE: no processors registered!\n");
358 return num_processors
;
361 #ifdef CONFIG_X86_IO_APIC
363 static int __init
ELCR_trigger(unsigned int irq
)
367 port
= 0x4d0 + (irq
>> 3);
368 return (inb(port
) >> (irq
& 7)) & 1;
371 static void __init
construct_default_ioirq_mptable(int mpc_default_type
)
373 struct mpc_intsrc intsrc
;
375 int ELCR_fallback
= 0;
377 intsrc
.type
= MP_INTSRC
;
378 intsrc
.irqflag
= 0; /* conforming */
380 intsrc
.dstapic
= mp_ioapics
[0].apicid
;
382 intsrc
.irqtype
= mp_INT
;
385 * If true, we have an ISA/PCI system with no IRQ entries
386 * in the MP table. To prevent the PCI interrupts from being set up
387 * incorrectly, we try to use the ELCR. The sanity check to see if
388 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
389 * never be level sensitive, so we simply see if the ELCR agrees.
390 * If it does, we assume it's valid.
392 if (mpc_default_type
== 5) {
393 printk(KERN_INFO
"ISA/PCI bus type with no IRQ information... "
394 "falling back to ELCR\n");
396 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
398 printk(KERN_ERR
"ELCR contains invalid data... "
402 "Using ELCR to identify PCI interrupts\n");
407 for (i
= 0; i
< 16; i
++) {
408 switch (mpc_default_type
) {
410 if (i
== 0 || i
== 13)
411 continue; /* IRQ0 & IRQ13 not connected */
415 continue; /* IRQ2 is never connected */
420 * If the ELCR indicates a level-sensitive interrupt, we
421 * copy that information over to the MP table in the
422 * irqflag field (level sensitive, active high polarity).
430 intsrc
.srcbusirq
= i
;
431 intsrc
.dstirq
= i
? i
: 2; /* IRQ0 to INTIN2 */
432 MP_intsrc_info(&intsrc
);
435 intsrc
.irqtype
= mp_ExtINT
;
436 intsrc
.srcbusirq
= 0;
437 intsrc
.dstirq
= 0; /* 8259A to INTIN0 */
438 MP_intsrc_info(&intsrc
);
442 static void __init
construct_ioapic_table(int mpc_default_type
)
444 struct mpc_ioapic ioapic
;
449 switch (mpc_default_type
) {
451 printk(KERN_ERR
"???\nUnknown standard configuration %d\n",
456 memcpy(bus
.bustype
, "ISA ", 6);
461 memcpy(bus
.bustype
, "EISA ", 6);
465 memcpy(bus
.bustype
, "MCA ", 6);
468 if (mpc_default_type
> 4) {
470 memcpy(bus
.bustype
, "PCI ", 6);
474 ioapic
.type
= MP_IOAPIC
;
476 ioapic
.apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
477 ioapic
.flags
= MPC_APIC_USABLE
;
478 ioapic
.apicaddr
= IO_APIC_DEFAULT_PHYS_BASE
;
479 MP_ioapic_info(&ioapic
);
482 * We set up most of the low 16 IO-APIC pins according to MPS rules.
484 construct_default_ioirq_mptable(mpc_default_type
);
487 static inline void __init
construct_ioapic_table(int mpc_default_type
) { }
490 static inline void __init
construct_default_ISA_mptable(int mpc_default_type
)
492 struct mpc_cpu processor
;
493 struct mpc_lintsrc lintsrc
;
494 int linttypes
[2] = { mp_ExtINT
, mp_NMI
};
498 * local APIC has default address
500 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
503 * 2 CPUs, numbered 0 & 1.
505 processor
.type
= MP_PROCESSOR
;
506 /* Either an integrated APIC or a discrete 82489DX. */
507 processor
.apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
508 processor
.cpuflag
= CPU_ENABLED
;
509 processor
.cpufeature
= (boot_cpu_data
.x86
<< 8) |
510 (boot_cpu_data
.x86_model
<< 4) | boot_cpu_data
.x86_mask
;
511 processor
.featureflag
= boot_cpu_data
.x86_capability
[0];
512 processor
.reserved
[0] = 0;
513 processor
.reserved
[1] = 0;
514 for (i
= 0; i
< 2; i
++) {
515 processor
.apicid
= i
;
516 MP_processor_info(&processor
);
519 construct_ioapic_table(mpc_default_type
);
521 lintsrc
.type
= MP_LINTSRC
;
522 lintsrc
.irqflag
= 0; /* conforming */
523 lintsrc
.srcbusid
= 0;
524 lintsrc
.srcbusirq
= 0;
525 lintsrc
.destapic
= MP_APIC_ALL
;
526 for (i
= 0; i
< 2; i
++) {
527 lintsrc
.irqtype
= linttypes
[i
];
528 lintsrc
.destapiclint
= i
;
529 MP_lintsrc_info(&lintsrc
);
533 static struct mpf_intel
*mpf_found
;
535 static unsigned long __init
get_mpc_size(unsigned long physptr
)
537 struct mpc_table
*mpc
;
540 mpc
= early_ioremap(physptr
, PAGE_SIZE
);
542 early_iounmap(mpc
, PAGE_SIZE
);
543 apic_printk(APIC_VERBOSE
, " mpc: %lx-%lx\n", physptr
, physptr
+ size
);
548 static int __init
check_physptr(struct mpf_intel
*mpf
, unsigned int early
)
550 struct mpc_table
*mpc
;
553 size
= get_mpc_size(mpf
->physptr
);
554 mpc
= early_ioremap(mpf
->physptr
, size
);
556 * Read the physical hardware table. Anything here will
557 * override the defaults.
559 if (!smp_read_mpc(mpc
, early
)) {
560 #ifdef CONFIG_X86_LOCAL_APIC
561 smp_found_config
= 0;
563 printk(KERN_ERR
"BIOS bug, MP table errors detected!...\n"
564 "... disabling SMP support. (tell your hw vendor)\n");
565 early_iounmap(mpc
, size
);
568 early_iounmap(mpc
, size
);
573 #ifdef CONFIG_X86_IO_APIC
575 * If there are no explicit MP IRQ entries, then we are
576 * broken. We set up most of the low 16 IO-APIC pins to
577 * ISA defaults and hope it will work.
579 if (!mp_irq_entries
) {
582 printk(KERN_ERR
"BIOS bug, no explicit IRQ entries, "
583 "using default mptable. (tell your hw vendor)\n");
587 memcpy(bus
.bustype
, "ISA ", 6);
590 construct_default_ioirq_mptable(0);
598 * Scan the memory blocks for an SMP configuration block.
600 void __init
default_get_smp_config(unsigned int early
)
602 struct mpf_intel
*mpf
= mpf_found
;
607 if (acpi_lapic
&& early
)
611 * MPS doesn't support hyperthreading, aka only have
612 * thread 0 apic id in MPS table
614 if (acpi_lapic
&& acpi_ioapic
)
617 printk(KERN_INFO
"Intel MultiProcessor Specification v1.%d\n",
619 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
620 if (mpf
->feature2
& (1 << 7)) {
621 printk(KERN_INFO
" IMCR and PIC compatibility mode.\n");
624 printk(KERN_INFO
" Virtual Wire compatibility mode.\n");
629 * Now see if we need to read further.
631 if (mpf
->feature1
!= 0) {
634 * local APIC has default address
636 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
640 printk(KERN_INFO
"Default MP configuration #%d\n",
642 construct_default_ISA_mptable(mpf
->feature1
);
644 } else if (mpf
->physptr
) {
645 if (check_physptr(mpf
, early
))
651 printk(KERN_INFO
"Processors: %d\n", num_processors
);
653 * Only use the first configuration found.
657 static void __init
smp_reserve_memory(struct mpf_intel
*mpf
)
659 unsigned long size
= get_mpc_size(mpf
->physptr
);
661 memblock_x86_reserve_range(mpf
->physptr
, mpf
->physptr
+size
, "* MP-table mpc");
664 static int __init
smp_scan_config(unsigned long base
, unsigned long length
)
666 unsigned int *bp
= phys_to_virt(base
);
667 struct mpf_intel
*mpf
;
670 apic_printk(APIC_VERBOSE
, "Scan SMP from %p for %ld bytes.\n",
672 BUILD_BUG_ON(sizeof(*mpf
) != 16);
675 mpf
= (struct mpf_intel
*)bp
;
676 if ((*bp
== SMP_MAGIC_IDENT
) &&
677 (mpf
->length
== 1) &&
678 !mpf_checksum((unsigned char *)bp
, 16) &&
679 ((mpf
->specification
== 1)
680 || (mpf
->specification
== 4))) {
681 #ifdef CONFIG_X86_LOCAL_APIC
682 smp_found_config
= 1;
686 printk(KERN_INFO
"found SMP MP-table at [%p] %llx\n",
687 mpf
, (u64
)virt_to_phys(mpf
));
689 mem
= virt_to_phys(mpf
);
690 memblock_x86_reserve_range(mem
, mem
+ sizeof(*mpf
), "* MP-table mpf");
692 smp_reserve_memory(mpf
);
702 void __init
default_find_smp_config(void)
704 unsigned int address
;
707 * FIXME: Linux assumes you have 640K of base ram..
708 * this continues the error...
710 * 1) Scan the bottom 1K for a signature
711 * 2) Scan the top 1K of base RAM
712 * 3) Scan the 64K of bios
714 if (smp_scan_config(0x0, 0x400) ||
715 smp_scan_config(639 * 0x400, 0x400) ||
716 smp_scan_config(0xF0000, 0x10000))
719 * If it is an SMP machine we should know now, unless the
720 * configuration is in an EISA/MCA bus machine with an
721 * extended bios data area.
723 * there is a real-mode segmented pointer pointing to the
724 * 4K EBDA area at 0x40E, calculate and scan it here.
726 * NOTE! There are Linux loaders that will corrupt the EBDA
727 * area, and as such this kind of SMP config may be less
728 * trustworthy, simply because the SMP table may have been
729 * stomped on during early boot. These loaders are buggy and
732 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
735 address
= get_bios_ebda();
737 smp_scan_config(address
, 0x400);
740 #ifdef CONFIG_X86_IO_APIC
741 static u8 __initdata irq_used
[MAX_IRQ_SOURCES
];
743 static int __init
get_MP_intsrc_index(struct mpc_intsrc
*m
)
747 if (m
->irqtype
!= mp_INT
)
750 if (m
->irqflag
!= 0x0f)
755 for (i
= 0; i
< mp_irq_entries
; i
++) {
756 if (mp_irqs
[i
].irqtype
!= mp_INT
)
759 if (mp_irqs
[i
].irqflag
!= 0x0f)
762 if (mp_irqs
[i
].srcbus
!= m
->srcbus
)
764 if (mp_irqs
[i
].srcbusirq
!= m
->srcbusirq
)
767 /* already claimed */
778 #define SPARE_SLOT_NUM 20
780 static struct mpc_intsrc __initdata
*m_spare
[SPARE_SLOT_NUM
];
782 static void __init
check_irq_src(struct mpc_intsrc
*m
, int *nr_m_spare
)
786 apic_printk(APIC_VERBOSE
, "OLD ");
787 print_MP_intsrc_info(m
);
789 i
= get_MP_intsrc_index(m
);
791 assign_to_mpc_intsrc(&mp_irqs
[i
], m
);
792 apic_printk(APIC_VERBOSE
, "NEW ");
793 print_mp_irq_info(&mp_irqs
[i
]);
797 /* legacy, do nothing */
800 if (*nr_m_spare
< SPARE_SLOT_NUM
) {
802 * not found (-1), or duplicated (-2) are invalid entries,
803 * we need to use the slot later
805 m_spare
[*nr_m_spare
] = m
;
809 #else /* CONFIG_X86_IO_APIC */
811 inline void __init
check_irq_src(struct mpc_intsrc
*m
, int *nr_m_spare
) {}
812 #endif /* CONFIG_X86_IO_APIC */
815 check_slot(unsigned long mpc_new_phys
, unsigned long mpc_new_length
, int count
)
819 if (!mpc_new_phys
|| count
<= mpc_new_length
) {
820 WARN(1, "update_mptable: No spare slots (length: %x)\n", count
);
827 static int __init
replace_intsrc_all(struct mpc_table
*mpc
,
828 unsigned long mpc_new_phys
,
829 unsigned long mpc_new_length
)
831 #ifdef CONFIG_X86_IO_APIC
834 int count
= sizeof(*mpc
);
836 unsigned char *mpt
= ((unsigned char *)mpc
) + count
;
838 printk(KERN_INFO
"mpc_length %x\n", mpc
->length
);
839 while (count
< mpc
->length
) {
842 skip_entry(&mpt
, &count
, sizeof(struct mpc_cpu
));
845 skip_entry(&mpt
, &count
, sizeof(struct mpc_bus
));
848 skip_entry(&mpt
, &count
, sizeof(struct mpc_ioapic
));
851 check_irq_src((struct mpc_intsrc
*)mpt
, &nr_m_spare
);
852 skip_entry(&mpt
, &count
, sizeof(struct mpc_intsrc
));
855 skip_entry(&mpt
, &count
, sizeof(struct mpc_lintsrc
));
859 smp_dump_mptable(mpc
, mpt
);
864 #ifdef CONFIG_X86_IO_APIC
865 for (i
= 0; i
< mp_irq_entries
; i
++) {
869 if (mp_irqs
[i
].irqtype
!= mp_INT
)
872 if (mp_irqs
[i
].irqflag
!= 0x0f)
875 if (nr_m_spare
> 0) {
876 apic_printk(APIC_VERBOSE
, "*NEW* found\n");
878 assign_to_mpc_intsrc(&mp_irqs
[i
], m_spare
[nr_m_spare
]);
879 m_spare
[nr_m_spare
] = NULL
;
881 struct mpc_intsrc
*m
= (struct mpc_intsrc
*)mpt
;
882 count
+= sizeof(struct mpc_intsrc
);
883 if (check_slot(mpc_new_phys
, mpc_new_length
, count
) < 0)
885 assign_to_mpc_intsrc(&mp_irqs
[i
], m
);
887 mpt
+= sizeof(struct mpc_intsrc
);
889 print_mp_irq_info(&mp_irqs
[i
]);
893 /* update checksum */
895 mpc
->checksum
-= mpf_checksum((unsigned char *)mpc
, mpc
->length
);
900 int enable_update_mptable
;
902 static int __init
update_mptable_setup(char *str
)
904 enable_update_mptable
= 1;
910 early_param("update_mptable", update_mptable_setup
);
912 static unsigned long __initdata mpc_new_phys
;
913 static unsigned long mpc_new_length __initdata
= 4096;
915 /* alloc_mptable or alloc_mptable=4k */
916 static int __initdata alloc_mptable
;
917 static int __init
parse_alloc_mptable_opt(char *p
)
919 enable_update_mptable
= 1;
926 mpc_new_length
= memparse(p
, &p
);
929 early_param("alloc_mptable", parse_alloc_mptable_opt
);
931 void __init
early_reserve_e820_mpc_new(void)
933 if (enable_update_mptable
&& alloc_mptable
) {
935 mpc_new_phys
= early_reserve_e820(startt
, mpc_new_length
, 4);
939 static int __init
update_mp_table(void)
943 struct mpf_intel
*mpf
;
944 struct mpc_table
*mpc
, *mpc_new
;
946 if (!enable_update_mptable
)
954 * Now see if we need to go further.
956 if (mpf
->feature1
!= 0)
962 mpc
= phys_to_virt(mpf
->physptr
);
964 if (!smp_check_mpc(mpc
, oem
, str
))
967 printk(KERN_INFO
"mpf: %llx\n", (u64
)virt_to_phys(mpf
));
968 printk(KERN_INFO
"physptr: %x\n", mpf
->physptr
);
970 if (mpc_new_phys
&& mpc
->length
> mpc_new_length
) {
972 printk(KERN_INFO
"mpc_new_length is %ld, please use alloc_mptable=8k\n",
977 unsigned char old
, new;
978 /* check if we can change the postion */
980 old
= mpf_checksum((unsigned char *)mpc
, mpc
->length
);
981 mpc
->checksum
= 0xff;
982 new = mpf_checksum((unsigned char *)mpc
, mpc
->length
);
984 printk(KERN_INFO
"mpc is readonly, please try alloc_mptable instead\n");
987 printk(KERN_INFO
"use in-positon replacing\n");
989 mpf
->physptr
= mpc_new_phys
;
990 mpc_new
= phys_to_virt(mpc_new_phys
);
991 memcpy(mpc_new
, mpc
, mpc
->length
);
993 /* check if we can modify that */
994 if (mpc_new_phys
- mpf
->physptr
) {
995 struct mpf_intel
*mpf_new
;
996 /* steal 16 bytes from [0, 1k) */
997 printk(KERN_INFO
"mpf new: %x\n", 0x400 - 16);
998 mpf_new
= phys_to_virt(0x400 - 16);
999 memcpy(mpf_new
, mpf
, 16);
1001 mpf
->physptr
= mpc_new_phys
;
1004 mpf
->checksum
-= mpf_checksum((unsigned char *)mpf
, 16);
1005 printk(KERN_INFO
"physptr new: %x\n", mpf
->physptr
);
1009 * only replace the one with mp_INT and
1010 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1011 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1012 * may need pci=routeirq for all coverage
1014 replace_intsrc_all(mpc
, mpc_new_phys
, mpc_new_length
);
1019 late_initcall(update_mp_table
);