1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Texas Instruments Incorporated - https://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 */
17 #include <linux/errno.h>
20 * struct fw_rsc_hdr - firmware resource entry header
21 * @type: resource type
22 * @data: resource data
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.
34 * enum fw_resource_type - types of resource entries
36 * @RSC_CARVEOUT: request for allocation of a physically contiguous
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
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
49 * For more details regarding a specific resource type, please see its
50 * dedicated structure below.
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.
57 enum fw_resource_type
{
62 RSC_PRELOAD_VENDOR
= 4,
63 RSC_POSTLOAD_VENDOR
= 5,
67 #define FW_RSC_ADDR_ANY (-1)
70 * struct fw_rsc_carveout - physically contiguous memory request
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
78 * This resource entry requests the host to allocate a physically contiguous
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, ...).
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.
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.
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
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.
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).
112 struct fw_rsc_carveout
{
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
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
135 * This is obviously only needed if the remote processor is accessing memory
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).
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.
150 struct fw_rsc_devmem
{
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
166 * This resource entry provides the host information about a trace buffer
167 * into which the remote processor will write log messages.
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.
172 * After booting the remote processor, the trace buffers are exposed to the
173 * user via debugfs entries (called trace0, trace1, etc..).
175 struct fw_rsc_trace
{
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
192 * This descriptor is not a resource entry by itself; it is part of the
193 * vdev resource type (see below).
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.
199 struct fw_rsc_vdev_vring
{
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'.
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.
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).
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.
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.
251 struct fw_rsc_vdev_vring vring
[0];
255 * struct rproc_mem_entry - memory entry descriptor
256 * @va: virtual address
258 * @len: length, in bytes
259 * @da: device address
260 * @priv: associated data
261 * @name: associated memory region name (optional)
264 struct rproc_mem_entry
{
271 struct list_head node
;
276 typedef u32(*init_func_proto
) (u32 core_id
, struct rproc
*cfg
);
284 struct rproc_intmem_to_l3_mapping
{
286 struct l3_map mappings
[16];
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
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.
298 * Feel free to add more types when needed.
300 enum rproc_crash_type
{
306 /* we currently support only two vrings per rvdev */
307 #define RVDEV_NUM_VRINGS 2
309 #define RPMSG_NUM_BUFS (512)
310 #define RPMSG_BUF_SIZE (512)
311 #define RPMSG_TOTAL_BUF_SPACE (RPMSG_NUM_BUFS * RPMSG_BUF_SIZE)
314 * struct rproc_vring - remoteproc vring state
315 * @va: virtual 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
331 struct rproc_vdev
*rvdev
;
332 struct virtqueue
*vq
;
335 /** struct rproc - structure with all processor specific information for
336 * loading remotecore from boot loader.
338 * @num_iommus: Number of IOMMUs for this remote core. Zero indicates that the
339 * processor does not have an IOMMU.
341 * @cma_base: Base address of the carveout for this remotecore.
343 * @cma_size: Length of the carveout in bytes.
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
350 * @mmu_base_addr: base address of the MMU
352 * @entry_point: address that is the entry point for the remote core. This
353 * address is in the memory view of the remotecore.
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.
361 * @firmware_name: Name of the file that is expected to contain the ELF image.
363 * @has_rsc_table: Flag populated after parsing the ELF binary on target.
368 unsigned long cma_base
;
370 unsigned long page_table_addr
;
371 unsigned long mmu_base_addr
[2];
372 unsigned long load_addr
;
373 unsigned long entry_point
;
377 init_func_proto start_clocks
;
378 init_func_proto config_mmu
;
379 init_func_proto config_peripherals
;
380 init_func_proto start_core
;
382 struct rproc_intmem_to_l3_mapping
*intmem_to_l3_mapping
;
387 extern struct rproc
*rproc_cfg_arr
[2];
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.
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.
397 enum rproc_mem_type
{
398 RPROC_INTERNAL_MEMORY_MAPPED
= 0,
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.
407 * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC
411 struct dm_rproc_uclass_pdata
{
413 enum rproc_mem_type mem_type
;
414 void *driver_plat_data
;
418 * struct dm_rproc_ops - Driver model remote proc operations.
420 * This defines the operations provided by remote proc driver.
422 struct dm_rproc_ops
{
424 * init() - Initialize the remoteproc device (optional)
426 * This is called after the probe is completed allowing the remote
427 * processor drivers to split up the initializations between probe and
430 * @dev: Remote proc device
431 * @return 0 if all ok, else appropriate error value.
433 int (*init
)(struct udevice
*dev
);
436 * load() - Load the remoteproc device using data provided (mandatory)
438 * Load the remoteproc device with an image, do not start the device.
440 * @dev: Remote proc device
441 * @addr: Address of the image to be loaded
442 * @size: Size of the image to be loaded
443 * @return 0 if all ok, else appropriate error value.
445 int (*load
)(struct udevice
*dev
, ulong addr
, ulong size
);
448 * start() - Start the remoteproc device (mandatory)
450 * @dev: Remote proc device
451 * @return 0 if all ok, else appropriate error value.
453 int (*start
)(struct udevice
*dev
);
456 * stop() - Stop the remoteproc device (optional)
458 * @dev: Remote proc device
459 * @return 0 if all ok, else appropriate error value.
461 int (*stop
)(struct udevice
*dev
);
464 * reset() - Reset the remoteproc device (optional)
466 * @dev: Remote proc device
467 * @return 0 if all ok, else appropriate error value.
469 int (*reset
)(struct udevice
*dev
);
472 * is_running() - Check if the remote processor is running (optional)
474 * @dev: Remote proc device
475 * @return 0 if running, 1 if not running, -ve on error.
477 int (*is_running
)(struct udevice
*dev
);
480 * ping() - Ping the remote device for basic communication (optional)
482 * @dev: Remote proc device
483 * @return 0 on success, 1 if not responding, -ve on other errors.
485 int (*ping
)(struct udevice
*dev
);
488 * device_to_virt() - Return translated virtual address (optional)
490 * Translate a device address (remote processor view) to virtual
491 * address (main processor view).
493 * @dev: Remote proc device
494 * @da: Device address
495 * @size: Size of the memory region @da is pointing to
496 * @return virtual address.
498 void * (*device_to_virt
)(struct udevice
*dev
, ulong da
, ulong size
);
499 int (*add_res
)(struct udevice
*dev
,
500 struct rproc_mem_entry
*mapping
);
501 void * (*alloc_mem
)(struct udevice
*dev
, unsigned long len
,
502 unsigned long align
);
503 unsigned int (*config_pagetable
)(struct udevice
*dev
, unsigned int virt
,
504 unsigned int phys
, unsigned int len
);
508 #define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops)
510 #if CONFIG_IS_ENABLED(REMOTEPROC)
512 * rproc_init() - Initialize all bound remote proc devices
513 * Return: 0 if all ok, else appropriate error value.
515 int rproc_init(void);
518 * rproc_dev_init() - Initialize a remote proc device based on id
519 * @id: id of the remote processor
520 * Return: 0 if all ok, else appropriate error value.
522 int rproc_dev_init(int id
);
525 * rproc_is_initialized() - check to see if remoteproc devices are initialized
526 * Return: true if all devices are initialized, false otherwise.
528 bool rproc_is_initialized(void);
531 * rproc_load() - load binary or elf to a remote processor
532 * @id: id of the remote processor
533 * @addr: address in memory where the image is located
534 * @size: size of the image
535 * Return: 0 if all ok, else appropriate error value.
537 int rproc_load(int id
, ulong addr
, ulong size
);
540 * rproc_start() - Start a remote processor
541 * @id: id of the remote processor
542 * Return: 0 if all ok, else appropriate error value.
544 int rproc_start(int id
);
547 * rproc_stop() - Stop a remote processor
548 * @id: id of the remote processor
549 * Return: 0 if all ok, else appropriate error value.
551 int rproc_stop(int id
);
554 * rproc_reset() - reset a remote processor
555 * @id: id of the remote processor
556 * Return: 0 if all ok, else appropriate error value.
558 int rproc_reset(int id
);
561 * rproc_ping() - ping a remote processor to check if it can communicate
562 * @id: id of the remote processor
563 * Return: 0 if all ok, else appropriate error value.
565 * NOTE: this might need communication path available, which is not implemented
566 * as part of remoteproc framework - hook on to appropriate bus architecture to
569 int rproc_ping(int id
);
572 * rproc_is_running() - check to see if remote processor is running
573 * @id: id of the remote processor
574 * Return: 0 if running, 1 if not running, -ve on error.
576 * NOTE: this may not involve actual communication capability of the remote
577 * processor, but just ensures that it is out of reset and executing code.
579 int rproc_is_running(int id
);
582 * rproc_elf32_sanity_check() - Verify if an image is a valid ELF32 one
584 * Check if a valid ELF32 image exists at the given memory location. Verify
585 * basic ELF32 format requirements like magic number and sections size.
587 * @addr: address of the image to verify
588 * @size: size of the image
589 * Return: 0 if the image looks good, else appropriate error value.
591 int rproc_elf32_sanity_check(ulong addr
, ulong size
);
594 * rproc_elf64_sanity_check() - Verify if an image is a valid ELF32 one
596 * Check if a valid ELF64 image exists at the given memory location. Verify
597 * basic ELF64 format requirements like magic number and sections size.
599 * @addr: address of the image to verify
600 * @size: size of the image
601 * Return: 0 if the image looks good, else appropriate error value.
603 int rproc_elf64_sanity_check(ulong addr
, ulong size
);
606 * rproc_elf32_load_image() - load an ELF32 image
607 * @dev: device loading the ELF32 image
608 * @addr: valid ELF32 image address
609 * @size: size of the image
610 * Return: 0 if the image is successfully loaded, else appropriate error value.
612 int rproc_elf32_load_image(struct udevice
*dev
, unsigned long addr
, ulong size
);
615 * rproc_elf64_load_image() - load an ELF64 image
616 * @dev: device loading the ELF64 image
617 * @addr: valid ELF64 image address
618 * @size: size of the image
619 * Return: 0 if the image is successfully loaded, else appropriate error value.
621 int rproc_elf64_load_image(struct udevice
*dev
, ulong addr
, ulong size
);
624 * rproc_elf_load_image() - load an ELF image
625 * @dev: device loading the ELF image
626 * @addr: valid ELF image address
627 * @size: size of the image
629 * Auto detects if the image is ELF32 or ELF64 image and load accordingly.
630 * Return: 0 if the image is successfully loaded, else appropriate error value.
632 int rproc_elf_load_image(struct udevice
*dev
, unsigned long addr
, ulong size
);
635 * rproc_elf_get_boot_addr() - Get rproc's boot address.
636 * @dev: device loading the ELF image
637 * @addr: valid ELF image address
639 * This function returns the entry point address of the ELF
642 ulong
rproc_elf_get_boot_addr(struct udevice
*dev
, ulong addr
);
645 * rproc_elf32_load_rsc_table() - load the resource table from an ELF32 image
647 * Search for the resource table in an ELF32 image, and if found, copy it to
650 * @dev: device loading the resource table
651 * @fw_addr: ELF image address
652 * @fw_size: size of the ELF image
653 * @rsc_addr: pointer to the found resource table address. Updated on
655 * @rsc_size: pointer to the found resource table size. Updated on operation
658 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
659 * is no resource table (which is optional), or another appropriate error value.
661 int rproc_elf32_load_rsc_table(struct udevice
*dev
, ulong fw_addr
,
662 ulong fw_size
, ulong
*rsc_addr
, ulong
*rsc_size
);
664 * rproc_elf64_load_rsc_table() - load the resource table from an ELF64 image
666 * Search for the resource table in an ELF64 image, and if found, copy it to
669 * @dev: device loading the resource table
670 * @fw_addr: ELF image address
671 * @fw_size: size of the ELF image
672 * @rsc_addr: pointer to the found resource table address. Updated on
674 * @rsc_size: pointer to the found resource table size. Updated on operation
677 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
678 * is no resource table (which is optional), or another appropriate error value.
680 int rproc_elf64_load_rsc_table(struct udevice
*dev
, ulong fw_addr
,
681 ulong fw_size
, ulong
*rsc_addr
, ulong
*rsc_size
);
683 * rproc_elf_load_rsc_table() - load the resource table from an ELF image
685 * Auto detects if the image is ELF32 or ELF64 image and search accordingly for
686 * the resource table, and if found, copy it to device memory.
688 * @dev: device loading the resource table
689 * @fw_addr: ELF image address
690 * @fw_size: size of the ELF image
691 * @rsc_addr: pointer to the found resource table address. Updated on
693 * @rsc_size: pointer to the found resource table size. Updated on operation
696 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
697 * is no resource table (which is optional), or another appropriate error value.
699 int rproc_elf_load_rsc_table(struct udevice
*dev
, ulong fw_addr
,
700 ulong fw_size
, ulong
*rsc_addr
, ulong
*rsc_size
);
702 unsigned long rproc_parse_resource_table(struct udevice
*dev
,
705 struct resource_table
*rproc_find_resource_table(struct udevice
*dev
,
709 static inline int rproc_init(void) { return -ENOSYS
; }
710 static inline int rproc_dev_init(int id
) { return -ENOSYS
; }
711 static inline bool rproc_is_initialized(void) { return false; }
712 static inline int rproc_load(int id
, ulong addr
, ulong size
) { return -ENOSYS
; }
713 static inline int rproc_start(int id
) { return -ENOSYS
; }
714 static inline int rproc_stop(int id
) { return -ENOSYS
; }
715 static inline int rproc_reset(int id
) { return -ENOSYS
; }
716 static inline int rproc_ping(int id
) { return -ENOSYS
; }
717 static inline int rproc_is_running(int id
) { return -ENOSYS
; }
718 static inline int rproc_elf32_sanity_check(ulong addr
,
719 ulong size
) { return -ENOSYS
; }
720 static inline int rproc_elf64_sanity_check(ulong addr
,
721 ulong size
) { return -ENOSYS
; }
722 static inline int rproc_elf_sanity_check(ulong addr
,
723 ulong size
) { return -ENOSYS
; }
724 static inline int rproc_elf32_load_image(struct udevice
*dev
,
725 unsigned long addr
, ulong size
)
727 static inline int rproc_elf64_load_image(struct udevice
*dev
, ulong addr
,
730 static inline int rproc_elf_load_image(struct udevice
*dev
, ulong addr
,
733 static inline ulong
rproc_elf_get_boot_addr(struct udevice
*dev
, ulong addr
)
735 static inline int rproc_elf32_load_rsc_table(struct udevice
*dev
, ulong fw_addr
,
736 ulong fw_size
, ulong
*rsc_addr
,
739 static inline int rproc_elf64_load_rsc_table(struct udevice
*dev
, ulong fw_addr
,
740 ulong fw_size
, ulong
*rsc_addr
,
743 static inline int rproc_elf_load_rsc_table(struct udevice
*dev
, ulong fw_addr
,
744 ulong fw_size
, ulong
*rsc_addr
,
749 #endif /* _RPROC_H_ */