1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Taken from Linux v4.9 drivers/of/address.c
6 * Copyright (c) 2017 Google, Inc
13 * of_translate_address() - translate a device-tree address to a CPU address
15 * Translate an address from the device-tree into a CPU physical address,
16 * this walks up the tree and applies the various bus mappings on the way.
18 * Note: We consider that crossing any level with #size-cells == 0 to mean
19 * that translation is impossible (that is we are not dealing with a value
20 * that can be mapped to a cpu physical address). This is not really specified
21 * that way, but this is traditionally the way IBM at least do things
24 * @in_addr: pointer to input address
25 * @return translated address or OF_BAD_ADDR on error
27 u64 of_translate_address(const struct device_node *no, const __be32 *in_addr);
30 * of_translate_dma_address() - translate a device-tree DMA address to a CPU
33 * Translate a DMA address from the device-tree into a CPU physical address,
34 * this walks up the tree and applies the various bus mappings on the way.
36 * Note: We consider that crossing any level with #size-cells == 0 to mean
37 * that translation is impossible (that is we are not dealing with a value
38 * that can be mapped to a cpu physical address). This is not really specified
39 * that way, but this is traditionally the way IBM at least do things
42 * @in_addr: pointer to input DMA address
43 * @return translated DMA address or OF_BAD_ADDR on error
45 u64 of_translate_dma_address(const struct device_node *no, const __be32 *in_addr);
49 * of_get_dma_range() - get dma-ranges for a specific DT node
51 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
52 * cpu->bus address translations
54 * @param blob Pointer to device tree blob
55 * @param node_offset Node DT offset
56 * @param cpu Pointer to variable storing the range's cpu address
57 * @param bus Pointer to variable storing the range's bus address
58 * @param size Pointer to variable storing the range's size
59 * @return translated DMA address or OF_BAD_ADDR on error
61 int of_get_dma_range(const struct device_node *dev, phys_addr_t *cpu,
62 dma_addr_t *bus, u64 *size);
65 * of_get_address() - obtain an address from a node
67 * Extract an address from a node, returns the region size and the address
68 * space flags too. The PCI version uses a BAR number instead of an absolute
72 * @index: Index of address to read (0 = first)
73 * @size: place to put size on success
74 * @flags: place to put flags on success
75 * @return pointer to address which can be read
77 const __be32 *of_get_address(const struct device_node *no, int index,
78 u64 *size, unsigned int *flags);
83 * of_address_to_resource() - translate device tree address to resource
85 * Note that if your address is a PIO address, the conversion will fail if
86 * the physical address can't be internally converted to an IO token with
87 * pci_address_to_pio(), that is because it's either called to early or it
88 * can't be matched to any host bridge IO space
91 * @index: index of address to read (0 = first)
92 * @r: place to put resource information
93 * @return 0 if OK, -ve on error
95 int of_address_to_resource(const struct device_node *no, int index,