[PATCH 09/16] qemu-kvm: Implement kvm_has_pit_state2 in upstream style

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 hw/i8254-kvm.c |    4 ++--
 hw/i8254.c     |    4 ++--
 kvm-all.c      |   11 +++++++++++
 kvm-stub.c     |    5 +++++
 kvm.h          |    1 +
 qemu-kvm-x86.c |   12 +-----------
 qemu-kvm.c     |    5 +++++
 qemu-kvm.h     |   15 +--------------
 8 files changed, 28 insertions(+), 29 deletions(-)

diff --git a/hw/i8254-kvm.c b/hw/i8254-kvm.c
index b495dc1..44ed86c 100644
--- a/hw/i8254-kvm.c
+++ b/hw/i8254-kvm.c
@@ -38,7 +38,7 @@ static void kvm_pit_pre_save(void *opaque)
     struct PITChannelState *sc;
     int i;
 
-    if(qemu_kvm_has_pit_state2()) {
+    if (kvm_has_pit_state2()) {
         kvm_get_pit2(kvm_context, &pit2);
         s->flags = pit2.flags;
     } else {
@@ -91,7 +91,7 @@ static int kvm_pit_post_load(void *opaque, int version_id)
 	c->count_load_time = sc->count_load_time;
     }
 
-    if(qemu_kvm_has_pit_state2()) {
+    if (kvm_has_pit_state2()) {
         kvm_set_pit2(kvm_context, &pit2);
     } else {
         kvm_set_pit(kvm_context, (struct kvm_pit_state *)&pit2);
diff --git a/hw/i8254.c b/hw/i8254.c
index 43ac106..33974db 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -497,7 +497,7 @@ void hpet_pit_disable(void)
     PITChannelState *s = &pit_state.channels[0];
 
     if (kvm_enabled() && kvm_pit_in_kernel()) {
-        if (qemu_kvm_has_pit_state2()) {
+        if (kvm_has_pit_state2()) {
             kvm_hpet_disable_kpit();
         } else {
              fprintf(stderr, "%s: kvm does not support pit_state2!\n", __FUNCTION__);
@@ -521,7 +521,7 @@ void hpet_pit_enable(void)
     PITChannelState *s = &pit->channels[0];
 
     if (kvm_enabled() && kvm_pit_in_kernel()) {
-        if (qemu_kvm_has_pit_state2()) {
+        if (kvm_has_pit_state2()) {
             kvm_hpet_enable_kpit();
         } else {
              fprintf(stderr, "%s: kvm does not support pit_state2!\n", __FUNCTION__);
diff --git a/kvm-all.c b/kvm-all.c
index d936d35..9463341 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -82,6 +82,7 @@ struct KVMState
     int pit_in_kernel;
     int xsave, xcrs;
     int many_ioeventfds;
+    int pit_state2;
 };
 
 KVMState *kvm_state;
@@ -783,6 +784,11 @@ int kvm_init(void)
     s->xcrs = kvm_check_extension(s, KVM_CAP_XCRS);
 #endif
 
+    s->pit_state2 = 0;
+#ifdef KVM_CAP_PIT_STATE2
+    s->pit_state2 = kvm_check_extension(s, KVM_CAP_PIT_STATE2);
+#endif
+
     ret = kvm_arch_init(s);
     if (ret < 0) {
         goto err;
@@ -1113,6 +1119,11 @@ int kvm_has_xcrs(void)
     return kvm_state->xcrs;
 }
 
+int kvm_has_pit_state2(void)
+{
+    return kvm_state->pit_state2;
+}
+
 int kvm_has_many_ioeventfds(void)
 {
     if (!kvm_enabled()) {
diff --git a/kvm-stub.c b/kvm-stub.c
index 4f1f7d3..90fed66 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -98,6 +98,11 @@ int kvm_allows_irq0_override(void)
     return 1;
 }
 
+int kvm_has_pit_state2(void)
+{
+    return 0;
+}
+
 void kvm_setup_guest_memory(void *start, size_t size)
 {
 }
diff --git a/kvm.h b/kvm.h
index 4ba5465..7d548ed 100644
--- a/kvm.h
+++ b/kvm.h
@@ -56,6 +56,7 @@ int kvm_has_debugregs(void);
 int kvm_has_xsave(void);
 int kvm_has_xcrs(void);
 int kvm_has_many_ioeventfds(void);
+int kvm_has_pit_state2(void);
 
 #ifdef NEED_CPU_H
 int kvm_init_vcpu(CPUState *env);
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 53083bd..bbdf218 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -178,16 +178,6 @@ int kvm_set_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2)
 #endif
 #endif
 
-int kvm_has_pit_state2(kvm_context_t kvm)
-{
-    int r = 0;
-
-#ifdef KVM_CAP_PIT_STATE2
-    r = kvm_check_extension(kvm_state, KVM_CAP_PIT_STATE2);
-#endif
-    return r;
-}
-
 static void kvm_set_cr8(CPUState *env, uint64_t cr8)
 {
     env->kvm_run->cr8 = cr8;
@@ -328,7 +318,7 @@ int kvm_arch_init_irq_routing(void)
         }
         kvm_commit_irq_routes();
 
-        if (!qemu_kvm_has_pit_state2()) {
+        if (!kvm_has_pit_state2()) {
             no_hpet = 1;
         }
     } else {
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 48c92e6..98bb765 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1428,6 +1428,11 @@ static int kvm_create_context(void)
 
     kvm_state->many_ioeventfds = kvm_check_many_ioeventfds();
 
+    kvm_state->pit_state2 = 0;
+#ifdef KVM_CAP_PIT_STATE2
+    kvm_state->pit_state2 = kvm_check_extension(kvm_state, KVM_CAP_PIT_STATE2);
+#endif
+
     kvm_init_ap();
 
     return 0;
diff --git a/qemu-kvm.h b/qemu-kvm.h
index cd9bb37..b101c03 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -185,14 +185,6 @@ int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);
 
 #ifdef KVM_CAP_PIT_STATE2
 /*!
- * \brief Check for kvm support of kvm_pit_state2
- *
- * \param kvm Pointer to the current kvm_context
- * \return 0 on success
- */
-int kvm_has_pit_state2(kvm_context_t kvm);
-
-/*!
  * \brief Set in kernel PIT state2 of the virtual domain
  *
  *
@@ -407,14 +399,8 @@ int kvm_arch_halt(CPUState *env);
 int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip,
                       int is_write);
 
-#ifdef TARGET_I386
-#define qemu_kvm_has_pit_state2() kvm_has_pit_state2(kvm_context)
-#endif
 #else
 #define kvm_nested 0
-#ifdef TARGET_I386
-#define qemu_kvm_has_pit_state2() (0)
-#endif
 #endif
 
 #ifdef CONFIG_KVM
@@ -449,6 +435,7 @@ struct KVMState {
     int pit_in_kernel;
     int xsave, xcrs;
     int many_ioeventfds;
+    int pit_state2;
 
     struct kvm_context kvm_context;
 };
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux