Skip to contentSkip to conversation

qemu-kvm: Prepare kvm PIT for upstream merge

PATCH Applied Jan Kiszka 2 participants 7 messages Mar 19, 2012 – Mar 21, 2012

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

cover qemu-kvm: Prepare kvm PIT for upstream merge

Some preparation patches to arrange qemu-kvm for merging in latest qemu with its own in-kernel PIT support. Later on, we can switch to that version without losing features on the way, even just temporarily.

Jan Kiszka (5):
qemu-kvm: i8254/pcspk: Remove unused bits to make PC speaker
kvm-aware
qemu-kvm: i8254: Reset broken pit_load_old to upstream version
qemu-kvm: i8254: Revert pit_load_count to upstream version
qemu-kvm: i8254: Drop bogus irq_disabled clearing in pit_reset
qemu-kvm: i8254: Reorganize i8254-kvm code

 Makefile.objs   |    2 +-
 Makefile.target |    5 +-
 hw/i8254-kvm.c  |   12 ++----
 hw/i8254.c      |  112 ++++++++++++++++++++++++-------------------------------
 hw/i8254.h      |   49 +-----------------------
 hw/pcspk.c      |    6 ---
 6 files changed, 58 insertions(+), 128 deletions(-)
Signature · 1 line
1.7.3.4
author
#1 lore raw

PATCH 1/5 qemu-kvm: i8254/pcspk: Remove unused bits to make PC speaker kvm-aware

Due to old-style-only creation of the in-kernel PIT (became broken long ago during refactorings), the kernel always handled the speaker port in qemu-kvm for a long while. Thus all bits that try to make the user space speaker emulating kvm-aware are actually unused. Upstream will come with fully-working speaker emulation even while the in-kernel PIT is enabled, so let's drop the dead bits from qemu-kvm to ease merging with upstream.

---
 Makefile.objs   |    2 +-
 Makefile.target |    4 ++--
 hw/i8254.c      |   44 --------------------------------------------
 hw/pcspk.c      |    6 ------
 4 files changed, 3 insertions(+), 53 deletions(-)
Makefile.objs +1 -1
index c33c0f2..39791ac 100644
@@ -212,7 +212,7 @@ hw-obj-$(CONFIG_SERIAL) += serial.o
 hw-obj-$(CONFIG_PARALLEL) += parallel.o
 # Moved back to Makefile.target due to #include qemu-kvm.h:
 #hw-obj-$(CONFIG_I8254) += i8254.o
-#hw-obj-$(CONFIG_PCSPK) += pcspk.o
+hw-obj-$(CONFIG_PCSPK) += pcspk.o
 hw-obj-$(CONFIG_PCKBD) += pckbd.o
 hw-obj-$(CONFIG_USB_UHCI) += usb-uhci.o
 hw-obj-$(CONFIG_USB_OHCI) += usb-ohci.o
Makefile.target +2 -2
index ae04331..5f6b963 100644
@@ -250,7 +250,7 @@ obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
 obj-i386-y += testdev.o
 obj-i386-y += acpi.o acpi_piix4.o
 
-obj-i386-y += pcspk.o i8254.o
+obj-i386-y += i8254.o
 obj-i386-$(CONFIG_KVM_PIT) += i8254-kvm.o
 obj-i386-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += device-assignment.o
 
@@ -308,7 +308,7 @@ obj-lm32-y += milkymist-vgafb.o
 obj-lm32-y += framebuffer.o
 
 obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
-obj-mips-y += pcspk.o i8254.o
+obj-mips-y += i8254.o
 obj-mips-y += acpi.o acpi_piix4.o
 obj-mips-y += mips_addr.o mips_timer.o mips_int.o
 obj-mips-y += gt64xxx.o mc146818rtc.o
hw/i8254.c +0 -44

55 lines not on this page · raw message

hw/pcspk.c +0 -6
index bb25ffb..e430324 100644
@@ -29,7 +29,6 @@
 #include "qemu-timer.h"
 #include "i8254.h"
 #include "pcspk.h"
-#include "qemu-kvm.h"
 
 #define PCSPK_BUF_LEN 1792
 #define PCSPK_SAMPLE_RATE 32000
@@ -141,9 +140,6 @@ static void pcspk_io_write(void *opaque, target_phys_addr_t addr, uint64_t val,
 {
     PCSpkState *s = opaque;
     const int gate = val & 1;
-    PITChannelInfo ch;
-
-    pit_get_channel_info(s->pit, 2, &ch);
 
     s->data_on = (val >> 1) & 1;
     pit_set_gate(s->pit, 2, gate);
@@ -152,8 +148,6 @@ static void pcspk_io_write(void *opaque, target_phys_addr_t addr, uint64_t val,
             s->play_pos = 0;
         AUD_set_active_out(s->voice, gate & s->data_on);
     }
-
-    /*  kvm_set_pit_ch2(s->pit, &inkernel_state); ?? */
 }
 
 static const MemoryRegionOps pcspk_io_ops = {
Signature · 1 line
1.7.3.4
author
#2 lore raw

PATCH 2/5 qemu-kvm: i8254: Reset broken pit_load_old to upstream version

In reply to Jan Kiszka

pit_load_old is only called with version_id == 1, but PIT_SAVEVM_VERSION is 2. So this function is broken in qemu_kvm for ages, and also the dummy qemu_get_be32 is pointless. Revert to upstream.

---
 hw/i8254.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
hw/i8254.c +1 -2
index 8925139..7089832 100644
@@ -390,10 +390,9 @@ static int pit_load_old(QEMUFile *f, void *opaque, int version_id)
     PITChannelState *s;
     int i;
 
-    if (version_id != PIT_SAVEVM_VERSION)
+    if (version_id != 1)
         return -EINVAL;
 
-    (void)qemu_get_be32(f);
     for(i = 0; i < 3; i++) {
         s = &pit->channels[i];
         s->count=qemu_get_be32(f);
Signature · 1 line
1.7.3.4
author
#3 lore raw

PATCH 3/5 qemu-kvm: i8254: Revert pit_load_count to upstream version

In reply to Jan Kiszka

pit_irq_timer_update now checks generically if a channel IRQ is disabled, so we can drop the hacks from qemu-kvm.

---
 hw/i8254.c |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)
hw/i8254.c +7 -12
index 7089832..befad05 100644
@@ -187,18 +187,13 @@ void pit_get_channel_info(ISADevice *dev, int channel, PITChannelInfo *info)
     info->out = pit_get_out(s, qemu_get_clock_ns(vm_clock));
 }
 
-static inline void pit_load_count(PITState *s, int val, int chan)
+static inline void pit_load_count(PITChannelState *s, int val)
 {
     if (val == 0)
         val = 0x10000;
-    s->channels[chan].count_load_time = qemu_get_clock_ns(vm_clock);
-    s->channels[chan].count = val;
-#ifdef TARGET_I386
-    if (chan == 0 && s->channels[0].irq_disabled) {
-        return;
-    }
-#endif
-    pit_irq_timer_update(&s->channels[chan], s->channels[chan].count_load_time);
+    s->count_load_time = qemu_get_clock_ns(vm_clock);
+    s->count = val;
+    pit_irq_timer_update(s, s->count_load_time);
 }
 
 /* if already latched, do not latch again */
@@ -260,17 +255,17 @@ static void pit_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         switch(s->write_state) {
         default:
         case RW_STATE_LSB:
-            pit_load_count(pit, val, addr);
+            pit_load_count(s, val);
             break;
         case RW_STATE_MSB:
-            pit_load_count(pit, val << 8, addr);
+            pit_load_count(s, 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(pit, s->write_latch | (val << 8), addr);
+            pit_load_count(s, s->write_latch | (val << 8));
             s->write_state = RW_STATE_WORD0;
             break;
         }
Signature · 1 line
1.7.3.4
author
#4 lore raw

PATCH 4/5 qemu-kvm: i8254: Drop bogus irq_disabled clearing in pit_reset

In reply to Jan Kiszka

The IRQ output line is reset along with the HPET (via signaling a new state on the corresponding GPIO line), not the PIT itself.

---
 hw/i8254.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
hw/i8254.c +0 -3
index befad05..ca24ab9 100644
@@ -432,9 +432,6 @@ static void pit_reset(DeviceState *dev)
     PITChannelState *s;
     int i;
 
-#ifdef TARGET_I386
-    pit->channels[0].irq_disabled = 0;
-#endif
     for(i = 0;i < 3; i++) {
         s = &pit->channels[i];
         s->mode = 3;
Signature · 1 line
1.7.3.4
author
#5 lore raw

PATCH 5/5 qemu-kvm: i8254: Reorganize i8254-kvm code

In reply to Jan Kiszka

Include i8254-kvm.c instead of building it as a separate module. This allows to reduce the diff to upstream and will help with merging the latter.

---
 Makefile.target |    1 -
 hw/i8254-kvm.c  |   12 ++++--------
 hw/i8254.c      |   43 +++++++++++++++++++++++++++++++++++++++++--
 hw/i8254.h      |   49 ++-----------------------------------------------
 4 files changed, 47 insertions(+), 58 deletions(-)
Makefile.target +0 -1
index 5f6b963..24386a4 100644
@@ -251,7 +251,6 @@ obj-i386-y += testdev.o
 obj-i386-y += acpi.o acpi_piix4.o
 
 obj-i386-y += i8254.o
-obj-i386-$(CONFIG_KVM_PIT) += i8254-kvm.o
 obj-i386-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += device-assignment.o
 
 # shared objects
hw/i8254-kvm.c +4 -8
index 7316111..e2aa4d6 100644
@@ -21,14 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "hw.h"
-#include "pc.h"
-#include "isa.h"
-#include "qemu-timer.h"
-#include "i8254.h"
-#include "qemu-kvm.h"
 
-extern VMStateDescription vmstate_pit;
+#ifdef CONFIG_KVM_PIT
 
 static void kvm_pit_pre_save(void *opaque)
 {
@@ -103,7 +97,7 @@ static void dummy_timer(void *opaque)
 {
 }
 
-void kvm_pit_init(PITState *pit)
+static void qemu_kvm_pit_init(PITState *pit)
 {
     PITChannelState *s;
 
@@ -116,3 +110,5 @@ void kvm_pit_init(PITState *pit)
     vmstate_pit.post_load = kvm_pit_post_load;
     return;
 }
+
+#endif
hw/i8254.c +41 -2

66 lines not on this page · raw message

hw/i8254.h +2 -47

57 lines not on this page · raw message

Signature · 1 line
1.7.3.4
Applied
#6 lore raw
In reply to Jan Kiszka
Quoted 4 lines · Jan Kiszka

Some preparation patches to arrange qemu-kvm for merging in latest qemu with its own in-kernel PIT support. Later on, we can switch to that version without losing features on the way, even just temporarily.

Thanks, applied.

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