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>
20 #include <linux/pci.h>
23 #include <asm/mpspec.h>
24 #include <asm/pgalloc.h>
25 #include <asm/io_apic.h>
26 #include <asm/proto.h>
27 #include <asm/bios_ebda.h>
29 #include <asm/trampoline.h>
30 #include <asm/setup.h>
35 * Checksum an MP configuration block.
38 static int __init
mpf_checksum(unsigned char *mp
, int len
)
48 int __init
default_mpc_apic_id(struct mpc_cpu
*m
)
53 static void __init
MP_processor_info(struct mpc_cpu
*m
)
56 char *bootup_cpu
= "";
58 if (!(m
->cpuflag
& CPU_ENABLED
)) {
63 apicid
= x86_init
.mpparse
.mpc_apic_id(m
);
65 if (m
->cpuflag
& CPU_BOOTPROCESSOR
) {
66 bootup_cpu
= " (Bootup-CPU)";
67 boot_cpu_physical_apicid
= m
->apicid
;
70 printk(KERN_INFO
"Processor #%d%s\n", m
->apicid
, bootup_cpu
);
71 generic_processor_info(apicid
, m
->apicver
);
74 #ifdef CONFIG_X86_IO_APIC
75 void __init
default_mpc_oem_bus_info(struct mpc_bus
*m
, char *str
)
77 memcpy(str
, m
->bustype
, 6);
79 apic_printk(APIC_VERBOSE
, "Bus #%d is %s\n", m
->busid
, str
);
82 static void __init
MP_bus_info(struct mpc_bus
*m
)
86 x86_init
.mpparse
.mpc_oem_bus_info(m
, str
);
88 #if MAX_MP_BUSSES < 256
89 if (m
->busid
>= MAX_MP_BUSSES
) {
90 printk(KERN_WARNING
"MP table busid value (%d) for bustype %s "
91 " is too large, max. supported is %d\n",
92 m
->busid
, str
, MAX_MP_BUSSES
- 1);
97 if (strncmp(str
, BUSTYPE_ISA
, sizeof(BUSTYPE_ISA
) - 1) == 0) {
98 set_bit(m
->busid
, mp_bus_not_pci
);
99 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
100 mp_bus_id_to_type
[m
->busid
] = MP_BUS_ISA
;
102 } else if (strncmp(str
, BUSTYPE_PCI
, sizeof(BUSTYPE_PCI
) - 1) == 0) {
103 if (x86_init
.mpparse
.mpc_oem_pci_bus
)
104 x86_init
.mpparse
.mpc_oem_pci_bus(m
);
106 clear_bit(m
->busid
, mp_bus_not_pci
);
107 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
108 mp_bus_id_to_type
[m
->busid
] = MP_BUS_PCI
;
109 } else if (strncmp(str
, BUSTYPE_EISA
, sizeof(BUSTYPE_EISA
) - 1) == 0) {
110 mp_bus_id_to_type
[m
->busid
] = MP_BUS_EISA
;
111 } else if (strncmp(str
, BUSTYPE_MCA
, sizeof(BUSTYPE_MCA
) - 1) == 0) {
112 mp_bus_id_to_type
[m
->busid
] = MP_BUS_MCA
;
115 printk(KERN_WARNING
"Unknown bustype %s - ignoring\n", str
);
118 static int bad_ioapic(unsigned long address
)
120 if (nr_ioapics
>= MAX_IO_APICS
) {
121 printk(KERN_ERR
"ERROR: Max # of I/O APICs (%d) exceeded "
122 "(found %d)\n", MAX_IO_APICS
, nr_ioapics
);
123 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
126 printk(KERN_ERR
"WARNING: Bogus (zero) I/O APIC address"
127 " found in table, skipping!\n");
133 static void __init
MP_ioapic_info(struct mpc_ioapic
*m
)
135 if (!(m
->flags
& MPC_APIC_USABLE
))
138 printk(KERN_INFO
"I/O APIC #%d Version %d at 0x%X.\n",
139 m
->apicid
, m
->apicver
, m
->apicaddr
);
141 if (bad_ioapic(m
->apicaddr
))
144 mp_ioapics
[nr_ioapics
].apicaddr
= m
->apicaddr
;
145 mp_ioapics
[nr_ioapics
].apicid
= m
->apicid
;
146 mp_ioapics
[nr_ioapics
].type
= m
->type
;
147 mp_ioapics
[nr_ioapics
].apicver
= m
->apicver
;
148 mp_ioapics
[nr_ioapics
].flags
= m
->flags
;
152 static void print_MP_intsrc_info(struct mpc_intsrc
*m
)
154 apic_printk(APIC_VERBOSE
, "Int: type %d, pol %d, trig %d, bus %02x,"
155 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
156 m
->irqtype
, m
->irqflag
& 3, (m
->irqflag
>> 2) & 3, m
->srcbus
,
157 m
->srcbusirq
, m
->dstapic
, m
->dstirq
);
160 static void __init
print_mp_irq_info(struct mpc_intsrc
*mp_irq
)
162 apic_printk(APIC_VERBOSE
, "Int: type %d, pol %d, trig %d, bus %02x,"
163 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
164 mp_irq
->irqtype
, mp_irq
->irqflag
& 3,
165 (mp_irq
->irqflag
>> 2) & 3, mp_irq
->srcbus
,
166 mp_irq
->srcbusirq
, mp_irq
->dstapic
, mp_irq
->dstirq
);
169 static void __init
assign_to_mp_irq(struct mpc_intsrc
*m
,
170 struct mpc_intsrc
*mp_irq
)
172 mp_irq
->dstapic
= m
->dstapic
;
173 mp_irq
->type
= m
->type
;
174 mp_irq
->irqtype
= m
->irqtype
;
175 mp_irq
->irqflag
= m
->irqflag
;
176 mp_irq
->srcbus
= m
->srcbus
;
177 mp_irq
->srcbusirq
= m
->srcbusirq
;
178 mp_irq
->dstirq
= m
->dstirq
;
181 static void __init
assign_to_mpc_intsrc(struct mpc_intsrc
*mp_irq
,
182 struct mpc_intsrc
*m
)
184 m
->dstapic
= mp_irq
->dstapic
;
185 m
->type
= mp_irq
->type
;
186 m
->irqtype
= mp_irq
->irqtype
;
187 m
->irqflag
= mp_irq
->irqflag
;
188 m
->srcbus
= mp_irq
->srcbus
;
189 m
->srcbusirq
= mp_irq
->srcbusirq
;
190 m
->dstirq
= mp_irq
->dstirq
;
193 static int __init
mp_irq_mpc_intsrc_cmp(struct mpc_intsrc
*mp_irq
,
194 struct mpc_intsrc
*m
)
196 if (mp_irq
->dstapic
!= m
->dstapic
)
198 if (mp_irq
->type
!= m
->type
)
200 if (mp_irq
->irqtype
!= m
->irqtype
)
202 if (mp_irq
->irqflag
!= m
->irqflag
)
204 if (mp_irq
->srcbus
!= m
->srcbus
)
206 if (mp_irq
->srcbusirq
!= m
->srcbusirq
)
208 if (mp_irq
->dstirq
!= m
->dstirq
)
214 static void __init
MP_intsrc_info(struct mpc_intsrc
*m
)
218 print_MP_intsrc_info(m
);
220 for (i
= 0; i
< mp_irq_entries
; i
++) {
221 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs
[i
], m
))
225 assign_to_mp_irq(m
, &mp_irqs
[mp_irq_entries
]);
226 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
227 panic("Max # of irq sources exceeded!!\n");
229 #else /* CONFIG_X86_IO_APIC */
230 static inline void __init
MP_bus_info(struct mpc_bus
*m
) {}
231 static inline void __init
MP_ioapic_info(struct mpc_ioapic
*m
) {}
232 static inline void __init
MP_intsrc_info(struct mpc_intsrc
*m
) {}
233 #endif /* CONFIG_X86_IO_APIC */
236 static void __init
MP_lintsrc_info(struct mpc_lintsrc
*m
)
238 apic_printk(APIC_VERBOSE
, "Lint: type %d, pol %d, trig %d, bus %02x,"
239 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
240 m
->irqtype
, m
->irqflag
& 3, (m
->irqflag
>> 2) & 3, m
->srcbusid
,
241 m
->srcbusirq
, m
->destapic
, m
->destapiclint
);
248 static int __init
smp_check_mpc(struct mpc_table
*mpc
, char *oem
, char *str
)
251 if (memcmp(mpc
->signature
, MPC_SIGNATURE
, 4)) {
252 printk(KERN_ERR
"MPTABLE: bad signature [%c%c%c%c]!\n",
253 mpc
->signature
[0], mpc
->signature
[1],
254 mpc
->signature
[2], mpc
->signature
[3]);
257 if (mpf_checksum((unsigned char *)mpc
, mpc
->length
)) {
258 printk(KERN_ERR
"MPTABLE: checksum error!\n");
261 if (mpc
->spec
!= 0x01 && mpc
->spec
!= 0x04) {
262 printk(KERN_ERR
"MPTABLE: bad table version (%d)!!\n",
267 printk(KERN_ERR
"MPTABLE: null local APIC address!\n");
270 memcpy(oem
, mpc
->oem
, 8);
272 printk(KERN_INFO
"MPTABLE: OEM ID: %s\n", oem
);
274 memcpy(str
, mpc
->productid
, 12);
277 printk(KERN_INFO
"MPTABLE: Product ID: %s\n", str
);
279 printk(KERN_INFO
"MPTABLE: APIC at: 0x%X\n", mpc
->lapic
);
284 static void skip_entry(unsigned char **ptr
, int *count
, int size
)
290 static void __init
smp_dump_mptable(struct mpc_table
*mpc
, unsigned char *mpt
)
292 printk(KERN_ERR
"Your mptable is wrong, contact your HW vendor!\n"
294 print_hex_dump(KERN_ERR
, " ", DUMP_PREFIX_ADDRESS
, 16,
295 1, mpc
, mpc
->length
, 1);
298 void __init
default_smp_read_mpc_oem(struct mpc_table
*mpc
) { }
300 static int __init
smp_read_mpc(struct mpc_table
*mpc
, unsigned early
)
305 int count
= sizeof(*mpc
);
306 unsigned char *mpt
= ((unsigned char *)mpc
) + count
;
308 if (!smp_check_mpc(mpc
, oem
, str
))
312 generic_mps_oem_check(mpc
, oem
, str
);
314 /* save the local APIC address, it might be non-default */
316 mp_lapic_addr
= mpc
->lapic
;
322 x86_init
.mpparse
.smp_read_mpc_oem(mpc
);
325 * Now process the configuration blocks.
327 x86_init
.mpparse
.mpc_record(0);
329 while (count
< mpc
->length
) {
332 /* ACPI may have already provided this data */
334 MP_processor_info((struct mpc_cpu
*)mpt
);
335 skip_entry(&mpt
, &count
, sizeof(struct mpc_cpu
));
338 MP_bus_info((struct mpc_bus
*)mpt
);
339 skip_entry(&mpt
, &count
, sizeof(struct mpc_bus
));
342 MP_ioapic_info((struct mpc_ioapic
*)mpt
);
343 skip_entry(&mpt
, &count
, sizeof(struct mpc_ioapic
));
346 MP_intsrc_info((struct mpc_intsrc
*)mpt
);
347 skip_entry(&mpt
, &count
, sizeof(struct mpc_intsrc
));
350 MP_lintsrc_info((struct mpc_lintsrc
*)mpt
);
351 skip_entry(&mpt
, &count
, sizeof(struct mpc_lintsrc
));
355 smp_dump_mptable(mpc
, mpt
);
359 x86_init
.mpparse
.mpc_record(1);
362 #ifdef CONFIG_X86_BIGSMP
363 generic_bigsmp_probe();
366 if (apic
->setup_apic_routing
)
367 apic
->setup_apic_routing();
370 printk(KERN_ERR
"MPTABLE: no processors registered!\n");
371 return num_processors
;
374 #ifdef CONFIG_X86_IO_APIC
376 static int __init
ELCR_trigger(unsigned int irq
)
380 port
= 0x4d0 + (irq
>> 3);
381 return (inb(port
) >> (irq
& 7)) & 1;
384 static void __init
construct_default_ioirq_mptable(int mpc_default_type
)
386 struct mpc_intsrc intsrc
;
388 int ELCR_fallback
= 0;
390 intsrc
.type
= MP_INTSRC
;
391 intsrc
.irqflag
= 0; /* conforming */
393 intsrc
.dstapic
= mp_ioapics
[0].apicid
;
395 intsrc
.irqtype
= mp_INT
;
398 * If true, we have an ISA/PCI system with no IRQ entries
399 * in the MP table. To prevent the PCI interrupts from being set up
400 * incorrectly, we try to use the ELCR. The sanity check to see if
401 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
402 * never be level sensitive, so we simply see if the ELCR agrees.
403 * If it does, we assume it's valid.
405 if (mpc_default_type
== 5) {
406 printk(KERN_INFO
"ISA/PCI bus type with no IRQ information... "
407 "falling back to ELCR\n");
409 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
411 printk(KERN_ERR
"ELCR contains invalid data... "
415 "Using ELCR to identify PCI interrupts\n");
420 for (i
= 0; i
< 16; i
++) {
421 switch (mpc_default_type
) {
423 if (i
== 0 || i
== 13)
424 continue; /* IRQ0 & IRQ13 not connected */
428 continue; /* IRQ2 is never connected */
433 * If the ELCR indicates a level-sensitive interrupt, we
434 * copy that information over to the MP table in the
435 * irqflag field (level sensitive, active high polarity).
443 intsrc
.srcbusirq
= i
;
444 intsrc
.dstirq
= i
? i
: 2; /* IRQ0 to INTIN2 */
445 MP_intsrc_info(&intsrc
);
448 intsrc
.irqtype
= mp_ExtINT
;
449 intsrc
.srcbusirq
= 0;
450 intsrc
.dstirq
= 0; /* 8259A to INTIN0 */
451 MP_intsrc_info(&intsrc
);
455 static void __init
construct_ioapic_table(int mpc_default_type
)
457 struct mpc_ioapic ioapic
;
462 switch (mpc_default_type
) {
464 printk(KERN_ERR
"???\nUnknown standard configuration %d\n",
469 memcpy(bus
.bustype
, "ISA ", 6);
474 memcpy(bus
.bustype
, "EISA ", 6);
478 memcpy(bus
.bustype
, "MCA ", 6);
481 if (mpc_default_type
> 4) {
483 memcpy(bus
.bustype
, "PCI ", 6);
487 ioapic
.type
= MP_IOAPIC
;
489 ioapic
.apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
490 ioapic
.flags
= MPC_APIC_USABLE
;
491 ioapic
.apicaddr
= 0xFEC00000;
492 MP_ioapic_info(&ioapic
);
495 * We set up most of the low 16 IO-APIC pins according to MPS rules.
497 construct_default_ioirq_mptable(mpc_default_type
);
500 static inline void __init
construct_ioapic_table(int mpc_default_type
) { }
503 static inline void __init
construct_default_ISA_mptable(int mpc_default_type
)
505 struct mpc_cpu processor
;
506 struct mpc_lintsrc lintsrc
;
507 int linttypes
[2] = { mp_ExtINT
, mp_NMI
};
511 * local APIC has default address
513 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
516 * 2 CPUs, numbered 0 & 1.
518 processor
.type
= MP_PROCESSOR
;
519 /* Either an integrated APIC or a discrete 82489DX. */
520 processor
.apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
521 processor
.cpuflag
= CPU_ENABLED
;
522 processor
.cpufeature
= (boot_cpu_data
.x86
<< 8) |
523 (boot_cpu_data
.x86_model
<< 4) | boot_cpu_data
.x86_mask
;
524 processor
.featureflag
= boot_cpu_data
.x86_capability
[0];
525 processor
.reserved
[0] = 0;
526 processor
.reserved
[1] = 0;
527 for (i
= 0; i
< 2; i
++) {
528 processor
.apicid
= i
;
529 MP_processor_info(&processor
);
532 construct_ioapic_table(mpc_default_type
);
534 lintsrc
.type
= MP_LINTSRC
;
535 lintsrc
.irqflag
= 0; /* conforming */
536 lintsrc
.srcbusid
= 0;
537 lintsrc
.srcbusirq
= 0;
538 lintsrc
.destapic
= MP_APIC_ALL
;
539 for (i
= 0; i
< 2; i
++) {
540 lintsrc
.irqtype
= linttypes
[i
];
541 lintsrc
.destapiclint
= i
;
542 MP_lintsrc_info(&lintsrc
);
546 static struct mpf_intel
*mpf_found
;
548 static unsigned long __init
get_mpc_size(unsigned long physptr
)
550 struct mpc_table
*mpc
;
553 mpc
= early_ioremap(physptr
, PAGE_SIZE
);
555 early_iounmap(mpc
, PAGE_SIZE
);
556 apic_printk(APIC_VERBOSE
, " mpc: %lx-%lx\n", physptr
, physptr
+ size
);
561 static int __init
check_physptr(struct mpf_intel
*mpf
, unsigned int early
)
563 struct mpc_table
*mpc
;
566 size
= get_mpc_size(mpf
->physptr
);
567 mpc
= early_ioremap(mpf
->physptr
, size
);
569 * Read the physical hardware table. Anything here will
570 * override the defaults.
572 if (!smp_read_mpc(mpc
, early
)) {
573 #ifdef CONFIG_X86_LOCAL_APIC
574 smp_found_config
= 0;
576 printk(KERN_ERR
"BIOS bug, MP table errors detected!...\n"
577 "... disabling SMP support. (tell your hw vendor)\n");
578 early_iounmap(mpc
, size
);
581 early_iounmap(mpc
, size
);
586 #ifdef CONFIG_X86_IO_APIC
588 * If there are no explicit MP IRQ entries, then we are
589 * broken. We set up most of the low 16 IO-APIC pins to
590 * ISA defaults and hope it will work.
592 if (!mp_irq_entries
) {
595 printk(KERN_ERR
"BIOS bug, no explicit IRQ entries, "
596 "using default mptable. (tell your hw vendor)\n");
600 memcpy(bus
.bustype
, "ISA ", 6);
603 construct_default_ioirq_mptable(0);
611 * Scan the memory blocks for an SMP configuration block.
613 static void __init
__get_smp_config(unsigned int early
)
615 struct mpf_intel
*mpf
= mpf_found
;
620 if (acpi_lapic
&& early
)
624 * MPS doesn't support hyperthreading, aka only have
625 * thread 0 apic id in MPS table
627 if (acpi_lapic
&& acpi_ioapic
)
630 if (x86_quirks
->mach_get_smp_config
) {
631 if (x86_quirks
->mach_get_smp_config(early
))
635 printk(KERN_INFO
"Intel MultiProcessor Specification v1.%d\n",
637 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
638 if (mpf
->feature2
& (1 << 7)) {
639 printk(KERN_INFO
" IMCR and PIC compatibility mode.\n");
642 printk(KERN_INFO
" Virtual Wire compatibility mode.\n");
647 * Now see if we need to read further.
649 if (mpf
->feature1
!= 0) {
652 * local APIC has default address
654 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
658 printk(KERN_INFO
"Default MP configuration #%d\n",
660 construct_default_ISA_mptable(mpf
->feature1
);
662 } else if (mpf
->physptr
) {
663 if (check_physptr(mpf
, early
))
669 printk(KERN_INFO
"Processors: %d\n", num_processors
);
671 * Only use the first configuration found.
675 void __init
early_get_smp_config(void)
680 void __init
get_smp_config(void)
685 static void __init
smp_reserve_bootmem(struct mpf_intel
*mpf
)
687 unsigned long size
= get_mpc_size(mpf
->physptr
);
690 * We cannot access to MPC table to compute table size yet,
691 * as only few megabytes from the bottom is mapped now.
692 * PC-9800's MPC table places on the very last of physical
693 * memory; so that simply reserving PAGE_SIZE from mpf->physptr
694 * yields BUG() in reserve_bootmem.
695 * also need to make sure physptr is below than max_low_pfn
696 * we don't need reserve the area above max_low_pfn
698 unsigned long end
= max_low_pfn
* PAGE_SIZE
;
700 if (mpf
->physptr
< end
) {
701 if (mpf
->physptr
+ size
> end
)
702 size
= end
- mpf
->physptr
;
703 reserve_bootmem_generic(mpf
->physptr
, size
, BOOTMEM_DEFAULT
);
706 reserve_bootmem_generic(mpf
->physptr
, size
, BOOTMEM_DEFAULT
);
710 static int __init
smp_scan_config(unsigned long base
, unsigned long length
,
713 unsigned int *bp
= phys_to_virt(base
);
714 struct mpf_intel
*mpf
;
716 apic_printk(APIC_VERBOSE
, "Scan SMP from %p for %ld bytes.\n",
718 BUILD_BUG_ON(sizeof(*mpf
) != 16);
721 mpf
= (struct mpf_intel
*)bp
;
722 if ((*bp
== SMP_MAGIC_IDENT
) &&
723 (mpf
->length
== 1) &&
724 !mpf_checksum((unsigned char *)bp
, 16) &&
725 ((mpf
->specification
== 1)
726 || (mpf
->specification
== 4))) {
727 #ifdef CONFIG_X86_LOCAL_APIC
728 smp_found_config
= 1;
732 printk(KERN_INFO
"found SMP MP-table at [%p] %llx\n",
733 mpf
, (u64
)virt_to_phys(mpf
));
737 reserve_bootmem_generic(virt_to_phys(mpf
), sizeof(*mpf
),
740 smp_reserve_bootmem(mpf
);
750 static void __init
__find_smp_config(unsigned int reserve
)
752 unsigned int address
;
754 if (x86_quirks
->mach_find_smp_config
) {
755 if (x86_quirks
->mach_find_smp_config(reserve
))
759 * FIXME: Linux assumes you have 640K of base ram..
760 * this continues the error...
762 * 1) Scan the bottom 1K for a signature
763 * 2) Scan the top 1K of base RAM
764 * 3) Scan the 64K of bios
766 if (smp_scan_config(0x0, 0x400, reserve
) ||
767 smp_scan_config(639 * 0x400, 0x400, reserve
) ||
768 smp_scan_config(0xF0000, 0x10000, reserve
))
771 * If it is an SMP machine we should know now, unless the
772 * configuration is in an EISA/MCA bus machine with an
773 * extended bios data area.
775 * there is a real-mode segmented pointer pointing to the
776 * 4K EBDA area at 0x40E, calculate and scan it here.
778 * NOTE! There are Linux loaders that will corrupt the EBDA
779 * area, and as such this kind of SMP config may be less
780 * trustworthy, simply because the SMP table may have been
781 * stomped on during early boot. These loaders are buggy and
784 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
787 address
= get_bios_ebda();
789 smp_scan_config(address
, 0x400, reserve
);
792 void __init
early_find_smp_config(void)
794 __find_smp_config(0);
797 void __init
find_smp_config(void)
799 __find_smp_config(1);
802 #ifdef CONFIG_X86_IO_APIC
803 static u8 __initdata irq_used
[MAX_IRQ_SOURCES
];
805 static int __init
get_MP_intsrc_index(struct mpc_intsrc
*m
)
809 if (m
->irqtype
!= mp_INT
)
812 if (m
->irqflag
!= 0x0f)
817 for (i
= 0; i
< mp_irq_entries
; i
++) {
818 if (mp_irqs
[i
].irqtype
!= mp_INT
)
821 if (mp_irqs
[i
].irqflag
!= 0x0f)
824 if (mp_irqs
[i
].srcbus
!= m
->srcbus
)
826 if (mp_irqs
[i
].srcbusirq
!= m
->srcbusirq
)
829 /* already claimed */
840 #define SPARE_SLOT_NUM 20
842 static struct mpc_intsrc __initdata
*m_spare
[SPARE_SLOT_NUM
];
844 static void __init
check_irq_src(struct mpc_intsrc
*m
, int *nr_m_spare
)
848 apic_printk(APIC_VERBOSE
, "OLD ");
849 print_MP_intsrc_info(m
);
851 i
= get_MP_intsrc_index(m
);
853 assign_to_mpc_intsrc(&mp_irqs
[i
], m
);
854 apic_printk(APIC_VERBOSE
, "NEW ");
855 print_mp_irq_info(&mp_irqs
[i
]);
859 /* legacy, do nothing */
862 if (*nr_m_spare
< SPARE_SLOT_NUM
) {
864 * not found (-1), or duplicated (-2) are invalid entries,
865 * we need to use the slot later
867 m_spare
[*nr_m_spare
] = m
;
871 #else /* CONFIG_X86_IO_APIC */
873 inline void __init
check_irq_src(struct mpc_intsrc
*m
, int *nr_m_spare
) {}
874 #endif /* CONFIG_X86_IO_APIC */
877 check_slot(unsigned long mpc_new_phys
, unsigned long mpc_new_length
, int count
)
881 if (!mpc_new_phys
|| count
<= mpc_new_length
) {
882 WARN(1, "update_mptable: No spare slots (length: %x)\n", count
);
889 static int __init
replace_intsrc_all(struct mpc_table
*mpc
,
890 unsigned long mpc_new_phys
,
891 unsigned long mpc_new_length
)
893 #ifdef CONFIG_X86_IO_APIC
896 int count
= sizeof(*mpc
);
898 unsigned char *mpt
= ((unsigned char *)mpc
) + count
;
900 printk(KERN_INFO
"mpc_length %x\n", mpc
->length
);
901 while (count
< mpc
->length
) {
904 skip_entry(&mpt
, &count
, sizeof(struct mpc_cpu
));
907 skip_entry(&mpt
, &count
, sizeof(struct mpc_bus
));
910 skip_entry(&mpt
, &count
, sizeof(struct mpc_ioapic
));
913 check_irq_src((struct mpc_intsrc
*)mpt
, &nr_m_spare
);
914 skip_entry(&mpt
, &count
, sizeof(struct mpc_intsrc
));
917 skip_entry(&mpt
, &count
, sizeof(struct mpc_lintsrc
));
921 smp_dump_mptable(mpc
, mpt
);
926 #ifdef CONFIG_X86_IO_APIC
927 for (i
= 0; i
< mp_irq_entries
; i
++) {
931 if (mp_irqs
[i
].irqtype
!= mp_INT
)
934 if (mp_irqs
[i
].irqflag
!= 0x0f)
937 if (nr_m_spare
> 0) {
938 apic_printk(APIC_VERBOSE
, "*NEW* found\n");
940 assign_to_mpc_intsrc(&mp_irqs
[i
], m_spare
[nr_m_spare
]);
941 m_spare
[nr_m_spare
] = NULL
;
943 struct mpc_intsrc
*m
= (struct mpc_intsrc
*)mpt
;
944 count
+= sizeof(struct mpc_intsrc
);
945 if (check_slot(mpc_new_phys
, mpc_new_length
, count
) < 0)
947 assign_to_mpc_intsrc(&mp_irqs
[i
], m
);
949 mpt
+= sizeof(struct mpc_intsrc
);
951 print_mp_irq_info(&mp_irqs
[i
]);
955 /* update checksum */
957 mpc
->checksum
-= mpf_checksum((unsigned char *)mpc
, mpc
->length
);
962 int enable_update_mptable
;
964 static int __init
update_mptable_setup(char *str
)
966 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;
988 mpc_new_length
= memparse(p
, &p
);
991 early_param("alloc_mptable", parse_alloc_mptable_opt
);
993 void __init
early_reserve_e820_mpc_new(void)
995 if (enable_update_mptable
&& alloc_mptable
) {
997 #ifdef CONFIG_X86_TRAMPOLINE
998 startt
= TRAMPOLINE_BASE
;
1000 mpc_new_phys
= early_reserve_e820(startt
, mpc_new_length
, 4);
1004 static int __init
update_mp_table(void)
1008 struct mpf_intel
*mpf
;
1009 struct mpc_table
*mpc
, *mpc_new
;
1011 if (!enable_update_mptable
)
1019 * Now see if we need to go further.
1021 if (mpf
->feature1
!= 0)
1027 mpc
= phys_to_virt(mpf
->physptr
);
1029 if (!smp_check_mpc(mpc
, oem
, str
))
1032 printk(KERN_INFO
"mpf: %llx\n", (u64
)virt_to_phys(mpf
));
1033 printk(KERN_INFO
"physptr: %x\n", mpf
->physptr
);
1035 if (mpc_new_phys
&& mpc
->length
> mpc_new_length
) {
1037 printk(KERN_INFO
"mpc_new_length is %ld, please use alloc_mptable=8k\n",
1041 if (!mpc_new_phys
) {
1042 unsigned char old
, new;
1043 /* check if we can change the postion */
1045 old
= mpf_checksum((unsigned char *)mpc
, mpc
->length
);
1046 mpc
->checksum
= 0xff;
1047 new = mpf_checksum((unsigned char *)mpc
, mpc
->length
);
1049 printk(KERN_INFO
"mpc is readonly, please try alloc_mptable instead\n");
1052 printk(KERN_INFO
"use in-positon replacing\n");
1054 mpf
->physptr
= mpc_new_phys
;
1055 mpc_new
= phys_to_virt(mpc_new_phys
);
1056 memcpy(mpc_new
, mpc
, mpc
->length
);
1058 /* check if we can modify that */
1059 if (mpc_new_phys
- mpf
->physptr
) {
1060 struct mpf_intel
*mpf_new
;
1061 /* steal 16 bytes from [0, 1k) */
1062 printk(KERN_INFO
"mpf new: %x\n", 0x400 - 16);
1063 mpf_new
= phys_to_virt(0x400 - 16);
1064 memcpy(mpf_new
, mpf
, 16);
1066 mpf
->physptr
= mpc_new_phys
;
1069 mpf
->checksum
-= mpf_checksum((unsigned char *)mpf
, 16);
1070 printk(KERN_INFO
"physptr new: %x\n", mpf
->physptr
);
1074 * only replace the one with mp_INT and
1075 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1076 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1077 * may need pci=routeirq for all coverage
1079 replace_intsrc_all(mpc
, mpc_new_phys
, mpc_new_length
);
1084 late_initcall(update_mp_table
);