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

Rptun framework update and related driver update #13526

Merged
merged 22 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a27e014
nuttx/dirvers: Add secure rptun file
Aug 10, 2023
317d48c
rptun: use local rx virtqueue idx to resolve remote low power
GUIDINGLI Apr 30, 2022
dd9eac5
rptun/pm: add check to rptun_pm_callback() incase of start early
GUIDINGLI Jan 5, 2023
58e5230
rptun/pm: use pm_wakelock
GUIDINGLI Jun 16, 2022
e21a27d
rptun: add RPTUN_PM_AUTORELAX method.
GUIDINGLI Apr 7, 2023
31a98d9
drivers/rptun: flush the image memory when read from the file system
CV-Bowen Mar 28, 2024
0ca81db
rptun: use detail name for pm wakelock
GUIDINGLI Jun 20, 2022
b950142
rptun: BUG fix, should not destory the semaphore twice
CV-Bowen Sep 18, 2024
36b1570
rptun/rptun_dump: remove unused rptun_dump.c
CV-Bowen Sep 18, 2024
e7f4a2e
rptun: add timeout to wait_tx_buffer callback
GUIDINGLI Apr 27, 2022
92cd7cf
rptun: Rename rptun_panic_ to rptun_panic
xiaoxiang781216 Feb 18, 2024
8a5424c
rptun: rptun pm and rptun dump support cacheable memory
CV-Bowen Feb 23, 2024
0d072ff
drivers/rptun/rptun.c: move headrx out of CONFIG_RPTUN_PM
CV-Bowen Aug 3, 2024
9b23ecc
rptun_ivshmem.c: Replace work queue with wdog
wyr-7 May 22, 2024
f3a2fd3
sim/sim_rptun: add 64-bit support for sim_rptun
CV-Bowen Jun 11, 2024
d18c7f3
rptun.c/rpmsg_virtio.c: move panic logic from chip to rptun/rpmsg_virtio
wyr-7 Jul 26, 2024
91a4d5c
sim_rptun.c: remove sim_rptun_panic
wyr-7 Aug 5, 2024
9d65886
rptun/rpmsg_virtio: remove chip cmd and reuse the common ones
wyr-7 Aug 6, 2024
4acb838
rptun: move rptun cmd definition before the resource table
CV-Bowen Aug 14, 2024
ba8fcbd
rptun: fix memleak on failure
XuNeo Aug 23, 2024
68b1588
rptun/rptun_ivshmem:add restart cmd to reboot slave
Aug 20, 2024
2056b76
include/nuttx/rptun/rptun.h: change offset type to uint32_t
CV-Bowen Dec 20, 2023
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
4 changes: 2 additions & 2 deletions arch/sim/src/sim/sim_rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ struct sim_rpmsg_virtio_shmem_s
volatile uintptr_t base;
volatile unsigned int seqs;
volatile unsigned int seqm;
volatile unsigned int cmds;
volatile unsigned int cmdm;
volatile unsigned int boots;
volatile unsigned int bootm;
struct rpmsg_virtio_rsc_s rsc;
Expand Down Expand Up @@ -115,6 +113,8 @@ sim_rpmsg_virtio_get_resource(struct rpmsg_virtio_s *dev)
rsc->rpmsg_vring1.num = 8;
rsc->config.r2h_buf_size = 2048;
rsc->config.h2r_buf_size = 2048;
rsc->cmd_master = 0;
rsc->cmd_slave = 0;

priv->shmem->base = (uintptr_t)priv->shmem;
}
Expand Down
74 changes: 37 additions & 37 deletions arch/sim/src/sim/sim_rptun.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
* Pre-processor Definitions
****************************************************************************/

#define SIM_RPTUN_STOP 0x1
#define SIM_RPTUN_PANIC 0x2
#define SIM_RPTUN_MASK 0xffff
#define SIM_RPTUN_SHIFT 16
#define SIM_RPTUN_WORK_DELAY 1

/* Status byte for master/slave to report progress */
Expand All @@ -55,8 +51,6 @@ struct sim_rptun_shmem_s
volatile uint64_t base;
volatile uint32_t seqs;
volatile uint32_t seqm;
volatile uint32_t cmds;
volatile uint32_t cmdm;
volatile uint32_t boots;
volatile uint32_t bootm;
struct rptun_rsc_s rsc;
Expand All @@ -72,6 +66,7 @@ struct sim_rptun_dev_s
uint32_t seq;
struct sim_rptun_shmem_s *shmem;
struct simple_addrenv_s addrenv[2];
struct rptun_addrenv_s raddrenv[2];
char cpuname[RPMSG_NAME_SIZE + 1];
char shmemname[RPMSG_NAME_SIZE + 1];
pid_t pid;
Expand All @@ -93,26 +88,43 @@ static const char *sim_rptun_get_cpuname(struct rptun_dev_s *dev)
return priv->cpuname;
}

static const struct rptun_addrenv_s *
sim_rptun_get_addrenv(struct rptun_dev_s *dev)
{
struct sim_rptun_dev_s *priv = container_of(dev,
struct sim_rptun_dev_s, rptun);

return &priv->raddrenv[0];
}

static struct rptun_rsc_s *
sim_rptun_get_resource(struct rptun_dev_s *dev)
{
struct sim_rptun_dev_s *priv = container_of(dev,
struct sim_rptun_dev_s, rptun);
struct rptun_cmd_s *cmd;

priv->shmem = host_allocshmem(priv->shmemname,
sizeof(*priv->shmem));

if (!priv->shmem)
{
return NULL;
}

cmd = RPTUN_RSC2CMD(&priv->shmem->rsc);

priv->raddrenv[0].da = 0;
priv->raddrenv[0].size = sizeof(*priv->shmem);

if (priv->master)
{
struct rptun_rsc_s *rsc = &priv->shmem->rsc;

memset(priv->shmem->buf, 0, sizeof(priv->shmem->buf));
memset(rsc, 0, sizeof(struct rptun_rsc_s));

priv->raddrenv[0].pa = (uintptr_t)priv->shmem;

rsc->rsc_tbl_hdr.ver = 1;
rsc->rsc_tbl_hdr.num = 1;
rsc->offset[0] = offsetof(struct rptun_rsc_s,
Expand All @@ -135,6 +147,7 @@ sim_rptun_get_resource(struct rptun_dev_s *dev)
rsc->config.r2h_buf_size = 0x800;
rsc->config.h2r_buf_size = 0x800;

cmd->cmd_slave = 0;
priv->shmem->base = (uintptr_t)priv->shmem;

/* The master notifies its slave when it starts again */
Expand Down Expand Up @@ -164,11 +177,15 @@ sim_rptun_get_resource(struct rptun_dev_s *dev)
usleep(1000);
}

priv->shmem->boots = SIM_RPTUN_STATUS_OK;
cmd->cmd_master = 0;

priv->addrenv[0].va = (uintptr_t)priv->shmem;
priv->addrenv[0].pa = priv->shmem->base;
priv->addrenv[0].size = sizeof(*priv->shmem);
priv->raddrenv[0].pa = (uintptr_t)priv->shmem->base;

priv->shmem->boots = SIM_RPTUN_STATUS_OK;

priv->addrenv[0].va = (uintptr_t)priv->shmem;
priv->addrenv[0].pa = priv->shmem->base;
priv->addrenv[0].size = sizeof(*priv->shmem);

simple_addrenv_initialize(&priv->addrenv[0]);
}
Expand Down Expand Up @@ -220,12 +237,13 @@ static int sim_rptun_stop(struct rptun_dev_s *dev)
{
struct sim_rptun_dev_s *priv = container_of(dev,
struct sim_rptun_dev_s, rptun);
struct rptun_cmd_s *cmd = RPTUN_RSC2CMD(&priv->shmem->rsc);

/* Don't send SIM_RPTUN_STOP when slave recovery */
/* Don't send RPTUN_CMD_STOP when slave recovery */

if (priv->shmem->boots & SIM_RPTUN_STATUS_OK)
{
priv->shmem->cmdm = SIM_RPTUN_STOP << SIM_RPTUN_SHIFT;
cmd->cmd_master = RPTUN_CMD(RPTUN_CMD_STOP, 0);
}

if ((priv->master & SIM_RPTUN_BOOT) && priv->pid > 0)
Expand Down Expand Up @@ -274,33 +292,15 @@ static int sim_rptun_register_callback(struct rptun_dev_s *dev,
return 0;
}

static void sim_rptun_panic(struct rptun_dev_s *dev)
{
struct sim_rptun_dev_s *priv = container_of(dev,
struct sim_rptun_dev_s, rptun);

if (priv->master)
{
priv->shmem->cmdm = SIM_RPTUN_PANIC << SIM_RPTUN_SHIFT;
}
else
{
priv->shmem->cmds = SIM_RPTUN_PANIC << SIM_RPTUN_SHIFT;
}
}

static void sim_rptun_check_cmd(struct sim_rptun_dev_s *priv)
{
unsigned int cmd = priv->master ? priv->shmem->cmds : priv->shmem->cmdm;
struct rptun_cmd_s *rcmd = RPTUN_RSC2CMD(&priv->shmem->rsc);
uint32_t cmd = priv->master ? rcmd->cmd_slave : rcmd->cmd_master;

switch ((cmd >> SIM_RPTUN_SHIFT) & SIM_RPTUN_MASK)
switch (RPTUN_GET_CMD(cmd))
{
case SIM_RPTUN_STOP:
host_abort(cmd & SIM_RPTUN_MASK);
break;

case SIM_RPTUN_PANIC:
PANIC();
case RPTUN_CMD_STOP:
host_abort(RPTUN_GET_CMD_VAL(cmd));
break;

default:
Expand Down Expand Up @@ -365,14 +365,14 @@ static void sim_rptun_work(wdparm_t arg)
static const struct rptun_ops_s g_sim_rptun_ops =
{
.get_cpuname = sim_rptun_get_cpuname,
.get_addrenv = sim_rptun_get_addrenv,
.get_resource = sim_rptun_get_resource,
.is_autostart = sim_rptun_is_autostart,
.is_master = sim_rptun_is_master,
.start = sim_rptun_start,
.stop = sim_rptun_stop,
.notify = sim_rptun_notify,
.register_callback = sim_rptun_register_callback,
.panic = sim_rptun_panic,
};

/****************************************************************************
Expand Down
50 changes: 50 additions & 0 deletions drivers/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#define RPMSG_VIRTIO_TIMEOUT_MS 20
#define RPMSG_VIRTIO_NOTIFYID 0

#define RPMSG_VIRTIO_CMD_PANIC 0x1

/****************************************************************************
* Private Types
****************************************************************************/
Expand All @@ -69,6 +71,7 @@ struct rpmsg_virtio_priv_s

static int rpmsg_virtio_wait(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem);
static int rpmsg_virtio_post(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem);
static void rpmsg_virtio_panic(FAR struct rpmsg_s *rpmsg);
static void rpmsg_virtio_dump(FAR struct rpmsg_s *rpmsg);
static FAR const char *
rpmsg_virtio_get_local_cpuname(FAR struct rpmsg_s *rpmsg);
Expand Down Expand Up @@ -97,6 +100,7 @@ static const struct rpmsg_ops_s g_rpmsg_virtio_ops =
{
.wait = rpmsg_virtio_wait,
.post = rpmsg_virtio_post,
.panic = rpmsg_virtio_panic,
.dump = rpmsg_virtio_dump,
.get_local_cpuname = rpmsg_virtio_get_local_cpuname,
.get_cpuname = rpmsg_virtio_get_cpuname,
Expand Down Expand Up @@ -267,6 +271,23 @@ static int rpmsg_virtio_post(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem)
return ret;
}

static void rpmsg_virtio_panic(FAR struct rpmsg_s *rpmsg)
{
FAR struct rpmsg_virtio_priv_s *priv =
(FAR struct rpmsg_virtio_priv_s *)rpmsg;

if (RPMSG_VIRTIO_IS_MASTER(priv->dev))
{
priv->rsc->cmd_master = RPMSG_VIRTIO_CMD_PANIC;
}
else
{
priv->rsc->cmd_slave = RPMSG_VIRTIO_CMD_PANIC;
}

rpmsg_virtio_notify(priv->vdev.vrings_info->vq);
}

#ifdef CONFIG_OPENAMP_DEBUG
static int rpmsg_virtio_buffer_nused(FAR struct rpmsg_virtio_device *rvdev,
bool rx)
Expand Down Expand Up @@ -430,13 +451,42 @@ static void rpmsg_virtio_wakeup_rx(FAR struct rpmsg_virtio_priv_s *priv)
}
}

static void rpmsg_virtio_command(FAR struct rpmsg_virtio_priv_s *priv)
{
FAR struct rpmsg_virtio_rsc_s *rsc = priv->rsc;
uint32_t cmd;

if (RPMSG_VIRTIO_IS_MASTER(priv->dev))
{
cmd = rsc->cmd_slave;
rsc->cmd_slave = 0;
}
else
{
cmd = rsc->cmd_master;
rsc->cmd_master = 0;
}

switch (cmd)
{
case RPMSG_VIRTIO_CMD_PANIC:
PANIC();
break;

default:
break;
}
}

static int rpmsg_virtio_callback(FAR void *arg, uint32_t vqid)
{
FAR struct rpmsg_virtio_priv_s *priv = arg;
FAR struct rpmsg_virtio_device *rvdev = &priv->rvdev;
FAR struct virtio_device *vdev = rvdev->vdev;
FAR struct virtqueue *rvq = rvdev->rvq;

rpmsg_virtio_command(priv);

if (vqid == RPMSG_VIRTIO_NOTIFY_ALL ||
vqid == vdev->vrings_info[rvq->vq_queue_index].notifyid)
{
Expand Down
4 changes: 2 additions & 2 deletions drivers/rpmsg/rpmsg_virtio_ivshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ struct rpmsg_virtio_ivshmem_mem_s
volatile uint64_t basem;
volatile uint32_t seqs;
volatile uint32_t seqm;
volatile uint32_t cmds;
volatile uint32_t cmdm;
struct rpmsg_virtio_rsc_s rsc;
};

Expand Down Expand Up @@ -148,6 +146,8 @@ rpmsg_virtio_ivshmem_get_resource(FAR struct rpmsg_virtio_s *dev)
rsc->rpmsg_vring1.num = CONFIG_RPMSG_VIRTIO_IVSHMEM_BUFFNUM;
rsc->config.r2h_buf_size = CONFIG_RPMSG_VIRTIO_IVSHMEM_BUFFSIZE;
rsc->config.h2r_buf_size = CONFIG_RPMSG_VIRTIO_IVSHMEM_BUFFSIZE;
rsc->cmd_master = 0;
rsc->cmd_slave = 0;

priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem;
}
Expand Down
16 changes: 16 additions & 0 deletions drivers/rptun/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ menuconfig RPTUN

if RPTUN

config RPTUN_SECURE
bool "rptun secure support"
default n
---help---
This is a rptun driver for communications between secure (TEE)
and non-secure (REE) environments. With this driver, REE and
TEE and communicate with each other by using the native rpmsg
or various Rpmsg services have been implemented in NuttX.

config RPTUN_IVSHMEM
bool "rptun ivshmem support"
default n
Expand Down Expand Up @@ -69,4 +78,11 @@ config RPTUN_PM
goto RAM-retention mode, can't access from another CPU.
So, we provide this method to resolve this.

config RPTUN_PM_AUTORELAX
bool "rptun pm autorelax"
depends on RPTUN_PM
default y
---help---
use wd_timer to auto relax pm

endif # RPTUN
4 changes: 4 additions & 0 deletions drivers/rptun/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ ifeq ($(CONFIG_RPTUN_IVSHMEM),y)
CSRCS += rptun_ivshmem.c
endif

ifeq ($(CONFIG_RPTUN_SECURE),y)
CSRCS += rptun_secure.c
endif

DEPPATH += --dep-path rptun
VPATH += :rptun
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)drivers$(DELIM)rptun
Expand Down
Loading
Loading