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