1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */ 238d21b41SSimon Glass /* 338d21b41SSimon Glass * Taken from Linux v4.9 drivers/of/address.c 438d21b41SSimon Glass * 538d21b41SSimon Glass * Modified for U-Boot 638d21b41SSimon Glass * Copyright (c) 2017 Google, Inc 738d21b41SSimon Glass */ 838d21b41SSimon Glass 938d21b41SSimon Glass #ifndef _DM_OF_ADDR_H 1038d21b41SSimon Glass #define _DM_OF_ADDR_H 1138d21b41SSimon Glass 1238d21b41SSimon Glass /** 1338d21b41SSimon Glass * of_translate_address() - translate a device-tree address to a CPU address 1438d21b41SSimon Glass * 1538d21b41SSimon Glass * Translate an address from the device-tree into a CPU physical address, 1638d21b41SSimon Glass * this walks up the tree and applies the various bus mappings on the way. 1738d21b41SSimon Glass * 1838d21b41SSimon Glass * Note: We consider that crossing any level with #size-cells == 0 to mean 1938d21b41SSimon Glass * that translation is impossible (that is we are not dealing with a value 2038d21b41SSimon Glass * that can be mapped to a cpu physical address). This is not really specified 2138d21b41SSimon Glass * that way, but this is traditionally the way IBM at least do things 2238d21b41SSimon Glass * 2338d21b41SSimon Glass * @np: node to check 2438d21b41SSimon Glass * @in_addr: pointer to input address 2538d21b41SSimon Glass * @return translated address or OF_BAD_ADDR on error 2638d21b41SSimon Glass */ 2738d21b41SSimon Glass u64 of_translate_address(const struct device_node *no, const __be32 *in_addr); 2838d21b41SSimon Glass 2938d21b41SSimon Glass /** 3038d21b41SSimon Glass * of_get_address() - obtain an address from a node 3138d21b41SSimon Glass * 3238d21b41SSimon Glass * Extract an address from a node, returns the region size and the address 3338d21b41SSimon Glass * space flags too. The PCI version uses a BAR number instead of an absolute 3438d21b41SSimon Glass * index. 3538d21b41SSimon Glass * 3638d21b41SSimon Glass * @np: Node to check 3738d21b41SSimon Glass * @index: Index of address to read (0 = first) 3838d21b41SSimon Glass * @size: place to put size on success 3938d21b41SSimon Glass * @flags: place to put flags on success 4038d21b41SSimon Glass * @return pointer to address which can be read 4138d21b41SSimon Glass */ 4238d21b41SSimon Glass const __be32 *of_get_address(const struct device_node *no, int index, 4338d21b41SSimon Glass u64 *size, unsigned int *flags); 4438d21b41SSimon Glass 4538d21b41SSimon Glass struct resource; 4638d21b41SSimon Glass 4738d21b41SSimon Glass /** 4838d21b41SSimon Glass * of_address_to_resource() - translate device tree address to resource 4938d21b41SSimon Glass * 5038d21b41SSimon Glass * Note that if your address is a PIO address, the conversion will fail if 5138d21b41SSimon Glass * the physical address can't be internally converted to an IO token with 5238d21b41SSimon Glass * pci_address_to_pio(), that is because it's either called to early or it 5338d21b41SSimon Glass * can't be matched to any host bridge IO space 5438d21b41SSimon Glass * 5538d21b41SSimon Glass * @np: node to check 5638d21b41SSimon Glass * @index: index of address to read (0 = first) 5738d21b41SSimon Glass * @r: place to put resource information 5838d21b41SSimon Glass * @return 0 if OK, -ve on error 5938d21b41SSimon Glass */ 6038d21b41SSimon Glass int of_address_to_resource(const struct device_node *no, int index, 6138d21b41SSimon Glass struct resource *r); 6238d21b41SSimon Glass 6338d21b41SSimon Glass #endif 64