hw/arm/smmuv3: Avoid including CONFIG_DEVICES in hw/ header
v2 cover hw/arm/smmuv3: Avoid including CONFIG_DEVICES in hw/ header
Since v2:
- Restrict to ARM SMMUv3
- Address Shameer review comments
By inlinining the stubs we can avoid the use of target-specific CONFIG_DEVICES include in a hw/ header, allowing to build the source files including it as common objects.
Philippe Mathieu-Daudé (2):
hw/arm/smmuv3: Have smmuv3_accel_init() take an Error* parameter hw/arm/smmuv3: Avoid including CONFIG_DEVICES in hw/ header
hw/arm/smmuv3-accel.h | 41 +---------------------------- hw/arm/smmuv3-accel-stubs.c | 52 +++++++++++++++++++++++++++++++++++++ hw/arm/smmuv3-accel.c | 3 ++- hw/arm/smmuv3.c | 11 +++----- hw/arm/meson.build | 5 ++-- 5 files changed, 61 insertions(+), 51 deletions(-) create mode 100644 hw/arm/smmuv3-accel-stubs.c
Signature · 1 line
2.53.0
PATCH v2 1/2 hw/arm/smmuv3: Have smmuv3_accel_init() take an Error* parameter
By giving smmuv3_accel_init() the ability to populate an error, we can fail early in smmu_realize() when CONFIG_ARM_SMMUV3_ACCEL is not available, simplifying smmu_validate_property().
--- hw/arm/smmuv3-accel.h | 7 +++++-- hw/arm/smmuv3-accel.c | 3 ++- hw/arm/smmuv3.c | 11 +++-------- 3 files changed, 10 insertions(+), 11 deletions(-)
hw/arm/smmuv3-accel.h +5 -2
@@ -42,7 +42,7 @@ typedef struct SMMUv3AccelDevice { } SMMUv3AccelDevice;#ifdef CONFIG_ARM_SMMUV3_ACCEL -void smmuv3_accel_init (SMMUv3State *s); +bool smmuv3_accel_init (SMMUv3State *s,Error **errp);bool smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid,Error **errp); bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange *range,
@@ -54,8 +54,11 @@ void smmuv3_accel_idr_override(SMMUv3State *s);bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp);void smmuv3_accel_reset (SMMUv3State *s);#else -static inline void smmuv3_accel_init (SMMUv3State *s) +#include "qapi/error.h" +static inline bool smmuv3_accel_init (SMMUv3State *s,Error **errp) { +error_setg (errp,"accel=on support not compiled in" ); +return false; } static inline bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,
hw/arm/smmuv3-accel.c +2 -1
@@ -917,11 +917,12 @@ static void smmuv3_accel_as_init(SMMUv3State *s)address_space_init (shared_as_sysmem, &root,"smmuv3-accel-as-sysmem" ); } -void smmuv3_accel_init (SMMUv3State *s) +bool smmuv3_accel_init (SMMUv3State *s,Error **errp) {SMMUState *bs =ARM_SMMU (s); s->s_accel =g_new0 (SMMUv3AccelState,1 ); bs->iommu_ops = &smmuv3_accel_ops;smmuv3_accel_as_init (s); +return true; }
hw/arm/smmuv3.c +3 -8
@@ -1965,13 +1965,6 @@ static void smmu_reset_exit(Object *obj, ResetType type)static bool smmu_validate_property (SMMUv3State *s,Error **errp) { -#ifndef CONFIG_ARM_SMMUV3_ACCEL -if (s->accel) { -error_setg (errp,"accel=on support not compiled in" ); -return false; - } -#endif -if (s->ats ==ON_OFF_AUTO_AUTO ) {error_setg (errp,"ats auto mode is not supported" );return false;
@@ -2033,7 +2026,9 @@ static void smmu_realize(DeviceState *d, Error **errp) }if (s->accel) { -smmuv3_accel_init (s); +if (!smmuv3_accel_init (s, errp)) { +return ; + }error_setg (&s->migration_blocker,"Migration not supported with SMMUv3 " "accelerator mode enabled" );if (migrate_add_blocker (&s->migration_blocker, errp) <0 ) {
Signature · 1 line
2.53.0
RE: [PATCH v2 1/2] hw/arm/smmuv3: Have smmuv3_accel_init() take an Error* parameter
Quoted 16 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 10 April 2026 21:01
To: [email protected]
Cc: Nathan Chen <[email protected]>; [email protected]; Peter Maydell <[email protected]>; Shameer Kolothum Thodi <[email protected]>; Eric Auger <[email protected]>; Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v2 1/2] hw/arm/smmuv3: Havesmmuv3_accel_init()take an Error* parameterExternal email: Use caution opening links or attachments
Quoted 7 lines
By giving
smmuv3_accel_init()the ability to populate an error, we can fail early insmmu_realize()whenCONFIG_ARM_SMMUV3_ACCELis not available, simplifyingsmmu_validate_property().Suggested-by Shameer Kolothum Thodi <[email protected]>Co-developed-by Shameer Kolothum Thodi <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
Shameer
Quoted 85 lines
hw/arm/smmuv3-accel.h | 7 +++++-- hw/arm/smmuv3-accel.c | 3 ++- hw/arm/smmuv3.c | 11 +++-------- 3 files changed, 10 insertions(+), 11 deletions(-)hw/arm/smmuv3-accel.h +1
-1@@ -42,7 +42,7 @@ typedef struct SMMUv3AccelDevice { } SMMUv3AccelDevice;#ifdef CONFIG_ARM_SMMUV3_ACCEL -void smmuv3_accel_init (SMMUv3State *s); +bool smmuv3_accel_init (SMMUv3State *s,Error **errp);bool smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid,Error **errp); bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange*range,
hw/arm/smmuv3-accel.h +4
-1@@ -54,8 +54,11 @@ void smmuv3_accel_idr_override(SMMUv3State *s);bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp);void smmuv3_accel_reset (SMMUv3State *s);#else -static inline void smmuv3_accel_init (SMMUv3State *s) +#include "qapi/error.h" +static inline bool smmuv3_accel_init (SMMUv3State *s,Error **errp) { +error_setg (errp,"accel=on support not compiled in" ); +return false; } static inline bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,hw/arm/smmuv3-accel.c +2
-1@@ -917,11 +917,12 @@ static void smmuv3_accel_as_init(SMMUv3State *s)address_space_init (shared_as_sysmem, &root,"smmuv3-accel-as- sysmem"); } -void smmuv3_accel_init (SMMUv3State *s) +bool smmuv3_accel_init (SMMUv3State *s,Error **errp) {SMMUState *bs =ARM_SMMU (s); s->s_accel =g_new0 (SMMUv3AccelState,1 ); bs->iommu_ops = &smmuv3_accel_ops;smmuv3_accel_as_init (s); +return true;}
hw/arm/smmuv3.c +0
-7@@ -1965,13 +1965,6 @@ static void smmu_reset_exit(Object *obj, ResetType type)static bool smmu_validate_property (SMMUv3State *s,Error **errp) { -#ifndef CONFIG_ARM_SMMUV3_ACCEL -if (s->accel) { -error_setg (errp,"accel=on support not compiled in" ); -return false; - } -#endif -if (s->ats ==ON_OFF_AUTO_AUTO ) {error_setg (errp,"ats auto mode is not supported" );return false;hw/arm/smmuv3.c +3
-1@@ -2033,7 +2026,9 @@ static void smmu_realize(DeviceState *d, Error **errp) }if (s->accel) { -smmuv3_accel_init (s); +if (!smmuv3_accel_init (s, errp)) { +return ; + } error_setg(&s->migration_blocker, "Migration not supported withSMMUv3 "
"accelerator mode enabled"); if (migrate_add_blocker(&s->migration_blocker, errp) < 0) {--
2.53.0
Re: [PATCH v2 1/2] hw/arm/smmuv3: Have smmuv3_accel_init() take an Error* parameter
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
By giving
smmuv3_accel_init()the ability to populate an error, we can fail early insmmu_realize()whenCONFIG_ARM_SMMUV3_ACCELis not available, simplifyingsmmu_validate_property().
Quoted 9 lines
Suggested-by Shameer Kolothum Thodi <[email protected]>Co-developed-by Shameer Kolothum Thodi <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/arm/smmuv3-accel.h | 7 +++++-- hw/arm/smmuv3-accel.c | 3 ++- hw/arm/smmuv3.c | 11 +++-------- 3 files changed, 10 insertions(+), 11 deletions(-)
PATCH v2 2/2 hw/arm/smmuv3: Avoid including CONFIG_DEVICES in hw/ header
In reply to Philippe Mathieu-DaudéBy turning the inline functions into stubs we can avoid the use of target-specific CONFIG_DEVICES include in a hw/ header, allowing to build the source files including it as common objects.
--- hw/arm/smmuv3-accel.h | 42 ------------------------------ hw/arm/smmuv3-accel-stubs.c | 52 +++++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 5 ++-- 3 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 hw/arm/smmuv3-accel-stubs.c
hw/arm/smmuv3-accel.h +0 -42
@@ -14,7 +14,6 @@#ifdef CONFIG_LINUX #include <linux/iommufd.h> #endif -#include CONFIG_DEVICES /* * Represents an accelerated SMMU instance backed by an iommufd vIOMMU object.
@@ -41,7 +40,6 @@ typedef struct SMMUv3AccelDevice {SMMUv3AccelState *s_accel; } SMMUv3AccelDevice; -#ifdef CONFIG_ARM_SMMUV3_ACCEL bool smmuv3_accel_init (SMMUv3State *s,Error **errp);bool smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid,Error **errp);
@@ -53,45 +51,5 @@ bool smmuv3_accel_issue_inv_cmd(SMMUv3State *s, void *cmd, SMMUDevice *sdev,void smmuv3_accel_idr_override (SMMUv3State *s);bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp);void smmuv3_accel_reset (SMMUv3State *s); -#else -#include "qapi/error.h" -static inline bool smmuv3_accel_init (SMMUv3State *s,Error **errp) -{ -error_setg (errp,"accel=on support not compiled in" ); -return false; -} -static inline bool -smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, -Error **errp) -{ -return true; -} -static inline bool -smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, -Error **errp) -{ -return true; -} -static inline bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) -{ -return true; -} -static inline bool -smmuv3_accel_issue_inv_cmd (SMMUv3State *s,void *cmd,SMMUDevice *sdev, -Error **errp) -{ -return true; -} -static inline void smmuv3_accel_idr_override (SMMUv3State *s) -{ -} -static inline bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp) -{ -return true; -} -static inline void smmuv3_accel_reset (SMMUv3State *s) -{ -} -#endif #endif /* HW_ARM_SMMUV3_ACCEL_H */
hw/arm/smmuv3-accel-stubs.c new file +52 -0
52 lines not on this page · raw message
hw/arm/meson.build +3 -2
@@ -84,8 +84,9 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE', if_true: files('armsse.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-imx8mp.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true: files('imx8mp-evk.c')) -arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) -arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true: files('smmuv3-accel.c')) +arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) +arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true: files('smmuv3-accel.c')) +stub_ss.add(files('smmuv3-accel-stubs.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c')) arm_common_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c')) arm_common_ss.add(when: 'CONFIG_XEN', if_true: files(
Signature · 1 line
2.53.0
Quoted 16 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 10 April 2026 21:01
To: [email protected]
Cc: Nathan Chen <[email protected]>; [email protected]; Peter Maydell <[email protected]>; Shameer Kolothum Thodi <[email protected]>; Eric Auger <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Thomas Huth <[email protected]>
Subject: [PATCH v2 2/2] hw/arm/smmuv3: Avoid includingCONFIG_DEVICESin hw/ headerExternal email: Use caution opening links or attachments
Quoted 6 lines
By turning the inline functions into stubs we can avoid the use of target-specific
CONFIG_DEVICESinclude in a hw/ header, allowing to build the source files including it as common objects.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Thomas Huth <[email protected]>
Thanks,
Shameer
Quoted 168 lines
hw/arm/smmuv3-accel.h | 42 ------------------------------ hw/arm/smmuv3-accel-stubs.c | 52 +++++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 5 ++-- 3 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 hw/arm/smmuv3-accel-stubs.chw/arm/smmuv3-accel.h +0
-1@@ -14,7 +14,6 @@#ifdef CONFIG_LINUX #include <linux/iommufd.h> #endif -#include CONFIG_DEVICES /* * Represents an accelerated SMMU instance backed by an iommufd vIOMMU object.
hw/arm/smmuv3-accel.h +0
-1@@ -41,7 +40,6 @@ typedef struct SMMUv3AccelDevice {SMMUv3AccelState *s_accel; } SMMUv3AccelDevice; -#ifdef CONFIG_ARM_SMMUV3_ACCEL bool smmuv3_accel_init (SMMUv3State *s,Error **errp); bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,Error **errp);hw/arm/smmuv3-accel.h +0
-25@@ -53,45 +51,5 @@ bool smmuv3_accel_issue_inv_cmd(SMMUv3State *s, void *cmd, SMMUDevice *sdev, void smmuv3_accel_idr_override(SMMUv3State *s);bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp);void smmuv3_accel_reset (SMMUv3State *s); -#else -#include "qapi/error.h" -static inline bool smmuv3_accel_init (SMMUv3State *s,Error **errp) -{ -error_setg (errp,"accel=on support not compiled in" ); -return false; -} -static inline bool -smmuv3_accel_install_ste (SMMUv3State *s,SMMUDevice *sdev,int sid, -Error **errp) -{ -return true; -} -static inline bool -smmuv3_accel_install_ste_range (SMMUv3State *s,SMMUSIDRange *range, -Error **errp) -{ -return true; -} -static inline bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) -{ -return true; -} -static inline bool -smmuv3_accel_issue_inv_cmd(SMMUv3State *s, void *cmd, SMMUDevice*sdev,
hw/arm/smmuv3-accel.h +0
-8- Error **errp) -{ -return true; -} -static inline void smmuv3_accel_idr_override (SMMUv3State *s) -{ -} -static inline bool smmuv3_accel_alloc_veventq(SMMUv3State *s, Error**errp)
hw/arm/smmuv3-accel.h +0
-7-{ -return true; -} -static inline void smmuv3_accel_reset (SMMUv3State *s) -{ -} -#endif #endif /* HW_ARM_SMMUV3_ACCEL_H */ hw/arm/smmuv3-accel-stubs.c new file +2
-0@@ -0,0 +1,52 @@ +/* +* Stubs for accelerated SMMU instance backed by an iommufd vIOMMU object.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */hw/arm/smmuv3-accel-stubs.c new file +13
-0+ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/arm/smmuv3.h" +#include "hw/arm/smmuv3-accel.h" + +bool smmuv3_accel_init (SMMUv3State *s,Error **errp) +{ +error_setg (errp,"accel=on support not compiled in" ); +return false; +} + +bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, intsid,
hw/arm/smmuv3-accel-stubs.c new file +6
-0+ Error **errp) +{ +return true; +} + +bool smmuv3_accel_install_ste_range(SMMUv3State *s, SMMUSIDRange*range,
hw/arm/smmuv3-accel-stubs.c new file +11
-0+ Error **errp) +{ +return true; +} + +bool smmuv3_accel_attach_gbpa_hwpt (SMMUv3State *s,Error **errp) +{ +return true; +} + +bool smmuv3_accel_issue_inv_cmd(SMMUv3State *s, void *cmd,SMMUDevice *sdev,
hw/arm/smmuv3-accel-stubs.c new file +17
-0+ Error **errp) +{ +return true; +} + +void smmuv3_accel_idr_override (SMMUv3State *s) +{ +} + +bool smmuv3_accel_alloc_veventq (SMMUv3State *s,Error **errp) +{ +return true; +} + +void smmuv3_accel_reset (SMMUv3State *s) +{ +}hw/arm/meson.build +0
-2@@ -84,8 +84,9 @@ arm_common_ss.add(when: 'CONFIG_ARMSSE', if_true: files('armsse.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl- imx8mp.c')) arm_common_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true: files('imx8mp-evk.c')) -arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) -arm_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL', if_true: files('smmuv3-
accel.c'))
+arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3',if_true:
files('smmuv3.c'))
+arm_common_ss.add(when: 'CONFIG_ARM_SMMUV3_ACCEL',if_true:
files('smmuv3-accel.c')) +stub_ss.add(files('smmuv3-accel-stubs.c'))
arm_common_ss.add(when: 'CONFIG_FSL_IMX6UL',if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c'))
arm_common_ss.add(when: 'CONFIG_NRF51_SOC',if_true:files('nrf51_soc.c'))
arm_common_ss.add(when: 'CONFIG_XEN',if_true: files(
--
2.53.0
Quoted 4 lines · Philippe Mathieu-Daudé
By turning the inline functions into stubs we can avoid the use of target-specific
CONFIG_DEVICESinclude in a hw/ header, allowing to build the source files including it as common objects.
Quoted 9 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Thomas Huth <[email protected]>--- hw/arm/smmuv3-accel.h | 42 ------------------------------ hw/arm/smmuv3-accel-stubs.c | 52 +++++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 5 ++-- 3 files changed, 55 insertions(+), 44 deletions(-)create mode 100644
hw/arm/smmuv3-accel-stubs.c