Skip to contentSkip to conversation

add remote-port protocol implementation

RFC PATCH New [email protected] 1 participant 3 messages Dec 16, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover add remote-port protocol implementation

This patch series implements simulation of processor peripherals using SystemC-based modules running outside QEMU. The underlying mechanism for communication with external simulation environments from QEMU side is Remote Port socket based interface.

The simulation is provided by libSystemCTLM-SoC [1].

Originally implemented by Edgar Iglesias. The sources are now available at QEMU repo at AMD: https://github.com/Xilinx/qemu.

The implementation was checked on AWS Graviton 4 based metal instances with Renesas sourced peripherals (example link to follow).

There are number of modules which can be used including PCIe-based or MMIO based device. The SMMU support for later are going to be implemented within further patches.

[1] Link to the TLM2.0 protocol:
https://github.com/Xilinx/libsystemctlm-soc

[2] Overall description:
https://systemc.org/overview/systemc-tlm/

#1 lore raw

RFC PATCH 1/2 hw/core: Add support for loading a Hardware Device Tree

From: Ruslan Ruslichenko <[email protected]>

This feature allows QEMU to dynamically instantiate hardware model, instead of relying on static configs.

Key changes:

- Added a new global option '-hw-dtb' to the QEMU command-line parser.
- Implemented logic in the fdt-generic to parse this DTB and dynamically instantiate devices, memory regions, and interrupts based on the node definitions.

---
 blockdev.c                       |   12 +
 hw/arm/boot.c                    |    8 +-
 hw/arm/raspi4b.c                 |    4 +-
 hw/arm/vexpress.c                |    4 +-
 hw/arm/xlnx-zcu102.c             |    3 +-
 hw/core/fdt_generic.c            |  283 +++++
 hw/core/fdt_generic_devices.c    |  130 +++
 hw/core/fdt_generic_util.c       | 1883 ++++++++++++++++++++++++++++++
 hw/core/machine.c                |   19 +
 hw/core/meson.build              |    3 +
 include/hw/boards.h              |    1 +
 include/hw/fdt_generic.h         |  126 ++
 include/hw/fdt_generic_devices.h |   22 +
 include/hw/fdt_generic_util.h    |  283 +++++
 include/hw/qdev-properties.h     |    1 +
 include/net/net.h                |    4 +
 include/qemu/log.h               |    3 +
 include/system/blockdev.h        |    2 +
 include/system/device_tree.h     |  101 +-
 net/net.c                        |    4 +-
 qemu-options.hx                  |    9 +
 system/device_tree.c             |  377 +++++-
 system/globals.c                 |    2 +
 system/vl.c                      |    3 +
 24 files changed, 3248 insertions(+), 39 deletions(-)
 create mode 100644 hw/core/fdt_generic.c
 create mode 100644 hw/core/fdt_generic_devices.c
 create mode 100644 hw/core/fdt_generic_util.c
 create mode 100644 include/hw/fdt_generic.h
 create mode 100644 include/hw/fdt_generic_devices.h
 create mode 100644 include/hw/fdt_generic_util.h
blockdev.c +12 -0
index dbd1d4d3e8..fb97951149 100644
@@ -306,6 +306,18 @@ int drive_get_max_bus(BlockInterfaceType type)
     return max_bus;
 }
 
+/* Xilinx: keep for fdt_generic */
+/* Get a block device.  This should only be used for single-drive devices
+ * (e.g. SD/Floppy/MTD).  Multi-disk devices (scsi/ide) should use the
+ *  appropriate bus.
+ */
+DriveInfo *drive_get_next(BlockInterfaceType type)
+{
+    static int next_block_unit[IF_COUNT];
+   
+    return drive_get(type, 0, next_block_unit[type]++);
+}
+
 static void bdrv_format_print(void *opaque, const char *name)
 {
     qemu_printf(" %s", name);
hw/arm/boot.c +4 -4
index b91660208f..a2125efc7f 100644
@@ -509,10 +509,10 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
         return 0;
     }
 
-    acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells",
-                                   NULL, &error_fatal);
-    scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells",
-                                   NULL, &error_fatal);
+    acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells", 0,
+                                   false, &error_fatal);
+    scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells", 0,
+                                   false, &error_fatal);
     if (acells == 0 || scells == 0) {
         fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");
         goto fail;
hw/arm/raspi4b.c +2 -2
index 0422ae0f00..c06dc88d1b 100644
@@ -42,9 +42,9 @@ static void raspi_add_memory_node(void *fdt, hwaddr mem_base, hwaddr mem_len)
     uint32_t acells, scells;
     char *nodename = g_strdup_printf("/memory@%" PRIx64, mem_base);
 
-    acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells",
+    acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells", 0,
                                    NULL, &error_fatal);
-    scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells",
+    scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells", 0,
                                    NULL, &error_fatal);
     /* validated by arm_load_dtb */
     g_assert(acells && scells);
hw/arm/vexpress.c +2 -2
index 3492e03a65..e5cb884a50 100644
@@ -486,9 +486,9 @@ static void vexpress_modify_dtb(const struct arm_boot_info *info, void *fdt)
     const VEDBoardInfo *daughterboard = (const VEDBoardInfo *)info;
 
     acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells",
-                                   NULL, &error_fatal);
+                                   0, 0, &error_fatal);
     scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells",
-                                   NULL, &error_fatal);
+                                   0, 0, &error_fatal);
     intc = find_int_controller(fdt);
     if (!intc) {
         /* Not fatal, we just won't provide virtio. This will
hw/arm/xlnx-zcu102.c +2 -1
index 06a3d7dfe7..64b77d041a 100644
@@ -88,7 +88,8 @@ static void zcu102_modify_dtb(const struct arm_boot_info *binfo, void *fdt)
                                        &error_fatal);
 
         for (i = 0; node_path && node_path[i]; i++) {
-            r = qemu_fdt_getprop(fdt, node_path[i], "method", &prop_len, NULL);
+            r = qemu_fdt_getprop(fdt, node_path[i], "method", &prop_len,
+                false, NULL);
             method_is_hvc = r && !strcmp("hvc", r);
 
             /* Allow HVC based firmware if EL2 is enabled.  */
hw/core/fdt_generic.c new file +283 -0

283 lines not on this page · raw message

hw/core/fdt_generic_devices.c new file +130 -0

130 lines not on this page · raw message

hw/core/fdt_generic_util.c new file +1883 -0

1,884 lines not on this page · raw message

hw/core/machine.c +19 -0
index 27372bb01e..361da5978f 100644
@@ -375,6 +375,20 @@ static void machine_set_dtb(Object *obj, const char *value, Error **errp)
     ms->dtb = g_strdup(value);
 }
 
+static char *machine_get_hw_dtb(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->hw_dtb);
+}
+
+static void machine_set_hw_dtb(Object *obj, const char *value, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    ms->hw_dtb = g_strdup(value);
+}
+
 static char *machine_get_dumpdtb(Object *obj, Error **errp)
 {
     MachineState *ms = MACHINE(obj);
@@ -1284,6 +1298,11 @@ static void machine_initfn(Object *obj)
     ms->ram_size = mc->default_ram_size;
     ms->maxram_size = mc->default_ram_size;
 
+    object_property_add_str(obj, "hw-dtb",
+        machine_get_hw_dtb, machine_set_hw_dtb);
+    object_property_set_description(obj, "hw-dtb",
+                "A device tree used to describe the hardware to QEMU.");
+
     if (mc->nvdimm_supported) {
         ms->nvdimms_state = g_new0(NVDIMMState, 1);
         object_property_add_bool(obj, "nvdimm",
hw/core/meson.build +3 -0
index b5a545a0ed..cea3b4660e 100644
@@ -28,6 +28,9 @@ system_ss.add(when: 'CONFIG_EIF', if_true: [files('eif.c'), zlib, libcbor, gnutl
 
 system_ss.add(files(
   'cpu-system.c',
+  'fdt_generic.c',
+  'fdt_generic_devices.c',
+  'fdt_generic_util.c',
   'fw-path-provider.c',
   'gpio.c',
   'hotplug.c',
include/hw/boards.h +1 -0
index a48ed4f86a..68711be386 100644
@@ -402,6 +402,7 @@ struct MachineState {
 
     void *fdt;
     char *dtb;
+    char *hw_dtb;
     char *dumpdtb;
     int phandle_start;
     char *dt_compatible;
include/hw/fdt_generic.h new file +126 -0

126 lines not on this page · raw message

include/hw/fdt_generic_devices.h new file +22 -0
new file mode 100644
index 0000000000..f5eada89b5
@@ -0,0 +1,22 @@
+#ifndef FDT_GENERIC_DEVICES_H
+#define FDT_GENERIC_DEVICES_H
+
+#include "fdt_generic.h"
+#include "exec/cpu-common.h"
+
+#if !defined(CONFIG_USER_ONLY)
+
+/* XXX: Hack to find the last range in a memory node.  */
+typedef struct FDTMemoryInfo {
+    unsigned int nr_regions;
+    ram_addr_t last_base;
+    ram_addr_t last_size;
+} FDTMemoryInfo;
+
+#endif
+
+int pflash_cfi01_fdt_init(char *node_path, FDTMachineInfo *fdti, void *opaque);
+
+extern int fdt_generic_num_cpus;
+
+#endif /* FDT_GENERIC_DEVICES_H */
include/hw/fdt_generic_util.h new file +283 -0

283 lines not on this page · raw message

include/hw/qdev-properties.h +1 -0
index 60b8133009..8553abdda1 100644
@@ -133,6 +133,7 @@ extern const PropertyInfo qdev_prop_link;
                 .bitmask    = (_bitmask),                     \
                 .set_default = false)
 
+#define PROP_ARRAY_LEN_PREFIX "len-"
 /**
  * DEFINE_PROP_ARRAY:
  * @_name: name of the array
include/net/net.h +4 -0
index 72b476ee1d..3908d8bcb4 100644
@@ -309,6 +309,10 @@ struct NICInfo {
     int nvectors;
 };
 
+extern int nb_nics;
+extern NICInfo nd_table[MAX_NICS];
+extern const char *host_net_devices[];
+
 /* from net.c */
 extern NetClientStateList net_clients;
 bool netdev_is_modern(const char *optstr);
include/qemu/log.h +3 -0
index 7effba4da4..a0c3b12657 100644
@@ -39,6 +39,9 @@ bool qemu_log_separate(void);
 #define LOG_TB_OP_PLUGIN   (1u << 22)
 #define LOG_INVALID_MEM    (1u << 23)
 
+/* device entries */
+#define LOG_FDT            (1 << 24)
+
 /* Lock/unlock output. */
 
 FILE *qemu_log_trylock(void) G_GNUC_WARN_UNUSED_RESULT;
include/system/blockdev.h +2 -0
index 3211b16513..8d07f3a911 100644
@@ -55,6 +55,8 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 void drive_check_orphaned(void);
 DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
 int drive_get_max_bus(BlockInterfaceType type);
+/* Xilinx: keep for fdt_generic */
+DriveInfo *drive_get_next(BlockInterfaceType type);
 
 QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
                     const char *optstr);
include/system/device_tree.h +86 -15

122 lines not on this page · raw message

net/net.c +2 -2
index 8aefdb3424..51d96f793a 100644
@@ -78,8 +78,8 @@ static NetdevQueue nd_queue = QSIMPLEQ_HEAD_INITIALIZER(nd_queue);
 
 static GHashTable *nic_model_help;
 
-static int nb_nics;
-static NICInfo nd_table[MAX_NICS];
+//static int nb_nics;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

qemu-options.hx +9 -0
index fca2b7bc74..10567c5c45 100644

Lines of this file are not shown. View the raw message.

system/device_tree.c +364 -13

377 lines not on this page · raw message

system/globals.c +2 -0
index 98f9876d5d..32869e65ed 100644

Lines of this file are not shown. View the raw message.

system/vl.c +3 -0
index 5091fe52d9..c18306e914 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.

#2 lore raw

RFC PATCH 2/2 hw/core: add remote-port protocol implementation

In reply to [email protected]

From: Ruslan Ruslichenko <[email protected]>

Remote Port protocol is used for HW simulation, which allows QEMU to communicate with external simulators such as SystemC.

The implementation was long available as downstream patches, for example within https://github.com/Xilinx/qemu repo.

For more details regarding the protocol and simulation mechanism, following document is available:

https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/862421112/Co-simulation

---
 chardev/char-fe.c                      |   9 +
 hw/core/fdt_generic_util.c             | 103 +++
 hw/core/meson.build                    |   7 +
 hw/core/qdev-properties.c              |   5 +
 hw/core/remote-port-ats.c              | 405 ++++++++++
 hw/core/remote-port-gpio.c             | 199 +++++
 hw/core/remote-port-memory-master.c    | 402 ++++++++++
 hw/core/remote-port-memory-slave.c     | 257 +++++++
 hw/core/remote-port-proto.c            | 523 +++++++++++++
 hw/core/remote-port-stream.c           | 233 ++++++
 hw/core/remote-port.c                  | 986 +++++++++++++++++++++++++
 hw/core/trace-events                   |  17 +
 hw/misc/meson.build                    |   1 +
 hw/misc/xlnx-serbs.c                   |  43 ++
 include/chardev/char-fe.h              |   2 +
 include/chardev/char.h                 |   2 +
 include/hw/misc/xlnx-serbs.h           |  36 +
 include/hw/qdev-properties.h           |   2 +
 include/hw/remote-port-ats.h           |  74 ++
 include/hw/remote-port-device.h        |  56 ++
 include/hw/remote-port-gpio.h          |  32 +
 include/hw/remote-port-memory-master.h |  62 ++
 include/hw/remote-port-memory-slave.h  |  33 +
 include/hw/remote-port-proto.h         | 537 ++++++++++++++
 include/hw/remote-port.h               | 149 ++++
 include/system/dma.h                   |  19 +
 include/system/memory.h                |  50 ++
 include/system/system.h                |   2 +
 qemu-options.hx                        |  21 +
 system/physmem.c                       |  57 ++
 system/vl.c                            |   5 +
 31 files changed, 4329 insertions(+)
 create mode 100644 hw/core/remote-port-ats.c
 create mode 100644 hw/core/remote-port-gpio.c
 create mode 100644 hw/core/remote-port-memory-master.c
 create mode 100644 hw/core/remote-port-memory-slave.c
 create mode 100644 hw/core/remote-port-proto.c
 create mode 100644 hw/core/remote-port-stream.c
 create mode 100644 hw/core/remote-port.c
 create mode 100644 hw/misc/xlnx-serbs.c
 create mode 100644 include/hw/misc/xlnx-serbs.h
 create mode 100644 include/hw/remote-port-ats.h
 create mode 100644 include/hw/remote-port-device.h
 create mode 100644 include/hw/remote-port-gpio.h
 create mode 100644 include/hw/remote-port-memory-master.h
 create mode 100644 include/hw/remote-port-memory-slave.h
 create mode 100644 include/hw/remote-port-proto.h
 create mode 100644 include/hw/remote-port.h
chardev/char-fe.c +9 -0
index 34b83fc1c4..bb197d61df 100644
@@ -346,6 +346,15 @@ void qemu_chr_fe_set_open(CharFrontend *c, bool is_open)
     }
 }
 
+void qemu_chr_fe_set_blocking(CharFrontend *be, bool blocking)
+{
+    Chardev *chr = be->chr;
+
+    if (chr && CHARDEV_GET_CLASS(chr)->chr_set_blocking) {
+        CHARDEV_GET_CLASS(chr)->chr_set_blocking(chr, blocking);
+    }
+}
+
 guint qemu_chr_fe_add_watch(CharFrontend *c, GIOCondition cond,
                             FEWatchFunc func, void *user_data)
 {
hw/core/fdt_generic_util.c +103 -0

127 lines not on this page · raw message

hw/core/meson.build +7 -0
index cea3b4660e..84171ef649 100644
@@ -48,6 +48,13 @@ system_ss.add(files(
   'sysbus.c',
   'vm-change-state-handler.c',
   'clock-vmstate.c',
+  'remote-port-proto.c',
+  'remote-port.c',
+  'remote-port-memory-master.c',
+  'remote-port-memory-slave.c',
+  'remote-port-gpio.c',
+  'remote-port-stream.c',
+  'remote-port-ats.c'
 ))
 user_ss.add(files(
   'cpu-user.c',
hw/core/qdev-properties.c +5 -0
index 422a486969..b6d9c273c3 100644
@@ -52,6 +52,11 @@ void qdev_prop_allow_set_link_before_realize(const Object *obj,
     }
 }
 
+void qdev_prop_allow_set_link(const Object *obj, const char *name,
+                              Object *val, Error **errp)
+{
+}
+
 void *object_field_prop_ptr(Object *obj, const Property *prop)
 {
     void *ptr = obj;
hw/core/remote-port-ats.c new file +405 -0

405 lines not on this page · raw message

hw/core/remote-port-gpio.c new file +199 -0

199 lines not on this page · raw message

hw/core/remote-port-memory-master.c new file +402 -0

402 lines not on this page · raw message

hw/core/remote-port-memory-slave.c new file +257 -0

257 lines not on this page · raw message

hw/core/remote-port-proto.c new file +523 -0

523 lines not on this page · raw message

hw/core/remote-port-stream.c new file +233 -0

233 lines not on this page · raw message

hw/core/remote-port.c new file +986 -0

815 lines not on this page · raw message

hw/core/trace-events +17 -0
index 2cf085ac66..a1472ab2b2 100644

Lines of this file are not shown. View the raw message.

hw/misc/meson.build +1 -0
index b1d8d8e5d2..371af17c41 100644

Lines of this file are not shown. View the raw message.

hw/misc/xlnx-serbs.c new file +43 -0

43 lines not on this page · raw message

include/chardev/char-fe.h +2 -0
index 5f8a6df17d..5a2e3d60ee 100644

Lines of this file are not shown. View the raw message.

include/chardev/char.h +2 -0
index b65e9981c1..1dd2e7741a 100644

Lines of this file are not shown. View the raw message.

include/hw/misc/xlnx-serbs.h new file +36 -0
new file mode 100644
index 0000000000..ecf839acb3

Lines of this file are not shown. View the raw message.

include/hw/qdev-properties.h +2 -0
index 8553abdda1..07f88513a4 100644

Lines of this file are not shown. View the raw message.

include/hw/remote-port-ats.h new file +74 -0

74 lines not on this page · raw message

include/hw/remote-port-device.h new file +56 -0

56 lines not on this page · raw message

include/hw/remote-port-gpio.h new file +32 -0
new file mode 100644
index 0000000000..3a0c7c0a6e

Lines of this file are not shown. View the raw message.

include/hw/remote-port-memory-master.h new file +62 -0

62 lines not on this page · raw message

include/hw/remote-port-memory-slave.h new file +33 -0
new file mode 100644
index 0000000000..f0b75f90f4

Lines of this file are not shown. View the raw message.

include/hw/remote-port-proto.h new file +537 -0

537 lines not on this page · raw message

include/hw/remote-port.h new file +149 -0

149 lines not on this page · raw message

include/system/dma.h +19 -0
index 82e7ad5437..811ff32d69 100644

Lines of this file are not shown. View the raw message.

include/system/memory.h +50 -0

50 lines not on this page · raw message

include/system/system.h +2 -0
index 03a2d0e900..1bc17e94f3 100644

Lines of this file are not shown. View the raw message.

qemu-options.hx +21 -0
index 10567c5c45..82e45207b3 100644

Lines of this file are not shown. View the raw message.

system/physmem.c +57 -0

57 lines not on this page · raw message

system/vl.c +5 -0
index c18306e914..76d08d2078 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.