Skip to content

Commit

Permalink
remoteproc: add get_mem callback to remoteproc_ops
Browse files Browse the repository at this point in the history
Since the mapping info is normally managed inside the porting
layer, the new callback could avoid the mapping duplication.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  • Loading branch information
xiaoxiang781216 authored and arnopo committed Jan 4, 2021
1 parent ae1eba5 commit c7757cf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
22 changes: 22 additions & 0 deletions lib/include/openamp/remoteproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ struct remoteproc {
* memory may not be off.
* @shutdown: shutdown the remoteproc and release its resources.
* @notify: notify the remote
* @get_mem: get remoteproc memory I/O region.
*/
struct remoteproc_ops {
struct remoteproc *(*init)(struct remoteproc *rproc,
Expand All @@ -410,6 +411,27 @@ struct remoteproc_ops {
int (*stop)(struct remoteproc *rproc);
int (*shutdown)(struct remoteproc *rproc);
int (*notify)(struct remoteproc *rproc, uint32_t id);
/**
* get_mem
*
* get remoteproc memory I/O region by either name, virtual
* address, physical address or device address.
*
* @rproc - pointer to remoteproc instance
* @name - memory name
* @pa - physical address
* @da - device address
* @va - virtual address
* @size - memory size
*
* @returns remoteproc memory pointed by buf if success, otherwise NULL
*/
struct remoteproc_mem *(*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);
};

/* Remoteproc error codes */
Expand Down
24 changes: 17 additions & 7 deletions lib/remoteproc/remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ remoteproc_check_fw_format(const void *img_data, size_t img_len)
return NULL;
}

/* try the internal list added by remoteproc_add_mem first and then get_mem callback */
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)
void *va, size_t size, struct remoteproc_mem *buf)
{
struct metal_list *node;
struct remoteproc_mem *mem;
Expand Down Expand Up @@ -72,7 +73,11 @@ remoteproc_get_mem(struct remoteproc *rproc, const char *name,
return NULL;
}
}
return NULL;

if (!rproc->ops->get_mem)
return NULL;

return rproc->ops->get_mem(rproc, name, pa, da, va, size, buf);
}

static metal_phys_addr_t
Expand Down Expand Up @@ -282,9 +287,10 @@ remoteproc_get_io_with_name(struct remoteproc *rproc,
const char *name)
{
struct remoteproc_mem *mem;
struct remoteproc_mem buf;

mem = remoteproc_get_mem(rproc, name,
METAL_BAD_PHYS, METAL_BAD_PHYS, NULL, 0);
METAL_BAD_PHYS, METAL_BAD_PHYS, NULL, 0, &buf);
if (mem)
return mem->io;
else
Expand All @@ -296,8 +302,9 @@ remoteproc_get_io_with_pa(struct remoteproc *rproc,
metal_phys_addr_t pa)
{
struct remoteproc_mem *mem;
struct remoteproc_mem buf;

mem = remoteproc_get_mem(rproc, NULL, pa, METAL_BAD_PHYS, NULL, 0);
mem = remoteproc_get_mem(rproc, NULL, pa, METAL_BAD_PHYS, NULL, 0, &buf);
if (mem)
return mem->io;
else
Expand All @@ -310,8 +317,9 @@ remoteproc_get_io_with_da(struct remoteproc *rproc,
unsigned long *offset)
{
struct remoteproc_mem *mem;
struct remoteproc_mem buf;

mem = remoteproc_get_mem(rproc, NULL, METAL_BAD_PHYS, da, NULL, 0);
mem = remoteproc_get_mem(rproc, NULL, METAL_BAD_PHYS, da, NULL, 0, &buf);
if (mem) {
struct metal_io_region *io;
metal_phys_addr_t pa;
Expand All @@ -329,9 +337,10 @@ struct metal_io_region *
remoteproc_get_io_with_va(struct remoteproc *rproc, void *va)
{
struct remoteproc_mem *mem;
struct remoteproc_mem buf;

mem = remoteproc_get_mem(rproc, NULL, METAL_BAD_PHYS, METAL_BAD_PHYS,
va, 0);
va, 0, &buf);
if (mem)
return mem->io;
else
Expand All @@ -346,6 +355,7 @@ void *remoteproc_mmap(struct remoteproc *rproc,
void *va = NULL;
metal_phys_addr_t lpa, lda;
struct remoteproc_mem *mem;
struct remoteproc_mem buf;

if (!rproc)
return NULL;
Expand All @@ -359,7 +369,7 @@ void *remoteproc_mmap(struct remoteproc *rproc,
lda = *da;
else
lda = METAL_BAD_PHYS;
mem = remoteproc_get_mem(rproc, NULL, lpa, lda, NULL, size);
mem = remoteproc_get_mem(rproc, NULL, lpa, lda, NULL, size, &buf);
if (mem) {
if (lpa != METAL_BAD_PHYS)
lda = remoteproc_patoda(mem, lpa);
Expand Down

0 comments on commit c7757cf

Please sign in to comment.