blob: 5fb5a4855b46b6cb427702132d929690f0e04ea6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass6fe43a32017-05-18 20:08:59 -06002/*
3 * Taken from Linux v4.9 drivers/of/address.c
4 *
5 * Modified for U-Boot
6 * Copyright (c) 2017 Google, Inc
Simon Glass6fe43a32017-05-18 20:08:59 -06007 */
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 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010023 * @np: pointer to node to check
Simon Glass6fe43a32017-05-18 20:08:59 -060024 * @in_addr: pointer to input address
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010025 * Return: translated address or OF_BAD_ADDR on error
Simon Glass6fe43a32017-05-18 20:08:59 -060026 */
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010027u64 of_translate_address(const struct device_node *np, const __be32 *in_addr);
Simon Glass6fe43a32017-05-18 20:08:59 -060028
29/**
Fabien Dessenne22236e02019-05-31 15:11:30 +020030 * 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 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010041 * @np: ne
Fabien Dessenne22236e02019-05-31 15:11:30 +020042 * @in_addr: pointer to input DMA address
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010043 * Return: translated DMA address or OF_BAD_ADDR on error
Fabien Dessenne22236e02019-05-31 15:11:30 +020044 */
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010045u64 of_translate_dma_address(const struct device_node *np, const __be32 *in_addr);
Fabien Dessenne22236e02019-05-31 15:11:30 +020046
Nicolas Saenz Julienne50d2fa42021-01-12 13:55:22 +010047/**
48 * of_get_dma_range() - get dma-ranges for a specific DT node
49 *
50 * Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
51 * cpu->bus address translations
52 *
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010053 * @np: Pointer to device tree blob
54 * @cpu: Pointer to variable storing the range's cpu address
55 * @bus: Pointer to variable storing the range's bus address
56 * @size: Pointer to variable storing the range's size
57 * Return: translated DMA address or OF_BAD_ADDR on error
Nicolas Saenz Julienne50d2fa42021-01-12 13:55:22 +010058 */
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010059int of_get_dma_range(const struct device_node *np, phys_addr_t *cpu,
Nicolas Saenz Julienne50d2fa42021-01-12 13:55:22 +010060 dma_addr_t *bus, u64 *size);
61
Fabien Dessenne22236e02019-05-31 15:11:30 +020062/**
Simon Glass6fe43a32017-05-18 20:08:59 -060063 * of_get_address() - obtain an address from a node
64 *
65 * Extract an address from a node, returns the region size and the address
66 * space flags too. The PCI version uses a BAR number instead of an absolute
67 * index.
68 *
69 * @np: Node to check
70 * @index: Index of address to read (0 = first)
71 * @size: place to put size on success
72 * @flags: place to put flags on success
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010073 * Return: pointer to address which can be read
Simon Glass6fe43a32017-05-18 20:08:59 -060074 */
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010075const __be32 *of_get_address(const struct device_node *np, int index,
Simon Glass6fe43a32017-05-18 20:08:59 -060076 u64 *size, unsigned int *flags);
77
78struct resource;
79
80/**
81 * of_address_to_resource() - translate device tree address to resource
82 *
83 * Note that if your address is a PIO address, the conversion will fail if
84 * the physical address can't be internally converted to an IO token with
85 * pci_address_to_pio(), that is because it's either called to early or it
86 * can't be matched to any host bridge IO space
87 *
88 * @np: node to check
89 * @index: index of address to read (0 = first)
90 * @r: place to put resource information
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010091 * Return: 0 if OK, -ve on error
Simon Glass6fe43a32017-05-18 20:08:59 -060092 */
Patrick Delaunay92c1c5c2022-01-12 10:53:49 +010093int of_address_to_resource(const struct device_node *np, int index,
Simon Glass6fe43a32017-05-18 20:08:59 -060094 struct resource *r);
95
96#endif