Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 |
| 4 | * Texas Instruments Incorporated - http://www.ti.com/ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef _RPROC_H_ |
| 8 | #define _RPROC_H_ |
| 9 | |
| 10 | /* |
| 11 | * Note: The platform data support is not meant for use with newer |
| 12 | * platforms. This is meant only for legacy devices. This mode of |
| 13 | * initialization *will* be eventually removed once all necessary |
| 14 | * platforms have moved to dm/fdt. |
| 15 | */ |
| 16 | #include <dm/platdata.h> /* For platform data support - non dt world */ |
| 17 | |
| 18 | /** |
| 19 | * enum rproc_mem_type - What type of memory model does the rproc use |
| 20 | * @RPROC_INTERNAL_MEMORY_MAPPED: Remote processor uses own memory and is memory |
| 21 | * mapped to the host processor over an address range. |
| 22 | * |
| 23 | * Please note that this is an enumeration of memory model of different types |
| 24 | * of remote processors. Few of the remote processors do have own internal |
| 25 | * memories, while others use external memory for instruction and data. |
| 26 | */ |
| 27 | enum rproc_mem_type { |
| 28 | RPROC_INTERNAL_MEMORY_MAPPED = 0, |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * struct dm_rproc_uclass_pdata - platform data for a CPU |
| 33 | * @name: Platform-specific way of naming the Remote proc |
| 34 | * @mem_type: one of 'enum rproc_mem_type' |
| 35 | * @driver_plat_data: driver specific platform data that may be needed. |
| 36 | * |
| 37 | * This can be accessed with dev_get_uclass_platdata() for any UCLASS_REMOTEPROC |
| 38 | * device. |
| 39 | * |
| 40 | */ |
| 41 | struct dm_rproc_uclass_pdata { |
| 42 | const char *name; |
| 43 | enum rproc_mem_type mem_type; |
| 44 | void *driver_plat_data; |
| 45 | }; |
| 46 | |
| 47 | /** |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 48 | * struct dm_rproc_ops - Driver model remote proc operations. |
| 49 | * |
| 50 | * This defines the operations provided by remote proc driver. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 51 | */ |
| 52 | struct dm_rproc_ops { |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 53 | /** |
| 54 | * init() - Initialize the remoteproc device (optional) |
| 55 | * |
| 56 | * This is called after the probe is completed allowing the remote |
| 57 | * processor drivers to split up the initializations between probe and |
| 58 | * init if needed. |
| 59 | * |
| 60 | * @dev: Remote proc device |
| 61 | * @return 0 if all ok, else appropriate error value. |
| 62 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 63 | int (*init)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * load() - Load the remoteproc device using data provided (mandatory) |
| 67 | * |
| 68 | * Load the remoteproc device with an image, do not start the device. |
| 69 | * |
| 70 | * @dev: Remote proc device |
| 71 | * @addr: Address of the image to be loaded |
| 72 | * @size: Size of the image to be loaded |
| 73 | * @return 0 if all ok, else appropriate error value. |
| 74 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 75 | int (*load)(struct udevice *dev, ulong addr, ulong size); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * start() - Start the remoteproc device (mandatory) |
| 79 | * |
| 80 | * @dev: Remote proc device |
| 81 | * @return 0 if all ok, else appropriate error value. |
| 82 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 83 | int (*start)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * stop() - Stop the remoteproc device (optional) |
| 87 | * |
| 88 | * @dev: Remote proc device |
| 89 | * @return 0 if all ok, else appropriate error value. |
| 90 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 91 | int (*stop)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * reset() - Reset the remoteproc device (optional) |
| 95 | * |
| 96 | * @dev: Remote proc device |
| 97 | * @return 0 if all ok, else appropriate error value. |
| 98 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 99 | int (*reset)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * is_running() - Check if the remote processor is running (optional) |
| 103 | * |
| 104 | * @dev: Remote proc device |
| 105 | * @return 0 if running, 1 if not running, -ve on error. |
| 106 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 107 | int (*is_running)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * ping() - Ping the remote device for basic communication (optional) |
| 111 | * |
| 112 | * @dev: Remote proc device |
| 113 | * @return 0 on success, 1 if not responding, -ve on other errors. |
| 114 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 115 | int (*ping)(struct udevice *dev); |
Fabien Dessenne | 163b7d7 | 2019-05-31 15:11:32 +0200 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * device_to_virt() - Return translated virtual address (optional) |
| 119 | * |
| 120 | * Translate a device address (remote processor view) to virtual |
| 121 | * address (main processor view). |
| 122 | * |
| 123 | * @dev: Remote proc device |
| 124 | * @da: Device address |
| 125 | * @return virtual address. |
| 126 | */ |
| 127 | void * (*device_to_virt)(struct udevice *dev, ulong da); |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | /* Accessor */ |
| 131 | #define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops) |
| 132 | |
Suman Anna | 26557d1 | 2019-07-19 10:27:56 -0500 | [diff] [blame] | 133 | #if CONFIG_IS_ENABLED(REMOTEPROC) |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 134 | /** |
| 135 | * rproc_init() - Initialize all bound remote proc devices |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 136 | * @return 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 137 | */ |
| 138 | int rproc_init(void); |
| 139 | |
| 140 | /** |
Lokesh Vutla | 81ae6e6 | 2018-08-27 15:57:50 +0530 | [diff] [blame] | 141 | * rproc_dev_init() - Initialize a remote proc device based on id |
| 142 | * @id: id of the remote processor |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 143 | * @return 0 if all ok, else appropriate error value. |
Lokesh Vutla | 81ae6e6 | 2018-08-27 15:57:50 +0530 | [diff] [blame] | 144 | */ |
| 145 | int rproc_dev_init(int id); |
| 146 | |
| 147 | /** |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 148 | * rproc_is_initialized() - check to see if remoteproc devices are initialized |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 149 | * @return true if all devices are initialized, false otherwise. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 150 | */ |
| 151 | bool rproc_is_initialized(void); |
| 152 | |
| 153 | /** |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 154 | * rproc_load() - load binary or elf to a remote processor |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 155 | * @id: id of the remote processor |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 156 | * @addr: address in memory where the image is located |
| 157 | * @size: size of the image |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 158 | * @return 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 159 | */ |
| 160 | int rproc_load(int id, ulong addr, ulong size); |
| 161 | |
| 162 | /** |
| 163 | * rproc_start() - Start a remote processor |
| 164 | * @id: id of the remote processor |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 165 | * @return 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 166 | */ |
| 167 | int rproc_start(int id); |
| 168 | |
| 169 | /** |
| 170 | * rproc_stop() - Stop a remote processor |
| 171 | * @id: id of the remote processor |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 172 | * @return 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 173 | */ |
| 174 | int rproc_stop(int id); |
| 175 | |
| 176 | /** |
| 177 | * rproc_reset() - reset a remote processor |
| 178 | * @id: id of the remote processor |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 179 | * @return 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 180 | */ |
| 181 | int rproc_reset(int id); |
| 182 | |
| 183 | /** |
| 184 | * rproc_ping() - ping a remote processor to check if it can communicate |
| 185 | * @id: id of the remote processor |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 186 | * @return 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 187 | * |
| 188 | * NOTE: this might need communication path available, which is not implemented |
| 189 | * as part of remoteproc framework - hook on to appropriate bus architecture to |
| 190 | * do the same |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 191 | */ |
| 192 | int rproc_ping(int id); |
| 193 | |
| 194 | /** |
| 195 | * rproc_is_running() - check to see if remote processor is running |
| 196 | * @id: id of the remote processor |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 197 | * @return 0 if running, 1 if not running, -ve on error. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 198 | * |
| 199 | * NOTE: this may not involve actual communication capability of the remote |
| 200 | * processor, but just ensures that it is out of reset and executing code. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 201 | */ |
| 202 | int rproc_is_running(int id); |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * rproc_elf32_sanity_check() - Verify if an image is a valid ELF32 one |
| 206 | * |
| 207 | * Check if a valid ELF32 image exists at the given memory location. Verify |
| 208 | * basic ELF32 format requirements like magic number and sections size. |
| 209 | * |
| 210 | * @addr: address of the image to verify |
| 211 | * @size: size of the image |
| 212 | * @return 0 if the image looks good, else appropriate error value. |
| 213 | */ |
| 214 | int rproc_elf32_sanity_check(ulong addr, ulong size); |
| 215 | |
| 216 | /** |
| 217 | * rproc_elf32_load_image() - load an ELF32 image |
| 218 | * @dev: device loading the ELF32 image |
| 219 | * @addr: valid ELF32 image address |
| 220 | * @return 0 if the image is successfully loaded, else appropriate error value. |
| 221 | */ |
| 222 | int rproc_elf32_load_image(struct udevice *dev, unsigned long addr); |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 223 | #else |
| 224 | static inline int rproc_init(void) { return -ENOSYS; } |
Lokesh Vutla | 81ae6e6 | 2018-08-27 15:57:50 +0530 | [diff] [blame] | 225 | static inline int rproc_dev_init(int id) { return -ENOSYS; } |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 226 | static inline bool rproc_is_initialized(void) { return false; } |
| 227 | static inline int rproc_load(int id, ulong addr, ulong size) { return -ENOSYS; } |
| 228 | static inline int rproc_start(int id) { return -ENOSYS; } |
| 229 | static inline int rproc_stop(int id) { return -ENOSYS; } |
| 230 | static inline int rproc_reset(int id) { return -ENOSYS; } |
| 231 | static inline int rproc_ping(int id) { return -ENOSYS; } |
| 232 | static inline int rproc_is_running(int id) { return -ENOSYS; } |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 233 | static inline int rproc_elf32_sanity_check(ulong addr, |
| 234 | ulong size) { return -ENOSYS; } |
| 235 | static inline int rproc_elf32_load_image(struct udevice *dev, |
| 236 | unsigned long addr) { return -ENOSYS; } |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 237 | #endif |
| 238 | |
| 239 | #endif /* _RPROC_H_ */ |