]> git.sur5r.net Git - u-boot/blob - include/dm/of_addr.h
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / include / dm / of_addr.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Taken from Linux v4.9 drivers/of/address.c
4  *
5  * Modified for U-Boot
6  * Copyright (c) 2017 Google, Inc
7  */
8
9 #ifndef _DM_OF_ADDR_H
10 #define _DM_OF_ADDR_H
11
12 /**
13  * of_translate_address() - translate a device-tree address to a CPU address
14  *
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.
17  *
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
22  *
23  * @np: node to check
24  * @in_addr: pointer to input address
25  * @return translated address or OF_BAD_ADDR on error
26  */
27 u64 of_translate_address(const struct device_node *no, const __be32 *in_addr);
28
29 /**
30  * of_get_address() - obtain an address from a node
31  *
32  * Extract an address from a node, returns the region size and the address
33  * space flags too. The PCI version uses a BAR number instead of an absolute
34  * index.
35  *
36  * @np: Node to check
37  * @index: Index of address to read (0 = first)
38  * @size: place to put size on success
39  * @flags: place to put flags on success
40  * @return pointer to address which can be read
41  */
42 const __be32 *of_get_address(const struct device_node *no, int index,
43                              u64 *size, unsigned int *flags);
44
45 struct resource;
46
47 /**
48  * of_address_to_resource() - translate device tree address to resource
49  *
50  * Note that if your address is a PIO address, the conversion will fail if
51  * the physical address can't be internally converted to an IO token with
52  * pci_address_to_pio(), that is because it's either called to early or it
53  * can't be matched to any host bridge IO space
54  *
55  * @np: node to check
56  * @index: index of address to read (0 = first)
57  * @r: place to put resource information
58  * @return 0 if OK, -ve on error
59  */
60 int of_address_to_resource(const struct device_node *no, int index,
61                            struct resource *r);
62
63 #endif