Keerthy | a03df89 | 2022-01-27 13:16:55 +0100 | [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 |
Nishanth Menon | a94a407 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 4 | * Texas Instruments Incorporated - https://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 */ |
Max Krummenacher | e2e6929 | 2024-01-18 19:10:47 +0100 | [diff] [blame] | 17 | #include <linux/errno.h> |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 18 | |
| 19 | /** |
Keerthy | a03df89 | 2022-01-27 13:16:55 +0100 | [diff] [blame] | 20 | * struct fw_rsc_hdr - firmware resource entry header |
| 21 | * @type: resource type |
| 22 | * @data: resource data |
| 23 | * |
| 24 | * Every resource entry begins with a 'struct fw_rsc_hdr' header providing |
| 25 | * its @type. The content of the entry itself will immediately follow |
| 26 | * this header, and it should be parsed according to the resource type. |
| 27 | */ |
| 28 | struct fw_rsc_hdr { |
| 29 | u32 type; |
| 30 | u8 data[0]; |
| 31 | }; |
| 32 | |
| 33 | /** |
| 34 | * enum fw_resource_type - types of resource entries |
| 35 | * |
| 36 | * @RSC_CARVEOUT: request for allocation of a physically contiguous |
| 37 | * memory region. |
| 38 | * @RSC_DEVMEM: request to iommu_map a memory-based peripheral. |
| 39 | * @RSC_TRACE: announces the availability of a trace buffer into which |
| 40 | * the remote processor will be writing logs. |
| 41 | * @RSC_VDEV: declare support for a virtio device, and serve as its |
| 42 | * virtio header. |
| 43 | * @RSC_PRELOAD_VENDOR: a vendor resource type that needs to be handled by |
| 44 | * remoteproc implementations before loading |
| 45 | * @RSC_POSTLOAD_VENDOR: a vendor resource type that needs to be handled by |
| 46 | * remoteproc implementations after loading |
| 47 | * @RSC_LAST: just keep this one at the end |
| 48 | * |
| 49 | * For more details regarding a specific resource type, please see its |
| 50 | * dedicated structure below. |
| 51 | * |
| 52 | * Please note that these values are used as indices to the rproc_handle_rsc |
| 53 | * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to |
| 54 | * check the validity of an index before the lookup table is accessed, so |
| 55 | * please update it as needed. |
| 56 | */ |
| 57 | enum fw_resource_type { |
| 58 | RSC_CARVEOUT = 0, |
| 59 | RSC_DEVMEM = 1, |
| 60 | RSC_TRACE = 2, |
| 61 | RSC_VDEV = 3, |
| 62 | RSC_PRELOAD_VENDOR = 4, |
| 63 | RSC_POSTLOAD_VENDOR = 5, |
| 64 | RSC_LAST = 6, |
| 65 | }; |
| 66 | |
| 67 | #define FW_RSC_ADDR_ANY (-1) |
| 68 | |
| 69 | /** |
| 70 | * struct fw_rsc_carveout - physically contiguous memory request |
| 71 | * @da: device address |
| 72 | * @pa: physical address |
| 73 | * @len: length (in bytes) |
| 74 | * @flags: iommu protection flags |
| 75 | * @reserved: reserved (must be zero) |
| 76 | * @name: human-readable name of the requested memory region |
| 77 | * |
| 78 | * This resource entry requests the host to allocate a physically contiguous |
| 79 | * memory region. |
| 80 | * |
| 81 | * These request entries should precede other firmware resource entries, |
| 82 | * as other entries might request placing other data objects inside |
| 83 | * these memory regions (e.g. data/code segments, trace resource entries, ...). |
| 84 | * |
| 85 | * Allocating memory this way helps utilizing the reserved physical memory |
| 86 | * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries |
| 87 | * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB |
| 88 | * pressure is important; it may have a substantial impact on performance. |
| 89 | * |
| 90 | * If the firmware is compiled with static addresses, then @da should specify |
| 91 | * the expected device address of this memory region. If @da is set to |
| 92 | * FW_RSC_ADDR_ANY, then the host will dynamically allocate it, and then |
| 93 | * overwrite @da with the dynamically allocated address. |
| 94 | * |
| 95 | * We will always use @da to negotiate the device addresses, even if it |
| 96 | * isn't using an iommu. In that case, though, it will obviously contain |
| 97 | * physical addresses. |
| 98 | * |
| 99 | * Some remote processors needs to know the allocated physical address |
| 100 | * even if they do use an iommu. This is needed, e.g., if they control |
| 101 | * hardware accelerators which access the physical memory directly (this |
| 102 | * is the case with OMAP4 for instance). In that case, the host will |
| 103 | * overwrite @pa with the dynamically allocated physical address. |
| 104 | * Generally we don't want to expose physical addresses if we don't have to |
| 105 | * (remote processors are generally _not_ trusted), so we might want to |
| 106 | * change this to happen _only_ when explicitly required by the hardware. |
| 107 | * |
| 108 | * @flags is used to provide IOMMU protection flags, and @name should |
| 109 | * (optionally) contain a human readable name of this carveout region |
| 110 | * (mainly for debugging purposes). |
| 111 | */ |
| 112 | struct fw_rsc_carveout { |
| 113 | u32 da; |
| 114 | u32 pa; |
| 115 | u32 len; |
| 116 | u32 flags; |
| 117 | u32 reserved; |
| 118 | u8 name[32]; |
| 119 | }; |
| 120 | |
| 121 | /** |
| 122 | * struct fw_rsc_devmem - iommu mapping request |
| 123 | * @da: device address |
| 124 | * @pa: physical address |
| 125 | * @len: length (in bytes) |
| 126 | * @flags: iommu protection flags |
| 127 | * @reserved: reserved (must be zero) |
| 128 | * @name: human-readable name of the requested region to be mapped |
| 129 | * |
| 130 | * This resource entry requests the host to iommu map a physically contiguous |
| 131 | * memory region. This is needed in case the remote processor requires |
| 132 | * access to certain memory-based peripherals; _never_ use it to access |
| 133 | * regular memory. |
| 134 | * |
| 135 | * This is obviously only needed if the remote processor is accessing memory |
| 136 | * via an iommu. |
| 137 | * |
| 138 | * @da should specify the required device address, @pa should specify |
| 139 | * the physical address we want to map, @len should specify the size of |
| 140 | * the mapping and @flags is the IOMMU protection flags. As always, @name may |
| 141 | * (optionally) contain a human readable name of this mapping (mainly for |
| 142 | * debugging purposes). |
| 143 | * |
| 144 | * Note: at this point we just "trust" those devmem entries to contain valid |
| 145 | * physical addresses, but this isn't safe and will be changed: eventually we |
| 146 | * want remoteproc implementations to provide us ranges of physical addresses |
| 147 | * the firmware is allowed to request, and not allow firmwares to request |
| 148 | * access to physical addresses that are outside those ranges. |
| 149 | */ |
| 150 | struct fw_rsc_devmem { |
| 151 | u32 da; |
| 152 | u32 pa; |
| 153 | u32 len; |
| 154 | u32 flags; |
| 155 | u32 reserved; |
| 156 | u8 name[32]; |
| 157 | }; |
| 158 | |
| 159 | /** |
| 160 | * struct fw_rsc_trace - trace buffer declaration |
| 161 | * @da: device address |
| 162 | * @len: length (in bytes) |
| 163 | * @reserved: reserved (must be zero) |
| 164 | * @name: human-readable name of the trace buffer |
| 165 | * |
| 166 | * This resource entry provides the host information about a trace buffer |
| 167 | * into which the remote processor will write log messages. |
| 168 | * |
| 169 | * @da specifies the device address of the buffer, @len specifies |
| 170 | * its size, and @name may contain a human readable name of the trace buffer. |
| 171 | * |
| 172 | * After booting the remote processor, the trace buffers are exposed to the |
| 173 | * user via debugfs entries (called trace0, trace1, etc..). |
| 174 | */ |
| 175 | struct fw_rsc_trace { |
| 176 | u32 da; |
| 177 | u32 len; |
| 178 | u32 reserved; |
| 179 | u8 name[32]; |
| 180 | }; |
| 181 | |
| 182 | /** |
| 183 | * struct fw_rsc_vdev_vring - vring descriptor entry |
| 184 | * @da: device address |
| 185 | * @align: the alignment between the consumer and producer parts of the vring |
| 186 | * @num: num of buffers supported by this vring (must be power of two) |
| 187 | * @notifyid is a unique rproc-wide notify index for this vring. This notify |
| 188 | * index is used when kicking a remote processor, to let it know that this |
| 189 | * vring is triggered. |
| 190 | * @pa: physical address |
| 191 | * |
| 192 | * This descriptor is not a resource entry by itself; it is part of the |
| 193 | * vdev resource type (see below). |
| 194 | * |
| 195 | * Note that @da should either contain the device address where |
| 196 | * the remote processor is expecting the vring, or indicate that |
| 197 | * dynamically allocation of the vring's device address is supported. |
| 198 | */ |
| 199 | struct fw_rsc_vdev_vring { |
| 200 | u32 da; |
| 201 | u32 align; |
| 202 | u32 num; |
| 203 | u32 notifyid; |
| 204 | u32 pa; |
| 205 | }; |
| 206 | |
| 207 | /** |
| 208 | * struct fw_rsc_vdev - virtio device header |
| 209 | * @id: virtio device id (as in virtio_ids.h) |
| 210 | * @notifyid is a unique rproc-wide notify index for this vdev. This notify |
| 211 | * index is used when kicking a remote processor, to let it know that the |
| 212 | * status/features of this vdev have changes. |
| 213 | * @dfeatures specifies the virtio device features supported by the firmware |
| 214 | * @gfeatures is a place holder used by the host to write back the |
| 215 | * negotiated features that are supported by both sides. |
| 216 | * @config_len is the size of the virtio config space of this vdev. The config |
| 217 | * space lies in the resource table immediate after this vdev header. |
| 218 | * @status is a place holder where the host will indicate its virtio progress. |
| 219 | * @num_of_vrings indicates how many vrings are described in this vdev header |
| 220 | * @reserved: reserved (must be zero) |
| 221 | * @vring is an array of @num_of_vrings entries of 'struct fw_rsc_vdev_vring'. |
| 222 | * |
| 223 | * This resource is a virtio device header: it provides information about |
| 224 | * the vdev, and is then used by the host and its peer remote processors |
| 225 | * to negotiate and share certain virtio properties. |
| 226 | * |
| 227 | * By providing this resource entry, the firmware essentially asks remoteproc |
| 228 | * to statically allocate a vdev upon registration of the rproc (dynamic vdev |
| 229 | * allocation is not yet supported). |
| 230 | * |
| 231 | * Note: unlike virtualization systems, the term 'host' here means |
| 232 | * the Linux side which is running remoteproc to control the remote |
| 233 | * processors. We use the name 'gfeatures' to comply with virtio's terms, |
| 234 | * though there isn't really any virtualized guest OS here: it's the host |
| 235 | * which is responsible for negotiating the final features. |
| 236 | * Yeah, it's a bit confusing. |
| 237 | * |
| 238 | * Note: immediately following this structure is the virtio config space for |
| 239 | * this vdev (which is specific to the vdev; for more info, read the virtio |
| 240 | * spec). the size of the config space is specified by @config_len. |
| 241 | */ |
| 242 | struct fw_rsc_vdev { |
| 243 | u32 id; |
| 244 | u32 notifyid; |
| 245 | u32 dfeatures; |
| 246 | u32 gfeatures; |
| 247 | u32 config_len; |
| 248 | u8 status; |
| 249 | u8 num_of_vrings; |
| 250 | u8 reserved[2]; |
| 251 | struct fw_rsc_vdev_vring vring[0]; |
| 252 | }; |
| 253 | |
| 254 | /** |
| 255 | * struct rproc_mem_entry - memory entry descriptor |
| 256 | * @va: virtual address |
| 257 | * @dma: dma address |
| 258 | * @len: length, in bytes |
| 259 | * @da: device address |
| 260 | * @priv: associated data |
| 261 | * @name: associated memory region name (optional) |
| 262 | * @node: list node |
| 263 | */ |
| 264 | struct rproc_mem_entry { |
| 265 | void *va; |
| 266 | dma_addr_t dma; |
| 267 | int len; |
| 268 | u32 da; |
| 269 | void *priv; |
| 270 | char name[32]; |
| 271 | struct list_head node; |
| 272 | }; |
| 273 | |
| 274 | struct rproc; |
| 275 | |
| 276 | typedef u32(*init_func_proto) (u32 core_id, struct rproc *cfg); |
| 277 | |
| 278 | struct l3_map { |
| 279 | u32 priv_addr; |
| 280 | u32 l3_addr; |
| 281 | u32 len; |
| 282 | }; |
| 283 | |
| 284 | struct rproc_intmem_to_l3_mapping { |
| 285 | u32 num_entries; |
| 286 | struct l3_map mappings[16]; |
| 287 | }; |
| 288 | |
| 289 | /** |
| 290 | * enum rproc_crash_type - remote processor crash types |
| 291 | * @RPROC_MMUFAULT: iommu fault |
| 292 | * @RPROC_WATCHDOG: watchdog bite |
| 293 | * @RPROC_FATAL_ERROR fatal error |
| 294 | * |
| 295 | * Each element of the enum is used as an array index. So that, the value of |
| 296 | * the elements should be always something sane. |
| 297 | * |
| 298 | * Feel free to add more types when needed. |
| 299 | */ |
| 300 | enum rproc_crash_type { |
| 301 | RPROC_MMUFAULT, |
| 302 | RPROC_WATCHDOG, |
| 303 | RPROC_FATAL_ERROR, |
| 304 | }; |
| 305 | |
| 306 | /* we currently support only two vrings per rvdev */ |
| 307 | #define RVDEV_NUM_VRINGS 2 |
| 308 | |
| 309 | #define RPMSG_NUM_BUFS (512) |
| 310 | #define RPMSG_BUF_SIZE (512) |
| 311 | #define RPMSG_TOTAL_BUF_SPACE (RPMSG_NUM_BUFS * RPMSG_BUF_SIZE) |
| 312 | |
| 313 | /** |
| 314 | * struct rproc_vring - remoteproc vring state |
| 315 | * @va: virtual address |
| 316 | * @dma: dma address |
| 317 | * @len: length, in bytes |
| 318 | * @da: device address |
| 319 | * @align: vring alignment |
| 320 | * @notifyid: rproc-specific unique vring index |
| 321 | * @rvdev: remote vdev |
| 322 | * @vq: the virtqueue of this vring |
| 323 | */ |
| 324 | struct rproc_vring { |
| 325 | void *va; |
| 326 | dma_addr_t dma; |
| 327 | int len; |
| 328 | u32 da; |
| 329 | u32 align; |
| 330 | int notifyid; |
| 331 | struct rproc_vdev *rvdev; |
| 332 | struct virtqueue *vq; |
| 333 | }; |
| 334 | |
| 335 | /** struct rproc - structure with all processor specific information for |
| 336 | * loading remotecore from boot loader. |
| 337 | * |
| 338 | * @num_iommus: Number of IOMMUs for this remote core. Zero indicates that the |
| 339 | * processor does not have an IOMMU. |
| 340 | * |
| 341 | * @cma_base: Base address of the carveout for this remotecore. |
| 342 | * |
| 343 | * @cma_size: Length of the carveout in bytes. |
| 344 | * |
| 345 | * @page_table_addr: array with the physical address of the page table. We are |
| 346 | * using the same page table for both IOMMU's. There is currently no strong |
| 347 | * usecase for maintaining different page tables for different MMU's servicing |
| 348 | * the same CPU. |
| 349 | * |
| 350 | * @mmu_base_addr: base address of the MMU |
| 351 | * |
| 352 | * @entry_point: address that is the entry point for the remote core. This |
| 353 | * address is in the memory view of the remotecore. |
| 354 | * |
| 355 | * @load_addr: Address to which the bootloader loads the firmware from |
| 356 | * persistent storage before invoking the ELF loader. Keeping this address |
| 357 | * configurable allows future optimizations such as loading the firmware from |
| 358 | * storage for remotecore2 via EDMA while the CPU is processing the ELF image |
| 359 | * of remotecore1. This address is in the memory view of the A15. |
| 360 | * |
| 361 | * @firmware_name: Name of the file that is expected to contain the ELF image. |
| 362 | * |
| 363 | * @has_rsc_table: Flag populated after parsing the ELF binary on target. |
| 364 | */ |
| 365 | |
| 366 | struct rproc { |
| 367 | u32 num_iommus; |
| 368 | unsigned long cma_base; |
| 369 | u32 cma_size; |
| 370 | unsigned long page_table_addr; |
| 371 | unsigned long mmu_base_addr[2]; |
| 372 | unsigned long load_addr; |
| 373 | unsigned long entry_point; |
| 374 | char *core_name; |
| 375 | char *firmware_name; |
| 376 | char *ptn; |
| 377 | init_func_proto start_clocks; |
| 378 | init_func_proto config_mmu; |
| 379 | init_func_proto config_peripherals; |
| 380 | init_func_proto start_core; |
| 381 | u32 has_rsc_table; |
| 382 | struct rproc_intmem_to_l3_mapping *intmem_to_l3_mapping; |
| 383 | u32 trace_pa; |
| 384 | u32 trace_len; |
| 385 | }; |
| 386 | |
| 387 | extern struct rproc *rproc_cfg_arr[2]; |
| 388 | /** |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 389 | * enum rproc_mem_type - What type of memory model does the rproc use |
| 390 | * @RPROC_INTERNAL_MEMORY_MAPPED: Remote processor uses own memory and is memory |
| 391 | * mapped to the host processor over an address range. |
| 392 | * |
| 393 | * Please note that this is an enumeration of memory model of different types |
| 394 | * of remote processors. Few of the remote processors do have own internal |
| 395 | * memories, while others use external memory for instruction and data. |
| 396 | */ |
| 397 | enum rproc_mem_type { |
| 398 | RPROC_INTERNAL_MEMORY_MAPPED = 0, |
| 399 | }; |
| 400 | |
| 401 | /** |
| 402 | * struct dm_rproc_uclass_pdata - platform data for a CPU |
| 403 | * @name: Platform-specific way of naming the Remote proc |
| 404 | * @mem_type: one of 'enum rproc_mem_type' |
| 405 | * @driver_plat_data: driver specific platform data that may be needed. |
MD Danish Anwar | fb49d6c | 2024-03-21 15:58:19 +0530 | [diff] [blame] | 406 | * @fw_name: firmware name |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 407 | * |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 408 | * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 409 | * device. |
| 410 | * |
| 411 | */ |
| 412 | struct dm_rproc_uclass_pdata { |
| 413 | const char *name; |
| 414 | enum rproc_mem_type mem_type; |
| 415 | void *driver_plat_data; |
MD Danish Anwar | fb49d6c | 2024-03-21 15:58:19 +0530 | [diff] [blame] | 416 | char *fw_name; |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 417 | }; |
| 418 | |
| 419 | /** |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 420 | * struct dm_rproc_ops - Driver model remote proc operations. |
| 421 | * |
| 422 | * This defines the operations provided by remote proc driver. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 423 | */ |
| 424 | struct dm_rproc_ops { |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 425 | /** |
| 426 | * init() - Initialize the remoteproc device (optional) |
| 427 | * |
| 428 | * This is called after the probe is completed allowing the remote |
| 429 | * processor drivers to split up the initializations between probe and |
| 430 | * init if needed. |
| 431 | * |
| 432 | * @dev: Remote proc device |
| 433 | * @return 0 if all ok, else appropriate error value. |
| 434 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 435 | int (*init)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 436 | |
| 437 | /** |
| 438 | * load() - Load the remoteproc device using data provided (mandatory) |
| 439 | * |
| 440 | * Load the remoteproc device with an image, do not start the device. |
| 441 | * |
| 442 | * @dev: Remote proc device |
| 443 | * @addr: Address of the image to be loaded |
| 444 | * @size: Size of the image to be loaded |
| 445 | * @return 0 if all ok, else appropriate error value. |
| 446 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 447 | int (*load)(struct udevice *dev, ulong addr, ulong size); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 448 | |
| 449 | /** |
| 450 | * start() - Start the remoteproc device (mandatory) |
| 451 | * |
| 452 | * @dev: Remote proc device |
| 453 | * @return 0 if all ok, else appropriate error value. |
| 454 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 455 | int (*start)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 456 | |
| 457 | /** |
| 458 | * stop() - Stop the remoteproc device (optional) |
| 459 | * |
| 460 | * @dev: Remote proc device |
| 461 | * @return 0 if all ok, else appropriate error value. |
| 462 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 463 | int (*stop)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 464 | |
| 465 | /** |
| 466 | * reset() - Reset the remoteproc device (optional) |
| 467 | * |
| 468 | * @dev: Remote proc device |
| 469 | * @return 0 if all ok, else appropriate error value. |
| 470 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 471 | int (*reset)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 472 | |
| 473 | /** |
| 474 | * is_running() - Check if the remote processor is running (optional) |
| 475 | * |
| 476 | * @dev: Remote proc device |
| 477 | * @return 0 if running, 1 if not running, -ve on error. |
| 478 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 479 | int (*is_running)(struct udevice *dev); |
Fabien Dessenne | 31a839f | 2019-05-31 15:11:31 +0200 | [diff] [blame] | 480 | |
| 481 | /** |
| 482 | * ping() - Ping the remote device for basic communication (optional) |
| 483 | * |
| 484 | * @dev: Remote proc device |
| 485 | * @return 0 on success, 1 if not responding, -ve on other errors. |
| 486 | */ |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 487 | int (*ping)(struct udevice *dev); |
Fabien Dessenne | 163b7d7 | 2019-05-31 15:11:32 +0200 | [diff] [blame] | 488 | |
| 489 | /** |
| 490 | * device_to_virt() - Return translated virtual address (optional) |
| 491 | * |
| 492 | * Translate a device address (remote processor view) to virtual |
| 493 | * address (main processor view). |
| 494 | * |
| 495 | * @dev: Remote proc device |
| 496 | * @da: Device address |
Lokesh Vutla | c08eb93 | 2019-09-04 16:01:27 +0530 | [diff] [blame] | 497 | * @size: Size of the memory region @da is pointing to |
Fabien Dessenne | 163b7d7 | 2019-05-31 15:11:32 +0200 | [diff] [blame] | 498 | * @return virtual address. |
| 499 | */ |
Lokesh Vutla | c08eb93 | 2019-09-04 16:01:27 +0530 | [diff] [blame] | 500 | void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size); |
Keerthy | a03df89 | 2022-01-27 13:16:55 +0100 | [diff] [blame] | 501 | int (*add_res)(struct udevice *dev, |
| 502 | struct rproc_mem_entry *mapping); |
| 503 | void * (*alloc_mem)(struct udevice *dev, unsigned long len, |
| 504 | unsigned long align); |
| 505 | unsigned int (*config_pagetable)(struct udevice *dev, unsigned int virt, |
| 506 | unsigned int phys, unsigned int len); |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | /* Accessor */ |
| 510 | #define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops) |
| 511 | |
Suman Anna | 26557d1 | 2019-07-19 10:27:56 -0500 | [diff] [blame] | 512 | #if CONFIG_IS_ENABLED(REMOTEPROC) |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 513 | /** |
| 514 | * rproc_init() - Initialize all bound remote proc devices |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 515 | * Return: 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 516 | */ |
| 517 | int rproc_init(void); |
| 518 | |
| 519 | /** |
Lokesh Vutla | 81ae6e6 | 2018-08-27 15:57:50 +0530 | [diff] [blame] | 520 | * rproc_dev_init() - Initialize a remote proc device based on id |
| 521 | * @id: id of the remote processor |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 522 | * Return: 0 if all ok, else appropriate error value. |
Lokesh Vutla | 81ae6e6 | 2018-08-27 15:57:50 +0530 | [diff] [blame] | 523 | */ |
| 524 | int rproc_dev_init(int id); |
| 525 | |
| 526 | /** |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 527 | * rproc_is_initialized() - check to see if remoteproc devices are initialized |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 528 | * Return: true if all devices are initialized, false otherwise. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 529 | */ |
| 530 | bool rproc_is_initialized(void); |
| 531 | |
| 532 | /** |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 533 | * rproc_load() - load binary or elf to a remote processor |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 534 | * @id: id of the remote processor |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 535 | * @addr: address in memory where the image is located |
| 536 | * @size: size of the image |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 537 | * Return: 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 538 | */ |
| 539 | int rproc_load(int id, ulong addr, ulong size); |
| 540 | |
| 541 | /** |
| 542 | * rproc_start() - Start a remote processor |
| 543 | * @id: id of the remote processor |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 544 | * Return: 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 545 | */ |
| 546 | int rproc_start(int id); |
| 547 | |
| 548 | /** |
| 549 | * rproc_stop() - Stop a remote processor |
| 550 | * @id: id of the remote processor |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 551 | * Return: 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 552 | */ |
| 553 | int rproc_stop(int id); |
| 554 | |
| 555 | /** |
| 556 | * rproc_reset() - reset a remote processor |
| 557 | * @id: id of the remote processor |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 558 | * Return: 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 559 | */ |
| 560 | int rproc_reset(int id); |
| 561 | |
| 562 | /** |
| 563 | * rproc_ping() - ping a remote processor to check if it can communicate |
| 564 | * @id: id of the remote processor |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 565 | * Return: 0 if all ok, else appropriate error value. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 566 | * |
| 567 | * NOTE: this might need communication path available, which is not implemented |
| 568 | * as part of remoteproc framework - hook on to appropriate bus architecture to |
| 569 | * do the same |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 570 | */ |
| 571 | int rproc_ping(int id); |
| 572 | |
| 573 | /** |
| 574 | * rproc_is_running() - check to see if remote processor is running |
| 575 | * @id: id of the remote processor |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 576 | * Return: 0 if running, 1 if not running, -ve on error. |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 577 | * |
| 578 | * NOTE: this may not involve actual communication capability of the remote |
| 579 | * 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] | 580 | */ |
| 581 | int rproc_is_running(int id); |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 582 | |
| 583 | /** |
| 584 | * rproc_elf32_sanity_check() - Verify if an image is a valid ELF32 one |
| 585 | * |
| 586 | * Check if a valid ELF32 image exists at the given memory location. Verify |
| 587 | * basic ELF32 format requirements like magic number and sections size. |
| 588 | * |
| 589 | * @addr: address of the image to verify |
| 590 | * @size: size of the image |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 591 | * Return: 0 if the image looks good, else appropriate error value. |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 592 | */ |
| 593 | int rproc_elf32_sanity_check(ulong addr, ulong size); |
| 594 | |
| 595 | /** |
Lokesh Vutla | e3c4d6f | 2019-09-04 16:01:29 +0530 | [diff] [blame] | 596 | * rproc_elf64_sanity_check() - Verify if an image is a valid ELF32 one |
| 597 | * |
| 598 | * Check if a valid ELF64 image exists at the given memory location. Verify |
| 599 | * basic ELF64 format requirements like magic number and sections size. |
| 600 | * |
| 601 | * @addr: address of the image to verify |
| 602 | * @size: size of the image |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 603 | * Return: 0 if the image looks good, else appropriate error value. |
Lokesh Vutla | e3c4d6f | 2019-09-04 16:01:29 +0530 | [diff] [blame] | 604 | */ |
| 605 | int rproc_elf64_sanity_check(ulong addr, ulong size); |
| 606 | |
| 607 | /** |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 608 | * rproc_elf32_load_image() - load an ELF32 image |
| 609 | * @dev: device loading the ELF32 image |
| 610 | * @addr: valid ELF32 image address |
Lokesh Vutla | 14d963d | 2019-09-04 16:01:28 +0530 | [diff] [blame] | 611 | * @size: size of the image |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 612 | * Return: 0 if the image is successfully loaded, else appropriate error value. |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 613 | */ |
Lokesh Vutla | 14d963d | 2019-09-04 16:01:28 +0530 | [diff] [blame] | 614 | int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size); |
Lokesh Vutla | e3c4d6f | 2019-09-04 16:01:29 +0530 | [diff] [blame] | 615 | |
| 616 | /** |
| 617 | * rproc_elf64_load_image() - load an ELF64 image |
| 618 | * @dev: device loading the ELF64 image |
| 619 | * @addr: valid ELF64 image address |
| 620 | * @size: size of the image |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 621 | * Return: 0 if the image is successfully loaded, else appropriate error value. |
Lokesh Vutla | e3c4d6f | 2019-09-04 16:01:29 +0530 | [diff] [blame] | 622 | */ |
| 623 | int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size); |
Lokesh Vutla | 856c0ad | 2019-09-04 16:01:30 +0530 | [diff] [blame] | 624 | |
| 625 | /** |
| 626 | * rproc_elf_load_image() - load an ELF image |
| 627 | * @dev: device loading the ELF image |
| 628 | * @addr: valid ELF image address |
| 629 | * @size: size of the image |
| 630 | * |
| 631 | * Auto detects if the image is ELF32 or ELF64 image and load accordingly. |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 632 | * Return: 0 if the image is successfully loaded, else appropriate error value. |
Lokesh Vutla | 856c0ad | 2019-09-04 16:01:30 +0530 | [diff] [blame] | 633 | */ |
| 634 | int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong size); |
Lokesh Vutla | 81e39fb | 2019-09-04 16:01:31 +0530 | [diff] [blame] | 635 | |
| 636 | /** |
| 637 | * rproc_elf_get_boot_addr() - Get rproc's boot address. |
| 638 | * @dev: device loading the ELF image |
| 639 | * @addr: valid ELF image address |
| 640 | * |
| 641 | * This function returns the entry point address of the ELF |
| 642 | * image. |
| 643 | */ |
| 644 | ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr); |
Fabien Dessenne | ffcb880 | 2019-10-30 14:38:28 +0100 | [diff] [blame] | 645 | |
| 646 | /** |
| 647 | * rproc_elf32_load_rsc_table() - load the resource table from an ELF32 image |
| 648 | * |
| 649 | * Search for the resource table in an ELF32 image, and if found, copy it to |
| 650 | * device memory. |
| 651 | * |
| 652 | * @dev: device loading the resource table |
| 653 | * @fw_addr: ELF image address |
| 654 | * @fw_size: size of the ELF image |
| 655 | * @rsc_addr: pointer to the found resource table address. Updated on |
| 656 | * operation success |
| 657 | * @rsc_size: pointer to the found resource table size. Updated on operation |
| 658 | * success |
| 659 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 660 | * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there |
Fabien Dessenne | ffcb880 | 2019-10-30 14:38:28 +0100 | [diff] [blame] | 661 | * is no resource table (which is optional), or another appropriate error value. |
| 662 | */ |
| 663 | int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr, |
| 664 | ulong fw_size, ulong *rsc_addr, ulong *rsc_size); |
| 665 | /** |
| 666 | * rproc_elf64_load_rsc_table() - load the resource table from an ELF64 image |
| 667 | * |
| 668 | * Search for the resource table in an ELF64 image, and if found, copy it to |
| 669 | * device memory. |
| 670 | * |
| 671 | * @dev: device loading the resource table |
| 672 | * @fw_addr: ELF image address |
| 673 | * @fw_size: size of the ELF image |
| 674 | * @rsc_addr: pointer to the found resource table address. Updated on |
| 675 | * operation success |
| 676 | * @rsc_size: pointer to the found resource table size. Updated on operation |
| 677 | * success |
| 678 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 679 | * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there |
Fabien Dessenne | ffcb880 | 2019-10-30 14:38:28 +0100 | [diff] [blame] | 680 | * is no resource table (which is optional), or another appropriate error value. |
| 681 | */ |
| 682 | int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr, |
| 683 | ulong fw_size, ulong *rsc_addr, ulong *rsc_size); |
| 684 | /** |
| 685 | * rproc_elf_load_rsc_table() - load the resource table from an ELF image |
| 686 | * |
| 687 | * Auto detects if the image is ELF32 or ELF64 image and search accordingly for |
| 688 | * the resource table, and if found, copy it to device memory. |
| 689 | * |
| 690 | * @dev: device loading the resource table |
| 691 | * @fw_addr: ELF image address |
| 692 | * @fw_size: size of the ELF image |
| 693 | * @rsc_addr: pointer to the found resource table address. Updated on |
| 694 | * operation success |
| 695 | * @rsc_size: pointer to the found resource table size. Updated on operation |
| 696 | * success |
| 697 | * |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 698 | * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there |
Fabien Dessenne | ffcb880 | 2019-10-30 14:38:28 +0100 | [diff] [blame] | 699 | * is no resource table (which is optional), or another appropriate error value. |
| 700 | */ |
| 701 | int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr, |
| 702 | ulong fw_size, ulong *rsc_addr, ulong *rsc_size); |
Keerthy | a03df89 | 2022-01-27 13:16:55 +0100 | [diff] [blame] | 703 | |
| 704 | unsigned long rproc_parse_resource_table(struct udevice *dev, |
| 705 | struct rproc *cfg); |
| 706 | |
| 707 | struct resource_table *rproc_find_resource_table(struct udevice *dev, |
| 708 | unsigned int addr, |
| 709 | int *tablesz); |
MD Danish Anwar | fb49d6c | 2024-03-21 15:58:19 +0530 | [diff] [blame] | 710 | /** |
| 711 | * rproc_set_firmware() - assign a new firmware name |
| 712 | * @rproc_dev: device for which new firmware name is being assigned |
| 713 | * @fw_name: new firmware name to be assigned |
| 714 | * |
| 715 | * This function allows remoteproc drivers or clients to configure a custom |
| 716 | * firmware name. The function does not trigger a remote processor boot, |
| 717 | * only sets the firmware name used for a subsequent boot. |
| 718 | * |
| 719 | * This function sets the fw_name field in uclass pdata of the Remote proc |
| 720 | * |
| 721 | * Return: 0 on success or a negative value upon failure |
| 722 | */ |
| 723 | int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name); |
| 724 | |
| 725 | /** |
| 726 | * rproc_boot() - boot a remote processor |
| 727 | * @rproc_dev: rproc device to boot |
| 728 | * |
| 729 | * Boot a remote processor (i.e. load its firmware, power it on, ...). |
| 730 | * |
| 731 | * This function first loads the firmware set in the uclass pdata of Remote |
| 732 | * processor to a buffer and then loads firmware to the remote processor |
| 733 | * using rproc_load(). |
| 734 | * |
| 735 | * Return: 0 on success, and an appropriate error value otherwise |
| 736 | */ |
| 737 | int rproc_boot(struct udevice *rproc_dev); |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 738 | #else |
| 739 | static inline int rproc_init(void) { return -ENOSYS; } |
Lokesh Vutla | 81ae6e6 | 2018-08-27 15:57:50 +0530 | [diff] [blame] | 740 | static inline int rproc_dev_init(int id) { return -ENOSYS; } |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 741 | static inline bool rproc_is_initialized(void) { return false; } |
| 742 | static inline int rproc_load(int id, ulong addr, ulong size) { return -ENOSYS; } |
| 743 | static inline int rproc_start(int id) { return -ENOSYS; } |
| 744 | static inline int rproc_stop(int id) { return -ENOSYS; } |
| 745 | static inline int rproc_reset(int id) { return -ENOSYS; } |
| 746 | static inline int rproc_ping(int id) { return -ENOSYS; } |
| 747 | static inline int rproc_is_running(int id) { return -ENOSYS; } |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 748 | static inline int rproc_elf32_sanity_check(ulong addr, |
| 749 | ulong size) { return -ENOSYS; } |
Lokesh Vutla | e3c4d6f | 2019-09-04 16:01:29 +0530 | [diff] [blame] | 750 | static inline int rproc_elf64_sanity_check(ulong addr, |
| 751 | ulong size) { return -ENOSYS; } |
Lokesh Vutla | 856c0ad | 2019-09-04 16:01:30 +0530 | [diff] [blame] | 752 | static inline int rproc_elf_sanity_check(ulong addr, |
| 753 | ulong size) { return -ENOSYS; } |
Fabien Dessenne | 7a7c4cb | 2019-05-31 15:11:33 +0200 | [diff] [blame] | 754 | static inline int rproc_elf32_load_image(struct udevice *dev, |
Lokesh Vutla | 14d963d | 2019-09-04 16:01:28 +0530 | [diff] [blame] | 755 | unsigned long addr, ulong size) |
| 756 | { return -ENOSYS; } |
Lokesh Vutla | e3c4d6f | 2019-09-04 16:01:29 +0530 | [diff] [blame] | 757 | static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr, |
| 758 | ulong size) |
| 759 | { return -ENOSYS; } |
Lokesh Vutla | 856c0ad | 2019-09-04 16:01:30 +0530 | [diff] [blame] | 760 | static inline int rproc_elf_load_image(struct udevice *dev, ulong addr, |
| 761 | ulong size) |
| 762 | { return -ENOSYS; } |
Lokesh Vutla | 81e39fb | 2019-09-04 16:01:31 +0530 | [diff] [blame] | 763 | static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr) |
| 764 | { return 0; } |
Fabien Dessenne | ffcb880 | 2019-10-30 14:38:28 +0100 | [diff] [blame] | 765 | static inline int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr, |
| 766 | ulong fw_size, ulong *rsc_addr, |
| 767 | ulong *rsc_size) |
| 768 | { return -ENOSYS; } |
| 769 | static inline int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr, |
| 770 | ulong fw_size, ulong *rsc_addr, |
| 771 | ulong *rsc_size) |
| 772 | { return -ENOSYS; } |
| 773 | static inline int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr, |
| 774 | ulong fw_size, ulong *rsc_addr, |
| 775 | ulong *rsc_size) |
| 776 | { return -ENOSYS; } |
MD Danish Anwar | fb49d6c | 2024-03-21 15:58:19 +0530 | [diff] [blame] | 777 | static inline int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name) |
| 778 | { return -ENOSYS; } |
| 779 | static inline int rproc_boot(struct udevice *rproc_dev) |
| 780 | { return -ENOSYS; } |
Nishanth Menon | ddf56bc | 2015-09-17 15:42:39 -0500 | [diff] [blame] | 781 | #endif |
| 782 | |
| 783 | #endif /* _RPROC_H_ */ |