diff mbox

[2/4] KVM: MIPS: Implement GET_CLOCK_FREQ hypercall

Message ID f9d4759bdad2f939e3d28c6a7b4711a60101655e.1486377433.git-series.james.hogan@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

James Hogan Feb. 6, 2017, 10:46 a.m. UTC
Implement the MIPS GET_CLOCK_FREQ hypercall used by paravirtual guest
kernels. When the guest performs this hypercall, the value of count_hz
is returned, which is the current rate of the CP0_Count register.

We also document the hypercall along with the others as the
documentation was never added.

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: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
Cc: David Daney <david.daney@cavium.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: linux-doc@vger.kernel.org
---
 Documentation/virtual/kvm/hypercalls.txt |  6 ++++++
 arch/mips/kvm/hypcall.c                  | 18 +++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/Documentation/virtual/kvm/hypercalls.txt b/Documentation/virtual/kvm/hypercalls.txt
index 8f36582ce2b7..e9f1c9d3da98 100644
--- a/Documentation/virtual/kvm/hypercalls.txt
+++ b/Documentation/virtual/kvm/hypercalls.txt
@@ -86,3 +86,9 @@  the vcpu to sleep until occurrence of an appropriate event. Another vcpu of the
 same guest can wakeup the sleeping vcpu by issuing KVM_HC_KICK_CPU hypercall,
 specifying APIC ID (a1) of the vcpu to be woken up. An additional argument (a0)
 is used in the hypercall for future use.
+
+6. KVM_HC_MIPS_GET_CLOCK_FREQ
+------------------------
+Architecture: mips
+Status: active
+Purpose: Return the frequency of CP0_Count in HZ.
diff --git a/arch/mips/kvm/hypcall.c b/arch/mips/kvm/hypcall.c
index 83063435195f..7c74ec25f2b9 100644
--- a/arch/mips/kvm/hypcall.c
+++ b/arch/mips/kvm/hypcall.c
@@ -32,9 +32,21 @@  enum emulation_result kvm_mips_emul_hypcall(struct kvm_vcpu *vcpu,
 static int kvm_mips_hypercall(struct kvm_vcpu *vcpu, unsigned long num,
 			      const unsigned long *args, unsigned long *hret)
 {
-	/* Report unimplemented hypercall to guest */
-	*hret = -KVM_ENOSYS;
-	return RESUME_GUEST;
+	int ret = RESUME_GUEST;
+
+	switch (num) {
+	case KVM_HC_MIPS_GET_CLOCK_FREQ:
+		/* Return frequency of count/compare timer */
+		*hret = (s32)vcpu->arch.count_hz;
+		break;
+
+	default:
+		/* Report unimplemented hypercall to guest */
+		*hret = -KVM_ENOSYS;
+		break;
+	};
+
+	return ret;
 }
 
 int kvm_mips_handle_hypcall(struct kvm_vcpu *vcpu)