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/init.h>
18 #include <linux/delay.h>
19 #include <linux/bootmem.h>
20 #include <linux/smp_lock.h>
21 #include <linux/kernel_stat.h>
22 #include <linux/mc146818rtc.h>
23 #include <linux/acpi.h>
24 #include <linux/module.h>
28 #include <asm/mpspec.h>
29 #include <asm/pgalloc.h>
30 #include <asm/io_apic.h>
31 #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 unsigned char 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 };
48 static int mp_current_pci_id
= 0;
49 /* I/O APIC entries */
50 struct mpc_config_ioapic mp_ioapics
[MAX_IO_APICS
];
52 /* # of MP IRQ source entries */
53 struct mpc_config_intsrc mp_irqs
[MAX_IRQ_SOURCES
];
55 /* MP IRQ source entries */
60 unsigned long mp_lapic_addr
= 0;
64 /* Processor that is doing the boot up */
65 unsigned int boot_cpu_id
= -1U;
66 /* Internal processor count */
67 unsigned int num_processors __initdata
= 0;
69 unsigned disabled_cpus __initdata
;
71 /* Bitmask of physically existing CPUs */
72 physid_mask_t phys_cpu_present_map
= PHYSID_MASK_NONE
;
74 /* ACPI MADT entry parsing functions */
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*/
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 __cpuinit
MP_processor_info (struct mpc_config_processor
*m
)
114 if (!(m
->mpc_cpuflag
& CPU_ENABLED
)) {
119 printk(KERN_INFO
"Processor #%d %d:%d APIC version %d\n",
121 (m
->mpc_cpufeature
& CPU_FAMILY_MASK
)>>8,
122 (m
->mpc_cpufeature
& CPU_MODEL_MASK
)>>4,
125 if (m
->mpc_cpuflag
& CPU_BOOTPROCESSOR
) {
126 Dprintk(" Bootup CPU\n");
127 boot_cpu_id
= m
->mpc_apicid
;
129 if (num_processors
>= NR_CPUS
) {
130 printk(KERN_WARNING
"WARNING: NR_CPUS limit of %i reached."
131 " Processor ignored.\n", NR_CPUS
);
136 cpus_complement(tmp_map
, cpu_present_map
);
137 cpu
= first_cpu(tmp_map
);
140 if ((int)m
->mpc_apicid
> MAX_APICS
) {
141 printk(KERN_ERR
"Processor #%d INVALID. (Max ID: %d).\n",
142 m
->mpc_apicid
, MAX_APICS
);
146 ver
= m
->mpc_apicver
;
148 physid_set(m
->mpc_apicid
, phys_cpu_present_map
);
153 printk(KERN_ERR
"BIOS bug, APIC version is 0 for CPU#%d! fixing up to 0x10. (tell your hw vendor)\n", m
->mpc_apicid
);
156 apic_version
[m
->mpc_apicid
] = ver
;
157 if (m
->mpc_cpuflag
& CPU_BOOTPROCESSOR
) {
159 * bios_cpu_apicid is required to have processors listed
160 * in same order as logical cpu numbers. Hence the first
161 * entry is BSP, and so on.
165 bios_cpu_apicid
[cpu
] = m
->mpc_apicid
;
166 x86_cpu_to_apicid
[cpu
] = m
->mpc_apicid
;
168 cpu_set(cpu
, cpu_possible_map
);
169 cpu_set(cpu
, cpu_present_map
);
172 static void __init
MP_bus_info (struct mpc_config_bus
*m
)
176 memcpy(str
, m
->mpc_bustype
, 6);
178 Dprintk("Bus #%d is %s\n", m
->mpc_busid
, str
);
180 if (strncmp(str
, "ISA", 3) == 0) {
181 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_ISA
;
182 } else if (strncmp(str
, "EISA", 4) == 0) {
183 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_EISA
;
184 } else if (strncmp(str
, "PCI", 3) == 0) {
185 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_PCI
;
186 mp_bus_id_to_pci_bus
[m
->mpc_busid
] = mp_current_pci_id
;
188 } else if (strncmp(str
, "MCA", 3) == 0) {
189 mp_bus_id_to_type
[m
->mpc_busid
] = MP_BUS_MCA
;
191 printk(KERN_ERR
"Unknown bustype %s\n", str
);
195 static void __init
MP_ioapic_info (struct mpc_config_ioapic
*m
)
197 if (!(m
->mpc_flags
& MPC_APIC_USABLE
))
200 printk("I/O APIC #%d Version %d at 0x%X.\n",
201 m
->mpc_apicid
, m
->mpc_apicver
, m
->mpc_apicaddr
);
202 if (nr_ioapics
>= MAX_IO_APICS
) {
203 printk(KERN_ERR
"Max # of I/O APICs (%d) exceeded (found %d).\n",
204 MAX_IO_APICS
, nr_ioapics
);
205 panic("Recompile kernel with bigger MAX_IO_APICS!.\n");
207 if (!m
->mpc_apicaddr
) {
208 printk(KERN_ERR
"WARNING: bogus zero I/O APIC address"
209 " found in MP table, skipping!\n");
212 mp_ioapics
[nr_ioapics
] = *m
;
216 static void __init
MP_intsrc_info (struct mpc_config_intsrc
*m
)
218 mp_irqs
[mp_irq_entries
] = *m
;
219 Dprintk("Int: type %d, pol %d, trig %d, bus %d,"
220 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
221 m
->mpc_irqtype
, m
->mpc_irqflag
& 3,
222 (m
->mpc_irqflag
>> 2) & 3, m
->mpc_srcbus
,
223 m
->mpc_srcbusirq
, m
->mpc_dstapic
, m
->mpc_dstirq
);
224 if (++mp_irq_entries
>= MAX_IRQ_SOURCES
)
225 panic("Max # of irq sources exceeded!!\n");
228 static void __init
MP_lintsrc_info (struct mpc_config_lintsrc
*m
)
230 Dprintk("Lint: type %d, pol %d, trig %d, bus %d,"
231 " IRQ %02x, APIC ID %x, APIC LINT %02x\n",
232 m
->mpc_irqtype
, m
->mpc_irqflag
& 3,
233 (m
->mpc_irqflag
>> 2) &3, m
->mpc_srcbusid
,
234 m
->mpc_srcbusirq
, m
->mpc_destapic
, m
->mpc_destapiclint
);
236 * Well it seems all SMP boards in existence
237 * use ExtINT/LVT1 == LINT0 and
238 * NMI/LVT2 == LINT1 - the following check
239 * will show us if this assumptions is false.
240 * Until then we do not have to add baggage.
242 if ((m
->mpc_irqtype
== mp_ExtINT
) &&
243 (m
->mpc_destapiclint
!= 0))
245 if ((m
->mpc_irqtype
== mp_NMI
) &&
246 (m
->mpc_destapiclint
!= 1))
254 static int __init
smp_read_mpc(struct mp_config_table
*mpc
)
257 int count
=sizeof(*mpc
);
258 unsigned char *mpt
=((unsigned char *)mpc
)+count
;
260 if (memcmp(mpc
->mpc_signature
,MPC_SIGNATURE
,4)) {
261 printk("SMP mptable: bad signature [%c%c%c%c]!\n",
262 mpc
->mpc_signature
[0],
263 mpc
->mpc_signature
[1],
264 mpc
->mpc_signature
[2],
265 mpc
->mpc_signature
[3]);
268 if (mpf_checksum((unsigned char *)mpc
,mpc
->mpc_length
)) {
269 printk("SMP mptable: checksum error!\n");
272 if (mpc
->mpc_spec
!=0x01 && mpc
->mpc_spec
!=0x04) {
273 printk(KERN_ERR
"SMP mptable: bad table version (%d)!!\n",
277 if (!mpc
->mpc_lapic
) {
278 printk(KERN_ERR
"SMP mptable: null local APIC address!\n");
281 memcpy(str
,mpc
->mpc_oem
,8);
283 printk(KERN_INFO
"OEM ID: %s ",str
);
285 memcpy(str
,mpc
->mpc_productid
,12);
287 printk("Product ID: %s ",str
);
289 printk("APIC at: 0x%X\n",mpc
->mpc_lapic
);
291 /* save the local APIC address, it might be non-default */
293 mp_lapic_addr
= mpc
->mpc_lapic
;
296 * Now process the configuration blocks.
298 while (count
< mpc
->mpc_length
) {
302 struct mpc_config_processor
*m
=
303 (struct mpc_config_processor
*)mpt
;
305 MP_processor_info(m
);
312 struct mpc_config_bus
*m
=
313 (struct mpc_config_bus
*)mpt
;
321 struct mpc_config_ioapic
*m
=
322 (struct mpc_config_ioapic
*)mpt
;
330 struct mpc_config_intsrc
*m
=
331 (struct mpc_config_intsrc
*)mpt
;
340 struct mpc_config_lintsrc
*m
=
341 (struct mpc_config_lintsrc
*)mpt
;
349 clustered_apic_check();
351 printk(KERN_ERR
"SMP mptable: no processors registered!\n");
352 return num_processors
;
355 static int __init
ELCR_trigger(unsigned int irq
)
359 port
= 0x4d0 + (irq
>> 3);
360 return (inb(port
) >> (irq
& 7)) & 1;
363 static void __init
construct_default_ioirq_mptable(int mpc_default_type
)
365 struct mpc_config_intsrc intsrc
;
367 int ELCR_fallback
= 0;
369 intsrc
.mpc_type
= MP_INTSRC
;
370 intsrc
.mpc_irqflag
= 0; /* conforming */
371 intsrc
.mpc_srcbus
= 0;
372 intsrc
.mpc_dstapic
= mp_ioapics
[0].mpc_apicid
;
374 intsrc
.mpc_irqtype
= mp_INT
;
377 * If true, we have an ISA/PCI system with no IRQ entries
378 * in the MP table. To prevent the PCI interrupts from being set up
379 * incorrectly, we try to use the ELCR. The sanity check to see if
380 * there is good ELCR data is very simple - IRQ0, 1, 2 and 13 can
381 * never be level sensitive, so we simply see if the ELCR agrees.
382 * If it does, we assume it's valid.
384 if (mpc_default_type
== 5) {
385 printk(KERN_INFO
"ISA/PCI bus type with no IRQ information... falling back to ELCR\n");
387 if (ELCR_trigger(0) || ELCR_trigger(1) || ELCR_trigger(2) || ELCR_trigger(13))
388 printk(KERN_ERR
"ELCR contains invalid data... not using ELCR\n");
390 printk(KERN_INFO
"Using ELCR to identify PCI interrupts\n");
395 for (i
= 0; i
< 16; i
++) {
396 switch (mpc_default_type
) {
398 if (i
== 0 || i
== 13)
399 continue; /* IRQ0 & IRQ13 not connected */
403 continue; /* IRQ2 is never connected */
408 * If the ELCR indicates a level-sensitive interrupt, we
409 * copy that information over to the MP table in the
410 * irqflag field (level sensitive, active high polarity).
413 intsrc
.mpc_irqflag
= 13;
415 intsrc
.mpc_irqflag
= 0;
418 intsrc
.mpc_srcbusirq
= i
;
419 intsrc
.mpc_dstirq
= i
? i
: 2; /* IRQ0 to INTIN2 */
420 MP_intsrc_info(&intsrc
);
423 intsrc
.mpc_irqtype
= mp_ExtINT
;
424 intsrc
.mpc_srcbusirq
= 0;
425 intsrc
.mpc_dstirq
= 0; /* 8259A to INTIN0 */
426 MP_intsrc_info(&intsrc
);
429 static inline void __init
construct_default_ISA_mptable(int mpc_default_type
)
431 struct mpc_config_processor processor
;
432 struct mpc_config_bus bus
;
433 struct mpc_config_ioapic ioapic
;
434 struct mpc_config_lintsrc lintsrc
;
435 int linttypes
[2] = { mp_ExtINT
, mp_NMI
};
439 * local APIC has default address
441 mp_lapic_addr
= APIC_DEFAULT_PHYS_BASE
;
444 * 2 CPUs, numbered 0 & 1.
446 processor
.mpc_type
= MP_PROCESSOR
;
447 /* Either an integrated APIC or a discrete 82489DX. */
448 processor
.mpc_apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
449 processor
.mpc_cpuflag
= CPU_ENABLED
;
450 processor
.mpc_cpufeature
= (boot_cpu_data
.x86
<< 8) |
451 (boot_cpu_data
.x86_model
<< 4) |
452 boot_cpu_data
.x86_mask
;
453 processor
.mpc_featureflag
= boot_cpu_data
.x86_capability
[0];
454 processor
.mpc_reserved
[0] = 0;
455 processor
.mpc_reserved
[1] = 0;
456 for (i
= 0; i
< 2; i
++) {
457 processor
.mpc_apicid
= i
;
458 MP_processor_info(&processor
);
461 bus
.mpc_type
= MP_BUS
;
463 switch (mpc_default_type
) {
465 printk(KERN_ERR
"???\nUnknown standard configuration %d\n",
470 memcpy(bus
.mpc_bustype
, "ISA ", 6);
475 memcpy(bus
.mpc_bustype
, "EISA ", 6);
479 memcpy(bus
.mpc_bustype
, "MCA ", 6);
482 if (mpc_default_type
> 4) {
484 memcpy(bus
.mpc_bustype
, "PCI ", 6);
488 ioapic
.mpc_type
= MP_IOAPIC
;
489 ioapic
.mpc_apicid
= 2;
490 ioapic
.mpc_apicver
= mpc_default_type
> 4 ? 0x10 : 0x01;
491 ioapic
.mpc_flags
= MPC_APIC_USABLE
;
492 ioapic
.mpc_apicaddr
= 0xFEC00000;
493 MP_ioapic_info(&ioapic
);
496 * We set up most of the low 16 IO-APIC pins according to MPS rules.
498 construct_default_ioirq_mptable(mpc_default_type
);
500 lintsrc
.mpc_type
= MP_LINTSRC
;
501 lintsrc
.mpc_irqflag
= 0; /* conforming */
502 lintsrc
.mpc_srcbusid
= 0;
503 lintsrc
.mpc_srcbusirq
= 0;
504 lintsrc
.mpc_destapic
= MP_APIC_ALL
;
505 for (i
= 0; i
< 2; i
++) {
506 lintsrc
.mpc_irqtype
= linttypes
[i
];
507 lintsrc
.mpc_destapiclint
= i
;
508 MP_lintsrc_info(&lintsrc
);
512 static struct intel_mp_floating
*mpf_found
;
515 * Scan the memory blocks for an SMP configuration block.
517 void __init
get_smp_config (void)
519 struct intel_mp_floating
*mpf
= mpf_found
;
522 * ACPI supports both logical (e.g. Hyper-Threading) and physical
523 * processors, where MPS only supports physical.
525 if (acpi_lapic
&& acpi_ioapic
) {
526 printk(KERN_INFO
"Using ACPI (MADT) for SMP configuration information\n");
530 printk(KERN_INFO
"Using ACPI for processor (LAPIC) configuration information\n");
532 printk("Intel MultiProcessor Specification v1.%d\n", mpf
->mpf_specification
);
533 if (mpf
->mpf_feature2
& (1<<7)) {
534 printk(KERN_INFO
" IMCR and PIC compatibility mode.\n");
537 printk(KERN_INFO
" Virtual Wire compatibility mode.\n");
542 * Now see if we need to read further.
544 if (mpf
->mpf_feature1
!= 0) {
546 printk(KERN_INFO
"Default MP configuration #%d\n", mpf
->mpf_feature1
);
547 construct_default_ISA_mptable(mpf
->mpf_feature1
);
549 } else if (mpf
->mpf_physptr
) {
552 * Read the physical hardware table. Anything here will
553 * override the defaults.
555 if (!smp_read_mpc(phys_to_virt(mpf
->mpf_physptr
))) {
556 smp_found_config
= 0;
557 printk(KERN_ERR
"BIOS bug, MP table errors detected!...\n");
558 printk(KERN_ERR
"... disabling SMP support. (tell your hw vendor)\n");
562 * If there are no explicit MP IRQ entries, then we are
563 * broken. We set up most of the low 16 IO-APIC pins to
564 * ISA defaults and hope it will work.
566 if (!mp_irq_entries
) {
567 struct mpc_config_bus bus
;
569 printk(KERN_ERR
"BIOS bug, no explicit IRQ entries, using default mptable. (tell your hw vendor)\n");
571 bus
.mpc_type
= MP_BUS
;
573 memcpy(bus
.mpc_bustype
, "ISA ", 6);
576 construct_default_ioirq_mptable(0);
582 printk(KERN_INFO
"Processors: %d\n", num_processors
);
584 * Only use the first configuration found.
588 static int __init
smp_scan_config (unsigned long base
, unsigned long length
)
590 extern void __bad_mpf_size(void);
591 unsigned int *bp
= phys_to_virt(base
);
592 struct intel_mp_floating
*mpf
;
594 Dprintk("Scan SMP from %p for %ld bytes.\n", bp
,length
);
595 if (sizeof(*mpf
) != 16)
599 mpf
= (struct intel_mp_floating
*)bp
;
600 if ((*bp
== SMP_MAGIC_IDENT
) &&
601 (mpf
->mpf_length
== 1) &&
602 !mpf_checksum((unsigned char *)bp
, 16) &&
603 ((mpf
->mpf_specification
== 1)
604 || (mpf
->mpf_specification
== 4)) ) {
606 smp_found_config
= 1;
607 reserve_bootmem_generic(virt_to_phys(mpf
), PAGE_SIZE
);
608 if (mpf
->mpf_physptr
)
609 reserve_bootmem_generic(mpf
->mpf_physptr
, PAGE_SIZE
);
619 void __init
find_intel_smp (void)
621 unsigned int address
;
624 * FIXME: Linux assumes you have 640K of base ram..
625 * this continues the error...
627 * 1) Scan the bottom 1K for a signature
628 * 2) Scan the top 1K of base RAM
629 * 3) Scan the 64K of bios
631 if (smp_scan_config(0x0,0x400) ||
632 smp_scan_config(639*0x400,0x400) ||
633 smp_scan_config(0xF0000,0x10000))
636 * If it is an SMP machine we should know now, unless the
637 * configuration is in an EISA/MCA bus machine with an
638 * extended bios data area.
640 * there is a real-mode segmented pointer pointing to the
641 * 4K EBDA area at 0x40E, calculate and scan it here.
643 * NOTE! There are Linux loaders that will corrupt the EBDA
644 * area, and as such this kind of SMP config may be less
645 * trustworthy, simply because the SMP table may have been
646 * stomped on during early boot. These loaders are buggy and
650 address
= *(unsigned short *)phys_to_virt(0x40E);
652 if (smp_scan_config(address
, 0x1000))
655 /* If we have come this far, we did not find an MP table */
656 printk(KERN_INFO
"No mptable found.\n");
660 * - Intel MP Configuration Table
662 void __init
find_smp_config (void)
664 #ifdef CONFIG_X86_LOCAL_APIC
670 /* --------------------------------------------------------------------------
671 ACPI-based MP Configuration
672 -------------------------------------------------------------------------- */
676 void __init
mp_register_lapic_address (
679 mp_lapic_addr
= (unsigned long) address
;
681 set_fixmap_nocache(FIX_APIC_BASE
, mp_lapic_addr
);
683 if (boot_cpu_id
== -1U)
684 boot_cpu_id
= GET_APIC_ID(apic_read(APIC_ID
));
686 Dprintk("Boot CPU = %d\n", boot_cpu_physical_apicid
);
690 void __cpuinit
mp_register_lapic (
694 struct mpc_config_processor processor
;
697 if (id
>= MAX_APICS
) {
698 printk(KERN_WARNING
"Processor #%d invalid (max %d)\n",
703 if (id
== boot_cpu_physical_apicid
)
706 processor
.mpc_type
= MP_PROCESSOR
;
707 processor
.mpc_apicid
= id
;
708 processor
.mpc_apicver
= GET_APIC_VERSION(apic_read(APIC_LVR
));
709 processor
.mpc_cpuflag
= (enabled
? CPU_ENABLED
: 0);
710 processor
.mpc_cpuflag
|= (boot_cpu
? CPU_BOOTPROCESSOR
: 0);
711 processor
.mpc_cpufeature
= (boot_cpu_data
.x86
<< 8) |
712 (boot_cpu_data
.x86_model
<< 4) | boot_cpu_data
.x86_mask
;
713 processor
.mpc_featureflag
= boot_cpu_data
.x86_capability
[0];
714 processor
.mpc_reserved
[0] = 0;
715 processor
.mpc_reserved
[1] = 0;
717 MP_processor_info(&processor
);
720 #ifdef CONFIG_X86_IO_APIC
723 #define MP_MAX_IOAPIC_PIN 127
725 static struct mp_ioapic_routing
{
729 u32 pin_programmed
[4];
730 } mp_ioapic_routing
[MAX_IO_APICS
];
733 static int mp_find_ioapic (
738 /* Find the IOAPIC that manages this GSI. */
739 for (i
= 0; i
< nr_ioapics
; i
++) {
740 if ((gsi
>= mp_ioapic_routing
[i
].gsi_start
)
741 && (gsi
<= mp_ioapic_routing
[i
].gsi_end
))
745 printk(KERN_ERR
"ERROR: Unable to locate IOAPIC for GSI %d\n", gsi
);
751 void __init
mp_register_ioapic (
758 if (nr_ioapics
>= MAX_IO_APICS
) {
759 printk(KERN_ERR
"ERROR: Max # of I/O APICs (%d) exceeded "
760 "(found %d)\n", MAX_IO_APICS
, nr_ioapics
);
761 panic("Recompile kernel with bigger MAX_IO_APICS!\n");
764 printk(KERN_ERR
"WARNING: Bogus (zero) I/O APIC address"
765 " found in MADT table, skipping!\n");
771 mp_ioapics
[idx
].mpc_type
= MP_IOAPIC
;
772 mp_ioapics
[idx
].mpc_flags
= MPC_APIC_USABLE
;
773 mp_ioapics
[idx
].mpc_apicaddr
= address
;
775 set_fixmap_nocache(FIX_IO_APIC_BASE_0
+ idx
, address
);
776 mp_ioapics
[idx
].mpc_apicid
= id
;
777 mp_ioapics
[idx
].mpc_apicver
= io_apic_get_version(idx
);
780 * Build basic IRQ lookup table to facilitate gsi->io_apic lookups
781 * and to prevent reprogramming of IOAPIC pins (PCI IRQs).
783 mp_ioapic_routing
[idx
].apic_id
= mp_ioapics
[idx
].mpc_apicid
;
784 mp_ioapic_routing
[idx
].gsi_start
= gsi_base
;
785 mp_ioapic_routing
[idx
].gsi_end
= gsi_base
+
786 io_apic_get_redir_entries(idx
);
788 printk(KERN_INFO
"IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
789 "GSI %d-%d\n", idx
, mp_ioapics
[idx
].mpc_apicid
,
790 mp_ioapics
[idx
].mpc_apicver
, mp_ioapics
[idx
].mpc_apicaddr
,
791 mp_ioapic_routing
[idx
].gsi_start
,
792 mp_ioapic_routing
[idx
].gsi_end
);
798 void __init
mp_override_legacy_irq (
804 struct mpc_config_intsrc intsrc
;
809 * Convert 'gsi' to 'ioapic.pin'.
811 ioapic
= mp_find_ioapic(gsi
);
814 pin
= gsi
- mp_ioapic_routing
[ioapic
].gsi_start
;
817 * TBD: This check is for faulty timer entries, where the override
818 * erroneously sets the trigger to level, resulting in a HUGE
819 * increase of timer interrupts!
821 if ((bus_irq
== 0) && (trigger
== 3))
824 intsrc
.mpc_type
= MP_INTSRC
;
825 intsrc
.mpc_irqtype
= mp_INT
;
826 intsrc
.mpc_irqflag
= (trigger
<< 2) | polarity
;
827 intsrc
.mpc_srcbus
= MP_ISA_BUS
;
828 intsrc
.mpc_srcbusirq
= bus_irq
; /* IRQ */
829 intsrc
.mpc_dstapic
= mp_ioapics
[ioapic
].mpc_apicid
; /* APIC ID */
830 intsrc
.mpc_dstirq
= pin
; /* INTIN# */
832 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n",
833 intsrc
.mpc_irqtype
, intsrc
.mpc_irqflag
& 3,
834 (intsrc
.mpc_irqflag
>> 2) & 3, intsrc
.mpc_srcbus
,
835 intsrc
.mpc_srcbusirq
, intsrc
.mpc_dstapic
, intsrc
.mpc_dstirq
);
837 mp_irqs
[mp_irq_entries
] = intsrc
;
838 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
839 panic("Max # of irq sources exceeded!\n");
845 void __init
mp_config_acpi_legacy_irqs (void)
847 struct mpc_config_intsrc intsrc
;
852 * Fabricate the legacy ISA bus (bus #31).
854 mp_bus_id_to_type
[MP_ISA_BUS
] = MP_BUS_ISA
;
855 Dprintk("Bus #%d is ISA\n", MP_ISA_BUS
);
858 * Locate the IOAPIC that manages the ISA IRQs (0-15).
860 ioapic
= mp_find_ioapic(0);
864 intsrc
.mpc_type
= MP_INTSRC
;
865 intsrc
.mpc_irqflag
= 0; /* Conforming */
866 intsrc
.mpc_srcbus
= MP_ISA_BUS
;
867 intsrc
.mpc_dstapic
= mp_ioapics
[ioapic
].mpc_apicid
;
870 * Use the default configuration for the IRQs 0-15. Unless
871 * overridden by (MADT) interrupt source override entries.
873 for (i
= 0; i
< 16; i
++) {
876 for (idx
= 0; idx
< mp_irq_entries
; idx
++) {
877 struct mpc_config_intsrc
*irq
= mp_irqs
+ idx
;
879 /* Do we already have a mapping for this ISA IRQ? */
880 if (irq
->mpc_srcbus
== MP_ISA_BUS
&& irq
->mpc_srcbusirq
== i
)
883 /* Do we already have a mapping for this IOAPIC pin */
884 if ((irq
->mpc_dstapic
== intsrc
.mpc_dstapic
) &&
885 (irq
->mpc_dstirq
== i
))
889 if (idx
!= mp_irq_entries
) {
890 printk(KERN_DEBUG
"ACPI: IRQ%d used by override.\n", i
);
891 continue; /* IRQ already used */
894 intsrc
.mpc_irqtype
= mp_INT
;
895 intsrc
.mpc_srcbusirq
= i
; /* Identity mapped */
896 intsrc
.mpc_dstirq
= i
;
898 Dprintk("Int: type %d, pol %d, trig %d, bus %d, irq %d, "
899 "%d-%d\n", intsrc
.mpc_irqtype
, intsrc
.mpc_irqflag
& 3,
900 (intsrc
.mpc_irqflag
>> 2) & 3, intsrc
.mpc_srcbus
,
901 intsrc
.mpc_srcbusirq
, intsrc
.mpc_dstapic
,
904 mp_irqs
[mp_irq_entries
] = intsrc
;
905 if (++mp_irq_entries
== MAX_IRQ_SOURCES
)
906 panic("Max # of irq sources exceeded!\n");
912 #define MAX_GSI_NUM 4096
914 int mp_register_gsi(u32 gsi
, int triggering
, int polarity
)
919 static int pci_irq
= 16;
921 * Mapping between Global System Interrupts, which
922 * represent all possible interrupts, to the IRQs
923 * assigned to actual devices.
925 static int gsi_to_irq
[MAX_GSI_NUM
];
927 if (acpi_irq_model
!= ACPI_IRQ_MODEL_IOAPIC
)
930 /* Don't set up the ACPI SCI because it's already set up */
931 if (acpi_fadt
.sci_int
== gsi
)
934 ioapic
= mp_find_ioapic(gsi
);
936 printk(KERN_WARNING
"No IOAPIC for GSI %u\n", gsi
);
940 ioapic_pin
= gsi
- mp_ioapic_routing
[ioapic
].gsi_start
;
943 * Avoid pin reprogramming. PRTs typically include entries
944 * with redundant pin->gsi mappings (but unique PCI devices);
945 * we only program the IOAPIC on the first.
947 bit
= ioapic_pin
% 32;
948 idx
= (ioapic_pin
< 32) ? 0 : (ioapic_pin
/ 32);
950 printk(KERN_ERR
"Invalid reference to IOAPIC pin "
951 "%d-%d\n", mp_ioapic_routing
[ioapic
].apic_id
,
955 if ((1<<bit
) & mp_ioapic_routing
[ioapic
].pin_programmed
[idx
]) {
956 Dprintk(KERN_DEBUG
"Pin %d-%d already programmed\n",
957 mp_ioapic_routing
[ioapic
].apic_id
, ioapic_pin
);
958 return gsi_to_irq
[gsi
];
961 mp_ioapic_routing
[ioapic
].pin_programmed
[idx
] |= (1<<bit
);
963 if (triggering
== ACPI_LEVEL_SENSITIVE
) {
965 * For PCI devices assign IRQs in order, avoiding gaps
966 * due to unused I/O APIC pins.
969 if (gsi
< MAX_GSI_NUM
) {
971 * Retain the VIA chipset work-around (gsi > 15), but
972 * avoid a problem where the 8254 timer (IRQ0) is setup
973 * via an override (so it's not on pin 0 of the ioapic),
974 * and at the same time, the pin 0 interrupt is a PCI
975 * type. The gsi > 15 test could cause these two pins
976 * to be shared as IRQ0, and they are not shareable.
977 * So test for this condition, and if necessary, avoid
980 if (gsi
> 15 || (gsi
== 0 && !timer_uses_ioapic_pin_0
))
983 * Don't assign IRQ used by ACPI SCI
985 if (gsi
== acpi_fadt
.sci_int
)
987 gsi_to_irq
[irq
] = gsi
;
989 printk(KERN_ERR
"GSI %u is too high\n", gsi
);
994 io_apic_set_pci_routing(ioapic
, ioapic_pin
, gsi
,
995 triggering
== ACPI_EDGE_SENSITIVE
? 0 : 1,
996 polarity
== ACPI_ACTIVE_HIGH
? 0 : 1);
1000 #endif /*CONFIG_X86_IO_APIC*/
1001 #endif /*CONFIG_ACPI*/