]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
x86: switch xen implementation to use hypervisor framework
authorWei Liu <liuwe@microsoft.com>
Mon, 30 Sep 2019 13:05:09 +0000 (14:05 +0100)
committerWei Liu <liuwe@microsoft.com>
Tue, 5 Nov 2019 11:19:52 +0000 (11:19 +0000)
Take the chance to change probe_hypervisor to hypervisor_probe.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
Reviewed-by: Paul Durrant <paul@xen.org>
---
V3:
1. Address Roger's comments
2. Change xen_hypervisor_ops to xen_ops

xen/arch/x86/guest/hypervisor.c
xen/arch/x86/guest/xen/pvh-boot.c
xen/arch/x86/guest/xen/xen.c
xen/arch/x86/setup.c
xen/include/asm-x86/guest/xen.h

index 89b9ae4de0d26d4b94b54dda6f88fabe2c321fb7..33bf1a769d9a89de5501197867451a1480c3195d 100644 (file)
@@ -22,7 +22,7 @@
 #include <xen/types.h>
 
 #include <asm/cache.h>
-#include <asm/guest/hypervisor.h>
+#include <asm/guest.h>
 
 static struct hypervisor_ops *hops __read_mostly;
 
@@ -31,9 +31,39 @@ bool hypervisor_probe(void)
     if ( hops )
         return true;
 
+    /* Too early to use cpu_has_hypervisor */
+    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
+        return false;
+
+#ifdef CONFIG_XEN_GUEST
+    if ( xen_probe() )
+    {
+        hops = &xen_ops;
+        return true;
+    }
+#endif
+
     return false;
 }
 
+void hypervisor_setup(void)
+{
+    if ( hops && hops->setup )
+        hops->setup();
+}
+
+void hypervisor_ap_setup(void)
+{
+    if ( hops && hops->ap_setup )
+        hops->ap_setup();
+}
+
+void hypervisor_resume(void)
+{
+    if ( hops && hops->resume )
+        hops->resume();
+}
+
 /*
  * Local variables:
  * mode: C
index ca8e156f7dc388e768e254dd4b194e375937c008..498625eae0a3f065c41366aa8b51c2e571c6ca63 100644 (file)
@@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod)
 {
     convert_pvh_info(mbi, mod);
 
-    probe_hypervisor();
+    hypervisor_probe();
     ASSERT(xen_guest);
 
     get_memory_map();
index 9895025d027e3800982aa1dab22548dd87304ce5..655435c1f7bf098045391114c717a975a68b08a0 100644 (file)
@@ -67,24 +67,19 @@ static void __init find_xen_leaves(void)
     }
 }
 
-void __init probe_hypervisor(void)
+bool __init xen_probe(void)
 {
-    if ( xen_guest )
-        return;
-
-    /* Too early to use cpu_has_hypervisor */
-    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
-        return;
-
     find_xen_leaves();
 
     if ( !xen_cpuid_base )
-        return;
+        return false;
 
     /* Fill the hypercall page. */
     wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
 
     xen_guest = true;
+
+    return true;
 }
 
 static void map_shared_info(void)
@@ -249,7 +244,7 @@ static void init_evtchn(void)
     }
 }
 
-void __init hypervisor_setup(void)
+static void __init xen_setup(void)
 {
     init_memmap();
 
@@ -277,7 +272,7 @@ void __init hypervisor_setup(void)
     init_evtchn();
 }
 
-void hypervisor_ap_setup(void)
+static void xen_ap_setup(void)
 {
     set_vcpu_id();
     map_vcpuinfo();
@@ -307,7 +302,7 @@ static void ap_resume(void *unused)
     init_evtchn();
 }
 
-void hypervisor_resume(void)
+static void xen_resume(void)
 {
     /* Reset shared info page. */
     map_shared_info();
@@ -330,6 +325,13 @@ void hypervisor_resume(void)
         pv_console_init();
 }
 
+struct hypervisor_ops xen_ops = {
+    .name = "Xen",
+    .setup = xen_setup,
+    .ap_setup = xen_ap_setup,
+    .resume = xen_resume,
+};
+
 /*
  * Local variables:
  * mode: C
index dec60d03019cd43da17fc1b5d7d7e2628bcf8ace..0ee11b15a6ac83fbef731f59303f2b5f34451d85 100644 (file)
@@ -763,7 +763,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
      * allocing any xenheap structures wanted in lower memory. */
     kexec_early_calculations();
 
-    probe_hypervisor();
+    hypervisor_probe();
 
     parse_video_info();
 
index 8221fc132506bf6b91da746628438049ca7e3729..c3c6bea24f9702ed44f37270e7c5f9438e96be99 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <asm/e820.h>
 #include <asm/fixmap.h>
+#include <asm/guest/hypervisor.h>
 
 #define XEN_shared_info ((struct shared_info *)fix_to_virt(FIX_XEN_SHARED_INFO))
 
@@ -31,8 +32,9 @@
 extern bool xen_guest;
 extern bool pv_console;
 extern uint32_t xen_cpuid_base;
+extern struct hypervisor_ops xen_ops;
 
-void probe_hypervisor(void);
+bool xen_probe(void);
 int xen_alloc_unused_page(mfn_t *mfn);
 int xen_free_unused_page(mfn_t mfn);
 
@@ -44,7 +46,7 @@ DECLARE_PER_CPU(struct vcpu_info *, vcpu_info);
 #define xen_guest 0
 #define pv_console 0
 
-static inline void probe_hypervisor(void) {}
+static inline bool xen_probe(void) { return false; }
 
 #endif /* CONFIG_XEN_GUEST */
 #endif /* __X86_GUEST_XEN_H__ */