Page 1 of 1
Question on APIC
Posted: Wed Jul 05, 2006 12:31 am
by Cody
Hi, All
Recently I read a post here about APIC and someone said that PCI Interrupt line must be connnected to IOAPIC 16~24 and save 0~15 for Legacy ISA IRQ uses. Is that a must? And I know in PIC mode, PCI Interrupt line is mapped to one of the IRQ free interrupt. So in APIC mode, shall I program PCI line vector to be the same as that of IRQ line(for example, in PIC mode, PIRQA is connected to IRQ9, shall I set the vector is PIRQA line to be the same as IRQ9 line? here I assume PIRQA is connected to IOAPIC line 16, IRQ9 line is connected to IOAPIC line 9).
And actually my another puzzle is that why PCI needs to keep an "Interrupt Line" register in its config space which records the IRQ number this interrupt pin(A..D) is mapped to? What is its primary function and will it be useful when the systme turns to APIC mode? I couldn't figure out a case where this register may be necessary now that we always have PIRQ routing table and ACPI table to use and you never need to worry about IRQ when you write PCI device drivers.
Anyone has any ideas? Thanks!
Cody
Re:Question on APIC
Posted: Fri Jul 07, 2006 12:47 pm
by kataklinger
PIC may or may not be connected to IOAPIC in Symmetric Mode, you have to read MP configuration table to see this.
And do not make relationships between IRQs and IOAPIC inputs instead, as I said, use MP config. table.
And the answer to the second question is also in MP Specification [D-3 I/O Interrupt Assignment Entries for PCI Devices]
Re:Question on APIC
Posted: Mon Jul 10, 2006 12:43 am
by Cody
Hi, Kataklinger
Thanks for your explanation.
I have done some investigation these days and now I have got a better idea of how this is supposed to be fulfilled:
"PIC may or may not be connected to IOAPIC in Symmetric Mode, you have to read MP configuration table to see this."
-------------
Yes, you can tell that from MP IO Interrupt assignment entries. But the problem is that not every computer comes with its bios implementing MP tables. MP relies heavily on APIC yet it is not designed specifically for MP. It wouldn't surprise me seeing a mobile with single CPU(both physically and logically) to use APIC symmetry mode just for the benefits brought by additional PCI IRQ interrupt lines (with nowadays ioApic 24 inputs, 1 extint, 15 ISA IRQ and 6 for PIRQ A~H).
For this, I believe ACPI APIC table should come to the help. ACPI stipulates that "APIC INTIN 0~15 must be identity mapped to ISA IRQ 0~15", and if it is not the case, "Source Override structure is necessary to change the default". For example, IRQ0 is usually connected to PIC 8259A input 0, but on APIC, INTIN0 is usually used for connecting 8259A so a source override is needed to remap it to INTIN2.
I have checked the datasheet of ICH and there seems to be a bit for each PIRQ controlling whether it is routed to 8259 or not. I believe the transition to APIC mode may include programming this bit so duplicate Interrupts won't be observed on two IoAPIC input lines.
For example, if a pci device uses INTA and this line is connected to PIRQA, PIRQA is programmed to ISA IRQ3 by BIOS POST. By default, ACPI assumes APIC INTIN3 is for IRQ3. When OS transitions the system to APIC mode, it programs the bit for PIRQA to not routing to 8259 mode and enables IoAPIC. Now PIRQA is connected to INTIN16 (this is determined by board layout). Any pulse on PIRQA will cause Interrupt to be observed at INTIN16 but not on INTIN3 so no duplicate interrupts is generated.
I am not sure if my understanding is correct but I believe this basic model should work. Please correct me if I am wrong! Thanks again for your help!
Best regards,
Cody
Re:Question on APIC
Posted: Mon Jul 10, 2006 3:58 am
by Brendan
Hi,
Cody wrote: Recently I read a post here about APIC and someone said that PCI Interrupt line must be connnected to IOAPIC 16~24 and save 0~15 for Legacy ISA IRQ uses. Is that a must?
Motherboard manufacturers may connect any IRQ line to any I/O APIC input wihout restriction (as long as the MP specification tables and APIC tables match). Most motherboard manufacturers do use I/O APIC inputs 0 to 15 for legacy IRQs and IRQs 16 to 24 for PCI, with the exception of input 0 and 2 (which are often different). There's also "unusual" interrput sources (SCI or "ACPI" IRQ and TCO interrupt) that usually use legacy IRQ numbers, and there's PCI devices that usually use legacy IRQ lines (ATA/ATAPI controllers normally use IRQs 14 or 15 instead of PCI IRQ lines, even when everything is setup for non-legacy I/O APIC).
Cody wrote: And actually my another puzzle is that why PCI needs to keep an "Interrupt Line" register in its config space which records the IRQ number this interrupt pin(A..D) is mapped to? What is its primary function and will it be useful when the systme turns to APIC mode? I couldn't figure out a case where this register may be necessary now that we always have PIRQ routing table and ACPI table to use and you never need to worry about IRQ when you write PCI device drivers.
Normally the PCI interrupts are connected to the PIC chips via. a programmable IRQ router. This means that the BIOS can change which PIC inputs the PCI lines are connected to during boot, and the OS can change them whenever it wants (sort of). The entire PCI bus uses "PCI IRQ lines", or PIRQA, PIRQB, PIRQC, PIRQD, and knows nothing about this. So that an OS knows how the BIOS has routed PCI IRQs to the PIC chip, the BIOS stores which PIC input each device is connected to into that device's PCI configuration space header in the "interrupt number" field (which is entirely unused by the device itself).
[continued]
Re:Question on APIC
Posted: Mon Jul 10, 2006 3:59 am
by Brendan
[continued]
Cody wrote:Yes, you can tell that from MP IO Interrupt assignment entries. But the problem is that not every computer comes with its bios implementing MP tables. MP relies heavily on APIC yet it is not designed specifically for MP. It wouldn't surprise me seeing a mobile with single CPU(both physically and logically) to use APIC symmetry mode just for the benefits brought by additional PCI IRQ interrupt lines (with nowadays ioApic 24 inputs, 1 extint, 15 ISA IRQ and 6 for PIRQ A~H).
Intel's MP specification is designed specifically for multi-CPU, but is also used for single CPU computers now (mostly due to Pentium 4 and later CPUs, where there's a single CPU socket but the chip itself may support hyper-threading or be a multi-core chip). ACPI is not designed specifically for multi-CPU, and is replacing Intel's MP specification. I/O APICs were originally designed for multi-CPU, but are much more useful than the PIC chips. AFAIK Microsoft decided that motherboard manufacturers should include an I/O APIC in all computers (including single-CPU only computers) about 4 years ago, and like most things Microsoft tend to get their way.
Please don't assume that there is one I/O APIC or that each I/O APIC has 24 inputs. My dual PIII has two I/O APIC chips with 16 inputs each, and I've seen specifications for chipsets with four I/O APICs.
Cody wrote:For this, I believe ACPI APIC table should come to the help. ACPI stipulates that "APIC INTIN 0~15 must be identity mapped to ISA IRQ 0~15", and if it is not the case, "Source Override structure is necessary to change the default".
This just makes it easier to specify which IRQ is connected where, compared to the MP Specification - for e.g. a BIOS manufacturer only needs to give details on some IRQs for ACPI (rather than all of them, like the MP specification).
Cody wrote:For example, IRQ0 is usually connected to PIC 8259A input 0, but on APIC, INTIN0 is usually used for connecting 8259A so a source override is needed to remap it to INTIN2.
I've seen IRQ0 connected to INTIN2 and the master PIC chip's INTR line connected to INTIN0 as "extInt", I've seen the reverse (IRQ0 as INTIN0 and INTIN2 as "extINT"). I've also seen the master PIC chip's INTR line connected directly to the local APIC (with no connection to any I/O APIC) and IRQ0 connected to either INTIN0 or INTIN2.
Cody wrote:I have checked the datasheet of ICH and there seems to be a bit for each PIRQ controlling whether it is routed to 8259 or not. I believe the transition to APIC mode may include programming this bit so duplicate Interrupts won't be observed on two IoAPIC input lines.
Leave this alone - you shouldn't need to touch anything that doesn't have a "generic" interface, and it shouldn't matter what is connected to the PIC chips if you're using the I/O APICs. To disable the PIC chips, use the IRQ enable/disable masks.
Cheers,
Brendan
Re:Question on APIC
Posted: Mon Jul 10, 2006 4:00 am
by Cody
Well, I have found a good article on PCI IRQ Routing in APIC, here is the address:
http://www.microsoft.com/whdc/system/CEC/ACPI-MP.mspx
According to this article, "The Advanced Configuration and Power Interface Specification, Revision 1.0b replaces the Multiprocessor Specification, Version 1.4. ", this may explain why MP spec cease to update ever since its 1997 version.
I have checked my IBM Thinkcenter workstation and dumped its ACPI source code and I am convinced that it is ACPI that is playing all the games. Though details about how OS transitions from PIC model to APIC model is left unclear, it is obvious that the _PRT method dominate the interrupt direction and the ASL source code is consistent with the interrupt assignments observed in "Device Manager".
Re:Question on APIC
Posted: Mon Jul 10, 2006 4:21 am
by Cody
Hi, Brendan
Thanks very much for your detailed explainations!!!! ;D
There are still several places I am not sure about though.
First, Microsoft claimed MP Spec to be obsolete and ACPI is to replaces it. Several years have passed since then and people here are still talking about MP tables. Do today's OS like windows xp/2k3 still relies heavily on MP?
Second, you mentioned that PIC should be disabled by mask bit. But the question here is if PIRQA is connected to two INTINs at the same time with one in ISA IRQ range and the other outside it, how can we prevent duplicate interrupts? IOAPIC does provide each user defined interrupt with a mask bit but you cannot enable/disable it individually. Is there any general method for dealing with this kind of situatiosn?
And I am reading ICH6's datasheet. It seems to me that you can configure each PIRQ A~H to an IRQ number by programming chipset configuration registers, but there is no way you can configure how a PIRQ can connect to IOAPIC inputs. They seem to have hardwired the connection. If that is the case, shall the os disable the PIRQ when it transitiosn to IoAPIC mode? I couldn't find any clue from the datasheet's descriptions. :-[
Thanks again for your kind help!
Best regards,
Cody
Re:Question on APIC
Posted: Mon Jul 10, 2006 8:58 am
by Brendan
Hi,
Cody wrote:First, Microsoft claimed MP Spec to be obsolete and ACPI is to replaces it. Several years have passed since then and people here are still talking about MP tables. Do today's OS like windows xp/2k3 still relies heavily on MP?
The MP Specification tables will be around for a long time (backward compatibility). Most modern OSs use them if ACPI tables aren't present (but use ACPI tables instead if they can). AFAIK Vista is an exception here - it refuses to boot if ACPI tables aren't present (and OS X too I guess, but that runs on "proprietory-ish" hardware).
Cody wrote:Second, you mentioned that PIC should be disabled by mask bit. But the question here is if PIRQA is connected to two INTINs at the same time with one in ISA IRQ range and the other outside it, how can we prevent duplicate interrupts? IOAPIC does provide each user defined interrupt with a mask bit but you cannot enable/disable it individually. Is there any general method for dealing with this kind of situatiosn?
The I/O APIC connections are hardwired, don't go through the programmable interrupt router, and have nothing to do with how IRQs are connected to the PIC. For example, PIRQA might be connected to I/O APIC INTIN16 and (via. the IRQ router) to PIC input 3. When you disable the PIC (mask all IRQs) and enable the I/O APIC (unmask all IRQs) you will only get one interrupt from the device.
It is possible to have a "messed up" mode, where the OS uses the PICs and the I/O APIC/s at the same time. There's very few sane reasons to do this though...
Apart from this, an IRQ is never connected to 2 different I/O APIC inputs at the same time (AFAIK).
Cheers,
Brendan
Re:Question on APIC
Posted: Mon Jul 10, 2006 6:13 pm
by Cody
Hi, Brendan
Again, thanks!!! ;D You are truly knowlegable in this field!
Yes, Vista is a hard core and refuses to boot if your ACPI tables is not "Kosher" in any corner. The bios that used to boot winxp and win2k3 smoothly couldn't boot Vista. After a thorough check we decided that the MCFG(used for setting PCI Express Memory map base address) table is not configured correctly. Winxp/2k3 will ignore it yet Vista forces us to set it correctly. As to Mac OS X, isn't it changing to Intel Hardware using Intel Core Duo? If that is the case, its hardware will no longer be proprietory I think.
As to PIC and IOAPIC, I am feeling much much better now with your explanation. My worry is gone if no IRQ is ever connected to 2 different I/O Apic inputs at the same time.
And the ASL source code I have at hand for ICH6 has proved your saying that "I/O APIC connections are hardwired". In the _PRS (Possible Resource Settings) method, there are several interrupt resoruce descriptor for selection, i.e. you can set IRQ 3, 7, 14, 15 to Bus 0, Device 29, Function 0 (USB UHCI) and the final decision is made by OS based on its resouce allocation algorithm and this decision is passed down to bios via _SRS(Set Resource Settign) method. But when the current mode is APIC mode (Through notification from OS in _PIC method), the interrupt resource is unique for each interrupt pin on each device. So they must be hardwired internally leaving no space for outsiders to configure it dynamically.
I guess one article here on I/O Apic misled me. The author set the PCI interrupt's vector to be the same as when it is using PIC. Now I feel this is totally not necessary although not wrong technically. We could program the interrupt's vector table to some other vector and insure it won't overlap with any other's. By using the same vector (especially when there is ISA device sharing with it) reduces the benifits you could enjoy by using independent line for PCI interrupts. (Since there is still interrupt sharing and ISR chaining). Am I right?
Finally, there is still one tiny question, why won't intel make its I/O apic be able to make any inputs independently instead of making them as a whole? Is there any considerations here?
Again, thanks for your help! This is the best explanation on how PCI IRQ routing is done in APIC ages I have seen. (so far). ;D
Best regards,
Cody
Re:Question on APIC
Posted: Mon Jul 10, 2006 10:56 pm
by Ryu
Brendans THE man. I think he can knock out several years of aging with his explainations.

Re:Question on APIC
Posted: Tue Jul 11, 2006 12:40 am
by Brendan
Hi,
Cody wrote:As to Mac OS X, isn't it changing to Intel Hardware using Intel Core Duo? If that is the case, its hardware will no longer be proprietory I think.
Apple have changed to Intel CPUs, and will be using Core, but they don't support hardware that doesn't come from Apple and use EFI instead of the legacy/real mode BIOS. This means they don't need to worry about supporting thousands of device drivers or thousands of motherboards or any form of backward compatibility (e.g. DOS, PICs, etc) - it's proprietory hardware built from generic components.
Cody wrote:I guess one article here on I/O Apic misled me. The author set the PCI interrupt's vector to be the same as when it is using PIC. Now I feel this is totally not necessary although not wrong technically. We could program the interrupt's vector table to some other vector and insure it won't overlap with any other's. By using the same vector (especially when there is ISA device sharing with it) reduces the benifits you could enjoy by using independent line for PCI interrupts. (Since there is still interrupt sharing and ISR chaining). Am I right?
Don't confuse the interrupt vector with the I/O APIC input pin - unlike the PIC chips, any input pin can be used to generate any interrupt (and any interrupt type). The interrupt priorities are also done completely differently, where the priority comes for the interrupt vector set by the OS and has nothing to do with which pin the IRQ is connected to. This means that the input pin an IRQ is physically connected to makes no real difference, which is why there's no point having an interrupt router on the I/O APIC inputs.
The author of whatever you've read may be refering to the interrupt priority scheme, where they've used the same interrupt priorities as you'd get from the PIC chips. This does make some sense for some IRQs (but not for others IMHO).
Cheers,
Brendan
Re:Question on APIC
Posted: Tue Jul 11, 2006 10:35 pm
by Cody
Hi, Brendan
Thanks for your help!
I have some other questions and maybe you can give me some clues. ;D
Best regards,
Cody