Add a sysbus device that owns the HMX state.  A core has one HMX unit
shared by all its threads.

Reviewed-by: Marco Liebel <[email protected]>
Signed-off-by: Brian Cain <[email protected]>
---
 include/hw/hexagon/hexagon.h             |  5 +++
 include/hw/hexagon/hexagon_hmx_context.h | 24 ++++++++++++++
 hw/hexagon/hex-subsys.c                  | 16 ++++++++++
 hw/hexagon/hexagon_hmx_context.c         | 40 ++++++++++++++++++++++++
 hw/hexagon/meson.build                   |  1 +
 5 files changed, 86 insertions(+)
 create mode 100644 include/hw/hexagon/hexagon_hmx_context.h
 create mode 100644 hw/hexagon/hexagon_hmx_context.c

diff --git a/include/hw/hexagon/hexagon.h b/include/hw/hexagon/hexagon.h
index 678e658a6d3..c45c2befa50 100644
--- a/include/hw/hexagon/hexagon.h
+++ b/include/hw/hexagon/hexagon.h
@@ -40,6 +40,11 @@ typedef enum {
 #define HEXAGON_LATEST_REV v85
 #define HEXAGON_LATEST_REV_UPPER V85
 
+#define HEXAGON_COPROC_HMX (1U << 2)
+
+#define HEXAGON_CFGTABLE_HAS_HMX(t) \
+    ((t)->coproc2_reg0 != 0 || ((t)->coproc_present & HEXAGON_COPROC_HMX))
+
 /*
  * Config table address bases represent bits [35:16].
  */
diff --git a/include/hw/hexagon/hexagon_hmx_context.h 
b/include/hw/hexagon/hexagon_hmx_context.h
new file mode 100644
index 00000000000..8ded9ad385d
--- /dev/null
+++ b/include/hw/hexagon/hexagon_hmx_context.h
@@ -0,0 +1,24 @@
+/*
+ * Hexagon HMX Extension Context QOM Object
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_HMX_CONTEXT_H
+#define HEXAGON_HMX_CONTEXT_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+#include "target/hexagon/hmx_state.h"
+
+#define TYPE_HEXAGON_HMX_CONTEXT "hexagon-hmx-context"
+OBJECT_DECLARE_SIMPLE_TYPE(HexagonHMXContextState, HEXAGON_HMX_CONTEXT)
+
+struct HexagonHMXContextState {
+    SysBusDevice parent_obj;
+
+    HmxState regs;
+};
+
+#endif /* HEXAGON_HMX_CONTEXT_H */
diff --git a/hw/hexagon/hex-subsys.c b/hw/hexagon/hex-subsys.c
index 1e6578255eb..4d9a79cff74 100644
--- a/hw/hexagon/hex-subsys.c
+++ b/hw/hexagon/hex-subsys.c
@@ -10,6 +10,7 @@
 #include "hw/hexagon/hex-subsys.h"
 #include "hw/hexagon/hexagon_globalreg.h"
 #include "hw/hexagon/hexagon_hvx_context.h"
+#include "hw/hexagon/hexagon_hmx_context.h"
 #include "hw/hexagon/hexagon_tlb.h"
 #include "hw/intc/hex-l2vic.h"
 #include "hw/timer/qct-qtimer.h"
@@ -120,6 +121,20 @@ static void hvx_contexts_create(HexagonCommonMachineState 
*hms,
     hms->num_hvx_ctx = n;
 }
 
+static void hmx_context_create(HexagonCommonMachineState *hms,
+                               const struct hexagon_machine_config *m_cfg)
+{
+    DeviceState *ctx;
+
+    if (!HEXAGON_CFGTABLE_HAS_HMX(&m_cfg->cfgtable)) {
+        return;
+    }
+
+    ctx = qdev_new(TYPE_HEXAGON_HMX_CONTEXT);
+    object_property_add_child(OBJECT(hms), "hmx-context", OBJECT(ctx));
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(ctx), &error_fatal);
+}
+
 static DeviceState *cluster_create(HexagonCommonMachineState *hms)
 {
     DeviceState *cluster = qdev_new(TYPE_CPU_CLUSTER);
@@ -167,6 +182,7 @@ void hex_subsys_create(HexagonCommonMachineState *hms,
     hms->glob_regs = globalreg_create(hms, m_cfg, rev);
     hms->tlb = tlb_create(hms, m_cfg);
     hvx_contexts_create(hms, m_cfg);
+    hmx_context_create(hms, m_cfg);
 }
 
 void hex_subsys_add_cpu(HexagonCommonMachineState *hms, DeviceState *cpu)
diff --git a/hw/hexagon/hexagon_hmx_context.c b/hw/hexagon/hexagon_hmx_context.c
new file mode 100644
index 00000000000..e3ea7b71474
--- /dev/null
+++ b/hw/hexagon/hexagon_hmx_context.c
@@ -0,0 +1,40 @@
+/*
+ * Hexagon HMX Extension Context QOM Object
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/hexagon/hexagon_hmx_context.h"
+
+static void hexagon_hmx_context_reset_hold(Object *obj, ResetType type)
+{
+    HexagonHMXContextState *s = HEXAGON_HMX_CONTEXT(obj);
+
+    memset(&s->regs, 0, sizeof(s->regs));
+}
+
+static void hexagon_hmx_context_class_init(ObjectClass *klass,
+                                           const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+
+    rc->phases.hold = hexagon_hmx_context_reset_hold;
+    dc->user_creatable = false;
+}
+
+static const TypeInfo hexagon_hmx_context_info = {
+    .name = TYPE_HEXAGON_HMX_CONTEXT,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(HexagonHMXContextState),
+    .class_init = hexagon_hmx_context_class_init,
+};
+
+static void hexagon_hmx_context_register_types(void)
+{
+    type_register_static(&hexagon_hmx_context_info);
+}
+
+type_init(hexagon_hmx_context_register_types)
diff --git a/hw/hexagon/meson.build b/hw/hexagon/meson.build
index fa5bc5eb9f1..e7abad1c234 100644
--- a/hw/hexagon/meson.build
+++ b/hw/hexagon/meson.build
@@ -2,6 +2,7 @@ hexagon_ss = ss.source_set()
 hexagon_ss.add(files('hexagon_tlb.c'))
 hexagon_ss.add(files('hexagon_globalreg.c'))
 hexagon_ss.add(files('hexagon_hvx_context.c'))
+hexagon_ss.add(files('hexagon_hmx_context.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hex-subsys.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_BOARD', if_true: files('hex-board.c'))
-- 
2.34.1

Reply via email to