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>
34 /* Have we found an MP table */
36 unsigned int __initdata maxcpus = NR_CPUS;
41 * Various Linux-internal data structures created from the
44 int apic_version [MAX_APICS];
45 unsigned char mp_bus_id_to_type [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
46 int mp_bus_id_to_pci_bus [MAX_MP_BUSSES] = { [0 ... MAX_MP_BUSSES-1] = -1 };
47 cpumask_t pci_bus_to_cpumask [256] = { [0 ... 255] = CPU_MASK_ALL };
49 static int mp_current_pci_id = 0;
50 /* I/O APIC entries */
51 struct mpc_config_ioapic mp_ioapics[MAX_IO_APICS];
53 /* # of MP IRQ source entries */
54 struct mpc_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
56 /* MP IRQ source entries */
61 unsigned long mp_lapic_addr = 0;
65 /* Processor that is doing the boot up */
66 unsigned int boot_cpu_id = -1U;
67 /* Internal processor count */
68 static unsigned int num_processors = 0;
70 /* Bitmask of physically existing CPUs */
71 physid_mask_t phys_cpu_present_map = PHYSID_MASK_NONE;
73 /* ACPI MADT entry parsing functions */
74 #ifdef CONFIG_ACPI_BOOT
75 extern struct acpi_boot_flags acpi_boot;
76 #ifdef CONFIG_X86_LOCAL_APIC
77 extern int acpi_parse_lapic (acpi_table_entry_header *header);
78 extern int acpi_parse_lapic_addr_ovr (acpi_table_entry_header *header);
79 extern int acpi_parse_lapic_nmi (acpi_table_entry_header *header);
80 #endif /*CONFIG_X86_LOCAL_APIC*/
81 #ifdef CONFIG_X86_IO_APIC
82 extern int acpi_parse_ioapic (acpi_table_entry_header *header);
83 #endif /*CONFIG_X86_IO_APIC*/
84 #endif /*CONFIG_ACPI_BOOT*/
86 u8 bios_cpu_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = BAD_APICID };
90 * Intel MP BIOS table parsing routines:
94 * Checksum an MP configuration block.
97 static int __init mpf_checksum(unsigned char *mp, int len)
107 static void __init MP_processor_info (struct mpc_config_processor *m)
110 static int found_bsp=0;
112 if (!(m->mpc_cpuflag & CPU_ENABLED))
115 printk(KERN_INFO "Processor #%d %d:%d APIC version %d\n",
117 (m->mpc_cpufeature & CPU_FAMILY_MASK)>>8,
118 (m->mpc_cpufeature & CPU_MODEL_MASK)>>4,
121 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
122 Dprintk(" Bootup CPU\n");
123 boot_cpu_id = m->mpc_apicid;
125 if (num_processors >= NR_CPUS) {
126 printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
127 " Processor ignored.\n", NR_CPUS);
133 if (m->mpc_apicid > MAX_APICS) {
134 printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
135 m->mpc_apicid, MAX_APICS);
138 ver = m->mpc_apicver;
140 physid_set(m->mpc_apicid, phys_cpu_present_map);
145 printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! fixing up to 0x10. (tell your hw vendor)\n", m->mpc_apicid);
148 apic_version[m->mpc_apicid] = ver;
149 if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
151 * bios_cpu_apicid is required to have processors listed
152 * in same order as logical cpu numbers. Hence the first
153 * entry is BSP, and so on.
155 bios_cpu_apicid[0] = m->mpc_apicid;
156 x86_cpu_to_apicid[0] = m->mpc_apicid;
159 bios_cpu_apicid[num_processors - found_bsp] = m->mpc_apicid;
160 x86_cpu_to_apicid[num_processors - found_bsp] = m->mpc_apicid;
164 static void __init MP_bus_info (struct mpc_config_bus *m)
168 memcpy(str, m->mpc_bustype, 6);
170 Dprintk("Bus #%d is %s\n", m->mpc_busid, str);
172 if (strncmp(str, "ISA", 3) == 0) {
173 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_ISA;
174 } else if (strncmp(str, "EISA", 4) == 0) {
175 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_EISA;
176 } else if (strncmp(str, "PCI", 3) == 0) {
177 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_PCI;
178 mp_bus_id_to_pci_bus[m->mpc_busid] = mp_current_pci_id;
180 } else if (strncmp(str, "MCA", 3) == 0) {
181 mp_bus_id_to_type[m->mpc_busid] = MP_BUS_MCA;
183 printk(KERN_ERR "Unknown bustype %s\n", str);
187 static void __init MP_ioapic_info (struct mpc_config_ioapic *m)
189 if (!(m->mpc_flags & MPC_APIC_USABLE))
192 printk("I/O APIC #%d Version %d at 0x%X.\n",
193 m->mpc_apicid, m->mpc_apicver, m->mpc_apicaddr);
194 if (nr_ioapics >= MAX_IO_APICS) {
195 printk(KERN_ERR "Max # of I/O APICs (%d) exceeded (found %d).\n",
196 MAX_IO_APICS, nr_ioapics);
197 panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
199 if (!m->mpc_apicaddr) {
200 printk(KERN_ERR "WARNING: bogus zero I/O APIC address"
201 " found in MP table, skipping!\n");
204 mp_ioapics[nr_ioapics] = *m;
208 static void __init MP_intsrc_info (struct mpc_config_intsrc *m)
210 mp_irqs [mp_irq_entries] = *m;
211 Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
212 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
213 m->mpc_irqtype, m->mpc_irqflag & 3,
214 (m->mpc_irqflag >> 2) & 3, m->mpc_srcbus,
215 m->mpc_srcbusirq, m->mpc_dstapic, m->mpc_dstirq);
216 if (++mp_irq_entries == MAX_IRQ_SOURCES)
217 panic("Max # of irq sources exceeded!!\n");
220 static void __init MP_lintsrc_info (struct mpc_config_lintsrc *m)
222 Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
223 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
224 m->mpc_irqtype, m->mpc_irqflag & 3,
225 (m->mpc_irqflag >> 2) &3, m->mpc_srcbusid,
226 m->mpc_srcbusirq, m->mpc_destapic, m->mpc_destapiclint);
228 * Well it seems all SMP boards in existence
229 * use ExtINT/LVT1 == LINT0 and
230 * NMI/LVT2 == LINT1 - the following check
231 * will show us if this assumptions is false.
232 * Until then we do not have to add baggage.
234 if ((m->mpc_irqtype == mp_ExtINT) &&
235 (m->mpc_destapiclint != 0))
237 if ((m->mpc_irqtype == mp_NMI) &&
238 (m->mpc_destapiclint != 1))
246 static int __init smp_read_mpc(struct mp_config_table *mpc)
249 int count=sizeof(*mpc);
250 unsigned char *mpt=((unsigned char *)mpc)+count;
252 if (memcmp(mpc->mpc_signature,MPC_SIGNATURE,4)) {
253 printk("SMP mptable: bad signature [%c%c%c%c]!\n",
254 mpc->mpc_signature[0],
255 mpc->mpc_signature[1],
256 mpc->mpc_signature[2],
257 mpc->mpc_signature[3]);
260 if (mpf_checksum((unsigned char *)mpc,mpc->mpc_length)) {
261 printk("SMP mptable: checksum error!\n");
264 if (mpc->mpc_spec!=0x01 && mpc->mpc_spec!=0x04) {
265 printk(KERN_ERR "SMP mptable: bad table version (%d)!!\n",
269 if (!mpc->mpc_lapic) {
270 printk(KERN_ERR "SMP mptable: null local APIC address!\n");
273 memcpy(str,mpc->mpc_oem,8);
275 printk(KERN_INFO "OEM ID: %s ",str);
277 memcpy(str,mpc->mpc_productid,12);
279 printk(KERN_INFO "Product ID: %s ",str);
281 printk(KERN_INFO "APIC at: 0x%X\n",mpc->mpc_lapic);
283 /* save the local APIC address, it might be non-default */
285 mp_lapic_addr = mpc->mpc_lapic;
288 * Now process the configuration blocks.
290 while (count < mpc->mpc_length) {
294 struct mpc_config_processor *m=
295 (struct mpc_config_processor *)mpt;
297 MP_processor_info(m);
304 struct mpc_config_bus *m=
305 (struct mpc_config_bus *)mpt;
313 struct mpc_config_ioapic *m=
314 (struct mpc_config_ioapic *)mpt;
322 struct mpc_config_intsrc *m=
323 (struct mpc_config_intsrc *)mpt;
332 struct mpc_config_lintsrc *m=
333 (struct mpc_config_lintsrc *)mpt;
341 clustered_apic_check();
343 printk(KERN_ERR "SMP mptable: no processors registered!\n");
344 return num_processors;
347 static int __init ELCR_trigger(unsigned int irq)
351 port = 0x4d0 + (irq >> 3);
352 return (inb(port) >> (irq & 7)) & 1;
355 static void __init construct_default_ioirq_mptable(int mpc_default_type)
357 struct mpc_config_intsrc intsrc;
359 int ELCR_fallback = 0;
361 intsrc.mpc_type = MP_INTSRC;
362 intsrc.mpc_irqflag = 0; /* conforming */
363 intsrc.mpc_srcbus = 0;
364 intsrc.mpc_dstapic = mp_ioapics[0].mpc_apicid;
366 intsrc.mpc_irqtype = mp_INT;
369 * If true, we have an ISA/PCI system with no IRQ entries
370 * in the MP table. To prevent the PCI interrupts from being set up
371 * incorrectly, we try to use the ELCR. The sanity check to see if
372 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
373 * never be level sensitive, so we simply see if the ELCR agrees.
374 * If it does, we assume it's valid.
376 if (mpc_default_type == 5) {
377 printk(KERN_INFO "ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
379 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
380 printk(KERN_ERR "ELCR contains invalid data... not using ELCR\n");
382 printk(KERN_INFO "Using ELCR to identify PCI interrupts\n");
387 for (i = 0; i < 16; i++) {
388 switch (mpc_default_type) {
390 if (i == 0 || i == 13)
391 continue; /* IRQ0 & IRQ13 not connected */
395 continue; /* IRQ2 is never connected */
400 * If the ELCR indicates a level-sensitive interrupt, we
401 * copy that information over to the MP table in the
402 * irqflag field (level sensitive, active high polarity).
405 intsrc.mpc_irqflag = 13;
407 intsrc.mpc_irqflag = 0;
410 intsrc.mpc_srcbusirq = i;
411 intsrc.mpc_dstirq = i ? i : 2; /* IRQ0 to INTIN2 */
412 MP_intsrc_info(&intsrc);
415 intsrc.mpc_irqtype = mp_ExtINT;
416 intsrc.mpc_srcbusirq = 0;
417 intsrc.mpc_dstirq = 0; /* 8259A to INTIN0 */
418 MP_intsrc_info(&intsrc);
421 static inline void __init construct_default_ISA_mptable(int mpc_default_type)
423 struct mpc_config_processor processor;
424 struct mpc_config_bus bus;
425 struct mpc_config_ioapic ioapic;
426 struct mpc_config_lintsrc lintsrc;
427 int linttypes[2] = { mp_ExtINT, mp_NMI };
431 * local APIC has default address
433 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
436 * 2 CPUs, numbered 0 & 1.
438 processor.mpc_type = MP_PROCESSOR;
439 /* Either an integrated APIC or a discrete 82489DX. */
440 processor.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
441 processor.mpc_cpuflag = CPU_ENABLED;
442 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
443 (boot_cpu_data.x86_model << 4) |
444 boot_cpu_data.x86_mask;
445 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
446 processor.mpc_reserved[0] = 0;
447 processor.mpc_reserved[1] = 0;
448 for (i = 0; i < 2; i++) {
449 processor.mpc_apicid = i;
450 MP_processor_info(&processor);
453 bus.mpc_type = MP_BUS;
455 switch (mpc_default_type) {
457 printk(KERN_ERR "???\nUnknown standard configuration %d\n",
462 memcpy(bus.mpc_bustype, "ISA ", 6);
467 memcpy(bus.mpc_bustype, "EISA ", 6);
471 memcpy(bus.mpc_bustype, "MCA ", 6);
474 if (mpc_default_type > 4) {
476 memcpy(bus.mpc_bustype, "PCI ", 6);
480 ioapic.mpc_type = MP_IOAPIC;
481 ioapic.mpc_apicid = 2;
482 ioapic.mpc_apicver = mpc_default_type > 4 ? 0x10 : 0x01;
483 ioapic.mpc_flags = MPC_APIC_USABLE;
484 ioapic.mpc_apicaddr = 0xFEC00000;
485 MP_ioapic_info(&ioapic);
488 * We set up most of the low 16 IO-APIC pins according to MPS rules.
490 construct_default_ioirq_mptable(mpc_default_type);
492 lintsrc.mpc_type = MP_LINTSRC;
493 lintsrc.mpc_irqflag = 0; /* conforming */
494 lintsrc.mpc_srcbusid = 0;
495 lintsrc.mpc_srcbusirq = 0;
496 lintsrc.mpc_destapic = MP_APIC_ALL;
497 for (i = 0; i < 2; i++) {
498 lintsrc.mpc_irqtype = linttypes[i];
499 lintsrc.mpc_destapiclint = i;
500 MP_lintsrc_info(&lintsrc);
504 static struct intel_mp_floating *mpf_found;
507 * Scan the memory blocks for an SMP configuration block.
509 void __init get_smp_config (void)
511 struct intel_mp_floating *mpf = mpf_found;
514 * ACPI may be used to obtain the entire SMP configuration or just to
515 * enumerate/configure processors (CONFIG_ACPI_BOOT). Note that
516 * ACPI supports both logical (e.g. Hyper-Threading) and physical
517 * processors, where MPS only supports physical.
519 if (acpi_lapic && acpi_ioapic) {
520 printk(KERN_INFO "Using ACPI (MADT) for SMP configuration information\n");
524 printk(KERN_INFO "Using ACPI for processor (LAPIC) configuration information\n");
526 printk("Intel MultiProcessor Specification v1.%d\n", mpf->mpf_specification);
527 if (mpf->mpf_feature2 & (1<<7)) {
528 printk(KERN_INFO " IMCR and PIC compatibility mode.\n");
531 printk(KERN_INFO " Virtual Wire compatibility mode.\n");
536 * Now see if we need to read further.
538 if (mpf->mpf_feature1 != 0) {
540 printk(KERN_INFO "Default MP configuration #%d\n", mpf->mpf_feature1);
541 construct_default_ISA_mptable(mpf->mpf_feature1);
543 } else if (mpf->mpf_physptr) {
546 * Read the physical hardware table. Anything here will
547 * override the defaults.
549 if (!smp_read_mpc((void *)(unsigned long)mpf->mpf_physptr)) {
550 smp_found_config = 0;
551 printk(KERN_ERR "BIOS bug, MP table errors detected!...\n");
552 printk(KERN_ERR "... disabling SMP support. (tell your hw vendor)\n");
556 * If there are no explicit MP IRQ entries, then we are
557 * broken. We set up most of the low 16 IO-APIC pins to
558 * ISA defaults and hope it will work.
560 if (!mp_irq_entries) {
561 struct mpc_config_bus bus;
563 printk(KERN_ERR "BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
565 bus.mpc_type = MP_BUS;
567 memcpy(bus.mpc_bustype, "ISA ", 6);
570 construct_default_ioirq_mptable(0);
576 printk(KERN_INFO "Processors: %d\n", num_processors);
578 * Only use the first configuration found.
582 static int __init smp_scan_config (unsigned long base, unsigned long length)
584 extern void __bad_mpf_size(void);
585 unsigned int *bp = phys_to_virt(base);
586 struct intel_mp_floating *mpf;
588 Dprintk("Scan SMP from %p for %ld bytes.\n", bp,length);
589 if (sizeof(*mpf) != 16)
593 mpf = (struct intel_mp_floating *)bp;
594 if ((*bp == SMP_MAGIC_IDENT) &&
595 (mpf->mpf_length == 1) &&
596 !mpf_checksum((unsigned char *)bp, 16) &&
597 ((mpf->mpf_specification == 1)
598 || (mpf->mpf_specification == 4)) ) {
600 smp_found_config = 1;
601 reserve_bootmem_generic(virt_to_phys(mpf), PAGE_SIZE);
602 if (mpf->mpf_physptr)
603 reserve_bootmem_generic(mpf->mpf_physptr, PAGE_SIZE);
613 void __init find_intel_smp (void)
615 unsigned int address;
618 * FIXME: Linux assumes you have 640K of base ram..
619 * this continues the error...
621 * 1) Scan the bottom 1K for a signature
622 * 2) Scan the top 1K of base RAM
623 * 3) Scan the 64K of bios
625 if (smp_scan_config(0x0,0x400) ||
626 smp_scan_config(639*0x400,0x400) ||
627 smp_scan_config(0xF0000,0x10000))
630 * If it is an SMP machine we should know now, unless the
631 * configuration is in an EISA/MCA bus machine with an
632 * extended bios data area.
634 * there is a real-mode segmented pointer pointing to the
635 * 4K EBDA area at 0x40E, calculate and scan it here.
637 * NOTE! There are Linux loaders that will corrupt the EBDA
638 * area, and as such this kind of SMP config may be less
639 * trustworthy, simply because the SMP table may have been
640 * stomped on during early boot. These loaders are buggy and
644 address = *(unsigned short *)phys_to_virt(0x40E);
646 if (smp_scan_config(address, 0x1000))
649 /* If we have come this far, we did not find an MP table */
650 printk(KERN_INFO "No mptable found.\n");
654 * - Intel MP Configuration Table
656 void __init find_smp_config (void)
658 #ifdef CONFIG_X86_LOCAL_APIC
664 /* --------------------------------------------------------------------------
665 ACPI-based MP Configuration
666 -------------------------------------------------------------------------- */
668 #ifdef CONFIG_ACPI_BOOT
670 void __init mp_register_lapic_address (
673 mp_lapic_addr = (unsigned long) address;
675 set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
677 if (boot_cpu_id == -1U)
678 boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID));
680 Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid);
684 void __init mp_register_lapic (
688 struct mpc_config_processor processor;
691 if (id >= MAX_APICS) {
692 printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
697 if (id == boot_cpu_physical_apicid)
700 processor.mpc_type = MP_PROCESSOR;
701 processor.mpc_apicid = id;
702 processor.mpc_apicver = 0x10; /* TBD: lapic version */
703 processor.mpc_cpuflag = (enabled ? CPU_ENABLED : 0);
704 processor.mpc_cpuflag |= (boot_cpu ? CPU_BOOTPROCESSOR : 0);
705 processor.mpc_cpufeature = (boot_cpu_data.x86 << 8) |
706 (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_mask;
707 processor.mpc_featureflag = boot_cpu_data.x86_capability[0];
708 processor.mpc_reserved[0] = 0;
709 processor.mpc_reserved[1] = 0;
711 MP_processor_info(&processor);
714 #ifdef CONFIG_X86_IO_APIC
717 #define MP_MAX_IOAPIC_PIN 127
719 static struct mp_ioapic_routing {
723 u32 pin_programmed[4];
724 } mp_ioapic_routing[MAX_IO_APICS];
727 static int mp_find_ioapic (
732 /* Find the IOAPIC that manages this GSI. */
733 for (i = 0; i < nr_ioapics; i++) {
734 if ((gsi >= mp_ioapic_routing[i].gsi_start)
735 && (gsi <= mp_ioapic_routing[i].gsi_end))
739 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
745 void __init mp_register_ioapic (
752 if (nr_ioapics >= MAX_IO_APICS) {
753 printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
754 "(found %d)\n", MAX_IO_APICS, nr_ioapics);
755 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
758 printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
759 " found in MADT table, skipping!\n");
765 mp_ioapics[idx].mpc_type = MP_IOAPIC;
766 mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
767 mp_ioapics[idx].mpc_apicaddr = address;
769 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
770 mp_ioapics[idx].mpc_apicid = id;
771 mp_ioapics[idx].mpc_apicver = io_apic_get_version(idx);
774 * Build basic IRQ lookup table to facilitate gsi->io_apic lookups
775 * and to prevent reprogramming of IOAPIC pins (PCI IRQs).
777 mp_ioapic_routing[idx].apic_id = mp_ioapics[idx].mpc_apicid;
778 mp_ioapic_routing[idx].gsi_start = gsi_base;
779 mp_ioapic_routing[idx].gsi_end = gsi_base +
780 io_apic_get_redir_entries(idx);
782 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
783 "GSI %d-%d\n", idx, mp_ioapics[idx].mpc_apicid,
784 mp_ioapics[idx].mpc_apicver, mp_ioapics[idx].mpc_apicaddr,
785 mp_ioapic_routing[idx].gsi_start,
786 mp_ioapic_routing[idx].gsi_end);
792 void __init mp_override_legacy_irq (
798 struct mpc_config_intsrc intsrc;
803 * Convert 'gsi' to 'ioapic.pin'.
805 ioapic = mp_find_ioapic(gsi);
808 pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
811 * TBD: This check is for faulty timer entries, where the override
812 * erroneously sets the trigger to level, resulting in a HUGE
813 * increase of timer interrupts!
815 if ((bus_irq == 0) && (trigger == 3))
818 intsrc.mpc_type = MP_INTSRC;
819 intsrc.mpc_irqtype = mp_INT;
820 intsrc.mpc_irqflag = (trigger << 2) | polarity;
821 intsrc.mpc_srcbus = MP_ISA_BUS;
822 intsrc.mpc_srcbusirq = bus_irq; /* IRQ */
823 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid; /* APIC ID */
824 intsrc.mpc_dstirq = pin; /* INTIN# */
826 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
827 intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
828 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
829 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq);
831 mp_irqs[mp_irq_entries] = intsrc;
832 if (++mp_irq_entries == MAX_IRQ_SOURCES)
833 panic("Max # of irq sources exceeded!\n");
839 void __init mp_config_acpi_legacy_irqs (void)
841 struct mpc_config_intsrc intsrc;
846 * Fabricate the legacy ISA bus (bus #31).
848 mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
849 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS);
852 * Locate the IOAPIC that manages the ISA IRQs (0-15).
854 ioapic = mp_find_ioapic(0);
858 intsrc.mpc_type = MP_INTSRC;
859 intsrc.mpc_irqflag = 0; /* Conforming */
860 intsrc.mpc_srcbus = MP_ISA_BUS;
861 intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;
864 * Use the default configuration for the IRQs 0-15. Unless
865 * overridden by (MADT) interrupt source override entries.
867 for (i = 0; i < 16; i++) {
870 for (idx = 0; idx < mp_irq_entries; idx++) {
871 struct mpc_config_intsrc *irq = mp_irqs + idx;
873 /* Do we already have a mapping for this ISA IRQ? */
874 if (irq->mpc_srcbus == MP_ISA_BUS && irq->mpc_srcbusirq == i)
877 /* Do we already have a mapping for this IOAPIC pin */
878 if ((irq->mpc_dstapic == intsrc.mpc_dstapic) &&
879 (irq->mpc_dstirq == i))
883 if (idx != mp_irq_entries) {
884 printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
885 continue; /* IRQ already used */
888 intsrc.mpc_irqtype = mp_INT;
889 intsrc.mpc_srcbusirq = i; /* Identity mapped */
890 intsrc.mpc_dstirq = i;
892 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
893 "%d-%d\n", intsrc.mpc_irqtype, intsrc.mpc_irqflag & 3,
894 (intsrc.mpc_irqflag >> 2) & 3, intsrc.mpc_srcbus,
895 intsrc.mpc_srcbusirq, intsrc.mpc_dstapic,
898 mp_irqs[mp_irq_entries] = intsrc;
899 if (++mp_irq_entries == MAX_IRQ_SOURCES)
900 panic("Max # of irq sources exceeded!\n");
906 int mp_register_gsi(u32 gsi, int edge_level, int active_high_low)
912 if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
915 #ifdef CONFIG_ACPI_BUS
916 /* Don't set up the ACPI SCI because it's already set up */
917 if (acpi_fadt.sci_int == gsi)
921 ioapic = mp_find_ioapic(gsi);
923 printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
927 ioapic_pin = gsi - mp_ioapic_routing[ioapic].gsi_start;
930 * Avoid pin reprogramming. PRTs typically include entries
931 * with redundant pin->gsi mappings (but unique PCI devices);
932 * we only program the IOAPIC on the first.
934 bit = ioapic_pin % 32;
935 idx = (ioapic_pin < 32) ? 0 : (ioapic_pin / 32);
937 printk(KERN_ERR "Invalid reference to IOAPIC pin "
938 "%d-%d\n", mp_ioapic_routing[ioapic].apic_id,
942 if ((1<<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) {
943 Dprintk(KERN_DEBUG "Pin %d-%d already programmed\n",
944 mp_ioapic_routing[ioapic].apic_id, ioapic_pin);
948 mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1<<bit);
950 io_apic_set_pci_routing(ioapic, ioapic_pin, gsi,
951 edge_level == ACPI_EDGE_SENSITIVE ? 0 : 1,
952 active_high_low == ACPI_ACTIVE_HIGH ? 0 : 1);
956 #endif /*CONFIG_X86_IO_APIC*/
957 #endif /*CONFIG_ACPI_BOOT*/