KVM: Add reset support for in kernel PIT
authorSheng Yang <sheng.yang@intel.com>
Thu, 13 Mar 2008 02:22:26 +0000 (10:22 +0800)
committerAvi Kivity <avi@qumranet.com>
Sun, 27 Apr 2008 09:00:23 +0000 (12:00 +0300)
Separate the reset part and prepare for reset support.

Signed-off-by: Sheng Yang <sheng.yang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
arch/x86/kvm/i8254.c
arch/x86/kvm/i8254.h

index 8642f9d1206ad6025f3e4d40e66bb9ca9f233334..9f118e2f350d656d423530c3a8b5a1c5a55d0b7f 100644 (file)
@@ -478,12 +478,28 @@ static int speaker_in_range(struct kvm_io_device *this, gpa_t addr)
        return (addr == KVM_SPEAKER_BASE_ADDRESS);
 }
 
-struct kvm_pit *kvm_create_pit(struct kvm *kvm)
+void kvm_pit_reset(struct kvm_pit *pit)
 {
        int i;
+       struct kvm_kpit_channel_state *c;
+
+       mutex_lock(&pit->pit_state.lock);
+       for (i = 0; i < 3; i++) {
+               c = &pit->pit_state.channels[i];
+               c->mode = 0xff;
+               c->gate = (i != 2);
+               pit_load_count(pit->kvm, i, 0);
+       }
+       mutex_unlock(&pit->pit_state.lock);
+
+       atomic_set(&pit->pit_state.pit_timer.pending, 0);
+       pit->pit_state.inject_pending = 1;
+}
+
+struct kvm_pit *kvm_create_pit(struct kvm *kvm)
+{
        struct kvm_pit *pit;
        struct kvm_kpit_state *pit_state;
-       struct kvm_kpit_channel_state *c;
 
        pit = kzalloc(sizeof(struct kvm_pit), GFP_KERNEL);
        if (!pit)
@@ -512,17 +528,9 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm)
        pit_state->pit = pit;
        hrtimer_init(&pit_state->pit_timer.timer,
                     CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
-       atomic_set(&pit_state->pit_timer.pending, 0);
-       for (i = 0; i < 3; i++) {
-               c = &pit_state->channels[i];
-               c->mode = 0xff;
-               c->gate = (i != 2);
-               pit_load_count(kvm, i, 0);
-       }
-
        mutex_unlock(&pit->pit_state.lock);
 
-       pit->pit_state.inject_pending = 1;
+       kvm_pit_reset(pit);
 
        return pit;
 }
index fe09eced7783bc02954d9bc0573d65488ee6d762..db25c2a6c8c4a612afedd77a9c93d3378230ab33 100644 (file)
@@ -58,5 +58,6 @@ void kvm_pit_timer_intr_post(struct kvm_vcpu *vcpu, int vec);
 void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val);
 struct kvm_pit *kvm_create_pit(struct kvm *kvm);
 void kvm_free_pit(struct kvm *kvm);
+void kvm_pit_reset(struct kvm_pit *pit);
 
 #endif