From 93c147c5e6e6bf6821eeffdc6fbc9863b93199ba Mon Sep 17 00:00:00 2001 From: Yidi Lin Date: Fri, 12 Sep 2025 13:08:54 +0800 Subject: [PATCH] commonlib/device_tree: Add dt_add_iommu_addr_prop function `dt_add_reg_prop` and the newly introduced `dt_add_iommu_addr_prop` share identical logic for building the binary data buffer, differing only in the property name written to the Device Tree. Therefore, refactor the shared logic into a new static helper function, `dt_add_addr_and_size_prop`. The existing `dt_add_reg_prop` is converted to a wrapper around this new helper. `dt_add_iommu_addr_prop` is introduced as a separate wrapper to specifically add the `iommu-addresses` property. This property defines reserved IOVA ranges or identity-mapped regions, such as a display framebuffer configured by the bootloader. It is typically utilized within the `reserved-memory` subsystem. BUG=b:435289727 TEST=The below translation fault does not occur. [ 0.171028] arm-smmu-v3 30800000.iommu: TBU_id-2-fault_id:0x2000008(0x8), TF read in NORMAL world, iova:0xa3000000, sid:144, ssid:0, ssidv:0, secsidv:0 Change-Id: Icedcce5681a7b659b11b7e7208663bc1d920ce3b Signed-off-by: Yidi Lin Reviewed-on: https://review.coreboot.org/c/coreboot/+/89152 Reviewed-by: Yu-Ping Wu Tested-by: build bot (Jenkins) --- src/commonlib/device_tree.c | 52 ++++++++++++++----- src/commonlib/include/commonlib/device_tree.h | 4 +- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/commonlib/device_tree.c b/src/commonlib/device_tree.c index a6fdd0cb61..d244ad9954 100644 --- a/src/commonlib/device_tree.c +++ b/src/commonlib/device_tree.c @@ -1533,21 +1533,12 @@ void dt_add_u64_prop(struct device_tree_node *node, const char *name, u64 val) dt_add_bin_prop(node, name, val_ptr, sizeof(*val_ptr)); } -/* - * Add a 'reg' address list property to a node, or update it if it exists. - * - * @param node The device tree node to add to. - * @param regions Array of address values to be stored in the property. - * @param sizes Array of corresponding size values to 'addrs'. - * @param count Number of values in 'addrs' and 'sizes' (must be equal). - * @param addr_cells Value of #address-cells property valid for this node. - * @param size_cells Value of #size-cells property valid for this node. - */ -void dt_add_reg_prop(struct device_tree_node *node, u64 *addrs, u64 *sizes, - int count, u32 addr_cells, u32 size_cells) +static void dt_add_addr_and_size_prop(struct device_tree_node *node, const char *prop_name, + const u64 *addrs, const u64 *sizes, int count, + u32 addr_cells, u32 size_cells) { int i; - size_t length = (addr_cells + size_cells) * sizeof(u32) * count; + size_t length = (size_t)(addr_cells + size_cells) * sizeof(u32) * count; u8 *data = xmalloc(length); u8 *cur = data; @@ -1558,7 +1549,40 @@ void dt_add_reg_prop(struct device_tree_node *node, u64 *addrs, u64 *sizes, cur += size_cells * sizeof(u32); } - dt_add_bin_prop(node, "reg", data, length); + dt_add_bin_prop(node, prop_name, data, length); +} + +/* + * Add a 'reg' address list property to a node, or update it if it exists. + * + * @param node The device tree node to add to. + * @param regions Array of address values to be stored in the property. + * @param sizes Array of corresponding size values to 'addrs'. + * @param count Number of values in 'addrs' and 'sizes' (must be equal). + * @param addr_cells Value of #address-cells property valid for this node. + * @param size_cells Value of #size-cells property valid for this node. + */ +void dt_add_reg_prop(struct device_tree_node *node, const u64 *addrs, const u64 *sizes, + int count, u32 addr_cells, u32 size_cells) +{ + dt_add_addr_and_size_prop(node, "reg", addrs, sizes, count, addr_cells, size_cells); +} + +/* + * Add a 'iommu-addresses' address list property to a node, or update it if it exists. + * + * @param node The device tree node to add to. + * @param regions Array of address values to be stored in the property. + * @param sizes Array of corresponding size values to 'addrs'. + * @param count Number of values in 'addrs' and 'sizes' (must be equal). + * @param addr_cells Value of #address-cells property valid for this node. + * @param size_cells Value of #size-cells property valid for this node. + */ +void dt_add_iommu_addr_prop(struct device_tree_node *node, const u64 *addrs, const u64 *sizes, + int count, u32 addr_cells, u32 size_cells) +{ + dt_add_addr_and_size_prop(node, "iommu-addresses", addrs, sizes, count, addr_cells, + size_cells); } /* diff --git a/src/commonlib/include/commonlib/device_tree.h b/src/commonlib/include/commonlib/device_tree.h index 5ab5fbf294..be945d93da 100644 --- a/src/commonlib/include/commonlib/device_tree.h +++ b/src/commonlib/include/commonlib/device_tree.h @@ -189,8 +189,10 @@ void dt_add_string_prop(struct device_tree_node *node, const char *name, const char *str); void dt_add_u32_prop(struct device_tree_node *node, const char *name, u32 val); void dt_add_u64_prop(struct device_tree_node *node, const char *name, u64 val); -void dt_add_reg_prop(struct device_tree_node *node, u64 *addrs, u64 *sizes, +void dt_add_reg_prop(struct device_tree_node *node, const u64 *addrs, const u64 *sizes, int count, u32 addr_cells, u32 size_cells); +void dt_add_iommu_addr_prop(struct device_tree_node *node, const u64 *addrs, const u64 *sizes, + int count, u32 addr_cells, u32 size_cells); int dt_set_bin_prop_by_path(struct device_tree *tree, const char *path, void *data, size_t size, int create);