1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Texas Instruments Incorporated - http://www.ti.com/
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.
16 #include <dm/platdata.h> /* For platform data support - non dt world */
19 * struct fw_rsc_hdr - firmware resource entry header
20 * @type: resource type
21 * @data: resource data
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.
33 * enum fw_resource_type - types of resource entries
35 * @RSC_CARVEOUT: request for allocation of a physically contiguous
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
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
48 * For more details regarding a specific resource type, please see its
49 * dedicated structure below.
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.
56 enum fw_resource_type {
61 RSC_PRELOAD_VENDOR = 4,
62 RSC_POSTLOAD_VENDOR = 5,
66 #define FW_RSC_ADDR_ANY (-1)
69 * struct fw_rsc_carveout - physically contiguous memory request
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
77 * This resource entry requests the host to allocate a physically contiguous
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, ...).
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.
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.
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
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.
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).
111 struct fw_rsc_carveout {
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
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
134 * This is obviously only needed if the remote processor is accessing memory
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).
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.
149 struct fw_rsc_devmem {
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
165 * This resource entry provides the host information about a trace buffer
166 * into which the remote processor will write log messages.
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.
171 * After booting the remote processor, the trace buffers are exposed to the
172 * user via debugfs entries (called trace0, trace1, etc..).
174 struct fw_rsc_trace {
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
191 * This descriptor is not a resource entry by itself; it is part of the
192 * vdev resource type (see below).
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.
198 struct fw_rsc_vdev_vring {
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'.
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.
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).
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.
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.
250 struct fw_rsc_vdev_vring vring[0];
254 * struct rproc_mem_entry - memory entry descriptor
255 * @va: virtual address
257 * @len: length, in bytes
258 * @da: device address
259 * @priv: associated data
260 * @name: associated memory region name (optional)
263 struct rproc_mem_entry {
270 struct list_head node;
275 typedef u32(*init_func_proto) (u32 core_id, struct rproc *cfg);
283 struct rproc_intmem_to_l3_mapping {
285 struct l3_map mappings[16];
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
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.
297 * Feel free to add more types when needed.
299 enum rproc_crash_type {
305 /* we currently support only two vrings per rvdev */
306 #define RVDEV_NUM_VRINGS 2
308 #define RPMSG_NUM_BUFS (512)
309 #define RPMSG_BUF_SIZE (512)
310 #define RPMSG_TOTAL_BUF_SPACE (RPMSG_NUM_BUFS * RPMSG_BUF_SIZE)
313 * struct rproc_vring - remoteproc vring state
314 * @va: virtual 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
330 struct rproc_vdev *rvdev;
331 struct virtqueue *vq;
334 /** struct rproc - structure with all processor specific information for
335 * loading remotecore from boot loader.
337 * @num_iommus: Number of IOMMUs for this remote core. Zero indicates that the
338 * processor does not have an IOMMU.
340 * @cma_base: Base address of the carveout for this remotecore.
342 * @cma_size: Length of the carveout in bytes.
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
349 * @mmu_base_addr: base address of the MMU
351 * @entry_point: address that is the entry point for the remote core. This
352 * address is in the memory view of the remotecore.
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.
360 * @firmware_name: Name of the file that is expected to contain the ELF image.
362 * @has_rsc_table: Flag populated after parsing the ELF binary on target.
367 unsigned long cma_base;
369 unsigned long page_table_addr;
370 unsigned long mmu_base_addr[2];
371 unsigned long load_addr;
372 unsigned long entry_point;
376 init_func_proto start_clocks;
377 init_func_proto config_mmu;
378 init_func_proto config_peripherals;
379 init_func_proto start_core;
381 struct rproc_intmem_to_l3_mapping *intmem_to_l3_mapping;
386 extern struct rproc *rproc_cfg_arr[2];
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.
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.
396 enum rproc_mem_type {
397 RPROC_INTERNAL_MEMORY_MAPPED = 0,
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.
406 * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC
410 struct dm_rproc_uclass_pdata {
412 enum rproc_mem_type mem_type;
413 void *driver_plat_data;
417 * struct dm_rproc_ops - Driver model remote proc operations.
419 * This defines the operations provided by remote proc driver.
421 struct dm_rproc_ops {
423 * init() - Initialize the remoteproc device (optional)
425 * This is called after the probe is completed allowing the remote
426 * processor drivers to split up the initializations between probe and
429 * @dev: Remote proc device
430 * @return 0 if all ok, else appropriate error value.
432 int (*init)(struct udevice *dev);
435 * load() - Load the remoteproc device using data provided (mandatory)
437 * Load the remoteproc device with an image, do not start the device.
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.
444 int (*load)(struct udevice *dev, ulong addr, ulong size);
447 * start() - Start the remoteproc device (mandatory)
449 * @dev: Remote proc device
450 * @return 0 if all ok, else appropriate error value.
452 int (*start)(struct udevice *dev);
455 * stop() - Stop the remoteproc device (optional)
457 * @dev: Remote proc device
458 * @return 0 if all ok, else appropriate error value.
460 int (*stop)(struct udevice *dev);
463 * reset() - Reset the remoteproc device (optional)
465 * @dev: Remote proc device
466 * @return 0 if all ok, else appropriate error value.
468 int (*reset)(struct udevice *dev);
471 * is_running() - Check if the remote processor is running (optional)
473 * @dev: Remote proc device
474 * @return 0 if running, 1 if not running, -ve on error.
476 int (*is_running)(struct udevice *dev);
479 * ping() - Ping the remote device for basic communication (optional)
481 * @dev: Remote proc device
482 * @return 0 on success, 1 if not responding, -ve on other errors.
484 int (*ping)(struct udevice *dev);
487 * device_to_virt() - Return translated virtual address (optional)
489 * Translate a device address (remote processor view) to virtual
490 * address (main processor view).
492 * @dev: Remote proc device
493 * @da: Device address
494 * @size: Size of the memory region @da is pointing to
495 * @return virtual address.
497 void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size);
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);
507 #define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops)
509 #if CONFIG_IS_ENABLED(REMOTEPROC)
511 * rproc_init() - Initialize all bound remote proc devices
512 * Return: 0 if all ok, else appropriate error value.
514 int rproc_init(void);
517 * rproc_dev_init() - Initialize a remote proc device based on id
518 * @id: id of the remote processor
519 * Return: 0 if all ok, else appropriate error value.
521 int rproc_dev_init(int id);
524 * rproc_is_initialized() - check to see if remoteproc devices are initialized
525 * Return: true if all devices are initialized, false otherwise.
527 bool rproc_is_initialized(void);
530 * rproc_load() - load binary or elf to a remote processor
531 * @id: id of the remote processor
532 * @addr: address in memory where the image is located
533 * @size: size of the image
534 * Return: 0 if all ok, else appropriate error value.
536 int rproc_load(int id, ulong addr, ulong size);
539 * rproc_start() - Start a remote processor
540 * @id: id of the remote processor
541 * Return: 0 if all ok, else appropriate error value.
543 int rproc_start(int id);
546 * rproc_stop() - Stop a remote processor
547 * @id: id of the remote processor
548 * Return: 0 if all ok, else appropriate error value.
550 int rproc_stop(int id);
553 * rproc_reset() - reset a remote processor
554 * @id: id of the remote processor
555 * Return: 0 if all ok, else appropriate error value.
557 int rproc_reset(int id);
560 * rproc_ping() - ping a remote processor to check if it can communicate
561 * @id: id of the remote processor
562 * Return: 0 if all ok, else appropriate error value.
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
568 int rproc_ping(int id);
571 * rproc_is_running() - check to see if remote processor is running
572 * @id: id of the remote processor
573 * Return: 0 if running, 1 if not running, -ve on error.
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.
578 int rproc_is_running(int id);
581 * rproc_elf32_sanity_check() - Verify if an image is a valid ELF32 one
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.
586 * @addr: address of the image to verify
587 * @size: size of the image
588 * Return: 0 if the image looks good, else appropriate error value.
590 int rproc_elf32_sanity_check(ulong addr, ulong size);
593 * rproc_elf64_sanity_check() - Verify if an image is a valid ELF32 one
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.
598 * @addr: address of the image to verify
599 * @size: size of the image
600 * Return: 0 if the image looks good, else appropriate error value.
602 int rproc_elf64_sanity_check(ulong addr, ulong size);
605 * rproc_elf32_load_image() - load an ELF32 image
606 * @dev: device loading the ELF32 image
607 * @addr: valid ELF32 image address
608 * @size: size of the image
609 * Return: 0 if the image is successfully loaded, else appropriate error value.
611 int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size);
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
618 * Return: 0 if the image is successfully loaded, else appropriate error value.
620 int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
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
628 * Auto detects if the image is ELF32 or ELF64 image and load accordingly.
629 * Return: 0 if the image is successfully loaded, else appropriate error value.
631 int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong size);
634 * rproc_elf_get_boot_addr() - Get rproc's boot address.
635 * @dev: device loading the ELF image
636 * @addr: valid ELF image address
638 * This function returns the entry point address of the ELF
641 ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr);
644 * rproc_elf32_load_rsc_table() - load the resource table from an ELF32 image
646 * Search for the resource table in an ELF32 image, and if found, copy it to
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
654 * @rsc_size: pointer to the found resource table size. Updated on operation
657 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
658 * is no resource table (which is optional), or another appropriate error value.
660 int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
661 ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
663 * rproc_elf64_load_rsc_table() - load the resource table from an ELF64 image
665 * Search for the resource table in an ELF64 image, and if found, copy it to
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
673 * @rsc_size: pointer to the found resource table size. Updated on operation
676 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
677 * is no resource table (which is optional), or another appropriate error value.
679 int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr,
680 ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
682 * rproc_elf_load_rsc_table() - load the resource table from an ELF image
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.
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
692 * @rsc_size: pointer to the found resource table size. Updated on operation
695 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
696 * is no resource table (which is optional), or another appropriate error value.
698 int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr,
699 ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
701 unsigned long rproc_parse_resource_table(struct udevice *dev,
704 struct resource_table *rproc_find_resource_table(struct udevice *dev,
708 static inline int rproc_init(void) { return -ENOSYS; }
709 static inline int rproc_dev_init(int id) { return -ENOSYS; }
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; }
717 static inline int rproc_elf32_sanity_check(ulong addr,
718 ulong size) { return -ENOSYS; }
719 static inline int rproc_elf64_sanity_check(ulong addr,
720 ulong size) { return -ENOSYS; }
721 static inline int rproc_elf_sanity_check(ulong addr,
722 ulong size) { return -ENOSYS; }
723 static inline int rproc_elf32_load_image(struct udevice *dev,
724 unsigned long addr, ulong size)
726 static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
729 static inline int rproc_elf_load_image(struct udevice *dev, ulong addr,
732 static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr)
734 static inline int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
735 ulong fw_size, ulong *rsc_addr,
738 static inline int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr,
739 ulong fw_size, ulong *rsc_addr,
742 static inline int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr,
743 ulong fw_size, ulong *rsc_addr,
748 #endif /* _RPROC_H_ */