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>
9 * Erich Boleyn : MP v1.4 and additional changes.
10 * Alan Cox : Added EBDA scanning
11 * Ingo Molnar : various cleanups and rewrites
12 * Maciej W. Rozycki: Bits for default MP configurations
13 * Paul Diefenbaugh: Added full ACPI support
17 #include <linux/irq.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
20 #include <linux/config.h>
21 #include <linux/bootmem.h>
22 #include <linux/smp_lock.h>
23 #include <linux/kernel_stat.h>
24 #include <linux/mc146818rtc.h>
25 #include <linux/acpi.h>
29 #include <asm/mpspec.h>
30 #include <asm/pgalloc.h>
31 #include <asm/io_apic.h>
32 #include <asm/proto.h>
35 /* Have we found an MP table */
37 unsigned int __initdata maxcpus = NR_CPUS;
42 * Various Linux-internal data structures created from the
45 int apic_version [MAX_APICS];
46 unsigned char mp_bus_id_to_type [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
47 int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
48 cpumask_t pci_bus_to_cpumask [256] = { [0 ... 255] = CPU_MASK_ALL };
50 static int mp_current_pci_id = 0;
51 /* I/O APIC entries */
52 struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
54 /* # of MP IRQ source entries */
55 struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
57 /* MP IRQ source entries */
62 unsigned long mp_lapic_addr = 0;
66 /* Processor that is doing the boot up */
67 unsigned int boot_cpu_id = -1U;
68 /* Internal processor count */
69 static unsigned int num_processors = 0;
71 /* Bitmask of physically existing CPUs */
72 physid_mask_t phys_cpu_present_map = PHYSID_MASK_NONE;
74 /* ACPI MADT entry parsing functions */
75 #ifdef CONFIG_ACPI_BOOT
76 extern struct acpi_boot_flags acpi_boot;
77 #ifdef CONFIG_X86_LOCAL_APIC
78 extern int acpi_parse_lapic (acpi_table_entry_header *header);
79 extern int acpi_parse_lapic_addr_ovr (acpi_table_entry_header *header);
80 extern int acpi_parse_lapic_nmi (acpi_table_entry_header *header);
81 #endif /*CONFIG_X86_LOCAL_APIC*/
82 #ifdef CONFIG_X86_IO_APIC
83 extern int acpi_parse_ioapic (acpi_table_entry_header *header);
84 #endif /*CONFIG_X86_IO_APIC*/
85 #endif /*CONFIG_ACPI_BOOT*/
87 u8 bios_cpu_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
91 * Intel MP BIOS table parsing routines:
95 * Checksum an MP configuration block.
98 static int __init mpf_checksum(unsigned char *mp, int len)
108 static void __init MP_processor_info (struct mpc_config_processor *m)
111 static int found_bsp=0;
113 if (!(m->mpc_cpuflag & CPU_ENABLED))
116 printk(KERN_INFO "Processor #%d %d:%d APIC version %d\n",
118 (m->mpc_cpufeature & CPU_FAMILY_MASK)>>8,
119 (m->mpc_cpufeature & CPU_MODEL_MASK)>>4,
122 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
123 Dprintk(" Bootup CPU\n");
124 boot_cpu_id = m->mpc_apicid;
126 if (num_processors >= NR_CPUS) {
127 printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
128 " Processor ignored.\n", NR_CPUS);
134 if (m->mpc_apicid > MAX_APICS) {
135 printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
136 m->mpc_apicid, MAX_APICS);
139 ver = m->mpc_apicver;
141 physid_set(m->mpc_apicid, phys_cpu_present_map);
146 printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! fixing up to 0x10. (tell your hw vendor)\n", m->mpc_apicid);
149 apic_version[m->mpc_apicid] = ver;
150 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
152 * bios_cpu_apicid is required to have processors listed
153 * in same order as logical cpu numbers. Hence the first
154 * entry is BSP, and so on.
156 bios_cpu_apicid[0] = m->mpc_apicid;
157 x86_cpu_to_apicid[0] = m->mpc_apicid;
160 bios_cpu_apicid[num_processors - found_bsp] = m->mpc_apicid;
161 x86_cpu_to_apicid[num_processors - found_bsp] = m->mpc_apicid;
165 static void __init MP_bus_info (struct mpc_config_bus *m)
169 memcpy(str, m->mpc_bustype, 6);
171 Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
173 if (strncmp(str, "ISA", 3) == 0) {
174 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
175 } else if (strncmp(str, "EISA", 4) == 0) {
176 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
177 } else if (strncmp(str, "PCI", 3) == 0) {
178 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
179 mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
181 } else if (strncmp(str, "MCA", 3) == 0) {
182 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
184 printk(KERN_ERR "Unknown bustype %s\n", str);
188 static void __init MP_ioapic_info (struct mpc_config_ioapic *m)
190 if (!(m->mpc_flags & MPC_APIC_USABLE))
193 printk("I/O APIC #%d Version %d at 0x%X.\n",
194 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
195 if (nr_ioapics >= MAX_IO_APICS) {
196 printk(KERN_ERR "Max # of I/O APICs (%d) exceeded (found %d).\n",
197 MAX_IO_APICS, nr_ioapics);
198 panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
200 if (!m->mpc_apicaddr) {
201 printk(KERN_ERR "WARNING: bogus zero I/O APIC address"
202 " found in MP table, skipping!\n");
205 mp_ioapics[nr_ioapics] = *m;
209 static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
211 mp_irqs [mp_irq_entries] = *m;
212 Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
213 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
214 m->mpc_irqtype, m->mpc_irqflag & 3,
215 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
216 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
217 if (++mp_irq_entries == MAX_IRQ_SOURCES)
218 panic("Max # of irq sources exceeded!!\n");
221 static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m)
223 Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
224 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
225 m->mpc_irqtype, m->mpc_irqflag & 3,
226 (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
227 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
229 * Well it seems all SMP boards in existence
230 * use ExtINT/LVT1 == LINT0 and
231 * NMI/LVT2 == LINT1 - the following check
232 * will show us if this assumptions is false.
233 * Until then we do not have to add baggage.
235 if ((m->mpc_irqtype == mp_ExtINT) &&
236 (m->mpc_destapiclint != 0))
238 if ((m->mpc_irqtype == mp_NMI) &&
239 (m->mpc_destapiclint != 1))
247 static int __init smp_read_mpc(struct mp_config_table *mpc)
250 int count=sizeof(*mpc);
251 unsigned char *mpt=((unsigned char *)mpc)+count;
253 if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) {
254 printk("SMP mptable: bad signature [%c%c%c%c]!\n",
255 mpc->mpc_signature[0],
256 mpc->mpc_signature[1],
257 mpc->mpc_signature[2],
258 mpc->mpc_signature[3]);
261 if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) {
262 printk("SMP mptable: checksum error!\n");
265 if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
266 printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
270 if (!mpc->mpc_lapic) {
271 printk(KERN_ERR "SMP mptable: null local APIC address!\n");
274 memcpy(str,mpc->mpc_oem,8);
276 printk(KERN_INFO "OEM ID: %s ",str);
278 memcpy(str,mpc->mpc_productid,12);
280 printk(KERN_INFO "Product ID: %s ",str);
282 printk(KERN_INFO "APIC at: 0x%X\n",mpc->mpc_lapic);
284 /* save the local APIC address, it might be non-default */
286 mp_lapic_addr = mpc->mpc_lapic;
289 * Now process the configuration blocks.
291 while (count < mpc->mpc_length) {
295 struct mpc_config_processor *m=
296 (struct mpc_config_processor *)mpt;
298 MP_processor_info(m);
305 struct mpc_config_bus *m=
306 (struct mpc_config_bus *)mpt;
314 struct mpc_config_ioapic *m=
315 (struct mpc_config_ioapic *)mpt;
323 struct mpc_config_intsrc *m=
324 (struct mpc_config_intsrc *)mpt;
333 struct mpc_config_lintsrc *m=
334 (struct mpc_config_lintsrc *)mpt;
342 clustered_apic_check();
344 printk(KERN_ERR "SMP mptable: no processors registered!\n");
345 return num_processors;
348 static int __init ELCR_trigger(unsigned int irq)
352 port = 0x4d0 + (irq >> 3);
353 return (inb(port) >> (irq & 7)) & 1;
356 static void __init construct_default_ioirq_mptable(int mpc_default_type)
358 struct mpc_config_intsrc intsrc;
360 int ELCR_fallback = 0;
362 intsrc.mpc_type = MP_INTSRC;
363 intsrc.mpc_irqflag = 0; /* conforming */
364 intsrc.mpc_srcbus = 0;
365 intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
367 intsrc.mpc_irqtype = mp_INT;
370 * If true, we have an ISA/PCI system with no IRQ entries
371 * in the MP table. To prevent the PCI interrupts from being set up
372 * incorrectly, we try to use the ELCR. The sanity check to see if
373 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
374 * never be level sensitive, so we simply see if the ELCR agrees.
375 * If it does, we assume it's valid.
377 if (mpc_default_type == 5) {
378 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
380 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
381 printk(KERN_ERR "ELCR contains invalid data... not using ELCR\n");
383 printk(KERN_INFO "Using ELCR to identify PCI interrupts\n");
388 for (i = 0; i < 16; i++) {
389 switch (mpc_default_type) {
391 if (i == 0 || i == 13)
392 continue; /* IRQ0 & IRQ13 not connected */
396 continue; /* IRQ2 is never connected */
401 * If the ELCR indicates a level-sensitive interrupt, we
402 * copy that information over to the MP table in the
403 * irqflag field (level sensitive, active high polarity).
406 intsrc.mpc_irqflag = 13;
408 intsrc.mpc_irqflag = 0;
411 intsrc.mpc_srcbusirq = i;
412 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
413 MP_intsrc_info(&intsrc);
416 intsrc.mpc_irqtype = mp_ExtINT;
417 intsrc.mpc_srcbusirq = 0;
418 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
419 MP_intsrc_info(&intsrc);
422 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
424 struct mpc_config_processor processor;
425 struct mpc_config_bus bus;
426 struct mpc_config_ioapic ioapic;
427 struct mpc_config_lintsrc lintsrc;
428 int linttypes[2] = { mp_ExtINT, mp_NMI };
432 * local APIC has default address
434 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
437 * 2 CPUs, numbered 0 & 1.
439 processor.mpc_type = MP_PROCESSOR;
440 /* Either an integrated APIC or a discrete 82489DX. */
441 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
442 processor.mpc_cpuflag = CPU_ENABLED;
443 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
444 (boot_cpu_data.x86_model << 4) |
445 boot_cpu_data.x86_mask;
446 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
447 processor.mpc_reserved[0] = 0;
448 processor.mpc_reserved[1] = 0;
449 for (i = 0; i < 2; i++) {
450 processor.mpc_apicid = i;
451 MP_processor_info(&processor);
454 bus.mpc_type = MP_BUS;
456 switch (mpc_default_type) {
458 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
463 memcpy(bus.mpc_bustype, "ISA ", 6);
468 memcpy(bus.mpc_bustype, "EISA ", 6);
472 memcpy(bus.mpc_bustype, "MCA ", 6);
475 if (mpc_default_type > 4) {
477 memcpy(bus.mpc_bustype, "PCI ", 6);
481 ioapic.mpc_type = MP_IOAPIC;
482 ioapic.mpc_apicid = 2;
483 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
484 ioapic.mpc_flags = MPC_APIC_USABLE;
485 ioapic.mpc_apicaddr = 0xFEC00000;
486 MP_ioapic_info(&ioapic);
489 * We set up most of the low 16 IO-APIC pins according to MPS rules.
491 construct_default_ioirq_mptable(mpc_default_type);
493 lintsrc.mpc_type = MP_LINTSRC;
494 lintsrc.mpc_irqflag = 0; /* conforming */
495 lintsrc.mpc_srcbusid = 0;
496 lintsrc.mpc_srcbusirq = 0;
497 lintsrc.mpc_destapic = MP_APIC_ALL;
498 for (i = 0; i < 2; i++) {
499 lintsrc.mpc_irqtype = linttypes[i];
500 lintsrc.mpc_destapiclint = i;
501 MP_lintsrc_info(&lintsrc);
505 static struct intel_mp_floating *mpf_found;
508 * Scan the memory blocks for an SMP configuration block.
510 void __init get_smp_config (void)
512 struct intel_mp_floating *mpf = mpf_found;
515 * ACPI may be used to obtain the entire SMP configuration or just to
516 * enumerate/configure processors (CONFIG_ACPI_BOOT). Note that
517 * ACPI supports both logical (e.g. Hyper-Threading) and physical
518 * processors, where MPS only supports physical.
520 if (acpi_lapic && acpi_ioapic) {
521 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n");
525 printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n");
527 printk("Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification);
528 if (mpf->mpf_feature2 & (1<<7)) {
529 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
532 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
537 * Now see if we need to read further.
539 if (mpf->mpf_feature1 != 0) {
541 printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1);
542 construct_default_ISA_mptable(mpf->mpf_feature1);
544 } else if (mpf->mpf_physptr) {
547 * Read the physical hardware table. Anything here will
548 * override the defaults.
550 if (!smp_read_mpc((void *)(unsigned long)mpf->mpf_physptr)) {
551 smp_found_config = 0;
552 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
553 printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
557 * If there are no explicit MP IRQ entries, then we are
558 * broken. We set up most of the low 16 IO-APIC pins to
559 * ISA defaults and hope it will work.
561 if (!mp_irq_entries) {
562 struct mpc_config_bus bus;
564 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
566 bus.mpc_type = MP_BUS;
568 memcpy(bus.mpc_bustype, "ISA ", 6);
571 construct_default_ioirq_mptable(0);
577 printk(KERN_INFO "Processors: %d\n", num_processors);
579 * Only use the first configuration found.
583 static int __init smp_scan_config (unsigned long base, unsigned long length)
585 extern void __bad_mpf_size(void);
586 unsigned int *bp = phys_to_virt(base);
587 struct intel_mp_floating *mpf;
589 Dprintk("Scan SMP from %p for %ld bytes.\n", bp,length);
590 if (sizeof(*mpf) != 16)
594 mpf = (struct intel_mp_floating *)bp;
595 if ((*bp == SMP_MAGIC_IDENT) &&
596 (mpf->mpf_length == 1) &&
597 !mpf_checksum((unsigned char *)bp, 16) &&
598 ((mpf->mpf_specification == 1)
599 || (mpf->mpf_specification == 4)) ) {
601 smp_found_config = 1;
602 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
603 if (mpf->mpf_physptr)
604 reserve_bootmem_generic(mpf->mpf_physptr, PAGE_SIZE);
614 void __init find_intel_smp (void)
616 unsigned int address;
619 * FIXME: Linux assumes you have 640K of base ram..
620 * this continues the error...
622 * 1) Scan the bottom 1K for a signature
623 * 2) Scan the top 1K of base RAM
624 * 3) Scan the 64K of bios
626 if (smp_scan_config(0x0,0x400) ||
627 smp_scan_config(639*0x400,0x400) ||
628 smp_scan_config(0xF0000,0x10000))
631 * If it is an SMP machine we should know now, unless the
632 * configuration is in an EISA/MCA bus machine with an
633 * extended bios data area.
635 * there is a real-mode segmented pointer pointing to the
636 * 4K EBDA area at 0x40E, calculate and scan it here.
638 * NOTE! There are Linux loaders that will corrupt the EBDA
639 * area, and as such this kind of SMP config may be less
640 * trustworthy, simply because the SMP table may have been
641 * stomped on during early boot. These loaders are buggy and
645 address = *(unsigned short *)phys_to_virt(0x40E);
647 if (smp_scan_config(address, 0x1000))
650 /* If we have come this far, we did not find an MP table */
651 printk(KERN_INFO "No mptable found.\n");
655 * - Intel MP Configuration Table
657 void __init find_smp_config (void)
659 #ifdef CONFIG_X86_LOCAL_APIC
665 /* --------------------------------------------------------------------------
666 ACPI-based MP Configuration
667 -------------------------------------------------------------------------- */
669 #ifdef CONFIG_ACPI_BOOT
671 void __init mp_register_lapic_address (
674 mp_lapic_addr = (unsigned long) address;
676 set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
678 if (boot_cpu_id == -1U)
679 boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID));
681 Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
685 void __init mp_register_lapic (
689 struct mpc_config_processor processor;
692 if (id >= MAX_APICS) {
693 printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
698 if (id == boot_cpu_physical_apicid)
701 processor.mpc_type = MP_PROCESSOR;
702 processor.mpc_apicid = id;
703 processor.mpc_apicver = 0x10; /* TBD: lapic version */
704 processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
705 processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
706 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
707 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
708 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
709 processor.mpc_reserved[0] = 0;
710 processor.mpc_reserved[1] = 0;
712 MP_processor_info(&processor);
715 #ifdef CONFIG_X86_IO_APIC
718 #define MP_MAX_IOAPIC_PIN 127
720 static struct mp_ioapic_routing {
724 u32 pin_programmed[4];
725 } mp_ioapic_routing[MAX_IO_APICS];
728 static int mp_find_ioapic (
733 /* Find the IOAPIC that manages this GSI. */
734 for (i = 0; i < nr_ioapics; i++) {
735 if ((gsi >= mp_ioapic_routing[i].gsi_start)
736 && (gsi <= mp_ioapic_routing[i].gsi_end))
740 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
746 void __init mp_register_ioapic (
753 if (nr_ioapics >= MAX_IO_APICS) {
754 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
755 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
756 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
759 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
760 " found in MADT table, skipping!\n");
766 mp_ioapics[idx].mpc_type = MP_IOAPIC;
767 mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
768 mp_ioapics[idx].mpc_apicaddr = address;
770 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
771 mp_ioapics[idx].mpc_apicid = id;
772 mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
775 * Build basic IRQ lookup table to facilitate gsi->io_apic lookups
776 * and to prevent reprogramming of IOAPIC pins (PCI IRQs).
778 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
779 mp_ioapic_routing[idx].gsi_start = gsi_base;
780 mp_ioapic_routing[idx].gsi_end = gsi_base +
781 io_apic_get_redir_entries(idx);
783 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
784 "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
785 mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
786 mp_ioapic_routing[idx].gsi_start,
787 mp_ioapic_routing[idx].gsi_end);
793 void __init mp_override_legacy_irq (
799 struct mpc_config_intsrc intsrc;
804 * Convert 'gsi' to 'ioapic.pin'.
806 ioapic = mp_find_ioapic(gsi);
809 pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
812 * TBD: This check is for faulty timer entries, where the override
813 * erroneously sets the trigger to level, resulting in a HUGE
814 * increase of timer interrupts!
816 if ((bus_irq == 0) && (trigger == 3))
819 intsrc.mpc_type = MP_INTSRC;
820 intsrc.mpc_irqtype = mp_INT;
821 intsrc.mpc_irqflag = (trigger << 2) | polarity;
822 intsrc.mpc_srcbus = MP_ISA_BUS;
823 intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
824 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
825 intsrc.mpc_dstirq = pin; /* INTIN# */
827 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
828 intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
829 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
830 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
832 mp_irqs[mp_irq_entries] = intsrc;
833 if (++mp_irq_entries == MAX_IRQ_SOURCES)
834 panic("Max # of irq sources exceeded!\n");
840 void __init mp_config_acpi_legacy_irqs (void)
842 struct mpc_config_intsrc intsrc;
847 * Fabricate the legacy ISA bus (bus #31).
849 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
850 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
853 * Locate the IOAPIC that manages the ISA IRQs (0-15).
855 ioapic = mp_find_ioapic(0);
859 intsrc.mpc_type = MP_INTSRC;
860 intsrc.mpc_irqflag = 0; /* Conforming */
861 intsrc.mpc_srcbus = MP_ISA_BUS;
862 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
865 * Use the default configuration for the IRQs 0-15. Unless
866 * overridden by (MADT) interrupt source override entries.
868 for (i = 0; i < 16; i++) {
871 for (idx = 0; idx < mp_irq_entries; idx++) {
872 struct mpc_config_intsrc *irq = mp_irqs + idx;
874 /* Do we already have a mapping for this ISA IRQ? */
875 if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
878 /* Do we already have a mapping for this IOAPIC pin */
879 if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
880 (irq->mpc_dstirq == i))
884 if (idx != mp_irq_entries) {
885 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
886 continue; /* IRQ already used */
889 intsrc.mpc_irqtype = mp_INT;
890 intsrc.mpc_srcbusirq = i; /* Identity mapped */
891 intsrc.mpc_dstirq = i;
893 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
894 "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
895 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
896 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
899 mp_irqs[mp_irq_entries] = intsrc;
900 if (++mp_irq_entries == MAX_IRQ_SOURCES)
901 panic("Max # of irq sources exceeded!\n");
907 int mp_register_gsi(u32 gsi, int edge_level, int active_high_low)
913 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
916 #ifdef CONFIG_ACPI_BUS
917 /* Don't set up the ACPI SCI because it's already set up */
918 if (acpi_fadt.sci_int == gsi)
922 ioapic = mp_find_ioapic(gsi);
924 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
928 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
931 * Avoid pin reprogramming. PRTs typically include entries
932 * with redundant pin->gsi mappings (but unique PCI devices);
933 * we only program the IOAPIC on the first.
935 bit = ioapic_pin % 32;
936 idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
938 printk(KERN_ERR "Invalid reference to IOAPIC pin "
939 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
943 if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
944 Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
945 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
949 mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
951 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
952 edge_level == ACPI_EDGE_SENSITIVE ? 0 : 1,
953 active_high_low == ACPI_ACTIVE_HIGH ? 0 : 1);
957 #endif /*CONFIG_X86_IO_APIC*/
958 #endif /*CONFIG_ACPI_BOOT*/