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: pointer to node to check
24 * @in_addr: pointer to input address
25 * Return: translated address or OF_BAD_ADDR on error
26 */
27u64 of_translate_address(const struct device_node *np, const __be32 *in_addr);
28
29/**
30 * of_translate_dma_address() - translate a device-tree DMA address to a CPU
31 *				address
32 *
33 * Translate a DMA address from the device-tree into a CPU physical address,
34 * this walks up the tree and applies the various bus mappings on the way.
35 *
36 * Note: We consider that crossing any level with #size-cells == 0 to mean
37 * that translation is impossible (that is we are not dealing with a value
38 * that can be mapped to a cpu physical address). This is not really specified
39 * that way, but this is traditionally the way IBM at least do things
40 *
41 * @np: ne
42 * @in_addr: pointer to input DMA address
43 * Return: translated DMA address or OF_BAD_ADDR on error
44 */
45u64 of_translate_dma_address(const struct device_node *np, const __be32 *in_addr);
46
47
48/**
49 * of_get_dma_range() - get dma-ranges for a specific DT node
50 *
51 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
52 * cpu->bus address translations
53 *
54 * @np:		Pointer to device tree blob
55 * @cpu:	Pointer to variable storing the range's cpu address
56 * @bus:	Pointer to variable storing the range's bus address
57 * @size:	Pointer to variable storing the range's size
58 * Return: translated DMA address or OF_BAD_ADDR on error
59 */
60int of_get_dma_range(const struct device_node *np, phys_addr_t *cpu,
61		     dma_addr_t *bus, u64 *size);
62
63/**
64 * of_get_address() - obtain an address from a node
65 *
66 * Extract an address from a node, returns the region size and the address
67 * space flags too. The PCI version uses a BAR number instead of an absolute
68 * index.
69 *
70 * @np: Node to check
71 * @index: Index of address to read (0 = first)
72 * @size: place to put size on success
73 * @flags: place to put flags on success
74 * Return: pointer to address which can be read
75 */
76const __be32 *of_get_address(const struct device_node *np, int index,
77			     u64 *size, unsigned int *flags);
78
79struct resource;
80
81/**
82 * of_address_to_resource() - translate device tree address to resource
83 *
84 * Note that if your address is a PIO address, the conversion will fail if
85 * the physical address can't be internally converted to an IO token with
86 * pci_address_to_pio(), that is because it's either called to early or it
87 * can't be matched to any host bridge IO space
88 *
89 * @np: node to check
90 * @index: index of address to read (0 = first)
91 * @r: place to put resource information
92 * Return: 0 if OK, -ve on error
93 */
94int of_address_to_resource(const struct device_node *np, int index,
95			   struct resource *r);
96
97#endif
98