OpenAMP Library  latest
Loading...
Searching...
No Matches
remoteproc.h
Go to the documentation of this file.
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
20extern "C" {
21#endif
22
23#define RSC_NOTIFY_ID_ANY 0xFFFFFFFFU
24
25#define RPROC_MAX_NAME_LEN 32
26
50METAL_PACKED_BEGIN
53 uint32_t ver;
54
56 uint32_t num;
57
59 uint32_t reserved[2];
60
62 uint32_t offset[0];
64
72METAL_PACKED_BEGIN
73struct fw_rsc_hdr {
75 uint32_t type;
76
78 uint8_t data[0];
80
121
122#define FW_RSC_U64_ADDR_ANY 0xFFFFFFFFFFFFFFFFUL
123#define FW_RSC_U32_ADDR_ANY 0xFFFFFFFFUL
124
158METAL_PACKED_BEGIN
161 uint32_t type;
162
164 uint32_t da;
165
167 uint32_t pa;
168
170 uint32_t len;
171
173 uint32_t flags;
174
176 uint32_t reserved;
177
181
199METAL_PACKED_BEGIN
202 uint32_t type;
203
205 uint32_t da;
206
208 uint32_t pa;
209
211 uint32_t len;
212
214 uint32_t flags;
215
217 uint32_t reserved;
218
222
232METAL_PACKED_BEGIN
235 uint32_t type;
236
238 uint32_t da;
239
241 uint32_t len;
242
244 uint32_t reserved;
245
249
256METAL_PACKED_BEGIN
263 uint32_t da;
264
266 uint32_t align;
267
269 uint32_t num;
270
276 uint32_t notifyid;
277
279 uint32_t reserved;
281
303METAL_PACKED_BEGIN
306 uint32_t type;
307
309 uint32_t id;
310
316 uint32_t notifyid;
317
319 uint32_t dfeatures;
320
325 uint32_t gfeatures;
326
331 uint32_t config_len;
332
334 uint8_t status;
335
338
340 uint8_t reserved[2];
341
345
355METAL_PACKED_BEGIN
358 uint32_t type;
359
361 uint32_t len;
363
364struct loader_ops;
365struct image_store_ops;
366struct remoteproc_ops;
367
371 metal_phys_addr_t da;
372
374 metal_phys_addr_t pa;
375
377 size_t size;
378
381
383 struct metal_io_region *io;
384
386 struct metal_list node;
387};
388
398 metal_mutex_t lock;
399
402
404 size_t rsc_len;
405
407 struct metal_io_region *rsc_io;
408
410 struct metal_list mems;
411
413 struct metal_list vdevs;
414
416 unsigned long bitmap;
417
419 const struct remoteproc_ops *ops;
420
422 metal_phys_addr_t bootaddr;
423
425 const struct loader_ops *loader;
426
428 unsigned int state;
429
431 void *priv;
432};
433
441 struct remoteproc *(*init)(struct remoteproc *rproc,
442 const struct remoteproc_ops *ops, void *arg);
443
445 void (*remove)(struct remoteproc *rproc);
446
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
454 int (*handle_rsc)(struct remoteproc *rproc, void *rsc, size_t len);
455
457 int (*config)(struct remoteproc *rproc, void *data);
458
460 int (*start)(struct remoteproc *rproc);
461
466 int (*stop)(struct remoteproc *rproc);
467
469 int (*shutdown)(struct remoteproc *rproc);
470
472 int (*notify)(struct remoteproc *rproc, uint32_t id);
473
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
513static inline long RPROC_PTR_ERR(const void *ptr)
514{
515 return (long)ptr;
516}
517
518static 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
526static inline void *RPROC_ERR_PTR(long error)
527{
528 return (void *)error;
529}
530
552
562struct remoteproc *remoteproc_init(struct remoteproc *rproc,
563 const struct remoteproc_ops *ops,
564 void *priv);
565
573int remoteproc_remove(struct remoteproc *rproc);
574
585void 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
595void remoteproc_add_mem(struct remoteproc *rproc, struct remoteproc_mem *mem);
596
605struct metal_io_region *
607 const char *name);
608
617struct metal_io_region *
619 metal_phys_addr_t pa);
620
630struct metal_io_region *
632 metal_phys_addr_t da,
633 unsigned long *offset);
634
643struct metal_io_region *
645 void *va);
646
659void *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
673int remoteproc_set_rsc_table(struct remoteproc *rproc,
674 struct resource_table *rsc_table,
675 size_t rsc_size);
676
686int remoteproc_config(struct remoteproc *rproc, void *data);
687
696int remoteproc_start(struct remoteproc *rproc);
697
706int remoteproc_stop(struct remoteproc *rproc);
707
716int remoteproc_shutdown(struct remoteproc *rproc);
717
734int remoteproc_load(struct remoteproc *rproc, const char *path,
735 void *store, const struct image_store_ops *store_ops,
736 void **img_info);
737
788int 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
804unsigned int remoteproc_allocate_id(struct remoteproc *rproc,
805 unsigned int start,
806 unsigned int end);
807
819struct virtio_device *
821 int vdev_id, unsigned int role,
822 void (*rst_cb)(struct virtio_device *vdev));
823
830void remoteproc_remove_virtio(struct remoteproc *rproc,
831 struct virtio_device *vdev);
832
843 uint32_t notifyid);
844#if defined __cplusplus
845}
846#endif
847
848#endif /* REMOTEPROC_H_ */
static long RPROC_PTR_ERR(const void *ptr)
Definition remoteproc.h:513
int remoteproc_remove(struct remoteproc *rproc)
Remove remoteproc resource.
Definition remoteproc.c:193
static void * RPROC_ERR_PTR(long error)
Definition remoteproc.h:526
#define RPROC_MAX_NAME_LEN
Definition remoteproc.h:25
void remoteproc_remove_virtio(struct remoteproc *rproc, struct virtio_device *vdev)
Remove virtio device.
Definition remoteproc.c:1034
struct metal_io_region * remoteproc_get_io_with_name(struct remoteproc *rproc, const char *name)
Get remoteproc memory I/O region with name.
Definition remoteproc.c:328
int remoteproc_load(struct remoteproc *rproc, const char *path, void *store, const struct image_store_ops *store_ops, void **img_info)
Loads the executable.
Definition remoteproc.c:444
int remoteproc_config(struct remoteproc *rproc, void *data)
This function configures the remote processor to get it ready to load and run executable.
Definition remoteproc.c:211
struct metal_io_region * remoteproc_get_io_with_pa(struct remoteproc *rproc, metal_phys_addr_t pa)
Get remoteproc memory I/O region with physical address.
Definition remoteproc.c:346
unsigned int remoteproc_allocate_id(struct remoteproc *rproc, unsigned int start, unsigned int end)
Allocate notifyid for resource.
Definition remoteproc.c:906
struct remoteproc * remoteproc_init(struct remoteproc *rproc, const struct remoteproc_ops *ops, void *priv)
Initializes remoteproc resource.
Definition remoteproc.c:175
fw_resource_type
Types of resource entries.
Definition remoteproc.h:92
@ RSC_VENDOR_END
End of the vendor specific resource types range.
Definition remoteproc.h:119
@ RSC_VENDOR_START
Start of the vendor specific resource types range.
Definition remoteproc.h:117
@ RSC_DEVMEM
device memory resource
Definition remoteproc.h:102
@ RSC_LAST
end of the generic resources
Definition remoteproc.h:115
@ RSC_CARVEOUT
carveout resource
Definition remoteproc.h:97
@ RSC_TRACE
trace resource
Definition remoteproc.h:108
@ RSC_VDEV
virtio device resource
Definition remoteproc.h:113
int remoteproc_set_rsc_table(struct remoteproc *rproc, struct resource_table *rsc_table, size_t rsc_size)
Parse and set resource table of remoteproc.
Definition remoteproc.c:153
int remoteproc_shutdown(struct remoteproc *rproc)
This function shuts down the remote processor and releases its resources.
Definition remoteproc.c:278
int remoteproc_load_noblock(struct remoteproc *rproc, const void *img_data, size_t offset, size_t len, void **img_info, metal_phys_addr_t *pa, struct metal_io_region **io, size_t *noffset, size_t *nlen, size_t *nmlen, unsigned char *padding)
Loads the executable.
Definition remoteproc.c:715
METAL_PACKED_BEGIN struct resource_table METAL_PACKED_END
struct metal_io_region * remoteproc_get_io_with_va(struct remoteproc *rproc, void *va)
Get remoteproc memory I/O region with virtual address.
Definition remoteproc.c:388
void remoteproc_add_mem(struct remoteproc *rproc, struct remoteproc_mem *mem)
Add remoteproc memory.
Definition remoteproc.c:320
static int RPROC_IS_ERR(const void *ptr)
Definition remoteproc.h:518
struct virtio_device * remoteproc_create_virtio(struct remoteproc *rproc, int vdev_id, unsigned int role, void(*rst_cb)(struct virtio_device *vdev))
Create virtio device, it returns pointer to the created virtio device.
Definition remoteproc.c:939
int remoteproc_stop(struct remoteproc *rproc)
This function stops the remote processor but it will not release its resource.
Definition remoteproc.c:256
void remoteproc_init_mem(struct remoteproc_mem *mem, const char *name, metal_phys_addr_t pa, metal_phys_addr_t da, size_t size, struct metal_io_region *io)
Initialize remoteproc memory.
Definition remoteproc.c:304
#define RPROC_EMAX
Definition remoteproc.h:509
remoteproc_state
Remote processor states.
Definition remoteproc.h:534
@ RPROC_STOPPED
Remote is stopped.
Definition remoteproc.h:548
@ RPROC_LAST
Just keep this one at the end.
Definition remoteproc.h:550
@ RPROC_CONFIGURED
Remote is configured.
Definition remoteproc.h:538
@ RPROC_SUSPENDED
Remote is suspended.
Definition remoteproc.h:544
@ RPROC_ERROR
Remote is has error; need to recover.
Definition remoteproc.h:546
@ RPROC_READY
Remote is ready to start.
Definition remoteproc.h:540
@ RPROC_OFFLINE
Remote is offline.
Definition remoteproc.h:536
@ RPROC_RUNNING
Remote is up and running.
Definition remoteproc.h:542
void * remoteproc_mmap(struct remoteproc *rproc, metal_phys_addr_t *pa, metal_phys_addr_t *da, size_t size, unsigned int attribute, struct metal_io_region **io)
Remoteproc mmap memory.
Definition remoteproc.c:404
int remoteproc_get_notification(struct remoteproc *rproc, uint32_t notifyid)
remoteproc is got notified, it will check its subdevices for the notification
Definition remoteproc.c:1051
int remoteproc_start(struct remoteproc *rproc)
This function starts the remote processor.
Definition remoteproc.c:237
struct metal_io_region * remoteproc_get_io_with_da(struct remoteproc *rproc, metal_phys_addr_t da, unsigned long *offset)
Get remoteproc memory I/O region with device address.
Definition remoteproc.c:363
Resource table physically contiguous memory request entry.
Definition remoteproc.h:159
uint32_t len
Length in bytes.
Definition remoteproc.h:170
uint32_t type
Resource carveout has type 0.
Definition remoteproc.h:161
uint8_t name[RPROC_MAX_NAME_LEN]
Optional human-readable name of the requested memory region used for debugging.
Definition remoteproc.h:179
uint32_t pa
Physical address.
Definition remoteproc.h:167
uint32_t reserved
Reserved (must be zero).
Definition remoteproc.h:176
uint32_t da
Device address.
Definition remoteproc.h:164
uint32_t flags
IOMMU protection flags.
Definition remoteproc.h:173
Resource table IOMMU mapping request entry.
Definition remoteproc.h:200
uint32_t pa
Physical address to map.
Definition remoteproc.h:208
uint32_t da
Device address.
Definition remoteproc.h:205
uint32_t len
Length of the mapping in bytes.
Definition remoteproc.h:211
uint32_t reserved
Reserved (must be zero).
Definition remoteproc.h:217
uint32_t type
IOMMU mapping request has type 1.
Definition remoteproc.h:202
uint32_t flags
IOMMU protection flags.
Definition remoteproc.h:214
uint8_t name[RPROC_MAX_NAME_LEN]
Optional human-readable name of the requested memory region used for debugging.
Definition remoteproc.h:220
Resource table entry header.
Definition remoteproc.h:73
uint32_t type
Resource type matching the type field of the structure in data.
Definition remoteproc.h:75
uint8_t data[0]
Resource data.
Definition remoteproc.h:78
Resource table trace buffer declaration entry.
Definition remoteproc.h:233
uint32_t da
Device address of the buffer.
Definition remoteproc.h:238
uint8_t name[RPROC_MAX_NAME_LEN]
Optional human-readable name of the requested memory region used for debugging.
Definition remoteproc.h:247
uint32_t reserved
Reserved (must be zero).
Definition remoteproc.h:244
uint32_t type
Trace buffer entry has type 2.
Definition remoteproc.h:235
uint32_t len
Length of the buffer in bytes.
Definition remoteproc.h:241
Resource table vring descriptor entry.
Definition remoteproc.h:257
uint32_t da
The device address where the remoteproc is expecting the vring, or FW_RSC_U32_ADDR_ANY/FW_RSC_U64_ADD...
Definition remoteproc.h:263
uint32_t align
The alignment between the consumer and producer parts of the vring.
Definition remoteproc.h:266
uint32_t notifyid
A unique rproc-wide notify index for this vring.
Definition remoteproc.h:276
uint32_t num
Number of buffers supported by this vring (must be power of two).
Definition remoteproc.h:269
uint32_t reserved
Reserved (must be zero).
Definition remoteproc.h:279
Resource table virtio device entry.
Definition remoteproc.h:304
uint32_t config_len
The size of the virtio config space of this vdev.
Definition remoteproc.h:331
uint32_t notifyid
A unique rproc-wide notify index for this vdev.
Definition remoteproc.h:316
uint8_t reserved[2]
Reserved (must be zero).
Definition remoteproc.h:340
uint32_t type
Virtio device header has type 3.
Definition remoteproc.h:306
uint8_t num_of_vrings
Number of vrings described in this vdev header.
Definition remoteproc.h:337
uint32_t dfeatures
The virtio device features supported by the firmware.
Definition remoteproc.h:319
uint32_t gfeatures
A place holder used by the host to write back the negotiated features that are supported by both side...
Definition remoteproc.h:325
uint8_t status
A place holder where the host will indicate its virtio progress.
Definition remoteproc.h:334
uint32_t id
Virtio device id (as in virtio_ids.h).
Definition remoteproc.h:309
struct fw_rsc_vdev_vring vring[0]
An array of num_of_vrings entries of fw_rsc_vdev_vring.
Definition remoteproc.h:343
Resource table remote processor vendor specific entry.
Definition remoteproc.h:356
uint32_t len
Length of the resource.
Definition remoteproc.h:361
uint32_t type
Vendor specific resource type can be values 128-512.
Definition remoteproc.h:358
User-defined image store operations.
Definition remoteproc_loader.h:58
Loader operations.
Definition remoteproc_loader.h:76
Memory used by the remote processor.
Definition remoteproc.h:369
char name[RPROC_MAX_NAME_LEN]
Optional human-readable name of the memory region.
Definition remoteproc.h:380
struct metal_io_region * io
Pointer to the I/O region.
Definition remoteproc.h:383
metal_phys_addr_t pa
Physical memory.
Definition remoteproc.h:374
metal_phys_addr_t da
Device memory.
Definition remoteproc.h:371
struct metal_list node
List node.
Definition remoteproc.h:386
size_t size
Size of the memory.
Definition remoteproc.h:377
Remoteproc operations to manage a remoteproc instance.
Definition remoteproc.h:439
int(* stop)(struct remoteproc *rproc)
Stop the remoteproc from running the application, the resource such as memory may not be off.
Definition remoteproc.h:466
int(* notify)(struct remoteproc *rproc, uint32_t id)
Notify the remote.
Definition remoteproc.h:472
int(* handle_rsc)(struct remoteproc *rproc, void *rsc, size_t len)
Handle the vendor specific resource.
Definition remoteproc.h:454
int(* shutdown)(struct remoteproc *rproc)
Shutdown the remoteproc and release its resources.
Definition remoteproc.h:469
int(* start)(struct remoteproc *rproc)
Kick the remoteproc to run the application.
Definition remoteproc.h:460
int(* config)(struct remoteproc *rproc, void *data)
Configure the remoteproc to make it ready to load and run the executable.
Definition remoteproc.h:457
void(* remove)(struct remoteproc *rproc)
Remove the remoteproc instance.
Definition remoteproc.h:445
A remote processor instance.
Definition remoteproc.h:396
void * priv
Private data.
Definition remoteproc.h:431
const struct loader_ops * loader
Executable loader.
Definition remoteproc.h:425
struct metal_list mems
Remoteproc memories.
Definition remoteproc.h:410
struct metal_io_region * rsc_io
Metal I/O region of the resource table.
Definition remoteproc.h:407
size_t rsc_len
Length of the resource table.
Definition remoteproc.h:404
struct metal_list vdevs
Remoteproc virtio devices.
Definition remoteproc.h:413
metal_mutex_t lock
Mutex lock.
Definition remoteproc.h:398
unsigned int state
Remote processor state.
Definition remoteproc.h:428
void * rsc_table
Pointer to the resource table.
Definition remoteproc.h:401
unsigned long bitmap
Bitmap for notify IDs for remoteproc subdevices.
Definition remoteproc.h:416
const struct remoteproc_ops * ops
Remoteproc operations.
Definition remoteproc.h:419
metal_phys_addr_t bootaddr
Boot address.
Definition remoteproc.h:422
Resource table header.
Definition remoteproc.h:51
uint32_t ver
Version number.
Definition remoteproc.h:53
uint32_t num
Number of resource entries.
Definition remoteproc.h:56
uint32_t offset[0]
Array of offsets pointing at the various resource entries.
Definition remoteproc.h:62
uint32_t reserved[2]
Reserved (must be zero).
Definition remoteproc.h:59
Structure definition for virtio devices for use by the applications/drivers.
Definition virtio.h:176
unsigned int role
If it is virtio backend or front end.
Definition virtio.h:187
uint32_t notifyid
Unique position on the virtio bus.
Definition virtio.h:178