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>
30 #include <asm/setup.h>
32 #include <mach_apic.h>
34 #include <mach_apicdef.h>
35 #include <mach_mpparse.h>
39 * Checksum an MP configuration block.
42 static int __init
mpf_checksum(unsigned char *mp
, int len
)
52 static void __cpuinit
MP_processor_info(struct mpc_config_processor
*m
)
55 char *bootup_cpu
= "";
57 if (!(m
->mpc_cpuflag
& CPU_ENABLED
)) {
62 if (x86_quirks
->mpc_apic_id
)
63 apicid
= x86_quirks
->mpc_apic_id(m
);
65 apicid
= m
->mpc_apicid
;
67 if (m
->mpc_cpuflag
& CPU_BOOTPROCESSOR
) {
68 bootup_cpu
= " (Bootup-CPU)";
69 boot_cpu_physical_apicid
= m
->mpc_apicid
;
72 printk(KERN_INFO
"Processor #%d%s\n", m
->mpc_apicid
, bootup_cpu
);
73 generic_processor_info(apicid
, m
->mpc_apicver
);
76 #ifdef CONFIG_X86_IO_APIC
77 static void __init
MP_bus_info(struct mpc_config_bus
*m
)
80 memcpy(str
, m
->mpc_bustype
, 6);
83 if (x86_quirks
->mpc_oem_bus_info
)
84 x86_quirks
->mpc_oem_bus_info(m
, str
);
86 printk(KERN_INFO
"Bus #%d is %s\n", m
->mpc_busid
, str
);
88 #if MAX_MP_BUSSES < 256
89 if (m
->mpc_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
->mpc_busid
, str
, MAX_MP_BUSSES
- 1);
97 if (strncmp(str
, BUSTYPE_ISA
, sizeof(BUSTYPE_ISA
) - 1) == 0) {
98 set_bit(m
->mpc_busid
, mp_bus_not_pci
);
99 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
100 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_ISA
;
102 } else if (strncmp(str
, BUSTYPE_PCI
, sizeof(BUSTYPE_PCI
) - 1) == 0) {
103 if (x86_quirks
->mpc_oem_pci_bus
)
104 x86_quirks
->mpc_oem_pci_bus(m
);
106 clear_bit(m
->mpc_busid
, mp_bus_not_pci
);
107 #if defined(CONFIG_EISA) || defined (CONFIG_MCA)
108 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_PCI
;
109 } else if (strncmp(str
, BUSTYPE_EISA
, sizeof(BUSTYPE_EISA
) - 1) == 0) {
110 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_EISA
;
111 } else if (strncmp(str
, BUSTYPE_MCA
, sizeof(BUSTYPE_MCA
) - 1) == 0) {
112 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_MCA
;
115 printk(KERN_WARNING
"Unknown bustype %s - ignoring\n", str
);
119 #ifdef CONFIG_X86_IO_APIC
121 static int bad_ioapic(unsigned long address
)
123 if (nr_ioapics
>= MAX_IO_APICS
) {
124 printk(KERN_ERR
"ERROR: Max # of I/O APICs (%d) exceeded "
125 "(found %d)\n", MAX_IO_APICS
, nr_ioapics
);
126 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
129 printk(KERN_ERR
"WARNING: Bogus (zero) I/O APIC address"
130 " found in table, skipping!\n");
136 static void __init
MP_ioapic_info(struct mpc_config_ioapic
*m
)
138 if (!(m
->mpc_flags
& MPC_APIC_USABLE
))
141 printk(KERN_INFO
"I/O APIC #%d Version %d at 0x%X.\n",
142 m
->mpc_apicid
, m
->mpc_apicver
, m
->mpc_apicaddr
);
144 if (bad_ioapic(m
->mpc_apicaddr
))
147 mp_ioapics
[nr_ioapics
].mp_apicaddr
= m
->mpc_apicaddr
;
148 mp_ioapics
[nr_ioapics
].mp_apicid
= m
->mpc_apicid
;
149 mp_ioapics
[nr_ioapics
].mp_type
= m
->mpc_type
;
150 mp_ioapics
[nr_ioapics
].mp_apicver
= m
->mpc_apicver
;
151 mp_ioapics
[nr_ioapics
].mp_flags
= m
->mpc_flags
;
155 static void print_MP_intsrc_info(struct mpc_config_intsrc
*m
)
157 printk(KERN_CONT
"Int: type %d, pol %d, trig %d, bus %02x,"
158 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
159 m
->mpc_irqtype
, m
->mpc_irqflag
& 3,
160 (m
->mpc_irqflag
>> 2) & 3, m
->mpc_srcbus
,
161 m
->mpc_srcbusirq
, m
->mpc_dstapic
, m
->mpc_dstirq
);
164 static void __init
print_mp_irq_info(struct mp_config_intsrc
*mp_irq
)
166 printk(KERN_CONT
"Int: type %d, pol %d, trig %d, bus %02x,"
167 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
168 mp_irq
->mp_irqtype
, mp_irq
->mp_irqflag
& 3,
169 (mp_irq
->mp_irqflag
>> 2) & 3, mp_irq
->mp_srcbus
,
170 mp_irq
->mp_srcbusirq
, mp_irq
->mp_dstapic
, mp_irq
->mp_dstirq
);
173 static void __init
assign_to_mp_irq(struct mpc_config_intsrc
*m
,
174 struct mp_config_intsrc
*mp_irq
)
176 mp_irq
->mp_dstapic
= m
->mpc_dstapic
;
177 mp_irq
->mp_type
= m
->mpc_type
;
178 mp_irq
->mp_irqtype
= m
->mpc_irqtype
;
179 mp_irq
->mp_irqflag
= m
->mpc_irqflag
;
180 mp_irq
->mp_srcbus
= m
->mpc_srcbus
;
181 mp_irq
->mp_srcbusirq
= m
->mpc_srcbusirq
;
182 mp_irq
->mp_dstirq
= m
->mpc_dstirq
;
185 static void __init
assign_to_mpc_intsrc(struct mp_config_intsrc
*mp_irq
,
186 struct mpc_config_intsrc
*m
)
188 m
->mpc_dstapic
= mp_irq
->mp_dstapic
;
189 m
->mpc_type
= mp_irq
->mp_type
;
190 m
->mpc_irqtype
= mp_irq
->mp_irqtype
;
191 m
->mpc_irqflag
= mp_irq
->mp_irqflag
;
192 m
->mpc_srcbus
= mp_irq
->mp_srcbus
;
193 m
->mpc_srcbusirq
= mp_irq
->mp_srcbusirq
;
194 m
->mpc_dstirq
= mp_irq
->mp_dstirq
;
197 static int __init
mp_irq_mpc_intsrc_cmp(struct mp_config_intsrc
*mp_irq
,
198 struct mpc_config_intsrc
*m
)
200 if (mp_irq
->mp_dstapic
!= m
->mpc_dstapic
)
202 if (mp_irq
->mp_type
!= m
->mpc_type
)
204 if (mp_irq
->mp_irqtype
!= m
->mpc_irqtype
)
206 if (mp_irq
->mp_irqflag
!= m
->mpc_irqflag
)
208 if (mp_irq
->mp_srcbus
!= m
->mpc_srcbus
)
210 if (mp_irq
->mp_srcbusirq
!= m
->mpc_srcbusirq
)
212 if (mp_irq
->mp_dstirq
!= m
->mpc_dstirq
)
218 static void __init
MP_intsrc_info(struct mpc_config_intsrc
*m
)
222 print_MP_intsrc_info(m
);
224 for (i
= 0; i
< mp_irq_entries
; i
++) {
225 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs
[i
], m
))
229 assign_to_mp_irq(m
, &mp_irqs
[mp_irq_entries
]);
230 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
231 panic("Max # of irq sources exceeded!!\n");
236 static void __init
MP_lintsrc_info(struct mpc_config_lintsrc
*m
)
238 printk(KERN_INFO
"Lint: type %d, pol %d, trig %d, bus %02x,"
239 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
240 m
->mpc_irqtype
, m
->mpc_irqflag
& 3,
241 (m
->mpc_irqflag
>> 2) & 3, m
->mpc_srcbusid
,
242 m
->mpc_srcbusirq
, m
->mpc_destapic
, m
->mpc_destapiclint
);
249 static int __init
smp_check_mpc(struct mp_config_table
*mpc
, char *oem
,
253 if (memcmp(mpc
->mpc_signature
, MPC_SIGNATURE
, 4)) {
254 printk(KERN_ERR
"MPTABLE: bad signature [%c%c%c%c]!\n",
255 mpc
->mpc_signature
[0], mpc
->mpc_signature
[1],
256 mpc
->mpc_signature
[2], mpc
->mpc_signature
[3]);
259 if (mpf_checksum((unsigned char *)mpc
, mpc
->mpc_length
)) {
260 printk(KERN_ERR
"MPTABLE: checksum error!\n");
263 if (mpc
->mpc_spec
!= 0x01 && mpc
->mpc_spec
!= 0x04) {
264 printk(KERN_ERR
"MPTABLE: bad table version (%d)!!\n",
268 if (!mpc
->mpc_lapic
) {
269 printk(KERN_ERR
"MPTABLE: null local APIC address!\n");
272 memcpy(oem
, mpc
->mpc_oem
, 8);
274 printk(KERN_INFO
"MPTABLE: OEM ID: %s\n", oem
);
276 memcpy(str
, mpc
->mpc_productid
, 12);
279 printk(KERN_INFO
"MPTABLE: Product ID: %s\n", str
);
281 printk(KERN_INFO
"MPTABLE: APIC at: 0x%X\n", mpc
->mpc_lapic
);
286 static int __init
smp_read_mpc(struct mp_config_table
*mpc
, unsigned early
)
291 int count
= sizeof(*mpc
);
292 unsigned char *mpt
= ((unsigned char *)mpc
) + count
;
294 if (!smp_check_mpc(mpc
, oem
, str
))
299 * need to make sure summit and es7000's mps_oem_check is safe to be
300 * called early via genericarch 's mps_oem_check
303 #ifdef CONFIG_X86_NUMAQ
304 numaq_mps_oem_check(mpc
, oem
, str
);
307 mps_oem_check(mpc
, oem
, str
);
309 /* save the local APIC address, it might be non-default */
311 mp_lapic_addr
= mpc
->mpc_lapic
;
316 if (mpc
->mpc_oemptr
&& x86_quirks
->smp_read_mpc_oem
) {
317 struct mp_config_oemtable
*oem_table
= (struct mp_config_oemtable
*)(unsigned long)mpc
->mpc_oemptr
;
318 x86_quirks
->smp_read_mpc_oem(oem_table
, mpc
->mpc_oemsize
);
322 * Now process the configuration blocks.
324 if (x86_quirks
->mpc_record
)
325 *x86_quirks
->mpc_record
= 0;
327 while (count
< mpc
->mpc_length
) {
331 struct mpc_config_processor
*m
=
332 (struct mpc_config_processor
*)mpt
;
333 /* ACPI may have already provided this data */
335 MP_processor_info(m
);
342 struct mpc_config_bus
*m
=
343 (struct mpc_config_bus
*)mpt
;
344 #ifdef CONFIG_X86_IO_APIC
353 #ifdef CONFIG_X86_IO_APIC
354 struct mpc_config_ioapic
*m
=
355 (struct mpc_config_ioapic
*)mpt
;
358 mpt
+= sizeof(struct mpc_config_ioapic
);
359 count
+= sizeof(struct mpc_config_ioapic
);
364 #ifdef CONFIG_X86_IO_APIC
365 struct mpc_config_intsrc
*m
=
366 (struct mpc_config_intsrc
*)mpt
;
370 mpt
+= sizeof(struct mpc_config_intsrc
);
371 count
+= sizeof(struct mpc_config_intsrc
);
376 struct mpc_config_lintsrc
*m
=
377 (struct mpc_config_lintsrc
*)mpt
;
385 printk(KERN_ERR
"Your mptable is wrong, contact your HW vendor!\n");
386 printk(KERN_ERR
"type %x\n", *mpt
);
387 print_hex_dump(KERN_ERR
, " ", DUMP_PREFIX_ADDRESS
, 16,
388 1, mpc
, mpc
->mpc_length
, 1);
389 count
= mpc
->mpc_length
;
392 if (x86_quirks
->mpc_record
)
393 (*x86_quirks
->mpc_record
)++;
396 #ifdef CONFIG_X86_GENERICARCH
397 generic_bigsmp_probe();
400 setup_apic_routing();
402 printk(KERN_ERR
"MPTABLE: no processors registered!\n");
403 return num_processors
;
406 #ifdef CONFIG_X86_IO_APIC
408 static int __init
ELCR_trigger(unsigned int irq
)
412 port
= 0x4d0 + (irq
>> 3);
413 return (inb(port
) >> (irq
& 7)) & 1;
416 static void __init
construct_default_ioirq_mptable(int mpc_default_type
)
418 struct mpc_config_intsrc intsrc
;
420 int ELCR_fallback
= 0;
422 intsrc
.mpc_type
= MP_INTSRC
;
423 intsrc
.mpc_irqflag
= 0; /* conforming */
424 intsrc
.mpc_srcbus
= 0;
425 intsrc
.mpc_dstapic
= mp_ioapics
[0].mp_apicid
;
427 intsrc
.mpc_irqtype
= mp_INT
;
430 * If true, we have an ISA/PCI system with no IRQ entries
431 * in the MP table. To prevent the PCI interrupts from being set up
432 * incorrectly, we try to use the ELCR. The sanity check to see if
433 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
434 * never be level sensitive, so we simply see if the ELCR agrees.
435 * If it does, we assume it's valid.
437 if (mpc_default_type
== 5) {
438 printk(KERN_INFO
"ISA/PCI bus type with no IRQ information... "
439 "falling back to ELCR\n");
441 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
443 printk(KERN_ERR
"ELCR contains invalid data... "
447 "Using ELCR to identify PCI interrupts\n");
452 for (i
= 0; i
< 16; i
++) {
453 switch (mpc_default_type
) {
455 if (i
== 0 || i
== 13)
456 continue; /* IRQ0 & IRQ13 not connected */
460 continue; /* IRQ2 is never connected */
465 * If the ELCR indicates a level-sensitive interrupt, we
466 * copy that information over to the MP table in the
467 * irqflag field (level sensitive, active high polarity).
470 intsrc
.mpc_irqflag
= 13;
472 intsrc
.mpc_irqflag
= 0;
475 intsrc
.mpc_srcbusirq
= i
;
476 intsrc
.mpc_dstirq
= i
? i
: 2; /* IRQ0 to INTIN2 */
477 MP_intsrc_info(&intsrc
);
480 intsrc
.mpc_irqtype
= mp_ExtINT
;
481 intsrc
.mpc_srcbusirq
= 0;
482 intsrc
.mpc_dstirq
= 0; /* 8259A to INTIN0 */
483 MP_intsrc_info(&intsrc
);
487 static void construct_ioapic_table(int mpc_default_type
)
489 struct mpc_config_ioapic ioapic
;
490 struct mpc_config_bus bus
;
492 bus
.mpc_type
= MP_BUS
;
494 switch (mpc_default_type
) {
496 printk(KERN_ERR
"???\nUnknown standard configuration %d\n",
501 memcpy(bus
.mpc_bustype
, "ISA ", 6);
506 memcpy(bus
.mpc_bustype
, "EISA ", 6);
510 memcpy(bus
.mpc_bustype
, "MCA ", 6);
513 if (mpc_default_type
> 4) {
515 memcpy(bus
.mpc_bustype
, "PCI ", 6);
519 ioapic
.mpc_type
= MP_IOAPIC
;
520 ioapic
.mpc_apicid
= 2;
521 ioapic
.mpc_apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
522 ioapic
.mpc_flags
= MPC_APIC_USABLE
;
523 ioapic
.mpc_apicaddr
= 0xFEC00000;
524 MP_ioapic_info(&ioapic
);
527 * We set up most of the low 16 IO-APIC pins according to MPS rules.
529 construct_default_ioirq_mptable(mpc_default_type
);
532 static inline void construct_ioapic_table(int mpc_default_type
) { }
535 static inline void __init
construct_default_ISA_mptable(int mpc_default_type
)
537 struct mpc_config_processor processor
;
538 struct mpc_config_lintsrc lintsrc
;
539 int linttypes
[2] = { mp_ExtINT
, mp_NMI
};
543 * local APIC has default address
545 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
548 * 2 CPUs, numbered 0 & 1.
550 processor
.mpc_type
= MP_PROCESSOR
;
551 /* Either an integrated APIC or a discrete 82489DX. */
552 processor
.mpc_apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
553 processor
.mpc_cpuflag
= CPU_ENABLED
;
554 processor
.mpc_cpufeature
= (boot_cpu_data
.x86
<< 8) |
555 (boot_cpu_data
.x86_model
<< 4) | boot_cpu_data
.x86_mask
;
556 processor
.mpc_featureflag
= boot_cpu_data
.x86_capability
[0];
557 processor
.mpc_reserved
[0] = 0;
558 processor
.mpc_reserved
[1] = 0;
559 for (i
= 0; i
< 2; i
++) {
560 processor
.mpc_apicid
= i
;
561 MP_processor_info(&processor
);
564 construct_ioapic_table(mpc_default_type
);
566 lintsrc
.mpc_type
= MP_LINTSRC
;
567 lintsrc
.mpc_irqflag
= 0; /* conforming */
568 lintsrc
.mpc_srcbusid
= 0;
569 lintsrc
.mpc_srcbusirq
= 0;
570 lintsrc
.mpc_destapic
= MP_APIC_ALL
;
571 for (i
= 0; i
< 2; i
++) {
572 lintsrc
.mpc_irqtype
= linttypes
[i
];
573 lintsrc
.mpc_destapiclint
= i
;
574 MP_lintsrc_info(&lintsrc
);
578 static struct intel_mp_floating
*mpf_found
;
581 * Scan the memory blocks for an SMP configuration block.
583 static void __init
__get_smp_config(unsigned int early
)
585 struct intel_mp_floating
*mpf
= mpf_found
;
587 if (x86_quirks
->mach_get_smp_config
) {
588 if (x86_quirks
->mach_get_smp_config(early
))
591 if (acpi_lapic
&& early
)
594 * ACPI supports both logical (e.g. Hyper-Threading) and physical
595 * processors, where MPS only supports physical.
597 if (acpi_lapic
&& acpi_ioapic
) {
598 printk(KERN_INFO
"Using ACPI (MADT) for SMP configuration "
601 } else if (acpi_lapic
)
602 printk(KERN_INFO
"Using ACPI for processor (LAPIC) "
603 "configuration information\n");
605 printk(KERN_INFO
"Intel MultiProcessor Specification v1.%d\n",
606 mpf
->mpf_specification
);
607 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
608 if (mpf
->mpf_feature2
& (1 << 7)) {
609 printk(KERN_INFO
" IMCR and PIC compatibility mode.\n");
612 printk(KERN_INFO
" Virtual Wire compatibility mode.\n");
617 * Now see if we need to read further.
619 if (mpf
->mpf_feature1
!= 0) {
622 * local APIC has default address
624 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
628 printk(KERN_INFO
"Default MP configuration #%d\n",
630 construct_default_ISA_mptable(mpf
->mpf_feature1
);
632 } else if (mpf
->mpf_physptr
) {
635 * Read the physical hardware table. Anything here will
636 * override the defaults.
638 if (!smp_read_mpc(phys_to_virt(mpf
->mpf_physptr
), early
)) {
639 #ifdef CONFIG_X86_LOCAL_APIC
640 smp_found_config
= 0;
643 "BIOS bug, MP table errors detected!...\n");
644 printk(KERN_ERR
"... disabling SMP support. "
645 "(tell your hw vendor)\n");
651 #ifdef CONFIG_X86_IO_APIC
653 * If there are no explicit MP IRQ entries, then we are
654 * broken. We set up most of the low 16 IO-APIC pins to
655 * ISA defaults and hope it will work.
657 if (!mp_irq_entries
) {
658 struct mpc_config_bus bus
;
660 printk(KERN_ERR
"BIOS bug, no explicit IRQ entries, "
661 "using default mptable. "
662 "(tell your hw vendor)\n");
664 bus
.mpc_type
= MP_BUS
;
666 memcpy(bus
.mpc_bustype
, "ISA ", 6);
669 construct_default_ioirq_mptable(0);
676 printk(KERN_INFO
"Processors: %d\n", num_processors
);
678 * Only use the first configuration found.
682 void __init
early_get_smp_config(void)
687 void __init
get_smp_config(void)
692 static int __init
smp_scan_config(unsigned long base
, unsigned long length
,
695 unsigned int *bp
= phys_to_virt(base
);
696 struct intel_mp_floating
*mpf
;
698 printk(KERN_DEBUG
"Scan SMP from %p for %ld bytes.\n", bp
, length
);
699 BUILD_BUG_ON(sizeof(*mpf
) != 16);
702 mpf
= (struct intel_mp_floating
*)bp
;
703 if ((*bp
== SMP_MAGIC_IDENT
) &&
704 (mpf
->mpf_length
== 1) &&
705 !mpf_checksum((unsigned char *)bp
, 16) &&
706 ((mpf
->mpf_specification
== 1)
707 || (mpf
->mpf_specification
== 4))) {
708 #ifdef CONFIG_X86_LOCAL_APIC
709 smp_found_config
= 1;
713 printk(KERN_INFO
"found SMP MP-table at [%p] %08lx\n",
714 mpf
, virt_to_phys(mpf
));
718 reserve_bootmem_generic(virt_to_phys(mpf
), PAGE_SIZE
,
720 if (mpf
->mpf_physptr
) {
721 unsigned long size
= PAGE_SIZE
;
724 * We cannot access to MPC table to compute
725 * table size yet, as only few megabytes from
726 * the bottom is mapped now.
727 * PC-9800's MPC table places on the very last
728 * of physical memory; so that simply reserving
729 * PAGE_SIZE from mpg->mpf_physptr yields BUG()
730 * in reserve_bootmem.
732 unsigned long end
= max_low_pfn
* PAGE_SIZE
;
733 if (mpf
->mpf_physptr
+ size
> end
)
734 size
= end
- mpf
->mpf_physptr
;
736 reserve_bootmem_generic(mpf
->mpf_physptr
, size
,
748 static void __init
__find_smp_config(unsigned int reserve
)
750 unsigned int address
;
752 if (x86_quirks
->mach_find_smp_config
) {
753 if (x86_quirks
->mach_find_smp_config(reserve
))
757 * FIXME: Linux assumes you have 640K of base ram..
758 * this continues the error...
760 * 1) Scan the bottom 1K for a signature
761 * 2) Scan the top 1K of base RAM
762 * 3) Scan the 64K of bios
764 if (smp_scan_config(0x0, 0x400, reserve
) ||
765 smp_scan_config(639 * 0x400, 0x400, reserve
) ||
766 smp_scan_config(0xF0000, 0x10000, reserve
))
769 * If it is an SMP machine we should know now, unless the
770 * configuration is in an EISA/MCA bus machine with an
771 * extended bios data area.
773 * there is a real-mode segmented pointer pointing to the
774 * 4K EBDA area at 0x40E, calculate and scan it here.
776 * NOTE! There are Linux loaders that will corrupt the EBDA
777 * area, and as such this kind of SMP config may be less
778 * trustworthy, simply because the SMP table may have been
779 * stomped on during early boot. These loaders are buggy and
782 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
785 address
= get_bios_ebda();
787 smp_scan_config(address
, 0x400, reserve
);
790 void __init
early_find_smp_config(void)
792 __find_smp_config(0);
795 void __init
find_smp_config(void)
797 __find_smp_config(1);
800 #ifdef CONFIG_X86_IO_APIC
801 static u8 __initdata irq_used
[MAX_IRQ_SOURCES
];
803 static int __init
get_MP_intsrc_index(struct mpc_config_intsrc
*m
)
807 if (m
->mpc_irqtype
!= mp_INT
)
810 if (m
->mpc_irqflag
!= 0x0f)
815 for (i
= 0; i
< mp_irq_entries
; i
++) {
816 if (mp_irqs
[i
].mp_irqtype
!= mp_INT
)
819 if (mp_irqs
[i
].mp_irqflag
!= 0x0f)
822 if (mp_irqs
[i
].mp_srcbus
!= m
->mpc_srcbus
)
824 if (mp_irqs
[i
].mp_srcbusirq
!= m
->mpc_srcbusirq
)
827 /* already claimed */
838 #define SPARE_SLOT_NUM 20
840 static struct mpc_config_intsrc __initdata
*m_spare
[SPARE_SLOT_NUM
];
843 static int __init
replace_intsrc_all(struct mp_config_table
*mpc
,
844 unsigned long mpc_new_phys
,
845 unsigned long mpc_new_length
)
847 #ifdef CONFIG_X86_IO_APIC
852 int count
= sizeof(*mpc
);
853 unsigned char *mpt
= ((unsigned char *)mpc
) + count
;
855 printk(KERN_INFO
"mpc_length %x\n", mpc
->mpc_length
);
856 while (count
< mpc
->mpc_length
) {
860 struct mpc_config_processor
*m
=
861 (struct mpc_config_processor
*)mpt
;
868 struct mpc_config_bus
*m
=
869 (struct mpc_config_bus
*)mpt
;
876 mpt
+= sizeof(struct mpc_config_ioapic
);
877 count
+= sizeof(struct mpc_config_ioapic
);
882 #ifdef CONFIG_X86_IO_APIC
883 struct mpc_config_intsrc
*m
=
884 (struct mpc_config_intsrc
*)mpt
;
886 printk(KERN_INFO
"OLD ");
887 print_MP_intsrc_info(m
);
888 i
= get_MP_intsrc_index(m
);
890 assign_to_mpc_intsrc(&mp_irqs
[i
], m
);
891 printk(KERN_INFO
"NEW ");
892 print_mp_irq_info(&mp_irqs
[i
]);
894 /* legacy, do nothing */
895 } else if (nr_m_spare
< SPARE_SLOT_NUM
) {
897 * not found (-1), or duplicated (-2)
898 * are invalid entries,
899 * we need to use the slot later
901 m_spare
[nr_m_spare
] = m
;
905 mpt
+= sizeof(struct mpc_config_intsrc
);
906 count
+= sizeof(struct mpc_config_intsrc
);
911 struct mpc_config_lintsrc
*m
=
912 (struct mpc_config_lintsrc
*)mpt
;
919 printk(KERN_ERR
"Your mptable is wrong, contact your HW vendor!\n");
920 printk(KERN_ERR
"type %x\n", *mpt
);
921 print_hex_dump(KERN_ERR
, " ", DUMP_PREFIX_ADDRESS
, 16,
922 1, mpc
, mpc
->mpc_length
, 1);
927 #ifdef CONFIG_X86_IO_APIC
928 for (i
= 0; i
< mp_irq_entries
; i
++) {
932 if (mp_irqs
[i
].mp_irqtype
!= mp_INT
)
935 if (mp_irqs
[i
].mp_irqflag
!= 0x0f)
938 if (nr_m_spare
> 0) {
939 printk(KERN_INFO
"*NEW* found ");
941 assign_to_mpc_intsrc(&mp_irqs
[i
], m_spare
[nr_m_spare
]);
942 m_spare
[nr_m_spare
] = NULL
;
944 struct mpc_config_intsrc
*m
=
945 (struct mpc_config_intsrc
*)mpt
;
946 count
+= sizeof(struct mpc_config_intsrc
);
948 printk(KERN_INFO
"No spare slots, try to append...take your risk, new mpc_length %x\n", count
);
950 if (count
<= mpc_new_length
)
951 printk(KERN_INFO
"No spare slots, try to append..., new mpc_length %x\n", count
);
953 printk(KERN_ERR
"mpc_new_length %lx is too small\n", mpc_new_length
);
957 assign_to_mpc_intsrc(&mp_irqs
[i
], m
);
958 mpc
->mpc_length
= count
;
959 mpt
+= sizeof(struct mpc_config_intsrc
);
961 print_mp_irq_info(&mp_irqs
[i
]);
965 /* update checksum */
966 mpc
->mpc_checksum
= 0;
967 mpc
->mpc_checksum
-= mpf_checksum((unsigned char *)mpc
,
973 static int __initdata enable_update_mptable
;
975 static int __init
update_mptable_setup(char *str
)
977 enable_update_mptable
= 1;
980 early_param("update_mptable", update_mptable_setup
);
982 static unsigned long __initdata mpc_new_phys
;
983 static unsigned long mpc_new_length __initdata
= 4096;
985 /* alloc_mptable or alloc_mptable=4k */
986 static int __initdata alloc_mptable
;
987 static int __init
parse_alloc_mptable_opt(char *p
)
989 enable_update_mptable
= 1;
993 mpc_new_length
= memparse(p
, &p
);
996 early_param("alloc_mptable", parse_alloc_mptable_opt
);
998 void __init
early_reserve_e820_mpc_new(void)
1000 if (enable_update_mptable
&& alloc_mptable
) {
1002 #ifdef CONFIG_X86_TRAMPOLINE
1003 startt
= TRAMPOLINE_BASE
;
1005 mpc_new_phys
= early_reserve_e820(startt
, mpc_new_length
, 4);
1009 static int __init
update_mp_table(void)
1013 struct intel_mp_floating
*mpf
;
1014 struct mp_config_table
*mpc
;
1015 struct mp_config_table
*mpc_new
;
1017 if (!enable_update_mptable
)
1025 * Now see if we need to go further.
1027 if (mpf
->mpf_feature1
!= 0)
1030 if (!mpf
->mpf_physptr
)
1033 mpc
= phys_to_virt(mpf
->mpf_physptr
);
1035 if (!smp_check_mpc(mpc
, oem
, str
))
1038 printk(KERN_INFO
"mpf: %lx\n", virt_to_phys(mpf
));
1039 printk(KERN_INFO
"mpf_physptr: %x\n", mpf
->mpf_physptr
);
1041 if (mpc_new_phys
&& mpc
->mpc_length
> mpc_new_length
) {
1043 printk(KERN_INFO
"mpc_new_length is %ld, please use alloc_mptable=8k\n",
1047 if (!mpc_new_phys
) {
1048 unsigned char old
, new;
1049 /* check if we can change the postion */
1050 mpc
->mpc_checksum
= 0;
1051 old
= mpf_checksum((unsigned char *)mpc
, mpc
->mpc_length
);
1052 mpc
->mpc_checksum
= 0xff;
1053 new = mpf_checksum((unsigned char *)mpc
, mpc
->mpc_length
);
1055 printk(KERN_INFO
"mpc is readonly, please try alloc_mptable instead\n");
1058 printk(KERN_INFO
"use in-positon replacing\n");
1060 mpf
->mpf_physptr
= mpc_new_phys
;
1061 mpc_new
= phys_to_virt(mpc_new_phys
);
1062 memcpy(mpc_new
, mpc
, mpc
->mpc_length
);
1064 /* check if we can modify that */
1065 if (mpc_new_phys
- mpf
->mpf_physptr
) {
1066 struct intel_mp_floating
*mpf_new
;
1067 /* steal 16 bytes from [0, 1k) */
1068 printk(KERN_INFO
"mpf new: %x\n", 0x400 - 16);
1069 mpf_new
= phys_to_virt(0x400 - 16);
1070 memcpy(mpf_new
, mpf
, 16);
1072 mpf
->mpf_physptr
= mpc_new_phys
;
1074 mpf
->mpf_checksum
= 0;
1075 mpf
->mpf_checksum
-= mpf_checksum((unsigned char *)mpf
, 16);
1076 printk(KERN_INFO
"mpf_physptr new: %x\n", mpf
->mpf_physptr
);
1080 * only replace the one with mp_INT and
1081 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1082 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1083 * may need pci=routeirq for all coverage
1085 replace_intsrc_all(mpc
, mpc_new_phys
, mpc_new_length
);
1090 late_initcall(update_mp_table
);