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.ho...@imgtec.com>
Cc: Paolo Bonzini <pbonz...@redhat.com>
Cc: "Radim Krčmář" <rkrc...@redhat.com>
Cc: Ralf Baechle <r...@linux-mips.org>
Cc: Andreas Herrmann <andreas.herrm...@caviumnetworks.com>
Cc: David Daney <david.da...@cavium.com>
Cc: Jonathan Corbet <cor...@lwn.net>
Cc: linux-m...@linux-mips.org
Cc: k...@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 --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)
-- 
git-series 0.8.10
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to