blob: f48054de6ba9bce1f149f9d0f27de92a1074c4eb [file] [log] [blame]
Keerthya03df892022-01-27 13:16:55 +01001/* SPDX-License-Identifier: GPL-2.0 */
Nishanth Menonddf56bc2015-09-17 15:42:39 -05002/*
3 * (C) Copyright 2015
4 * Texas Instruments Incorporated - http://www.ti.com/
Nishanth Menonddf56bc2015-09-17 15:42:39 -05005 */
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/**
Keerthya03df892022-01-27 13:16:55 +010019 * 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 */
27struct 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 */
56enum 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 */
111struct 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 */
149struct 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 */
174struct 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 */
198struct 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 */
241struct 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 */
263struct 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
273struct rproc;
274
275typedef u32(*init_func_proto) (u32 core_id, struct rproc *cfg);
276
277struct l3_map {
278 u32 priv_addr;
279 u32 l3_addr;
280 u32 len;
281};
282
283struct 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 */
299enum 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 */
323struct 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
365struct 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
386extern struct rproc *rproc_cfg_arr[2];
387/**
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500388 * 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 */
396enum 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 Glasscaa4daa2020-12-03 16:55:18 -0700406 * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500407 * device.
408 *
409 */
410struct dm_rproc_uclass_pdata {
411 const char *name;
412 enum rproc_mem_type mem_type;
413 void *driver_plat_data;
414};
415
416/**
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200417 * struct dm_rproc_ops - Driver model remote proc operations.
418 *
419 * This defines the operations provided by remote proc driver.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500420 */
421struct dm_rproc_ops {
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200422 /**
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 Menonddf56bc2015-09-17 15:42:39 -0500432 int (*init)(struct udevice *dev);
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200433
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 Menonddf56bc2015-09-17 15:42:39 -0500444 int (*load)(struct udevice *dev, ulong addr, ulong size);
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200445
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 Menonddf56bc2015-09-17 15:42:39 -0500452 int (*start)(struct udevice *dev);
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200453
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 Menonddf56bc2015-09-17 15:42:39 -0500460 int (*stop)(struct udevice *dev);
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200461
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 Menonddf56bc2015-09-17 15:42:39 -0500468 int (*reset)(struct udevice *dev);
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200469
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 Menonddf56bc2015-09-17 15:42:39 -0500476 int (*is_running)(struct udevice *dev);
Fabien Dessenne31a839f2019-05-31 15:11:31 +0200477
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 Menonddf56bc2015-09-17 15:42:39 -0500484 int (*ping)(struct udevice *dev);
Fabien Dessenne163b7d72019-05-31 15:11:32 +0200485
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 Vutlac08eb932019-09-04 16:01:27 +0530494 * @size: Size of the memory region @da is pointing to
Fabien Dessenne163b7d72019-05-31 15:11:32 +0200495 * @return virtual address.
496 */
Lokesh Vutlac08eb932019-09-04 16:01:27 +0530497 void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size);
Keerthya03df892022-01-27 13:16:55 +0100498 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 Menonddf56bc2015-09-17 15:42:39 -0500504};
505
506/* Accessor */
507#define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops)
508
Suman Anna26557d12019-07-19 10:27:56 -0500509#if CONFIG_IS_ENABLED(REMOTEPROC)
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500510/**
511 * rproc_init() - Initialize all bound remote proc devices
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100512 * Return: 0 if all ok, else appropriate error value.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500513 */
514int rproc_init(void);
515
516/**
Lokesh Vutla81ae6e62018-08-27 15:57:50 +0530517 * rproc_dev_init() - Initialize a remote proc device based on id
518 * @id: id of the remote processor
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100519 * Return: 0 if all ok, else appropriate error value.
Lokesh Vutla81ae6e62018-08-27 15:57:50 +0530520 */
521int rproc_dev_init(int id);
522
523/**
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500524 * rproc_is_initialized() - check to see if remoteproc devices are initialized
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100525 * Return: true if all devices are initialized, false otherwise.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500526 */
527bool rproc_is_initialized(void);
528
529/**
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200530 * rproc_load() - load binary or elf to a remote processor
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500531 * @id: id of the remote processor
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200532 * @addr: address in memory where the image is located
533 * @size: size of the image
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100534 * Return: 0 if all ok, else appropriate error value.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500535 */
536int 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 Schuchardt185f8122022-01-19 18:05:50 +0100541 * Return: 0 if all ok, else appropriate error value.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500542 */
543int rproc_start(int id);
544
545/**
546 * rproc_stop() - Stop a remote processor
547 * @id: id of the remote processor
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100548 * Return: 0 if all ok, else appropriate error value.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500549 */
550int rproc_stop(int id);
551
552/**
553 * rproc_reset() - reset a remote processor
554 * @id: id of the remote processor
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100555 * Return: 0 if all ok, else appropriate error value.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500556 */
557int 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 Schuchardt185f8122022-01-19 18:05:50 +0100562 * Return: 0 if all ok, else appropriate error value.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500563 *
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 Menonddf56bc2015-09-17 15:42:39 -0500567 */
568int 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 Schuchardt185f8122022-01-19 18:05:50 +0100573 * Return: 0 if running, 1 if not running, -ve on error.
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500574 *
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 Menonddf56bc2015-09-17 15:42:39 -0500577 */
578int rproc_is_running(int id);
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200579
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 Schuchardt185f8122022-01-19 18:05:50 +0100588 * Return: 0 if the image looks good, else appropriate error value.
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200589 */
590int rproc_elf32_sanity_check(ulong addr, ulong size);
591
592/**
Lokesh Vutlae3c4d6f2019-09-04 16:01:29 +0530593 * 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 Schuchardt185f8122022-01-19 18:05:50 +0100600 * Return: 0 if the image looks good, else appropriate error value.
Lokesh Vutlae3c4d6f2019-09-04 16:01:29 +0530601 */
602int rproc_elf64_sanity_check(ulong addr, ulong size);
603
604/**
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200605 * rproc_elf32_load_image() - load an ELF32 image
606 * @dev: device loading the ELF32 image
607 * @addr: valid ELF32 image address
Lokesh Vutla14d963d2019-09-04 16:01:28 +0530608 * @size: size of the image
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100609 * Return: 0 if the image is successfully loaded, else appropriate error value.
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200610 */
Lokesh Vutla14d963d2019-09-04 16:01:28 +0530611int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size);
Lokesh Vutlae3c4d6f2019-09-04 16:01:29 +0530612
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 Schuchardt185f8122022-01-19 18:05:50 +0100618 * Return: 0 if the image is successfully loaded, else appropriate error value.
Lokesh Vutlae3c4d6f2019-09-04 16:01:29 +0530619 */
620int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
Lokesh Vutla856c0ad2019-09-04 16:01:30 +0530621
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 Schuchardt185f8122022-01-19 18:05:50 +0100629 * Return: 0 if the image is successfully loaded, else appropriate error value.
Lokesh Vutla856c0ad2019-09-04 16:01:30 +0530630 */
631int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong size);
Lokesh Vutla81e39fb2019-09-04 16:01:31 +0530632
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 */
641ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr);
Fabien Dessenneffcb8802019-10-30 14:38:28 +0100642
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 Schuchardt185f8122022-01-19 18:05:50 +0100657 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
Fabien Dessenneffcb8802019-10-30 14:38:28 +0100658 * is no resource table (which is optional), or another appropriate error value.
659 */
660int 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 Schuchardt185f8122022-01-19 18:05:50 +0100676 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
Fabien Dessenneffcb8802019-10-30 14:38:28 +0100677 * is no resource table (which is optional), or another appropriate error value.
678 */
679int 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 Schuchardt185f8122022-01-19 18:05:50 +0100695 * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
Fabien Dessenneffcb8802019-10-30 14:38:28 +0100696 * is no resource table (which is optional), or another appropriate error value.
697 */
698int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr,
699 ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
Keerthya03df892022-01-27 13:16:55 +0100700
701unsigned long rproc_parse_resource_table(struct udevice *dev,
702 struct rproc *cfg);
703
704struct resource_table *rproc_find_resource_table(struct udevice *dev,
705 unsigned int addr,
706 int *tablesz);
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500707#else
708static inline int rproc_init(void) { return -ENOSYS; }
Lokesh Vutla81ae6e62018-08-27 15:57:50 +0530709static inline int rproc_dev_init(int id) { return -ENOSYS; }
Nishanth Menonddf56bc2015-09-17 15:42:39 -0500710static inline bool rproc_is_initialized(void) { return false; }
711static inline int rproc_load(int id, ulong addr, ulong size) { return -ENOSYS; }
712static inline int rproc_start(int id) { return -ENOSYS; }
713static inline int rproc_stop(int id) { return -ENOSYS; }
714static inline int rproc_reset(int id) { return -ENOSYS; }
715static inline int rproc_ping(int id) { return -ENOSYS; }
716static inline int rproc_is_running(int id) { return -ENOSYS; }
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200717static inline int rproc_elf32_sanity_check(ulong addr,
718 ulong size) { return -ENOSYS; }
Lokesh Vutlae3c4d6f2019-09-04 16:01:29 +0530719static inline int rproc_elf64_sanity_check(ulong addr,
720 ulong size) { return -ENOSYS; }
Lokesh Vutla856c0ad2019-09-04 16:01:30 +0530721static inline int rproc_elf_sanity_check(ulong addr,
722 ulong size) { return -ENOSYS; }
Fabien Dessenne7a7c4cb2019-05-31 15:11:33 +0200723static inline int rproc_elf32_load_image(struct udevice *dev,
Lokesh Vutla14d963d2019-09-04 16:01:28 +0530724 unsigned long addr, ulong size)
725{ return -ENOSYS; }
Lokesh Vutlae3c4d6f2019-09-04 16:01:29 +0530726static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
727 ulong size)
728{ return -ENOSYS; }
Lokesh Vutla856c0ad2019-09-04 16:01:30 +0530729static inline int rproc_elf_load_image(struct udevice *dev, ulong addr,
730 ulong size)
731{ return -ENOSYS; }
Lokesh Vutla81e39fb2019-09-04 16:01:31 +0530732static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr)
733{ return 0; }
Fabien Dessenneffcb8802019-10-30 14:38:28 +0100734static 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; }
738static 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; }
742static 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 Menonddf56bc2015-09-17 15:42:39 -0500746#endif
747
748#endif /* _RPROC_H_ */