1 /*
2  * Remoteproc Framework
3  *
4  * Copyright(c) 2018 Xilinx Ltd.
5  * Copyright(c) 2011 Texas Instruments, Inc.
6  * Copyright(c) 2011 Google, Inc.
7  * All rights reserved.
8  *
9  * SPDX-License-Identifier: BSD-3-Clause
10  */
11 
12 #ifndef REMOTEPROC_H
13 #define REMOTEPROC_H
14 
15 #include <metal/io.h>
16 #include <metal/mutex.h>
17 #include <metal/compiler.h>
18 
19 #if defined __cplusplus
20 extern "C" {
21 #endif
22 
23 #define RSC_NOTIFY_ID_ANY 0xFFFFFFFFU
24 
25 #define RPROC_MAX_NAME_LEN 32
26 
27 /**
28  * @brief Resource table header
29  *
30  * A resource table is essentially a list of system resources required
31  * by the remote remoteproc. It may also include configuration entries.
32  * If needed, the remote remoteproc firmware should contain this table
33  * as a dedicated ".resource_table" ELF section.
34  *
35  * Some resource entries are mere announcements, where the host is informed
36  * of specific remoteproc configurations. Other entries require the host to
37  * do something (e.g. allocate a system resource). Sometimes a negotiation
38  * is expected, where the firmware requests a resource, and once allocated,
39  * the host should provide back its details (e.g. address of an allocated
40  * memory region).
41  *
42  * The header of the resource table, as expressed by this structure,
43  * contains a version number (should we need to change this format in the
44  * future), the number of available resource entries, and their offsets
45  * in the table.
46  *
47  * Immediately following this header are the resource entries themselves,
48  * each of which begins with a resource entry header.
49  */
50 METAL_PACKED_BEGIN
51 struct resource_table {
52 	/** Version number */
53 	uint32_t ver;
54 
55 	/** Number of resource entries */
56 	uint32_t num;
57 
58 	/** Reserved (must be zero) */
59 	uint32_t reserved[2];
60 
61 	/** Array of offsets pointing at the various resource entries */
62 	uint32_t offset[0];
63 } METAL_PACKED_END;
64 
65 /**
66  * @brief Resource table entry header
67  *
68  * Every resource entry begins with this firmware resource header providing
69  * its \ref type. The content of the entry itself will immediately follow
70  * this header, and it should be parsed according to the resource type.
71  */
72 METAL_PACKED_BEGIN
73 struct fw_rsc_hdr {
74 	/** Resource type matching the type field of the structure in \ref data */
75 	uint32_t type;
76 
77 	/** Resource data */
78 	uint8_t data[0];
79 } METAL_PACKED_END;
80 
81 /**
82  * @brief Types of resource entries
83  *
84  * For more details regarding a specific resource type, please see its
85  * dedicated structure below.
86  *
87  * Please note that these values are used as indices to the rproc_handle_rsc
88  * lookup table, so please keep them sane. Moreover, \ref RSC_LAST is used to
89  * check the validity of an index before the lookup table is accessed, so
90  * please update it as needed.
91  */
92 enum fw_resource_type {
93 	/** carveout resource
94 	 *
95 	 *  Request for allocation of a physically contiguous memory region.
96 	 */
97 	RSC_CARVEOUT = 0,
98 	/** device memory resource
99 	 *
100 	 *  Request to iommu_map a memory-based peripheral.
101 	 */
102 	RSC_DEVMEM = 1,
103 	/** trace resource
104 	 *
105 	 *  Announces the availability of a trace buffer into which the remote remoteproc will be
106 	 *  writing logs.
107 	 */
108 	RSC_TRACE = 2,
109 	/** virtio device resource
110 	 *
111 	 *  Declare support for a virtio device, and serve as its virtio header.
112 	 */
113 	RSC_VDEV = 3,
114 	/** end of the generic resources */
115 	RSC_LAST = 4,
116 	/** Start of the vendor specific resource types range */
117 	RSC_VENDOR_START = 128,
118 	/** End of the vendor specific resource types range */
119 	RSC_VENDOR_END = 512,
120 };
121 
122 #define FW_RSC_U64_ADDR_ANY 0xFFFFFFFFFFFFFFFFUL
123 #define FW_RSC_U32_ADDR_ANY 0xFFFFFFFFUL
124 
125 /**
126  * @brief Resource table physically contiguous memory request entry
127  *
128  * This resource entry requests the host to allocate a physically contiguous
129  * memory region.
130  *
131  * These request entries should precede other firmware resource entries,
132  * as other entries might request placing other data objects inside
133  * these memory regions (e.g. data/code segments, trace resource entries, ...).
134  *
135  * Allocating memory this way helps utilizing the reserved physical memory
136  * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries
137  * needed to map it (in case rproc is using an IOMMU). Reducing the TLB
138  * pressure is important; it may have a substantial impact on performance.
139  *
140  * If the firmware is compiled with static addresses, then \ref da should specify
141  * the expected device address of this memory region. If \ref da is set to
142  * FW_RSC_ADDR_ANY, then the host will dynamically allocate it, and then
143  * overwrite \ref da with the dynamically allocated address.
144  *
145  * We will always use \ref da to negotiate the device addresses, even if it
146  * isn't using an IOMMU. In that case, though, it will obviously contain
147  * physical addresses.
148  *
149  * Some remote remoteprocs need to know the allocated physical address
150  * even if they do use an IOMMU. This is needed, e.g., if they control
151  * hardware accelerators which access the physical memory directly (this
152  * is the case with OMAP4 for instance). In that case, the host will
153  * overwrite \ref pa with the dynamically allocated physical address.
154  * Generally we don't want to expose physical addresses if we don't have to
155  * (remote remoteprocs are generally _not_ trusted), so we might want to
156  * change this to happen _only_ when explicitly required by the hardware.
157  */
158 METAL_PACKED_BEGIN
159 struct fw_rsc_carveout {
160 	/** Resource carveout has type 0 */
161 	uint32_t type;
162 
163 	/** Device address */
164 	uint32_t da;
165 
166 	/** Physical address */
167 	uint32_t pa;
168 
169 	/** Length in bytes */
170 	uint32_t len;
171 
172 	/** IOMMU protection flags */
173 	uint32_t flags;
174 
175 	/** Reserved (must be zero) */
176 	uint32_t reserved;
177 
178 	/** Optional human-readable name of the requested memory region used for debugging */
179 	uint8_t name[RPROC_MAX_NAME_LEN];
180 } METAL_PACKED_END;
181 
182 /**
183  * @brief Resource table IOMMU mapping request entry
184  *
185  * This resource entry requests the host to IOMMU map a physically contiguous
186  * memory region. This is needed in case the remote remoteproc requires
187  * access to certain memory-based peripherals; _never_ use it to access
188  * regular memory.
189  *
190  * This is obviously only needed if the remote remoteproc is accessing memory
191  * via an IOMMU.
192  *
193  * Note: at this point we just "trust" those devmem entries to contain valid
194  * physical addresses, but this isn't safe and will be changed: eventually we
195  * want remoteproc implementations to provide us ranges of physical addresses
196  * the firmware is allowed to request, and not allow firmwares to request
197  * access to physical addresses that are outside those ranges.
198  */
199 METAL_PACKED_BEGIN
200 struct fw_rsc_devmem {
201 	/** IOMMU mapping request has type 1 */
202 	uint32_t type;
203 
204 	/** Device address */
205 	uint32_t da;
206 
207 	/** Physical address to map */
208 	uint32_t pa;
209 
210 	/** Length of the mapping in bytes */
211 	uint32_t len;
212 
213 	/** IOMMU protection flags */
214 	uint32_t flags;
215 
216 	/** Reserved (must be zero) */
217 	uint32_t reserved;
218 
219 	/** Optional human-readable name of the requested memory region used for debugging */
220 	uint8_t name[RPROC_MAX_NAME_LEN];
221 } METAL_PACKED_END;
222 
223 /**
224  * @brief Resource table trace buffer declaration entry
225  *
226  * This resource entry provides the host information about a trace buffer
227  * into which the remote remoteproc will write log messages.
228  *
229  * After booting the remote remoteproc, the trace buffers are exposed to the
230  * user via debugfs entries (called trace0, trace1, etc..).
231  */
232 METAL_PACKED_BEGIN
233 struct fw_rsc_trace {
234 	/** Trace buffer entry has type 2 */
235 	uint32_t type;
236 
237 	/** Device address of the buffer */
238 	uint32_t da;
239 
240 	/** Length of the buffer in bytes */
241 	uint32_t len;
242 
243 	/** Reserved (must be zero) */
244 	uint32_t reserved;
245 
246 	/** Optional human-readable name of the requested memory region used for debugging */
247 	uint8_t name[RPROC_MAX_NAME_LEN];
248 } METAL_PACKED_END;
249 
250 /**
251  * @brief Resource table vring descriptor entry
252  *
253  * This descriptor is not a resource entry by itself; it is part of the
254  * \ref fw_rsc_vdev resource type.
255  */
256 METAL_PACKED_BEGIN
257 struct fw_rsc_vdev_vring {
258 	/**
259 	 * The device address where the remoteproc is expecting the vring, or
260 	 * FW_RSC_U32_ADDR_ANY/FW_RSC_U64_ADDR_ANY to indicate that dynamic
261 	 * allocation of the vring's device address is supported
262 	 */
263 	uint32_t da;
264 
265 	/** The alignment between the consumer and producer parts of the vring */
266 	uint32_t align;
267 
268 	/** Number of buffers supported by this vring (must be power of two) */
269 	uint32_t num;
270 
271 	/**
272 	 * A unique rproc-wide notify index for this vring. This notify index is
273 	 * used when kicking a remote remoteproc, to let it know that this vring
274 	 * is triggered
275 	 */
276 	uint32_t notifyid;
277 
278 	/** Reserved (must be zero) */
279 	uint32_t reserved;
280 } METAL_PACKED_END;
281 
282 /**
283  * @brief Resource table virtio device entry
284  *
285  * This resource is a virtio device header: it provides information about
286  * the vdev, and is then used by the host and its peer remote remoteprocs
287  * to negotiate and share certain virtio properties.
288  *
289  * By providing this resource entry, the firmware essentially asks remoteproc
290  * to statically allocate a vdev upon registration of the rproc (dynamic vdev
291  * allocation is not yet supported).
292  *
293  * Note: unlike virtualization systems, the term 'host' here means
294  * the Linux side which is running remoteproc to control the remote
295  * remoteprocs. We use the name 'gfeatures' to comply with virtio's terms,
296  * though there isn't really any virtualized guest OS here: it's the host
297  * which is responsible for negotiating the final features.
298  *
299  * Note: immediately following this structure is the virtio config space for
300  * this vdev (which is specific to the vdev; for more info, read the virtio
301  * spec).
302  */
303 METAL_PACKED_BEGIN
304 struct fw_rsc_vdev {
305 	/** Virtio device header has type 3 */
306 	uint32_t type;
307 
308 	/** Virtio device id (as in virtio_ids.h) */
309 	uint32_t id;
310 
311 	/**
312 	 * A unique rproc-wide notify index for this vdev. This notify index is
313 	 * used when kicking a remote remoteproc, to let it know that the
314 	 * status/features of this vdev have changes.
315 	 */
316 	uint32_t notifyid;
317 
318 	/** The virtio device features supported by the firmware */
319 	uint32_t dfeatures;
320 
321 	/**
322 	 * A place holder used by the host to write back the negotiated features
323 	 * that are supported by both sides
324 	 */
325 	uint32_t gfeatures;
326 
327 	/**
328 	 * The size of the virtio config space of this vdev. The config space lies
329 	 * in the resource table immediate after this vdev header
330 	 */
331 	uint32_t config_len;
332 
333 	/** A place holder where the host will indicate its virtio progress */
334 	uint8_t status;
335 
336 	/** Number of vrings described in this vdev header */
337 	uint8_t num_of_vrings;
338 
339 	/** Reserved (must be zero) */
340 	uint8_t reserved[2];
341 
342 	/** An array of \ref num_of_vrings entries of \ref fw_rsc_vdev_vring */
343 	struct fw_rsc_vdev_vring vring[0];
344 } METAL_PACKED_END;
345 
346 /**
347  * @brief Resource table remote processor vendor specific entry
348  *
349  * This resource entry tells the host the vendor specific resource
350  * required by the remote.
351  *
352  * These request entries should precede other shared resource entries
353  * such as vdevs, vrings.
354  */
355 METAL_PACKED_BEGIN
356 struct fw_rsc_vendor {
357 	/** Vendor specific resource type can be values 128-512 */
358 	uint32_t type;
359 
360 	/** Length of the resource */
361 	uint32_t len;
362 } METAL_PACKED_END;
363 
364 struct loader_ops;
365 struct image_store_ops;
366 struct remoteproc_ops;
367 
368 /** @brief Memory used by the remote processor */
369 struct remoteproc_mem {
370 	/** Device memory */
371 	metal_phys_addr_t da;
372 
373 	/** Physical memory */
374 	metal_phys_addr_t pa;
375 
376 	/** Size of the memory */
377 	size_t size;
378 
379 	/** Optional human-readable name of the memory region */
380 	char name[RPROC_MAX_NAME_LEN];
381 
382 	/** Pointer to the I/O region */
383 	struct metal_io_region *io;
384 
385 	/** List node */
386 	struct metal_list node;
387 };
388 
389 /**
390  * @brief A remote processor instance
391  *
392  * This structure is maintained by the remoteproc to represent the remote
393  * processor instance. This structure acts as a prime parameter to use
394  * the remoteproc APIs.
395  */
396 struct remoteproc {
397 	/** Mutex lock */
398 	metal_mutex_t lock;
399 
400 	/** Pointer to the resource table */
401 	void *rsc_table;
402 
403 	/** Length of the resource table */
404 	size_t rsc_len;
405 
406 	/** Metal I/O region of the resource table */
407 	struct metal_io_region *rsc_io;
408 
409 	/** Remoteproc memories */
410 	struct metal_list mems;
411 
412 	/** Remoteproc virtio devices */
413 	struct metal_list vdevs;
414 
415 	/** Bitmap for notify IDs for remoteproc subdevices */
416 	unsigned long bitmap;
417 
418 	/** Remoteproc operations */
419 	const struct remoteproc_ops *ops;
420 
421 	/** Boot address */
422 	metal_phys_addr_t bootaddr;
423 
424 	/** Executable loader */
425 	const struct loader_ops *loader;
426 
427 	/** Remote processor state */
428 	unsigned int state;
429 
430 	/** Private data */
431 	void *priv;
432 };
433 
434 /**
435  * @brief Remoteproc operations to manage a remoteproc instance
436  *
437  * Remoteproc operations need to be implemented by each remoteproc driver
438  */
439 struct remoteproc_ops {
440 	/** Initialize the remoteproc instance */
441 	struct remoteproc *(*init)(struct remoteproc *rproc,
442 				   const struct remoteproc_ops *ops, void *arg);
443 
444 	/** Remove the remoteproc instance */
445 	void (*remove)(struct remoteproc *rproc);
446 
447 	/** Memory map the memory with physical address or destination address as input */
448 	void *(*mmap)(struct remoteproc *rproc,
449 		      metal_phys_addr_t *pa, metal_phys_addr_t *da,
450 		      size_t size, unsigned int attribute,
451 		      struct metal_io_region **io);
452 
453 	/** Handle the vendor specific resource */
454 	int (*handle_rsc)(struct remoteproc *rproc, void *rsc, size_t len);
455 
456 	/** Configure the remoteproc to make it ready to load and run the executable */
457 	int (*config)(struct remoteproc *rproc, void *data);
458 
459 	/** Kick the remoteproc to run the application */
460 	int (*start)(struct remoteproc *rproc);
461 
462 	/**
463 	 * Stop the remoteproc from running the application, the resource such as
464 	 * memory may not be off
465 	 */
466 	int (*stop)(struct remoteproc *rproc);
467 
468 	/** Shutdown the remoteproc and release its resources */
469 	int (*shutdown)(struct remoteproc *rproc);
470 
471 	/** Notify the remote */
472 	int (*notify)(struct remoteproc *rproc, uint32_t id);
473 
474 	/**
475 	 * @brief Get remoteproc memory I/O region by either name, virtual
476 	 * address, physical address or device address.
477 	 *
478 	 * @param rproc		Pointer to remoteproc instance
479 	 * @param name		Memory name
480 	 * @param pa		Physical address
481 	 * @param da		Device address
482 	 * @param va		Virtual address
483 	 * @param size		Memory size
484 	 * @param buf		Pointer to remoteproc_mem struct object to store result
485 	 *
486 	 * @return remoteproc memory pointed by buf if success, otherwise NULL
487 	 */
488 	struct remoteproc_mem *(*get_mem)(struct remoteproc *rproc,
489 					  const char *name,
490 					  metal_phys_addr_t pa,
491 					  metal_phys_addr_t da,
492 					  void *va, size_t size,
493 					  struct remoteproc_mem *buf);
494 };
495 
496 /* Remoteproc error codes */
497 #define RPROC_EBASE	0
498 #define RPROC_ENOMEM	(RPROC_EBASE + 1)
499 #define RPROC_EINVAL	(RPROC_EBASE + 2)
500 #define RPROC_ENODEV	(RPROC_EBASE + 3)
501 #define RPROC_EAGAIN	(RPROC_EBASE + 4)
502 #define RPROC_ERR_RSC_TAB_TRUNC (RPROC_EBASE + 5)
503 #define RPROC_ERR_RSC_TAB_VER   (RPROC_EBASE + 6)
504 #define RPROC_ERR_RSC_TAB_RSVD  (RPROC_EBASE + 7)
505 #define RPROC_ERR_RSC_TAB_VDEV_NRINGS (RPROC_EBASE + 9)
506 #define RPROC_ERR_RSC_TAB_NP          (RPROC_EBASE + 10)
507 #define RPROC_ERR_RSC_TAB_NS          (RPROC_EBASE + 11)
508 #define RPROC_ERR_LOADER_STATE (RPROC_EBASE + 12)
509 #define RPROC_EMAX	(RPROC_EBASE + 16)
510 #define RPROC_EPTR	(void *)(-1)
511 #define RPROC_EOF	(void *)(-1)
512 
RPROC_PTR_ERR(const void * ptr)513 static inline long RPROC_PTR_ERR(const void *ptr)
514 {
515 	return (long)ptr;
516 }
517 
RPROC_IS_ERR(const void * ptr)518 static inline int RPROC_IS_ERR(const void *ptr)
519 {
520 	if ((unsigned long)ptr >= (unsigned long)(-RPROC_EMAX))
521 		return 1;
522 	else
523 		return 0;
524 }
525 
RPROC_ERR_PTR(long error)526 static inline void *RPROC_ERR_PTR(long error)
527 {
528 	return (void *)error;
529 }
530 
531 /**
532  * @brief Remote processor states
533  */
534 enum remoteproc_state {
535 	/** Remote is offline */
536 	RPROC_OFFLINE		= 0,
537 	/** Remote is configured */
538 	RPROC_CONFIGURED	= 1,
539 	/** Remote is ready to start */
540 	RPROC_READY		= 2,
541 	/** Remote is up and running */
542 	RPROC_RUNNING		= 3,
543 	/** Remote is suspended */
544 	RPROC_SUSPENDED		= 4,
545 	/** Remote is has error; need to recover */
546 	RPROC_ERROR		= 5,
547 	/** Remote is stopped */
548 	RPROC_STOPPED		= 6,
549 	/** Just keep this one at the end */
550 	RPROC_LAST		= 7,
551 };
552 
553 /**
554  * @brief Initializes remoteproc resource.
555  *
556  * @param rproc	Pointer to remoteproc instance
557  * @param ops	Pointer to remoteproc operations
558  * @param priv	Pointer to private data
559  *
560  * @return Created remoteproc pointer
561  */
562 struct remoteproc *remoteproc_init(struct remoteproc *rproc,
563 				   const struct remoteproc_ops *ops,
564 				   void *priv);
565 
566 /**
567  * @brief Remove remoteproc resource
568  *
569  * @param rproc	Pointer to remoteproc instance
570  *
571  * @return 0 for success, negative value for failure
572  */
573 int remoteproc_remove(struct remoteproc *rproc);
574 
575 /**
576  * @brief Initialize remoteproc memory
577  *
578  * @param mem	Pointer to remoteproc memory
579  * @param name	Memory name (max string size \ref RPROC_MAX_NAME_LEN)
580  * @param pa	Physical address
581  * @param da	Device address
582  * @param size	Memory size
583  * @param io	Pointer to the I/O region
584  */
585 void remoteproc_init_mem(struct remoteproc_mem *mem, const char *name,
586 			 metal_phys_addr_t pa, metal_phys_addr_t da,
587 			 size_t size, struct metal_io_region *io);
588 
589 /**
590  * @brief Add remoteproc memory
591  *
592  * @param rproc	Pointer to remoteproc
593  * @param mem	Pointer to remoteproc memory
594  */
595 void remoteproc_add_mem(struct remoteproc *rproc, struct remoteproc_mem *mem);
596 
597 /**
598  * @brief Get remoteproc memory I/O region with name
599  *
600  * @param rproc	Pointer to the remote processor
601  * @param name	Name of the shared memory
602  *
603  * @return Metal I/O region pointer, NULL for failure
604  */
605 struct metal_io_region *
606 remoteproc_get_io_with_name(struct remoteproc *rproc,
607 			    const char *name);
608 
609 /**
610  * @brief Get remoteproc memory I/O region with physical address
611  *
612  * @param rproc	Pointer to the remote processor
613  * @param pa	Physical address
614  *
615  * @return Metal I/O region pointer, NULL for failure
616  */
617 struct metal_io_region *
618 remoteproc_get_io_with_pa(struct remoteproc *rproc,
619 			  metal_phys_addr_t pa);
620 
621 /**
622  * @brief Get remoteproc memory I/O region with device address
623  *
624  * @param rproc		Pointer to the remote processor
625  * @param da		Device address
626  * @param offset	I/O region offset of the device address
627  *
628  * @return Metal I/O region pointer, NULL for failure
629  */
630 struct metal_io_region *
631 remoteproc_get_io_with_da(struct remoteproc *rproc,
632 			  metal_phys_addr_t da,
633 			  unsigned long *offset);
634 
635 /**
636  * @brief Get remoteproc memory I/O region with virtual address
637  *
638  * @param rproc	Pointer to the remote processor
639  * @param va	Virtual address
640  *
641  * @return Metal I/O region pointer, NULL for failure
642  */
643 struct metal_io_region *
644 remoteproc_get_io_with_va(struct remoteproc *rproc,
645 			  void *va);
646 
647 /**
648  * @brief Remoteproc mmap memory
649  *
650  * @param rproc		Pointer to the remote processor
651  * @param pa		Physical address pointer
652  * @param da		Device address pointer
653  * @param size		Size of the memory
654  * @param attribute	Memory attribute
655  * @param io		Pointer to the I/O region
656  *
657  * @return Pointer to the memory
658  */
659 void *remoteproc_mmap(struct remoteproc *rproc,
660 		      metal_phys_addr_t *pa, metal_phys_addr_t *da,
661 		      size_t size, unsigned int attribute,
662 		      struct metal_io_region **io);
663 
664 /**
665  * @brief Parse and set resource table of remoteproc
666  *
667  * @param rproc		Pointer to remoteproc instance
668  * @param rsc_table	Pointer to resource table
669  * @param rsc_size	Resource table size
670  *
671  * @return 0 for success and negative value for errors
672  */
673 int remoteproc_set_rsc_table(struct remoteproc *rproc,
674 			     struct resource_table *rsc_table,
675 			     size_t rsc_size);
676 
677 /**
678  * @brief This function configures the remote processor to get it
679  * ready to load and run executable.
680  *
681  * @param rproc	Pointer to remoteproc instance to start
682  * @param data	Configuration data
683  *
684  * @return 0 for success and negative value for errors
685  */
686 int remoteproc_config(struct remoteproc *rproc, void *data);
687 
688 /**
689  * @brief This function starts the remote processor.
690  * It assumes the firmware is already loaded.
691  *
692  * @param rproc	Pointer to remoteproc instance to start
693  *
694  * @return 0 for success and negative value for errors
695  */
696 int remoteproc_start(struct remoteproc *rproc);
697 
698 /**
699  * @brief This function stops the remote processor but it
700  * will not release its resource.
701  *
702  * @param rproc	Pointer to remoteproc instance
703  *
704  * @return 0 for success and negative value for errors
705  */
706 int remoteproc_stop(struct remoteproc *rproc);
707 
708 /**
709  * @brief This function shuts down the remote processor and
710  * releases its resources.
711  *
712  * @param rproc	Pointer to remoteproc instance
713  *
714  * @return 0 for success and negative value for errors
715  */
716 int remoteproc_shutdown(struct remoteproc *rproc);
717 
718 /**
719  * @brief Loads the executable
720  *
721  * Expects the user application defines how to open the executable file and how
722  * to get data from the executable file and how to load data to the target
723  * memory.
724  *
725  * @param rproc		Pointer to the remoteproc instance
726  * @param path		Optional path to the image file
727  * @param store		Pointer to user defined image store argument
728  * @param store_ops	Pointer to image store operations
729  * @param img_info	Pointer to memory which stores image information used
730  *			by remoteproc loader
731  *
732  * @return 0 for success and negative value for failure
733  */
734 int remoteproc_load(struct remoteproc *rproc, const char *path,
735 		    void *store, const struct image_store_ops *store_ops,
736 		    void **img_info);
737 
738 /**
739  * @brief Loads the executable
740  *
741  * Expects the caller has loaded image data to local
742  * memory and passed to the this function. If the function needs more
743  * image data it will return the next expected image data offset and
744  * the next expected image data length. If the function requires the
745  * caller to download image data to the target memory, it will also
746  * return the target physical address besides the offset and length.
747  * This function can be used to load firmware in stream mode. In this
748  * mode, you cannot do seek to the executable file. If the executable
749  * is ELF, it cannot get the resource table section before it loads
750  * the full ELF file. Furthermore, application usually don't store
751  * the data which is loaded to local memory in streaming mode, and
752  * thus, in this mode, it will load the binary to the target memory
753  * before it gets the resource table. And thus, when calling this function
754  * don't put the target executable memory in the resource table, as
755  * this function will parse the resource table after it loads the binary
756  * to target memory.
757  *
758  * @param rproc		Pointer to the remoteproc instance
759  * @param img_data	Pointer to image data for remoteproc loader to parse
760  * @param offset	Image data offset to the beginning of the image file
761  * @param len		Image data length
762  * @param img_info	Pointer to memory which stores image information used
763  *			by remoteproc loader
764  * @param pa		Pointer to the target memory physical address. If the
765  *			next expected data doesn't need to load to the target
766  *			memory, the function will set it to ANY.
767  * @param io		Pointer to the io region. If the next expected data
768  *			doesn't need to load to the target memory, the function
769  *			will set it to NULL.
770  * @param noffset	Pointer to the next image data offset to the beginning
771  *			of the image file needs to load to local or to the
772  *			target memory.
773  * @param nlen		Pointer to the next image data length needs to load to
774  *			local or to the target memory.
775  * @param nmlen		Pointer to the memory size. It is only used when the
776  *			next expected data is going to be loaded to the target
777  *			memory. E.g. in ELF, it is possible that loadable
778  *			segment in memory is larger that the segment data in
779  *			the ELF file. In this case, application will need to
780  *			pad the rest of the memory with padding.
781  * @param padding	Pointer to the padding value. It is only used when the
782  *			next expected data is going to be loaded to the target
783  *			memory and the target memory size is larger than the
784  *			segment data in the executable file.
785  *
786  * @return 0 for success and negative value for failure
787  */
788 int remoteproc_load_noblock(struct remoteproc *rproc,
789 			    const void *img_data, size_t offset, size_t len,
790 			    void **img_info,
791 			    metal_phys_addr_t *pa, struct metal_io_region **io,
792 			    size_t *noffset, size_t *nlen,
793 			    size_t *nmlen, unsigned char *padding);
794 
795 /**
796  * @brief Allocate notifyid for resource
797  *
798  * @param rproc	Pointer to the remoteproc instance
799  * @param start	Start of the id range
800  * @param end	End of the id range
801  *
802  * @return Allocated notify id
803  */
804 unsigned int remoteproc_allocate_id(struct remoteproc *rproc,
805 				    unsigned int start,
806 				    unsigned int end);
807 
808 /**
809  * @brief Create virtio device, it returns pointer to the created virtio
810  * device.
811  *
812  * @param rproc		Pointer to the remoteproc instance
813  * @param vdev_id	virtio device ID
814  * @param role		virtio device role
815  * @param rst_cb	virtio device reset callback
816  *
817  * @return Pointer to the created virtio device, NULL for failure.
818  */
819 struct virtio_device *
820 remoteproc_create_virtio(struct remoteproc *rproc,
821 			 int vdev_id, unsigned int role,
822 			 void (*rst_cb)(struct virtio_device *vdev));
823 
824 /**
825  * @brief Remove virtio device
826  *
827  * @param rproc	Pointer to the remoteproc instance
828  * @param vdev	Pointer to the virtio device
829  */
830 void remoteproc_remove_virtio(struct remoteproc *rproc,
831 			      struct virtio_device *vdev);
832 
833 /**
834  * @brief remoteproc is got notified, it will check its subdevices
835  * for the notification
836  *
837  * @param rproc		Pointer to the remoteproc instance
838  * @param notifyid	Notification id
839  *
840  * @return 0 for succeed, negative value for failure
841  */
842 int remoteproc_get_notification(struct remoteproc *rproc,
843 				uint32_t notifyid);
844 #if defined __cplusplus
845 }
846 #endif
847 
848 #endif /* REMOTEPROC_H_ */
849