Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for imx8mp_evk M7 core for openamp_rsc_table sample #78585

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONFIG_LOG_PRINTK=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_16=n
CONFIG_IPM_IMX_MAX_DATA_SIZE_4=y
CONFIG_OPENAMP_WITH_DCACHE=y
CONFIG_IPM_IMX_FW_READY_REPLY=y
CONFIG_LOG=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_LOG_DEFAULT_LEVEL=0
CONFIG_LOG_MODE_MINIMAL=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2024 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
/*
* shared memory reserved for the inter-processor communication
*/
zephyr,ipc_shm = &shram;
zephyr,ipc = &mailbox0;
};

shram: memory@55000000 {
compatible = "mmio-sram";
reg = <0x55000000 0x500000>;
};
};

&mailbox0 {
status = "okay";
};
21 changes: 15 additions & 6 deletions samples/subsys/ipc/openamp_rsc_table/src/main_remote.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, STMICROELECTRONICS
* Copyright 2024 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -63,6 +64,10 @@ struct rpmsg_rcv_msg {
size_t len;
};

struct ipm_channel {
uint8_t channel_id;
};

static struct metal_io_region *shm_io = &shm_io_data;

static struct metal_io_region *rsc_io = &rsc_io_data;
Expand All @@ -78,14 +83,19 @@ static struct rpmsg_rcv_msg sc_msg = {.data = rx_sc_msg};
static struct rpmsg_endpoint tty_ept;
static struct rpmsg_rcv_msg tty_msg;

static struct ipm_channel app_ipm_channel;

static K_SEM_DEFINE(data_sem, 0, 1);
static K_SEM_DEFINE(data_sc_sem, 0, 1);
static K_SEM_DEFINE(data_tty_sem, 0, 1);

static void platform_ipm_callback(const struct device *dev, void *context,
uint32_t id, volatile void *data)
{
struct ipm_channel *ipm_ch = (struct ipm_channel *)context;

LOG_DBG("%s: msg received from mb %d", __func__, id);
ipm_ch->channel_id = id;
k_sem_give(&data_sem);
}

Expand Down Expand Up @@ -130,10 +140,10 @@ static void new_service_cb(struct rpmsg_device *rdev, const char *name,

int mailbox_notify(void *priv, uint32_t id)
{
ARG_UNUSED(priv);
struct ipm_channel *ipm_ch = (struct ipm_channel *)priv;

LOG_DBG("%s: msg received", __func__);
ipm_send(ipm_handle, 0, id, NULL, 0);
ipm_send(ipm_handle, 0, ipm_ch->channel_id, NULL, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy past from #78228 (comment):

This probably introduces a regression on existing platforms. I can see two assumptions in this patch:

  1. The IPM channel ID used for RX and TX is the same. The initial implementation is that
    channel id 0 is used for RX and channel id 1 is usedfor Tx.

  2. You assume that we receive a first message before sending the first one (ipm_ch->channel_id is set in platform_ipm_callback()), which seems like a dangerous assumption to me.

Some simple solutions could be to put the code under platform configuration or, perhaps more generically, to define CONFIG_IPM_RX_CHANNEL_ID and CONFIG_IPM_TX_CHANNEL_ID to configure the channel IDs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using the CONFIG_ definitions would work for us.


return 0;
}
Expand Down Expand Up @@ -167,7 +177,7 @@ int platform_init(void)
return -1;
}

ipm_register_callback(ipm_handle, platform_ipm_callback, NULL);
ipm_register_callback(ipm_handle, platform_ipm_callback, (void *)&app_ipm_channel);

status = ipm_set_enabled(ipm_handle, 1);
if (status) {
Expand Down Expand Up @@ -195,9 +205,8 @@ platform_create_rpmsg_vdev(unsigned int vdev_index,
struct virtio_device *vdev;
int ret;

vdev = rproc_virtio_create_vdev(VIRTIO_DEV_DEVICE, VDEV_ID,
rsc_table_to_vdev(rsc_table),
rsc_io, NULL, mailbox_notify, NULL);
vdev = rproc_virtio_create_vdev(VIRTIO_DEV_DEVICE, VDEV_ID, rsc_table_to_vdev(rsc_table),
rsc_io, (void *)&app_ipm_channel, mailbox_notify, NULL);

if (!vdev) {
LOG_ERR("failed to create vdev");
Expand Down
Loading