From 0714052c74bfe4e74ae6fca705da4d7d66c92681 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Wed, 20 Mar 2024 14:48:31 -0500 Subject: [PATCH] samples: ipc: openamp_rsc_table: Remove virtual shared memory device 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 --- .../ipc/openamp_rsc_table/CMakeLists.txt | 6 --- .../ipc/openamp_rsc_table/src/main_remote.c | 49 +++---------------- 2 files changed, 8 insertions(+), 47 deletions(-) diff --git a/samples/subsys/ipc/openamp_rsc_table/CMakeLists.txt b/samples/subsys/ipc/openamp_rsc_table/CMakeLists.txt index 57640da841..dd89bf7754 100644 --- a/samples/subsys/ipc/openamp_rsc_table/CMakeLists.txt +++ b/samples/subsys/ipc/openamp_rsc_table/CMakeLists.txt @@ -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) diff --git a/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c b/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c index 6cc906c6a2..8bc1a475d0 100644 --- a/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c +++ b/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c @@ -14,7 +14,8 @@ #include #include -#include +#include +#include #include #ifdef CONFIG_SHELL_BACKEND_RPMSG @@ -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; @@ -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; @@ -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");