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