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
)
111 if (!(m
->mpc_cpuflag
& CPU_ENABLED
))
114 printk(KERN_INFO
"Processor #%d %d:%d APIC version %d\n",
116 (m
->mpc_cpufeature
& CPU_FAMILY_MASK
)>>8,
117 (m
->mpc_cpufeature
& CPU_MODEL_MASK
)>>4,
120 if (m
->mpc_cpuflag
& CPU_BOOTPROCESSOR
) {
121 Dprintk(" Bootup CPU\n");
122 boot_cpu_id
= m
->mpc_apicid
;
124 if (num_processors
>= NR_CPUS
) {
125 printk(KERN_WARNING
"WARNING: NR_CPUS limit of %i reached."
126 " Processor ignored.\n", NR_CPUS
);
129 if (num_processors
>= maxcpus
) {
130 printk(KERN_WARNING
"WARNING: maxcpus limit of %i reached."
131 " Processor ignored.\n", maxcpus
);
137 if (m
->mpc_apicid
> MAX_APICS
) {
138 printk(KERN_ERR
"Processor #%d INVALID. (Max ID: %d).\n",
139 m
->mpc_apicid
, MAX_APICS
);
142 ver
= m
->mpc_apicver
;
144 physid_set(m
->mpc_apicid
, phys_cpu_present_map
);
149 printk(KERN_ERR
"BIOS bug, APIC version is 0 for CPU#%d! fixing up to 0x10. (tell your hw vendor)\n", m
->mpc_apicid
);
152 apic_version
[m
->mpc_apicid
] = ver
;
153 bios_cpu_apicid
[num_processors
- 1] = m
->mpc_apicid
;
156 static void __init
MP_bus_info (struct mpc_config_bus
*m
)
160 memcpy(str
, m
->mpc_bustype
, 6);
162 Dprintk("Bus #%d is %s\n", m
->mpc_busid
, str
);
164 if (strncmp(str
, "ISA", 3) == 0) {
165 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_ISA
;
166 } else if (strncmp(str
, "EISA", 4) == 0) {
167 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_EISA
;
168 } else if (strncmp(str
, "PCI", 3) == 0) {
169 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_PCI
;
170 mp_bus_id_to_pci_bus
[m
->mpc_busid
] = mp_current_pci_id
;
172 } else if (strncmp(str
, "MCA", 3) == 0) {
173 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_MCA
;
175 printk(KERN_ERR
"Unknown bustype %s\n", str
);
179 static void __init
MP_ioapic_info (struct mpc_config_ioapic
*m
)
181 if (!(m
->mpc_flags
& MPC_APIC_USABLE
))
184 printk("I/O APIC #%d Version %d at 0x%X.\n",
185 m
->mpc_apicid
, m
->mpc_apicver
, m
->mpc_apicaddr
);
186 if (nr_ioapics
>= MAX_IO_APICS
) {
187 printk(KERN_ERR
"Max # of I/O APICs (%d) exceeded (found %d).\n",
188 MAX_IO_APICS
, nr_ioapics
);
189 panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
191 if (!m
->mpc_apicaddr
) {
192 printk(KERN_ERR
"WARNING: bogus zero I/O APIC address"
193 " found in MP table, skipping!\n");
196 mp_ioapics
[nr_ioapics
] = *m
;
200 static void __init
MP_intsrc_info (struct mpc_config_intsrc
*m
)
202 mp_irqs
[mp_irq_entries
] = *m
;
203 Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
204 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
205 m
->mpc_irqtype
, m
->mpc_irqflag
& 3,
206 (m
->mpc_irqflag
>> 2) & 3, m
->mpc_srcbus
,
207 m
->mpc_srcbusirq
, m
->mpc_dstapic
, m
->mpc_dstirq
);
208 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
209 panic("Max # of irq sources exceeded!!\n");
212 static void __init
MP_lintsrc_info (struct mpc_config_lintsrc
*m
)
214 Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
215 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
216 m
->mpc_irqtype
, m
->mpc_irqflag
& 3,
217 (m
->mpc_irqflag
>> 2) &3, m
->mpc_srcbusid
,
218 m
->mpc_srcbusirq
, m
->mpc_destapic
, m
->mpc_destapiclint
);
220 * Well it seems all SMP boards in existence
221 * use ExtINT/LVT1 == LINT0 and
222 * NMI/LVT2 == LINT1 - the following check
223 * will show us if this assumptions is false.
224 * Until then we do not have to add baggage.
226 if ((m
->mpc_irqtype
== mp_ExtINT
) &&
227 (m
->mpc_destapiclint
!= 0))
229 if ((m
->mpc_irqtype
== mp_NMI
) &&
230 (m
->mpc_destapiclint
!= 1))
238 static int __init
smp_read_mpc(struct mp_config_table
*mpc
)
241 int count
=sizeof(*mpc
);
242 unsigned char *mpt
=((unsigned char *)mpc
)+count
;
244 if (memcmp(mpc
->mpc_signature
,MPC_SIGNATURE
,4)) {
245 printk("SMP mptable: bad signature [%c%c%c%c]!\n",
246 mpc
->mpc_signature
[0],
247 mpc
->mpc_signature
[1],
248 mpc
->mpc_signature
[2],
249 mpc
->mpc_signature
[3]);
252 if (mpf_checksum((unsigned char *)mpc
,mpc
->mpc_length
)) {
253 printk("SMP mptable: checksum error!\n");
256 if (mpc
->mpc_spec
!=0x01 && mpc
->mpc_spec
!=0x04) {
257 printk(KERN_ERR
"SMP mptable: bad table version (%d)!!\n",
261 if (!mpc
->mpc_lapic
) {
262 printk(KERN_ERR
"SMP mptable: null local APIC address!\n");
265 memcpy(str
,mpc
->mpc_oem
,8);
267 printk(KERN_INFO
"OEM ID: %s ",str
);
269 memcpy(str
,mpc
->mpc_productid
,12);
271 printk(KERN_INFO
"Product ID: %s ",str
);
273 printk(KERN_INFO
"APIC at: 0x%X\n",mpc
->mpc_lapic
);
275 /* save the local APIC address, it might be non-default */
277 mp_lapic_addr
= mpc
->mpc_lapic
;
280 * Now process the configuration blocks.
282 while (count
< mpc
->mpc_length
) {
286 struct mpc_config_processor
*m
=
287 (struct mpc_config_processor
*)mpt
;
289 MP_processor_info(m
);
296 struct mpc_config_bus
*m
=
297 (struct mpc_config_bus
*)mpt
;
305 struct mpc_config_ioapic
*m
=
306 (struct mpc_config_ioapic
*)mpt
;
314 struct mpc_config_intsrc
*m
=
315 (struct mpc_config_intsrc
*)mpt
;
324 struct mpc_config_lintsrc
*m
=
325 (struct mpc_config_lintsrc
*)mpt
;
333 clustered_apic_check();
335 printk(KERN_ERR
"SMP mptable: no processors registered!\n");
336 return num_processors
;
339 static int __init
ELCR_trigger(unsigned int irq
)
343 port
= 0x4d0 + (irq
>> 3);
344 return (inb(port
) >> (irq
& 7)) & 1;
347 static void __init
construct_default_ioirq_mptable(int mpc_default_type
)
349 struct mpc_config_intsrc intsrc
;
351 int ELCR_fallback
= 0;
353 intsrc
.mpc_type
= MP_INTSRC
;
354 intsrc
.mpc_irqflag
= 0; /* conforming */
355 intsrc
.mpc_srcbus
= 0;
356 intsrc
.mpc_dstapic
= mp_ioapics
[0].mpc_apicid
;
358 intsrc
.mpc_irqtype
= mp_INT
;
361 * If true, we have an ISA/PCI system with no IRQ entries
362 * in the MP table. To prevent the PCI interrupts from being set up
363 * incorrectly, we try to use the ELCR. The sanity check to see if
364 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
365 * never be level sensitive, so we simply see if the ELCR agrees.
366 * If it does, we assume it's valid.
368 if (mpc_default_type
== 5) {
369 printk(KERN_INFO
"ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
371 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
372 printk(KERN_ERR
"ELCR contains invalid data... not using ELCR\n");
374 printk(KERN_INFO
"Using ELCR to identify PCI interrupts\n");
379 for (i
= 0; i
< 16; i
++) {
380 switch (mpc_default_type
) {
382 if (i
== 0 || i
== 13)
383 continue; /* IRQ0 & IRQ13 not connected */
387 continue; /* IRQ2 is never connected */
392 * If the ELCR indicates a level-sensitive interrupt, we
393 * copy that information over to the MP table in the
394 * irqflag field (level sensitive, active high polarity).
397 intsrc
.mpc_irqflag
= 13;
399 intsrc
.mpc_irqflag
= 0;
402 intsrc
.mpc_srcbusirq
= i
;
403 intsrc
.mpc_dstirq
= i
? i
: 2; /* IRQ0 to INTIN2 */
404 MP_intsrc_info(&intsrc
);
407 intsrc
.mpc_irqtype
= mp_ExtINT
;
408 intsrc
.mpc_srcbusirq
= 0;
409 intsrc
.mpc_dstirq
= 0; /* 8259A to INTIN0 */
410 MP_intsrc_info(&intsrc
);
413 static inline void __init
construct_default_ISA_mptable(int mpc_default_type
)
415 struct mpc_config_processor processor
;
416 struct mpc_config_bus bus
;
417 struct mpc_config_ioapic ioapic
;
418 struct mpc_config_lintsrc lintsrc
;
419 int linttypes
[2] = { mp_ExtINT
, mp_NMI
};
423 * local APIC has default address
425 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
428 * 2 CPUs, numbered 0 & 1.
430 processor
.mpc_type
= MP_PROCESSOR
;
431 /* Either an integrated APIC or a discrete 82489DX. */
432 processor
.mpc_apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
433 processor
.mpc_cpuflag
= CPU_ENABLED
;
434 processor
.mpc_cpufeature
= (boot_cpu_data
.x86
<< 8) |
435 (boot_cpu_data
.x86_model
<< 4) |
436 boot_cpu_data
.x86_mask
;
437 processor
.mpc_featureflag
= boot_cpu_data
.x86_capability
[0];
438 processor
.mpc_reserved
[0] = 0;
439 processor
.mpc_reserved
[1] = 0;
440 for (i
= 0; i
< 2; i
++) {
441 processor
.mpc_apicid
= i
;
442 MP_processor_info(&processor
);
445 bus
.mpc_type
= MP_BUS
;
447 switch (mpc_default_type
) {
449 printk(KERN_ERR
"???\nUnknown standard configuration %d\n",
454 memcpy(bus
.mpc_bustype
, "ISA ", 6);
459 memcpy(bus
.mpc_bustype
, "EISA ", 6);
463 memcpy(bus
.mpc_bustype
, "MCA ", 6);
466 if (mpc_default_type
> 4) {
468 memcpy(bus
.mpc_bustype
, "PCI ", 6);
472 ioapic
.mpc_type
= MP_IOAPIC
;
473 ioapic
.mpc_apicid
= 2;
474 ioapic
.mpc_apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
475 ioapic
.mpc_flags
= MPC_APIC_USABLE
;
476 ioapic
.mpc_apicaddr
= 0xFEC00000;
477 MP_ioapic_info(&ioapic
);
480 * We set up most of the low 16 IO-APIC pins according to MPS rules.
482 construct_default_ioirq_mptable(mpc_default_type
);
484 lintsrc
.mpc_type
= MP_LINTSRC
;
485 lintsrc
.mpc_irqflag
= 0; /* conforming */
486 lintsrc
.mpc_srcbusid
= 0;
487 lintsrc
.mpc_srcbusirq
= 0;
488 lintsrc
.mpc_destapic
= MP_APIC_ALL
;
489 for (i
= 0; i
< 2; i
++) {
490 lintsrc
.mpc_irqtype
= linttypes
[i
];
491 lintsrc
.mpc_destapiclint
= i
;
492 MP_lintsrc_info(&lintsrc
);
496 static struct intel_mp_floating
*mpf_found
;
499 * Scan the memory blocks for an SMP configuration block.
501 void __init
get_smp_config (void)
503 struct intel_mp_floating
*mpf
= mpf_found
;
506 * ACPI may be used to obtain the entire SMP configuration or just to
507 * enumerate/configure processors (CONFIG_ACPI_BOOT). Note that
508 * ACPI supports both logical (e.g. Hyper-Threading) and physical
509 * processors, where MPS only supports physical.
511 if (acpi_lapic
&& acpi_ioapic
) {
512 printk(KERN_INFO
"Using ACPI (MADT) for SMP configuration information\n");
516 printk(KERN_INFO
"Using ACPI for processor (LAPIC) configuration information\n");
518 printk("Intel MultiProcessor Specification v1.%d\n", mpf
->mpf_specification
);
519 if (mpf
->mpf_feature2
& (1<<7)) {
520 printk(KERN_INFO
" IMCR and PIC compatibility mode.\n");
523 printk(KERN_INFO
" Virtual Wire compatibility mode.\n");
528 * Now see if we need to read further.
530 if (mpf
->mpf_feature1
!= 0) {
532 printk(KERN_INFO
"Default MP configuration #%d\n", mpf
->mpf_feature1
);
533 construct_default_ISA_mptable(mpf
->mpf_feature1
);
535 } else if (mpf
->mpf_physptr
) {
538 * Read the physical hardware table. Anything here will
539 * override the defaults.
541 if (!smp_read_mpc((void *)(unsigned long)mpf
->mpf_physptr
)) {
542 smp_found_config
= 0;
543 printk(KERN_ERR
"BIOS bug, MP table errors detected!...\n");
544 printk(KERN_ERR
"... disabling SMP support. (tell your hw vendor)\n");
548 * If there are no explicit MP IRQ entries, then we are
549 * broken. We set up most of the low 16 IO-APIC pins to
550 * ISA defaults and hope it will work.
552 if (!mp_irq_entries
) {
553 struct mpc_config_bus bus
;
555 printk(KERN_ERR
"BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
557 bus
.mpc_type
= MP_BUS
;
559 memcpy(bus
.mpc_bustype
, "ISA ", 6);
562 construct_default_ioirq_mptable(0);
568 printk(KERN_INFO
"Processors: %d\n", num_processors
);
570 * Only use the first configuration found.
574 static int __init
smp_scan_config (unsigned long base
, unsigned long length
)
576 extern void __bad_mpf_size(void);
577 unsigned int *bp
= phys_to_virt(base
);
578 struct intel_mp_floating
*mpf
;
580 Dprintk("Scan SMP from %p for %ld bytes.\n", bp
,length
);
581 if (sizeof(*mpf
) != 16)
585 mpf
= (struct intel_mp_floating
*)bp
;
586 if ((*bp
== SMP_MAGIC_IDENT
) &&
587 (mpf
->mpf_length
== 1) &&
588 !mpf_checksum((unsigned char *)bp
, 16) &&
589 ((mpf
->mpf_specification
== 1)
590 || (mpf
->mpf_specification
== 4)) ) {
592 smp_found_config
= 1;
593 reserve_bootmem_generic(virt_to_phys(mpf
), PAGE_SIZE
);
594 if (mpf
->mpf_physptr
)
595 reserve_bootmem_generic(mpf
->mpf_physptr
, PAGE_SIZE
);
605 void __init
find_intel_smp (void)
607 unsigned int address
;
610 * FIXME: Linux assumes you have 640K of base ram..
611 * this continues the error...
613 * 1) Scan the bottom 1K for a signature
614 * 2) Scan the top 1K of base RAM
615 * 3) Scan the 64K of bios
617 if (smp_scan_config(0x0,0x400) ||
618 smp_scan_config(639*0x400,0x400) ||
619 smp_scan_config(0xF0000,0x10000))
622 * If it is an SMP machine we should know now, unless the
623 * configuration is in an EISA/MCA bus machine with an
624 * extended bios data area.
626 * there is a real-mode segmented pointer pointing to the
627 * 4K EBDA area at 0x40E, calculate and scan it here.
629 * NOTE! There are Linux loaders that will corrupt the EBDA
630 * area, and as such this kind of SMP config may be less
631 * trustworthy, simply because the SMP table may have been
632 * stomped on during early boot. These loaders are buggy and
636 address
= *(unsigned short *)phys_to_virt(0x40E);
638 if (smp_scan_config(address
, 0x1000))
641 /* If we have come this far, we did not find an MP table */
642 printk(KERN_INFO
"No mptable found.\n");
646 * - Intel MP Configuration Table
648 void __init
find_smp_config (void)
650 #ifdef CONFIG_X86_LOCAL_APIC
656 /* --------------------------------------------------------------------------
657 ACPI-based MP Configuration
658 -------------------------------------------------------------------------- */
660 #ifdef CONFIG_ACPI_BOOT
662 void __init
mp_register_lapic_address (
665 mp_lapic_addr
= (unsigned long) address
;
667 set_fixmap_nocache(FIX_APIC_BASE
, mp_lapic_addr
);
669 if (boot_cpu_id
== -1U)
670 boot_cpu_id
= GET_APIC_ID(apic_read(APIC_ID
));
672 Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid
);
676 void __init
mp_register_lapic (
680 struct mpc_config_processor processor
;
683 if (id
>= MAX_APICS
) {
684 printk(KERN_WARNING
"Processor #%d invalid (max %d)\n",
689 if (id
== boot_cpu_physical_apicid
)
692 processor
.mpc_type
= MP_PROCESSOR
;
693 processor
.mpc_apicid
= id
;
694 processor
.mpc_apicver
= 0x10; /* TBD: lapic version */
695 processor
.mpc_cpuflag
= (enabled
? CPU_ENABLED
: 0);
696 processor
.mpc_cpuflag
|= (boot_cpu
? CPU_BOOTPROCESSOR
: 0);
697 processor
.mpc_cpufeature
= (boot_cpu_data
.x86
<< 8) |
698 (boot_cpu_data
.x86_model
<< 4) | boot_cpu_data
.x86_mask
;
699 processor
.mpc_featureflag
= boot_cpu_data
.x86_capability
[0];
700 processor
.mpc_reserved
[0] = 0;
701 processor
.mpc_reserved
[1] = 0;
703 MP_processor_info(&processor
);
706 #ifdef CONFIG_X86_IO_APIC
709 #define MP_MAX_IOAPIC_PIN 127
711 static struct mp_ioapic_routing
{
715 u32 pin_programmed
[4];
716 } mp_ioapic_routing
[MAX_IO_APICS
];
719 static int mp_find_ioapic (
724 /* Find the IOAPIC that manages this GSI. */
725 for (i
= 0; i
< nr_ioapics
; i
++) {
726 if ((gsi
>= mp_ioapic_routing
[i
].gsi_start
)
727 && (gsi
<= mp_ioapic_routing
[i
].gsi_end
))
731 printk(KERN_ERR
"ERROR: Unable to locate IOAPIC for GSI %d\n", gsi
);
737 void __init
mp_register_ioapic (
744 if (nr_ioapics
>= MAX_IO_APICS
) {
745 printk(KERN_ERR
"ERROR: Max # of I/O APICs (%d) exceeded "
746 "(found %d)\n", MAX_IO_APICS
, nr_ioapics
);
747 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
750 printk(KERN_ERR
"WARNING: Bogus (zero) I/O APIC address"
751 " found in MADT table, skipping!\n");
757 mp_ioapics
[idx
].mpc_type
= MP_IOAPIC
;
758 mp_ioapics
[idx
].mpc_flags
= MPC_APIC_USABLE
;
759 mp_ioapics
[idx
].mpc_apicaddr
= address
;
761 set_fixmap_nocache(FIX_IO_APIC_BASE_0
+ idx
, address
);
762 mp_ioapics
[idx
].mpc_apicid
= io_apic_get_unique_id(idx
, id
);
763 mp_ioapics
[idx
].mpc_apicver
= io_apic_get_version(idx
);
766 * Build basic IRQ lookup table to facilitate gsi->io_apic lookups
767 * and to prevent reprogramming of IOAPIC pins (PCI IRQs).
769 mp_ioapic_routing
[idx
].apic_id
= mp_ioapics
[idx
].mpc_apicid
;
770 mp_ioapic_routing
[idx
].gsi_start
= gsi_base
;
771 mp_ioapic_routing
[idx
].gsi_end
= gsi_base
+
772 io_apic_get_redir_entries(idx
);
774 printk(KERN_INFO
"IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
775 "GSI %d-%d\n", idx
, mp_ioapics
[idx
].mpc_apicid
,
776 mp_ioapics
[idx
].mpc_apicver
, mp_ioapics
[idx
].mpc_apicaddr
,
777 mp_ioapic_routing
[idx
].gsi_start
,
778 mp_ioapic_routing
[idx
].gsi_end
);
784 void __init
mp_override_legacy_irq (
790 struct mpc_config_intsrc intsrc
;
795 * Convert 'gsi' to 'ioapic.pin'.
797 ioapic
= mp_find_ioapic(gsi
);
800 pin
= gsi
- mp_ioapic_routing
[ioapic
].gsi_start
;
803 * TBD: This check is for faulty timer entries, where the override
804 * erroneously sets the trigger to level, resulting in a HUGE
805 * increase of timer interrupts!
807 if ((bus_irq
== 0) && (trigger
== 3))
810 intsrc
.mpc_type
= MP_INTSRC
;
811 intsrc
.mpc_irqtype
= mp_INT
;
812 intsrc
.mpc_irqflag
= (trigger
<< 2) | polarity
;
813 intsrc
.mpc_srcbus
= MP_ISA_BUS
;
814 intsrc
.mpc_srcbusirq
= bus_irq
; /* IRQ */
815 intsrc
.mpc_dstapic
= mp_ioapics
[ioapic
].mpc_apicid
; /* APIC ID */
816 intsrc
.mpc_dstirq
= pin
; /* INTIN# */
818 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
819 intsrc
.mpc_irqtype
, intsrc
.mpc_irqflag
& 3,
820 (intsrc
.mpc_irqflag
>> 2) & 3, intsrc
.mpc_srcbus
,
821 intsrc
.mpc_srcbusirq
, intsrc
.mpc_dstapic
, intsrc
.mpc_dstirq
);
823 mp_irqs
[mp_irq_entries
] = intsrc
;
824 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
825 panic("Max # of irq sources exceeded!\n");
831 void __init
mp_config_acpi_legacy_irqs (void)
833 struct mpc_config_intsrc intsrc
;
838 * Fabricate the legacy ISA bus (bus #31).
840 mp_bus_id_to_type
[MP_ISA_BUS
] = MP_BUS_ISA
;
841 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS
);
844 * Locate the IOAPIC that manages the ISA IRQs (0-15).
846 ioapic
= mp_find_ioapic(0);
850 intsrc
.mpc_type
= MP_INTSRC
;
851 intsrc
.mpc_irqflag
= 0; /* Conforming */
852 intsrc
.mpc_srcbus
= MP_ISA_BUS
;
853 intsrc
.mpc_dstapic
= mp_ioapics
[ioapic
].mpc_apicid
;
856 * Use the default configuration for the IRQs 0-15. Unless
857 * overridden by (MADT) interrupt source override entries.
859 for (i
= 0; i
< 16; i
++) {
862 for (idx
= 0; idx
< mp_irq_entries
; idx
++) {
863 struct mpc_config_intsrc
*irq
= mp_irqs
+ idx
;
865 /* Do we already have a mapping for this ISA IRQ? */
866 if (irq
->mpc_srcbus
== MP_ISA_BUS
&& irq
->mpc_srcbusirq
== i
)
869 /* Do we already have a mapping for this IOAPIC pin */
870 if ((irq
->mpc_dstapic
== intsrc
.mpc_dstapic
) &&
871 (irq
->mpc_dstirq
== i
))
875 if (idx
!= mp_irq_entries
) {
876 printk(KERN_DEBUG
"ACPI: IRQ%d used by override.\n", i
);
877 continue; /* IRQ already used */
880 intsrc
.mpc_irqtype
= mp_INT
;
881 intsrc
.mpc_srcbusirq
= i
; /* Identity mapped */
882 intsrc
.mpc_dstirq
= i
;
884 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
885 "%d-%d\n", intsrc
.mpc_irqtype
, intsrc
.mpc_irqflag
& 3,
886 (intsrc
.mpc_irqflag
>> 2) & 3, intsrc
.mpc_srcbus
,
887 intsrc
.mpc_srcbusirq
, intsrc
.mpc_dstapic
,
890 mp_irqs
[mp_irq_entries
] = intsrc
;
891 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
892 panic("Max # of irq sources exceeded!\n");
898 int mp_register_gsi(u32 gsi
, int edge_level
, int active_high_low
)
904 if (acpi_irq_model
!= ACPI_IRQ_MODEL_IOAPIC
)
907 #ifdef CONFIG_ACPI_BUS
908 /* Don't set up the ACPI SCI because it's already set up */
909 if (acpi_fadt
.sci_int
== gsi
)
913 ioapic
= mp_find_ioapic(gsi
);
915 printk(KERN_WARNING
"No IOAPIC for GSI %u\n", gsi
);
919 ioapic_pin
= gsi
- mp_ioapic_routing
[ioapic
].gsi_start
;
922 * Avoid pin reprogramming. PRTs typically include entries
923 * with redundant pin->gsi mappings (but unique PCI devices);
924 * we only program the IOAPIC on the first.
926 bit
= ioapic_pin
% 32;
927 idx
= (ioapic_pin
< 32) ? 0 : (ioapic_pin
/ 32);
929 printk(KERN_ERR
"Invalid reference to IOAPIC pin "
930 "%d-%d\n", mp_ioapic_routing
[ioapic
].apic_id
,
934 if ((1<<bit
) & mp_ioapic_routing
[ioapic
].pin_programmed
[idx
]) {
935 Dprintk(KERN_DEBUG
"Pin %d-%d already programmed\n",
936 mp_ioapic_routing
[ioapic
].apic_id
, ioapic_pin
);
940 mp_ioapic_routing
[ioapic
].pin_programmed
[idx
] |= (1<<bit
);
942 io_apic_set_pci_routing(ioapic
, ioapic_pin
, gsi
,
943 edge_level
== ACPI_EDGE_SENSITIVE
? 0 : 1,
944 active_high_low
== ACPI_ACTIVE_HIGH
? 0 : 1);
948 #endif /*CONFIG_X86_IO_APIC*/
949 #endif /*CONFIG_ACPI_BOOT*/