xref: /openbmc/u-boot/include/dm/of_addr.h (revision 3bc599c9)
1 /*
2  * Taken from Linux v4.9 drivers/of/address.c
3  *
4  * Modified for U-Boot
5  * Copyright (c) 2017 Google, Inc
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #ifndef _DM_OF_ADDR_H
11 #define _DM_OF_ADDR_H
12 
13 /**
14  * of_translate_address() - translate a device-tree address to a CPU address
15  *
16  * Translate an address from the device-tree into a CPU physical address,
17  * this walks up the tree and applies the various bus mappings on the  way.
18  *
19  * Note: We consider that crossing any level with #size-cells == 0 to mean
20  * that translation is impossible (that is we are not dealing with a value
21  * that can be mapped to a cpu physical address). This is not really specified
22  * that way, but this is traditionally the way IBM at least do things
23  *
24  * @np: node to check
25  * @in_addr: pointer to input address
26  * @return translated address or OF_BAD_ADDR on error
27  */
28 u64 of_translate_address(const struct device_node *no, const __be32 *in_addr);
29 
30 /**
31  * of_get_address() - obtain an address from a node
32  *
33  * Extract an address from a node, returns the region size and the address
34  * space flags too. The PCI version uses a BAR number instead of an absolute
35  * index.
36  *
37  * @np: Node to check
38  * @index: Index of address to read (0 = first)
39  * @size: place to put size on success
40  * @flags: place to put flags on success
41  * @return pointer to address which can be read
42  */
43 const __be32 *of_get_address(const struct device_node *no, int index,
44 			     u64 *size, unsigned int *flags);
45 
46 struct resource;
47 
48 /**
49  * of_address_to_resource() - translate device tree address to resource
50  *
51  * Note that if your address is a PIO address, the conversion will fail if
52  * the physical address can't be internally converted to an IO token with
53  * pci_address_to_pio(), that is because it's either called to early or it
54  * can't be matched to any host bridge IO space
55  *
56  * @np: node to check
57  * @index: index of address to read (0 = first)
58  * @r: place to put resource information
59  * @return 0 if OK, -ve on error
60  */
61 int of_address_to_resource(const struct device_node *no, int index,
62 			   struct resource *r);
63 
64 #endif
65