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