blob: 6d2fa8f1044b98bce3d106c61a7806abc842f3ed [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassaadfaf02017-05-17 17:18:04 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 *
5 * (C) Copyright 2012
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
7 * Marek Vasut <marex@denx.de>
Simon Glassaadfaf02017-05-17 17:18:04 -06008 */
9
Simon Glass6fe43a32017-05-18 20:08:59 -060010#ifndef _DM_FDTADDR_H
11#define _DM_FDTADDR_H
Simon Glassaadfaf02017-05-17 17:18:04 -060012
13#include <fdtdec.h>
14
15struct udevice;
16
17/**
Simon Glassba1dea42017-05-17 17:18:05 -060018 * devfdt_get_addr() - Get the reg property of a device
Simon Glassaadfaf02017-05-17 17:18:04 -060019 *
20 * @dev: Pointer to a device
21 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +010022 * Return: addr
Simon Glassaadfaf02017-05-17 17:18:04 -060023 */
Simon Glassc6548b82020-01-27 08:49:39 -070024fdt_addr_t devfdt_get_addr(const struct udevice *dev);
Simon Glassaadfaf02017-05-17 17:18:04 -060025
26/**
Simon Glassba1dea42017-05-17 17:18:05 -060027 * devfdt_get_addr_ptr() - Return pointer to the address of the reg property
Simon Glassaadfaf02017-05-17 17:18:04 -060028 * of a device
29 *
30 * @dev: Pointer to a device
31 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +010032 * Return: Pointer to addr, or NULL if there is no such property
Simon Glassaadfaf02017-05-17 17:18:04 -060033 */
Simon Glassc6548b82020-01-27 08:49:39 -070034void *devfdt_get_addr_ptr(const struct udevice *dev);
Simon Glassaadfaf02017-05-17 17:18:04 -060035
36/**
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +020037 * devfdt_remap_addr() - Return pointer to the memory-mapped I/O address
38 * of the reg property of a device
39 *
40 * @dev: Pointer to a device
41 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +010042 * Return: Pointer to addr, or NULL if there is no such property
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +020043 */
Simon Glassc6548b82020-01-27 08:49:39 -070044void *devfdt_remap_addr(const struct udevice *dev);
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +020045
46/**
47 * devfdt_remap_addr_index() - Return indexed pointer to the memory-mapped
48 * I/O address of the reg property of a device
49 * @index: the 'reg' property can hold a list of <addr, size> pairs
50 * and @index is used to select which one is required
51 *
52 * @dev: Pointer to a device
53 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +010054 * Return: Pointer to addr, or NULL if there is no such property
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +020055 */
Simon Glassc6548b82020-01-27 08:49:39 -070056void *devfdt_remap_addr_index(const struct udevice *dev, int index);
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +020057
58/**
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +010059 * devfdt_remap_addr_name() - Get the reg property of a device, indexed by
60 * name, as a memory-mapped I/O pointer
61 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
62 * 'reg-names' property providing named-based identification. @index
63 * indicates the value to search for in 'reg-names'.
64 *
65 * @dev: Pointer to a device
66 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +010067 * Return: Pointer to addr, or NULL if there is no such property
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +010068 */
Simon Glassc6548b82020-01-27 08:49:39 -070069void *devfdt_remap_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +010070
71/**
Simon Glassba1dea42017-05-17 17:18:05 -060072 * devfdt_map_physmem() - Read device address from reg property of the
Simon Glassaadfaf02017-05-17 17:18:04 -060073 * device node and map the address into CPU address
74 * space.
75 *
76 * @dev: Pointer to device
77 * @size: size of the memory to map
78 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +010079 * Return: mapped address, or NULL if the device does not have reg property.
Simon Glassaadfaf02017-05-17 17:18:04 -060080 */
Simon Glassc6548b82020-01-27 08:49:39 -070081void *devfdt_map_physmem(const struct udevice *dev, unsigned long size);
Simon Glassaadfaf02017-05-17 17:18:04 -060082
83/**
Simon Glassba1dea42017-05-17 17:18:05 -060084 * devfdt_get_addr_index() - Get the indexed reg property of a device
Simon Glassaadfaf02017-05-17 17:18:04 -060085 *
86 * @dev: Pointer to a device
87 * @index: the 'reg' property can hold a list of <addr, size> pairs
88 * and @index is used to select which one is required
89 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +010090 * Return: addr
Simon Glassaadfaf02017-05-17 17:18:04 -060091 */
Simon Glassc6548b82020-01-27 08:49:39 -070092fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index);
Simon Glassaadfaf02017-05-17 17:18:04 -060093
94/**
Bin Menga44397f2021-09-12 11:15:12 +080095 * devfdt_get_addr_index_ptr() - Return indexed pointer to the address of the
96 * reg property of a device
97 *
98 * @dev: Pointer to a device
99 * @index: the 'reg' property can hold a list of <addr, size> pairs
100 * and @index is used to select which one is required
101 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +0100102 * Return: Pointer to addr, or NULL if there is no such property
Bin Menga44397f2021-09-12 11:15:12 +0800103 */
104void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index);
105
106/**
Simon Glassba1dea42017-05-17 17:18:05 -0600107 * devfdt_get_addr_size_index() - Get the indexed reg property of a device
Simon Glassaadfaf02017-05-17 17:18:04 -0600108 *
109 * Returns the address and size specified in the 'reg' property of a device.
110 *
111 * @dev: Pointer to a device
112 * @index: the 'reg' property can hold a list of <addr, size> pairs
113 * and @index is used to select which one is required
Johan Jonkeref6769f2023-04-21 17:33:58 +0200114 * @size: Pointer to size variable - this function returns the size
Simon Glassaadfaf02017-05-17 17:18:04 -0600115 * specified in the 'reg' property here
116 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +0100117 * Return: addr
Simon Glassaadfaf02017-05-17 17:18:04 -0600118 */
Simon Glassc6548b82020-01-27 08:49:39 -0700119fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index,
120 fdt_size_t *size);
Simon Glassaadfaf02017-05-17 17:18:04 -0600121
122/**
Johan Jonkeref6769f2023-04-21 17:33:58 +0200123 * devfdt_get_addr_size_index_ptr() - Return indexed pointer to the address of the
124 * reg property of a device
125 *
126 * @dev: Pointer to a device
127 * @index: the 'reg' property can hold a list of <addr, size> pairs
128 * and @index is used to select which one is required
129 * @size: Pointer to size variable - this function returns the size
130 * specified in the 'reg' property here
131 *
132 * Return: Pointer to addr, or NULL if there is no such property
133 */
134void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index,
135 fdt_size_t *size);
136
137/**
Simon Glassba1dea42017-05-17 17:18:05 -0600138 * devfdt_get_addr_name() - Get the reg property of a device, indexed by name
Simon Glassaadfaf02017-05-17 17:18:04 -0600139 *
140 * @dev: Pointer to a device
141 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
142 * 'reg-names' property providing named-based identification. @index
143 * indicates the value to search for in 'reg-names'.
144 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +0100145 * Return: addr
Simon Glassaadfaf02017-05-17 17:18:04 -0600146 */
Simon Glassc6548b82020-01-27 08:49:39 -0700147fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name);
Simon Glassaadfaf02017-05-17 17:18:04 -0600148
Sekhar Norif677c6f2019-08-01 19:12:56 +0530149/**
150 * devfdt_get_addr_size_name() - Get the reg property and its size for a device,
151 * indexed by name
152 *
153 * Returns the address and size specified in the 'reg' property of a device.
154 *
155 * @dev: Pointer to a device
156 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
157 * 'reg-names' property providing named-based identification. @index
158 * indicates the value to search for in 'reg-names'.
159 * @size: Pointer to size variable - this function returns the size
160 * specified in the 'reg' property here
161 *
Patrick Delaunayd17a6792022-01-12 10:55:41 +0100162 * Return: addr
Sekhar Norif677c6f2019-08-01 19:12:56 +0530163 */
Simon Glassc6548b82020-01-27 08:49:39 -0700164fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev,
165 const char *name, fdt_size_t *size);
Sekhar Norif677c6f2019-08-01 19:12:56 +0530166
Simon Glass23b27592019-09-15 12:08:58 -0600167/**
168 * devfdt_get_addr_pci() - Read an address and handle PCI address translation
169 *
170 * @dev: Device to read from
Simon Glass4289c262023-09-26 08:14:58 -0600171 * @sizep: If non-NULL, returns size of address space
Patrick Delaunayd17a6792022-01-12 10:55:41 +0100172 * Return: address or FDT_ADDR_T_NONE if not found
Simon Glass23b27592019-09-15 12:08:58 -0600173 */
Simon Glass4289c262023-09-26 08:14:58 -0600174fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev, fdt_size_t *sizep);
Simon Glass23b27592019-09-15 12:08:58 -0600175
Simon Glassaadfaf02017-05-17 17:18:04 -0600176#endif