Skip to contentSkip to conversation

Seabios irq override v3

PATCH In review Jes Sorensen 4 participants 5 messages Jul 29, 2009 – Aug 3, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Seabios irq override v3

Hi Kevin,

Here's a third version of the irq override patch, which applies against the latest tree. There was a conflict in what you pulled into git since yesterday or so.

Per Beth's email this patch is fine now. Would you be fine applying it to Seabios now?

Cheers,
Jes

Implement irq override support for timer interrupts. This matches what QEMU+BOCHS has been doing for the latest 8 months, and is also what real hardware does.

Windows expects this according to Beth Kon.

---
 src/acpi.c    |   12 ++++++++++++
 src/mptable.c |   26 +++++++++++++++++++++++---
 src/util.h    |    3 +++
 3 files changed, 38 insertions(+), 3 deletions(-)
src/acpi.c +12 -0
Index: seabios/src/acpi.c
===================================================================
@@ -331,6 +331,18 @@ build_madt(struct rsdt_descriptor_rev1 *
     io_apic->interrupt = cpu_to_le32(0);
 
     struct madt_intsrcovr *intsrcovr = (void*)&io_apic[1];
+
+    if (irq0override) {
+        memset(intsrcovr, 0, sizeof(*intsrcovr));
+        intsrcovr->type   = APIC_XRUPT_OVERRIDE;
+        intsrcovr->length = sizeof(*intsrcovr);
+        intsrcovr->source = 0;
+        intsrcovr->gsi    = 2;
+        intsrcovr->flags  = 0; /* conforms to bus specifications */
+        intsrcovr++;
+        madt_size += sizeof(struct madt_intsrcovr);
+    }
+
     for (i = 0; i < 16; i++) {
         if (!(PCI_ISA_IRQ_MASK & (1 << i)))
             /* No need for a INT source override structure. */
src/mptable.c +23 -3
Index: seabios/src/mptable.c
===================================================================
@@ -10,6 +10,12 @@
 #include "config.h" // CONFIG_*
 #include "mptable.h" // MPTABLE_SIGNATURE
 
+#if CONFIG_KVM
+int irq0override = 1;
+#else
+int irq0override = 0;
+#endif
+
 void
 mptable_init(void)
 {
@@ -28,7 +34,10 @@ mptable_init(void)
                   + sizeof(struct mpt_cpu) * smp_cpus
                   + sizeof(struct mpt_bus)
                   + sizeof(struct mpt_ioapic)
-                  + sizeof(struct mpt_intsrc) * 16);
+                  + sizeof(struct mpt_intsrc) * 15);
+    if (!irq0override)
+        length += sizeof(struct mpt_intsrc);
+
     void *start = malloc_fseg(length);
     if (!start) {
         dprintf(1, "No room for MPTABLE!\n");
@@ -95,13 +104,24 @@ mptable_init(void)
 
     /* irqs */
     struct mpt_intsrc *intsrcs = (void *)&ioapic[1];
+    int j = 0;
     for(i = 0; i < 16; i++) {
-        struct mpt_intsrc *isrc = &intsrcs[i];
+        struct mpt_intsrc *isrc;
+        /* One entry per ioapic interrupt destination. Destination 2 is covered
+           by irq0->inti2 override (i == 0). Source IRQ 2 is unused */
+        if (irq0override && i == 2) {
+            j = 1;
+            continue;
+        }
+        isrc = &intsrcs[i - j];
         memset(isrc, 0, sizeof(*isrc));
         isrc->type = MPT_TYPE_INTSRC;
         isrc->srcbusirq = i;
         isrc->dstapic = ioapic_id;
-        isrc->dstirq = i;
+        if (irq0override && i == 0)
+	    isrc->dstirq = 2;
+        else
+	    isrc->dstirq = i;
     }
 
     // Set checksum.
src/util.h +3 -0
Index: seabios/src/util.h
===================================================================
@@ -244,4 +244,7 @@ void reset_vector() __attribute__ ((nore
 // misc.c
 extern u8 BiosChecksum;
 
+// mptable.c
+extern int irq0override;
+
 #endif // util.h
#1 lore raw
Quoted 8 lines · Jes Sorensen

Hi Kevin,

Here's a third version of the irq override patch, which applies against the latest tree. There was a conflict in what you pulled into git since yesterday or so.

Per Beth's email this patch is fine now. Would you be fine applying it to Seabios now?

Thanks Jes,

I made some cleanups and committed a modified patch.

I'd like to see what the dynamic irq0override code looks like. The kvm on my machine is a little older and it fails when irq0override is set.

Also, there is a set of irq overrides in the acpi madt code for kvm that set irq 5,9,10,11 to level triggered interrupts. I don't see this in the latest kvm - can this now be removed?

-Kevin

#2 lore raw
Quoted 9 lines · Kevin O'Connor

I made some cleanups and committed a modified patch.

I'd like to see what the dynamic irq0override code looks like. The kvm on my machine is a little older and it fails when irq0override is set.

Also, there is a set of irq overrides in the acpi madt code for kvm that set irq 5,9,10,11 to level triggered interrupts. I don't see this in the latest kvm - can this now be removed?

Hi Kevin,

I justed tested your version and it works fine here. If I got some of the formatting wrong, please let me know and I'll try to get it right in the next set.

The tricky part with the irqoverride is that it is used by recent KVM, but not older versions. qemu-kvm has a fw_cfg flag it uses to set (and not set it when it detects an older version of KVM), however upstream QEMU relies on the irqoverride unconditionally.

As the BIOS cannot detect which version of KVM it is running on, there are two options, either we port the irqoverride fw_cfg to upstream QEMU, or accept that Seabios will not work on older versions of KVM. I don't think Anthony is super excited about adding this to upstream QEMU since it is for legacy support, and I don't anticipate any distros starting to ship Seabios with older version of KVM. I think it would be simpler to just accept it won't work with the older KVM.

I thought about how to best do the dynamic override thing, and I think the best thing is to just set it when we detect we are running on QEMU, be it QEMU, KVM, or KQEMU. I have a patch that allows me to remove all instances of CONFIG_KVM in Seabios, by using a new fw_cfg that tells the bios what emulator it is running on. It would be interesting to see if we could come up with a way for Coreboot to flag as well, so we can share a single BIOS binary.

For the MADT stuff, I really don't know. Maybe Avi or Anthony can comment?

I will post this patch shortly, I just need to make a few more minor tweaks to it.

Cheers,
Jes

#3 lore raw
Quoted 38 lines · Jes Sorensen
Quoted 9 lines · Kevin O'Connor

I made some cleanups and committed a modified patch.

I'd like to see what the dynamic irq0override code looks like. The kvm on my machine is a little older and it fails when irq0override is set.

Also, there is a set of irq overrides in the acpi madt code for kvm that set irq 5,9,10,11 to level triggered interrupts. I don't see this in the latest kvm - can this now be removed?

Hi Kevin,

I justed tested your version and it works fine here. If I got some of the formatting wrong, please let me know and I'll try to get it right in the next set.

The tricky part with the irqoverride is that it is used by recent KVM, but not older versions. qemu-kvm has a fw_cfg flag it uses to set (and not set it when it detects an older version of KVM), however upstream QEMU relies on the irqoverride unconditionally.

As the BIOS cannot detect which version of KVM it is running on, there are two options, either we port the irqoverride fw_cfg to upstream QEMU, or accept that Seabios will not work on older versions of KVM. I don't think Anthony is super excited about adding this to upstream QEMU since it is for legacy support, and I don't anticipate any distros starting to ship Seabios with older version of KVM. I think it would be simpler to just accept it won't work with the older KVM.

I thought about how to best do the dynamic override thing, and I think the best thing is to just set it when we detect we are running on QEMU, be it QEMU, KVM, or KQEMU. I have a patch that allows me to remove all instances of CONFIG_KVM in Seabios, by using a new fw_cfg that tells the bios what emulator it is running on. It would be interesting to see if we could come up with a way for Coreboot to flag as well, so we can share a single BIOS binary.

Quoted 2 lines

For the MADT stuff, I really don't know. Maybe Avi or Anthony can comment?

if (PCI_ISA_IRQ_MASK & (1U << i)) {
               memset(int_override, 0, sizeof(*int_override));
               int_override->type   = APIC_XRUPT_OVERRIDE;
               int_override->length = sizeof(*int_override);
               int_override->source = i;
               int_override->gsi    = i;
               int_override->flags  = 0xd; /* active high, level 
triggered */
           } else {

The above code is still in qemu-kvm/kvm/bios/rombios32.c, but has never been in qemu/bochs bios. I don't understand why.

In any case it has nothing to do with the irq0override code.

is still in the latest kvm bios but has never been in the qemu/bochs bios. I don't understand why that is.

Quoted 6 lines

I will post this patch shortly, I just need to make a few more minor tweaks to it.

Cheers,
Jes

#4 lore raw
Quoted 51 lines · Beth Kon
Quoted 38 lines · Jes Sorensen
Quoted 9 lines · Kevin O'Connor

I made some cleanups and committed a modified patch.

I'd like to see what the dynamic irq0override code looks like. The kvm on my machine is a little older and it fails when irq0override is set.

Also, there is a set of irq overrides in the acpi madt code for kvm that set irq 5,9,10,11 to level triggered interrupts. I don't see this in the latest kvm - can this now be removed?

Hi Kevin,

I justed tested your version and it works fine here. If I got some of the formatting wrong, please let me know and I'll try to get it right in the next set.

The tricky part with the irqoverride is that it is used by recent KVM, but not older versions. qemu-kvm has a fw_cfg flag it uses to set (and not set it when it detects an older version of KVM), however upstream QEMU relies on the irqoverride unconditionally.

As the BIOS cannot detect which version of KVM it is running on, there are two options, either we port the irqoverride fw_cfg to upstream QEMU, or accept that Seabios will not work on older versions of KVM. I don't think Anthony is super excited about adding this to upstream QEMU since it is for legacy support, and I don't anticipate any distros starting to ship Seabios with older version of KVM. I think it would be simpler to just accept it won't work with the older KVM.

I thought about how to best do the dynamic override thing, and I think the best thing is to just set it when we detect we are running on QEMU, be it QEMU, KVM, or KQEMU. I have a patch that allows me to remove all instances of CONFIG_KVM in Seabios, by using a new fw_cfg that tells the bios what emulator it is running on. It would be interesting to see if we could come up with a way for Coreboot to flag as well, so we can share a single BIOS binary.

Quoted 2 lines

For the MADT stuff, I really don't know. Maybe Avi or Anthony can comment?

if (PCI_ISA_IRQ_MASK & (1U << i)) {
               memset(int_override, 0, sizeof(*int_override));
               int_override->type   = APIC_XRUPT_OVERRIDE;
               int_override->length = sizeof(*int_override);
               int_override->source = i;
               int_override->gsi    = i;
               int_override->flags  = 0xd; /* active high, level 
triggered */
           } else {
Quoted 2 lines

The above code is still in qemu-kvm/kvm/bios/rombios32.c, but has never been in qemu/bochs bios. I don't understand why.

IIRC this is needed when using PCI without ACPI. qemu.git doesn't need it since the qemu ioapic does not implement polarity. The guest assumes active low but qemu implements active high.

Signature · 1 line
error compiling committee.c: too many arguments to function