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 | * |
| 22 | * @return addr |
| 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 | * |
| 32 | * @return Pointer to addr, or NULL if there is no such property |
| 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 | * |
| 42 | * @return Pointer to addr, or NULL if there is no such property |
| 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 | * |
| 54 | * @return Pointer to addr, or NULL if there is no such property |
| 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 |
| 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 | * |
| 67 | * @return Pointer to addr, or NULL if there is no such property |
| 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 | * |
| 79 | * @return mapped address, or NULL if the device does not have reg |
| 80 | * property. |
| 81 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 82 | void *devfdt_map_physmem(const struct udevice *dev, unsigned long size); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 83 | |
| 84 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 85 | * devfdt_get_addr_index() - Get the indexed reg property of a device |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 86 | * |
| 87 | * @dev: Pointer to a device |
| 88 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 89 | * and @index is used to select which one is required |
| 90 | * |
| 91 | * @return addr |
| 92 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 93 | 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] | 94 | |
| 95 | /** |
Bin Meng | fb9bec8 | 2021-09-12 11:15:12 +0800 | [diff] [blame] | 96 | * devfdt_get_addr_index_ptr() - Return indexed pointer to the address of the |
| 97 | * reg property of a device |
| 98 | * |
| 99 | * @dev: Pointer to a device |
| 100 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 101 | * and @index is used to select which one is required |
| 102 | * |
| 103 | * @return Pointer to addr, or NULL if there is no such property |
| 104 | */ |
| 105 | void *devfdt_get_addr_index_ptr(const struct udevice *dev, int index); |
| 106 | |
| 107 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 108 | * 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] | 109 | * |
| 110 | * Returns the address and size specified in the 'reg' property of a device. |
| 111 | * |
| 112 | * @dev: Pointer to a device |
| 113 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 114 | * and @index is used to select which one is required |
| 115 | * @size: Pointer to size varible - this function returns the size |
| 116 | * specified in the 'reg' property here |
| 117 | * |
| 118 | * @return addr |
| 119 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 120 | fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index, |
| 121 | fdt_size_t *size); |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 122 | |
| 123 | /** |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 124 | * 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] | 125 | * |
| 126 | * @dev: Pointer to a device |
| 127 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 128 | * 'reg-names' property providing named-based identification. @index |
| 129 | * indicates the value to search for in 'reg-names'. |
| 130 | * |
| 131 | * @return addr |
| 132 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 133 | 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] | 134 | |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 135 | /** |
| 136 | * devfdt_get_addr_size_name() - Get the reg property and its size for a device, |
| 137 | * indexed by name |
| 138 | * |
| 139 | * Returns the address and size specified in the 'reg' property of a device. |
| 140 | * |
| 141 | * @dev: Pointer to a device |
| 142 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 143 | * 'reg-names' property providing named-based identification. @index |
| 144 | * indicates the value to search for in 'reg-names'. |
| 145 | * @size: Pointer to size variable - this function returns the size |
| 146 | * specified in the 'reg' property here |
| 147 | * |
| 148 | * @return addr |
| 149 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 150 | fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, |
| 151 | const char *name, fdt_size_t *size); |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 152 | |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 153 | /** |
| 154 | * devfdt_get_addr_pci() - Read an address and handle PCI address translation |
| 155 | * |
| 156 | * @dev: Device to read from |
| 157 | * @return address or FDT_ADDR_T_NONE if not found |
| 158 | */ |
Simon Glass | d975ce2 | 2020-01-27 08:49:39 -0700 | [diff] [blame] | 159 | fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev); |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 160 | |
Simon Glass | d6ffb00 | 2017-05-17 17:18:04 -0600 | [diff] [blame] | 161 | #endif |