KVM: MIPS: Init timer frequency from callback
authorJames Hogan <james.hogan@imgtec.com>
Tue, 14 Mar 2017 10:15:21 +0000 (10:15 +0000)
committerJames Hogan <james.hogan@imgtec.com>
Tue, 28 Mar 2017 13:53:48 +0000 (14:53 +0100)
Currently the software emulated timer is initialised to a frequency of
100MHz by kvm_mips_init_count(), but this isn't suitable for VZ where
the frequency of the guest timer matches that of the host.

Add a count_hz argument so the caller can specify the default frequency,
and move the call from kvm_arch_vcpu_create() to the implementation
specific vcpu_setup() callback, so that VZ can specify a different
frequency.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
arch/mips/include/asm/kvm_host.h
arch/mips/kvm/emulate.c
arch/mips/kvm/mips.c
arch/mips/kvm/trap_emul.c

index e8843784b784a31218ed42659b256dc459d342cb..f0227c0d27801c3c1174da40977dc6dfbfb5ac28 100644 (file)
@@ -806,7 +806,7 @@ extern enum emulation_result kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu,
 u32 kvm_mips_read_count(struct kvm_vcpu *vcpu);
 void kvm_mips_write_count(struct kvm_vcpu *vcpu, u32 count);
 void kvm_mips_write_compare(struct kvm_vcpu *vcpu, u32 compare, bool ack);
-void kvm_mips_init_count(struct kvm_vcpu *vcpu);
+void kvm_mips_init_count(struct kvm_vcpu *vcpu, unsigned long count_hz);
 int kvm_mips_set_count_ctl(struct kvm_vcpu *vcpu, s64 count_ctl);
 int kvm_mips_set_count_resume(struct kvm_vcpu *vcpu, s64 count_resume);
 int kvm_mips_set_count_hz(struct kvm_vcpu *vcpu, s64 count_hz);
index d75ab8940e1fc562a52e9159ba8e57ef5625b1c2..f09a161926e709c44a1c7c4d869bab32b9fcaf93 100644 (file)
@@ -543,16 +543,15 @@ void kvm_mips_write_count(struct kvm_vcpu *vcpu, u32 count)
 /**
  * kvm_mips_init_count() - Initialise timer.
  * @vcpu:      Virtual CPU.
+ * @count_hz:  Frequency of timer.
  *
- * Initialise the timer to a sensible frequency, namely 100MHz, zero it, and set
- * it going if it's enabled.
+ * Initialise the timer to the specified frequency, zero it, and set it going if
+ * it's enabled.
  */
-void kvm_mips_init_count(struct kvm_vcpu *vcpu)
+void kvm_mips_init_count(struct kvm_vcpu *vcpu, unsigned long count_hz)
 {
-       /* 100 MHz */
-       vcpu->arch.count_hz = 100*1000*1000;
-       vcpu->arch.count_period = div_u64((u64)NSEC_PER_SEC << 32,
-                                         vcpu->arch.count_hz);
+       vcpu->arch.count_hz = count_hz;
+       vcpu->arch.count_period = div_u64((u64)NSEC_PER_SEC << 32, count_hz);
        vcpu->arch.count_dyn_bias = 0;
 
        /* Starting at 0 */
index 476ece99bf3be4a049312707bb651229ea7f4508..36561df8a7a792985b2e6c2be17ccc7d1db59574 100644 (file)
@@ -372,9 +372,6 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
        /* Init */
        vcpu->arch.last_sched_cpu = -1;
 
-       /* Start off the timer */
-       kvm_mips_init_count(vcpu);
-
        return vcpu;
 
 out_free_gebase:
index 3a854bb9e606be2a3661273b477ddb75bd408976..0e3d260aafcb5e3422c9fe59c644c6db7cf89019 100644 (file)
@@ -565,6 +565,9 @@ static int kvm_trap_emul_vcpu_setup(struct kvm_vcpu *vcpu)
        u32 config, config1;
        int vcpu_id = vcpu->vcpu_id;
 
+       /* Start off the timer at 100 MHz */
+       kvm_mips_init_count(vcpu, 100*1000*1000);
+
        /*
         * Arch specific stuff, set up config registers properly so that the
         * guest will come up as expected