From 39863b66bdfb0843544440cb1feebd5b3b223e62 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Mon, 11 Mar 2024 12:21:46 -0500 Subject: [PATCH] lib: open-amp: Use struct fw_resource_table type instead of void The type of the resource table is known, casting to and from void* only hides this type which can prevent the compiler from giving helpful warnings. One warning would have been the accidental use of "st_resource_table" in a cast, a struct which does not exist. Use the fw_resource_table type when dealing with resource tables. Signed-off-by: Andrew Davis --- lib/open-amp/resource_table.c | 4 ++-- lib/open-amp/resource_table.h | 14 +++++++------- .../subsys/ipc/openamp_rsc_table/src/main_remote.c | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/open-amp/resource_table.c b/lib/open-amp/resource_table.c index 8229a213ed56..53e38f185f0a 100644 --- a/lib/open-amp/resource_table.c +++ b/lib/open-amp/resource_table.c @@ -74,8 +74,8 @@ static struct fw_resource_table __resource resource_table = { #endif }; -void rsc_table_get(void **table_ptr, int *length) +void rsc_table_get(struct fw_resource_table **table_ptr, int *length) { - *table_ptr = (void *)&resource_table; + *table_ptr = &resource_table; *length = sizeof(resource_table); } diff --git a/lib/open-amp/resource_table.h b/lib/open-amp/resource_table.h index f3254ebb676a..dc577fafa7ed 100644 --- a/lib/open-amp/resource_table.h +++ b/lib/open-amp/resource_table.h @@ -56,23 +56,23 @@ struct fw_resource_table { #endif } METAL_PACKED_END; -void rsc_table_get(void **table_ptr, int *length); +void rsc_table_get(struct fw_resource_table **table_ptr, int *length); #if (CONFIG_OPENAMP_RSC_TABLE_NUM_RPMSG_BUFF > 0) -inline struct fw_rsc_vdev *rsc_table_to_vdev(void *rsc_table) +inline struct fw_rsc_vdev *rsc_table_to_vdev(struct fw_resource_table *rsc_table) { - return &((struct fw_resource_table *)rsc_table)->vdev; + return &rsc_table->vdev; } -inline struct fw_rsc_vdev_vring *rsc_table_get_vring0(void *rsc_table) +inline struct fw_rsc_vdev_vring *rsc_table_get_vring0(struct fw_resource_table *rsc_table) { - return &((struct fw_resource_table *)rsc_table)->vring0; + return &rsc_table->vring0; } -inline struct fw_rsc_vdev_vring *rsc_table_get_vring1(void *rsc_table) +inline struct fw_rsc_vdev_vring *rsc_table_get_vring1(struct fw_resource_table *rsc_table) { - return &((struct fw_resource_table *)rsc_table)->vring1; + return &rsc_table->vring1; } #endif 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 8bc1a475d081..c8d12092ace0 100644 --- a/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c +++ b/samples/subsys/ipc/openamp_rsc_table/src/main_remote.c @@ -53,6 +53,7 @@ static const struct device *const ipm_handle = DEVICE_DT_GET(DT_CHOSEN(zephyr_ipc)); static metal_phys_addr_t shm_physmap = SHM_START_ADDR; +static metal_phys_addr_t rsc_tab_physmap; static struct metal_io_region shm_io_data; /* shared memory */ static struct metal_io_region rsc_io_data; /* rsc_table memory */ @@ -67,7 +68,7 @@ static struct metal_io_region *shm_io = &shm_io_data; static struct metal_io_region *rsc_io = &rsc_io_data; static struct rpmsg_virtio_device rvdev; -static void *rsc_table; +static struct fw_resource_table *rsc_table; static struct rpmsg_device *rpdev; static char rx_sc_msg[20]; /* should receive "Hello world!" */ @@ -139,7 +140,6 @@ int mailbox_notify(void *priv, uint32_t id) int platform_init(void) { - void *rsc_tab_addr; int rsc_size; struct metal_init_params metal_params = METAL_INIT_DEFAULTS; int status; @@ -155,11 +155,11 @@ int platform_init(void) SHM_SIZE, -1, 0, NULL); /* declare resource table region */ - rsc_table_get(&rsc_tab_addr, &rsc_size); - rsc_table = (struct st_resource_table *)rsc_tab_addr; + rsc_table_get(&rsc_table, &rsc_size); + rsc_tab_physmap = (uintptr_t)rsc_table; metal_io_init(rsc_io, rsc_table, - (metal_phys_addr_t *)rsc_table, rsc_size, -1, 0, NULL); + &rsc_tab_physmap, rsc_size, -1, 0, NULL); /* setup IPM */ if (!device_is_ready(ipm_handle)) {