16 #include <metal/mutex.h>
17 #include <metal/compiler.h>
19 #if defined __cplusplus
23 #define RSC_NOTIFY_ID_ANY 0xFFFFFFFFU
25 #define RPROC_MAX_NAME_LEN 32
122 #define FW_RSC_U64_ADDR_ANY 0xFFFFFFFFFFFFFFFFUL
123 #define FW_RSC_U32_ADDR_ANY 0xFFFFFFFFUL
371 metal_phys_addr_t
da;
374 metal_phys_addr_t
pa;
383 struct metal_io_region *
io;
386 struct metal_list
node;
410 struct metal_list
mems;
413 struct metal_list
vdevs;
449 metal_phys_addr_t *pa, metal_phys_addr_t *da,
450 size_t size,
unsigned int attribute,
451 struct metal_io_region **io);
490 metal_phys_addr_t pa,
491 metal_phys_addr_t da,
492 void *va,
size_t size,
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)
520 if ((
unsigned long)ptr >= (
unsigned long)(-
RPROC_EMAX))
528 return (
void *)error;
586 metal_phys_addr_t pa, metal_phys_addr_t da,
587 size_t size,
struct metal_io_region *io);
605 struct metal_io_region *
617 struct metal_io_region *
619 metal_phys_addr_t pa);
630 struct metal_io_region *
632 metal_phys_addr_t da,
633 unsigned long *offset);
643 struct metal_io_region *
660 metal_phys_addr_t *pa, metal_phys_addr_t *da,
661 size_t size,
unsigned int attribute,
662 struct metal_io_region **io);
789 const void *img_data,
size_t offset,
size_t len,
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);
821 int vdev_id,
unsigned int role,
844 #if defined __cplusplus
static long RPROC_PTR_ERR(const void *ptr)
Definition: remoteproc.h:513
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:387
int remoteproc_remove(struct remoteproc *rproc)
Remove remoteproc resource.
Definition: remoteproc.c:193
#define RPROC_MAX_NAME_LEN
Definition: remoteproc.h:25
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:345
void remoteproc_remove_virtio(struct remoteproc *rproc, struct virtio_device *vdev)
Remove virtio device.
Definition: remoteproc.c:1033
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:443
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
unsigned int remoteproc_allocate_id(struct remoteproc *rproc, unsigned int start, unsigned int end)
Allocate notifyid for resource.
Definition: remoteproc.c:905
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
static void * RPROC_ERR_PTR(long error)
Definition: remoteproc.h:526
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:327
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:714
struct remoteproc * remoteproc_init(struct remoteproc *rproc, const struct remoteproc_ops *ops, void *priv)
Initializes remoteproc resource.
Definition: remoteproc.c:175
METAL_PACKED_BEGIN struct resource_table METAL_PACKED_END
void remoteproc_add_mem(struct remoteproc *rproc, struct remoteproc_mem *mem)
Add remoteproc memory.
Definition: remoteproc.c:319
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:938
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:303
#define RPROC_EMAX
Definition: remoteproc.h:509
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:362
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
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:1050
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:403
int remoteproc_start(struct remoteproc *rproc)
This function starts the remote processor.
Definition: remoteproc.c:237
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
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:188
unsigned int role
If it is virtio backend or front end.
Definition: virtio.h:199
uint32_t notifyid
Unique position on the virtio bus.
Definition: virtio.h:190
The virtqueue layout structure.
Definition: virtio_ring.h:157