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 <yidilin@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/89152
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Yidi Lin 2025-09-12 13:08:54 +08:00 committed by Matt DeVillier
commit 93c147c5e6
2 changed files with 40 additions and 14 deletions

View file

@ -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);
}
/*

View file

@ -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);