@samitouri / QOSamiQemu / commits / 197870349f

hw/hexagon: add hex-subsys

The virt and DSP machine models build the same core subsystem, let's abstract out that part. Start with the DDR and config table ROM setup. Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Link: https://lore.kernel.org/qemu-devel/20260806042723.3785369-2-brian.cain@oss.qualcomm.com Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>

Brian Cain committed Aug 5, 2026 at 21:27 UTC 197870349f2b6e5bb3ed89bf1a949ecaca09cd78
5 files changed +54 -27
hw/hexagon/hex-subsys.c new
+32
@@ -0,0 +1,32 @@
1 +/*
2 + * Hexagon subsystem helpers shared between the machine models.
3 + *
4 + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
5 + * SPDX-License-Identifier: GPL-2.0-or-later
6 + */
7 +
8 +#include "qemu/osdep.h"
9 +#include "qapi/error.h"
10 +#include "hw/hexagon/hex-subsys.h"
11 +#include "hw/core/loader.h"
12 +#include "system/address-spaces.h"
13 +
14 +void hex_subsys_create(HexagonCommonMachineState *hms,
15 + const struct hexagon_machine_config *m_cfg)
16 +{
17 + MachineState *machine = MACHINE(hms);
18 + MemoryRegion *sysmem = get_system_memory();
19 +
20 + /* Main DDR at the reset vector. */
21 + memory_region_init_ram(&hms->ram, NULL, "ddr.ram", machine->ram_size,
22 + &error_fatal);
23 + memory_region_add_subregion(sysmem, 0x0, &hms->ram);
24 +
25 + /* Config-table ROM and the blob that backs it. */
26 + memory_region_init_rom(&hms->cfgtable_rom, NULL, "config_table.rom",
27 + sizeof(m_cfg->cfgtable), &error_fatal);
28 + memory_region_add_subregion(sysmem, m_cfg->cfgbase, &hms->cfgtable_rom);
29 + rom_add_blob_fixed_as("config_table.rom", &m_cfg->cfgtable,
30 + sizeof(m_cfg->cfgtable), m_cfg->cfgbase,
31 + &address_space_memory);
32 +}
hw/hexagon/hexagon_dsp.c
+2 -15
@@ -14,6 +14,7 @@
14 #include "hw/core/boards.h"
15 #include "hw/core/qdev-properties.h"
16 #include "hw/hexagon/hexagon.h"
17 +#include "hw/hexagon/hex-subsys.h"
18 #include "hw/hexagon/hexagon_globalreg.h"
19 #include "hw/hexagon/hexagon_tlb.h"
20 #include "hw/core/loader.h"
@@ -108,7 +109,6 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
109 {
110 HexagonCommonMachineState *hms = HEXAGON_COMMON_MACHINE(machine);
111 HexagonDspMachineState *dms = HEXAGON_DSP_MACHINE(machine);
111 - MemoryRegion *address_space;
112 DeviceState *glob_regs_dev;
113 DeviceState *tlb_dev;
114
@@ -120,16 +120,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
120
121 machine->enable_graphics = 0;
122
123 - address_space = get_system_memory();
124 -
125 - memory_region_init_rom(&hms->cfgtable_rom, NULL, "config_table.rom",
126 - sizeof(m_cfg->cfgtable), &error_fatal);
127 - memory_region_add_subregion(address_space, m_cfg->cfgbase,
128 - &hms->cfgtable_rom);
129 -
130 - memory_region_init_ram(&hms->ram, NULL, "ddr.ram",
131 - machine->ram_size, &error_fatal);
132 - memory_region_add_subregion(address_space, 0x0, &hms->ram);
123 + hex_subsys_create(hms, m_cfg);
124
125 glob_regs_dev = qdev_new(TYPE_HEXAGON_GLOBALREG);
126 object_property_add_child(OBJECT(machine), "global-regs",
@@ -162,10 +153,6 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
153 OBJECT(tlb_dev), &error_fatal);
154 qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal);
155 }
165 -
166 - rom_add_blob_fixed_as("config_table.rom", &m_cfg->cfgtable,
167 - sizeof(m_cfg->cfgtable), m_cfg->cfgbase,
168 - &address_space_memory);
156 }
157
158 static void init_mc(MachineClass *mc)
hw/hexagon/meson.build
+1
@@ -1,6 +1,7 @@
1 hexagon_ss = ss.source_set()
2 hexagon_ss.add(files('hexagon_tlb.c'))
3 hexagon_ss.add(files('hexagon_globalreg.c'))
4 +hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hex-subsys.c'))
5 hexagon_ss.add(when: 'CONFIG_HEX_DSP', if_true: files('hexagon_dsp.c'))
6 hexagon_ss.add(when: 'CONFIG_HEX_VIRT', if_true: files('virt.c'))
7
hw/hexagon/virt.c
+2 -12
@@ -13,6 +13,7 @@
13 #include "hw/core/clock.h"
14 #include "hw/core/sysbus-fdt.h"
15 #include "hw/hexagon/hexagon.h"
16 +#include "hw/hexagon/hex-subsys.h"
17 #include "hw/hexagon/hexagon_globalreg.h"
18 #include "hw/hexagon/hexagon_tlb.h"
19 #include "hw/core/loader.h"
@@ -244,9 +245,7 @@ static void virt_init(MachineState *ms)
245 vms->apb_clk = clock_new(OBJECT(ms), "apb-pclk");
246 clock_set_hz(vms->apb_clk, 24000000);
247
247 - memory_region_init_ram(&vms->parent_obj.ram, NULL, "ddr.ram",
248 - ms->ram_size, &error_fatal);
249 - memory_region_add_subregion(vms->sys, 0x0, &vms->parent_obj.ram);
248 + hex_subsys_create(&vms->parent_obj, m_cfg);
249
250 if (m_cfg->l2tcm_size) {
251 memory_region_init_ram(&vms->tcm, NULL, "tcm.ram", m_cfg->l2tcm_size,
@@ -255,11 +254,6 @@ static void virt_init(MachineState *ms)
254 &vms->tcm);
255 }
256
258 - memory_region_init_rom(&vms->parent_obj.cfgtable_rom, NULL,
259 - "config_table.rom", sizeof(m_cfg->cfgtable),
260 - &error_fatal);
261 - memory_region_add_subregion(vms->sys, m_cfg->cfgbase,
262 - &vms->parent_obj.cfgtable_rom);
257 fdt_add_hvx(vms, m_cfg);
258
259 gsregs_dev = qdev_new(TYPE_HEXAGON_GLOBALREG);
@@ -302,10 +296,6 @@ static void virt_init(MachineState *ms)
296 clk_phandle = fdt_add_clocks(vms);
297 fdt_add_uart(vms, VIRT_UART0, clk_phandle);
298
305 - rom_add_blob_fixed_as("config_table.rom", &m_cfg->cfgtable,
306 - sizeof(m_cfg->cfgtable), m_cfg->cfgbase,
307 - &address_space_memory);
308 -
299 hexagon_load_fdt(vms);
300 }
301
include/hw/hexagon/hex-subsys.h new
+17
@@ -0,0 +1,17 @@
1 +/*
2 + * Hexagon subsystem helpers shared between the machine models.
3 + *
4 + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
5 + * SPDX-License-Identifier: GPL-2.0-or-later
6 + */
7 +
8 +#ifndef HW_HEXAGON_HEX_SUBSYS_H
9 +#define HW_HEXAGON_HEX_SUBSYS_H
10 +
11 +#include "hw/hexagon/hexagon.h"
12 +
13 +/* Create the subsystem shared by every Hexagon machine. */
14 +void hex_subsys_create(HexagonCommonMachineState *hms,
15 + const struct hexagon_machine_config *m_cfg);
16 +
17 +#endif /* HW_HEXAGON_HEX_SUBSYS_H */