Skip to content

Commit c7757cf

Browse files
xiaoxiang781216arnopo
authored andcommitted
remoteproc: add get_mem callback to remoteproc_ops
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>
1 parent ae1eba5 commit c7757cf

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

lib/include/openamp/remoteproc.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ struct remoteproc {
395395
* memory may not be off.
396396
* @shutdown: shutdown the remoteproc and release its resources.
397397
* @notify: notify the remote
398+
* @get_mem: get remoteproc memory I/O region.
398399
*/
399400
struct remoteproc_ops {
400401
struct remoteproc *(*init)(struct remoteproc *rproc,
@@ -410,6 +411,27 @@ struct remoteproc_ops {
410411
int (*stop)(struct remoteproc *rproc);
411412
int (*shutdown)(struct remoteproc *rproc);
412413
int (*notify)(struct remoteproc *rproc, uint32_t id);
414+
/**
415+
* get_mem
416+
*
417+
* get remoteproc memory I/O region by either name, virtual
418+
* address, physical address or device address.
419+
*
420+
* @rproc - pointer to remoteproc instance
421+
* @name - memory name
422+
* @pa - physical address
423+
* @da - device address
424+
* @va - virtual address
425+
* @size - memory size
426+
*
427+
* @returns remoteproc memory pointed by buf if success, otherwise NULL
428+
*/
429+
struct remoteproc_mem *(*get_mem)(struct remoteproc *rproc,
430+
const char *name,
431+
metal_phys_addr_t pa,
432+
metal_phys_addr_t da,
433+
void *va, size_t size,
434+
struct remoteproc_mem *buf);
413435
};
414436

415437
/* Remoteproc error codes */

lib/remoteproc/remoteproc.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ remoteproc_check_fw_format(const void *img_data, size_t img_len)
2929
return NULL;
3030
}
3131

32+
/* try the internal list added by remoteproc_add_mem first and then get_mem callback */
3233
static struct remoteproc_mem *
3334
remoteproc_get_mem(struct remoteproc *rproc, const char *name,
3435
metal_phys_addr_t pa, metal_phys_addr_t da,
35-
void *va, size_t size)
36+
void *va, size_t size, struct remoteproc_mem *buf)
3637
{
3738
struct metal_list *node;
3839
struct remoteproc_mem *mem;
@@ -72,7 +73,11 @@ remoteproc_get_mem(struct remoteproc *rproc, const char *name,
7273
return NULL;
7374
}
7475
}
75-
return NULL;
76+
77+
if (!rproc->ops->get_mem)
78+
return NULL;
79+
80+
return rproc->ops->get_mem(rproc, name, pa, da, va, size, buf);
7681
}
7782

7883
static metal_phys_addr_t
@@ -282,9 +287,10 @@ remoteproc_get_io_with_name(struct remoteproc *rproc,
282287
const char *name)
283288
{
284289
struct remoteproc_mem *mem;
290+
struct remoteproc_mem buf;
285291

286292
mem = remoteproc_get_mem(rproc, name,
287-
METAL_BAD_PHYS, METAL_BAD_PHYS, NULL, 0);
293+
METAL_BAD_PHYS, METAL_BAD_PHYS, NULL, 0, &buf);
288294
if (mem)
289295
return mem->io;
290296
else
@@ -296,8 +302,9 @@ remoteproc_get_io_with_pa(struct remoteproc *rproc,
296302
metal_phys_addr_t pa)
297303
{
298304
struct remoteproc_mem *mem;
305+
struct remoteproc_mem buf;
299306

300-
mem = remoteproc_get_mem(rproc, NULL, pa, METAL_BAD_PHYS, NULL, 0);
307+
mem = remoteproc_get_mem(rproc, NULL, pa, METAL_BAD_PHYS, NULL, 0, &buf);
301308
if (mem)
302309
return mem->io;
303310
else
@@ -310,8 +317,9 @@ remoteproc_get_io_with_da(struct remoteproc *rproc,
310317
unsigned long *offset)
311318
{
312319
struct remoteproc_mem *mem;
320+
struct remoteproc_mem buf;
313321

314-
mem = remoteproc_get_mem(rproc, NULL, METAL_BAD_PHYS, da, NULL, 0);
322+
mem = remoteproc_get_mem(rproc, NULL, METAL_BAD_PHYS, da, NULL, 0, &buf);
315323
if (mem) {
316324
struct metal_io_region *io;
317325
metal_phys_addr_t pa;
@@ -329,9 +337,10 @@ struct metal_io_region *
329337
remoteproc_get_io_with_va(struct remoteproc *rproc, void *va)
330338
{
331339
struct remoteproc_mem *mem;
340+
struct remoteproc_mem buf;
332341

333342
mem = remoteproc_get_mem(rproc, NULL, METAL_BAD_PHYS, METAL_BAD_PHYS,
334-
va, 0);
343+
va, 0, &buf);
335344
if (mem)
336345
return mem->io;
337346
else
@@ -346,6 +355,7 @@ void *remoteproc_mmap(struct remoteproc *rproc,
346355
void *va = NULL;
347356
metal_phys_addr_t lpa, lda;
348357
struct remoteproc_mem *mem;
358+
struct remoteproc_mem buf;
349359

350360
if (!rproc)
351361
return NULL;
@@ -359,7 +369,7 @@ void *remoteproc_mmap(struct remoteproc *rproc,
359369
lda = *da;
360370
else
361371
lda = METAL_BAD_PHYS;
362-
mem = remoteproc_get_mem(rproc, NULL, lpa, lda, NULL, size);
372+
mem = remoteproc_get_mem(rproc, NULL, lpa, lda, NULL, size, &buf);
363373
if (mem) {
364374
if (lpa != METAL_BAD_PHYS)
365375
lda = remoteproc_patoda(mem, lpa);

0 commit comments

Comments
 (0)