Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Thierry Reding and committed by
Joerg Roedel
e251c213 bb649412

+43
+41
drivers/of/address.c
··· 626 626 } 627 627 EXPORT_SYMBOL(of_translate_dma_address); 628 628 629 + /** 630 + * of_translate_dma_region - Translate device tree address and size tuple 631 + * @dev: device tree node for which to translate 632 + * @prop: pointer into array of cells 633 + * @start: return value for the start of the DMA range 634 + * @length: return value for the length of the DMA range 635 + * 636 + * Returns a pointer to the cell immediately following the translated DMA region. 637 + */ 638 + const __be32 *of_translate_dma_region(struct device_node *dev, const __be32 *prop, 639 + phys_addr_t *start, size_t *length) 640 + { 641 + struct device_node *parent; 642 + u64 address, size; 643 + int na, ns; 644 + 645 + parent = __of_get_dma_parent(dev); 646 + if (!parent) 647 + return NULL; 648 + 649 + na = of_bus_n_addr_cells(parent); 650 + ns = of_bus_n_size_cells(parent); 651 + 652 + of_node_put(parent); 653 + 654 + address = of_translate_dma_address(dev, prop); 655 + if (address == OF_BAD_ADDR) 656 + return NULL; 657 + 658 + size = of_read_number(prop + na, ns); 659 + 660 + if (start) 661 + *start = address; 662 + 663 + if (length) 664 + *length = size; 665 + 666 + return prop + na + ns; 667 + } 668 + EXPORT_SYMBOL(of_translate_dma_region); 669 + 629 670 const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, 630 671 u64 *size, unsigned int *flags) 631 672 {
+2
include/linux/of_address.h
··· 38 38 /* Translate a DMA address from device space to CPU space */ 39 39 extern u64 of_translate_dma_address(struct device_node *dev, 40 40 const __be32 *in_addr); 41 + extern const __be32 *of_translate_dma_region(struct device_node *dev, const __be32 *addr, 42 + phys_addr_t *start, size_t *length); 41 43 42 44 #ifdef CONFIG_OF_ADDRESS 43 45 extern u64 of_translate_address(struct device_node *np, const __be32 *addr);