Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 2 | /* |
| 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 Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 8 | */ |
| 9 | |
Simon Glass | 38d21b4 | 2017-05-18 20:08:59 -0600 | [diff] [blame] | 10 | #ifndef _DM_FDTADDR_H |
| 11 | #define _DM_FDTADDR_H |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 12 | |
| 13 | #include <fdtdec.h> |
| 14 | |
| 15 | struct udevice; |
| 16 | |
| 17 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 18 | * devfdt_get_addr() - Get the reg property of a device |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 19 | * |
| 20 | * @dev: Pointer to a device |
| 21 | * |
Matthias Schiffer | e42c4d6 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 22 | * Return: Address, or FDT_ADDR_T_NONE if there is no such property |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 23 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 24 | fdt_addr_t devfdt_get_addr(const struct udevice *dev); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 25 | |
| 26 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 27 | * devfdt_get_addr_ptr() - Return pointer to the address of the reg property |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 28 | * of a device |
| 29 | * |
| 30 | * @dev: Pointer to a device |
| 31 | * |
Patrick Delaunay | 5ebb527 | 2022-01-12 10:55:41 +0100 | [diff] [blame] | 32 | * Return: Pointer to addr, or NULL if there is no such property |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 33 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 34 | void *devfdt_get_addr_ptr(const struct udevice *dev); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 35 | |
| 36 | /** |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 37 | * 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 Delaunay | 5ebb527 | 2022-01-12 10:55:41 +0100 | [diff] [blame] | 42 | * Return: Pointer to addr, or NULL if there is no such property |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 43 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 44 | void *devfdt_remap_addr(const struct udevice *dev); |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 45 | |
| 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 Delaunay | 5ebb527 | 2022-01-12 10:55:41 +0100 | [diff] [blame] | 54 | * Return: Pointer to addr, or NULL if there is no such property |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 55 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 56 | void *devfdt_remap_addr_index(const struct udevice *dev, int index); |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 57 | |
| 58 | /** |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 59 | * 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 |
Matthias Schiffer | e42c4d6 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 62 | * 'reg-names' property providing named-based identification. @name |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 63 | * indicates the value to search for in 'reg-names'. |
| 64 | * |
| 65 | * @dev: Pointer to a device |
| 66 | * |
Patrick Delaunay | 5ebb527 | 2022-01-12 10:55:41 +0100 | [diff] [blame] | 67 | * Return: Pointer to addr, or NULL if there is no such property |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 68 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 69 | void *devfdt_remap_addr_name(const struct udevice *dev, const char *name); |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 70 | |
| 71 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 72 | * devfdt_map_physmem() - Read device address from reg property of the |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 73 | * 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 Delaunay | 5ebb527 | 2022-01-12 10:55:41 +0100 | [diff] [blame] | 79 | * Return: mapped address, or NULL if the device does not have reg property. |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 80 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 81 | void *devfdt_map_physmem(const struct udevice *dev, unsigned long size); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 82 | |
| 83 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 84 | * devfdt_get_addr_index() - Get the indexed reg property of a device |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 85 | * |
| 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 | * |
Matthias Schiffer | e42c4d6 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 90 | * Return: Address, or FDT_ADDR_T_NONE if there is no such property |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 91 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 92 | fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 93 | |
| 94 | /** |
Bin Meng | fb9bec8 | 2021-09-12 11:15:12 +0800 | [diff] [blame] | 95 | * 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 Delaunay | 5ebb527 | 2022-01-12 10:55:41 +0100 | [diff] [blame] | 102 | * Return: Pointer to addr, or NULL if there is no such property |
Bin Meng | fb9bec8 | 2021-09-12 11:15:12 +0800 | [diff] [blame] | 103 | */ |
| 104 | void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index); |
| 105 | |
| 106 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 107 | * devfdt_get_addr_size_index() - Get the indexed reg property of a device |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 108 | * |
| 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 Jonker | aa4f61a | 2023-04-21 17:33:58 +0200 | [diff] [blame] | 114 | * @size: Pointer to size variable - this function returns the size |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 115 | * specified in the 'reg' property here |
| 116 | * |
Matthias Schiffer | e42c4d6 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 117 | * Return: Address, or FDT_ADDR_T_NONE if there is no such property |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 118 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 119 | fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, |
| 120 | fdt_size_t *size); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 121 | |
| 122 | /** |
Johan Jonker | aa4f61a | 2023-04-21 17:33:58 +0200 | [diff] [blame] | 123 | * 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 | */ |
| 134 | void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index, |
| 135 | fdt_size_t *size); |
| 136 | |
| 137 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 138 | * devfdt_get_addr_name() - Get the reg property of a device, indexed by name |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 139 | * |
| 140 | * @dev: Pointer to a device |
| 141 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
Matthias Schiffer | e42c4d6 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 142 | * 'reg-names' property providing named-based identification. @name |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 143 | * indicates the value to search for in 'reg-names'. |
| 144 | * |
Matthias Schiffer | e367305 | 2023-09-27 15:33:31 +0200 | [diff] [blame] | 145 | * Return: Address, or FDT_ADDR_T_NONE if there is no such property |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 146 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 147 | fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 148 | |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 149 | /** |
Matthias Schiffer | bc8fa1c | 2023-09-27 15:33:32 +0200 | [diff] [blame] | 150 | * devfdt_get_addr_name_ptr() - Get the reg property of a device as a pointer, |
| 151 | * indexed by name |
| 152 | * |
| 153 | * @dev: Pointer to a device |
| 154 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 155 | * 'reg-names' property providing named-based identification. @name |
| 156 | * indicates the value to search for in 'reg-names'. |
| 157 | * |
| 158 | * Return: Pointer to addr, or NULL if there is no such property |
| 159 | */ |
| 160 | void *devfdt_get_addr_name_ptr(const struct udevice *dev, const char *name); |
| 161 | |
| 162 | /** |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 163 | * devfdt_get_addr_size_name() - Get the reg property and its size for a device, |
| 164 | * indexed by name |
| 165 | * |
| 166 | * Returns the address and size specified in the 'reg' property of a device. |
| 167 | * |
| 168 | * @dev: Pointer to a device |
| 169 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
Matthias Schiffer | e42c4d6 | 2023-09-27 15:33:30 +0200 | [diff] [blame] | 170 | * 'reg-names' property providing named-based identification. @name |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 171 | * indicates the value to search for in 'reg-names'. |
| 172 | * @size: Pointer to size variable - this function returns the size |
| 173 | * specified in the 'reg' property here |
| 174 | * |
Matthias Schiffer | e367305 | 2023-09-27 15:33:31 +0200 | [diff] [blame] | 175 | * Return: Address, or FDT_ADDR_T_NONE if there is no such property |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 176 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 177 | fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, |
| 178 | const char *name, fdt_size_t *size); |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 179 | |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 180 | /** |
Matthias Schiffer | bc8fa1c | 2023-09-27 15:33:32 +0200 | [diff] [blame] | 181 | * devfdt_get_addr_size_name_ptr() - Get the reg property for a device as a |
| 182 | * pointer, indexed by name |
| 183 | * |
| 184 | * Returns the address and size specified in the 'reg' property of a device. |
| 185 | * |
| 186 | * @dev: Pointer to a device |
| 187 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 188 | * 'reg-names' property providing named-based identification. @name |
| 189 | * indicates the value to search for in 'reg-names'. |
| 190 | * @size: Pointer to size variable - this function returns the size |
| 191 | * specified in the 'reg' property here |
| 192 | * |
| 193 | * Return: Pointer to addr, or NULL if there is no such property |
| 194 | */ |
| 195 | void *devfdt_get_addr_size_name_ptr(const struct udevice *dev, |
| 196 | const char *name, fdt_size_t *size); |
| 197 | |
| 198 | /** |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 199 | * devfdt_get_addr_pci() - Read an address and handle PCI address translation |
| 200 | * |
| 201 | * @dev: Device to read from |
Simon Glass | f69d3d6 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 202 | * @sizep: If non-NULL, returns size of address space |
Patrick Delaunay | 5ebb527 | 2022-01-12 10:55:41 +0100 | [diff] [blame] | 203 | * Return: address or FDT_ADDR_T_NONE if not found |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 204 | */ |
Simon Glass | f69d3d6 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 205 | fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev, fdt_size_t *sizep); |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 206 | |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 207 | #endif |