Add HmxConfig and hmx_init_config(), which derive the HMX configuration
from the CPU revision.

Reviewed-by: Marco Liebel <[email protected]>
Signed-off-by: Brian Cain <[email protected]>
---
 target/hexagon/cpu.h        |  8 ++++++++
 target/hexagon/hmx_config.h | 17 +++++++++++++++++
 hw/hexagon/hex-subsys.c     |  7 +++++++
 target/hexagon/cpu.c        | 23 +++++++++++++++++++++++
 target/hexagon/hmx_config.c | 15 +++++++++++++++
 target/hexagon/meson.build  |  1 +
 6 files changed, 71 insertions(+)
 create mode 100644 target/hexagon/hmx_config.h
 create mode 100644 target/hexagon/hmx_config.c

diff --git a/target/hexagon/cpu.h b/target/hexagon/cpu.h
index feb80368238..22aa1630767 100644
--- a/target/hexagon/cpu.h
+++ b/target/hexagon/cpu.h
@@ -30,12 +30,15 @@
 typedef struct HexagonTLBState HexagonTLBState;
 typedef struct HexagonGlobalRegState HexagonGlobalRegState;
 typedef struct HexagonHVXContextState HexagonHVXContextState;
+typedef struct HexagonHMXContextState HexagonHMXContextState;
 
 #include "cpu-qom.h"
 #include "exec/cpu-common.h"
 #include "exec/target_long.h"
 #include "hex_regs.h"
 #include "mmvec/mmvec.h"
+#include "hmx_config.h"
+#include "hmx_state.h"
 #include "hw/core/registerfields.h"
 #include "qemu/bitmap.h"
 
@@ -197,6 +200,8 @@ typedef struct CPUArchState {
     target_ulong vstore_pending[VSTORES_MAX];
     bool vtcm_pending;
     VTCMStoreLog vtcm_log;
+
+    HmxState *hmx_state;
 } CPUHexagonState;
 
 typedef struct HexagonCPUClass {
@@ -217,12 +222,15 @@ struct ArchCPU {
     HexagonCPUConfig cfg;
 #ifndef CONFIG_USER_ONLY
     HexagonHVXContextState *hvx_ctx[HVX_CONTEXTS_MAX];
+    HexagonHMXContextState *hmx_ctx;
     HexagonTLBState *tlb;
     uint32_t boot_addr;
     HexagonGlobalRegState *globalregs;
     uint32_t htid;
     HexL2VicInterface *l2vic;
 #endif
+    HmxState *hmx;
+    HmxConfig hmx_cfg;
 };
 
 static inline HexagonHVXContext *hex_hvx(CPUHexagonState *env)
diff --git a/target/hexagon/hmx_config.h b/target/hexagon/hmx_config.h
new file mode 100644
index 00000000000..cb1433f54b8
--- /dev/null
+++ b/target/hexagon/hmx_config.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_HMX_CONFIG_H
+#define HEXAGON_HMX_CONFIG_H
+
+#include "cpu-qom.h"
+
+typedef struct HmxConfig {
+    bool hmx_present;
+} HmxConfig;
+
+void hmx_init_config(HexagonCPU *cpu);
+
+#endif /* HEXAGON_HMX_CONFIG_H */
diff --git a/hw/hexagon/hex-subsys.c b/hw/hexagon/hex-subsys.c
index 4d9a79cff74..5d227c0db2b 100644
--- a/hw/hexagon/hex-subsys.c
+++ b/hw/hexagon/hex-subsys.c
@@ -187,6 +187,8 @@ void hex_subsys_create(HexagonCommonMachineState *hms,
 
 void hex_subsys_add_cpu(HexagonCommonMachineState *hms, DeviceState *cpu)
 {
+    Object *hmx;
+
     object_property_add_child(OBJECT(hms->cluster), "cpu[*]", OBJECT(cpu));
     object_property_set_link(OBJECT(cpu), "global-regs",
                              OBJECT(hms->glob_regs), &error_fatal);
@@ -200,6 +202,11 @@ void hex_subsys_add_cpu(HexagonCommonMachineState *hms, 
DeviceState *cpu)
 
         object_property_set_link(OBJECT(cpu), name, ctx, &error_fatal);
     }
+    hmx = object_resolve_path_component(OBJECT(hms), "hmx-context");
+    if (hmx) {
+        object_property_set_link(OBJECT(cpu), "hmx-context", hmx,
+                                 &error_fatal);
+    }
 }
 
 void hex_subsys_realize_cluster(HexagonCommonMachineState *hms)
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 281d201250b..83e23775ea2 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -45,6 +45,7 @@
 #include "exec/target_page.h"
 #include "hw/hexagon/hexagon_globalreg.h"
 #include "hw/hexagon/hexagon_hvx_context.h"
+#include "hw/hexagon/hexagon_hmx_context.h"
 #endif
 
 static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model)
@@ -539,6 +540,24 @@ static void hexagon_cpu_realize(DeviceState *dev, Error 
**errp)
 
     cpu->cfg.hex_def = mcc->hex_def;
 
+    hmx_init_config(cpu);
+#ifdef CONFIG_USER_ONLY
+    /* All threads of the process share one HMX unit */
+    static HmxState *user_hmx;
+
+    if (cpu->hmx_cfg.hmx_present) {
+        if (!user_hmx) {
+            user_hmx = g_new0(HmxState, 1);
+        }
+        cpu->hmx = user_hmx;
+    }
+#else
+    if (cpu->hmx_ctx && cpu->hmx_cfg.hmx_present) {
+        cpu->hmx = &cpu->hmx_ctx->regs;
+    }
+#endif
+    cpu_env(cs)->hmx_state = cpu->hmx;
+
     gdb_register_coprocessor(cs, hexagon_hvx_gdb_read_register,
                              hexagon_hvx_gdb_write_register,
                              gdb_find_static_feature("hexagon-hvx.xml"));
@@ -629,6 +648,10 @@ static void hexagon_cpu_init(Object *obj)
                                  qdev_prop_allow_set_link_before_realize,
                                  OBJ_PROP_LINK_STRONG);
     }
+    object_property_add_link(obj, "hmx-context", TYPE_HEXAGON_HMX_CONTEXT,
+                             (Object **)&cpu->hmx_ctx,
+                             qdev_prop_allow_set_link_before_realize,
+                             OBJ_PROP_LINK_STRONG);
 #endif
 }
 
diff --git a/target/hexagon/hmx_config.c b/target/hexagon/hmx_config.c
new file mode 100644
index 00000000000..5dcc7009a95
--- /dev/null
+++ b/target/hexagon/hmx_config.c
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "hmx_config.h"
+
+void hmx_init_config(HexagonCPU *cpu)
+{
+    HexagonVersion ver = cpu->cfg.hex_def->hex_version;
+
+    cpu->hmx_cfg.hmx_present = ver >= HEX_VER_V68;
+}
diff --git a/target/hexagon/meson.build b/target/hexagon/meson.build
index 06338523217..fe3206ef8b8 100644
--- a/target/hexagon/meson.build
+++ b/target/hexagon/meson.build
@@ -254,6 +254,7 @@ hexagon_ss.add(files(
     'mmvec/system_ext_mmvec.c',
     'mmvec/hvx_ieee_fp.c',
     'mmvec/hvx_qfloat.c',
+    'hmx_config.c',
 ))
 
 hexagon_softmmu_ss.add(files(
-- 
2.34.1

Reply via email to