Add an interface for TCG engines to register their tcg_enabled()
function for addition to a global list. Each TCG engine will
register and then two functions, tcg_any_enabled() & tcg_all_enabled()
can be used to query the overall tcg enablement state.

Signed-off-by: Peter Crosthwaite <crosthwaite.pe...@gmail.com>
---

 include/qemu-common.h |  5 +++++
 translate-all.c       |  5 +++++
 translate-common.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)

diff --git a/include/qemu-common.h b/include/qemu-common.h
index abb2030..a458e92 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -311,6 +311,11 @@ typedef struct PCIHostDeviceAddress {
 
 void tcg_exec_init_add(void (*fn)(unsigned long));
 void tcg_exec_init(unsigned long tb_size);
+
+void tcg_enabled_add(bool (*fn)(void));
+bool tcg_any_enabled(void);
+bool tcg_all_enabled(void);
+
 bool tcg_enabled(void);
 
 void cpu_exec_init_all(void);
diff --git a/translate-all.c b/translate-all.c
index 7532fe3..fb81a2f 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -703,6 +703,11 @@ bool tcg_enabled(void)
     return tcg_ctx.code_gen_buffer != NULL;
 }
 
+static __attribute__((constructor)) void register_tcg_enabled(void)
+{
+    tcg_enabled_add(tcg_enabled);
+}
+
 /* Allocate a new translation block. Flush the translation buffer if
    too many translation blocks or too much generated code. */
 static TranslationBlock *tb_alloc(target_ulong pc)
diff --git a/translate-common.c b/translate-common.c
index 339aac2..d6d04db 100644
--- a/translate-common.c
+++ b/translate-common.c
@@ -85,3 +85,46 @@ void tcg_exec_init(unsigned long tb_size)
         t->do_tcg_exec_init(tb_size);
     }
 }
+
+typedef struct TCGEnabledFn {
+    bool (*do_tcg_enabled)(void);
+    QLIST_ENTRY(TCGEnabledFn) list;
+} TCGEnabledFn;
+
+static QLIST_HEAD(, TCGEnabledFn) tcg_enabled_fn_list;
+
+void tcg_enabled_add(bool (*fn)(void))
+{
+    static bool inited;
+    TCGEnabledFn *lelem = g_malloc0(sizeof *lelem);
+
+    if (!inited) {
+        inited = true;
+        QLIST_INIT(&tcg_enabled_fn_list);
+    }
+
+    lelem->do_tcg_enabled = fn;
+    QLIST_INSERT_HEAD(&tcg_enabled_fn_list, lelem, list);
+}
+
+static inline bool tcg_any_all_enabled(bool all)
+{
+    TCGEnabledFn *t;
+
+    QLIST_FOREACH(t, &tcg_enabled_fn_list, list) {
+        if (t->do_tcg_enabled() != all) {
+            return !all;
+        }
+    }
+    return all;
+}
+
+bool tcg_any_enabled(void)
+{
+    return tcg_any_all_enabled(false);
+}
+
+bool tcg_all_enabled(void)
+{
+    return tcg_any_all_enabled(true);
+}
-- 
1.9.1


Reply via email to