Skip to contentSkip to conversation

Add hexagon l2vic, qtimer devices

PATCH Superseded Brian Cain 2 participants 20 messages Jul 24 – Jul 27 Arm/Amlogic Meson SoC support

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

v3 cover Add hexagon l2vic, qtimer devices

The previously independent threads for l2vic and qtimer are now combined, which seems to make the most sense because qtimer testing effectively depends on l2vic.

new:
* "refactor with hex-subsys": virt/DSP machines build the same core subsys, so extract it into hw/hexagon/hex-subsys.c. CPUs are now under a TYPE_CPU_CLUSTER.
* "extract get_reg_value/set_reg_value stubs": routes globalreg
r/w through accessors.
* virt machine gains virtio-mmio transports
* addl hexagon-arch-tests enabled

l2vic changes:
* Removed the QemuMutex "active"; the device runs under the BQL.
* Dropped the QEMU_ALIGNED(16) attribute from the bitmaps; no longer needed now that access goes through the bitmap32 helpers.
* Collapsed int_group_n0..int_group_n3 into an int_group_n[4] array.
* Moved the reg-offset macros and L2VIC_INTERRUPT_MAX from hdr to src
* Switched to DEFINE_TYPES()
* Renamed the vid0 field to vid

globalreg changes:
* VID/VID1 and TIMERLO/TIMERHI now go through get_reg_value/ set_reg_value, directing to L2VIC and QTimer respectively.
* l2vic and qtimer links are checked at realization

wiring changes:
* Renamed l2vic_dev to l2vic
* Reworded the connect-l2vic commit message

qtimer changes:
* Renamed the "freq" property to "freq-hz" and the field to freq_hz
* Per-frame frequency now inherits the device freq_hz property, so it is overridable.
* Added .impl = {4, 4} to qct_qtimer_ac_ops.
* Added qct_qtimer_unrealize().
* demux uses (QCT_QTIMER_TIMER_FRAME_ELTS - 1) * stride instead of a hardcoded 0xf * stride.
* getters take a const QctQtimerInterface *.
* Switched to DEFINE_TYPES().
* Removed per-frame freq_hz, these all read-through to the timer's freq.

test changes:
* qct-qtimer qtest: the view-region base is now taken per-machine from the machine config rather than a hardcoded addr, and
the redundant guard around the assert is removed.

l2vic v2: https://lore.kernel.org/qemu-devel/[email protected]/
l2vic v1: https://lore.kernel.org/qemu-devel/[email protected]/
qtimer v1: https://lore.kernel.org/qemu-devel/[email protected]/

Brian Cain (13):
hw/hexagon: refactor with hex-subsys
bitops.h: Add find_first_bit32()
hw/hexagon: extract get_reg_value/set_reg_value stubs in globalreg hw/hexagon: connect l2vic device
hw/hexagon/virt: instantiate virtio-mmio transports hw/hexagon/virt: add l2vic interrupt-controller and virtio-mmio FDT
nodes
hw/hexagon/virt: connect pl011 UART interrupt tests/qtest: add L2VIC qtest
tests/functional/hexagon: add arch_tests functional test hw/timer: Add QCT QTimer device model
hw/hexagon: connect qtimer device
tests/qtest: add qct-qtimer qtest tests/functional/hexagon: enable more arch_tests cases

Sid Manning (1):
hw/intc: Add l2vic interrupt controller

 MAINTAINERS                                 |   7 +
 docs/devel/hexagon-l2vic.rst                |  55 ++
 docs/devel/index-internals.rst              |   1 +
 include/hw/hexagon/hex-subsys.h             |  28 +
 include/hw/hexagon/hexagon.h                |   6 +
 include/hw/hexagon/hexagon_globalreg.h      |   8 +
 include/hw/hexagon/virt.h                   |   1 -
 include/hw/intc/hex-l2vic.h                 |  63 ++
 include/hw/timer/qct-qtimer.h               |  43 ++
 include/qemu/bitops.h                       |  30 +-
 target/hexagon/cpu.h                        |   2 +
 hw/hexagon/hex-subsys.c                     | 169 +++++
 hw/hexagon/hexagon_dsp.c                    |  40 +-
 hw/hexagon/hexagon_globalreg.c              |  65 +-
 hw/hexagon/virt.c                           | 127 ++--
 hw/intc/hex-l2vic.c                         | 536 ++++++++++++++++
 hw/timer/qct-qtimer.c                       | 664 ++++++++++++++++++++
 target/hexagon/cpu.c                        |   2 +
 target/hexagon/op_helper.c                  |  16 +-
 tests/qtest/l2vic-test.c                    | 221 +++++++
 tests/qtest/qct-qtimer-test.c               | 239 +++++++
 hw/hexagon/Kconfig                          |   3 +
 hw/hexagon/meson.build                      |   1 +
 hw/intc/Kconfig                             |   3 +
 hw/intc/meson.build                         |   2 +
 hw/intc/trace-events                        |   4 +
 hw/timer/Kconfig                            |   3 +
 hw/timer/meson.build                        |   2 +
 hw/timer/trace-events                       |   5 +
 tests/functional/hexagon/test_arch_tests.py |  38 ++
 tests/qtest/meson.build                     |   2 +-
 31 files changed, 2293 insertions(+), 93 deletions(-)
 create mode 100644 docs/devel/hexagon-l2vic.rst
 create mode 100644 include/hw/hexagon/hex-subsys.h
 create mode 100644 include/hw/intc/hex-l2vic.h
 create mode 100644 include/hw/timer/qct-qtimer.h
 create mode 100644 hw/hexagon/hex-subsys.c
 create mode 100644 hw/intc/hex-l2vic.c
 create mode 100644 hw/timer/qct-qtimer.c
 create mode 100644 tests/qtest/l2vic-test.c
 create mode 100644 tests/qtest/qct-qtimer-test.c
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/14 hw/hexagon: refactor with hex-subsys

The virt and DSP machine models build the same core subsystem, let's abstract out that part.

The CPUs are now grouped in a TYPE_CPU_CLUSTER.

---
 include/hw/hexagon/hex-subsys.h |  24 ++++++++
 include/hw/hexagon/hexagon.h    |   4 ++
 include/hw/hexagon/virt.h       |   1 -
 hw/hexagon/hex-subsys.c         | 105 ++++++++++++++++++++++++++++++++
 hw/hexagon/hexagon_dsp.c        |  40 ++----------
 hw/hexagon/virt.c               |  52 +++-------------
 hw/hexagon/Kconfig              |   1 +
 hw/hexagon/meson.build          |   1 +
 8 files changed, 147 insertions(+), 81 deletions(-)
 create mode 100644 include/hw/hexagon/hex-subsys.h
 create mode 100644 hw/hexagon/hex-subsys.c
include/hw/hexagon/hex-subsys.h new file +24 -0
new file mode 100644
index 00000000000..73403e8951c
@@ -0,0 +1,24 @@
+/*
+ * Hexagon subsystem helpers shared between the machine models.
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_HEXAGON_HEX_SUBSYS_H
+#define HW_HEXAGON_HEX_SUBSYS_H
+
+#include "hw/hexagon/hexagon.h"
+#include "hw/core/qdev.h"
+
+/* Create the subsystem shared by every Hexagon machine. */
+void hex_subsys_create(HexagonCommonMachineState *hms,
+                       const struct hexagon_machine_config *m_cfg, Rev_t rev);
+
+/* Realize a CPU into the subsystem, then hex_subsys_realize_cluster(). */
+void hex_subsys_realize_cpu(HexagonCommonMachineState *hms, DeviceState *cpu);
+
+/* Realize the CPU cluster, once all CPUs have been parented into it. */
+void hex_subsys_realize_cluster(HexagonCommonMachineState *hms);
+
+#endif /* HW_HEXAGON_HEX_SUBSYS_H */
include/hw/hexagon/hexagon.h +4 -0
index 1034b09c2ac..31669a829f8 100644
@@ -156,6 +156,10 @@ struct HexagonCommonMachineState {
 
     MemoryRegion ram;
     MemoryRegion cfgtable_rom;
+    MemoryRegion vtcm;
+    DeviceState *cluster;
+    DeviceState *glob_regs;
+    DeviceState *tlb;
 };
 
 #endif
include/hw/hexagon/virt.h +0 -1
index fcb47762194..cf0cd2f8f22 100644
@@ -17,7 +17,6 @@ struct HexagonVirtMachineState {
     int fdt_size;
     MemoryRegion *sys;
     MemoryRegion tcm;
-    MemoryRegion vtcm;
     MemoryRegion bios;
     Clock *apb_clk;
 };
hw/hexagon/hex-subsys.c new file +105 -0

105 lines not on this page · raw message

hw/hexagon/hexagon_dsp.c +4 -36
index aa493993229..5275ab92386 100644
@@ -14,8 +14,7 @@
 #include "hw/core/boards.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/hexagon/hexagon.h"
-#include "hw/hexagon/hexagon_globalreg.h"
-#include "hw/hexagon/hexagon_tlb.h"
+#include "hw/hexagon/hex-subsys.h"
 #include "hw/core/loader.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
@@ -108,9 +107,6 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
 {
     HexagonCommonMachineState *hms = HEXAGON_COMMON_MACHINE(machine);
     HexagonDspMachineState *dms = HEXAGON_DSP_MACHINE(machine);
-    MemoryRegion *address_space;
-    DeviceState *glob_regs_dev;
-    DeviceState *tlb_dev;
 
     memset(&hexagon_binfo, 0, sizeof(hexagon_binfo));
     if (machine->kernel_filename) {
@@ -120,29 +116,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
 
     machine->enable_graphics = 0;
 
-    address_space = get_system_memory();
-
-    memory_region_init_rom(&hms->cfgtable_rom, NULL, "config_table.rom",
-                           sizeof(m_cfg->cfgtable), &error_fatal);
-    memory_region_add_subregion(address_space, m_cfg->cfgbase,
-                                &hms->cfgtable_rom);
-
-    memory_region_init_ram(&hms->ram, NULL, "ddr.ram",
-                           machine->ram_size, &error_fatal);
-    memory_region_add_subregion(address_space, 0x0, &hms->ram);
-
-    glob_regs_dev = qdev_new(TYPE_HEXAGON_GLOBALREG);
-    object_property_add_child(OBJECT(machine), "global-regs",
-                              OBJECT(glob_regs_dev));
-    qdev_prop_set_uint64(glob_regs_dev, "config-table-addr", m_cfg->cfgbase);
-    qdev_prop_set_uint32(glob_regs_dev, "dsp-rev", rev);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(glob_regs_dev), &error_fatal);
-
-    tlb_dev = qdev_new(TYPE_HEXAGON_TLB);
-    object_property_add_child(OBJECT(machine), "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);
+    hex_subsys_create(hms, m_cfg, rev);
 
     for (int i = 0; i < machine->smp.cpus; i++) {
         HexagonCPU *cpu = HEXAGON_CPU(object_new(machine->cpu_type));
@@ -156,16 +130,10 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
         if (i == 0) {
             hexagon_init_bootstrap(dms, cpu);
         }
-        object_property_set_link(OBJECT(cpu), "global-regs",
-                                 OBJECT(glob_regs_dev), &error_fatal);
-        object_property_set_link(OBJECT(cpu), "tlb",
-                                 OBJECT(tlb_dev), &error_fatal);
-        qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal);
+        hex_subsys_realize_cpu(hms, DEVICE(cpu));
     }
 
-    rom_add_blob_fixed_as("config_table.rom", &m_cfg->cfgtable,
-                          sizeof(m_cfg->cfgtable), m_cfg->cfgbase,
-                          &address_space_memory);
+    hex_subsys_realize_cluster(hms);
 }
 
 static void init_mc(MachineClass *mc)
hw/hexagon/virt.c +8 -44

102 lines not on this page · raw message

hw/hexagon/Kconfig +1 -0
index 52065ab3b22..121c548bbb9 100644
@@ -2,6 +2,7 @@ config HEX_DSP
     bool
     default y
     depends on HEXAGON
+    select CPU_CLUSTER
 
 config HEX_VIRT
     bool
hw/hexagon/meson.build +1 -0
index bade3a32921..720a5d54dcc 100644
@@ -1,6 +1,7 @@
 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('hex-subsys.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
 hexagon_ss.add(when: 'CONFIG_HEX_VIRT', if_true: files('virt.c'))
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 01/14] hw/hexagon: refactor with hex-subsys

Quoted 4 lines · Brian Cain

The virt and DSP machine models build the same core subsystem, let's abstract out that part.

The CPUs are now grouped in a TYPE_CPU_CLUSTER.

Too many changes in the same patch...

Quoted 20 lines
---
  include/hw/hexagon/hex-subsys.h |  24 ++++++++
  include/hw/hexagon/hexagon.h    |   4 ++
  include/hw/hexagon/virt.h       |   1 -
  hw/hexagon/hex-subsys.c         | 105 ++++++++++++++++++++++++++++++++
  hw/hexagon/hexagon_dsp.c        |  40 ++----------
  hw/hexagon/virt.c               |  52 +++-------------
  hw/hexagon/Kconfig              |   1 +
  hw/hexagon/meson.build          |   1 +
  8 files changed, 147 insertions(+), 81 deletions(-)

create mode 100644 include/hw/hexagon/hex-subsys.h create mode 100644 hw/hexagon/hex-subsys.c

include/hw/hexagon/hexagon.h +0 -0
index 1034b09c2ac..31669a829f8 100644

include/hw/hexagon/hexagon.h struct HexagonCommonMachineState { · line 162

Quoted 7 lines
include/hw/hexagon/hexagon.h +4 -0
@@ -156,6 +156,10 @@ struct HexagonCommonMachineState {
 
      MemoryRegion ram;
      MemoryRegion cfgtable_rom;
+    MemoryRegion vtcm;
+    DeviceState *cluster;
+    DeviceState *glob_regs;
+    DeviceState *tlb;

Each field looks like a natural separation.

Quoted 1 line
include/hw/hexagon/hexagon.h +0 -0
  };
author
#3 lore raw

PATCH v3 2/14 bitops.h: Add find_first_bit32()

In reply to Brian Cain

set_bit32()/test_bit32()/etc already let devices operate on guest-visible uint32_t register arrays without depending on the host's 'unsigned long' size. Add find_first_bit32() so callers need not cast a uint32_t array to 'unsigned long *'.

---
 include/qemu/bitops.h | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)
include/qemu/bitops.h +26 -4
index c7b838a6283..f7363a5479f 100644
@@ -43,10 +43,9 @@
  * be some guest-visible register view of the bit array.
  *
  * We do not currently implement uint32_t versions of find_last_bit(),
- * find_next_bit(), find_next_zero_bit(), find_first_bit() or
- * find_first_zero_bit(), because we haven't yet needed them. If you
- * need them you should implement them similarly to the 'unsigned long'
- * versions.
+ * find_next_bit(), find_next_zero_bit() or find_first_zero_bit(),
+ * because we haven't yet needed them. If you need them you should
+ * implement them similarly to the 'unsigned long' versions.
  *
  * You can declare a bitmap to be used with these functions via the
  * DECLARE_BITMAP and DECLARE_BITMAP32 macros in bitmap.h.
@@ -382,6 +381,29 @@ static inline int test_bit32(long nr, const uint32_t *addr)
     return 1U & (addr[BIT32_WORD(nr)] >> (nr & 31));
 }
 
+/**
+ * find_first_bit32 - find the first set bit in a memory region
+ * @addr: The address to start the search at
+ * @size: The maximum size to search
+ *
+ * Returns the bit number of the first set bit,
+ * or @size if there is no set bit in the bitmap.
+ */
+static inline uint32_t find_first_bit32(const uint32_t *addr, uint32_t size)
+{
+    uint32_t result;
+
+    for (result = 0; result < size; result += 32) {
+        uint32_t tmp = *addr++;
+        if (tmp) {
+            result += ctz32(tmp);
+            return result < size ? result : size;
+        }
+    }
+    /* Not found */
+    return size;
+}
+
 /**
  * DOC: Miscellaneous bit operations on single values
  *
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v3 3/14 hw/intc: Add l2vic interrupt controller

In reply to Brian Cain

From: Sid Manning <[email protected]>

The Hexagon DSP requires an L2VIC to route up to 1024 external interrupt sources through 4 VID output groups into the core's 8 interrupt inputs. Add a device model for it.

---
 MAINTAINERS                    |   3 +
 docs/devel/hexagon-l2vic.rst   |  55 ++++
 docs/devel/index-internals.rst |   1 +
 include/hw/intc/hex-l2vic.h    |  63 ++++
 target/hexagon/cpu.h           |   2 +
 hw/intc/hex-l2vic.c            | 536 +++++++++++++++++++++++++++++++++
 target/hexagon/cpu.c           |   2 +
 target/hexagon/op_helper.c     |  16 +-
 hw/hexagon/Kconfig             |   1 +
 hw/intc/Kconfig                |   3 +
 hw/intc/meson.build            |   2 +
 hw/intc/trace-events           |   4 +
 12 files changed, 687 insertions(+), 1 deletion(-)
 create mode 100644 docs/devel/hexagon-l2vic.rst
 create mode 100644 include/hw/intc/hex-l2vic.h
 create mode 100644 hw/intc/hex-l2vic.c
MAINTAINERS +3 -0
index a28935c8986..a76366d6da5 100644
@@ -250,6 +250,8 @@ M: Brian Cain <[email protected]>
 R: Pierrick Bouvier <[email protected]>
 S: Supported
 F: target/hexagon/
+F: hw/intc/hex-l2vic.c
+F: include/hw/intc/hex-l2vic.h
 X: target/hexagon/idef-parser/
 X: target/hexagon/gen_idef_parser_funcs.py
 F: linux-user/hexagon/
@@ -262,6 +264,7 @@ F: gdbstub/gdb-xml/hexagon*.xml
 F: docs/system/target-hexagon.rst
 F: docs/system/hexagon/
 F: docs/devel/hexagon-sys.rst
+F: docs/devel/hexagon-l2vic.rst
 T: git https://github.com/qualcomm/qemu.git hex-next
 
 Hexagon idef-parser
docs/devel/hexagon-l2vic.rst new file +55 -0

55 lines not on this page · raw message

docs/devel/index-internals.rst +1 -0
index a8f5e310df3..763cda1e76f 100644
@@ -15,6 +15,7 @@ Details about QEMU's various subsystems including how to add features to them.
    clocks
    ebpf_rss
    hexagon-sys
+   hexagon-l2vic
    migration/index
    multi-process
    reset
include/hw/intc/hex-l2vic.h new file +63 -0

63 lines not on this page · raw message

target/hexagon/cpu.h +2 -0
index 7694fd91fa8..f6c3c639325 100644
@@ -39,6 +39,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState;
 #include "qemu/bitmap.h"
 
 #include "target/hexagon/reg_fields.h"
+#include "hw/intc/hex-l2vic.h"
 
 #define NUM_PREGS 4
 #define TOTAL_PER_THREAD_REGS 64
@@ -198,6 +199,7 @@ struct ArchCPU {
     uint32_t boot_addr;
     HexagonGlobalRegState *globalregs;
     uint32_t htid;
+    HexL2VicInterface *l2vic;
 #endif
 };
 
hw/intc/hex-l2vic.c new file +536 -0

536 lines not on this page · raw message

target/hexagon/cpu.c +2 -0
index 12d27ce1381..75cae450299 100644
@@ -65,6 +65,8 @@ static const Property hexagon_cpu_properties[] = {
     DEFINE_PROP_LINK("tlb", HexagonCPU, tlb, TYPE_HEXAGON_TLB,
                      HexagonTLBState *),
     DEFINE_PROP_UINT32("exec-start-addr", HexagonCPU, boot_addr, 0xffffffff),
+    DEFINE_PROP_LINK("l2vic", HexagonCPU, l2vic,
+                     TYPE_HEX_L2VIC_INTERFACE, HexL2VicInterface *),
     DEFINE_PROP_LINK("global-regs", HexagonCPU, globalregs,
         TYPE_HEXAGON_GLOBALREG, HexagonGlobalRegState *),
     DEFINE_PROP_UINT32("htid", HexagonCPU, htid, 0),
target/hexagon/op_helper.c +15 -1
index 3ce223caba3..8fb3d43c33b 100644
@@ -40,6 +40,7 @@
 #include "hw/hexagon/hexagon_globalreg.h"
 #include "hex_mmu.h"
 #include "hw/hexagon/hexagon_tlb.h"
+#include "hw/intc/hex-l2vic.h"
 #include "hex_interrupts.h"
 #include "hexswi.h"
 #endif
@@ -1564,7 +1565,20 @@ void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
 
 void HELPER(ciad)(CPUHexagonState *env, uint32_t mask)
 {
-    g_assert_not_reached();
+    uint32_t ipendad;
+    uint32_t iad;
+    HexagonCPU *cpu;
+
+    BQL_LOCK_GUARD();
+    cpu = env_archcpu(env);
+    ipendad = hexagon_globalreg_read(cpu->globalregs, HEX_SREG_IPENDAD,
+                                      env->threadId);
+    iad = fGET_FIELD(ipendad, IPENDAD_IAD);
+    fSET_FIELD(ipendad, IPENDAD_IAD, iad & ~(mask));
+    hexagon_globalreg_write(cpu->globalregs, HEX_SREG_IPENDAD,
+                            ipendad, env->threadId);
+    l2vic_clear_interrupt(cpu->l2vic);
+    hex_interrupt_update(env);
 }
 
 void HELPER(siad)(CPUHexagonState *env, uint32_t mask)
hw/hexagon/Kconfig +1 -0
index 121c548bbb9..c75090c44a1 100644
@@ -3,6 +3,7 @@ config HEX_DSP
     default y
     depends on HEXAGON
     select CPU_CLUSTER
+    select HEX_L2VIC
 
 config HEX_VIRT
     bool
hw/intc/Kconfig +3 -0
index 636d00b7e88..097de4efc5d 100644
@@ -8,6 +8,9 @@ config I8259
 config PL190
     bool
 
+config HEX_L2VIC
+    bool
+
 config IOAPIC
     bool
     select I8259
hw/intc/meson.build +2 -0
index fac2d228f9b..9077a3f3297 100644
@@ -74,6 +74,8 @@ specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('xics_spapr.c', 'spapr_xi
 specific_ss.add(when: 'CONFIG_XIVE', if_true: files('xive.c'))
 specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XIVE'],
 		if_true: files('spapr_xive_kvm.c'))
+
+specific_ss.add(when: 'CONFIG_HEX_L2VIC', if_true: files('hex-l2vic.c'))
 specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c'))
 specific_ss.add(when: 'CONFIG_LOONGSON_IPI_COMMON', if_true: files('loongson_ipi_common.c'))
 specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: files('loongson_ipi.c'))
hw/intc/trace-events +4 -0
index e7d6c304487..7512c6e6004 100644
@@ -337,6 +337,10 @@ sh_intc_register(const char *s, int id, unsigned short v, int c, int m) "%s %u -
 sh_intc_read(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " -> 0x%lx"
 sh_intc_write(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " <- 0x%lx"
 sh_intc_set(int id, int enable) "setting interrupt group %d to %d"
+# hex-l2vic.c
+hex_l2vic_reg_write(unsigned int addr, uint32_t value) "addr: 0x%03x value: 0x%08"PRIx32
+hex_l2vic_reg_read(unsigned int addr, uint32_t value) "addr: 0x%03x value: 0x%08"PRIx32
+hex_l2vic_delivered(int irq, int vid) "l2vic: delivered %d (vid %d)"
 
 # loongson_ipi.c
 loongson_ipi_read(unsigned size, uint64_t addr, uint64_t val) "size: %u addr: 0x%"PRIx64 "val: 0x%"PRIx64
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH v3 4/14 hw/hexagon: extract get_reg_value/set_reg_value stubs in globalreg

In reply to Brian Cain

Route the globalreg read/write accessors through new get_reg_value()/set_reg_value() helpers instead of touching s->regs[reg] directly.

This will be exploited by a subsequent patch that redirects VID/VID1 accesses to the L2VIC.

---
 hw/hexagon/hexagon_globalreg.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
hw/hexagon/hexagon_globalreg.c +18 -5
index b5e5913507e..105475219ab 100644
@@ -135,6 +135,17 @@ static inline uint32_t apply_write_mask(uint32_t new_val, uint32_t cur_val,
     return new_val;
 }
 
+static uint32_t get_reg_value(HexagonGlobalRegState *s, uint32_t reg)
+{
+    return s->regs[reg];
+}
+
+static void set_reg_value(HexagonGlobalRegState *s, uint32_t reg,
+                          uint32_t value)
+{
+    s->regs[reg] = value;
+}
+
 uint32_t hexagon_globalreg_read(HexagonGlobalRegState *s, uint32_t reg,
                                 uint32_t htid)
 {
@@ -146,7 +157,7 @@ uint32_t hexagon_globalreg_read(HexagonGlobalRegState *s, uint32_t reg,
     g_assert(reg < NUM_SREGS);
     g_assert(reg >= HEX_SREG_GLB_START);
 
-    value = s->regs[reg];
+    value = get_reg_value(s, reg);
 
     trace_hexagon_globalreg_read(htid, get_sreg_name(reg), value);
     return value;
@@ -160,7 +171,7 @@ void hexagon_globalreg_write(HexagonGlobalRegState *s, uint32_t reg,
     }
     g_assert(reg < NUM_SREGS);
     g_assert(reg >= HEX_SREG_GLB_START);
-    s->regs[reg] = value;
+    set_reg_value(s, reg, value);
     trace_hexagon_globalreg_write(htid, get_sreg_name(reg), value);
 }
 
@@ -168,6 +179,7 @@ uint32_t hexagon_globalreg_masked_value(HexagonGlobalRegState *s, uint32_t reg,
                                         uint32_t value)
 {
     uint32_t reg_mask;
+    uint32_t cur_val;
 
     if (!s) {
         return value;
@@ -175,9 +187,10 @@ uint32_t hexagon_globalreg_masked_value(HexagonGlobalRegState *s, uint32_t reg,
     g_assert(reg < NUM_SREGS);
     g_assert(reg >= HEX_SREG_GLB_START);
     reg_mask = global_sreg_immut_masks[reg];
+    cur_val = get_reg_value(s, reg);
     return reg_mask == IMMUTABLE ?
-            s->regs[reg] :
-            apply_write_mask(value, s->regs[reg], reg_mask);
+            cur_val :
+            apply_write_mask(value, cur_val, reg_mask);
 }
 
 void hexagon_globalreg_write_masked(HexagonGlobalRegState *s, uint32_t reg,
@@ -186,7 +199,7 @@ void hexagon_globalreg_write_masked(HexagonGlobalRegState *s, uint32_t reg,
     if (!s) {
         return;
     }
-    s->regs[reg] = hexagon_globalreg_masked_value(s, reg, value);
+    set_reg_value(s, reg, hexagon_globalreg_masked_value(s, reg, value));
 }
 
 uint64_t hexagon_globalreg_get_pcycle_base(HexagonGlobalRegState *s)
Signature · 1 line
2.34.1
Reviewed-by on v3 4/14
#6 lore raw

Re: [PATCH v3 04/14] hw/hexagon: extract get_reg_value/set_reg_value stubs in globalreg

Quoted 11 lines · Brian Cain

Route the globalreg read/write accessors through new get_reg_value()/set_reg_value() helpers instead of touching s->regs[reg] directly.

This will be exploited by a subsequent patch that redirects VID/VID1 accesses to the L2VIC.

---
  hw/hexagon/hexagon_globalreg.c | 23 ++++++++++++++++++-----
  1 file changed, 18 insertions(+), 5 deletions(-)
author
#7 lore raw

PATCH v3 5/14 hw/hexagon: connect l2vic device

In reply to Brian Cain

Add the l2vic to the shared hex-subsys so both machine models pick it up. Map its register banks, wire the interrupt lines to CPU[0] and link each vCPU, globalregs.

---
 include/hw/hexagon/hex-subsys.h        |  8 ++++--
 include/hw/hexagon/hexagon.h           |  1 +
 include/hw/hexagon/hexagon_globalreg.h |  4 +++
 hw/hexagon/hex-subsys.c                | 38 +++++++++++++++++++++++++-
 hw/hexagon/hexagon_dsp.c               |  2 +-
 hw/hexagon/hexagon_globalreg.c         | 25 +++++++++++++++++
 hw/hexagon/virt.c                      |  2 +-
 7 files changed, 75 insertions(+), 5 deletions(-)
include/hw/hexagon/hex-subsys.h +6 -2
index 73403e8951c..cdd59f09e4f 100644
@@ -15,8 +15,12 @@
 void hex_subsys_create(HexagonCommonMachineState *hms,
                        const struct hexagon_machine_config *m_cfg, Rev_t rev);
 
-/* Realize a CPU into the subsystem, then hex_subsys_realize_cluster(). */
-void hex_subsys_realize_cpu(HexagonCommonMachineState *hms, DeviceState *cpu);
+/*
+ * Realize a CPU into the subsystem, then hex_subsys_realize_cluster().
+ * CPU[0] receives the L2VIC outputs.
+ */
+void hex_subsys_realize_cpu(HexagonCommonMachineState *hms, DeviceState *cpu,
+                            bool boot_cpu);
 
 /* Realize the CPU cluster, once all CPUs have been parented into it. */
 void hex_subsys_realize_cluster(HexagonCommonMachineState *hms);
include/hw/hexagon/hexagon.h +1 -0
index 31669a829f8..ec1578807d8 100644
@@ -158,6 +158,7 @@ struct HexagonCommonMachineState {
     MemoryRegion cfgtable_rom;
     MemoryRegion vtcm;
     DeviceState *cluster;
+    DeviceState *l2vic;
     DeviceState *glob_regs;
     DeviceState *tlb;
 };
include/hw/hexagon/hexagon_globalreg.h +4 -0
index 950099808fd..397dc6854c9 100644
@@ -10,6 +10,7 @@
 
 #include "hw/core/qdev.h"
 #include "hw/core/sysbus.h"
+#include "hw/intc/hex-l2vic.h"
 #include "qom/object.h"
 #include "target/hexagon/cpu.h"
 
@@ -22,6 +23,9 @@ struct HexagonGlobalRegState {
     /* Array of system registers */
     uint32_t regs[NUM_SREGS];
 
+    /* L2VIC interface used to back the VID/VID1 registers */
+    HexL2VicInterface *l2vic;
+
     /* Global performance cycle counter base */
     uint64_t g_pcycle_base;
 
hw/hexagon/hex-subsys.c +37 -1
index 638b6429100..5f238006bae 100644
@@ -10,6 +10,7 @@
 #include "hw/hexagon/hex-subsys.h"
 #include "hw/hexagon/hexagon_globalreg.h"
 #include "hw/hexagon/hexagon_tlb.h"
+#include "hw/intc/hex-l2vic.h"
 #include "hw/cpu/cluster.h"
 #include "hw/core/loader.h"
 #include "hw/core/qdev-properties.h"
@@ -17,6 +18,31 @@
 #include "hw/core/sysbus.h"
 #include "system/address-spaces.h"
 
+#define HEX_L2VIC_CPU_IRQS 8
+
+static DeviceState *l2vic_create(HexagonCommonMachineState *hms,
+                                 const struct hexagon_machine_config *m_cfg)
+{
+    DeviceState *l2vic = qdev_new(TYPE_HEX_L2VIC);
+
+    object_property_add_child(OBJECT(hms), "l2vic", OBJECT(l2vic));
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(l2vic), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(l2vic), 0, m_cfg->l2vic_base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(l2vic), 1,
+                    m_cfg->cfgtable.fastl2vic_base << 16);
+
+    return l2vic;
+}
+
+static void l2vic_connect_cpu(DeviceState *l2vic, DeviceState *cpu)
+{
+    int i;
+
+    for (i = 0; i < HEX_L2VIC_CPU_IRQS; i++) {
+        sysbus_connect_irq(SYS_BUS_DEVICE(l2vic), i, qdev_get_gpio_in(cpu, i));
+    }
+}
+
 static DeviceState *globalreg_create(HexagonCommonMachineState *hms,
                                      const struct hexagon_machine_config *m_cfg,
                                      Rev_t rev)
@@ -26,6 +52,8 @@ static DeviceState *globalreg_create(HexagonCommonMachineState *hms,
     object_property_add_child(OBJECT(hms), "global-regs", OBJECT(glob_regs));
     qdev_prop_set_uint64(glob_regs, "config-table-addr", m_cfg->cfgbase);
     qdev_prop_set_uint32(glob_regs, "dsp-rev", rev);
+    object_property_set_link(OBJECT(glob_regs), "l2vic", OBJECT(hms->l2vic),
+                             &error_fatal);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(glob_regs), &error_fatal);
 
     return glob_regs;
@@ -81,18 +109,26 @@ void hex_subsys_create(HexagonCommonMachineState *hms,
     }
 
     hms->cluster = cluster_create(hms);
+    hms->l2vic = l2vic_create(hms, m_cfg);
     hms->glob_regs = globalreg_create(hms, m_cfg, rev);
     hms->tlb = tlb_create(hms, m_cfg);
 }
 
-void hex_subsys_realize_cpu(HexagonCommonMachineState *hms, DeviceState *cpu)
+void hex_subsys_realize_cpu(HexagonCommonMachineState *hms, DeviceState *cpu,
+                            bool boot_cpu)
 {
     object_property_add_child(OBJECT(hms->cluster), "cpu[*]", OBJECT(cpu));
     object_property_set_link(OBJECT(cpu), "global-regs",
                              OBJECT(hms->glob_regs), &error_fatal);
     object_property_set_link(OBJECT(cpu), "tlb", OBJECT(hms->tlb),
                              &error_fatal);
+    object_property_set_link(OBJECT(cpu), "l2vic", OBJECT(hms->l2vic),
+                             &error_fatal);
     qdev_realize_and_unref(cpu, NULL, &error_fatal);
+
+    if (boot_cpu) {
+        l2vic_connect_cpu(hms->l2vic, cpu);
+    }
 }
 
 void hex_subsys_realize_cluster(HexagonCommonMachineState *hms)
hw/hexagon/hexagon_dsp.c +1 -1
index 5275ab92386..6be5668471c 100644
@@ -130,7 +130,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
         if (i == 0) {
             hexagon_init_bootstrap(dms, cpu);
         }
-        hex_subsys_realize_cpu(hms, DEVICE(cpu));
+        hex_subsys_realize_cpu(hms, DEVICE(cpu), (i == 0));
     }
 
     hex_subsys_realize_cluster(hms);
hw/hexagon/hexagon_globalreg.c +25 -0
index 105475219ab..285cb48c44b 100644
@@ -11,6 +11,7 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/core/sysbus.h"
 #include "hw/core/resettable.h"
+#include "hw/intc/hex-l2vic.h"
 #include "migration/vmstate.h"
 #include "qom/object.h"
 #include "target/hexagon/cpu.h"
@@ -135,8 +136,16 @@ static inline uint32_t apply_write_mask(uint32_t new_val, uint32_t cur_val,
     return new_val;
 }
 
+static inline bool is_vid_reg(uint32_t reg)
+{
+    return reg == HEX_SREG_VID || reg == HEX_SREG_VID1;
+}
+
 static uint32_t get_reg_value(HexagonGlobalRegState *s, uint32_t reg)
 {
+    if (is_vid_reg(reg)) {
+        return l2vic_read_vid(s->l2vic, reg == HEX_SREG_VID ? 0 : 1);
+    }
     return s->regs[reg];
 }
 
@@ -144,6 +153,9 @@ static void set_reg_value(HexagonGlobalRegState *s, uint32_t reg,
                           uint32_t value)
 {
     s->regs[reg] = value;
+    if (is_vid_reg(reg)) {
+        l2vic_update_vid(s->l2vic, reg == HEX_SREG_VID ? 0 : 1, value);
+    }
 }
 
 uint32_t hexagon_globalreg_read(HexagonGlobalRegState *s, uint32_t reg,
@@ -269,6 +281,16 @@ static void hexagon_globalreg_reset_hold(Object *obj, ResetType type)
     do_hexagon_globalreg_reset(s);
 }
 
+static void hexagon_globalreg_realize(DeviceState *dev, Error **errp)
+{
+    HexagonGlobalRegState *s = HEXAGON_GLOBALREG(dev);
+
+    if (!s->l2vic) {
+        error_setg(errp, "hexagon_globalreg: 'l2vic' link property not set");
+        return;
+    }
+}
+
 static const VMStateDescription vmstate_hexagon_globalreg = {
     .name = "hexagon_globalreg",
     .version_id = 1,
@@ -288,6 +310,8 @@ static const VMStateDescription vmstate_hexagon_globalreg = {
 };
 
 static const Property hexagon_globalreg_properties[] = {
+    DEFINE_PROP_LINK("l2vic", HexagonGlobalRegState, l2vic,
+                     TYPE_HEX_L2VIC_INTERFACE, HexL2VicInterface *),
     DEFINE_PROP_UINT32("boot-evb", HexagonGlobalRegState, boot_evb, 0x0),
     DEFINE_PROP_UINT64("config-table-addr", HexagonGlobalRegState,
                        config_table_addr, 0xffffffffULL),
@@ -308,6 +332,7 @@ static void hexagon_globalreg_class_init(ObjectClass *klass, const void *data)
     ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     rc->phases.hold = hexagon_globalreg_reset_hold;
+    dc->realize = hexagon_globalreg_realize;
     dc->vmsd = &vmstate_hexagon_globalreg;
     dc->user_creatable = false;
     device_class_set_props(dc, hexagon_globalreg_properties);
hw/hexagon/virt.c +1 -1
index ac2b6605dbd..7561aedd2b7 100644
@@ -267,7 +267,7 @@ static void virt_init(MachineState *ms)
         }
         qdev_prop_set_uint32(DEVICE(cpu), "htid", i);
         qdev_prop_set_bit(DEVICE(cpu), "start-powered-off", (i != 0));
-        hex_subsys_realize_cpu(&vms->parent_obj, DEVICE(cpu));
+        hex_subsys_realize_cpu(&vms->parent_obj, DEVICE(cpu), (i == 0));
     }
 
     hex_subsys_realize_cluster(&vms->parent_obj);
Signature · 1 line
2.34.1
Reviewed-by on v3 5/14
#8 lore raw

Re: [PATCH v3 05/14] hw/hexagon: connect l2vic device

Quoted 5 lines · Brian Cain

Add the l2vic to the shared hex-subsys so both machine models pick it up. Map its register banks, wire the interrupt lines to CPU[0] and link each vCPU, globalregs.

Quoted 9 lines
---
  include/hw/hexagon/hex-subsys.h        |  8 ++++--
  include/hw/hexagon/hexagon.h           |  1 +
  include/hw/hexagon/hexagon_globalreg.h |  4 +++
  hw/hexagon/hex-subsys.c                | 38 +++++++++++++++++++++++++-
  hw/hexagon/hexagon_dsp.c               |  2 +-
  hw/hexagon/hexagon_globalreg.c         | 25 +++++++++++++++++
  hw/hexagon/virt.c                      |  2 +-
  7 files changed, 75 insertions(+), 5 deletions(-)
author
#9 lore raw

PATCH v3 6/14 hw/hexagon/virt: instantiate virtio-mmio transports

In reply to Brian Cain

Add a VIRT_MMIO region and virtio-mmio transports, wired into l2vic.

---
 hw/hexagon/virt.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
hw/hexagon/virt.c +28 -0
index 7561aedd2b7..46ff0687528 100644
@@ -30,11 +30,20 @@
 
 enum {
     VIRT_UART0,
+    VIRT_MMIO,
     VIRT_FDT,
 };
 
+static const int VIRTIO_DEV_COUNT = 8;
+/*
+ * Virtio IRQs run from VIRTIO_IRQ_BASE to
+ * VIRTIO_IRQ_BASE + VIRTIO_DEV_COUNT - 1
+ */
+static const int VIRTIO_IRQ_BASE = 16;
+
 static const MemMapEntry base_memmap[] = {
     [VIRT_UART0] = { 0x10000000, 0x00000200 },
+    [VIRT_MMIO] = { 0x11000000, 0x00001000 },
     [VIRT_FDT] = { 0x99800000, 0x00400000 },
 };
 
@@ -167,7 +176,24 @@ static void fdt_add_cpu_nodes(const HexagonVirtMachineState *vms)
     }
 }
 
+static void create_virtio_devices(const HexagonVirtMachineState *vms)
+{
+    hwaddr size = base_memmap[VIRT_MMIO].size;
 
+    for (int i = 0; i < VIRTIO_DEV_COUNT; i++) {
+        int irq = VIRTIO_IRQ_BASE + i;
+        hwaddr base = base_memmap[VIRT_MMIO].base + i * size;
+        DeviceState *dev = qdev_new("virtio-mmio");
+        SysBusDevice *s = SYS_BUS_DEVICE(dev);
+
+        object_property_add_child(OBJECT(MACHINE(vms)), "virtio-mmio[*]",
+                                  OBJECT(dev));
+        sysbus_realize_and_unref(s, &error_fatal);
+        sysbus_mmio_map(s, 0, base);
+        sysbus_connect_irq(s, 0,
+                           qdev_get_gpio_in(vms->parent_obj.l2vic, irq));
+    }
+}
 
 static void virt_instance_init(Object *obj)
 {
@@ -252,6 +278,8 @@ static void virt_init(MachineState *ms)
 
     fdt_add_hvx(vms, m_cfg);
 
+    create_virtio_devices(vms);
+
     for (int i = 0; i < ms->smp.cpus; i++) {
         HexagonCPU *cpu = HEXAGON_CPU(object_new(ms->cpu_type));
         qemu_register_reset(do_cpu_reset, cpu);
Signature · 1 line
2.34.1
Reviewed-by on v3 6/14
#10 lore raw

Re: [PATCH v3 06/14] hw/hexagon/virt: instantiate virtio-mmio transports

Quoted 8 lines · Brian Cain

Add a VIRT_MMIO region and virtio-mmio transports, wired into l2vic.

---
  hw/hexagon/virt.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)

hw/hexagon/virt.c static void fdt_add_cpu_nodes(const HexagonVirtMachineState *vms) · line 186

Quoted 8 lines
hw/hexagon/virt.c +7 -0
+static void create_virtio_devices(const HexagonVirtMachineState *vms)
+{
+    hwaddr size = base_memmap[VIRT_MMIO].size;
 
+    for (int i = 0; i < VIRTIO_DEV_COUNT; i++) {
+        int irq = VIRTIO_IRQ_BASE + i;
+        hwaddr base = base_memmap[VIRT_MMIO].base + i * size;
+        DeviceState *dev = qdev_new("virtio-mmio");

Better to keep a reference in HexagonVirtMachineState, otherwise:

Quoted 10 lines
hw/hexagon/virt.c +10 -0
+        SysBusDevice *s = SYS_BUS_DEVICE(dev);
+
+        object_property_add_child(OBJECT(MACHINE(vms)), "virtio-mmio[*]",
+                                  OBJECT(dev));
+        sysbus_realize_and_unref(s, &error_fatal);
+        sysbus_mmio_map(s, 0, base);
+        sysbus_connect_irq(s, 0,
+                           qdev_get_gpio_in(vms->parent_obj.l2vic, irq));
+    }
+}
author
#11 lore raw

PATCH v3 7/14 hw/hexagon/virt: add l2vic interrupt-controller and virtio-mmio FDT nodes

In reply to Brian Cain

Expose l2vic as a device-tree interrupt-controller node and reference it via interrupt-parent, so guest kernels can discover the virtio-mmio transports.

---
 hw/hexagon/virt.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)
hw/hexagon/virt.c +41 -2
index 46ff0687528..78e71d3bd65 100644
@@ -76,6 +76,30 @@ static void create_fdt(HexagonVirtMachineState *vms)
     qemu_fdt_setprop(fdt, "/chosen", "rng-seed", rng_seed, sizeof(rng_seed));
 }
 
+static int32_t fdt_add_l2vic(HexagonVirtMachineState *vms,
+                             const struct hexagon_machine_config *m_cfg)
+{
+    MachineState *ms = MACHINE(vms);
+    int32_t l2vic_phandle = qemu_fdt_alloc_phandle(ms->fdt);
+    char *nodename = g_strdup_printf("/soc/interrupt-controller@%x",
+                                     m_cfg->l2vic_base);
+    const char compat[] = "qcom,h2-pic\0hvm-pic";
+
+    qemu_fdt_setprop_cell(ms->fdt, "/soc", "interrupt-parent", l2vic_phandle);
+
+    qemu_fdt_add_subnode(ms->fdt, nodename);
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "#address-cells", 0x0);
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 0x1);
+    qemu_fdt_setprop(ms->fdt, nodename, "compatible", compat, sizeof(compat));
+    qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0,
+                           m_cfg->l2vic_base, m_cfg->l2vic_size);
+    qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0);
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", l2vic_phandle);
+
+    g_free(nodename);
+    return l2vic_phandle;
+}
+
 static void fdt_add_hvx(HexagonVirtMachineState *vms,
                         const struct hexagon_machine_config *m_cfg)
 {
@@ -176,13 +200,16 @@ static void fdt_add_cpu_nodes(const HexagonVirtMachineState *vms)
     }
 }
 
-static void create_virtio_devices(const HexagonVirtMachineState *vms)
+static void create_virtio_devices(const HexagonVirtMachineState *vms,
+                                  int32_t l2vic_phandle)
 {
+    MachineState *ms = MACHINE(vms);
     hwaddr size = base_memmap[VIRT_MMIO].size;
 
     for (int i = 0; i < VIRTIO_DEV_COUNT; i++) {
         int irq = VIRTIO_IRQ_BASE + i;
         hwaddr base = base_memmap[VIRT_MMIO].base + i * size;
+        char *nodename = g_strdup_printf("/soc/virtio_mmio@%" PRIx64, base);
         DeviceState *dev = qdev_new("virtio-mmio");
         SysBusDevice *s = SYS_BUS_DEVICE(dev);
 
@@ -192,6 +219,16 @@ static void create_virtio_devices(const HexagonVirtMachineState *vms)
         sysbus_mmio_map(s, 0, base);
         sysbus_connect_irq(s, 0,
                            qdev_get_gpio_in(vms->parent_obj.l2vic, irq));
+
+        qemu_fdt_add_subnode(ms->fdt, nodename);
+        qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
+                                "virtio,mmio");
+        qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0, base, size);
+        qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupts", irq);
+        qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+                              l2vic_phandle);
+
+        g_free(nodename);
     }
 }
 
@@ -258,6 +295,7 @@ static void virt_init(MachineState *ms)
     HexagonVirtMachineState *vms = HEXAGON_VIRT_MACHINE(ms);
     const struct hexagon_machine_config *m_cfg = &v68n_1024;
     int32_t clk_phandle;
+    int32_t l2vic_phandle;
 
     qemu_fdt_setprop_string(ms->fdt, "/chosen", "bootargs", ms->kernel_cmdline);
 
@@ -278,7 +316,8 @@ static void virt_init(MachineState *ms)
 
     fdt_add_hvx(vms, m_cfg);
 
-    create_virtio_devices(vms);
+    l2vic_phandle = fdt_add_l2vic(vms, m_cfg);
+    create_virtio_devices(vms, l2vic_phandle);
 
     for (int i = 0; i < ms->smp.cpus; i++) {
         HexagonCPU *cpu = HEXAGON_CPU(object_new(ms->cpu_type));
Signature · 1 line
2.34.1
author
#12 lore raw

PATCH v3 8/14 hw/hexagon/virt: connect pl011 UART interrupt

In reply to Brian Cain

Wire pl011's sysbus IRQ into l2vic at IRQ 15.

---
 hw/hexagon/virt.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
hw/hexagon/virt.c +8 -2
index 78e71d3bd65..cc3893b8ebb 100644
@@ -40,6 +40,7 @@ static const int VIRTIO_DEV_COUNT = 8;
  * VIRTIO_IRQ_BASE + VIRTIO_DEV_COUNT - 1
  */
 static const int VIRTIO_IRQ_BASE = 16;
+static const int VIRT_UART0_IRQ = 15;
 
 static const MemMapEntry base_memmap[] = {
     [VIRT_UART0] = { 0x10000000, 0x00000200 },
@@ -144,7 +145,7 @@ static int32_t fdt_add_clocks(const HexagonVirtMachineState *vms)
 }
 
 static void fdt_add_uart(const HexagonVirtMachineState *vms, int uart,
-                         int32_t clk_phandle)
+                         int32_t clk_phandle, int32_t l2vic_phandle)
 {
     char *nodename;
     hwaddr base = base_memmap[uart].base;
@@ -162,6 +163,8 @@ static void fdt_add_uart(const HexagonVirtMachineState *vms, int uart,
     qdev_connect_clock_in(dev, "clk", vms->apb_clk);
     sysbus_realize_and_unref(s, &error_fatal);
     sysbus_mmio_map(s, 0, base);
+    sysbus_connect_irq(s, 0,
+                       qdev_get_gpio_in(vms->parent_obj.l2vic, VIRT_UART0_IRQ));
 
     nodename = g_strdup_printf("/pl011@%" PRIx64, base);
     qemu_fdt_add_subnode(ms->fdt, nodename);
@@ -169,6 +172,9 @@ static void fdt_add_uart(const HexagonVirtMachineState *vms, int uart,
     /* 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);
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupts", VIRT_UART0_IRQ);
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
+                          l2vic_phandle);
     qemu_fdt_setprop_cells(ms->fdt, nodename, "clocks", clk_phandle,
                            clk_phandle);
     qemu_fdt_setprop(ms->fdt, nodename, "clock-names", clocknames,
@@ -341,7 +347,7 @@ static void virt_init(MachineState *ms)
 
     fdt_add_cpu_nodes(vms);
     clk_phandle = fdt_add_clocks(vms);
-    fdt_add_uart(vms, VIRT_UART0, clk_phandle);
+    fdt_add_uart(vms, VIRT_UART0, clk_phandle, l2vic_phandle);
 
     hexagon_load_fdt(vms);
 }
Signature · 1 line
2.34.1
author
#14 lore raw

PATCH v3 9/14 tests/qtest: add L2VIC qtest

In reply to Brian Cain

Add a qtest exercising L2VIC register access and interrupt enable/disable.

---
 MAINTAINERS              |   1 +
 tests/qtest/l2vic-test.c | 221 +++++++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build  |   2 +-
 3 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/l2vic-test.c
MAINTAINERS +1 -0
index a76366d6da5..114bbec45ad 100644
@@ -252,6 +252,7 @@ S: Supported
 F: target/hexagon/
 F: hw/intc/hex-l2vic.c
 F: include/hw/intc/hex-l2vic.h
+F: tests/qtest/l2vic-test.c
 X: target/hexagon/idef-parser/
 X: target/hexagon/gen_idef_parser_funcs.py
 F: linux-user/hexagon/
tests/qtest/l2vic-test.c new file +221 -0

221 lines not on this page · raw message

tests/qtest/meson.build +1 -1
index 56ff860e216..a76863c7dd6 100644
@@ -299,7 +299,7 @@ qtests_riscv64 = ['riscv-csr-test'] + \
    ['iommu-riscv-test'] : []) + \
   (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test'] : [])
 
-qtests_hexagon = ['boot-serial-test']
+qtests_hexagon = ['boot-serial-test', 'l2vic-test']
 
 qos_test_ss = ss.source_set()
 qos_test_ss.add(
Signature · 1 line
2.34.1
author
#15 lore raw

PATCH v3 10/14 tests/functional/hexagon: add arch_tests functional test

In reply to Brian Cain

Add the test_int_steering case from hexagon-arch-tests.

---
 tests/functional/hexagon/test_arch_tests.py | 6 ++++++
 1 file changed, 6 insertions(+)
tests/functional/hexagon/test_arch_tests.py +6 -0
index 54a1412c597..2bb34f9b8dc 100755
@@ -52,6 +52,12 @@ def test_guest_mode(self) -> None:
         """
         self.run_uart_test("test_guest_mode")
 
+    def test_int_steering(self) -> None:
+        """Tests interrupt steering via priority-based routing to
+        specific threads using STID priority and iassignw.
+        """
+        self.run_uart_test("test_int_steering")
+
 
 if __name__ == "__main__":
     QemuSystemTest.main()
Signature · 1 line
2.34.1
author
#16 lore raw

PATCH v3 11/14 hw/timer: Add QCT QTimer device model

In reply to Brian Cain

Implement the QCT QTimer generic timer device used by Hexagon DSP systems.

---
 MAINTAINERS                   |   2 +
 include/hw/timer/qct-qtimer.h |  43 +++
 hw/timer/qct-qtimer.c         | 664 ++++++++++++++++++++++++++++++++++
 hw/timer/Kconfig              |   3 +
 hw/timer/meson.build          |   2 +
 hw/timer/trace-events         |   5 +
 6 files changed, 719 insertions(+)
 create mode 100644 include/hw/timer/qct-qtimer.h
 create mode 100644 hw/timer/qct-qtimer.c
MAINTAINERS +2 -0
index 114bbec45ad..de106416b64 100644
@@ -253,6 +253,8 @@ F: target/hexagon/
 F: hw/intc/hex-l2vic.c
 F: include/hw/intc/hex-l2vic.h
 F: tests/qtest/l2vic-test.c
+F: hw/timer/qct-qtimer.c
+F: include/hw/timer/qct-qtimer.h
 X: target/hexagon/idef-parser/
 X: target/hexagon/gen_idef_parser_funcs.py
 F: linux-user/hexagon/
include/hw/timer/qct-qtimer.h new file +43 -0

43 lines not on this page · raw message

hw/timer/qct-qtimer.c new file +664 -0

664 lines not on this page · raw message

hw/timer/Kconfig +3 -0
index b3d823ce2c3..e1b751a54a7 100644
@@ -65,3 +65,6 @@ config STELLARIS_GPTM
 
 config AVR_TIMER16
     bool
+
+config HEX_QTIMER
+    bool
hw/timer/meson.build +2 -0
index 201b5d8316d..0e8326b0492 100644
@@ -34,3 +34,5 @@ specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_timer.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_PWM', if_true: files('sifive_pwm.c'))
 
 system_ss.add(when: 'CONFIG_AVR_TIMER16', if_true: files('avr_timer16.c'))
+
+specific_ss.add(when: 'CONFIG_HEX_QTIMER', if_true: files('qct-qtimer.c'))
hw/timer/trace-events +5 -0
index 634ba1da27a..636310f8caa 100644
@@ -128,3 +128,8 @@ imx_epit_get_freq(uint32_t freq) "ptimer frequency is %u"
 imx_epit_read(const char *name, uint32_t value) "(%s) = 0x%08x"
 imx_epit_write(const char *name, uint64_t value) "(%s, value = 0x%08" PRIx64 ")"
 imx_epit_cmp(uint32_t sr) "sr was %d"
+
+# qct-qtimer.c
+qtimer_interrupt(void) "qtimer interrupt line updated"
+qtimer_read(uint64_t offset) "offset 0x%" PRIx64
+qtimer_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64
Signature · 1 line
2.34.1
author
#17 lore raw

PATCH v3 12/14 hw/hexagon: connect qtimer device

In reply to Brian Cain

Add the QTimer to the shared hex-subsys so both machine models pick it up. Map its view region, wire its interrupt lines into l2vic, and link it to the globalreg device backing HEX_SREG_TIMERLO/TIMERHI.

---
 include/hw/hexagon/hexagon.h           |  1 +
 include/hw/hexagon/hexagon_globalreg.h |  4 ++++
 hw/hexagon/hex-subsys.c                | 28 ++++++++++++++++++++++++++
 hw/hexagon/hexagon_globalreg.c         | 17 ++++++++++++++++
 hw/hexagon/Kconfig                     |  1 +
 5 files changed, 51 insertions(+)
include/hw/hexagon/hexagon.h +1 -0
index ec1578807d8..3d7b3cb12dc 100644
@@ -159,6 +159,7 @@ struct HexagonCommonMachineState {
     MemoryRegion vtcm;
     DeviceState *cluster;
     DeviceState *l2vic;
+    DeviceState *qtimer;
     DeviceState *glob_regs;
     DeviceState *tlb;
 };
include/hw/hexagon/hexagon_globalreg.h +4 -0
index 397dc6854c9..07437dfabb1 100644
@@ -11,6 +11,7 @@
 #include "hw/core/qdev.h"
 #include "hw/core/sysbus.h"
 #include "hw/intc/hex-l2vic.h"
+#include "hw/timer/qct-qtimer.h"
 #include "qom/object.h"
 #include "target/hexagon/cpu.h"
 
@@ -26,6 +27,9 @@ struct HexagonGlobalRegState {
     /* L2VIC interface used to back the VID/VID1 registers */
     HexL2VicInterface *l2vic;
 
+    /* QTimer interface used to back the TIMERLO/TIMERHI registers */
+    QctQtimerInterface *qtimer;
+
     /* Global performance cycle counter base */
     uint64_t g_pcycle_base;
 
hw/hexagon/hex-subsys.c +28 -0
index 5f238006bae..b231b749eb9 100644
@@ -11,6 +11,7 @@
 #include "hw/hexagon/hexagon_globalreg.h"
 #include "hw/hexagon/hexagon_tlb.h"
 #include "hw/intc/hex-l2vic.h"
+#include "hw/timer/qct-qtimer.h"
 #include "hw/cpu/cluster.h"
 #include "hw/core/loader.h"
 #include "hw/core/qdev-properties.h"
@@ -20,6 +21,13 @@
 
 #define HEX_L2VIC_CPU_IRQS 8
 
+/* L2VIC input lines the QTimer's two frames are wired to. */
+#define HEX_QTIMER_L2VIC_IRQ0 3
+#define HEX_QTIMER_L2VIC_IRQ1 4
+
+/* Number of QTimer frames instantiated for every Hexagon machine. */
+#define HEX_QTIMER_NR_FRAMES 3
+
 static DeviceState *l2vic_create(HexagonCommonMachineState *hms,
                                  const struct hexagon_machine_config *m_cfg)
 {
@@ -43,6 +51,23 @@ static void l2vic_connect_cpu(DeviceState *l2vic, DeviceState *cpu)
     }
 }
 
+static DeviceState *qtimer_create(HexagonCommonMachineState *hms,
+                                  const struct hexagon_machine_config *m_cfg)
+{
+    DeviceState *qtimer = qdev_new(TYPE_QCT_QTIMER);
+
+    object_property_add_child(OBJECT(hms), "qtimer", OBJECT(qtimer));
+    qdev_prop_set_uint32(qtimer, "nr_frames", HEX_QTIMER_NR_FRAMES);
+    sysbus_realize_and_unref(SYS_BUS_DEVICE(qtimer), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(qtimer), 1, m_cfg->qtmr_region);
+    sysbus_connect_irq(SYS_BUS_DEVICE(qtimer), 0,
+                       qdev_get_gpio_in(hms->l2vic, HEX_QTIMER_L2VIC_IRQ0));
+    sysbus_connect_irq(SYS_BUS_DEVICE(qtimer), 1,
+                       qdev_get_gpio_in(hms->l2vic, HEX_QTIMER_L2VIC_IRQ1));
+
+    return qtimer;
+}
+
 static DeviceState *globalreg_create(HexagonCommonMachineState *hms,
                                      const struct hexagon_machine_config *m_cfg,
                                      Rev_t rev)
@@ -54,6 +79,8 @@ static DeviceState *globalreg_create(HexagonCommonMachineState *hms,
     qdev_prop_set_uint32(glob_regs, "dsp-rev", rev);
     object_property_set_link(OBJECT(glob_regs), "l2vic", OBJECT(hms->l2vic),
                              &error_fatal);
+    object_property_set_link(OBJECT(glob_regs), "qtimer", OBJECT(hms->qtimer),
+                             &error_fatal);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(glob_regs), &error_fatal);
 
     return glob_regs;
@@ -110,6 +137,7 @@ void hex_subsys_create(HexagonCommonMachineState *hms,
 
     hms->cluster = cluster_create(hms);
     hms->l2vic = l2vic_create(hms, m_cfg);
+    hms->qtimer = qtimer_create(hms, m_cfg);
     hms->glob_regs = globalreg_create(hms, m_cfg, rev);
     hms->tlb = tlb_create(hms, m_cfg);
 }
hw/hexagon/hexagon_globalreg.c +17 -0
index 285cb48c44b..61621cf2b8f 100644
@@ -12,6 +12,7 @@
 #include "hw/core/sysbus.h"
 #include "hw/core/resettable.h"
 #include "hw/intc/hex-l2vic.h"
+#include "hw/timer/qct-qtimer.h"
 #include "migration/vmstate.h"
 #include "qom/object.h"
 #include "target/hexagon/cpu.h"
@@ -141,11 +142,21 @@ static inline bool is_vid_reg(uint32_t reg)
     return reg == HEX_SREG_VID || reg == HEX_SREG_VID1;
 }
 
+static inline bool is_timer_reg(uint32_t reg)
+{
+    return reg == HEX_SREG_TIMERLO || reg == HEX_SREG_TIMERHI;
+}
+
 static uint32_t get_reg_value(HexagonGlobalRegState *s, uint32_t reg)
 {
     if (is_vid_reg(reg)) {
         return l2vic_read_vid(s->l2vic, reg == HEX_SREG_VID ? 0 : 1);
     }
+    if (is_timer_reg(reg)) {
+        return reg == HEX_SREG_TIMERLO ?
+                qct_qtimer_get_timer_lo(s->qtimer) :
+                qct_qtimer_get_timer_hi(s->qtimer);
+    }
     return s->regs[reg];
 }
 
@@ -289,6 +300,10 @@ static void hexagon_globalreg_realize(DeviceState *dev, Error **errp)
         error_setg(errp, "hexagon_globalreg: 'l2vic' link property not set");
         return;
     }
+    if (!s->qtimer) {
+        error_setg(errp, "hexagon_globalreg: 'qtimer' link property not set");
+        return;
+    }
 }
 
 static const VMStateDescription vmstate_hexagon_globalreg = {
@@ -312,6 +327,8 @@ static const VMStateDescription vmstate_hexagon_globalreg = {
 static const Property hexagon_globalreg_properties[] = {
     DEFINE_PROP_LINK("l2vic", HexagonGlobalRegState, l2vic,
                      TYPE_HEX_L2VIC_INTERFACE, HexL2VicInterface *),
+    DEFINE_PROP_LINK("qtimer", HexagonGlobalRegState, qtimer,
+                     TYPE_QCT_QTIMER_INTERFACE, QctQtimerInterface *),
     DEFINE_PROP_UINT32("boot-evb", HexagonGlobalRegState, boot_evb, 0x0),
     DEFINE_PROP_UINT64("config-table-addr", HexagonGlobalRegState,
                        config_table_addr, 0xffffffffULL),
hw/hexagon/Kconfig +1 -0
index c75090c44a1..83b2763d1e3 100644
@@ -4,6 +4,7 @@ config HEX_DSP
     depends on HEXAGON
     select CPU_CLUSTER
     select HEX_L2VIC
+    select HEX_QTIMER
 
 config HEX_VIRT
     bool
Signature · 1 line
2.34.1
author
#18 lore raw

PATCH v3 13/14 tests/qtest: add qct-qtimer qtest

In reply to Brian Cain

Add a qtest exercising the QCT QTimer's register access, view-region frame addressing, and one-shot timer firing behavior.

---
 MAINTAINERS                   |   1 +
 tests/qtest/qct-qtimer-test.c | 239 ++++++++++++++++++++++++++++++++++
 tests/qtest/meson.build       |   2 +-
 3 files changed, 241 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/qct-qtimer-test.c
MAINTAINERS +1 -0
index de106416b64..0e0b99084df 100644
@@ -255,6 +255,7 @@ F: include/hw/intc/hex-l2vic.h
 F: tests/qtest/l2vic-test.c
 F: hw/timer/qct-qtimer.c
 F: include/hw/timer/qct-qtimer.h
+F: tests/qtest/qct-qtimer-test.c
 X: target/hexagon/idef-parser/
 X: target/hexagon/gen_idef_parser_funcs.py
 F: linux-user/hexagon/
tests/qtest/qct-qtimer-test.c new file +239 -0

239 lines not on this page · raw message

tests/qtest/meson.build +1 -1
index a76863c7dd6..651246b2ebb 100644
@@ -299,7 +299,7 @@ qtests_riscv64 = ['riscv-csr-test'] + \
    ['iommu-riscv-test'] : []) + \
   (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test'] : [])
 
-qtests_hexagon = ['boot-serial-test', 'l2vic-test']
+qtests_hexagon = ['boot-serial-test', 'l2vic-test', 'qct-qtimer-test']
 
 qos_test_ss = ss.source_set()
 qos_test_ss.add(
Signature · 1 line
2.34.1
author
#19 lore raw

PATCH v3 14/14 tests/functional/hexagon: enable more arch_tests cases

In reply to Brian Cain

Add more tests from hexagon-arch-tests, enabled by QTimer device.

These exercise cache maintenance ops, l2vic, thread start/stop, tlb/mmu operations, and user-mode transitions.

---
 tests/functional/hexagon/test_arch_tests.py | 32 +++++++++++++++++++++
 1 file changed, 32 insertions(+)
tests/functional/hexagon/test_arch_tests.py +32 -0
index 2bb34f9b8dc..0834398c3b1 100755
@@ -58,6 +58,38 @@ def test_int_steering(self) -> None:
         """
         self.run_uart_test("test_int_steering")
 
+    def test_cache(self) -> None:
+        """Tests cache operations: dckill/ickill, l2kill, dczeroa,
+        dccleaninva, cache disable/enable, barriers, and dcinva/dccleana.
+        """
+        self.run_uart_test("test_cache")
+
+    def test_l2vic(self) -> None:
+        """Tests the L2VIC interrupt controller: enable readback,
+        interrupt type readback, VID capture, and the fast interface.
+        """
+        self.run_uart_test("test_l2vic")
+
+    def test_threads(self) -> None:
+        """Tests hardware thread management: start/stop, MODECTL state,
+        per-thread HTID, shared memory, wait/resume, STID priority, and
+        SCHEDCFG/BESTWAIT readback.
+        """
+        self.run_uart_test("test_threads")
+
+    def test_tlb_mmu(self) -> None:
+        """Tests TLB/MMU operations: write/read/probe/invalidate,
+        global entries, multiple entries, overwrite, ASID matching,
+        and permission checks.
+        """
+        self.run_uart_test("test_tlb_mmu")
+
+    def test_user_mode(self) -> None:
+        """Tests user mode / privilege transitions: supervisor mode,
+        SSR UM/IE/XE/CE/PE bits, and the trap0 user-mode exit handler.
+        """
+        self.run_uart_test("test_user_mode")
+
 
 if __name__ == "__main__":
     QemuSystemTest.main()
Signature · 1 line
2.34.1