Skip to contentSkip to conversation

Hexagon system emulation - Part 3/3

PATCH Superseded Brian Cain 4 participants 36 messages Apr 16 – Apr 21 Arm/Amlogic Meson SoC support

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

v5 cover Hexagon system emulation - Part 3/3

This is Part 3 of the Hexagon system emulation series. It adds the board-level support, machine definitions, and build infrastructure needed to run hexagon-softmmu.

This includes:
- Global register model (QOM device for shared system registers)
- Global register tracing
- Machine configuration definitions (v66g, v68n, sa8775-cdsp0)
- cfgbase support
- Hexagon "virt" machine definition
- Build configuration for hexagon-softmmu target
- Boot serial test for hexagon

Based on Part 1 v6 + Part 2 v4.

Changes since v4:
- Removed empty hexagon_globalreg_realize() stub and its dc->realize assignment
- Changed virt machine default CPU from v73 to v68 to match the machine config
- Removed unnecessary "depends on TCG" from HEX_DSP Kconfig
- Removed unused "imply PTIMER" from HEX_DSP Kconfig
- Removed stale #include "exec/target_page.h" from translate.c

Previous versions:
- v4: https://lore.kernel.org/qemu-devel/[email protected]/
- v3: https://lore.kernel.org/qemu-devel/[email protected]/
- v2: https://lore.kernel.org/qemu-devel/[email protected]/
- v1: https://lore.kernel.org/qemu-devel/[email protected]/

Related series:
- Part 1 v6: https://lore.kernel.org/qemu-devel/[email protected]/
- Part 2 v4: https://lore.kernel.org/qemu-devel/[email protected]/

Brian Cain (8):
hw/hexagon: Add globalreg model
hw/hexagon: Add global register tracing
hw/hexagon: Add machine configs for sysemu
hw/hexagon: Add v68, sa8775-cdsp0 defs
hw/hexagon: Modify "Standalone" symbols
target/hexagon: add build config for softmmu
hw/hexagon: Define hexagon "virt" machine
tests/qtest: Add hexagon boot-serial-test

Sid Manning (1):
hw/hexagon: Add support for cfgbase

 MAINTAINERS                                 |   3 +
 configs/devices/hexagon-softmmu/default.mak |   8 +
 configs/targets/hexagon-softmmu.mak         |   8 +
 meson.build                                 |   1 +
 hw/hexagon/trace.h                          |   2 +
 include/hw/hexagon/hexagon.h                | 150 +++++++
 include/hw/hexagon/hexagon_globalreg.h      |  56 +++
 include/hw/hexagon/virt.h                   |  43 ++
 target/hexagon/cpu.h                        |   7 +-
 hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc   |  64 +++
 hw/hexagon/machine_cfg_v66g_1024.h.inc      |  64 +++
 hw/hexagon/machine_cfg_v68n_1024.h.inc      |  65 +++
 hw/hexagon/hexagon_dsp.c                    | 188 ++++++++
 hw/hexagon/hexagon_globalreg.c              | 313 ++++++++++++++
 hw/hexagon/virt.c                           | 456 ++++++++++++++++++++
 system/qdev-monitor.c                       |   2 +-
 target/hexagon/cpu.c                        |   6 +-
 target/hexagon/translate.c                  |   1 +
 tests/qtest/boot-serial-test.c              |   8 +
 hw/Kconfig                                  |   1 +
 hw/hexagon/Kconfig                          |  14 +
 hw/hexagon/meson.build                      |   8 +
 hw/hexagon/trace-events                     |   3 +
 hw/meson.build                              |   1 +
 target/Kconfig                              |   1 +
 target/hexagon/Kconfig                      |   2 +
 target/hexagon/meson.build                  |  13 +-
 tests/qemu-iotests/testenv.py               |   1 +
 tests/qtest/meson.build                     |   2 +
 29 files changed, 1480 insertions(+), 11 deletions(-)
 create mode 100644 configs/devices/hexagon-softmmu/default.mak
 create mode 100644 configs/targets/hexagon-softmmu.mak
 create mode 100644 hw/hexagon/trace.h
 create mode 100644 include/hw/hexagon/hexagon.h
 create mode 100644 include/hw/hexagon/hexagon_globalreg.h
 create mode 100644 include/hw/hexagon/virt.h
 create mode 100644 hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc
 create mode 100644 hw/hexagon/machine_cfg_v66g_1024.h.inc
 create mode 100644 hw/hexagon/machine_cfg_v68n_1024.h.inc
 create mode 100644 hw/hexagon/hexagon_dsp.c
 create mode 100644 hw/hexagon/hexagon_globalreg.c
 create mode 100644 hw/hexagon/virt.c
 create mode 100644 hw/hexagon/Kconfig
 create mode 100644 hw/hexagon/meson.build
 create mode 100644 hw/hexagon/trace-events
 create mode 100644 target/hexagon/Kconfig
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/9 hw/hexagon: Add globalreg model

Some of the system registers are shared among all threads in the core. This object contains the representation and interface to the system registers.

---
 include/hw/hexagon/hexagon_globalreg.h |  56 ++++++
 hw/hexagon/hexagon_globalreg.c         | 240 +++++++++++++++++++++++++
 2 files changed, 296 insertions(+)
 create mode 100644 include/hw/hexagon/hexagon_globalreg.h
 create mode 100644 hw/hexagon/hexagon_globalreg.c
include/hw/hexagon/hexagon_globalreg.h new file +56 -0
new file mode 100644
index 00000000000..c9e72f30b0a
@@ -0,0 +1,56 @@
+/*
+ * Hexagon Global Registers QOM Object
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HEXAGON_GLOBALREG_H
+#define HEXAGON_GLOBALREG_H
+
+#include "hw/core/qdev.h"
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+#include "target/hexagon/cpu.h"
+
+#define TYPE_HEXAGON_GLOBALREG "hexagon-globalreg"
+OBJECT_DECLARE_SIMPLE_TYPE(HexagonGlobalRegState, HEXAGON_GLOBALREG)
+
+struct HexagonGlobalRegState {
+    SysBusDevice parent_obj;
+
+    /* Array of system registers */
+    uint32_t regs[NUM_SREGS];
+
+    /* Global performance cycle counter base */
+    uint64_t g_pcycle_base;
+
+    /* Properties for global register reset values */
+    uint32_t boot_evb;           /* Boot Exception Vector Base (HEX_SREG_EVB) */
+    uint64_t config_table_addr;  /* Configuration table base */
+    uint32_t dsp_rev;           /* DSP revision register (HEX_SREG_REV) */
+
+    /* ISDB properties */
+    bool isdben_etm_enable;     /* ISDB ETM enable bit */
+    bool isdben_dfd_enable;     /* ISDB DFD enable bit */
+    bool isdben_trusted;        /* ISDB trusted mode bit */
+    bool isdben_secure;         /* ISDB secure mode bit */
+};
+
+/* Public interface functions */
+uint32_t hexagon_globalreg_read(HexagonGlobalRegState *s, uint32_t reg,
+                                uint32_t htid);
+void hexagon_globalreg_write(HexagonGlobalRegState *s, uint32_t reg,
+                             uint32_t value, uint32_t htid);
+uint32_t hexagon_globalreg_masked_value(HexagonGlobalRegState *s, uint32_t reg,
+                                        uint32_t value);
+void hexagon_globalreg_write_masked(HexagonGlobalRegState *s, uint32_t reg,
+                                    uint32_t value);
+void hexagon_globalreg_reset(HexagonGlobalRegState *s);
+
+/* Global performance cycle counter access */
+uint64_t hexagon_globalreg_get_pcycle_base(HexagonGlobalRegState *s);
+void hexagon_globalreg_set_pcycle_base(HexagonGlobalRegState *s,
+                                       uint64_t value);
+
+#endif /* HEXAGON_GLOBALREG_H */
hw/hexagon/hexagon_globalreg.c new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
2.34.1
Acked-by on v5 1/9
#2 lore raw

Re: [PATCH v5 1/9] hw/hexagon: Add globalreg model

Quoted 4 lines · Brian Cain

Some of the system registers are shared among all threads in the core. This object contains the representation and interface to the system registers.

Quoted 8 lines
---
  include/hw/hexagon/hexagon_globalreg.h |  56 ++++++
  hw/hexagon/hexagon_globalreg.c         | 240 +++++++++++++++++++++++++
  2 files changed, 296 insertions(+)

create mode 100644 include/hw/hexagon/hexagon_globalreg.h create mode 100644 hw/hexagon/hexagon_globalreg.c

Assuming you'll end merging this:

#3 lore raw

Re: [PATCH v5 1/9] hw/hexagon: Add globalreg model

In reply to Brian Cain

hw/hexagon/hexagon_globalreg.c line 55

Quoted 12 lines · On Thu, 16 Apr 2026 14:02:57 -0700 Brian Cain <[email protected]>…
hw/hexagon/hexagon_globalreg.c new file +5 -0
new file mode 100644
index 00000000000..97e75a2f1ea
 
+static void hexagon_globalreg_init(Object *obj)
+{
+    HexagonGlobalRegState *s = HEXAGON_GLOBALREG(obj);
+
+    memset(s->regs, 0, sizeof(uint32_t) * NUM_SREGS);

nit: sizeof(s->regs) would be safer

hw/hexagon/hexagon_globalreg.c line 175

Quoted 4 lines
hw/hexagon/hexagon_globalreg.c new file +4 -0
+void hexagon_globalreg_reset(HexagonGlobalRegState *s)
+{
+    do_hexagon_globalreg_reset(s);
+}

Is the wrapper really needed? Should we perhaps inline do_hexagon_globalreg_reset here, instead?

#4 lore raw

Re: [PATCH v5 1/9] hw/hexagon: Add globalreg model

In reply to Brian Cain

hw/hexagon/hexagon_globalreg.c line 176

Quoted 13 lines · Brian Cain

Some of the system registers are shared among all threads in the core. This object contains the representation and interface to the system registers.

---

hw/hexagon/hexagon_globalreg.c new file +5 -0
+void hexagon_globalreg_reset(HexagonGlobalRegState *s)
+{
+    do_hexagon_globalreg_reset(s);
+}
+

Where is this function is supposed to be used?
Seems like only reset_hold mechanism is used.

Regards,
Pierrick

author
#5 lore raw

PATCH v5 2/9 hw/hexagon: Add global register tracing

In reply to Brian Cain
---
 meson.build                    |  1 +
 hw/hexagon/trace.h             |  2 +
 hw/hexagon/hexagon_globalreg.c | 73 ++++++++++++++++++++++++++++++++++
 hw/hexagon/trace-events        |  3 ++
 4 files changed, 79 insertions(+)
 create mode 100644 hw/hexagon/trace.h
 create mode 100644 hw/hexagon/trace-events
meson.build +1 -0
index ab3e97eb9f4..3e4b70956b8 100644
@@ -3633,6 +3633,7 @@ if have_system
     'hw/display',
     'hw/dma',
     'hw/fsi',
+    'hw/hexagon',
     'hw/hyperv',
     'hw/i2c',
     'hw/i3c',
hw/hexagon/trace.h new file +2 -0
new file mode 100644
index 00000000000..9e0b39f3c66
@@ -0,0 +1,2 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "trace/trace-hw_hexagon.h"
hw/hexagon/hexagon_globalreg.c +73 -0

96 lines not on this page · raw message

hw/hexagon/trace-events new file +3 -0
new file mode 100644
index 00000000000..5d623ed2516
@@ -0,0 +1,3 @@
+# Hexagon global register access
+hexagon_globalreg_read(uint32_t htid, const char *reg_name, uint32_t value) "htid=%u reg=%s value=0x%x"
+hexagon_globalreg_write(uint32_t htid, const char *reg_name, uint32_t value) "htid=%u reg=%s value=0x%x"
Signature · 1 line
2.34.1
Reviewed-by on v5 2/9
#6 lore raw

Re: [PATCH v5 2/9] hw/hexagon: Add global register tracing

Quoted 10 lines · Brian Cain
---
  meson.build                    |  1 +
  hw/hexagon/trace.h             |  2 +
  hw/hexagon/hexagon_globalreg.c | 73 ++++++++++++++++++++++++++++++++++
  hw/hexagon/trace-events        |  3 ++
  4 files changed, 79 insertions(+)

create mode 100644 hw/hexagon/trace.h
create mode 100644 hw/hexagon/trace-events

author
#7 lore raw

PATCH v5 3/9 hw/hexagon: Add machine configs for sysemu

In reply to Brian Cain

From: Brian Cain <[email protected]>

Some header includes are modified here: these are uniquely required for basic system emulation functionality and had not been required for linux-user.

---
 MAINTAINERS                            |   2 +
 include/hw/hexagon/hexagon.h           | 150 +++++++++++++++++++++++
 hw/hexagon/machine_cfg_v66g_1024.h.inc |  64 ++++++++++
 hw/hexagon/hexagon_dsp.c               | 161 +++++++++++++++++++++++++
 system/qdev-monitor.c                  |   2 +-
 target/hexagon/translate.c             |   1 +
 hw/Kconfig                             |   1 +
 hw/hexagon/Kconfig                     |   4 +
 hw/hexagon/meson.build                 |   6 +
 hw/meson.build                         |   1 +
 10 files changed, 391 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/hexagon/hexagon.h
 create mode 100644 hw/hexagon/machine_cfg_v66g_1024.h.inc
 create mode 100644 hw/hexagon/hexagon_dsp.c
 create mode 100644 hw/hexagon/Kconfig
 create mode 100644 hw/hexagon/meson.build
MAINTAINERS +2 -0
index 4055fbe3c21..b9a7c553dfa 100644
@@ -246,6 +246,8 @@ Hexagon TCG CPUs
 M: Brian Cain <[email protected]>
 S: Supported
 F: target/hexagon/
+F: hw/hexagon/
+F: include/hw/hexagon/
 X: target/hexagon/idef-parser/
 X: target/hexagon/gen_idef_parser_funcs.py
 F: linux-user/hexagon/
include/hw/hexagon/hexagon.h new file +150 -0

150 lines not on this page · raw message

hw/hexagon/machine_cfg_v66g_1024.h.inc new file +64 -0

64 lines not on this page · raw message

hw/hexagon/hexagon_dsp.c new file +161 -0

161 lines not on this page · raw message

system/qdev-monitor.c +1 -1
index 1ac6d9a8575..72abc9182a9 100644
@@ -69,7 +69,7 @@ typedef struct QDevAlias
                               QEMU_ARCH_SPARC | \
                               QEMU_ARCH_XTENSA)
 #define QEMU_ARCH_VIRTIO_CCW (QEMU_ARCH_S390X)
-#define QEMU_ARCH_VIRTIO_MMIO (QEMU_ARCH_M68K)
+#define QEMU_ARCH_VIRTIO_MMIO (QEMU_ARCH_M68K | QEMU_ARCH_HEXAGON)
 
 /* Please keep this table sorted by typename. */
 static const QDevAlias qdev_alias_table[] = {
target/hexagon/translate.c +1 -0
index ae980c087f0..15258a203b3 100644
@@ -32,6 +32,7 @@
 #include "translate.h"
 #include "genptr.h"
 #include "printinsn.h"
+#include "exec/target_page.h"
 
 #define HELPER_H "helper.h"
 #include "exec/helper-info.c.inc"
hw/Kconfig +1 -0
index b3ed092f7a8..dda3139be74 100644
@@ -54,6 +54,7 @@ source arm/Kconfig
 source cpu/Kconfig
 source alpha/Kconfig
 source avr/Kconfig
+source hexagon/Kconfig
 source hppa/Kconfig
 source i386/Kconfig
 source loongarch/Kconfig
hw/hexagon/Kconfig new file +4 -0
new file mode 100644
index 00000000000..cdf7770a305
@@ -0,0 +1,4 @@
+config HEX_DSP
+    bool
+    default y
+    depends on HEXAGON
hw/hexagon/meson.build new file +6 -0
new file mode 100644
index 00000000000..f528d2bc4ab
@@ -0,0 +1,6 @@
+hexagon_ss = ss.source_set()
+hexagon_ss.add(files('hexagon_tlb.c'))
+hexagon_ss.add(files('hexagon_globalreg.c'))
+hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
+
+hw_arch += {'hexagon': hexagon_ss}
hw/meson.build +1 -0
index ef65ba51950..7fa81db453e 100644
@@ -3,6 +3,7 @@ subdir('alpha')
 subdir('arm')
 subdir('avr')
 subdir('hppa')
+subdir('hexagon')
 subdir('xenpv') # i386 uses it
 subdir('i386')
 subdir('loongarch')
Signature · 1 line
2.34.1
Reviewed-by on v5 3/9
#8 lore raw

Re: [PATCH v5 3/9] hw/hexagon: Add machine configs for sysemu

Quoted 21 lines · Brian Cain

From: Brian Cain <[email protected]>

Some header includes are modified here: these are uniquely required for basic system emulation functionality and had not been required for linux-user.

---
  MAINTAINERS                            |   2 +
  include/hw/hexagon/hexagon.h           | 150 +++++++++++++++++++++++
  hw/hexagon/machine_cfg_v66g_1024.h.inc |  64 ++++++++++
  hw/hexagon/hexagon_dsp.c               | 161 +++++++++++++++++++++++++
  system/qdev-monitor.c                  |   2 +-
  target/hexagon/translate.c             |   1 +
  hw/Kconfig                             |   1 +
  hw/hexagon/Kconfig                     |   4 +
  hw/hexagon/meson.build                 |   6 +
  hw/meson.build                         |   1 +
  10 files changed, 391 insertions(+), 1 deletion(-)
Quoted 6 lines

create mode 100644 include/hw/hexagon/hexagon.h create mode 100644 hw/hexagon/machine_cfg_v66g_1024.h.inc create mode 100644 hw/hexagon/hexagon_dsp.c create mode 100644 hw/hexagon/Kconfig
create mode 100644 hw/hexagon/meson.build

#9 lore raw

Re: [PATCH v5 3/9] hw/hexagon: Add machine configs for sysemu

In reply to Brian Cain
Quoted 32 lines · Brian Cain

From: Brian Cain <[email protected]>

Some header includes are modified here: these are uniquely required for basic system emulation functionality and had not been required for linux-user.

---
  MAINTAINERS                            |   2 +
  include/hw/hexagon/hexagon.h           | 150 +++++++++++++++++++++++
  hw/hexagon/machine_cfg_v66g_1024.h.inc |  64 ++++++++++
  hw/hexagon/hexagon_dsp.c               | 161 +++++++++++++++++++++++++
  system/qdev-monitor.c                  |   2 +-
  target/hexagon/translate.c             |   1 +
  hw/Kconfig                             |   1 +
  hw/hexagon/Kconfig                     |   4 +
  hw/hexagon/meson.build                 |   6 +
  hw/meson.build                         |   1 +
  10 files changed, 391 insertions(+), 1 deletion(-)

create mode 100644 include/hw/hexagon/hexagon.h create mode 100644 hw/hexagon/machine_cfg_v66g_1024.h.inc create mode 100644 hw/hexagon/hexagon_dsp.c create mode 100644 hw/hexagon/Kconfig
create mode 100644 hw/hexagon/meson.build

MAINTAINERS +0 -0
index 4055fbe3c21..b9a7c553dfa 100644

MAINTAINERS Hexagon TCG CPUs · line 250

Quoted 5 lines
MAINTAINERS +2 -0
@@ -246,6 +246,8 @@ Hexagon TCG CPUs
  M: Brian Cain <[email protected]>
  S: Supported
  F: target/hexagon/
+F: hw/hexagon/
+F: include/hw/hexagon/

IMHO long-term it is better to split architectural code from hardware modelling in distinct MAINTAINERS sections (and distinct set of reviewers / maintainers / lists).

Quoted 14 lines
MAINTAINERS +9 -0
  X: target/hexagon/idef-parser/
  X: target/hexagon/gen_idef_parser_funcs.py
  F: linux-user/hexagon/
 
 
+static void hexagon_common_init(MachineState *machine, Rev_t rev,
+                                const struct hexagon_machine_config *m_cfg)
+{
+    MemoryRegion *address_space;
+    MemoryRegion *sram;
+    DeviceState *glob_regs_dev;
+
+    memset(&hexagon_binfo, 0, sizeof(hexagon_binfo));
+    if (machine->kernel_filename) {

MAINTAINERS Hexagon TCG CPUs

Quoted 10 lines
MAINTAINERS +10 -0
+        hexagon_binfo.ram_size = machine->ram_size;
+        hexagon_binfo.kernel_filename = machine->kernel_filename;
+    }
+
+    machine->enable_graphics = 0;
+
+    address_space = get_system_memory();
+
+    sram = g_new(MemoryRegion, 1);
+    memory_region_init_ram(sram, NULL, "ddr.ram",

DDRAM or SRAM?

Quoted 21 lines
MAINTAINERS +21 -0
+        machine->ram_size, &error_fatal);
+    memory_region_add_subregion(address_space, 0x0, sram);
+
+    glob_regs_dev = qdev_new(TYPE_HEXAGON_GLOBALREG);
+    qdev_prop_set_uint64(glob_regs_dev, "config-table-addr", m_cfg->cfgbase);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(glob_regs_dev), &error_fatal);
+
+    for (int i = 0; i < machine->smp.cpus; i++) {
+        HexagonCPU *cpu = HEXAGON_CPU(object_new(machine->cpu_type));
+        qemu_register_reset(do_cpu_reset, cpu);
+
+        /*
+         * CPU #0 is the only CPU running at boot, others must be
+         * explicitly enabled via start instruction.
+         */
+        qdev_prop_set_bit(DEVICE(cpu), "start-powered-off", (i != 0));
+        if (i == 0) {
+            hexagon_init_bootstrap(machine, cpu);
+            if (!qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal)) {
+                return;
+            }

MAINTAINERS

Quoted 10 lines
MAINTAINERS +10 -0
+        } else if (!qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal)) {
+            return;
+        }
+
+    }
+}
+
+static void init_mc(MachineClass *mc)
+{
+    mc->block_default_type = IF_SD;

Is "By default try to boot on SD Card first" what you want?

Quoted 28 lines
MAINTAINERS +8 -0
+    mc->default_ram_size = 4 * GiB;
+    mc->no_parallel = 1;
+    mc->no_floppy = 1;
+    mc->no_cdrom = 1;
+    mc->no_serial = 1;
+    mc->is_default = false;
+    mc->max_cpus = 8;
+}
system/qdev-monitor.c +1 -1
index 1ac6d9a8575..72abc9182a9 100644
@@ -69,7 +69,7 @@ typedef struct QDevAlias
                                QEMU_ARCH_SPARC | \
                                QEMU_ARCH_XTENSA)
  #define QEMU_ARCH_VIRTIO_CCW (QEMU_ARCH_S390X)
-#define QEMU_ARCH_VIRTIO_MMIO (QEMU_ARCH_M68K)
+#define QEMU_ARCH_VIRTIO_MMIO (QEMU_ARCH_M68K | QEMU_ARCH_HEXAGON)
 
  /* Please keep this table sorted by typename. */
  static const QDevAlias qdev_alias_table[] = {
target/hexagon/translate.c +0 -0
index ae980c087f0..15258a203b3 100644

target/hexagon/translate.c line 35

Quoted 4 lines
target/hexagon/translate.c +1 -0
@@ -32,6 +32,7 @@
  #include "translate.h"
  #include "genptr.h"
  #include "printinsn.h"
+#include "exec/target_page.h"

Rebase left-over?

Quoted 11 lines
target/hexagon/translate.c +0 -0
  #define HELPER_H "helper.h"
  #include "exec/helper-info.c.inc"
 
hw/hexagon/meson.build new file +0 -0
new file mode 100644
index 00000000000..f528d2bc4ab

hw/hexagon/meson.build line 6

Quoted 6 lines
hw/hexagon/meson.build new file +6 -0
@@ -0,0 +1,6 @@
+hexagon_ss = ss.source_set()
+hexagon_ss.add(files('hexagon_tlb.c'))
+hexagon_ss.add(files('hexagon_globalreg.c'))
+hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
+
+hw_arch += {'hexagon': hexagon_ss}

Better would be:

hw_common_arch += {'hexagon': hexagon_common_ss}

Pierrick can help here!

author
#10 lore raw

PATCH v5 4/9 hw/hexagon: Add v68, sa8775-cdsp0 defs

In reply to Brian Cain

From: Brian Cain <[email protected]>

---
 hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc | 64 ++++++++++++++++++++++
 hw/hexagon/machine_cfg_v68n_1024.h.inc    | 65 +++++++++++++++++++++++
 2 files changed, 129 insertions(+)
 create mode 100644 hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc
 create mode 100644 hw/hexagon/machine_cfg_v68n_1024.h.inc
hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc new file +64 -0
new file mode 100644
index 00000000000..442cbe3be31
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+static const struct hexagon_machine_config SA8775P_cdsp0 = {
+    .cfgbase =         0x24000000 + 0x180000,
+    .l2tcm_size =      0x00000000,
+    .l2vic_base =      0x26300000 + 0x90000,
+    .l2vic_size =      0x00001000,
+    .csr_base =        0x26300000,
+    .qtmr_region =     0x26300000 + 0xA1000,
+    .cfgtable = {
+        .l2tcm_base = 0x00002400,
+        .reserved0 = 0x00000000,
+        .subsystem_base = 0x00002638,
+        .etm_base = 0x00002419,
+        .l2cfg_base = 0x0000241a,
+        .reserved1 = 0x0000241b,
+        .l1s0_base = 0x00002500,
+        .axi2_lowaddr = 0x00000000,
+        .streamer_base = 0x00000000,
+        .reserved2 = 0x00000000,
+        .fastl2vic_base = 0x0000241e,
+        .jtlb_size_entries = 0x00000080,
+        .coproc_present = 0x00000001,
+        .ext_contexts = 0x00000004,
+        .vtcm_base = 0x00002500,
+        .vtcm_size_kb = 0x00002000,
+        .l2tag_size = 0x00000400,
+        .l2ecomem_size = 0x00000000,
+        .thread_enable_mask = 0x0000003f,
+        .eccreg_base = 0x0000241f,
+        .l2line_size = 0x00000080,
+        .tiny_core = 0x00000000,
+        .l2itcm_size = 0x00000000,
+        .l2itcm_base = 0x00002400,
+        .reserved3 = 0x00000000,
+        .dtm_present = 0x00000000,
+        .dma_version = 0x00000003,
+        .hvx_vec_log_length = 0x00000007,
+        .core_id = 0x00000000,
+        .core_count = 0x00000000,
+        .coproc2_reg0 = 0x00000040,
+        .coproc2_reg1 = 0x00000020,
+        .v2x_mode = 0x00000001,
+        .coproc2_reg2 = 0x00000008,
+        .coproc2_reg3 = 0x00000020,
+        .coproc2_reg4 = 0x00000000,
+        .coproc2_reg5 = 0x00000002,
+        .coproc2_reg6 = 0x00000016,
+        .coproc2_reg7 = 0x00000006,
+        .acd_preset = 0x00000001,
+        .mnd_preset = 0x00000000,
+        .l1d_size_kb = 0x00000010,
+        .l1i_size_kb = 0x00000020,
+        .l1d_write_policy = 0x00000002,
+        .vtcm_bank_width = 0x00000080,
+        .reserved4 = 0x00000001,
+        .reserved5 = 0x00000000,
+        .reserved6 = 0x00000003,
+        .coproc2_cvt_mpy_size = 0x0000000a,
+        .consistency_domain = 0x000000e0,
+        .capacity_domain = 0x00000080,
+        .axi3_lowaddr = 0x00000000,
+    },
+};
hw/hexagon/machine_cfg_v68n_1024.h.inc new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.34.1
Acked-by on v5 4/9
#11 lore raw

Re: [PATCH v5 4/9] hw/hexagon: Add v68, sa8775-cdsp0 defs

Quoted 10 lines · Brian Cain

From: Brian Cain <[email protected]>

---
  hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc | 64 ++++++++++++++++++++++
  hw/hexagon/machine_cfg_v68n_1024.h.inc    | 65 +++++++++++++++++++++++
  2 files changed, 129 insertions(+)

create mode 100644 hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc create mode 100644 hw/hexagon/machine_cfg_v68n_1024.h.inc

Reviewed-by on v5 4/9
#12 lore raw

Re: [PATCH v5 4/9] hw/hexagon: Add v68, sa8775-cdsp0 defs

In reply to Brian Cain
Quoted 11 lines · Brian Cain

From: Brian Cain <[email protected]>

---
  hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc | 64 ++++++++++++++++++++++
  hw/hexagon/machine_cfg_v68n_1024.h.inc    | 65 +++++++++++++++++++++++
  2 files changed, 129 insertions(+)

create mode 100644 hw/hexagon/machine_cfg_sa8775_cdsp0.h.inc create mode 100644 hw/hexagon/machine_cfg_v68n_1024.h.inc

author
#13 lore raw

PATCH v5 5/9 hw/hexagon: Add support for cfgbase

In reply to Brian Cain

From: Sid Manning <[email protected]>

---
 hw/hexagon/hexagon_dsp.c | 11 +++++++++++
 target/hexagon/cpu.c     |  1 -
 2 files changed, 11 insertions(+), 1 deletion(-)
hw/hexagon/hexagon_dsp.c +11 -0
index d5df87605f4..649cafcf8ec 100644
@@ -73,6 +73,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
                                 const struct hexagon_machine_config *m_cfg)
 {
     MemoryRegion *address_space;
+    MemoryRegion *config_table_rom;
     MemoryRegion *sram;
     DeviceState *glob_regs_dev;
 
@@ -86,6 +87,12 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
 
     address_space = get_system_memory();
 
+    config_table_rom = g_new(MemoryRegion, 1);
+    memory_region_init_rom(config_table_rom, NULL, "config_table.rom",
+                           sizeof(m_cfg->cfgtable), &error_fatal);
+    memory_region_add_subregion(address_space, m_cfg->cfgbase,
+                                config_table_rom);
+
     sram = g_new(MemoryRegion, 1);
     memory_region_init_ram(sram, NULL, "ddr.ram",
         machine->ram_size, &error_fatal);
@@ -114,6 +121,10 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
         }
 
     }
+
+    rom_add_blob_fixed_as("config_table.rom", &m_cfg->cfgtable,
+                          sizeof(m_cfg->cfgtable), m_cfg->cfgbase,
+                          &address_space_memory);
 }
 
 static void init_mc(MachineClass *mc)
target/hexagon/cpu.c +0 -1
index bd3eec0d525..9883c4d1681 100644
@@ -404,7 +404,6 @@ void hexagon_cpu_soft_reset(CPUHexagonState *env)
 }
 #endif
 
-
 static void hexagon_cpu_reset_hold(Object *obj, ResetType type)
 {
     CPUState *cs = CPU(obj);
Signature · 1 line
2.34.1
#14 lore raw

Re: [PATCH v5 5/9] hw/hexagon: Add support for cfgbase

Quoted 23 lines · Brian Cain

From: Sid Manning <[email protected]>

---
  hw/hexagon/hexagon_dsp.c | 11 +++++++++++
  target/hexagon/cpu.c     |  1 -
  2 files changed, 11 insertions(+), 1 deletion(-)
hw/hexagon/hexagon_dsp.c +1 -0
index d5df87605f4..649cafcf8ec 100644
@@ -73,6 +73,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
                                  const struct hexagon_machine_config *m_cfg)
  {
      MemoryRegion *address_space;
+    MemoryRegion *config_table_rom;
      MemoryRegion *sram;
      DeviceState *glob_regs_dev;
 
@@ -86,6 +87,12 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
 

hw/hexagon/hexagon_dsp.c static void hexagon_common_init(MachineState *machine, Rev_t rev, · line 97

Quoted 10 lines
hw/hexagon/hexagon_dsp.c +6 -0
      address_space = get_system_memory();
 
+    config_table_rom = g_new(MemoryRegion, 1);
+    memory_region_init_rom(config_table_rom, NULL, "config_table.rom",
+                           sizeof(m_cfg->cfgtable), &error_fatal);
+    memory_region_add_subregion(address_space, m_cfg->cfgbase,
+                                config_table_rom);
+
      sram = g_new(MemoryRegion, 1);
      memory_region_init_ram(sram, NULL, "ddr.ram",

Better if we can keep reference to these things in the machine state. We can add HexagonMachineState (or HexagonCommonMachineState) which expands MachineState and have those fields:

#define TYPE_HEXAGON_MACHINE MACHINE_TYPE_NAME("hexagon-common") OBJECT_DECLARE_SIMPLE_TYPE(HexagonMachineState, HEXAGON_MACHINE)

struct HexagonMachineState {
    MachineState parent_obj;

    MemoryRegion sram;
    MemoryRegion config_table_rom;
    ...
};

static const TypeInfo hexagon_machine_types[] = {
{
.name = TYPE_HEXAGON_MACHINE,
.parent = TYPE_MACHINE,
.instance_size = sizeof(HexagonMachineState),
.abstract = true,
}, {
.name = MACHINE_TYPE_NAME("V66G_1024"), .parent = HEXAGON_MACHINE, .class_init = v66g_1024_init,
},
};

static void hexagon_common_init(MachineState *machine, Rev_t rev,
const struct hexagon_machine_config *m_cfg)

{
    HexagonMachineState *s = HEXAGON_MACHINE(machine);

    ...

    memory_region_init_rom(&s->config_table_rom, NULL,
                           "config_table.rom",
                           sizeof(m_cfg->cfgtable), &error_fatal);
    memory_region_add_subregion(address_space, m_cfg->cfgbase,
                                &s->config_table_rom);

    ...

This also helps during debugging because you can easily introspect from the machine to the particular MemoryRegion (in this example).

#15 lore raw

Re: [PATCH v5 5/9] hw/hexagon: Add support for cfgbase

Quoted 76 lines · Philippe Mathieu-Daudé
Quoted 22 lines · Brian Cain

From: Sid Manning <[email protected]>

---
  hw/hexagon/hexagon_dsp.c | 11 +++++++++++
  target/hexagon/cpu.c     |  1 -

  2 files changed, 11 insertions(+), 1 deletion(-)
hw/hexagon/hexagon_dsp.c +1 -0
index d5df87605f4..649cafcf8ec 100644
@@ -73,6 +73,7 @@ static void hexagon_common_init(MachineState 
 *machine, Rev_t rev,
                                   const struct hexagon_machine_config *m_cfg)
   {
       MemoryRegion *address_space;
+    MemoryRegion *config_table_rom;
       MemoryRegion *sram;
       DeviceState *glob_regs_dev;

hw/hexagon/hexagon_dsp.c static void hexagon_common_init(MachineState · line 96

Quoted 10 lines
hw/hexagon/hexagon_dsp.c +6 -0
@@ -86,6 +87,12 @@ static void hexagon_common_init(MachineState 
 *machine, Rev_t rev,
       address_space = get_system_memory();
+    config_table_rom = g_new(MemoryRegion, 1);
+    memory_region_init_rom(config_table_rom, NULL, "config_table.rom",
+                           sizeof(m_cfg->cfgtable), &error_fatal);
+    memory_region_add_subregion(address_space, m_cfg->cfgbase,
+                                config_table_rom);
+
       sram = g_new(MemoryRegion, 1);
       memory_region_init_ram(sram, NULL, "ddr.ram",

Better if we can keep reference to these things in the machine state. We can add HexagonMachineState (or HexagonCommonMachineState) which expands MachineState and have those fields:

#define TYPE_HEXAGON_MACHINE  MACHINE_TYPE_NAME("hexagon-common") OBJECT_DECLARE_SIMPLE_TYPE(HexagonMachineState, HEXAGON_MACHINE)

struct HexagonMachineState {
    MachineState parent_obj;

    MemoryRegion sram;
    MemoryRegion config_table_rom;
    ...
};

static const TypeInfo hexagon_machine_types[] = {
    {
        .name           = TYPE_HEXAGON_MACHINE, .parent         = TYPE_MACHINE, .instance_size  = sizeof(HexagonMachineState), .abstract       = true,
    }, {
        .name = MACHINE_TYPE_NAME("V66G_1024"), .parent = HEXAGON_MACHINE, .class_init = v66g_1024_init,
    },
};

static void hexagon_common_init(MachineState *machine, Rev_t rev,
                                const struct hexagon_machine_config
*m_cfg)
{
    HexagonMachineState *s = HEXAGON_MACHINE(machine);

    ...

    memory_region_init_rom(&s->config_table_rom, NULL, "config_table.rom", sizeof(m_cfg->cfgtable), &error_fatal); memory_region_add_subregion(address_space, m_cfg->cfgbase, &s->config_table_rom);

Quoted 4 lines

    ...

This also helps during debugging because you can easily introspect from the machine to the particular MemoryRegion (in this example).

And now I see you add HexagonVirtMachineState later...

Maybe the following OOP inheritance is still useful:

HexagonVirtMachineState -> HexagonCommonMachineState -> MachineState

author
#16 lore raw

PATCH v5 6/9 hw/hexagon: Modify "Standalone" symbols

In reply to Brian Cain

From: Brian Cain <[email protected]>

These symbols are used by Hexagon Standalone OS to indicate whether the program should halt and wait for interrupts at startup. For QEMU, we want these programs to just continue crt0 startup through to the user program's main().

---
 hw/hexagon/hexagon_dsp.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/hexagon/hexagon_dsp.c +16 -0
index 649cafcf8ec..3c269feed28 100644
@@ -28,9 +28,17 @@
 
 #include "machine_cfg_v66g_1024.h.inc"
 
+static hwaddr isdb_secure_flag;
+static hwaddr isdb_trusted_flag;
 static void hex_symbol_callback(const char *st_name, int st_info,
                                 uint64_t st_value, uint64_t st_size)
 {
+    if (!g_strcmp0("isdb_secure_flag", st_name)) {
+        isdb_secure_flag = st_value;
+    }
+    if (!g_strcmp0("isdb_trusted_flag", st_name)) {
+        isdb_trusted_flag = st_value;
+    }
 }
 
 /* Board init.  */
@@ -58,7 +66,15 @@ static void hexagon_load_kernel(HexagonCPU *cpu)
 static void hexagon_init_bootstrap(MachineState *machine, HexagonCPU *cpu)
 {
     if (machine->kernel_filename) {
+        uint32_t mem = 1;
+
         hexagon_load_kernel(cpu);
+        if (isdb_secure_flag) {
+            cpu_physical_memory_write(isdb_secure_flag, &mem, sizeof(mem));
+        }
+        if (isdb_trusted_flag) {
+            cpu_physical_memory_write(isdb_trusted_flag, &mem, sizeof(mem));
+        }
     }
 }
 
Signature · 1 line
2.34.1
#17 lore raw

Re: [PATCH v5 6/9] hw/hexagon: Modify "Standalone" symbols

Quoted 19 lines · Brian Cain

From: Brian Cain <[email protected]>

These symbols are used by Hexagon Standalone OS to indicate whether the program should halt and wait for interrupts at startup. For QEMU, we want these programs to just continue crt0 startup through to the user program's main().

---
  hw/hexagon/hexagon_dsp.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
hw/hexagon/hexagon_dsp.c +0 -0
index 649cafcf8ec..3c269feed28 100644

hw/hexagon/hexagon_dsp.c line 32

Quoted 5 lines
hw/hexagon/hexagon_dsp.c +2 -0
@@ -28,9 +28,17 @@
 
  #include "machine_cfg_v66g_1024.h.inc"
 
+static hwaddr isdb_secure_flag;
+static hwaddr isdb_trusted_flag;

I'd store these in HexagonMachineState mentioned in previous patch.

Quoted 10 lines
hw/hexagon/hexagon_dsp.c +6 -0
  static void hex_symbol_callback(const char *st_name, int st_info,
                                  uint64_t st_value, uint64_t st_size)
  {
+    if (!g_strcmp0("isdb_secure_flag", st_name)) {
+        isdb_secure_flag = st_value;
+    }
+    if (!g_strcmp0("isdb_trusted_flag", st_name)) {
+        isdb_trusted_flag = st_value;
+    }
  }
author
#18 lore raw

PATCH v5 7/9 target/hexagon: add build config for softmmu

In reply to Brian Cain
---
 MAINTAINERS                                 |  1 +
 configs/devices/hexagon-softmmu/default.mak |  7 +++++++
 configs/targets/hexagon-softmmu.mak         |  7 +++++++
 target/hexagon/cpu.h                        |  7 +------
 target/hexagon/cpu.c                        |  3 +--
 target/Kconfig                              |  1 +
 target/hexagon/Kconfig                      |  2 ++
 target/hexagon/meson.build                  | 13 ++++++++++++-
 8 files changed, 32 insertions(+), 9 deletions(-)
 create mode 100644 configs/devices/hexagon-softmmu/default.mak
 create mode 100644 configs/targets/hexagon-softmmu.mak
 create mode 100644 target/hexagon/Kconfig
MAINTAINERS +1 -0
index b9a7c553dfa..ed661c9f12e 100644
@@ -254,6 +254,7 @@ F: linux-user/hexagon/
 F: tests/tcg/hexagon/
 F: disas/hexagon.c
 F: configs/targets/hexagon-linux-user/default.mak
+F: configs/devices/hexagon-softmmu/default.mak
 F: docker/dockerfiles/debian-hexagon-cross.docker
 F: gdbstub/gdb-xml/hexagon*.xml
 F: docs/system/target-hexagon.rst
configs/devices/hexagon-softmmu/default.mak new file +7 -0
new file mode 100644
index 00000000000..08e709aea72
@@ -0,0 +1,7 @@
+# Default configuration for hexagon-softmmu
+
+# Uncomment the following lines to disable these optional devices:
+
+# Boards are selected by default, uncomment to keep out of the build.
+# CONFIG_HEX_DSP=y
+# CONFIG_L2VIC=y
configs/targets/hexagon-softmmu.mak new file +7 -0
new file mode 100644
index 00000000000..fdfa29b4f39
@@ -0,0 +1,7 @@
+# Default configuration for hexagon-softmmu
+
+TARGET_ARCH=hexagon
+TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
+TARGET_LONG_BITS=32
+TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
target/hexagon/cpu.h +1 -6
index 09d5cac4fe5..18dcfdb0b0a 100644
@@ -37,12 +37,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState;
 #include "mmvec/mmvec.h"
 #include "hw/core/registerfields.h"
 
-#ifndef CONFIG_USER_ONLY
-#error "Hexagon does not support system emulation"
-#endif
-
-#ifndef CONFIG_USER_ONLY
-#endif
+#include "reg_fields.h"
 
 #define NUM_PREGS 4
 #define TOTAL_PER_THREAD_REGS 64
target/hexagon/cpu.c +1 -2
index 9883c4d1681..355abb4fd24 100644
@@ -713,9 +713,8 @@ static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx,
 #endif
 
 static const TCGCPUOps hexagon_tcg_ops = {
-    /* MTTCG not yet supported: require strict ordering */
     .guest_default_memory_order = TCG_MO_ALL,
-    .mttcg_supported = false,
+    .mttcg_supported = true,
     .initialize = hexagon_translate_init,
     .translate_code = hexagon_translate_code,
     .get_tb_cpu_state = hexagon_get_tb_cpu_state,
target/Kconfig +1 -0
index 3c73e3bae01..0288a3f4164 100644
@@ -16,6 +16,7 @@ source sh4/Kconfig
 source sparc/Kconfig
 source tricore/Kconfig
 source xtensa/Kconfig
+source hexagon/Kconfig
 
 config TARGET_BIG_ENDIAN
     bool
target/hexagon/Kconfig new file +2 -0
new file mode 100644
index 00000000000..7e556f35063
@@ -0,0 +1,2 @@
+config HEXAGON
+    bool
target/hexagon/meson.build +12 -1
index 528beca3cd0..bc7a292e47b 100644
@@ -235,6 +235,7 @@ decodetree_trans_funcs_generated = custom_target(
     command: [python, files('gen_trans_funcs.py'), semantics_generated, '@OUTPUT@'],
 )
 hexagon_ss.add(decodetree_trans_funcs_generated)
+hexagon_softmmu_ss = ss.source_set()
 
 hexagon_ss.add(files(
     'cpu.c',
@@ -253,6 +254,14 @@ hexagon_ss.add(files(
     'mmvec/system_ext_mmvec.c',
 ))
 
+hexagon_softmmu_ss.add(files(
+    'cpu_helper.c',
+    'hex_mmu.c',
+    'hex_interrupts.c',
+    'hexswi.c',
+    'machine.c',
+))
+
 #
 # Step 4.5
 # We use flex/bison based idef-parser to generate TCG code for a lot
@@ -262,7 +271,8 @@ hexagon_ss.add(files(
 #     idef-generated-enabled-instructions
 #
 idef_parser_enabled = get_option('hexagon_idef_parser')
-if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
+if idef_parser_enabled and ('hexagon-linux-user' in target_dirs or
+                            'hexagon-softmmu' in target_dirs)
     idef_parser_input_generated = custom_target(
         'idef_parser_input.h.inc',
         output: 'idef_parser_input.h.inc',
@@ -390,3 +400,4 @@ analyze_funcs_generated = custom_target(
 hexagon_ss.add(analyze_funcs_generated)
 
 target_arch += {'hexagon': hexagon_ss}
+target_system_arch += {'hexagon': hexagon_softmmu_ss}
Signature · 1 line
2.34.1
#19 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

Quoted 22 lines · Brian Cain
---
  MAINTAINERS                                 |  1 +
  configs/devices/hexagon-softmmu/default.mak |  7 +++++++
  configs/targets/hexagon-softmmu.mak         |  7 +++++++
  target/hexagon/cpu.h                        |  7 +------
  target/hexagon/cpu.c                        |  3 +--
  target/Kconfig                              |  1 +
  target/hexagon/Kconfig                      |  2 ++
  target/hexagon/meson.build                  | 13 ++++++++++++-
  8 files changed, 32 insertions(+), 9 deletions(-)

create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

target/hexagon/cpu.c +0 -0
index 9883c4d1681..355abb4fd24 100644

target/hexagon/cpu.c static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx, · line 720

Quoted 10 lines
target/hexagon/cpu.c +1 -2
@@ -713,9 +713,8 @@ static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx,
  #endif
 
  static const TCGCPUOps hexagon_tcg_ops = {
-    /* MTTCG not yet supported: require strict ordering */
      .guest_default_memory_order = TCG_MO_ALL,
-    .mttcg_supported = false,
+    .mttcg_supported = true,
      .initialize = hexagon_translate_init,
      .translate_code = hexagon_translate_code,
      .get_tb_cpu_state = hexagon_get_tb_cpu_state,

Please commit this change as a separate patch, explaining why we can do that in the description.

author
#20 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Brian Cain
---
  MAINTAINERS                                 |  1 +
  configs/devices/hexagon-softmmu/default.mak |  7 +++++++
  configs/targets/hexagon-softmmu.mak         |  7 +++++++
  target/hexagon/cpu.h                        |  7 +------
  target/hexagon/cpu.c                        |  3 +--
  target/Kconfig                              |  1 +
  target/hexagon/Kconfig                      |  2 ++
  target/hexagon/meson.build                  | 13 ++++++++++++-
  8 files changed, 32 insertions(+), 9 deletions(-)

create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

target/hexagon/cpu.c +0 -0
index 9883c4d1681..355abb4fd24 100644
@@ -713,9 +713,8 @@ static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx,
  #endif
 
Quoted 11 lines

target/hexagon/cpu.c static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx, · line 720

Quoted 8 lines
target/hexagon/cpu.c +1 -2
  static const TCGCPUOps hexagon_tcg_ops = {
-    /* MTTCG not yet supported: require strict ordering */
      .guest_default_memory_order = TCG_MO_ALL,
-    .mttcg_supported = false,
+    .mttcg_supported = true,
      .initialize = hexagon_translate_init,
      .translate_code = hexagon_translate_code,
      .get_tb_cpu_state = hexagon_get_tb_cpu_state,

Please commit this change as a separate patch, explaining why we can do that in the description.

I think I'll drop it for now, and revisit after this series.

#21 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

Quoted 40 lines · Brian Cain
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Brian Cain
---
   MAINTAINERS                                 |  1 +
   configs/devices/hexagon-softmmu/default.mak |  7 +++++++
   configs/targets/hexagon-softmmu.mak         |  7 +++++++
   target/hexagon/cpu.h                        |  7 +------
   target/hexagon/cpu.c                        |  3 +--
   target/Kconfig                              |  1 +
   target/hexagon/Kconfig                      |  2 ++
   target/hexagon/meson.build                  | 13 ++++++++++++-
   8 files changed, 32 insertions(+), 9 deletions(-)

create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

target/hexagon/cpu.c +0 -0
index 9883c4d1681..355abb4fd24 100644
@@ -713,9 +713,8 @@ static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx,
   #endif
 
Quoted 11 lines

target/hexagon/cpu.c static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx, · line 720

Quoted 8 lines
target/hexagon/cpu.c +1 -2
   static const TCGCPUOps hexagon_tcg_ops = {
-    /* MTTCG not yet supported: require strict ordering */
       .guest_default_memory_order = TCG_MO_ALL,
-    .mttcg_supported = false,
+    .mttcg_supported = true,
       .initialize = hexagon_translate_init,
       .translate_code = hexagon_translate_code,
       .get_tb_cpu_state = hexagon_get_tb_cpu_state,

Please commit this change as a separate patch, explaining why we can do that in the description.

Quoted 1 line

I think I'll drop it for now, and revisit after this series.

It basically means supporting atomic instructions and memory barriers correctly. From what I saw, memory barriers are nop at the moment.

Regards,
Pierrick

#22 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

Quoted 42 lines · Pierrick Bouvier
Quoted 41 lines · Brian Cain
Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 32 lines · Brian Cain

---
   MAINTAINERS                                 |  1 + configs/devices/hexagon-softmmu/default.mak |  7 +++++++ configs/targets/hexagon-softmmu.mak         |  7 +++++++ target/hexagon/cpu.h                        |  7 +------ target/hexagon/cpu.c                        |  3 +-- target/Kconfig                              |  1 + target/hexagon/Kconfig                      |  2 ++ target/hexagon/meson.build                  | 13 ++++++++++++-

   8 files changed, 32 insertions(+), 9 deletions(-)

   create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

target/hexagon/cpu.c +1 -2
index 9883c4d1681..355abb4fd24 100644
@@ -713,9 +713,8 @@ static vaddr hexagon_pointer_wrap(CPUState *cs, 
 int mmu_idx,
    #endif
 
    static const TCGCPUOps hexagon_tcg_ops = {
-    /* MTTCG not yet supported: require strict ordering */
        .guest_default_memory_order = TCG_MO_ALL,
-    .mttcg_supported = false,
+    .mttcg_supported = true,
        .initialize = hexagon_translate_init,
        .translate_code = hexagon_translate_code,
Quoted 1 line

       .get_tb_cpu_state = hexagon_get_tb_cpu_state,

Please commit this change as a separate patch, explaining why we can do that in the description.

Quoted 3 lines
Quoted 1 line

I think I'll drop it for now, and revisit after this series.

It basically means supporting atomic instructions and memory barriers correctly. From what I saw, memory barriers are nop at the moment.

Sure. When I meant is such change also affecting user emulation should not be buried in a commit only mentioning softmmu changes.

Reviewed-by on v5 7/9
#23 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

In reply to Brian Cain
Quoted 12 lines · Brian Cain
---
  MAINTAINERS                                 |  1 +
  configs/devices/hexagon-softmmu/default.mak |  7 +++++++
  configs/targets/hexagon-softmmu.mak         |  7 +++++++
  target/hexagon/cpu.h                        |  7 +------
  target/hexagon/cpu.c                        |  3 +--
  target/Kconfig                              |  1 +
  target/hexagon/Kconfig                      |  2 ++
  target/hexagon/meson.build                  | 13 ++++++++++++-
  8 files changed, 32 insertions(+), 9 deletions(-)
Quoted 4 lines

create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

Minus the mttcg enable, for the rest:

#24 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

In reply to Brian Cain
Quoted 21 lines · Brian Cain
---
  MAINTAINERS                                 |  1 +
  configs/devices/hexagon-softmmu/default.mak |  7 +++++++
  configs/targets/hexagon-softmmu.mak         |  7 +++++++
  target/hexagon/cpu.h                        |  7 +------
  target/hexagon/cpu.c                        |  3 +--
  target/Kconfig                              |  1 +
  target/hexagon/Kconfig                      |  2 ++
  target/hexagon/meson.build                  | 13 ++++++++++++-
  8 files changed, 32 insertions(+), 9 deletions(-)

create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

MAINTAINERS +0 -0
index b9a7c553dfa..ed661c9f12e 100644

MAINTAINERS F: linux-user/hexagon/ · line 260

Quoted 7 lines
MAINTAINERS +1 -0
@@ -254,6 +254,7 @@ F: linux-user/hexagon/
  F: tests/tcg/hexagon/
  F: disas/hexagon.c
  F: configs/targets/hexagon-linux-user/default.mak
+F: configs/devices/hexagon-softmmu/default.mak
  F: docker/dockerfiles/debian-hexagon-cross.docker
  F: gdbstub/gdb-xml/hexagon*.xml
  F: docs/system/target-hexagon.rst

You really want to have multiple sections here. Easier to discriminate who is responsable for what.

Suggestion:

- Hexagon TCG CPUs
(and implicit linux-user)
- Hexagon Machines
(and implicit softmmu hardware)

configs/targets/hexagon-softmmu.mak line 7

Quoted 13 lines
configs/targets/hexagon-softmmu.mak new file +7 -0
new file mode 100644
index 00000000000..fdfa29b4f39
@@ -0,0 +1,7 @@
+# Default configuration for hexagon-softmmu
+
+TARGET_ARCH=hexagon
+TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
+TARGET_LONG_BITS=32
+TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y

\o/

Quoted 5 lines
target/hexagon/cpu.h +0 -0
index 09d5cac4fe5..18dcfdb0b0a 100644

target/hexagon/cpu.h typedef struct HexagonGlobalRegState HexagonGlobalRegState; · line 40

Quoted 10 lines
target/hexagon/cpu.h +1 -6
@@ -37,12 +37,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState;
  #include "mmvec/mmvec.h"
  #include "hw/core/registerfields.h"
 
-#ifndef CONFIG_USER_ONLY
-#error "Hexagon does not support system emulation"
-#endif
-
-#ifndef CONFIG_USER_ONLY
-#endif
+#include "reg_fields.h"

Please use full "target/hexagon/reg_fields.h" path.

Quoted 32 lines
target/hexagon/cpu.h +0 -0
  #define NUM_PREGS 4
  #define TOTAL_PER_THREAD_REGS 64
 
target/hexagon/meson.build +10 -1
index 528beca3cd0..bc7a292e47b 100644
 
+hexagon_softmmu_ss.add(files(
+    'cpu_helper.c',
+    'hex_mmu.c',
+    'hex_interrupts.c',
+    'hexswi.c',
+    'machine.c',
+))
+
  #
  # Step 4.5
  # We use flex/bison based idef-parser to generate TCG code for a lot
@@ -262,7 +271,8 @@ hexagon_ss.add(files(
  #     idef-generated-enabled-instructions
  #
  idef_parser_enabled = get_option('hexagon_idef_parser')
-if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
+if idef_parser_enabled and ('hexagon-linux-user' in target_dirs or
+                            'hexagon-softmmu' in target_dirs)
      idef_parser_input_generated = custom_target(
          'idef_parser_input.h.inc',
          output: 'idef_parser_input.h.inc',

target/hexagon/meson.build analyze_funcs_generated = custom_target( · line 403

Quoted 4 lines
target/hexagon/meson.build +1 -0
@@ -390,3 +400,4 @@ analyze_funcs_generated = custom_target(
  hexagon_ss.add(analyze_funcs_generated)
 
  target_arch += {'hexagon': hexagon_ss}
+target_system_arch += {'hexagon': hexagon_softmmu_ss}

Pierrick: is target_common_system_arch[] still relevant for a target which use fixed endianness / wordsize?

#25 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

Quoted 104 lines · Philippe Mathieu-Daudé
Quoted 21 lines · Brian Cain

---
  MAINTAINERS                                 |  1 + configs/devices/hexagon-softmmu/default.mak |  7 +++++++ configs/targets/hexagon-softmmu.mak         |  7 +++++++ target/hexagon/cpu.h                        |  7 +------ target/hexagon/cpu.c                        |  3 +-- target/Kconfig                              |  1 + target/hexagon/Kconfig                      |  2 ++ target/hexagon/meson.build                  | 13 ++++++++++++-

  8 files changed, 32 insertions(+), 9 deletions(-)

  create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

MAINTAINERS +0 -0
index b9a7c553dfa..ed661c9f12e 100644
@@ -254,6 +254,7 @@ F: linux-user/hexagon/
Quoted 7 lines

  F: tests/tcg/hexagon/
  F: disas/hexagon.c
  F: configs/targets/hexagon-linux-user/default.mak +F: configs/devices/hexagon-softmmu/default.mak
  F: docker/dockerfiles/debian-hexagon-cross.docker
  F: gdbstub/gdb-xml/hexagon*.xml
  F: docs/system/target-hexagon.rst

You really want to have multiple sections here. Easier to discriminate who is responsable for what.

Suggestion:

- Hexagon TCG CPUs
  (and implicit linux-user)
- Hexagon Machines
  (and implicit softmmu hardware)

configs/targets/hexagon-softmmu.mak line 7

Quoted 13 lines
configs/targets/hexagon-softmmu.mak new file +7 -0
new file mode 100644
index 00000000000..fdfa29b4f39
@@ -0,0 +1,7 @@
+# Default configuration for hexagon-softmmu
+
+TARGET_ARCH=hexagon
+TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
+TARGET_LONG_BITS=32
+TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
+TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y

\o/

Quoted 5 lines
target/hexagon/cpu.h +0 -0
index 09d5cac4fe5..18dcfdb0b0a 100644

target/hexagon/cpu.h typedef struct HexagonGlobalRegState · line 40

Quoted 10 lines
target/hexagon/cpu.h +1 -6
@@ -37,12 +37,7 @@ typedef struct HexagonGlobalRegState 
 HexagonGlobalRegState;
   #include "mmvec/mmvec.h"
   #include "hw/core/registerfields.h"
-#ifndef CONFIG_USER_ONLY
-#error "Hexagon does not support system emulation"
-#endif
-
-#ifndef CONFIG_USER_ONLY
-#endif
+#include "reg_fields.h"

Please use full "target/hexagon/reg_fields.h" path.

Quoted 29 lines
target/hexagon/cpu.h +0 -0
   #define NUM_PREGS 4
   #define TOTAL_PER_THREAD_REGS 64
 
target/hexagon/meson.build +8 -0
index 528beca3cd0..bc7a292e47b 100644
 
+hexagon_softmmu_ss.add(files(
+    'cpu_helper.c',
+    'hex_mmu.c',
+    'hex_interrupts.c',
+    'hexswi.c',
+    'machine.c',
+))
+

  #
  # Step 4.5
  # We use flex/bison based idef-parser to generate TCG code for a lot

target/hexagon/meson.build +2 -1
@@ -262,7 +271,8 @@ hexagon_ss.add(files(
   #     idef-generated-enabled-instructions
   #
   idef_parser_enabled = get_option('hexagon_idef_parser')
-if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
+if idef_parser_enabled and ('hexagon-linux-user' in target_dirs or
+                            'hexagon-softmmu' in target_dirs)

      idef_parser_input_generated = custom_target( 'idef_parser_input.h.inc',

Quoted 9 lines

target/hexagon/meson.build analyze_funcs_generated = custom_target( · line 402

Quoted 5 lines

          output: 'idef_parser_input.h.inc',

target/hexagon/meson.build +1 -0
@@ -390,3 +400,4 @@ analyze_funcs_generated = custom_target(
   hexagon_ss.add(analyze_funcs_generated)
   target_arch += {'hexagon': hexagon_ss}
+target_system_arch += {'hexagon': hexagon_softmmu_ss}

Pierrick: is target_common_system_arch[] still relevant for a target which use fixed endianness / wordsize?

It guarantees code doesn't use any target specific identifier, like accelerators related for instance. Common really means "Does not depend on any build generated target header".

Of course, if target comes in only one variant, it does not really matter, since files will be compiled once anyway. But I think it's more future proof to consider further variations could be added. As well, it forces from the start to do things without relying on compile time defines, which IMHO, is a big win.

Regards,
Pierrick

#26 lore raw

Re: [PATCH v5 7/9] target/hexagon: add build config for softmmu

Quoted 54 lines · Pierrick Bouvier
Quoted 43 lines · Philippe Mathieu-Daudé
Quoted 42 lines · Brian Cain

---
  MAINTAINERS                                 |  1 + configs/devices/hexagon-softmmu/default.mak |  7 +++++++ configs/targets/hexagon-softmmu.mak         |  7 +++++++ target/hexagon/cpu.h                        |  7 +------ target/hexagon/cpu.c                        |  3 +-- target/Kconfig                              |  1 + target/hexagon/Kconfig                      |  2 ++ target/hexagon/meson.build                  | 13 ++++++++++++-

  8 files changed, 32 insertions(+), 9 deletions(-)

  create mode 100644 configs/devices/hexagon-softmmu/default.mak create mode 100644 configs/targets/hexagon-softmmu.mak create mode 100644 target/hexagon/Kconfig

target/hexagon/meson.build +8 -0
index 528beca3cd0..bc7a292e47b 100644
 
+hexagon_softmmu_ss.add(files(
+    'cpu_helper.c',
+    'hex_mmu.c',
+    'hex_interrupts.c',
+    'hexswi.c',
+    'machine.c',
+))
+

  #
  # Step 4.5
  # We use flex/bison based idef-parser to generate TCG code for a lot

target/hexagon/meson.build +2 -1
@@ -262,7 +271,8 @@ hexagon_ss.add(files(
   #     idef-generated-enabled-instructions
   #
   idef_parser_enabled = get_option('hexagon_idef_parser')
-if idef_parser_enabled and 'hexagon-linux-user' in target_dirs
+if idef_parser_enabled and ('hexagon-linux-user' in target_dirs or
+                            'hexagon-softmmu' in target_dirs)

      idef_parser_input_generated = custom_target( 'idef_parser_input.h.inc',

Quoted 9 lines

target/hexagon/meson.build analyze_funcs_generated = custom_target( · line 402

Quoted 5 lines

          output: 'idef_parser_input.h.inc',

target/hexagon/meson.build +1 -0
@@ -390,3 +400,4 @@ analyze_funcs_generated = custom_target(
   hexagon_ss.add(analyze_funcs_generated)
   target_arch += {'hexagon': hexagon_ss}
+target_system_arch += {'hexagon': hexagon_softmmu_ss}

Pierrick: is target_common_system_arch[] still relevant for a target which use fixed endianness / wordsize?

Quoted 4 lines

It guarantees code doesn't use any target specific identifier, like accelerators related for instance. Common really means "Does not depend on any build generated target header".

Of course, if target comes in only one variant, it does not really matter, since files will be compiled once anyway. But I think it's more future proof to consider further variations could be added. As well, it forces from the start to do things without relying on compile time defines, which IMHO, is a big win.

Thanks for confirming my understanding.

author
#27 lore raw

PATCH v5 8/9 hw/hexagon: Define hexagon "virt" machine

In reply to Brian Cain

From: Brian Cain <[email protected]>

---
 configs/devices/hexagon-softmmu/default.mak |   1 +
 configs/targets/hexagon-softmmu.mak         |   1 +
 include/hw/hexagon/virt.h                   |  43 ++
 hw/hexagon/virt.c                           | 456 ++++++++++++++++++++
 target/hexagon/cpu.c                        |   2 +
 hw/hexagon/Kconfig                          |  10 +
 hw/hexagon/meson.build                      |   2 +
 tests/qemu-iotests/testenv.py               |   1 +
 8 files changed, 516 insertions(+)
 create mode 100644 include/hw/hexagon/virt.h
 create mode 100644 hw/hexagon/virt.c
configs/devices/hexagon-softmmu/default.mak +1 -0
index 08e709aea72..37b4f9f3237 100644
@@ -3,5 +3,6 @@
 # Uncomment the following lines to disable these optional devices:
 
 # Boards are selected by default, uncomment to keep out of the build.
+# CONFIG_HEX_VIRT=y
 # CONFIG_HEX_DSP=y
 # CONFIG_L2VIC=y
configs/targets/hexagon-softmmu.mak +1 -0
index fdfa29b4f39..a77c100f0c5 100644
@@ -5,3 +5,4 @@ TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
 TARGET_LONG_BITS=32
 TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
 TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
+TARGET_NEED_FDT=y
include/hw/hexagon/virt.h new file +43 -0

43 lines not on this page · raw message

hw/hexagon/virt.c new file +456 -0

456 lines not on this page · raw message

target/hexagon/cpu.c +2 -0
index 355abb4fd24..01781a76caf 100644
@@ -68,6 +68,8 @@ static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model)
 
 static const Property hexagon_cpu_properties[] = {
 #if !defined(CONFIG_USER_ONLY)
+    DEFINE_PROP_LINK("tlb", HexagonCPU, tlb, TYPE_HEXAGON_TLB,
+                     HexagonTLBState *),
     DEFINE_PROP_UINT32("exec-start-addr", HexagonCPU, boot_addr, 0xffffffff),
     DEFINE_PROP_LINK("global-regs", HexagonCPU, globalregs,
         TYPE_HEXAGON_GLOBALREG, HexagonGlobalRegState *),
hw/hexagon/Kconfig +10 -0
index cdf7770a305..52065ab3b22 100644
@@ -2,3 +2,13 @@ config HEX_DSP
     bool
     default y
     depends on HEXAGON
+
+config HEX_VIRT
+    bool
+    default y
+    depends on HEX_DSP && FDT
+    select DEVICE_TREE
+    select VIRTIO_MMIO
+    select PL011
+    select VIRTIO_BLK
+    select VIRTIO_SCSI
hw/hexagon/meson.build +2 -0
index f528d2bc4ab..5b6a5e11a17 100644
@@ -4,3 +4,5 @@ hexagon_ss.add(files('hexagon_globalreg.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
 
 hw_arch += {'hexagon': hexagon_ss}
+
+hexagon_ss.add(when: 'CONFIG_HEX_VIRT', if_true: files('virt.c'))
tests/qemu-iotests/testenv.py +1 -0
index c357e6ebf50..86bcdf7cfad 100644
@@ -259,6 +259,7 @@ def __init__(self, source_dir: str, build_dir: str,
             ('arm', 'virt'),
             ('aarch64', 'virt'),
             ('avr', 'mega2560'),
+            ('hexagon', 'virt'),
             ('m68k', 'virt'),
             ('or1k', 'virt'),
             ('riscv32', 'virt'),
Signature · 1 line
2.34.1
#28 lore raw

Re: [PATCH v5 8/9] hw/hexagon: Define hexagon "virt" machine

Quoted 47 lines · Brian Cain

From: Brian Cain <[email protected]>

---
  configs/devices/hexagon-softmmu/default.mak |   1 +
  configs/targets/hexagon-softmmu.mak         |   1 +
  include/hw/hexagon/virt.h                   |  43 ++
  hw/hexagon/virt.c                           | 456 ++++++++++++++++++++
  target/hexagon/cpu.c                        |   2 +
  hw/hexagon/Kconfig                          |  10 +
  hw/hexagon/meson.build                      |   2 +
  tests/qemu-iotests/testenv.py               |   1 +
  8 files changed, 516 insertions(+)

create mode 100644 include/hw/hexagon/virt.h
create mode 100644 hw/hexagon/virt.c

configs/devices/hexagon-softmmu/default.mak +1 -0
index 08e709aea72..37b4f9f3237 100644
@@ -3,5 +3,6 @@
  # Uncomment the following lines to disable these optional devices:
 
  # Boards are selected by default, uncomment to keep out of the build.
+# CONFIG_HEX_VIRT=y
  # CONFIG_HEX_DSP=y
  # CONFIG_L2VIC=y
configs/targets/hexagon-softmmu.mak +1 -0
index fdfa29b4f39..a77c100f0c5 100644
@@ -5,3 +5,4 @@ TARGET_XML_FILES=hexagon-core.xml hexagon-hvx.xml
  TARGET_LONG_BITS=32
  TARGET_NOT_USING_LEGACY_LDST_PHYS_API=y
  TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API=y
+TARGET_NEED_FDT=y
include/hw/hexagon/virt.h new file +5 -0
new file mode 100644
index 00000000000..a54eac5cf00
@@ -0,0 +1,43 @@
+/*
+ * Definitions for hexagon virt board.
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later

include/hw/hexagon/virt.h line 15

Quoted 10 lines
include/hw/hexagon/virt.h new file +10 -0
+ */
+
+#ifndef HW_HEXAGONVIRT_H
+#define HW_HEXAGONVIRT_H
+
+#include "hw/core/boards.h"
+#include "target/hexagon/cpu.h"
+
+struct HexagonVirtMachineState {
+    /*< private >*/

(remove this unuseful comment)

Quoted 13 lines
include/hw/hexagon/virt.h new file +13 -0
+    MachineState parent_obj;
+
+    int fdt_size;
+    MemoryRegion *sys;
+    MemoryRegion cfgtable;
+    MemoryRegion ram;
+    MemoryRegion tcm;
+    MemoryRegion vtcm;
+    MemoryRegion bios;
+    DeviceState *l2vic;
+    Clock *apb_clk;
+};
+

include/hw/hexagon/virt.h line 38

Quoted 10 lines
include/hw/hexagon/virt.h new file +10 -0
+void hexagon_load_fdt(const struct HexagonVirtMachineState *vms);
+
+enum {
+    VIRT_UART0,
+    VIRT_QTMR0,
+    VIRT_QTMR1,
+    VIRT_GPT,
+    VIRT_MMIO,
+    VIRT_FDT,
+};

Do we really need to expose this enum? Otherwise it could go in the source.

Quoted 113 lines
include/hw/hexagon/virt.h new file +5 -0
+
+#define TYPE_HEXAGON_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
+OBJECT_DECLARE_SIMPLE_TYPE(HexagonVirtMachineState, HEXAGON_VIRT_MACHINE)
+
+#endif /* HW_HEXAGONVIRT_H */
hw/hexagon/virt.c new file +102 -0
new file mode 100644
index 00000000000..ff93b5221ba
@@ -0,0 +1,456 @@
+/*
+ * Hexagon virt emulation
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/hexagon/virt.h"
+#include "elf.h"
+#include "hw/char/pl011.h"
+#include "hw/core/clock.h"
+#include "hw/core/sysbus-fdt.h"
+#include "hw/hexagon/hexagon.h"
+#include "hw/hexagon/hexagon_globalreg.h"
+#include "hw/hexagon/hexagon_tlb.h"
+#include "hw/core/loader.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/qdev-clock.h"
+#include "hw/core/register.h"
+#include "qemu/error-report.h"
+#include "qemu/guest-random.h"
+#include "qemu/units.h"
+#include "elf.h"
+#include "machine_cfg_v68n_1024.h.inc"
+#include "system/address-spaces.h"
+#include "system/device_tree.h"
+#include "system/reset.h"
+#include "system/system.h"
+#include <libfdt.h>
+
+static const int VIRTIO_DEV_COUNT = 8;
+
+static const MemMapEntry base_memmap[] = {
+    [VIRT_UART0] = { 0x10000000, 0x00000200 },
+    [VIRT_MMIO] = { 0x11000000, 0x1000000, },
+    [VIRT_GPT] = { 0xab000000, 0x00001000 },
+    [VIRT_FDT] = { 0x99800000, 0x00400000 },
+};
+
+static const int irqmap[] = {
+    [VIRT_MMIO] = 18, /* ...to 18 + VIRTIO_DEV_COUNT - 1 */
+    [VIRT_GPT] = 12,
+    [VIRT_UART0] = 15,
+    [VIRT_QTMR0] = 2,
+    [VIRT_QTMR1] = 4,
+};
+
+
+static void create_fdt(HexagonVirtMachineState *vms)
+{
+    MachineState *ms = MACHINE(vms);
+    void *fdt = create_device_tree(&vms->fdt_size);
+    uint8_t rng_seed[32];
+
+    if (!fdt) {
+        error_report("create_device_tree() failed");
+        exit(1);
+    }
+
+    ms->fdt = fdt;
+
+    qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2);
+    qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x1);
+    qemu_fdt_setprop_string(fdt, "/", "model", "hexagon-virt,qemu");
+    qemu_fdt_setprop_string(fdt, "/", "compatible", "qcom,sm8150");
+
+    qemu_fdt_add_subnode(fdt, "/soc");
+    qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
+    qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x1);
+    qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
+
+    qemu_fdt_add_subnode(fdt, "/chosen");
+    qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed));
+    qemu_fdt_setprop(fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
+}
+
+static void fdt_add_hvx(HexagonVirtMachineState *vms,
+                        const struct hexagon_machine_config *m_cfg,
+                        Error **errp)
+{
+    const MachineState *ms = MACHINE(vms);
+    uint32_t vtcm_size_bytes = m_cfg->cfgtable.vtcm_size_kb * 1024;
+    if (vtcm_size_bytes > 0) {
+        memory_region_init_ram(&vms->vtcm, NULL, "vtcm.ram", vtcm_size_bytes,
+                               errp);
+        memory_region_add_subregion(vms->sys, m_cfg->cfgtable.vtcm_base << 16,
+                                    &vms->vtcm);
+
+        qemu_fdt_add_subnode(ms->fdt, "/soc/vtcm");
+        qemu_fdt_setprop_string(ms->fdt, "/soc/vtcm", "compatible",
+                                "qcom,hexagon_vtcm");
+
+        assert(sizeof(m_cfg->cfgtable.vtcm_base) == sizeof(uint32_t));
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/vtcm", "reg", 0,
+                               m_cfg->cfgtable.vtcm_base << 16,
+                               vtcm_size_bytes);
+    }
+
+    if (m_cfg->cfgtable.ext_contexts > 0) {
+        qemu_fdt_add_subnode(ms->fdt, "/soc/hvx");

hw/hexagon/virt.c line 112

Quoted 10 lines
hw/hexagon/virt.c new file +10 -0
+        qemu_fdt_setprop_string(ms->fdt, "/soc/hvx", "compatible",
+                                "qcom,hexagon-hvx");
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/hvx", "qcom,hvx-max-ctxts",
+                               m_cfg->cfgtable.ext_contexts);
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/hvx", "qcom,hvx-vlength",
+                               m_cfg->cfgtable.hvx_vec_log_length);
+    }
+}
+
+static int32_t irq_hvm_ic_phandle = -1;

Maybe better to pass these handles as pointer argument?

Quoted 33 lines
hw/hexagon/virt.c new file +33 -0
+static void fdt_add_hvm_pic_node(HexagonVirtMachineState *vms,
+                                 const struct hexagon_machine_config *m_cfg)
+{
+    MachineState *ms = MACHINE(vms);
+    irq_hvm_ic_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+
+    qemu_fdt_setprop_cell(ms->fdt, "/soc", "interrupt-parent",
+                          irq_hvm_ic_phandle);
+
+    qemu_fdt_add_subnode(ms->fdt, "/soc/interrupt-controller");
+    qemu_fdt_setprop_cell(ms->fdt, "/soc/interrupt-controller",
+                          "#address-cells", 2);
+    qemu_fdt_setprop_cell(ms->fdt, "/soc/interrupt-controller",
+                          "#interrupt-cells", 2);
+    qemu_fdt_setprop_string(ms->fdt, "/soc/interrupt-controller", "compatible",
+                            "qcom,h2-pic,hvm-pic");
+    qemu_fdt_setprop(ms->fdt, "/soc/interrupt-controller",
+                     "interrupt-controller", NULL, 0);
+    qemu_fdt_setprop_cell(ms->fdt, "/soc/interrupt-controller", "phandle",
+                          irq_hvm_ic_phandle);
+
+    sysbus_mmio_map(SYS_BUS_DEVICE(vms->l2vic), 1,
+                    m_cfg->cfgtable.fastl2vic_base << 16);
+}
+
+
+static void fdt_add_gpt_node(HexagonVirtMachineState *vms)
+{
+    g_autofree char *name = NULL;
+    MachineState *ms = MACHINE(vms);
+
+    name = g_strdup_printf("/soc/gpt@%" PRIx64,
+                           (int64_t)base_memmap[VIRT_GPT].base);

hw/hexagon/virt.c line 155

Quoted 10 lines
hw/hexagon/virt.c new file +10 -0
+    qemu_fdt_add_subnode(ms->fdt, name);
+    qemu_fdt_setprop_string(ms->fdt, name, "compatible",
+                            "qcom,h2-timer,hvm-timer");
+    qemu_fdt_setprop_cells(ms->fdt, name, "interrupts", irqmap[VIRT_GPT], 0);
+    qemu_fdt_setprop_cells(ms->fdt, name, "reg", 0x0,
+                           base_memmap[VIRT_GPT].base,
+                           base_memmap[VIRT_GPT].size);
+}
+
+static int32_t clock_phandle = -1;

(ditto)

Quoted 163 lines
hw/hexagon/virt.c new file +163 -0
+static void fdt_add_clocks(const HexagonVirtMachineState *vms)
+{
+    MachineState *ms = MACHINE(vms);
+    clock_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+    qemu_fdt_add_subnode(ms->fdt, "/apb-pclk");
+    qemu_fdt_setprop_string(ms->fdt, "/apb-pclk", "compatible", "fixed-clock");
+    qemu_fdt_setprop_cell(ms->fdt, "/apb-pclk", "#clock-cells", 0x0);
+    qemu_fdt_setprop_cell(ms->fdt, "/apb-pclk", "clock-frequency", 24000000);
+    qemu_fdt_setprop_string(ms->fdt, "/apb-pclk", "clock-output-names",
+                            "clk24mhz");
+    qemu_fdt_setprop_cell(ms->fdt, "/apb-pclk", "phandle", clock_phandle);
+}
+
+static void fdt_add_uart(const HexagonVirtMachineState *vms, int uart)
+{
+    char *nodename;
+    hwaddr base = base_memmap[uart].base;
+    hwaddr size = base_memmap[uart].size;
+    assert(uart == 0);
+    int irq = irqmap[VIRT_UART0 + uart];
+    const char compat[] = "arm,pl011\0arm,primecell";
+    const char clocknames[] = "uartclk\0apb_pclk";
+    MachineState *ms = MACHINE(vms);
+    DeviceState *dev;
+    SysBusDevice *s;
+
+    dev = qdev_new(TYPE_PL011);
+    s = SYS_BUS_DEVICE(dev);
+    qdev_prop_set_chr(dev, "chardev", serial_hd(0));
+    qdev_connect_clock_in(dev, "clk", vms->apb_clk);
+    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_mmio_map(s, 0, base);
+    if (vms->l2vic) {
+        sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->l2vic, irq));
+    }
+
+    nodename = g_strdup_printf("/pl011@%" PRIx64, base);
+    qemu_fdt_add_subnode(ms->fdt, nodename);
+
+    /* Note that we can't use setprop_string because of the embedded NUL */
+    qemu_fdt_setprop(ms->fdt, nodename, "compatible", compat, sizeof(compat));
+    qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0, base, size);
+    if (vms->l2vic) {
+        qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
+                               32 + irq, 0);
+        qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+                              irq_hvm_ic_phandle);
+    }
+    qemu_fdt_setprop_cells(ms->fdt, nodename, "clocks", clock_phandle,
+                           clock_phandle);
+    qemu_fdt_setprop(ms->fdt, nodename, "clock-names", clocknames,
+                     sizeof(clocknames));
+
+    qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename);
+    qemu_fdt_add_subnode(ms->fdt, "/aliases");
+    qemu_fdt_setprop_string(ms->fdt, "/aliases", "serial0", nodename);
+
+    g_free(nodename);
+}
+
+static void fdt_add_cpu_nodes(const HexagonVirtMachineState *vms)
+{
+    MachineState *ms = MACHINE(vms);
+    qemu_fdt_add_subnode(ms->fdt, "/cpus");
+    qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1);
+    qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0);
+
+    /* cpu nodes */
+    for (int num = ms->smp.cpus - 1; num >= 0; num--) {
+        char *nodename = g_strdup_printf("/cpus/cpu@%d", num);
+        qemu_fdt_add_subnode(ms->fdt, nodename);
+        qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu");
+        qemu_fdt_setprop_cell(ms->fdt, nodename, "reg", num);
+        qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle",
+                              qemu_fdt_alloc_phandle(ms->fdt));
+        g_free(nodename);
+    }
+}
+
+
+static void fdt_add_virtio_devices(const HexagonVirtMachineState *vms)
+{
+    MachineState *ms = MACHINE(vms);
+    /* VirtIO MMIO devices */
+    for (int i = 0; i < VIRTIO_DEV_COUNT; i++) {
+        char *nodename;
+        int irq = irqmap[VIRT_MMIO] + i;
+        size_t size = base_memmap[VIRT_MMIO].size;
+        hwaddr base = base_memmap[VIRT_MMIO].base + i * size;
+
+        nodename = g_strdup_printf("/virtio_mmio@%" PRIx64, base);
+        qemu_fdt_add_subnode(ms->fdt, nodename);
+        qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "virtio,mmio");
+        qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 1,
+                                     size);
+        qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", irq, 0);
+        qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+                              irq_hvm_ic_phandle);
+
+        sysbus_create_simple(
+            "virtio-mmio", base,
+            qdev_get_gpio_in(vms->l2vic, irqmap[VIRT_MMIO] + i));
+
+        g_free(nodename);
+    }
+}
+
+static void virt_instance_init(Object *obj)
+{
+    HexagonVirtMachineState *vms = HEXAGON_VIRT_MACHINE(obj);
+
+    create_fdt(vms);
+}
+
+void hexagon_load_fdt(const HexagonVirtMachineState *vms)
+{
+    MachineState *ms = MACHINE(vms);
+    hwaddr fdt_addr = base_memmap[VIRT_FDT].base;
+    uint32_t fdtsize = vms->fdt_size;
+
+    g_assert(fdtsize <= base_memmap[VIRT_FDT].size);
+    /* copy in the device tree */
+    rom_add_blob_fixed_as("fdt", ms->fdt, fdtsize, fdt_addr,
+                          &address_space_memory);
+    qemu_register_reset_nosnapshotload(
+        qemu_fdt_randomize_seeds,
+        rom_ptr_for_as(&address_space_memory, fdt_addr, fdtsize));
+}
+
+static uint64_t load_kernel(const HexagonVirtMachineState *vms)
+{
+    MachineState *ms = MACHINE(vms);
+    uint64_t entry = 0;
+    if (load_elf_ram_sym(ms->kernel_filename, NULL, NULL, NULL, &entry, NULL,
+                         NULL, NULL, 0, EM_HEXAGON, 0, 0, &address_space_memory,
+                         false, NULL) > 0) {
+        return entry;
+    }
+    error_report("error loading '%s'", ms->kernel_filename);
+    exit(1);
+}
+
+static uint64_t load_bios(HexagonVirtMachineState *vms)
+{
+    MachineState *ms = MACHINE(vms);
+    uint64_t bios_addr = 0x0;  /* Load BIOS at reset vector address 0x0 */
+    int bios_size;
+
+    bios_size = load_image_targphys(ms->firmware ?: "",
+                                    bios_addr, 64 * 1024, NULL);
+    if (bios_size < 0) {
+        error_report("Could not load BIOS '%s'", ms->firmware ?: "");
+        exit(1);
+    }
+
+    return bios_addr;  /* Return entry point at address 0x0 */
+}
+
+static void do_cpu_reset(void *opaque)
+{
+    HexagonCPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
+    cpu_reset(cs);

hw/hexagon/virt.c line 328

Quoted 10 lines
hw/hexagon/virt.c new file +10 -0
+}
+
+static void virt_init(MachineState *ms)
+{
+    HexagonVirtMachineState *vms = HEXAGON_VIRT_MACHINE(ms);
+    const struct hexagon_machine_config *m_cfg = &v68n_1024;
+    const char *cpu_model;
+    DeviceState *gsregs_dev;
+    DeviceState *tlb_dev;
+    HexagonCPU *cpu_0;

Maybe directly to only use a single cast:

       DeviceState *cpu0;
Quoted 18 lines
hw/hexagon/virt.c new file +18 -0
+
+    qemu_fdt_setprop_string(ms->fdt, "/chosen", "bootargs", ms->kernel_cmdline);
+
+    vms->sys = get_system_memory();
+
+    /* Create APB clock for peripherals */
+    vms->apb_clk = clock_new(OBJECT(ms), "apb-pclk");
+    clock_set_hz(vms->apb_clk, 24000000);
+
+    memory_region_init_ram(&vms->ram, NULL, "ddr.ram", ms->ram_size,
+                           &error_fatal);
+    memory_region_add_subregion(vms->sys, 0x0, &vms->ram);
+
+    if (m_cfg->l2tcm_size) {
+        memory_region_init_ram(&vms->tcm, NULL, "tcm.ram", m_cfg->l2tcm_size,
+                               &error_fatal);
+        memory_region_add_subregion(vms->sys, m_cfg->cfgtable.l2tcm_base << 16,
+                                    &vms->tcm);

hw/hexagon/virt.c line 356

Quoted 10 lines
hw/hexagon/virt.c new file +10 -0
+    }
+
+    memory_region_init_rom(&vms->cfgtable, NULL, "config_table.rom",
+                           sizeof(m_cfg->cfgtable), &error_fatal);
+    memory_region_add_subregion(vms->sys, m_cfg->cfgbase, &vms->cfgtable);
+    fdt_add_hvx(vms, m_cfg, &error_fatal);
+    cpu_model = ms->cpu_type;
+
+    if (!cpu_model) {
+        cpu_model = HEXAGON_CPU_TYPE_NAME("v68");

Can that happen? There is a default defined...

hw/hexagon/virt.c line 365

Quoted 9 lines
hw/hexagon/virt.c new file +9 -0
+    }
+
+    gsregs_dev = qdev_new(TYPE_HEXAGON_GLOBALREG);
+    object_property_add_child(OBJECT(ms), "global-regs", OBJECT(gsregs_dev));
+    qdev_prop_set_uint64(gsregs_dev, "config-table-addr", m_cfg->cfgbase);
+    qdev_prop_set_uint32(gsregs_dev, "dsp-rev", v68_rev);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(gsregs_dev), &error_fatal);
+
+    tlb_dev = qdev_new(TYPE_HEXAGON_TLB);

Where is hw/hexagon/hexagon_tlb.h?

hw/hexagon/virt.c line 372

Quoted 7 lines
hw/hexagon/virt.c new file +7 -0
+    object_property_add_child(OBJECT(ms), "tlb", OBJECT(tlb_dev));
+    qdev_prop_set_uint32(tlb_dev, "num-entries",
+                         m_cfg->cfgtable.jtlb_size_entries);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(tlb_dev), &error_fatal);
+
+    cpu_0 = NULL;
+    for (int i = 0; i < ms->smp.cpus; i++) {

I suppose they belong to a cluster. In the future we'd create them within a TYPE_CPU_CLUSTER.

Quoted 52 lines
hw/hexagon/virt.c new file +52 -0
+        HexagonCPU *cpu = HEXAGON_CPU(object_new(ms->cpu_type));
+        qemu_register_reset(do_cpu_reset, cpu);
+
+        if (i == 0) {
+            cpu_0 = cpu;
+            if (ms->kernel_filename) {
+                uint64_t entry = load_kernel(vms);
+                qdev_prop_set_uint32(DEVICE(cpu_0), "exec-start-addr", entry);
+            } else if (ms->firmware) {
+                uint64_t entry = load_bios(vms);
+                qdev_prop_set_uint32(DEVICE(cpu_0), "exec-start-addr", entry);
+            }
+        }
+        qdev_prop_set_uint32(DEVICE(cpu), "htid", i);
+        qdev_prop_set_bit(DEVICE(cpu), "start-powered-off", (i != 0));
+        object_property_set_link(OBJECT(cpu), "global-regs",
+                                 OBJECT(gsregs_dev), &error_fatal);
+        object_property_set_link(OBJECT(cpu), "tlb",
+                                 OBJECT(tlb_dev), &error_fatal);
+
+        if (!qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal)) {
+            return;
+        }
+    }
+    /* TODO: enable l2vic when l2vic device arrives */
+    if (object_class_by_name("l2vic")) {
+        vms->l2vic = sysbus_create_varargs(
+            "l2vic", m_cfg->l2vic_base,
+            qdev_get_gpio_in(DEVICE(cpu_0), 0),
+            qdev_get_gpio_in(DEVICE(cpu_0), 1),
+            qdev_get_gpio_in(DEVICE(cpu_0), 2),
+            qdev_get_gpio_in(DEVICE(cpu_0), 3),
+            qdev_get_gpio_in(DEVICE(cpu_0), 4),
+            qdev_get_gpio_in(DEVICE(cpu_0), 5),
+            qdev_get_gpio_in(DEVICE(cpu_0), 6),
+            qdev_get_gpio_in(DEVICE(cpu_0), 7), NULL);
+
+        fdt_add_hvm_pic_node(vms, m_cfg);
+        fdt_add_virtio_devices(vms);
+        fdt_add_gpt_node(vms);
+    }
+
+    fdt_add_cpu_nodes(vms);
+    fdt_add_clocks(vms);
+    fdt_add_uart(vms, VIRT_UART0);
+
+    rom_add_blob_fixed_as("config_table.rom", &m_cfg->cfgtable,
+                          sizeof(m_cfg->cfgtable), m_cfg->cfgbase,
+                          &address_space_memory);
+
+
+    hexagon_load_fdt(vms);

hw/hexagon/virt.c line 434

Quoted 10 lines
hw/hexagon/virt.c new file +10 -0
+}
+
+
+static void virt_class_init(ObjectClass *oc, const void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->desc = "Hexagon Virtual Machine";
+    mc->init = virt_init;
+    mc->default_cpu_type = HEXAGON_CPU_TYPE_NAME("v68");

(this is the default CPU type)

Quoted 75 lines
hw/hexagon/virt.c new file +22 -0
+    mc->default_ram_size = 4 * GiB;
+    mc->max_cpus = 8;
+    mc->default_cpus = 8;
+    mc->is_default = false;
+    mc->default_kernel_irqchip_split = false;
+    mc->block_default_type = IF_VIRTIO;
+    mc->default_boot_order = NULL;
+    mc->no_cdrom = 1;
+    mc->numa_mem_supported = false;
+    mc->default_nic = "virtio-mmio-bus";
+}
+
+
+static const TypeInfo virt_machine_types[] = { {
+    .name = TYPE_HEXAGON_VIRT_MACHINE,
+    .parent = TYPE_MACHINE,
+    .instance_size = sizeof(HexagonVirtMachineState),
+    .class_init = virt_class_init,
+    .instance_init = virt_instance_init,
+} };
+
+DEFINE_TYPES(virt_machine_types)
target/hexagon/cpu.c +2 -0
index 355abb4fd24..01781a76caf 100644
@@ -68,6 +68,8 @@ static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model)
 
  static const Property hexagon_cpu_properties[] = {
  #if !defined(CONFIG_USER_ONLY)
+    DEFINE_PROP_LINK("tlb", HexagonCPU, tlb, TYPE_HEXAGON_TLB,
+                     HexagonTLBState *),
      DEFINE_PROP_UINT32("exec-start-addr", HexagonCPU, boot_addr, 0xffffffff),
      DEFINE_PROP_LINK("global-regs", HexagonCPU, globalregs,
          TYPE_HEXAGON_GLOBALREG, HexagonGlobalRegState *),
hw/hexagon/Kconfig +10 -0
index cdf7770a305..52065ab3b22 100644
@@ -2,3 +2,13 @@ config HEX_DSP
      bool
      default y
      depends on HEXAGON
+
+config HEX_VIRT
+    bool
+    default y
+    depends on HEX_DSP && FDT
+    select DEVICE_TREE
+    select VIRTIO_MMIO
+    select PL011
+    select VIRTIO_BLK
+    select VIRTIO_SCSI
hw/hexagon/meson.build +2 -0
index f528d2bc4ab..5b6a5e11a17 100644
@@ -4,3 +4,5 @@ hexagon_ss.add(files('hexagon_globalreg.c'))
  hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
 
  hw_arch += {'hexagon': hexagon_ss}
+
+hexagon_ss.add(when: 'CONFIG_HEX_VIRT', if_true: files('virt.c'))
tests/qemu-iotests/testenv.py +1 -0
index c357e6ebf50..86bcdf7cfad 100644
@@ -259,6 +259,7 @@ def __init__(self, source_dir: str, build_dir: str,
              ('arm', 'virt'),
              ('aarch64', 'virt'),
              ('avr', 'mega2560'),
+            ('hexagon', 'virt'),
              ('m68k', 'virt'),
              ('or1k', 'virt'),
              ('riscv32', 'virt'),
#29 lore raw

Re: [PATCH v5 8/9] hw/hexagon: Define hexagon "virt" machine

Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 21 lines · Brian Cain

From: Brian Cain <[email protected]>

---
  configs/devices/hexagon-softmmu/default.mak |   1 + configs/targets/hexagon-softmmu.mak         |   1 + include/hw/hexagon/virt.h                   |  43 ++ hw/hexagon/virt.c                           | 456 ++++++++++++++++++++ target/hexagon/cpu.c                        |   2 + hw/hexagon/Kconfig                          |  10 + hw/hexagon/meson.build                      |   2 + tests/qemu-iotests/testenv.py               |   1 +

  8 files changed, 516 insertions(+)

  create mode 100644 include/hw/hexagon/virt.h
  create mode 100644 hw/hexagon/virt.c

+    gsregs_dev = qdev_new(TYPE_HEXAGON_GLOBALREG);
+    object_property_add_child(OBJECT(ms), "global-regs", OBJECT(gsregs_dev));
+    qdev_prop_set_uint64(gsregs_dev, "config-table-addr", m_cfg-

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

cfgbase);

+    qdev_prop_set_uint32(gsregs_dev, "dsp-rev", v68_rev);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(gsregs_dev), &error_fatal); +
+    tlb_dev = qdev_new(TYPE_HEXAGON_TLB);

Where is hw/hexagon/hexagon_tlb.h?

Found it in "part 1/3":

https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 5 lines
Quoted 5 lines

+    object_property_add_child(OBJECT(ms), "tlb", OBJECT(tlb_dev)); +    qdev_prop_set_uint32(tlb_dev, "num-entries",
+                         m_cfg->cfgtable.jtlb_size_entries); +    sysbus_realize_and_unref(SYS_BUS_DEVICE(tlb_dev), &error_fatal);

#30 lore raw

Re: [PATCH v5 8/9] hw/hexagon: Define hexagon "virt" machine

In reply to Brian Cain
Quoted 22 lines · On Thu, 16 Apr 2026 14:03:04 -0700 Brian Cain <[email protected]>…
hw/hexagon/virt.c new file +15 -0
new file mode 100644
index 00000000000..ff93b5221ba
@@ -0,0 +1,456 @@
+/*
+ * Hexagon virt emulation
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/hexagon/virt.h"
+#include "elf.h"
+#include "hw/char/pl011.h"
+#include "hw/core/clock.h"
+#include "hw/core/sysbus-fdt.h"
+#include "hw/hexagon/hexagon.h"

hw/hexagon/virt.c line 25

Quoted 10 lines
hw/hexagon/virt.c new file +10 -0
+#include "hw/hexagon/hexagon_globalreg.h"
+#include "hw/hexagon/hexagon_tlb.h"
+#include "hw/core/loader.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/qdev-clock.h"
+#include "hw/core/register.h"
+#include "qemu/error-report.h"
+#include "qemu/guest-random.h"
+#include "qemu/units.h"
+#include "elf.h"

nit: elf.h was already included above

Quoted 7 lines
hw/hexagon/virt.c new file +7 -0
+#include "machine_cfg_v68n_1024.h.inc"
+#include "system/address-spaces.h"
+#include "system/device_tree.h"
+#include "system/reset.h"
+#include "system/system.h"
+#include <libfdt.h>
+

[...]

hw/hexagon/virt.c line 87

Quoted 9 lines
hw/hexagon/virt.c new file +9 -0
+static void fdt_add_hvx(HexagonVirtMachineState *vms,
+                        const struct hexagon_machine_config *m_cfg,
+                        Error **errp)
+{
+    const MachineState *ms = MACHINE(vms);
+    uint32_t vtcm_size_bytes = m_cfg->cfgtable.vtcm_size_kb * 1024;
+    if (vtcm_size_bytes > 0) {
+        memory_region_init_ram(&vms->vtcm, NULL, "vtcm.ram", vtcm_size_bytes,
+                               errp);

I was going to ask whether we should handle errp here and abort earlier, but fdt_add_hvx is always called with error_fatal, so that's fine. (I wonder, though, should we remove "Error **errp" from the function signature and use error_abort here directly, for clarity and future-proof?)

Quoted 23 lines
hw/hexagon/virt.c new file +23 -0
+        memory_region_add_subregion(vms->sys, m_cfg->cfgtable.vtcm_base << 16,
+                                    &vms->vtcm);
+
+        qemu_fdt_add_subnode(ms->fdt, "/soc/vtcm");
+        qemu_fdt_setprop_string(ms->fdt, "/soc/vtcm", "compatible",
+                                "qcom,hexagon_vtcm");
+
+        assert(sizeof(m_cfg->cfgtable.vtcm_base) == sizeof(uint32_t));
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/vtcm", "reg", 0,
+                               m_cfg->cfgtable.vtcm_base << 16,
+                               vtcm_size_bytes);
+    }
+
+    if (m_cfg->cfgtable.ext_contexts > 0) {
+        qemu_fdt_add_subnode(ms->fdt, "/soc/hvx");
+        qemu_fdt_setprop_string(ms->fdt, "/soc/hvx", "compatible",
+                                "qcom,hexagon-hvx");
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/hvx", "qcom,hvx-max-ctxts",
+                               m_cfg->cfgtable.ext_contexts);
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/hvx", "qcom,hvx-vlength",
+                               m_cfg->cfgtable.hvx_vec_log_length);
+    }
+}
#31 lore raw

Re: [PATCH v5 8/9] hw/hexagon: Define hexagon "virt" machine

Quoted 44 lines · Matheus Tavares Bernardino
Quoted 22 lines · On Thu, 16 Apr 2026 14:03:04 -0700 Brian Cain <[email protected]>…
hw/hexagon/virt.c new file +15 -0
new file mode 100644
index 00000000000..ff93b5221ba
@@ -0,0 +1,456 @@
+/*
+ * Hexagon virt emulation
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/hexagon/virt.h"
+#include "elf.h"
+#include "hw/char/pl011.h"
+#include "hw/core/clock.h"
+#include "hw/core/sysbus-fdt.h"
+#include "hw/hexagon/hexagon.h"

hw/hexagon/virt.c line 25

Quoted 10 lines
hw/hexagon/virt.c new file +10 -0
+#include "hw/hexagon/hexagon_globalreg.h"
+#include "hw/hexagon/hexagon_tlb.h"
+#include "hw/core/loader.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/qdev-clock.h"
+#include "hw/core/register.h"
+#include "qemu/error-report.h"
+#include "qemu/guest-random.h"
+#include "qemu/units.h"
+#include "elf.h"

nit: elf.h was already included above

Quoted 7 lines
hw/hexagon/virt.c new file +7 -0
+#include "machine_cfg_v68n_1024.h.inc"
+#include "system/address-spaces.h"
+#include "system/device_tree.h"
+#include "system/reset.h"
+#include "system/system.h"
+#include <libfdt.h>
+

[...]

Quoted 14 lines

hw/hexagon/virt.c line 87

Quoted 9 lines
hw/hexagon/virt.c new file +9 -0
+static void fdt_add_hvx(HexagonVirtMachineState *vms,
+                        const struct hexagon_machine_config *m_cfg,
+                        Error **errp)
+{
+    const MachineState *ms = MACHINE(vms);
+    uint32_t vtcm_size_bytes = m_cfg->cfgtable.vtcm_size_kb * 1024;
+    if (vtcm_size_bytes > 0) {
+        memory_region_init_ram(&vms->vtcm, NULL, "vtcm.ram", vtcm_size_bytes,
+                               errp);

I was going to ask whether we should handle errp here and abort earlier, but fdt_add_hvx is always called with error_fatal, so that's fine. (I wonder, though, should we remove "Error **errp" from the function signature and use error_abort here directly, for clarity and future-proof?)

The current "unchecked &errp because single use in function" isn't great because we could easily add a 2nd use (like another memory_region_init_ram call) and overwrite the first &errp, ignoring errors. So with that in mind your suggestion is better IMO.

Quoted 24 lines
Quoted 24 lines
hw/hexagon/virt.c new file +23 -0
+        memory_region_add_subregion(vms->sys, m_cfg->cfgtable.vtcm_base << 16,
+                                    &vms->vtcm);
+
+        qemu_fdt_add_subnode(ms->fdt, "/soc/vtcm");
+        qemu_fdt_setprop_string(ms->fdt, "/soc/vtcm", "compatible",
+                                "qcom,hexagon_vtcm");
+
+        assert(sizeof(m_cfg->cfgtable.vtcm_base) == sizeof(uint32_t));
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/vtcm", "reg", 0,
+                               m_cfg->cfgtable.vtcm_base << 16,
+                               vtcm_size_bytes);
+    }
+
+    if (m_cfg->cfgtable.ext_contexts > 0) {
+        qemu_fdt_add_subnode(ms->fdt, "/soc/hvx");
+        qemu_fdt_setprop_string(ms->fdt, "/soc/hvx", "compatible",
+                                "qcom,hexagon-hvx");
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/hvx", "qcom,hvx-max-ctxts",
+                               m_cfg->cfgtable.ext_contexts);
+        qemu_fdt_setprop_cells(ms->fdt, "/soc/hvx", "qcom,hvx-vlength",
+                               m_cfg->cfgtable.hvx_vec_log_length);
+    }
+}
#32 lore raw

Re: [PATCH v5 8/9] hw/hexagon: Define hexagon "virt" machine

In reply to Brian Cain
Quoted 61 lines · Brian Cain

From: Brian Cain <[email protected]>

---
  configs/devices/hexagon-softmmu/default.mak |   1 +
  configs/targets/hexagon-softmmu.mak         |   1 +
  include/hw/hexagon/virt.h                   |  43 ++
  hw/hexagon/virt.c                           | 456 ++++++++++++++++++++
  target/hexagon/cpu.c                        |   2 +
  hw/hexagon/Kconfig                          |  10 +
  hw/hexagon/meson.build                      |   2 +
  tests/qemu-iotests/testenv.py               |   1 +
  8 files changed, 516 insertions(+)

create mode 100644 include/hw/hexagon/virt.h
create mode 100644 hw/hexagon/virt.c

include/hw/hexagon/virt.h new file +31 -0
new file mode 100644
index 00000000000..a54eac5cf00
@@ -0,0 +1,43 @@
+/*
+ * Definitions for hexagon virt board.
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_HEXAGONVIRT_H
+#define HW_HEXAGONVIRT_H
+
+#include "hw/core/boards.h"
+#include "target/hexagon/cpu.h"
+
+struct HexagonVirtMachineState {
+    /*< private >*/
+    MachineState parent_obj;
+
+    int fdt_size;
+    MemoryRegion *sys;
+    MemoryRegion cfgtable;
+    MemoryRegion ram;
+    MemoryRegion tcm;
+    MemoryRegion vtcm;
+    MemoryRegion bios;
+    DeviceState *l2vic;
+    Clock *apb_clk;
+};
 
 
+#define TYPE_HEXAGON_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
+OBJECT_DECLARE_SIMPLE_TYPE(HexagonVirtMachineState, HEXAGON_VIRT_MACHINE)
+
+#endif /* HW_HEXAGONVIRT_H */
hw/hexagon/virt.c new file +0 -0
new file mode 100644
index 00000000000..ff93b5221ba

hw/hexagon/virt.c

Quoted 3 lines
hw/hexagon/virt.c new file +1 -0
 
 
+static int32_t irq_hvm_ic_phandle = -1;

Why not store in HexagonVirtMachineState?

Quoted 24 lines
hw/hexagon/virt.c new file +24 -0
+static void fdt_add_hvm_pic_node(HexagonVirtMachineState *vms,
+                                 const struct hexagon_machine_config *m_cfg)
+{
+    MachineState *ms = MACHINE(vms);
+    irq_hvm_ic_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+
+    qemu_fdt_setprop_cell(ms->fdt, "/soc", "interrupt-parent",
+                          irq_hvm_ic_phandle);
+
+    qemu_fdt_add_subnode(ms->fdt, "/soc/interrupt-controller");
+    qemu_fdt_setprop_cell(ms->fdt, "/soc/interrupt-controller",
+                          "#address-cells", 2);
+    qemu_fdt_setprop_cell(ms->fdt, "/soc/interrupt-controller",
+                          "#interrupt-cells", 2);
+    qemu_fdt_setprop_string(ms->fdt, "/soc/interrupt-controller", "compatible",
+                            "qcom,h2-pic,hvm-pic");
+    qemu_fdt_setprop(ms->fdt, "/soc/interrupt-controller",
+                     "interrupt-controller", NULL, 0);
+    qemu_fdt_setprop_cell(ms->fdt, "/soc/interrupt-controller", "phandle",
+                          irq_hvm_ic_phandle);
+
+    sysbus_mmio_map(SYS_BUS_DEVICE(vms->l2vic), 1,
+                    m_cfg->cfgtable.fastl2vic_base << 16);
+}
author
#33 lore raw

PATCH v5 9/9 tests/qtest: Add hexagon boot-serial-test

In reply to Brian Cain

Add boot-serial-test support for Hexagon architecture using the virt machine.

---
 tests/qtest/boot-serial-test.c | 8 ++++++++
 tests/qtest/meson.build        | 2 ++
 2 files changed, 10 insertions(+)
tests/qtest/boot-serial-test.c +8 -0
index bcd0a9c50e7..37fee7a91c4 100644
@@ -142,6 +142,13 @@ static const uint8_t kernel_stm32vldiscovery[] = {
     0x04, 0x38, 0x01, 0x40                  /* 0x40013804 = USART1 TXD */
 };
 
+static const uint8_t bios_hexagon[] = {
+    0x00, 0x40, 0x00, 0x01,                 /* immext(#0x10000000) */
+    0x00, 0xc0, 0x00, 0x78,                 /* r0 = ##0x10000000 */
+    0x54, 0xc0, 0x00, 0x3c,                 /* memb(r0+#0) = #0x54 Write 'T' */
+    0xf8, 0xff, 0xff, 0x59                  /* jump 0x0 ; Loop back to start */
+};
+
 typedef struct testdef {
     const char *arch;       /* Target architecture */
     const char *machine;    /* Name of the machine */
@@ -194,6 +201,7 @@ static const testdef_t tests[] = {
     { "arm", "microbit", "", "T", sizeof(kernel_nrf51), kernel_nrf51 },
     { "arm", "stm32vldiscovery", "", "T",
       sizeof(kernel_stm32vldiscovery), kernel_stm32vldiscovery },
+    { "hexagon", "virt", "", "TT", sizeof(bios_hexagon), NULL, bios_hexagon },
 
     { NULL }
 };
tests/qtest/meson.build +2 -0
index be4fa627b5f..baa1195371b 100644
@@ -290,6 +290,8 @@ qtests_riscv64 = ['riscv-csr-test'] + \
    config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
    ['iommu-riscv-test'] : [])
 
+qtests_hexagon = ['boot-serial-test']
+
 qos_test_ss = ss.source_set()
 qos_test_ss.add(
   'ac97-test.c',
Signature · 1 line
2.34.1
Acked-by on v5 9/9
#34 lore raw

Re: [PATCH v5 9/9] tests/qtest: Add hexagon boot-serial-test

Quoted 11 lines · Brian Cain

Add boot-serial-test support for Hexagon architecture using the virt machine.

---
  tests/qtest/boot-serial-test.c | 8 ++++++++
  tests/qtest/meson.build        | 2 ++
  2 files changed, 10 insertions(+)

tests/qtest/boot-serial-test.c static const uint8_t kernel_stm32vldiscovery[] = { · line 150

Quoted 6 lines
tests/qtest/boot-serial-test.c +6 -0
+static const uint8_t bios_hexagon[] = {
+    0x00, 0x40, 0x00, 0x01,                 /* immext(#0x10000000) */
+    0x00, 0xc0, 0x00, 0x78,                 /* r0 = ##0x10000000 */
+    0x54, 0xc0, 0x00, 0x3c,                 /* memb(r0+#0) = #0x54 Write 'T' */
+    0xf8, 0xff, 0xff, 0x59                  /* jump 0x0 ; Loop back to start */
+};

Great, thanks!

Reviewed-by on v5 9/9
#35 lore raw

Re: [PATCH v5 9/9] tests/qtest: Add hexagon boot-serial-test

In reply to Brian Cain
Quoted 10 lines · Brian Cain

Add boot-serial-test support for Hexagon architecture using the virt machine.

---
  tests/qtest/boot-serial-test.c | 8 ++++++++
  tests/qtest/meson.build        | 2 ++
  2 files changed, 10 insertions(+)