qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH v2 4/5] hax: simplify init


From: Vincent Palatin
Subject: [Qemu-devel] [PATCH v2 4/5] hax: simplify init
Date: Fri, 11 Nov 2016 12:28:34 +0100

remove the leftovers from the Android specific code,
and use the AccelClass allowed field as expected.
then we can simplify the remaining logic and remove the hax_pre_init
callback.

Signed-off-by: Vincent Palatin <address@hidden>
---
 hax-stub.c                | 15 ---------------
 include/sysemu/hax.h      |  4 ----
 target-i386/hax-all.c     | 49 ++++++++++++-----------------------------------
 target-i386/hax-windows.c | 20 -------------------
 4 files changed, 12 insertions(+), 76 deletions(-)

diff --git a/hax-stub.c b/hax-stub.c
index 0e756a3..a532dba 100644
--- a/hax-stub.c
+++ b/hax-stub.c
@@ -23,21 +23,6 @@ int hax_sync_vcpus(void)
     return 0;
 }
 
-void hax_disable(int disable)
-{
-   return;
-}
-
-int hax_pre_init(uint64_t ram_size)
-{
-   return 0;
-}
-
-int hax_get_max_ram(uint64_t *max_ram)
-{
-    return 0;
-}
-
 int hax_populate_ram(uint64_t va, uint32_t size)
 {
     return -ENOSYS;
diff --git a/include/sysemu/hax.h b/include/sysemu/hax.h
index 50b3fc4..51c8fd5 100644
--- a/include/sysemu/hax.h
+++ b/include/sysemu/hax.h
@@ -25,13 +25,9 @@
 #include "config-host.h"
 #include "qemu-common.h"
 
-int hax_pre_init(uint64_t ram_size);
 int hax_sync_vcpus(void);
-void hax_disable(int disable);
 int hax_init_vcpu(CPUState *cpu);
 int hax_smp_cpu_exec(CPUState *cpu);
-/* get the max haxm ram even before haxm library is initialized */
-int hax_get_max_ram(uint64_t *max_ram);
 int hax_populate_ram(uint64_t va, uint32_t size);
 
 void hax_cpu_synchronize_state(CPUState *cpu);
diff --git a/target-i386/hax-all.c b/target-i386/hax-all.c
index ad5414c..007178d 100644
--- a/target-i386/hax-all.c
+++ b/target-i386/hax-all.c
@@ -36,6 +36,7 @@
 #include "exec/address-spaces.h"
 #include "qemu/main-loop.h"
 #include "hax-slot.h"
+#include "hw/boards.h"
 
 static const char kHaxVcpuSyncFailed[] = "Failed to sync HAX vcpu context";
 #define derror(msg) do { fprintf(stderr, (msg)); } while (0)
@@ -66,7 +67,7 @@ const uint32_t hax_min_version = 0x3;
 #define HAX_EMULATE_STATE_NONE  0x3
 #define HAX_EMULATE_STATE_INITIAL       0x4
 
-bool hax_allowed;
+static bool hax_allowed;
 
 static void hax_vcpu_sync_state(CPUArchState *env, int modified);
 static int hax_arch_get_registers(CPUArchState *env);
@@ -75,20 +76,11 @@ static int hax_handle_io(CPUArchState *env, uint32_t df, 
uint16_t port,
 static int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft);
 
 struct hax_state hax_global;
-int ret_hax_init;
-static int hax_disabled = 1;
-
-int hax_support = -1;
 
 /* Called after hax_init */
 int hax_enabled(void)
 {
-    return !hax_disabled && hax_support;
-}
-
-void hax_disable(int disable)
-{
-    hax_disabled = disable;
+    return hax_allowed;
 }
 
 static int hax_prepare_emulation(CPUArchState *env)
@@ -456,32 +448,17 @@ static void hax_handle_interrupt(CPUState *cpu, int mask)
     }
 }
 
-int hax_pre_init(uint64_t ram_size)
-{
-    struct hax_state *hax = NULL;
-
-    fprintf(stdout, "Hax is %s\n", hax_disabled ? "disabled" : "enabled");
-    if (hax_disabled) {
-        return 0;
-    }
-    hax = &hax_global;
-    memset(hax, 0, sizeof(struct hax_state));
-    hax->mem_quota = ram_size;
-    fprintf(stdout, "Hax ram_size 0x%llx\n", ram_size);
-
-    return 0;
-}
-
-static int hax_init(void)
+static int hax_init(ram_addr_t ram_size)
 {
     struct hax_state *hax = NULL;
     struct hax_qemu_version qversion;
     int ret;
 
-    hax_support = 0;
-
     hax = &hax_global;
 
+    memset(hax, 0, sizeof(struct hax_state));
+    hax->mem_quota = ram_size;
+
     hax->fd = hax_mod_open();
     if (hax_invalid_fd(hax->fd)) {
         hax->fd = 0;
@@ -519,7 +496,6 @@ static int hax_init(void)
     qversion.min_version = hax_min_version;
     hax_notify_qemu_version(hax->vm->fd, &qversion);
     cpu_interrupt_handler = hax_handle_interrupt;
-    hax_support = 1;
 
     return ret;
   error:
@@ -535,17 +511,16 @@ static int hax_init(void)
 
 static int hax_accel_init(MachineState *ms)
 {
-    ret_hax_init = hax_init();
+    int ret = hax_init(ms->ram_size);
 
-    if (ret_hax_init && (ret_hax_init != -ENOSPC)) {
+    if (ret && (ret != -ENOSPC)) {
         fprintf(stderr, "No accelerator found.\n");
-        return ret_hax_init;
     } else {
         fprintf(stdout, "HAX is %s and emulator runs in %s mode.\n",
-                !ret_hax_init ? "working" : "not working",
-                !ret_hax_init ? "fast virt" : "emulation");
-        return 0;
+                !ret ? "working" : "not working",
+                !ret ? "fast virt" : "emulation");
     }
+    return ret;
 }
 
 static int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft)
diff --git a/target-i386/hax-windows.c b/target-i386/hax-windows.c
index 194ac1c..71c230d 100644
--- a/target-i386/hax-windows.c
+++ b/target-i386/hax-windows.c
@@ -54,26 +54,6 @@ static int hax_open_device(hax_fd *fd)
     return 0;
 }
 
-int hax_get_max_ram(uint64_t *max_ram)
-{
-    DWORD dSize = 0;
-    struct hax_capabilityinfo cap;
-    hax_fd fd = hax_mod_open();
-    if (fd == NULL) {
-        return -1;
-    }
-    int result = DeviceIoControl(fd, HAX_IOCTL_CAPABILITY, NULL, 0, &cap,
-                          sizeof(cap), &dSize, (LPOVERLAPPED) NULL);
-    CloseHandle(fd);
-
-    if (!result) {
-        return -2;
-    }
-    *max_ram = cap.mem_quota;
-
-    return 0;
-}
-
 /* hax_fd hax_mod_open */
  hax_fd hax_mod_open(void)
 {
-- 
2.8.0.rc3.226.g39d4020




reply via email to

[Prev in Thread] Current Thread [Next in Thread]