x86: remove mach_apicdef.h
[linux-2.6/mini2440.git] / arch / x86 / kernel / mpparse.c
bloba1452a53d14f35e0ec1f63e5e7c6df7d2ad68a0d
1 /*
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 Ingo Molnar <mingo@redhat.com>
7 * (c) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
8 */
10 #include <linux/mm.h>
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>
21 #include <asm/mtrr.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>
27 #include <asm/e820.h>
28 #include <asm/trampoline.h>
29 #include <asm/setup.h>
30 #include <asm/smp.h>
32 #include <mach_apic.h>
35 * Checksum an MP configuration block.
38 static int __init mpf_checksum(unsigned char *mp, int len)
40 int sum = 0;
42 while (len--)
43 sum += *mp++;
45 return sum & 0xFF;
48 static void __init MP_processor_info(struct mpc_cpu *m)
50 int apicid;
51 char *bootup_cpu = "";
53 if (!(m->cpuflag & CPU_ENABLED)) {
54 disabled_cpus++;
55 return;
58 if (x86_quirks->mpc_apic_id)
59 apicid = x86_quirks->mpc_apic_id(m);
60 else
61 apicid = m->apicid;
63 if (m->cpuflag & CPU_BOOTPROCESSOR) {
64 bootup_cpu = " (Bootup-CPU)";
65 boot_cpu_physical_apicid = m->apicid;
68 printk(KERN_INFO "Processor #%d%s\n", m->apicid, bootup_cpu);
69 generic_processor_info(apicid, m->apicver);
72 #ifdef CONFIG_X86_IO_APIC
73 static void __init MP_bus_info(struct mpc_bus *m)
75 char str[7];
76 memcpy(str, m->bustype, 6);
77 str[6] = 0;
79 if (x86_quirks->mpc_oem_bus_info)
80 x86_quirks->mpc_oem_bus_info(m, str);
81 else
82 apic_printk(APIC_VERBOSE, "Bus #%d is %s\n", m->busid, str);
84 #if MAX_MP_BUSSES < 256
85 if (m->busid >= MAX_MP_BUSSES) {
86 printk(KERN_WARNING "MP table busid value (%d) for bustype %s "
87 " is too large, max. supported is %d\n",
88 m->busid, str, MAX_MP_BUSSES - 1);
89 return;
91 #endif
93 if (strncmp(str, BUSTYPE_ISA, sizeof(BUSTYPE_ISA) - 1) == 0) {
94 set_bit(m->busid, mp_bus_not_pci);
95 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
96 mp_bus_id_to_type[m->busid] = MP_BUS_ISA;
97 #endif
98 } else if (strncmp(str, BUSTYPE_PCI, sizeof(BUSTYPE_PCI) - 1) == 0) {
99 if (x86_quirks->mpc_oem_pci_bus)
100 x86_quirks->mpc_oem_pci_bus(m);
102 clear_bit(m->busid, mp_bus_not_pci);
103 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
104 mp_bus_id_to_type[m->busid] = MP_BUS_PCI;
105 } else if (strncmp(str, BUSTYPE_EISA, sizeof(BUSTYPE_EISA) - 1) == 0) {
106 mp_bus_id_to_type[m->busid] = MP_BUS_EISA;
107 } else if (strncmp(str, BUSTYPE_MCA, sizeof(BUSTYPE_MCA) - 1) == 0) {
108 mp_bus_id_to_type[m->busid] = MP_BUS_MCA;
109 #endif
110 } else
111 printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
113 #endif
115 #ifdef CONFIG_X86_IO_APIC
117 static int bad_ioapic(unsigned long address)
119 if (nr_ioapics >= MAX_IO_APICS) {
120 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
121 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
122 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
124 if (!address) {
125 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
126 " found in table, skipping!\n");
127 return 1;
129 return 0;
132 static void __init MP_ioapic_info(struct mpc_ioapic *m)
134 if (!(m->flags & MPC_APIC_USABLE))
135 return;
137 printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
138 m->apicid, m->apicver, m->apicaddr);
140 if (bad_ioapic(m->apicaddr))
141 return;
143 mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
144 mp_ioapics[nr_ioapics].apicid = m->apicid;
145 mp_ioapics[nr_ioapics].type = m->type;
146 mp_ioapics[nr_ioapics].apicver = m->apicver;
147 mp_ioapics[nr_ioapics].flags = m->flags;
148 nr_ioapics++;
151 static void print_MP_intsrc_info(struct mpc_intsrc *m)
153 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
154 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
155 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
156 m->srcbusirq, m->dstapic, m->dstirq);
159 static void __init print_mp_irq_info(struct mpc_intsrc *mp_irq)
161 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
162 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
163 mp_irq->irqtype, mp_irq->irqflag & 3,
164 (mp_irq->irqflag >> 2) & 3, mp_irq->srcbus,
165 mp_irq->srcbusirq, mp_irq->dstapic, mp_irq->dstirq);
168 static void __init assign_to_mp_irq(struct mpc_intsrc *m,
169 struct mpc_intsrc *mp_irq)
171 mp_irq->dstapic = m->dstapic;
172 mp_irq->type = m->type;
173 mp_irq->irqtype = m->irqtype;
174 mp_irq->irqflag = m->irqflag;
175 mp_irq->srcbus = m->srcbus;
176 mp_irq->srcbusirq = m->srcbusirq;
177 mp_irq->dstirq = m->dstirq;
180 static void __init assign_to_mpc_intsrc(struct mpc_intsrc *mp_irq,
181 struct mpc_intsrc *m)
183 m->dstapic = mp_irq->dstapic;
184 m->type = mp_irq->type;
185 m->irqtype = mp_irq->irqtype;
186 m->irqflag = mp_irq->irqflag;
187 m->srcbus = mp_irq->srcbus;
188 m->srcbusirq = mp_irq->srcbusirq;
189 m->dstirq = mp_irq->dstirq;
192 static int __init mp_irq_mpc_intsrc_cmp(struct mpc_intsrc *mp_irq,
193 struct mpc_intsrc *m)
195 if (mp_irq->dstapic != m->dstapic)
196 return 1;
197 if (mp_irq->type != m->type)
198 return 2;
199 if (mp_irq->irqtype != m->irqtype)
200 return 3;
201 if (mp_irq->irqflag != m->irqflag)
202 return 4;
203 if (mp_irq->srcbus != m->srcbus)
204 return 5;
205 if (mp_irq->srcbusirq != m->srcbusirq)
206 return 6;
207 if (mp_irq->dstirq != m->dstirq)
208 return 7;
210 return 0;
213 static void __init MP_intsrc_info(struct mpc_intsrc *m)
215 int i;
217 print_MP_intsrc_info(m);
219 for (i = 0; i < mp_irq_entries; i++) {
220 if (!mp_irq_mpc_intsrc_cmp(&mp_irqs[i], m))
221 return;
224 assign_to_mp_irq(m, &mp_irqs[mp_irq_entries]);
225 if (++mp_irq_entries == MAX_IRQ_SOURCES)
226 panic("Max # of irq sources exceeded!!\n");
229 #endif
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);
240 * Read/parse the MPC
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]);
250 return 0;
252 if (mpf_checksum((unsigned char *)mpc, mpc->length)) {
253 printk(KERN_ERR "MPTABLE: checksum error!\n");
254 return 0;
256 if (mpc->spec != 0x01 && mpc->spec != 0x04) {
257 printk(KERN_ERR "MPTABLE: bad table version (%d)!!\n",
258 mpc->spec);
259 return 0;
261 if (!mpc->lapic) {
262 printk(KERN_ERR "MPTABLE: null local APIC address!\n");
263 return 0;
265 memcpy(oem, mpc->oem, 8);
266 oem[8] = 0;
267 printk(KERN_INFO "MPTABLE: OEM ID: %s\n", oem);
269 memcpy(str, mpc->productid, 12);
270 str[12] = 0;
272 printk(KERN_INFO "MPTABLE: Product ID: %s\n", str);
274 printk(KERN_INFO "MPTABLE: APIC at: 0x%X\n", mpc->lapic);
276 return 1;
279 static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
281 char str[16];
282 char oem[10];
284 int count = sizeof(*mpc);
285 unsigned char *mpt = ((unsigned char *)mpc) + count;
287 if (!smp_check_mpc(mpc, oem, str))
288 return 0;
290 #ifdef CONFIG_X86_32
291 generic_mps_oem_check(mpc, oem, str);
292 #endif
293 /* save the local APIC address, it might be non-default */
294 if (!acpi_lapic)
295 mp_lapic_addr = mpc->lapic;
297 if (early)
298 return 1;
300 if (mpc->oemptr && x86_quirks->smp_read_mpc_oem) {
301 struct mpc_oemtable *oem_table = (void *)(long)mpc->oemptr;
302 x86_quirks->smp_read_mpc_oem(oem_table, mpc->oemsize);
306 * Now process the configuration blocks.
308 if (x86_quirks->mpc_record)
309 *x86_quirks->mpc_record = 0;
311 while (count < mpc->length) {
312 switch (*mpt) {
313 case MP_PROCESSOR:
315 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
316 /* ACPI may have already provided this data */
317 if (!acpi_lapic)
318 MP_processor_info(m);
319 mpt += sizeof(*m);
320 count += sizeof(*m);
321 break;
323 case MP_BUS:
325 struct mpc_bus *m = (struct mpc_bus *)mpt;
326 #ifdef CONFIG_X86_IO_APIC
327 MP_bus_info(m);
328 #endif
329 mpt += sizeof(*m);
330 count += sizeof(*m);
331 break;
333 case MP_IOAPIC:
335 #ifdef CONFIG_X86_IO_APIC
336 struct mpc_ioapic *m = (struct mpc_ioapic *)mpt;
337 MP_ioapic_info(m);
338 #endif
339 mpt += sizeof(struct mpc_ioapic);
340 count += sizeof(struct mpc_ioapic);
341 break;
343 case MP_INTSRC:
345 #ifdef CONFIG_X86_IO_APIC
346 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
348 MP_intsrc_info(m);
349 #endif
350 mpt += sizeof(struct mpc_intsrc);
351 count += sizeof(struct mpc_intsrc);
352 break;
354 case MP_LINTSRC:
356 struct mpc_lintsrc *m =
357 (struct mpc_lintsrc *)mpt;
358 MP_lintsrc_info(m);
359 mpt += sizeof(*m);
360 count += sizeof(*m);
361 break;
363 default:
364 /* wrong mptable */
365 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
366 printk(KERN_ERR "type %x\n", *mpt);
367 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
368 1, mpc, mpc->length, 1);
369 count = mpc->length;
370 break;
372 if (x86_quirks->mpc_record)
373 (*x86_quirks->mpc_record)++;
376 #ifdef CONFIG_X86_GENERICARCH
377 generic_bigsmp_probe();
378 #endif
380 if (apic->setup_apic_routing)
381 apic->setup_apic_routing();
383 if (!num_processors)
384 printk(KERN_ERR "MPTABLE: no processors registered!\n");
385 return num_processors;
388 #ifdef CONFIG_X86_IO_APIC
390 static int __init ELCR_trigger(unsigned int irq)
392 unsigned int port;
394 port = 0x4d0 + (irq >> 3);
395 return (inb(port) >> (irq & 7)) & 1;
398 static void __init construct_default_ioirq_mptable(int mpc_default_type)
400 struct mpc_intsrc intsrc;
401 int i;
402 int ELCR_fallback = 0;
404 intsrc.type = MP_INTSRC;
405 intsrc.irqflag = 0; /* conforming */
406 intsrc.srcbus = 0;
407 intsrc.dstapic = mp_ioapics[0].apicid;
409 intsrc.irqtype = mp_INT;
412 * If true, we have an ISA/PCI system with no IRQ entries
413 * in the MP table. To prevent the PCI interrupts from being set up
414 * incorrectly, we try to use the ELCR. The sanity check to see if
415 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
416 * never be level sensitive, so we simply see if the ELCR agrees.
417 * If it does, we assume it's valid.
419 if (mpc_default_type == 5) {
420 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... "
421 "falling back to ELCR\n");
423 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) ||
424 ELCR_trigger(13))
425 printk(KERN_ERR "ELCR contains invalid data... "
426 "not using ELCR\n");
427 else {
428 printk(KERN_INFO
429 "Using ELCR to identify PCI interrupts\n");
430 ELCR_fallback = 1;
434 for (i = 0; i < 16; i++) {
435 switch (mpc_default_type) {
436 case 2:
437 if (i == 0 || i == 13)
438 continue; /* IRQ0 & IRQ13 not connected */
439 /* fall through */
440 default:
441 if (i == 2)
442 continue; /* IRQ2 is never connected */
445 if (ELCR_fallback) {
447 * If the ELCR indicates a level-sensitive interrupt, we
448 * copy that information over to the MP table in the
449 * irqflag field (level sensitive, active high polarity).
451 if (ELCR_trigger(i))
452 intsrc.irqflag = 13;
453 else
454 intsrc.irqflag = 0;
457 intsrc.srcbusirq = i;
458 intsrc.dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
459 MP_intsrc_info(&intsrc);
462 intsrc.irqtype = mp_ExtINT;
463 intsrc.srcbusirq = 0;
464 intsrc.dstirq = 0; /* 8259A to INTIN0 */
465 MP_intsrc_info(&intsrc);
469 static void __init construct_ioapic_table(int mpc_default_type)
471 struct mpc_ioapic ioapic;
472 struct mpc_bus bus;
474 bus.type = MP_BUS;
475 bus.busid = 0;
476 switch (mpc_default_type) {
477 default:
478 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
479 mpc_default_type);
480 /* fall through */
481 case 1:
482 case 5:
483 memcpy(bus.bustype, "ISA ", 6);
484 break;
485 case 2:
486 case 6:
487 case 3:
488 memcpy(bus.bustype, "EISA ", 6);
489 break;
490 case 4:
491 case 7:
492 memcpy(bus.bustype, "MCA ", 6);
494 MP_bus_info(&bus);
495 if (mpc_default_type > 4) {
496 bus.busid = 1;
497 memcpy(bus.bustype, "PCI ", 6);
498 MP_bus_info(&bus);
501 ioapic.type = MP_IOAPIC;
502 ioapic.apicid = 2;
503 ioapic.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
504 ioapic.flags = MPC_APIC_USABLE;
505 ioapic.apicaddr = 0xFEC00000;
506 MP_ioapic_info(&ioapic);
509 * We set up most of the low 16 IO-APIC pins according to MPS rules.
511 construct_default_ioirq_mptable(mpc_default_type);
513 #else
514 static inline void __init construct_ioapic_table(int mpc_default_type) { }
515 #endif
517 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
519 struct mpc_cpu processor;
520 struct mpc_lintsrc lintsrc;
521 int linttypes[2] = { mp_ExtINT, mp_NMI };
522 int i;
525 * local APIC has default address
527 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
530 * 2 CPUs, numbered 0 & 1.
532 processor.type = MP_PROCESSOR;
533 /* Either an integrated APIC or a discrete 82489DX. */
534 processor.apicver = mpc_default_type > 4 ? 0x10 : 0x01;
535 processor.cpuflag = CPU_ENABLED;
536 processor.cpufeature = (boot_cpu_data.x86 << 8) |
537 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
538 processor.featureflag = boot_cpu_data.x86_capability[0];
539 processor.reserved[0] = 0;
540 processor.reserved[1] = 0;
541 for (i = 0; i < 2; i++) {
542 processor.apicid = i;
543 MP_processor_info(&processor);
546 construct_ioapic_table(mpc_default_type);
548 lintsrc.type = MP_LINTSRC;
549 lintsrc.irqflag = 0; /* conforming */
550 lintsrc.srcbusid = 0;
551 lintsrc.srcbusirq = 0;
552 lintsrc.destapic = MP_APIC_ALL;
553 for (i = 0; i < 2; i++) {
554 lintsrc.irqtype = linttypes[i];
555 lintsrc.destapiclint = i;
556 MP_lintsrc_info(&lintsrc);
560 static struct mpf_intel *mpf_found;
563 * Scan the memory blocks for an SMP configuration block.
565 static void __init __get_smp_config(unsigned int early)
567 struct mpf_intel *mpf = mpf_found;
569 if (!mpf)
570 return;
572 if (acpi_lapic && early)
573 return;
576 * MPS doesn't support hyperthreading, aka only have
577 * thread 0 apic id in MPS table
579 if (acpi_lapic && acpi_ioapic)
580 return;
582 if (x86_quirks->mach_get_smp_config) {
583 if (x86_quirks->mach_get_smp_config(early))
584 return;
587 printk(KERN_INFO "Intel MultiProcessor Specification v1.%d\n",
588 mpf->specification);
589 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
590 if (mpf->feature2 & (1 << 7)) {
591 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
592 pic_mode = 1;
593 } else {
594 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
595 pic_mode = 0;
597 #endif
599 * Now see if we need to read further.
601 if (mpf->feature1 != 0) {
602 if (early) {
604 * local APIC has default address
606 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
607 return;
610 printk(KERN_INFO "Default MP configuration #%d\n",
611 mpf->feature1);
612 construct_default_ISA_mptable(mpf->feature1);
614 } else if (mpf->physptr) {
617 * Read the physical hardware table. Anything here will
618 * override the defaults.
620 if (!smp_read_mpc(phys_to_virt(mpf->physptr), early)) {
621 #ifdef CONFIG_X86_LOCAL_APIC
622 smp_found_config = 0;
623 #endif
624 printk(KERN_ERR
625 "BIOS bug, MP table errors detected!...\n");
626 printk(KERN_ERR "... disabling SMP support. "
627 "(tell your hw vendor)\n");
628 return;
631 if (early)
632 return;
633 #ifdef CONFIG_X86_IO_APIC
635 * If there are no explicit MP IRQ entries, then we are
636 * broken. We set up most of the low 16 IO-APIC pins to
637 * ISA defaults and hope it will work.
639 if (!mp_irq_entries) {
640 struct mpc_bus bus;
642 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, "
643 "using default mptable. "
644 "(tell your hw vendor)\n");
646 bus.type = MP_BUS;
647 bus.busid = 0;
648 memcpy(bus.bustype, "ISA ", 6);
649 MP_bus_info(&bus);
651 construct_default_ioirq_mptable(0);
653 #endif
654 } else
655 BUG();
657 if (!early)
658 printk(KERN_INFO "Processors: %d\n", num_processors);
660 * Only use the first configuration found.
664 void __init early_get_smp_config(void)
666 __get_smp_config(1);
669 void __init get_smp_config(void)
671 __get_smp_config(0);
674 static int __init smp_scan_config(unsigned long base, unsigned long length,
675 unsigned reserve)
677 unsigned int *bp = phys_to_virt(base);
678 struct mpf_intel *mpf;
680 apic_printk(APIC_VERBOSE, "Scan SMP from %p for %ld bytes.\n",
681 bp, length);
682 BUILD_BUG_ON(sizeof(*mpf) != 16);
684 while (length > 0) {
685 mpf = (struct mpf_intel *)bp;
686 if ((*bp == SMP_MAGIC_IDENT) &&
687 (mpf->length == 1) &&
688 !mpf_checksum((unsigned char *)bp, 16) &&
689 ((mpf->specification == 1)
690 || (mpf->specification == 4))) {
691 #ifdef CONFIG_X86_LOCAL_APIC
692 smp_found_config = 1;
693 #endif
694 mpf_found = mpf;
696 printk(KERN_INFO "found SMP MP-table at [%p] %08lx\n",
697 mpf, virt_to_phys(mpf));
699 if (!reserve)
700 return 1;
701 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE,
702 BOOTMEM_DEFAULT);
703 if (mpf->physptr) {
704 unsigned long size = PAGE_SIZE;
705 #ifdef CONFIG_X86_32
707 * We cannot access to MPC table to compute
708 * table size yet, as only few megabytes from
709 * the bottom is mapped now.
710 * PC-9800's MPC table places on the very last
711 * of physical memory; so that simply reserving
712 * PAGE_SIZE from mpf->physptr yields BUG()
713 * in reserve_bootmem.
715 unsigned long end = max_low_pfn * PAGE_SIZE;
716 if (mpf->physptr + size > end)
717 size = end - mpf->physptr;
718 #endif
719 reserve_bootmem_generic(mpf->physptr, size,
720 BOOTMEM_DEFAULT);
723 return 1;
725 bp += 4;
726 length -= 16;
728 return 0;
731 static void __init __find_smp_config(unsigned int reserve)
733 unsigned int address;
735 if (x86_quirks->mach_find_smp_config) {
736 if (x86_quirks->mach_find_smp_config(reserve))
737 return;
740 * FIXME: Linux assumes you have 640K of base ram..
741 * this continues the error...
743 * 1) Scan the bottom 1K for a signature
744 * 2) Scan the top 1K of base RAM
745 * 3) Scan the 64K of bios
747 if (smp_scan_config(0x0, 0x400, reserve) ||
748 smp_scan_config(639 * 0x400, 0x400, reserve) ||
749 smp_scan_config(0xF0000, 0x10000, reserve))
750 return;
752 * If it is an SMP machine we should know now, unless the
753 * configuration is in an EISA/MCA bus machine with an
754 * extended bios data area.
756 * there is a real-mode segmented pointer pointing to the
757 * 4K EBDA area at 0x40E, calculate and scan it here.
759 * NOTE! There are Linux loaders that will corrupt the EBDA
760 * area, and as such this kind of SMP config may be less
761 * trustworthy, simply because the SMP table may have been
762 * stomped on during early boot. These loaders are buggy and
763 * should be fixed.
765 * MP1.4 SPEC states to only scan first 1K of 4K EBDA.
768 address = get_bios_ebda();
769 if (address)
770 smp_scan_config(address, 0x400, reserve);
773 void __init early_find_smp_config(void)
775 __find_smp_config(0);
778 void __init find_smp_config(void)
780 __find_smp_config(1);
783 #ifdef CONFIG_X86_IO_APIC
784 static u8 __initdata irq_used[MAX_IRQ_SOURCES];
786 static int __init get_MP_intsrc_index(struct mpc_intsrc *m)
788 int i;
790 if (m->irqtype != mp_INT)
791 return 0;
793 if (m->irqflag != 0x0f)
794 return 0;
796 /* not legacy */
798 for (i = 0; i < mp_irq_entries; i++) {
799 if (mp_irqs[i].irqtype != mp_INT)
800 continue;
802 if (mp_irqs[i].irqflag != 0x0f)
803 continue;
805 if (mp_irqs[i].srcbus != m->srcbus)
806 continue;
807 if (mp_irqs[i].srcbusirq != m->srcbusirq)
808 continue;
809 if (irq_used[i]) {
810 /* already claimed */
811 return -2;
813 irq_used[i] = 1;
814 return i;
817 /* not found */
818 return -1;
821 #define SPARE_SLOT_NUM 20
823 static struct mpc_intsrc __initdata *m_spare[SPARE_SLOT_NUM];
824 #endif
826 static int __init replace_intsrc_all(struct mpc_table *mpc,
827 unsigned long mpc_new_phys,
828 unsigned long mpc_new_length)
830 #ifdef CONFIG_X86_IO_APIC
831 int i;
832 int nr_m_spare = 0;
833 #endif
835 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) {
840 switch (*mpt) {
841 case MP_PROCESSOR:
843 struct mpc_cpu *m = (struct mpc_cpu *)mpt;
844 mpt += sizeof(*m);
845 count += sizeof(*m);
846 break;
848 case MP_BUS:
850 struct mpc_bus *m = (struct mpc_bus *)mpt;
851 mpt += sizeof(*m);
852 count += sizeof(*m);
853 break;
855 case MP_IOAPIC:
857 mpt += sizeof(struct mpc_ioapic);
858 count += sizeof(struct mpc_ioapic);
859 break;
861 case MP_INTSRC:
863 #ifdef CONFIG_X86_IO_APIC
864 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
866 printk(KERN_INFO "OLD ");
867 print_MP_intsrc_info(m);
868 i = get_MP_intsrc_index(m);
869 if (i > 0) {
870 assign_to_mpc_intsrc(&mp_irqs[i], m);
871 printk(KERN_INFO "NEW ");
872 print_mp_irq_info(&mp_irqs[i]);
873 } else if (!i) {
874 /* legacy, do nothing */
875 } else if (nr_m_spare < SPARE_SLOT_NUM) {
877 * not found (-1), or duplicated (-2)
878 * are invalid entries,
879 * we need to use the slot later
881 m_spare[nr_m_spare] = m;
882 nr_m_spare++;
884 #endif
885 mpt += sizeof(struct mpc_intsrc);
886 count += sizeof(struct mpc_intsrc);
887 break;
889 case MP_LINTSRC:
891 struct mpc_lintsrc *m =
892 (struct mpc_lintsrc *)mpt;
893 mpt += sizeof(*m);
894 count += sizeof(*m);
895 break;
897 default:
898 /* wrong mptable */
899 printk(KERN_ERR "Your mptable is wrong, contact your HW vendor!\n");
900 printk(KERN_ERR "type %x\n", *mpt);
901 print_hex_dump(KERN_ERR, " ", DUMP_PREFIX_ADDRESS, 16,
902 1, mpc, mpc->length, 1);
903 goto out;
907 #ifdef CONFIG_X86_IO_APIC
908 for (i = 0; i < mp_irq_entries; i++) {
909 if (irq_used[i])
910 continue;
912 if (mp_irqs[i].irqtype != mp_INT)
913 continue;
915 if (mp_irqs[i].irqflag != 0x0f)
916 continue;
918 if (nr_m_spare > 0) {
919 printk(KERN_INFO "*NEW* found ");
920 nr_m_spare--;
921 assign_to_mpc_intsrc(&mp_irqs[i], m_spare[nr_m_spare]);
922 m_spare[nr_m_spare] = NULL;
923 } else {
924 struct mpc_intsrc *m = (struct mpc_intsrc *)mpt;
925 count += sizeof(struct mpc_intsrc);
926 if (!mpc_new_phys) {
927 printk(KERN_INFO "No spare slots, try to append...take your risk, new mpc_length %x\n", count);
928 } else {
929 if (count <= mpc_new_length)
930 printk(KERN_INFO "No spare slots, try to append..., new mpc_length %x\n", count);
931 else {
932 printk(KERN_ERR "mpc_new_length %lx is too small\n", mpc_new_length);
933 goto out;
936 assign_to_mpc_intsrc(&mp_irqs[i], m);
937 mpc->length = count;
938 mpt += sizeof(struct mpc_intsrc);
940 print_mp_irq_info(&mp_irqs[i]);
942 #endif
943 out:
944 /* update checksum */
945 mpc->checksum = 0;
946 mpc->checksum -= mpf_checksum((unsigned char *)mpc, mpc->length);
948 return 0;
951 static int __initdata enable_update_mptable;
953 static int __init update_mptable_setup(char *str)
955 enable_update_mptable = 1;
956 return 0;
958 early_param("update_mptable", update_mptable_setup);
960 static unsigned long __initdata mpc_new_phys;
961 static unsigned long mpc_new_length __initdata = 4096;
963 /* alloc_mptable or alloc_mptable=4k */
964 static int __initdata alloc_mptable;
965 static int __init parse_alloc_mptable_opt(char *p)
967 enable_update_mptable = 1;
968 alloc_mptable = 1;
969 if (!p)
970 return 0;
971 mpc_new_length = memparse(p, &p);
972 return 0;
974 early_param("alloc_mptable", parse_alloc_mptable_opt);
976 void __init early_reserve_e820_mpc_new(void)
978 if (enable_update_mptable && alloc_mptable) {
979 u64 startt = 0;
980 #ifdef CONFIG_X86_TRAMPOLINE
981 startt = TRAMPOLINE_BASE;
982 #endif
983 mpc_new_phys = early_reserve_e820(startt, mpc_new_length, 4);
987 static int __init update_mp_table(void)
989 char str[16];
990 char oem[10];
991 struct mpf_intel *mpf;
992 struct mpc_table *mpc, *mpc_new;
994 if (!enable_update_mptable)
995 return 0;
997 mpf = mpf_found;
998 if (!mpf)
999 return 0;
1002 * Now see if we need to go further.
1004 if (mpf->feature1 != 0)
1005 return 0;
1007 if (!mpf->physptr)
1008 return 0;
1010 mpc = phys_to_virt(mpf->physptr);
1012 if (!smp_check_mpc(mpc, oem, str))
1013 return 0;
1015 printk(KERN_INFO "mpf: %lx\n", virt_to_phys(mpf));
1016 printk(KERN_INFO "physptr: %x\n", mpf->physptr);
1018 if (mpc_new_phys && mpc->length > mpc_new_length) {
1019 mpc_new_phys = 0;
1020 printk(KERN_INFO "mpc_new_length is %ld, please use alloc_mptable=8k\n",
1021 mpc_new_length);
1024 if (!mpc_new_phys) {
1025 unsigned char old, new;
1026 /* check if we can change the postion */
1027 mpc->checksum = 0;
1028 old = mpf_checksum((unsigned char *)mpc, mpc->length);
1029 mpc->checksum = 0xff;
1030 new = mpf_checksum((unsigned char *)mpc, mpc->length);
1031 if (old == new) {
1032 printk(KERN_INFO "mpc is readonly, please try alloc_mptable instead\n");
1033 return 0;
1035 printk(KERN_INFO "use in-positon replacing\n");
1036 } else {
1037 mpf->physptr = mpc_new_phys;
1038 mpc_new = phys_to_virt(mpc_new_phys);
1039 memcpy(mpc_new, mpc, mpc->length);
1040 mpc = mpc_new;
1041 /* check if we can modify that */
1042 if (mpc_new_phys - mpf->physptr) {
1043 struct mpf_intel *mpf_new;
1044 /* steal 16 bytes from [0, 1k) */
1045 printk(KERN_INFO "mpf new: %x\n", 0x400 - 16);
1046 mpf_new = phys_to_virt(0x400 - 16);
1047 memcpy(mpf_new, mpf, 16);
1048 mpf = mpf_new;
1049 mpf->physptr = mpc_new_phys;
1051 mpf->checksum = 0;
1052 mpf->checksum -= mpf_checksum((unsigned char *)mpf, 16);
1053 printk(KERN_INFO "physptr new: %x\n", mpf->physptr);
1057 * only replace the one with mp_INT and
1058 * MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
1059 * already in mp_irqs , stored by ... and mp_config_acpi_gsi,
1060 * may need pci=routeirq for all coverage
1062 replace_intsrc_all(mpc, mpc_new_phys, mpc_new_length);
1064 return 0;
1067 late_initcall(update_mp_table);