OpenAMP Library  353
remoteproc.c File Reference
#include <internal/utilities.h>
#include <metal/alloc.h>
#include <metal/log.h>
#include <metal/utilities.h>
#include <openamp/elf_loader.h>
#include <openamp/remoteproc.h>
#include <openamp/remoteproc_loader.h>
#include <openamp/remoteproc_virtio.h>
#include "rsc_table_parser.h"

Functions

static const struct loader_opsremoteproc_check_fw_format (const void *img_data, size_t img_len)
 
static struct remoteproc_memremoteproc_get_mem (struct remoteproc *rproc, const char *name, metal_phys_addr_t pa, metal_phys_addr_t da, void *va, size_t size, struct remoteproc_mem *buf)
 
static metal_phys_addr_t remoteproc_datopa (struct remoteproc_mem *mem, metal_phys_addr_t da)
 
static metal_phys_addr_t remoteproc_patoda (struct remoteproc_mem *mem, metal_phys_addr_t pa)
 
static void * remoteproc_get_rsc_table (struct remoteproc *rproc, void *store, const struct image_store_ops *store_ops, size_t offset, size_t len)
 
static int remoteproc_parse_rsc_table (struct remoteproc *rproc, struct resource_table *rsc_table, size_t rsc_size)
 
int remoteproc_set_rsc_table (struct remoteproc *rproc, struct resource_table *rsc_table, size_t rsc_size)
 Parse and set resource table of remoteproc. More...
 
struct remoteprocremoteproc_init (struct remoteproc *rproc, const struct remoteproc_ops *ops, void *priv)
 Initializes remoteproc resource. More...
 
int remoteproc_remove (struct remoteproc *rproc)
 Remove remoteproc resource. More...
 
int remoteproc_config (struct remoteproc *rproc, void *data)
 This function configures the remote processor to get it ready to load and run executable. More...
 
int remoteproc_start (struct remoteproc *rproc)
 This function starts the remote processor. More...
 
int remoteproc_stop (struct remoteproc *rproc)
 This function stops the remote processor but it will not release its resource. More...
 
int remoteproc_shutdown (struct remoteproc *rproc)
 This function shuts down the remote processor and releases its resources. More...
 
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. More...
 
void remoteproc_add_mem (struct remoteproc *rproc, struct remoteproc_mem *mem)
 Add remoteproc memory. More...
 
struct metal_io_region * remoteproc_get_io_with_name (struct remoteproc *rproc, const char *name)
 Get remoteproc memory I/O region with name. More...
 
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. More...
 
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. More...
 
struct metal_io_region * remoteproc_get_io_with_va (struct remoteproc *rproc, void *va)
 Get remoteproc memory I/O region with virtual address. More...
 
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. More...
 
int remoteproc_load (struct remoteproc *rproc, const char *path, void *store, const struct image_store_ops *store_ops, void **img_info)
 Loads the executable. More...
 
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. More...
 
unsigned int remoteproc_allocate_id (struct remoteproc *rproc, unsigned int start, unsigned int end)
 Allocate notifyid for resource. More...
 
static int remoteproc_virtio_notify (void *priv, uint32_t id)
 
struct virtio_deviceremoteproc_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. More...
 
void remoteproc_remove_virtio (struct remoteproc *rproc, struct virtio_device *vdev)
 Remove virtio device. More...
 
int remoteproc_get_notification (struct remoteproc *rproc, uint32_t notifyid)
 remoteproc is got notified, it will check its subdevices for the notification More...
 

Function Documentation

◆ remoteproc_add_mem()

void remoteproc_add_mem ( struct remoteproc rproc,
struct remoteproc_mem mem 
)

Add remoteproc memory.

Parameters
rprocPointer to remoteproc
memPointer to remoteproc memory

◆ remoteproc_allocate_id()

unsigned int remoteproc_allocate_id ( struct remoteproc rproc,
unsigned int  start,
unsigned int  end 
)

Allocate notifyid for resource.

Parameters
rprocPointer to the remoteproc instance
startStart of the id range
endEnd of the id range
Returns
Allocated notify id

◆ remoteproc_check_fw_format()

static const struct loader_ops* remoteproc_check_fw_format ( const void *  img_data,
size_t  img_len 
)
static

◆ remoteproc_config()

int remoteproc_config ( struct remoteproc rproc,
void *  data 
)

This function configures the remote processor to get it ready to load and run executable.

Parameters
rprocPointer to remoteproc instance to start
dataConfiguration data
Returns
0 for success and negative value for errors

◆ remoteproc_create_virtio()

struct virtio_device* remoteproc_create_virtio ( struct remoteproc rproc,
int  vdev_id,
unsigned int  role,
void(*)(struct virtio_device *vdev)  rst_cb 
)

Create virtio device, it returns pointer to the created virtio device.

Parameters
rprocPointer to the remoteproc instance
vdev_idvirtio device ID
rolevirtio device role
rst_cbvirtio device reset callback
Returns
Pointer to the created virtio device, NULL for failure.

◆ remoteproc_datopa()

static metal_phys_addr_t remoteproc_datopa ( struct remoteproc_mem mem,
metal_phys_addr_t  da 
)
static

◆ remoteproc_get_io_with_da()

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.

Parameters
rprocPointer to the remote processor
daDevice address
offsetI/O region offset of the device address
Returns
Metal I/O region pointer, NULL for failure

◆ remoteproc_get_io_with_name()

struct metal_io_region* remoteproc_get_io_with_name ( struct remoteproc rproc,
const char *  name 
)

Get remoteproc memory I/O region with name.

Parameters
rprocPointer to the remote processor
nameName of the shared memory
Returns
Metal I/O region pointer, NULL for failure

◆ remoteproc_get_io_with_pa()

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.

Parameters
rprocPointer to the remote processor
paPhysical address
Returns
Metal I/O region pointer, NULL for failure

◆ remoteproc_get_io_with_va()

struct metal_io_region* remoteproc_get_io_with_va ( struct remoteproc rproc,
void *  va 
)

Get remoteproc memory I/O region with virtual address.

Parameters
rprocPointer to the remote processor
vaVirtual address
Returns
Metal I/O region pointer, NULL for failure

◆ remoteproc_get_mem()

static struct remoteproc_mem* remoteproc_get_mem ( struct remoteproc rproc,
const char *  name,
metal_phys_addr_t  pa,
metal_phys_addr_t  da,
void *  va,
size_t  size,
struct remoteproc_mem buf 
)
static

◆ remoteproc_get_notification()

int remoteproc_get_notification ( struct remoteproc rproc,
uint32_t  notifyid 
)

remoteproc is got notified, it will check its subdevices for the notification

Parameters
rprocPointer to the remoteproc instance
notifyidNotification id
Returns
0 for succeed, negative value for failure

◆ remoteproc_get_rsc_table()

static void* remoteproc_get_rsc_table ( struct remoteproc rproc,
void *  store,
const struct image_store_ops store_ops,
size_t  offset,
size_t  len 
)
static

◆ remoteproc_init()

struct remoteproc* remoteproc_init ( struct remoteproc rproc,
const struct remoteproc_ops ops,
void *  priv 
)

Initializes remoteproc resource.

Parameters
rprocPointer to remoteproc instance
opsPointer to remoteproc operations
privPointer to private data
Returns
Created remoteproc pointer

◆ remoteproc_init_mem()

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.

Parameters
memPointer to remoteproc memory
nameMemory name (max string size RPROC_MAX_NAME_LEN)
paPhysical address
daDevice address
sizeMemory size
ioPointer to the I/O region

◆ remoteproc_load()

int remoteproc_load ( struct remoteproc rproc,
const char *  path,
void *  store,
const struct image_store_ops store_ops,
void **  img_info 
)

Loads the executable.

Expects the user application defines how to open the executable file and how to get data from the executable file and how to load data to the target memory.

Parameters
rprocPointer to the remoteproc instance
pathOptional path to the image file
storePointer to user defined image store argument
store_opsPointer to image store operations
img_infoPointer to memory which stores image information used by remoteproc loader
Returns
0 for success and negative value for failure

◆ remoteproc_load_noblock()

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.

Expects the caller has loaded image data to local memory and passed to the this function. If the function needs more image data it will return the next expected image data offset and the next expected image data length. If the function requires the caller to download image data to the target memory, it will also return the target physical address besides the offset and length. This function can be used to load firmware in stream mode. In this mode, you cannot do seek to the executable file. If the executable is ELF, it cannot get the resource table section before it loads the full ELF file. Furthermore, application usually don't store the data which is loaded to local memory in streaming mode, and thus, in this mode, it will load the binary to the target memory before it gets the resource table. And thus, when calling this function don't put the target executable memory in the resource table, as this function will parse the resource table after it loads the binary to target memory.

Parameters
rprocPointer to the remoteproc instance
img_dataPointer to image data for remoteproc loader to parse
offsetImage data offset to the beginning of the image file
lenImage data length
img_infoPointer to memory which stores image information used by remoteproc loader
paPointer to the target memory physical address. If the next expected data doesn't need to load to the target memory, the function will set it to ANY.
ioPointer to the io region. If the next expected data doesn't need to load to the target memory, the function will set it to NULL.
noffsetPointer to the next image data offset to the beginning of the image file needs to load to local or to the target memory.
nlenPointer to the next image data length needs to load to local or to the target memory.
nmlenPointer to the memory size. It is only used when the next expected data is going to be loaded to the target memory. E.g. in ELF, it is possible that loadable segment in memory is larger that the segment data in the ELF file. In this case, application will need to pad the rest of the memory with padding.
paddingPointer to the padding value. It is only used when the next expected data is going to be loaded to the target memory and the target memory size is larger than the segment data in the executable file.
Returns
0 for success and negative value for failure

◆ remoteproc_mmap()

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.

Parameters
rprocPointer to the remote processor
paPhysical address pointer
daDevice address pointer
sizeSize of the memory
attributeMemory attribute
ioPointer to the I/O region
Returns
Pointer to the memory

◆ remoteproc_parse_rsc_table()

static int remoteproc_parse_rsc_table ( struct remoteproc rproc,
struct resource_table rsc_table,
size_t  rsc_size 
)
static

◆ remoteproc_patoda()

static metal_phys_addr_t remoteproc_patoda ( struct remoteproc_mem mem,
metal_phys_addr_t  pa 
)
static

◆ remoteproc_remove()

int remoteproc_remove ( struct remoteproc rproc)

Remove remoteproc resource.

Parameters
rprocPointer to remoteproc instance
Returns
0 for success, negative value for failure

◆ remoteproc_remove_virtio()

void remoteproc_remove_virtio ( struct remoteproc rproc,
struct virtio_device vdev 
)

Remove virtio device.

Parameters
rprocPointer to the remoteproc instance
vdevPointer to the virtio device

◆ remoteproc_set_rsc_table()

int remoteproc_set_rsc_table ( struct remoteproc rproc,
struct resource_table rsc_table,
size_t  rsc_size 
)

Parse and set resource table of remoteproc.

Parameters
rprocPointer to remoteproc instance
rsc_tablePointer to resource table
rsc_sizeResource table size
Returns
0 for success and negative value for errors

◆ remoteproc_shutdown()

int remoteproc_shutdown ( struct remoteproc rproc)

This function shuts down the remote processor and releases its resources.

Parameters
rprocPointer to remoteproc instance
Returns
0 for success and negative value for errors

◆ remoteproc_start()

int remoteproc_start ( struct remoteproc rproc)

This function starts the remote processor.

It assumes the firmware is already loaded.

Parameters
rprocPointer to remoteproc instance to start
Returns
0 for success and negative value for errors

◆ remoteproc_stop()

int remoteproc_stop ( struct remoteproc rproc)

This function stops the remote processor but it will not release its resource.

Parameters
rprocPointer to remoteproc instance
Returns
0 for success and negative value for errors

◆ remoteproc_virtio_notify()

static int remoteproc_virtio_notify ( void *  priv,
uint32_t  id 
)
static