Skip to contentSkip to conversation

Seabios irq override support.

PATCH In review Jes Sorensen 3 participants 5 messages Jul 24, 2009 – Jul 28, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Seabios irq override support.

Hi Kevin,

Here is a patch to implement irq override for timer interrupts from irq0 to int2. It's based on what Beth Kon implemented for BOCHS earlier, git commit c6d25871212c05af647eccaad6efc07a6f7a4acb.

With this patch applied, I can boot KVM using the latest upstream QEMU and Seabios.

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    |   10 ++++++++++
 src/mptable.c |   16 +++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
src/acpi.c +10 -0
Index: seabios/src/acpi.c
===================================================================
@@ -440,6 +440,16 @@ void acpi_bios_init(void)
     io_apic->interrupt = cpu_to_le32(0);
 
     struct madt_intsrcovr *intsrcovr = (void*)&io_apic[1];
+
+    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 +13 -3
Index: seabios/src/mptable.c
===================================================================
@@ -29,7 +29,7 @@ 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 (start + length > bios_table_end_addr) {
         dprintf(1, "No room for MPTABLE!\n");
         return;
@@ -96,13 +96,23 @@ 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];
+        /* One entry per ioapic interrupt destination. Destination 2 is covered
+           by irq0->inti2 override (i == 0). Source IRQ 2 is unused */
+        if (i == 2) {
+            j = 1;
+            continue;
+        }
+        struct mpt_intsrc *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 (i == 0)
+	    isrc->dstirq = 2;
+        else
+	    isrc->dstirq = i;
     }
 
     // Set checksum.
#1 lore raw
Quoted 8 lines · Jes Sorensen

Hi Kevin,

Here is a patch to implement irq override for timer interrupts from irq0 to int2. It's based on what Beth Kon implemented for BOCHS earlier, git commit c6d25871212c05af647eccaad6efc07a6f7a4acb.

With this patch applied, I can boot KVM using the latest upstream QEMU and Seabios.

Thanks Jes.

The bochs commit shows this wrapped in "#ifdef BX_QEMU". Will this patch break bochs, or were the ifdefs just bochs paranoia?

-Kevin

#2 lore raw
Quoted 8 lines · Kevin O'Connor
Quoted 2 lines · Jes Sorensen

With this patch applied, I can boot KVM using the latest upstream QEMU and Seabios.

Thanks Jes.

The bochs commit shows this wrapped in "#ifdef BX_QEMU". Will this patch break bochs, or were the ifdefs just bochs paranoia?

Hi Kevin,

I don't actually know for sure. I didn't add the #ifdefs since I got the impression that Seabios doesn't have them in many places. The original code was designed by Beth Kon, so maybe she can comment on whether we should add them to Seabios.

Beth?

Thanks,
Jes

#3 lore raw
Quoted 17 lines · Jes Sorensen
Quoted 8 lines · Kevin O'Connor
Quoted 2 lines · Jes Sorensen

With this patch applied, I can boot KVM using the latest upstream QEMU and Seabios.

Thanks Jes.

The bochs commit shows this wrapped in "#ifdef BX_QEMU". Will this patch break bochs, or were the ifdefs just bochs paranoia?

Hi Kevin,

I don't actually know for sure. I didn't add the #ifdefs since I got the impression that Seabios doesn't have them in many places. The original code was designed by Beth Kon, so maybe she can comment on whether we should add them to Seabios.

Quoted 4 lines

Beth?

Thanks,
Jes

Hi Jes. These bios changes rely on matching userspace/kernel changes that translate irq0->inti2. So assuming seabios is used for systems other than kvm and qemu, this code would need to be conditionally removed.

But I'm not clear on what you're doing with this patch. You didn't include the irq0override flag that is needed by kvm because there are circumstances under which kvm turns off irq0override (i.e., old kernels that don't support irq routing). So this patch is fine for qemu, since it is permanently enabled there, but it is not a permanent solution for kvm.

#4 lore raw
Quoted 3 lines · Beth Kon

Hi Jes. These bios changes rely on matching userspace/kernel changes that translate irq0->inti2. So assuming seabios is used for systems other than kvm and qemu, this code would need to be conditionally removed.

Hi Beth,

Thanks for the input. I guess we'll want it to be CONFIG_KVM for now then, since Seabios doesn't know of BX_QEMU. Once we have more of the cfg_fw stuff needed for this, the #ifdef part can be made prettier.

Quoted 6 lines

But I'm not clear on what you're doing with this patch. You didn't include the irq0override flag that is needed by kvm because there are circumstances under which kvm turns off irq0override (i.e., old kernels that don't support irq routing). So this patch is fine for qemu, since it is permanently enabled there, but it is not a permanent solution for kvm.

The reason I didn't include the irq0override flag is that the fw_cfg bits for this aren't in Seabios yet. I'll be happy to add them in a follow up patch.

How do you like this version? It's a little more complex as I introduced the irq0override variable, but it will make it very easy to add the cfg_fw stuff.

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
===================================================================
@@ -433,6 +433,18 @@ void acpi_bios_init(void)
     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)
 {
@@ -29,7 +35,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);
+
     if (start + length > bios_table_end_addr) {
         dprintf(1, "No room for MPTABLE!\n");
         return;
@@ -96,13 +105,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
===================================================================
@@ -238,4 +238,7 @@ void reset_vector() __attribute__ ((nore
 // misc.c
 extern u8 BiosChecksum;
 
+// mptable.c
+extern int irq0override;
+
 #endif // util.h