Skip to contentSkip to conversation

BIOS changes for configuring irq0->inti2 override (v4)

PATCH In review Beth Kon 2 participants 8 messages Jun 11, 2009

Subsystems (3)
lore
Share & tools
lore

Beth Kon

author
#0 lore raw

PATCH 1/5 BIOS changes for configuring irq0->inti2 override (v4)

These patches resolve the irq0->inti2 override issue, and get the hpet working on kvm.

Override and HPET changes are sent as a series because HPET depends on the override. Win2k8 expects the HPET interrupt on inti2, regardless of whether an override exists in the BIOS. And the HPET spec states that in legacy mode, timer interrupt is on inti2.

The irq0->inti2 override will always be used unless the kernel cannot do irq routing (i.e., compatibility with old kernels). So if the kernel is capable, userspace sets up irq0->inti2 via the irq routing interface, and adds the irq0->inti2 override to the MADT interrupt source override table, and the mp table (for the no-acpi case).

Changes from v3:

- changes based on comments from Avi and Gleb.
- corrected legacy enable/disable for in-kernel PIT. The code now best approximates a multiplexer that disables PIT interrupts when HPET is in legacy mode (as described by HPET spec). Any changes to the PIT that may occur while HPET is operating in legacy mode are saved, so if HPET leaves legacy mode, the PIT is just reenabled, with mode set to whatever the last setting from guest was. Legacy mode is disabled at least during crash and shutdown (in Linux), so this needs to be handled properly.

---
 kvm/bios/rombios32.c |   60 ++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 44 insertions(+), 16 deletions(-)
kvm/bios/rombios32.c +44 -16
index 369cbef..9d6910e 100755
@@ -444,6 +444,9 @@ uint32_t cpuid_features;
 uint32_t cpuid_ext_features;
 unsigned long ram_size;
 uint64_t ram_end;
+#ifdef BX_QEMU
+uint8_t irq0_override;
+#endif
 #ifdef BX_USE_EBDA_TABLES
 unsigned long ebda_cur_addr;
 #endif
@@ -485,6 +488,7 @@ void wrmsr_smp(uint32_t index, uint64_t val)
 #define QEMU_CFG_ARCH_LOCAL     0x8000
 #define QEMU_CFG_ACPI_TABLES  (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES  (QEMU_CFG_ARCH_LOCAL + 1)
+#define QEMU_CFG_IRQ0_OVERRIDE   (QEMU_CFG_ARCH_LOCAL + 2)
 
 int qemu_cfg_port;
 
@@ -553,6 +557,17 @@ uint64_t qemu_cfg_get64 (void)
 }
 #endif
 
+#ifdef BX_QEMU
+void irq0_override_probe(void)
+{
+    if(qemu_cfg_port) {
+        qemu_cfg_select(QEMU_CFG_IRQ0_OVERRIDE);
+        qemu_cfg_read(&irq0_override, 1);
+        return;
+    }
+}
+#endif
+
 void cpu_probe(void)
 {
     uint32_t eax, ebx, ecx, edx;
@@ -1195,6 +1210,13 @@ static void mptable_init(void)
 
     /* irqs */
     for(i = 0; i < 16; i++) {
+#ifdef BX_QEMU
+        /* One entry per ioapic interrupt destination. Destination 2 is covered
+         * by irq0->inti2 override (i == 0). Source IRQ 2 is unused
+         */
+        if (irq0_override && i == 2)
+            continue;
+#endif
         putb(&q, 3); /* entry type = I/O interrupt */
         putb(&q, 0); /* interrupt type = vectored interrupt */
         putb(&q, 0); /* flags: po=0, el=0 */
@@ -1202,7 +1224,12 @@ static void mptable_init(void)
         putb(&q, 0); /* source bus ID = ISA */
         putb(&q, i); /* source bus IRQ */
         putb(&q, ioapic_id); /* dest I/O APIC ID */
-        putb(&q, i); /* dest I/O APIC interrupt in */
+#ifdef BX_QEMU
+        if (irq0_override && i == 0)
+            putb(&q, 2); /* dest I/O APIC interrupt in */
+        else
+#endif
+            putb(&q, i); /* dest I/O APIC interrupt in */
     }
     /* patch length */
     len = q - mp_config_table;
@@ -1758,23 +1785,21 @@ void acpi_bios_init(void)
         io_apic->io_apic_id = smp_cpus;
         io_apic->address = cpu_to_le32(0xfec00000);
         io_apic->interrupt = cpu_to_le32(0);
-#ifdef BX_QEMU
-#ifdef HPET_WORKS_IN_KVM
         io_apic++;
-
-        int_override = (void *)io_apic;
-        int_override->type = APIC_XRUPT_OVERRIDE;
-        int_override->length = sizeof(*int_override);
-        int_override->bus = cpu_to_le32(0);
-        int_override->source = cpu_to_le32(0);
-        int_override->gsi = cpu_to_le32(2);
-        int_override->flags = cpu_to_le32(0);
-#endif
+        int_override = (struct madt_int_override*)(io_apic);
+#ifdef BX_QEMU
+        if (irq0_override) {
+            memset(int_override, 0, sizeof(*int_override));
+            int_override->type = APIC_XRUPT_OVERRIDE;
+            int_override->length = sizeof(*int_override);
+            int_override->source = 0;
+            int_override->gsi = 2;
+            int_override->flags = 0; /* conforms to bus specifications */
+            int_override++;
+        }
 #endif
-
-        int_override = (struct madt_int_override*)(io_apic + 1);
-        for ( i = 0; i < 16; i++ ) {
-            if ( PCI_ISA_IRQ_MASK & (1U << i) ) {
+        for (i = 0; i < 16; i++) {
+            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);
@@ -2697,6 +2722,9 @@ void rombios32_init(uint32_t *s3_resume_vector, uint8_t *shutdown_flag)
 
     if (bios_table_cur_addr != 0) {
 
+#ifdef BX_QEMU
+        irq0_override_probe();
+#endif
         mptable_init();
 
         smbios_init();
author
#1 lore raw

PATCH 2/5 Userspace changes for configuring irq0->inti2 override (v4)

---
 hw/ioapic.c    |    6 +++---
 hw/pc.c        |    2 ++
 qemu-kvm-x86.c |    6 +++++-
 qemu-kvm.h     |    2 ++
 sysemu.h       |    1 +
 vl.c           |   11 +++++++++--
 6 files changed, 22 insertions(+), 6 deletions(-)
hw/ioapic.c +3 -3
index 6c178c7..a67b766 100644
@@ -23,6 +23,7 @@
 
 #include "hw.h"
 #include "pc.h"
+#include "sysemu.h"
 #include "qemu-timer.h"
 #include "host-utils.h"
 
@@ -95,14 +96,13 @@ void ioapic_set_irq(void *opaque, int vector, int level)
 {
     IOAPICState *s = opaque;
 
-#if 0
     /* ISA IRQs map to GSI 1-1 except for IRQ0 which maps
      * to GSI 2.  GSI maps to ioapic 1-1.  This is not
      * the cleanest way of doing it but it should work. */
 
-    if (vector == 0)
+    if (vector == 0 && irq0override) {
         vector = 2;
-#endif
+    }
 
     if (vector >= 0 && vector < IOAPIC_NUM_PINS) {
         uint32_t mask = 1 << vector;
hw/pc.c +2 -0
index 66f4635..1c068fb 100644
@@ -55,6 +55,7 @@
 #define BIOS_CFG_IOPORT 0x510
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
+#define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
 
 #define MAX_IDE_BUS 2
 
@@ -476,6 +477,7 @@ static void bochs_bios_init(void)
     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
     fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
                      acpi_tables_len);
+    fw_cfg_add_bytes(fw_cfg, FW_CFG_IRQ0_OVERRIDE, &irq0override, 1);
 
     smbios_table = smbios_get_table(&smbios_len);
     if (smbios_table)
qemu-kvm-x86.c +5 -1
index 5526d8f..89337e9 100644
@@ -909,7 +909,11 @@ int kvm_arch_init_irq_routing(void)
                 return r;
         }
         for (i = 0; i < 24; ++i) {
-            r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_IOAPIC, i);
+            if (i == 0) {
+                r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_IOAPIC, 2);
+            } else if (i != 2) {
+                r = kvm_add_irq_route(kvm_context, i, KVM_IRQCHIP_IOAPIC, i);
+            }
             if (r < 0)
                 return r;
         }
qemu-kvm.h +2 -0
index fa40542..6bbafbc 100644
@@ -169,6 +169,7 @@ int handle_tpr_access(void *opaque, kvm_vcpu_context_t vcpu,
 #define kvm_enabled() (kvm_allowed)
 #define qemu_kvm_irqchip_in_kernel() kvm_irqchip_in_kernel(kvm_context)
 #define qemu_kvm_pit_in_kernel() kvm_pit_in_kernel(kvm_context)
+#define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing(kvm_context)
 #define kvm_has_sync_mmu() qemu_kvm_has_sync_mmu()
 void kvm_init_vcpu(CPUState *env);
 void kvm_load_tsc(CPUState *env);
@@ -177,6 +178,7 @@ void kvm_load_tsc(CPUState *env);
 #define kvm_nested 0
 #define qemu_kvm_irqchip_in_kernel() (0)
 #define qemu_kvm_pit_in_kernel() (0)
+#define qemu_kvm_has_gsi_routing() (0)
 #define kvm_has_sync_mmu() (0)
 #define kvm_load_registers(env) do {} while(0)
 #define kvm_save_registers(env) do {} while(0)
sysemu.h +1 -0
index 47d001e..f78e974 100644
@@ -108,6 +108,7 @@ extern int xenfb_enabled;
 extern int graphic_width;
 extern int graphic_height;
 extern int graphic_depth;
+extern uint8_t irq0override;
 extern DisplayType display_type;
 extern const char *keyboard_layout;
 extern int win2k_install_hack;
vl.c +9 -2
index 2fda17b..9b1d1ab 100644
@@ -253,6 +253,7 @@ int no_reboot = 0;
 int no_shutdown = 0;
 int cursor_hide = 1;
 int graphic_rotate = 0;
+uint8_t irq0override = 1;
 #ifndef _WIN32
 int daemonize = 0;
 #endif
@@ -6054,8 +6055,14 @@ int main(int argc, char **argv, char **envp)
 
     module_call_init(MODULE_INIT_DEVICE);
 
-    if (kvm_enabled())
-	kvm_init_ap();
+    if (kvm_enabled()) {
+       kvm_init_ap();
+#ifdef USE_KVM
+        if (kvm_irqchip && !qemu_kvm_has_gsi_routing()) {
+            irq0override = 0;
+        }
+#endif
+    }
 
     machine->init(ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
author
#2 lore raw

PATCH 3/5 BIOS changes for KVM HPET (v5)

In reply to Beth Kon
---
 kvm/bios/acpi-dsdt.dsl |    2 --
 kvm/bios/rombios32.c   |   11 +++--------
 2 files changed, 3 insertions(+), 10 deletions(-)
kvm/bios/acpi-dsdt.dsl +0 -2
index db57307..71d0a5e 100755
@@ -296,7 +296,6 @@ DefinitionBlock (
             })
         }
 #ifdef BX_QEMU
-#ifdef HPET_WORKS_IN_KVM
         Device(HPET) {
             Name(_HID,  EISAID("PNP0103"))
             Name(_UID, 0)
@@ -316,7 +315,6 @@ DefinitionBlock (
             })
         }
 #endif
-#endif
     }
 
     Scope(\_SB.PCI0) {
kvm/bios/rombios32.c +3 -8
index 9d6910e..1106f38 100755
@@ -1518,8 +1518,8 @@ struct acpi_20_generic_address {
 } __attribute__((__packed__));
 
 /*
- *  * HPET Description Table
- *   */
+ *  HPET Description Table
+ */
 struct acpi_20_hpet {
     ACPI_TABLE_HEADER_DEF                           /* ACPI common table header */
     uint32_t           timer_block_id;
@@ -1703,13 +1703,11 @@ void acpi_bios_init(void)
     addr += madt_size;
 
 #ifdef BX_QEMU
-#ifdef HPET_WORKS_IN_KVM
     addr = (addr + 7) & ~7;
     hpet_addr = addr;
     hpet = (void *)(addr);
     addr += sizeof(*hpet);
 #endif
-#endif
 
     /* RSDP */
     memset(rsdp, 0, sizeof(*rsdp));
@@ -1883,7 +1881,6 @@ void acpi_bios_init(void)
     }
 
     /* HPET */
-#ifdef HPET_WORKS_IN_KVM
     memset(hpet, 0, sizeof(*hpet));
     /* Note timer_block_id value must be kept in sync with value advertised by
      * emulated hpet
@@ -1892,7 +1889,6 @@ void acpi_bios_init(void)
     hpet->addr.address = cpu_to_le32(ACPI_HPET_ADDRESS);
     acpi_build_table_header((struct  acpi_table_header *)hpet,
                              "HPET", sizeof(*hpet), 1);
-#endif
 
     acpi_additional_tables(); /* resets cfg to required entry */
     for(i = 0; i < external_tables; i++) {
@@ -1912,8 +1908,7 @@ void acpi_bios_init(void)
     /* kvm has no ssdt (processors are in dsdt) */
 //  rsdt->table_offset_entry[nb_rsdt_entries++] = cpu_to_le32(ssdt_addr);
 #ifdef BX_QEMU
-    /* No HPET (yet) */
-//  rsdt->table_offset_entry[nb_rsdt_entries++] = cpu_to_le32(hpet_addr);
+    rsdt->table_offset_entry[nb_rsdt_entries++] = cpu_to_le32(hpet_addr);
     if (nb_numa_nodes > 0)
         rsdt->table_offset_entry[nb_rsdt_entries++] = cpu_to_le32(srat_addr);
 #endif
author
#3 lore raw

PATCH 4/5 Userspace changes for KVM HPET (v4)

In reply to Beth Kon

The big change here is handling of enabling/disabling of hpet legacy mode. When hpet enters legacy mode, the spec says that the pit stops generating interrupts. In practice, we want to stop the pit periodic timer from running because it is wasteful in a virtual environment.

We also have to worry about the hpet leaving legacy mode (which, at least in linux, happens only during a shutdown or crash). At this point, according to the hpet spec, PIT interrupts need to be reenabled. For us, it means the PIT timer needs to be restarted.

This patch handles this situation better than the previous version by coming closer to just disabling PIT interrupts. It allows the PIT state to change if the OS modifies it, even while PIT is disabled, but does not allow a pit timer to start. Then if HPET legacy mode is disabled, whatever the PIT state is at that point, the PIT timer is restarted accordingly.

---
 hw/hpet.c                 |   15 +++++++++++----
 hw/i8254.c                |   43 ++++++++++++++++++++++++++++++-------------
 hw/i8254.h                |    2 ++
 hw/pc.h                   |    4 ++--
 kvm/include/x86/asm/kvm.h |    1 +
 qemu-kvm.c                |   20 ++++++++++++++++++++
 qemu-kvm.h                |    3 ++-
 vl.c                      |    7 ++++++-
 8 files changed, 74 insertions(+), 21 deletions(-)
hw/hpet.c +11 -4
index 29db325..043b92b 100644
@@ -206,6 +206,9 @@ static int hpet_load(QEMUFile *f, void *opaque, int version_id)
             qemu_get_timer(f, s->timer[i].qemu_timer);
         }
     }
+    if (hpet_in_legacy_mode()) {
+        hpet_disable_pit();
+    }
     return 0;
 }
 
@@ -475,9 +478,11 @@ static void hpet_ram_writel(void *opaque, target_phys_addr_t addr,
                 }
                 /* i8254 and RTC are disabled when HPET is in legacy mode */
                 if (activating_bit(old_val, new_val, HPET_CFG_LEGACY)) {
-                    hpet_pit_disable();
+                    hpet_disable_pit();
+                    dprintf("qemu: hpet disabled pit\n");
                 } else if (deactivating_bit(old_val, new_val, HPET_CFG_LEGACY)) {
-                    hpet_pit_enable();
+                    hpet_enable_pit();
+                    dprintf("qemu: hpet enabled pit\n");
                 }
                 break;
             case HPET_CFG + 4:
@@ -554,13 +559,15 @@ static void hpet_reset(void *opaque) {
     /* 64-bit main counter; 3 timers supported; LegacyReplacementRoute. */
     s->capability = 0x8086a201ULL;
     s->capability |= ((HPET_CLK_PERIOD) << 32);
-    if (count > 0)
+    if (count > 0) {
         /* we don't enable pit when hpet_reset is first called (by hpet_init)
          * because hpet is taking over for pit here. On subsequent invocations,
          * hpet_reset is called due to system reset. At this point control must
          * be returned to pit until SW reenables hpet.
          */
-        hpet_pit_enable();
+        hpet_enable_pit();
+        dprintf("qemu: hpet enabled pit\n");
+    }
     count = 1;
 }
 
hw/i8254.c +30 -13

90 lines not on this page · raw message

hw/i8254.h +2 -0
index ee68ab5..9efd4ab 100644
@@ -35,6 +35,7 @@
 
 typedef struct PITChannelState {
     int count; /* can be 65536 */
+    uint8_t channel;
     uint16_t latched_count;
     uint8_t count_latched;
     uint8_t status_latched;
@@ -55,6 +56,7 @@ typedef struct PITChannelState {
 
 struct PITState {
     PITChannelState channels[3];
+    uint8_t hpet_legacy_mode;
 };
 
 void pit_save(QEMUFile *f, void *opaque);
hw/pc.h +2 -2
index 3af22f2..abac8d8 100644
@@ -74,8 +74,8 @@ int pit_get_out(PITState *pit, int channel, int64_t current_time);
 
 PITState *kvm_pit_init(int base, qemu_irq irq);
 
-void hpet_pit_disable(void);
-void hpet_pit_enable(void);
+void hpet_disable_pit(void);
+void hpet_enable_pit(void);
 
 /* vmport.c */
 void vmport_init(void);
kvm/include/x86/asm/kvm.h +1 -0
index dc90c47..df8d846 100644
@@ -274,6 +274,7 @@ struct kvm_guest_debug_arch {
 
 struct kvm_pit_state {
 	struct kvm_pit_channel_state channels[3];
+    __u8 hpet_legacy_mode;
 };
 
 struct kvm_reinject_control {
qemu-kvm.c +20 -0
index 7acc0ef..98bd117 100644
@@ -467,6 +467,26 @@ int kvm_vcpu_inited(CPUState *env)
     return env->kvm_cpu_state.created;
 }
 
+void kvm_hpet_disable_kpit(void)
+{
+    struct kvm_pit_state ps;
+    if (qemu_kvm_pit_in_kernel()) {
+        kvm_get_pit(kvm_context, &ps);
+        ps.hpet_legacy_mode = 1;
+        kvm_set_pit(kvm_context, &ps);
+    }
+}
+
+void kvm_hpet_enable_kpit(void)
+{
+    struct kvm_pit_state ps;
+    if (qemu_kvm_pit_in_kernel()) {
+        kvm_get_pit(kvm_context, &ps);
+        ps.hpet_legacy_mode = 0;
+        kvm_set_pit(kvm_context, &ps);
+    }
+}
+
 int kvm_init_ap(void)
 {
 #ifdef TARGET_I386
qemu-kvm.h +2 -1
index 6bbafbc..c094107 100644
@@ -34,7 +34,8 @@ int kvm_qemu_check_extension(int ext);
 void kvm_apic_init(CPUState *env);
 /* called from vcpu initialization */
 void qemu_kvm_load_lapic(CPUState *env);
-
+void kvm_hpet_enable_kpit(void);
+void kvm_hpet_disable_kpit(void);
 int kvm_set_irq(int irq, int level, int *status);
 
 int kvm_physical_memory_set_dirty_tracking(int enable);
vl.c +6 -1
index 9b1d1ab..485b091 100644
@@ -6056,10 +6056,15 @@ int main(int argc, char **argv, char **envp)
     module_call_init(MODULE_INIT_DEVICE);
 
     if (kvm_enabled()) {
-       kvm_init_ap();
+        kvm_init_ap();
 #ifdef USE_KVM
         if (kvm_irqchip && !qemu_kvm_has_gsi_routing()) {
             irq0override = 0;
+            /* if kernel can't do irq routing, interrupt source
+             * override 0->2 can not be set up as required by hpet,
+             * so disable hpet.
+             */
+            no_hpet=1;
         }
 #endif
     }
author
#4 lore raw

PATCH 5/5 HPET interaction with in-kernel PIT

In reply to Beth Kon
---
 arch/x86/include/asm/kvm.h |    1 +
 arch/x86/kvm/i8254.c       |   24 +++++++++++++++++++-----
 arch/x86/kvm/i8254.h       |    3 ++-
 arch/x86/kvm/x86.c         |    5 ++++-
 4 files changed, 26 insertions(+), 7 deletions(-)
arch/x86/include/asm/kvm.h +1 -0
index 708b9c3..3c44923 100644
@@ -235,6 +235,7 @@ struct kvm_guest_debug_arch {
 
 struct kvm_pit_state {
 	struct kvm_pit_channel_state channels[3];
+	u8 hpet_legacy_mode;
 };
 
 struct kvm_reinject_control {
arch/x86/kvm/i8254.c +19 -5
index 331705f..bb8382b 100644
@@ -340,10 +340,20 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val)
 	}
 }
 
-void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val)
+void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_start)
 {
+	u8 saved_mode;
 	mutex_lock(&kvm->arch.vpit->pit_state.lock);
-	pit_load_count(kvm, channel, val);
+	if (hpet_legacy_start) {
+		/* save existing mode for later reenablement */
+		saved_mode = kvm->arch.vpit->pit_state.channels[0].mode;
+		kvm->arch.vpit->pit_state.channels[0].mode = 0xff; /* disable timer */
+		pit_load_count(kvm, channel, val);
+		kvm->arch.vpit->pit_state.channels[0].mode = saved_mode;
+	} else {
+			if (!(channel == 0 && kvm->arch.vpit->pit_state.hpet_legacy_mode))
+			pit_load_count(kvm, channel, val);
+	}
 	mutex_unlock(&kvm->arch.vpit->pit_state.lock);
 }
 
@@ -411,17 +421,20 @@ static void pit_ioport_write(struct kvm_io_device *this,
 		switch (s->write_state) {
 		default:
 		case RW_STATE_LSB:
-			pit_load_count(kvm, addr, val);
+			if (!(addr == 0 && pit_state->hpet_legacy_mode))
+				pit_load_count(kvm, addr, val);
 			break;
 		case RW_STATE_MSB:
-			pit_load_count(kvm, addr, val << 8);
+			if (!(addr == 0 && pit_state->hpet_legacy_mode))
+				pit_load_count(kvm, addr, val << 8);
 			break;
 		case RW_STATE_WORD0:
 			s->write_latch = val;
 			s->write_state = RW_STATE_WORD1;
 			break;
 		case RW_STATE_WORD1:
-			pit_load_count(kvm, addr, s->write_latch | (val << 8));
+			if (!(addr == 0 && pit_state->hpet_legacy_mode))
+				pit_load_count(kvm, addr, s->write_latch | (val << 8));
 			s->write_state = RW_STATE_WORD0;
 			break;
 		}
@@ -548,6 +561,7 @@ void kvm_pit_reset(struct kvm_pit *pit)
 	struct kvm_kpit_channel_state *c;
 
 	mutex_lock(&pit->pit_state.lock);
+	pit->pit_state.hpet_legacy_mode = 0;
 	for (i = 0; i < 3; i++) {
 		c = &pit->pit_state.channels[i];
 		c->mode = 0xff;
arch/x86/kvm/i8254.h +2 -1
index b267018..b5967ca 100644
@@ -21,6 +21,7 @@ struct kvm_kpit_channel_state {
 
 struct kvm_kpit_state {
 	struct kvm_kpit_channel_state channels[3];
+	u8 hpet_legacy_mode;
 	struct kvm_timer pit_timer;
 	bool is_periodic;
 	u32    speaker_data_on;
@@ -49,7 +50,7 @@ struct kvm_pit {
 #define KVM_PIT_CHANNEL_MASK	    0x3
 
 void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu);
-void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val);
+void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val, int hpet_legacy_start);
 struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags);
 void kvm_free_pit(struct kvm *kvm);
 void kvm_pit_reset(struct kvm_pit *pit);
arch/x86/kvm/x86.c +4 -1
index 1b91ea7..3c70545 100644
@@ -1948,9 +1948,12 @@ static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps)
 static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps)
 {
 	int r = 0;
+	int hpet_legacy_start = 0;
 
+	if (ps->hpet_legacy_mode && !kvm->arch.vpit->pit_state.hpet_legacy_mode)
+		hpet_legacy_start = 1;
 	memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state));
-	kvm_pit_load_count(kvm, 0, ps->channels[0].count);
+	kvm_pit_load_count(kvm, 0, ps->channels[0].count, hpet_legacy_start);
 	return r;
 }
 
#5 lore raw
In reply to Beth Kon
Quoted 27 lines · Beth Kon

These patches resolve the irq0->inti2 override issue, and get the hpet working on kvm.

Override and HPET changes are sent as a series because HPET depends on the override. Win2k8 expects the HPET interrupt on inti2, regardless of whether an override exists in the BIOS. And the HPET spec states that in legacy mode, timer interrupt is on inti2.

The irq0->inti2 override will always be used unless the kernel cannot do irq routing (i.e., compatibility with old kernels). So if the kernel is capable, userspace sets up irq0->inti2 via the irq routing interface, and adds the irq0->inti2 override to the MADT interrupt source override table, and the mp table (for the no-acpi case).

Changes from v3:

- changes based on comments from Avi and Gleb.
- corrected legacy enable/disable for in-kernel PIT. The code now best approximates a multiplexer that disables PIT interrupts when HPET is in legacy mode (as described by HPET spec). Any changes to the PIT that may occur while HPET is operating in legacy mode are saved, so if HPET leaves legacy mode, the PIT is just reenabled, with mode set to whatever the last setting from guest was. Legacy mode is disabled at least during crash and shutdown (in Linux), so this needs to be handled properly.

Quoted 3 lines

---
kvm/bios/rombios32.c | 60 ++++++++++++++++++++++++++++++++++++-------------

1 files changed, 44 insertions(+), 16 deletions(-)

What about the mptable entry count?
Think it would need something like

#ifdef BX_QEMU
if (irq0_override)
putle16(&q, smp_cpus + 17); /* entry count */
else
putle16(&q, smp_cpus + 18); /* entry count */
#else
putle16(&q, smp_cpus + 18); /* entry count */
#endif

Your patch "Fix non-ACPI Timer Interrupt Routing - v3" [1] included such a change.

[1] http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01396.html

- Sebastian

author
#6 lore raw
Quoted 43 lines · Sebastian Herbszt
Quoted 25 lines · Beth Kon

These patches resolve the irq0->inti2 override issue, and get the hpet working on kvm.

Override and HPET changes are sent as a series because HPET depends on the override. Win2k8 expects the HPET interrupt on inti2, regardless of whether an override exists in the BIOS. And the HPET spec states that in legacy mode, timer interrupt is on inti2.

The irq0->inti2 override will always be used unless the kernel cannot do irq routing (i.e., compatibility with old kernels). So if the kernel is capable, userspace sets up irq0->inti2 via the irq routing interface, and adds the irq0->inti2 override to the MADT interrupt source override table, and the mp table (for the no-acpi case).

Changes from v3:

- changes based on comments from Avi and Gleb.
- corrected legacy enable/disable for in-kernel PIT. The code now best approximates a multiplexer that disables PIT interrupts when HPET is in legacy mode (as described by HPET spec). Any changes to the PIT
that may occur while HPET is operating in legacy mode are saved, so if HPET leaves legacy mode, the PIT is just reenabled, with mode set to whatever the last setting from guest was. Legacy mode is disabled
at least during crash and shutdown (in Linux), so this needs to be handled properly.

Quoted 4 lines

---
kvm/bios/rombios32.c | 60
++++++++++++++++++++++++++++++++++++-------------

1 files changed, 44 insertions(+), 16 deletions(-)

What about the mptable entry count?
Think it would need something like

#ifdef BX_QEMU
if (irq0_override)
putle16(&q, smp_cpus + 17); /* entry count */
else
putle16(&q, smp_cpus + 18); /* entry count */
#else
putle16(&q, smp_cpus + 18); /* entry count */
#endif

Quoted 3 lines

Your patch "Fix non-ACPI Timer Interrupt Routing - v3" [1] included such a change.

[1] http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01396.html

Yes, I lost that somehow! Thanks (again!).

Quoted 3 lines

- Sebastian

author
#7 lore raw
Quoted 43 lines · Beth Kon
Quoted 42 lines · Sebastian Herbszt
Quoted 24 lines · Beth Kon

These patches resolve the irq0->inti2 override issue, and get the hpet working on kvm.

Override and HPET changes are sent as a series because HPET depends on the override. Win2k8 expects the HPET interrupt on inti2, regardless of whether an override exists in the BIOS. And the HPET spec states that in legacy mode, timer interrupt is on inti2.

The irq0->inti2 override will always be used unless the kernel cannot do irq routing (i.e., compatibility with old kernels). So if the kernel is capable, userspace sets up irq0->inti2 via the irq routing interface, and adds the irq0->inti2 override to the MADT interrupt source override table, and the mp table (for the no-acpi case).

Changes from v3:

- changes based on comments from Avi and Gleb.
- corrected legacy enable/disable for in-kernel PIT. The code now best approximates a multiplexer that disables PIT interrupts when HPET
is in legacy mode (as described by HPET spec). Any changes to the PIT that may occur while HPET is operating in legacy mode are saved, so if HPET leaves legacy mode, the PIT is just reenabled, with mode set to whatever the last setting from guest was. Legacy mode is disabled
at least during crash and shutdown (in Linux), so this needs to be handled properly.

Quoted 4 lines

---
kvm/bios/rombios32.c | 60
++++++++++++++++++++++++++++++++++++-------------

1 files changed, 44 insertions(+), 16 deletions(-)

What about the mptable entry count?
Think it would need something like

#ifdef BX_QEMU
if (irq0_override)
putle16(&q, smp_cpus + 17); /* entry count */
else
putle16(&q, smp_cpus + 18); /* entry count */
#else
putle16(&q, smp_cpus + 18); /* entry count */
#endif

Quoted 4 lines
Quoted 3 lines

Your patch "Fix non-ACPI Timer Interrupt Routing - v3" [1] included such a change.

[1] http://lists.gnu.org/archive/html/qemu-devel/2009-04/msg01396.html

Yes, I lost that somehow! Thanks (again!).

Actually, it isn't that simple. That patch that you referred to was a qemu patch. But I still don't see it in qemu-patched bochs bios. Apparently, I did neglect to add it to the kvm bios patches that I had waiting.

Anthony, do you know what happened to this patch?

Quoted 9 lines
Quoted 4 lines

- Sebastian

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html