Skip to content

Commit

Permalink
samples: ipc: openamp_rsc_table: Remove virtual shared memory device
Browse files Browse the repository at this point in the history
A virtual metal_device is created and then the needed IO regions created
and added to this device. Immediately we extract these regions back out
and make use of them. There is no reason to do this, instead simply
use the created IO regions.

This also removes the need to have struct metal_device defined to have
more than one IO region (METAL_MAX_DEVICE_REGIONS), which is not default.
If the libmetal library was built with a different value, then updating
this header would not fix the underlying implementation leading to runtime
failures.

Signed-off-by: Andrew Davis <[email protected]>
  • Loading branch information
glneo authored and dleach02 committed Mar 29, 2024
1 parent 993f978 commit 0714052
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 47 deletions.
6 changes: 0 additions & 6 deletions samples/subsys/ipc/openamp_rsc_table/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(openamp_rsc_table_remote)

# METAL_MAX_DEVICE_REGIONS is used to give the number of memory regions shared
# between processors. By default only one region is defined for the vrings
# and rpmsg buffers. The METAL_MAX_DEVICE_REGIONS has to be redefined to add a
# second region for the resource table.
zephyr_compile_definitions(METAL_MAX_DEVICE_REGIONS=2)

target_include_directories(app PRIVATE ${LIBMETAL_INCLUDE_DIR} ${OPENAMP_INCLUDE_DIR} ${PLATFORM_DIR})

target_sources(app PRIVATE src/main_remote.c)
49 changes: 8 additions & 41 deletions samples/subsys/ipc/openamp_rsc_table/src/main_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include <zephyr/drivers/ipm.h>

#include <openamp/open_amp.h>
#include <metal/device.h>
#include <metal/sys.h>
#include <metal/io.h>
#include <resource_table.h>

#ifdef CONFIG_SHELL_BACKEND_RPMSG
Expand Down Expand Up @@ -53,26 +54,17 @@ static const struct device *const ipm_handle =

static metal_phys_addr_t shm_physmap = SHM_START_ADDR;

struct metal_device shm_device = {
.name = SHM_DEVICE_NAME,
.num_regions = 2,
.regions = {
{.virt = NULL}, /* shared memory */
{.virt = NULL}, /* rsc_table memory */
},
.node = { NULL },
.irq_num = 0,
.irq_info = NULL
};
static struct metal_io_region shm_io_data; /* shared memory */
static struct metal_io_region rsc_io_data; /* rsc_table memory */

struct rpmsg_rcv_msg {
void *data;
size_t len;
};

static struct metal_io_region *shm_io;
static struct metal_io_region *shm_io = &shm_io_data;

static struct metal_io_region *rsc_io;
static struct metal_io_region *rsc_io = &rsc_io_data;
static struct rpmsg_virtio_device rvdev;

static void *rsc_table;
Expand Down Expand Up @@ -149,7 +141,6 @@ int platform_init(void)
{
void *rsc_tab_addr;
int rsc_size;
struct metal_device *device;
struct metal_init_params metal_params = METAL_INIT_DEFAULTS;
int status;

Expand All @@ -159,41 +150,17 @@ int platform_init(void)
return -1;
}

status = metal_register_generic_device(&shm_device);
if (status) {
LOG_ERR("Couldn't register shared memory: %d\n", status);
return -1;
}

status = metal_device_open("generic", SHM_DEVICE_NAME, &device);
if (status) {
LOG_ERR("metal_device_open failed: %d\n", status);
return -1;
}

/* declare shared memory region */
metal_io_init(&device->regions[0], (void *)SHM_START_ADDR, &shm_physmap,
metal_io_init(shm_io, (void *)SHM_START_ADDR, &shm_physmap,
SHM_SIZE, -1, 0, NULL);

shm_io = metal_device_io_region(device, 0);
if (!shm_io) {
LOG_ERR("Failed to get shm_io region\n");
return -1;
}

/* declare resource table region */
rsc_table_get(&rsc_tab_addr, &rsc_size);
rsc_table = (struct st_resource_table *)rsc_tab_addr;

metal_io_init(&device->regions[1], rsc_table,
metal_io_init(rsc_io, rsc_table,
(metal_phys_addr_t *)rsc_table, rsc_size, -1, 0, NULL);

rsc_io = metal_device_io_region(device, 1);
if (!rsc_io) {
LOG_ERR("Failed to get rsc_io region\n");
return -1;
}

/* setup IPM */
if (!device_is_ready(ipm_handle)) {
LOG_ERR("IPM device is not ready");
Expand Down

0 comments on commit 0714052

Please sign in to comment.