Skip to content

Commit

Permalink
lib: open-amp: Use struct fw_resource_table type instead of void
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
glneo authored and nashif committed May 24, 2024
1 parent 4c5eb92 commit 39863b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/open-amp/resource_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
14 changes: 7 additions & 7 deletions lib/open-amp/resource_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions samples/subsys/ipc/openamp_rsc_table/src/main_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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!" */
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit 39863b6

Please sign in to comment.