From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Elena Ufimtseva" <elena.ufimtseva@oracle.com>,
"Jagannathan Raman" <jag.raman@oracle.com>,
"Jonathan Cameron" <jic23@kernel.org>,
qemu-arm@nongnu.org, linux-cxl@vger.kernel.org
Subject: [PATCH v5 45/62] include: add QEMU_REPEAT helper macro
Date: Fri, 11 Sep 2026 20:35:19 +0400 [thread overview]
Message-ID: <20260911-qom-qapi-v5-45-7732a55b7760@redhat.com> (raw)
In-Reply-To: <20260911-qom-qapi-v5-0-7732a55b7760@redhat.com>
Introduce a macro used in following commit, and convert a few existing
candidates. Inspired by a similar macro in Linux kernel/trace/bpf_trace.c
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
hw/misc/tz-ppc.c | 19 ++-----------------
hw/remote/vfio-user-obj.c | 17 +++--------------
include/hw/cxl/cxl_component.h | 5 +----
include/qemu/osdep.h | 33 +++++++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 35 deletions(-)
diff --git a/hw/misc/tz-ppc.c b/hw/misc/tz-ppc.c
index 6f820430eed8..5f09ce164c19 100644
--- a/hw/misc/tz-ppc.c
+++ b/hw/misc/tz-ppc.c
@@ -303,26 +303,11 @@ static const VMStateDescription tz_ppc_vmstate = {
#define DEFINE_PORT(N) \
DEFINE_PROP_LINK("port[" #N "]", TZPPC, port[N].downstream, \
- TYPE_MEMORY_REGION, MemoryRegion *)
+ TYPE_MEMORY_REGION, MemoryRegion *),
static const Property tz_ppc_properties[] = {
DEFINE_PROP_UINT32("NONSEC_MASK", TZPPC, nonsec_mask, 0),
- DEFINE_PORT(0),
- DEFINE_PORT(1),
- DEFINE_PORT(2),
- DEFINE_PORT(3),
- DEFINE_PORT(4),
- DEFINE_PORT(5),
- DEFINE_PORT(6),
- DEFINE_PORT(7),
- DEFINE_PORT(8),
- DEFINE_PORT(9),
- DEFINE_PORT(10),
- DEFINE_PORT(11),
- DEFINE_PORT(12),
- DEFINE_PORT(13),
- DEFINE_PORT(14),
- DEFINE_PORT(15),
+ QEMU_REPEAT(TZ_NUM_PORTS, DEFINE_PORT)
};
static void tz_ppc_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index 7e6819f670b5..84c3ff05cfb8 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -496,22 +496,11 @@ static size_t vfu_object_bar_rw(PCIDevice *pci_dev, int pci_bar,
buf, count, is_write); \
} \
-VFU_OBJECT_BAR_HANDLER(0)
-VFU_OBJECT_BAR_HANDLER(1)
-VFU_OBJECT_BAR_HANDLER(2)
-VFU_OBJECT_BAR_HANDLER(3)
-VFU_OBJECT_BAR_HANDLER(4)
-VFU_OBJECT_BAR_HANDLER(5)
-VFU_OBJECT_BAR_HANDLER(6)
+QEMU_REPEAT(PCI_NUM_REGIONS, VFU_OBJECT_BAR_HANDLER)
+#define VFU_OBJECT_BAR_HANDLER_PTR(BAR_NO) vfu_object_bar##BAR_NO##_handler,
static vfu_region_access_cb_t *vfu_object_bar_handlers[PCI_NUM_REGIONS] = {
- &vfu_object_bar0_handler,
- &vfu_object_bar1_handler,
- &vfu_object_bar2_handler,
- &vfu_object_bar3_handler,
- &vfu_object_bar4_handler,
- &vfu_object_bar5_handler,
- &vfu_object_bar6_handler,
+ QEMU_REPEAT(PCI_NUM_REGIONS, VFU_OBJECT_BAR_HANDLER_PTR)
};
/**
diff --git a/include/hw/cxl/cxl_component.h b/include/hw/cxl/cxl_component.h
index ffc82202206c..fca8b7055ccd 100644
--- a/include/hw/cxl/cxl_component.h
+++ b/include/hw/cxl/cxl_component.h
@@ -186,10 +186,7 @@ REG32(CXL_HDM_DECODER_GLOBAL_CONTROL, CXL_HDM_REGISTERS_OFFSET + 4)
/* Support 4 decoders at all levels of topology */
#define CXL_HDM_DECODER_COUNT 4
-HDM_DECODER_INIT(0);
-HDM_DECODER_INIT(1);
-HDM_DECODER_INIT(2);
-HDM_DECODER_INIT(3);
+QEMU_REPEAT(CXL_HDM_DECODER_COUNT, HDM_DECODER_INIT)
/*
* CXL r3.1 Section 8.2.4.21: CXL Extended Security Capability Structure
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 1ec5b42230be..a5e7ff99cb89 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -191,6 +191,39 @@ extern "C" {
#include "qemu/typedefs.h"
+/*
+ * QEMU_REPEAT(n, m) - invoke m(0) m(1) ... m(n-1)
+ *
+ * Expands to n invocations of m, each with a literal integer argument.
+ * n must be a compile-time constant in 0..16.
+ *
+ * Example - generate 4 per-index function definitions:
+ *
+ * #define DEFINE_GETTER(i) \
+ * static int get_##i(void) { return values[i]; }
+ *
+ * QEMU_REPEAT(4, DEFINE_GETTER)
+ */
+#define QEMU_REPEAT_0(m)
+#define QEMU_REPEAT_1(m) QEMU_REPEAT_0(m) m(0)
+#define QEMU_REPEAT_2(m) QEMU_REPEAT_1(m) m(1)
+#define QEMU_REPEAT_3(m) QEMU_REPEAT_2(m) m(2)
+#define QEMU_REPEAT_4(m) QEMU_REPEAT_3(m) m(3)
+#define QEMU_REPEAT_5(m) QEMU_REPEAT_4(m) m(4)
+#define QEMU_REPEAT_6(m) QEMU_REPEAT_5(m) m(5)
+#define QEMU_REPEAT_7(m) QEMU_REPEAT_6(m) m(6)
+#define QEMU_REPEAT_8(m) QEMU_REPEAT_7(m) m(7)
+#define QEMU_REPEAT_9(m) QEMU_REPEAT_8(m) m(8)
+#define QEMU_REPEAT_10(m) QEMU_REPEAT_9(m) m(9)
+#define QEMU_REPEAT_11(m) QEMU_REPEAT_10(m) m(10)
+#define QEMU_REPEAT_12(m) QEMU_REPEAT_11(m) m(11)
+#define QEMU_REPEAT_13(m) QEMU_REPEAT_12(m) m(12)
+#define QEMU_REPEAT_14(m) QEMU_REPEAT_13(m) m(13)
+#define QEMU_REPEAT_15(m) QEMU_REPEAT_14(m) m(14)
+#define QEMU_REPEAT_16(m) QEMU_REPEAT_15(m) m(15)
+#define QEMU_REPEAT_(n, m) QEMU_REPEAT_##n(m)
+#define QEMU_REPEAT(n, m) QEMU_REPEAT_(n, m)
+
/**
* Mark a function that executes in coroutine context
*
--
2.55.0.543.g5ebe2ebe4ea8
prev parent reply other threads:[~2026-09-11 16:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260911-qom-qapi-v5-0-7732a55b7760@redhat.com>
2026-09-11 16:34 ` [PATCH v5 17/62] qom: convert struct properties to QAPI-aware registration Marc-André Lureau
2026-09-11 16:35 ` [PATCH v5 35/62] qom: convert scalar " Marc-André Lureau
2026-09-11 16:35 ` Marc-André Lureau [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260911-qom-qapi-v5-45-7732a55b7760@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=elena.ufimtseva@oracle.com \
--cc=jag.raman@oracle.com \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox