diff options
author | Thierry Reding <treding@nvidia.com> | 2023-01-20 18:42:48 +0100 |
---|---|---|
committer | Joerg Roedel <jroedel@suse.de> | 2023-01-25 11:48:27 +0100 |
commit | e251c21372c07694f547afe3c9828f7f6ef01267 (patch) | |
tree | 2796ba3a2d1109af85300a86c54b7065ad9fc000 /drivers/of | |
parent | bb649412d39f18eb2a8b7956209a068a08f4bc1e (diff) | |
download | lwn-e251c21372c07694f547afe3c9828f7f6ef01267.tar.gz lwn-e251c21372c07694f547afe3c9828f7f6ef01267.zip |
of: Introduce of_translate_dma_region()
This function is similar to of_translate_dma_address() but also reads a
length in addition to an address from a device tree property.
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20230120174251.4004100-2-thierry.reding@gmail.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/address.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c index c34ac33b7338..14f137a21b0c 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -626,6 +626,47 @@ u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) } EXPORT_SYMBOL(of_translate_dma_address); +/** + * of_translate_dma_region - Translate device tree address and size tuple + * @dev: device tree node for which to translate + * @prop: pointer into array of cells + * @start: return value for the start of the DMA range + * @length: return value for the length of the DMA range + * + * Returns a pointer to the cell immediately following the translated DMA region. + */ +const __be32 *of_translate_dma_region(struct device_node *dev, const __be32 *prop, + phys_addr_t *start, size_t *length) +{ + struct device_node *parent; + u64 address, size; + int na, ns; + + parent = __of_get_dma_parent(dev); + if (!parent) + return NULL; + + na = of_bus_n_addr_cells(parent); + ns = of_bus_n_size_cells(parent); + + of_node_put(parent); + + address = of_translate_dma_address(dev, prop); + if (address == OF_BAD_ADDR) + return NULL; + + size = of_read_number(prop + na, ns); + + if (start) + *start = address; + + if (length) + *length = size; + + return prop + na + ns; +} +EXPORT_SYMBOL(of_translate_dma_region); + const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, u64 *size, unsigned int *flags) { |