diff --git a/arch/sim/src/sim/sim_rpmsg_virtio.c b/arch/sim/src/sim/sim_rpmsg_virtio.c index e06c6f11fcd0b..e8362d225e431 100644 --- a/arch/sim/src/sim/sim_rpmsg_virtio.c +++ b/arch/sim/src/sim/sim_rpmsg_virtio.c @@ -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; @@ -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; } diff --git a/arch/sim/src/sim/sim_rptun.c b/arch/sim/src/sim/sim_rptun.c index fa55d282dc433..447cf9582650a 100644 --- a/arch/sim/src/sim/sim_rptun.c +++ b/arch/sim/src/sim/sim_rptun.c @@ -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 */ @@ -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; @@ -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; @@ -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, @@ -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 */ @@ -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]); } @@ -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) @@ -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: @@ -365,6 +365,7 @@ 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, @@ -372,7 +373,6 @@ static const struct rptun_ops_s g_sim_rptun_ops = .stop = sim_rptun_stop, .notify = sim_rptun_notify, .register_callback = sim_rptun_register_callback, - .panic = sim_rptun_panic, }; /**************************************************************************** diff --git a/drivers/rpmsg/rpmsg_virtio.c b/drivers/rpmsg/rpmsg_virtio.c index e192145b054df..da1f815f687e2 100644 --- a/drivers/rpmsg/rpmsg_virtio.c +++ b/drivers/rpmsg/rpmsg_virtio.c @@ -45,6 +45,8 @@ #define RPMSG_VIRTIO_TIMEOUT_MS 20 #define RPMSG_VIRTIO_NOTIFYID 0 +#define RPMSG_VIRTIO_CMD_PANIC 0x1 + /**************************************************************************** * Private Types ****************************************************************************/ @@ -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); @@ -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, @@ -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) @@ -430,6 +451,33 @@ 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; @@ -437,6 +485,8 @@ static int rpmsg_virtio_callback(FAR void *arg, uint32_t vqid) 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) { diff --git a/drivers/rpmsg/rpmsg_virtio_ivshmem.c b/drivers/rpmsg/rpmsg_virtio_ivshmem.c index a08d1057edbd5..7004d1d29265c 100644 --- a/drivers/rpmsg/rpmsg_virtio_ivshmem.c +++ b/drivers/rpmsg/rpmsg_virtio_ivshmem.c @@ -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; }; @@ -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; } diff --git a/drivers/rptun/Kconfig b/drivers/rptun/Kconfig index d9f52cd365c87..9dfc93ac2e9bf 100644 --- a/drivers/rptun/Kconfig +++ b/drivers/rptun/Kconfig @@ -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 @@ -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 diff --git a/drivers/rptun/Make.defs b/drivers/rptun/Make.defs index e4afb1657b8b7..05969d1f0ff24 100644 --- a/drivers/rptun/Make.defs +++ b/drivers/rptun/Make.defs @@ -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 diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c index f80af913965f1..144bae67a4fd8 100644 --- a/drivers/rptun/rptun.c +++ b/drivers/rptun/rptun.c @@ -52,7 +52,7 @@ # define ALIGN_UP(s, a) (((s) + (a) - 1) & ~((a) - 1)) #endif -#define RPTUNIOC_NONE 0 +#define RPTUN_TIMEOUT_MS 20 /**************************************************************************** * Private Types @@ -68,8 +68,10 @@ struct rptun_priv_s sem_t semtx; sem_t semrx; pid_t tid; + uint16_t headrx; #ifdef CONFIG_RPTUN_PM - bool stay; + struct pm_wakelock_s wakelock; + struct wdog_s wdog; #endif }; @@ -123,7 +125,7 @@ static int rptun_wait(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem); static int rptun_post(FAR struct rpmsg_s *rpmsg, FAR sem_t *sem); static int rptun_ioctl(FAR struct rpmsg_s *rpmsg, int cmd, unsigned long arg); -static void rptun_panic_(FAR struct rpmsg_s *rpmsg); +static void rptun_panic(FAR struct rpmsg_s *rpmsg); static void rptun_dump(FAR struct rpmsg_s *rpmsg); static FAR const char *rptun_get_local_cpuname(FAR struct rpmsg_s *rpmsg); static FAR const char *rptun_get_cpuname(FAR struct rpmsg_s *rpmsg); @@ -161,7 +163,7 @@ static const struct rpmsg_ops_s g_rptun_rpmsg_ops = rptun_wait, rptun_post, rptun_ioctl, - rptun_panic_, + rptun_panic, rptun_dump, rptun_get_local_cpuname, rptun_get_cpuname, @@ -176,9 +178,20 @@ static const struct rpmsg_ops_s g_rptun_rpmsg_ops = static int rptun_buffer_nused(FAR struct rpmsg_virtio_device *rvdev, bool rx) { FAR struct virtqueue *vq = rx ? rvdev->rvq : rvdev->svq; - uint16_t nused = vq->vq_ring.avail->idx - vq->vq_ring.used->idx; + uint16_t nused; + bool is_host = rpmsg_virtio_get_role(rvdev) == RPMSG_HOST; - if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx) + if (is_host) + { + RPTUN_INVALIDATE(vq->vq_ring.used->idx); + } + else + { + RPTUN_INVALIDATE(vq->vq_ring.avail->idx); + } + + nused = vq->vq_ring.avail->idx - vq->vq_ring.used->idx; + if (is_host ^ rx) { return nused; } @@ -200,32 +213,106 @@ static void rptun_wakeup_tx(FAR struct rptun_priv_s *priv) } #ifdef CONFIG_RPTUN_PM + +#ifdef CONFIG_RPTUN_PM_AUTORELAX +static void rptun_pm_callback(wdparm_t arg) +{ + FAR struct rptun_priv_s *priv = (FAR struct rptun_priv_s *)arg; + + if (priv->rproc.state != RPROC_RUNNING) + { + return; + } + + if (rptun_buffer_nused(&priv->rvdev, false)) + { + rptun_wakeup_tx(priv); + + wd_start(&priv->wdog, MSEC2TICK(RPTUN_TIMEOUT_MS), + rptun_pm_callback, (wdparm_t)priv); + } + else + { + pm_wakelock_relax(&priv->wakelock); + } +} +#endif + static inline void rptun_pm_action(FAR struct rptun_priv_s *priv, bool stay) { irqstate_t flags; + int count; flags = enter_critical_section(); - if (stay && !priv->stay) + count = pm_wakelock_staycount(&priv->wakelock); + if (stay && count == 0) { - pm_stay(PM_IDLE_DOMAIN, PM_IDLE); - priv->stay = true; + pm_wakelock_stay(&priv->wakelock); +#ifdef CONFIG_RPTUN_PM_AUTORELAX + wd_start(&priv->wdog, MSEC2TICK(RPTUN_TIMEOUT_MS), + rptun_pm_callback, (wdparm_t)priv); +#endif } - if (!stay && priv->stay && !rptun_buffer_nused(&priv->rvdev, false)) +#ifndef CONFIG_RPTUN_PM_AUTORELAX + if (!stay && count > 0 && rptun_buffer_nused(&priv->rvdev, false) == 0) { - pm_relax(PM_IDLE_DOMAIN, PM_IDLE); - priv->stay = false; + pm_wakelock_relax(&priv->wakelock); } +#endif leave_critical_section(flags); } +static inline bool rptun_available_rx(FAR struct rptun_priv_s *priv) +{ + FAR struct rpmsg_virtio_device *rvdev = &priv->rvdev; + FAR struct virtqueue *rvq = rvdev->rvq; + + if (priv->rproc.state != RPROC_RUNNING) + { + return false; + } + + if (rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) + { + return priv->headrx != rvq->vq_used_cons_idx; + } + else + { + return priv->headrx != rvq->vq_available_idx; + } +} + #else # define rptun_pm_action(priv, stay) +# define rptun_available_rx(priv) true #endif +static inline void rptun_update_rx(FAR struct rptun_priv_s *priv) +{ + FAR struct rpmsg_virtio_device *rvdev = &priv->rvdev; + FAR struct virtqueue *rvq = rvdev->rvq; + + if (priv->rproc.state != RPROC_RUNNING) + { + return; + } + + if (rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) + { + RPTUN_INVALIDATE(rvq->vq_ring.used->idx); + priv->headrx = rvq->vq_ring.used->idx; + } + else + { + RPTUN_INVALIDATE(rvq->vq_ring.avail->idx); + priv->headrx = rvq->vq_ring.avail->idx; + } +} + static void rptun_start_worker(FAR void *arg) { FAR struct rptun_priv_s *priv = arg; @@ -240,7 +327,10 @@ static void rptun_worker(FAR void *arg) { FAR struct rptun_priv_s *priv = arg; - remoteproc_get_notification(&priv->rproc, RPTUN_NOTIFY_ALL); + if (rptun_available_rx(priv)) + { + remoteproc_get_notification(&priv->rproc, RPTUN_NOTIFY_ALL); + } } static int rptun_thread(int argc, FAR char *argv[]) @@ -280,6 +370,33 @@ static bool rptun_is_recursive(FAR struct rptun_priv_s *priv) return nxsched_gettid() == priv->tid; } +static void rptun_command(FAR struct rptun_priv_s *priv) +{ + FAR struct rptun_cmd_s *rptun_cmd = RPTUN_RSC2CMD(priv->rproc.rsc_table); + uint32_t cmd; + + if (RPTUN_IS_MASTER(priv->dev)) + { + cmd = rptun_cmd->cmd_slave; + rptun_cmd->cmd_slave = 0; + } + else + { + cmd = rptun_cmd->cmd_master; + rptun_cmd->cmd_master = 0; + } + + switch (RPTUN_GET_CMD(cmd)) + { + case RPTUN_CMD_PANIC: + PANIC(); + break; + + default: + break; + } +} + static int rptun_callback(FAR void *arg, uint32_t vqid) { FAR struct rptun_priv_s *priv = arg; @@ -288,13 +405,13 @@ static int rptun_callback(FAR void *arg, uint32_t vqid) FAR struct virtqueue *svq = rvdev->svq; FAR struct virtqueue *rvq = rvdev->rvq; + rptun_command(priv); + if (vqid == RPTUN_NOTIFY_ALL || vqid == vdev->vrings_info[rvq->vq_queue_index].notifyid) { - if (rptun_buffer_nused(&priv->rvdev, true)) - { - rptun_wakeup_rx(priv); - } + rptun_update_rx(priv); + rptun_wakeup_rx(priv); } if (vqid == RPTUN_NOTIFY_ALL || @@ -362,10 +479,11 @@ static int rptun_notify(FAR struct remoteproc *rproc, uint32_t id) { FAR struct rptun_priv_s *priv = rproc->priv; FAR struct rpmsg_virtio_device *rvdev = &priv->rvdev; - FAR struct virtqueue *vq = rvdev->svq; + FAR struct virtio_device *vdev = rvdev->vdev; + FAR struct virtqueue *svq = rvdev->svq; - if (rvdev->vdev && vq && - rvdev->vdev->vrings_info[vq->vq_queue_index].notifyid == id) + if (priv->rproc.state == RPROC_RUNNING && + id == vdev->vrings_info[svq->vq_queue_index].notifyid) { rptun_pm_action(priv, true); } @@ -424,7 +542,7 @@ static int rptun_notify_wait(FAR struct remoteproc *rproc, uint32_t id) /* Wait to wakeup */ - nxsem_wait(&priv->semtx); + nxsem_tickwait(&priv->semtx, MSEC2TICK(RPTUN_TIMEOUT_MS)); rptun_worker(priv); return 0; @@ -448,12 +566,16 @@ static void rptun_dump_buffer(FAR struct rpmsg_virtio_device *rvdev, { if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx) { + RPTUN_INVALIDATE(vq->vq_ring.used->idx); desc_idx = (vq->vq_ring.used->idx + i) & (vq->vq_nentries - 1); + RPTUN_INVALIDATE(vq->vq_ring.avail->ring[desc_idx]); desc_idx = vq->vq_ring.avail->ring[desc_idx]; } else { + RPTUN_INVALIDATE(vq->vq_ring.avail->idx); desc_idx = (vq->vq_ring.avail->idx + i) & (vq->vq_nentries - 1); + RPTUN_INVALIDATE(vq->vq_ring.used->ring[desc_idx].id); desc_idx = vq->vq_ring.used->ring[desc_idx].id; } @@ -553,11 +675,27 @@ static int rptun_ioctl(FAR struct rpmsg_s *rpmsg, int cmd, unsigned long arg) return ret; } -static void rptun_panic_(FAR struct rpmsg_s *rpmsg) +static void rptun_panic(FAR struct rpmsg_s *rpmsg) { FAR struct rptun_priv_s *priv = (FAR struct rptun_priv_s *)rpmsg; + FAR struct rptun_cmd_s *cmd = RPTUN_RSC2CMD(priv->rproc.rsc_table); + + if (priv->dev->ops->panic != NULL) + { + RPTUN_PANIC(priv->dev); + return; + } + + if (RPTUN_IS_MASTER(priv->dev)) + { + cmd->cmd_master = RPTUN_CMD(RPTUN_CMD_PANIC, 0); + } + else + { + cmd->cmd_slave = RPTUN_CMD(RPTUN_CMD_PANIC, 0); + } - RPTUN_PANIC(priv->dev); + rptun_notify(&priv->rproc, RPTUN_NOTIFY_ALL); } static void rptun_dump(FAR struct rpmsg_s *rpmsg) @@ -569,6 +707,9 @@ static void rptun_dump(FAR struct rpmsg_s *rpmsg) FAR struct metal_list *node; bool needlock = true; + metal_log(METAL_LOG_EMERGENCY, "Remote: %s headrx %d\n", + RPTUN_GET_CPUNAME(priv->dev), priv->headrx); + if (!rvdev->vdev) { return; @@ -612,10 +753,6 @@ static void rptun_dump(FAR struct rpmsg_s *rpmsg) { metal_mutex_release(&rdev->lock); } - -#ifdef CONFIG_RPTUN_PM - metal_log(METAL_LOG_EMERGENCY, "rptun headrx %d\n", priv->headrx); -#endif } static FAR const char *rptun_get_local_cpuname(FAR struct rpmsg_s *rpmsg) @@ -811,6 +948,8 @@ static int rptun_dev_start(FAR struct remoteproc *rproc) /* Register callback to mbox for receiving remote message */ RPTUN_REGISTER_CALLBACK(priv->dev, rptun_callback, priv); + + rptun_update_rx(priv); rptun_wakeup_rx(priv); /* Broadcast device_created to all registers */ @@ -883,7 +1022,13 @@ static int rptun_store_open(FAR void *store_, *img_data = store->buf; - return file_read(&store->file, store->buf, len); + ret = file_read(&store->file, store->buf, len); + if (ret < 0) + { + file_close(&store->file); + } + + return ret; } static void rptun_store_close(FAR void *store_) @@ -902,6 +1047,7 @@ static int rptun_store_load(FAR void *store_, size_t offset, { FAR struct rptun_store_s *store = store_; FAR char *tmp; + ssize_t ret; if (pa == METAL_BAD_PHYS) { @@ -924,7 +1070,13 @@ static int rptun_store_load(FAR void *store_, size_t offset, } file_seek(&store->file, offset, SEEK_SET); - return file_read(&store->file, tmp, size); + ret = file_read(&store->file, tmp, size); + if (ret > 0) + { + metal_cache_flush(tmp, ret); + } + + return ret; } #endif @@ -1017,13 +1169,14 @@ int rptun_initialize(FAR struct rptun_dev_s *dev) goto err_thread; } - /* Add priv to list */ +#ifdef CONFIG_RPTUN_PM + snprintf(name, sizeof(name), "rptun-%s", RPTUN_GET_CPUNAME(dev)); + pm_wakelock_init(&priv->wakelock, name, PM_IDLE_DOMAIN, PM_IDLE); +#endif return OK; err_thread: - nxsem_destroy(&priv->semtx); - nxsem_destroy(&priv->semrx); rpmsg_unregister(name, &priv->rpmsg); err_driver: diff --git a/drivers/rptun/rptun_dump.c b/drivers/rptun/rptun_dump.c deleted file mode 100644 index b51152f32a597..0000000000000 --- a/drivers/rptun/rptun_dump.c +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** - * drivers/rptun/rptun_dump.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -#include - -#include "rptun.h" - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -static void rptun_dump_addr(FAR struct rpmsg_device *rdev, - FAR void *addr, bool rx) -{ - FAR struct rpmsg_hdr *hdr = addr; - FAR struct rpmsg_endpoint *ept; - - ept = rpmsg_get_ept_from_addr(rdev, rx ? hdr->dst : hdr->src); - if (ept) - { - metal_log(METAL_LOG_EMERGENCY, - " %s buffer %p hold by %s\n", - rx ? "RX" : "TX", hdr, ept->name); - } -} - -static void rptun_dump_buffer(FAR struct rpmsg_virtio_device *rvdev, - bool rx) -{ - FAR struct virtqueue *vq = rx ? rvdev->rvq : rvdev->svq; - FAR void *addr; - int desc_idx; - int num; - int i; - - num = rptun_buffer_nused(rvdev, rx); - metal_log(METAL_LOG_EMERGENCY, - " %s buffer, total %d, pending %d\n", - rx ? "RX" : "TX", vq->vq_nentries, num); - - for (i = 0; i < num; i++) - { - if ((rpmsg_virtio_get_role(rvdev) == RPMSG_HOST) ^ rx) - { - desc_idx = (vq->vq_ring.used->idx + i) & (vq->vq_nentries - 1); - desc_idx = vq->vq_ring.avail->ring[desc_idx]; - } - else - { - desc_idx = (vq->vq_ring.avail->idx + i) & (vq->vq_nentries - 1); - desc_idx = vq->vq_ring.used->ring[desc_idx].id; - } - - addr = metal_io_phys_to_virt(vq->shm_io, - vq->vq_ring.desc[desc_idx].addr); - if (addr) - { - rptun_dump_addr(&rvdev->rdev, addr, rx); - } - } -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void rptun_dump(FAR struct rpmsg_virtio_device *rvdev) -{ - FAR struct rpmsg_device *rdev = &rvdev->rdev; - FAR struct rpmsg_endpoint *ept; - FAR struct metal_list *node; - bool needlock = true; - - if (!rvdev->vdev) - { - return; - } - - if (up_interrupt_context() || sched_idletask() || - nxmutex_is_hold(&rdev->lock)) - { - needlock = false; - } - - if (needlock) - { - metal_mutex_acquire(&rdev->lock); - } - - metal_log(METAL_LOG_EMERGENCY, - "Dump rpmsg info between cpu (master: %s)%s <==> %s:\n", - rpmsg_virtio_get_role(rvdev) == RPMSG_HOST ? "yes" : "no", - CONFIG_RPMSG_LOCAL_CPUNAME, rpmsg_get_cpuname(rdev)); - - metal_log(METAL_LOG_EMERGENCY, "rpmsg vq RX:\n"); - virtqueue_dump(rvdev->rvq); - metal_log(METAL_LOG_EMERGENCY, "rpmsg vq TX:\n"); - virtqueue_dump(rvdev->svq); - - metal_log(METAL_LOG_EMERGENCY, " rpmsg ept list:\n"); - - metal_list_for_each(&rdev->endpoints, node) - { - ept = metal_container_of(node, struct rpmsg_endpoint, node); - metal_log(METAL_LOG_EMERGENCY, " ept %s\n", ept->name); - } - - metal_log(METAL_LOG_EMERGENCY, " rpmsg buffer list:\n"); - - rptun_dump_buffer(rvdev, true); - rptun_dump_buffer(rvdev, false); - - if (needlock) - { - metal_mutex_release(&rdev->lock); - } -} diff --git a/drivers/rptun/rptun_ivshmem.c b/drivers/rptun/rptun_ivshmem.c index ae4838d65b8c6..34ad6030b1f71 100644 --- a/drivers/rptun/rptun_ivshmem.c +++ b/drivers/rptun/rptun_ivshmem.c @@ -28,11 +28,12 @@ #include #include +#include #include #include #include #include -#include +#include /**************************************************************************** * Pre-processor Definitions @@ -42,8 +43,7 @@ container_of(ivshmem_get_driver(dev), struct rptun_ivshmem_dev_s, drv) #define RPTUN_IVSHMEM_SHMEM_BAR 2 -#define RPTUN_IVSHMEM_READY 1 -#define RPTUN_IVSHMEM_WORK_DELAY MSEC2TICK(1) +#define RPTUN_IVSHMEM_WDOG_DELAY MSEC2TICK(1) /**************************************************************************** * Private Types @@ -54,8 +54,6 @@ struct rptun_ivshmem_mem_s volatile uint64_t basem; volatile uint32_t seqs; volatile uint32_t seqm; - volatile uint32_t cmds; - volatile uint32_t cmdm; volatile uint32_t reserved; volatile uint32_t rsc_size; struct rptun_rsc_s rsc; @@ -76,9 +74,9 @@ struct rptun_ivshmem_dev_s char cpuname[RPMSG_NAME_SIZE + 1]; FAR struct ivshmem_device_s *ivdev; - /* Work queue for transmit */ + /* Wdog for transmit */ - struct work_s worker; + struct wdog_s wdog; }; /**************************************************************************** @@ -100,7 +98,7 @@ static int rptun_ivshmem_register_callback(FAR struct rptun_dev_s *dev, rptun_callback_t callback, FAR void *arg); -static void rptun_ivshmem_work(FAR void *arg); +static void rptun_ivshmem_wdog(wdparm_t arg); static int rptun_ivshmem_probe(FAR struct ivshmem_device_s *dev); static void rptun_ivshmem_remove(FAR struct ivshmem_device_s *dev); @@ -145,6 +143,7 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev) { FAR struct rptun_ivshmem_dev_s *priv = (FAR struct rptun_ivshmem_dev_s *)dev; + FAR struct rptun_cmd_s *cmd = RPTUN_RSC2CMD(&priv->shmem->rsc); priv->raddrenv[0].da = 0; priv->raddrenv[0].size = priv->shmem_size; @@ -155,18 +154,17 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev) /* Wait untils salve is ready */ - while (priv->shmem->cmds != RPTUN_IVSHMEM_READY) + while (RPTUN_GET_CMD(cmd->cmd_slave) != RPTUN_CMD_READY) { usleep(1000); } - priv->shmem->cmds = 0; + cmd->cmd_slave = 0; priv->shmem->basem = (uint64_t)(uintptr_t)priv->shmem; } else { FAR struct rptun_rsc_s *rsc = &priv->shmem->rsc; - memset(priv->shmem, 0, priv->shmem_size); rsc->rsc_tbl_hdr.ver = 1; @@ -193,7 +191,8 @@ rptun_ivshmem_get_resource(FAR struct rptun_dev_s *dev) rsc->config.h2r_buf_size = CONFIG_RPTUN_IVSHMEM_BUFFSIZE; priv->shmem->rsc_size = sizeof(struct rptun_rsc_s); - priv->shmem->cmds = RPTUN_IVSHMEM_READY; + cmd->cmd_master = 0; + cmd->cmd_slave = RPTUN_CMD(RPTUN_CMD_READY, 0); /* Wait untils master is ready, salve need use master base to * initialize addrenv. @@ -238,7 +237,7 @@ static int rptun_ivshmem_start(FAR struct rptun_dev_s *dev) return 0; } - return work_queue(HPWORK, &priv->worker, rptun_ivshmem_work, priv, 0); + return wd_start(&priv->wdog, 0, rptun_ivshmem_wdog, (wdparm_t)priv); } static int rptun_ivshmem_stop(FAR struct rptun_dev_s *dev) @@ -251,7 +250,7 @@ static int rptun_ivshmem_stop(FAR struct rptun_dev_s *dev) return 0; } - return work_cancel_sync(HPWORK, &priv->worker); + return wd_cancel(&priv->wdog); } static int rptun_ivshmem_notify(FAR struct rptun_dev_s *dev, uint32_t vqid) @@ -287,6 +286,38 @@ static int rptun_ivshmem_register_callback(FAR struct rptun_dev_s *dev, return 0; } +/**************************************************************************** + * Name: rptun_ivshmem_check_cmd + ****************************************************************************/ + +static void rptun_ivshmem_check_cmd(FAR struct rptun_ivshmem_dev_s *priv) +{ + FAR struct rptun_cmd_s *rptun_cmd = RPTUN_RSC2CMD(&priv->shmem->rsc); + uint32_t cmd; + + if (priv->master) + { + cmd = RPTUN_GET_CMD(rptun_cmd->cmd_slave); + rptun_cmd->cmd_slave = RPTUN_CMD(RPTUN_CMD_DEFAULT, 0); + } + else + { + cmd = RPTUN_GET_CMD(rptun_cmd->cmd_master); + rptun_cmd->cmd_master = RPTUN_CMD(RPTUN_CMD_DEFAULT, 0); + } + + switch (cmd) + { + case RPTUN_CMD_RESTART: +#ifdef CONFIG_BOARDCTL_RESET + board_reset(0); +#endif + break; + default: + break; + } +} + /**************************************************************************** * Name: rptun_ivshmem_interrupt ****************************************************************************/ @@ -295,6 +326,8 @@ static int rptun_ivshmem_interrupt(int irq, FAR void *context, FAR void *arg) { FAR struct rptun_ivshmem_dev_s *priv = arg; + rptun_ivshmem_check_cmd(priv); + if (priv->callback != NULL) { priv->callback(priv->arg, RPTUN_NOTIFY_ALL); @@ -304,14 +337,17 @@ static int rptun_ivshmem_interrupt(int irq, FAR void *context, FAR void *arg) } /**************************************************************************** - * Name: rptun_ivshmem_work + * Name: rptun_ivshmem_wdog ****************************************************************************/ -static void rptun_ivshmem_work(FAR void *arg) +static void rptun_ivshmem_wdog(wdparm_t arg) { - FAR struct rptun_ivshmem_dev_s *priv = arg; + FAR struct rptun_ivshmem_dev_s *priv = + (FAR struct rptun_ivshmem_dev_s *)arg; bool should_notify = false; + rptun_ivshmem_check_cmd(priv); + if (priv->master && priv->seq != priv->shmem->seqs) { priv->seq = priv->shmem->seqs; @@ -328,8 +364,8 @@ static void rptun_ivshmem_work(FAR void *arg) priv->callback(priv->arg, RPTUN_NOTIFY_ALL); } - work_queue(HPWORK, &priv->worker, rptun_ivshmem_work, priv, - RPTUN_IVSHMEM_WORK_DELAY); + wd_start(&priv->wdog, RPTUN_IVSHMEM_WDOG_DELAY, rptun_ivshmem_wdog, + (wdparm_t)priv); } /**************************************************************************** @@ -363,11 +399,8 @@ static int rptun_ivshmem_probe(FAR struct ivshmem_device_s *ivdev) if (!priv->master && !ivshmem_support_irq(ivdev)) { - pciinfo("queue the worker\n"); - - /* Queue the worker for slave, master will do this in ops->start() */ - - work_queue(HPWORK, &priv->worker, rptun_ivshmem_work, priv, 0); + pciinfo("Start the wdog\n"); + wd_start(&priv->wdog, 0, rptun_ivshmem_wdog, (wdparm_t)priv); } return ret; diff --git a/drivers/rptun/rptun_secure.c b/drivers/rptun/rptun_secure.c new file mode 100644 index 0000000000000..539416c503b6b --- /dev/null +++ b/drivers/rptun/rptun_secure.c @@ -0,0 +1,221 @@ +/**************************************************************************** + * drivers/rptun/rptun_secure.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct rptun_secure_dev_s +{ + struct rptun_dev_s rptun; + rptun_callback_t callback; + FAR void *arg; + bool master; + FAR struct rptun_rsc_s *rsc; + char cpuname[RPMSG_NAME_SIZE + 1]; + int irq_event; + int irq_trigger; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static FAR const char *rptun_secure_get_cpuname(FAR struct rptun_dev_s *dev); +static struct +FAR rptun_rsc_s *rptun_secure_get_resource(FAR struct rptun_dev_s *dev); +static bool rptun_secure_is_autostart(FAR struct rptun_dev_s *dev); +static bool rptun_secure_is_master(FAR struct rptun_dev_s *dev); +static int rptun_secure_start(FAR struct rptun_dev_s *dev); +static int rptun_secure_stop(FAR struct rptun_dev_s *dev); +static int rptun_secure_notify(FAR struct rptun_dev_s *dev, + uint32_t notifyid); +static int rptun_secure_register_callback(FAR struct rptun_dev_s *dev, + rptun_callback_t callback, + FAR void *arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct rptun_ops_s g_rptun_secure_ops = +{ + .get_cpuname = rptun_secure_get_cpuname, + .get_resource = rptun_secure_get_resource, + .is_autostart = rptun_secure_is_autostart, + .is_master = rptun_secure_is_master, + .start = rptun_secure_start, + .stop = rptun_secure_stop, + .notify = rptun_secure_notify, + .register_callback = rptun_secure_register_callback, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static FAR const char *rptun_secure_get_cpuname(FAR struct rptun_dev_s *dev) +{ + FAR struct rptun_secure_dev_s *priv = (FAR struct rptun_secure_dev_s *)dev; + return priv->cpuname; +} + +static FAR struct rptun_rsc_s * +rptun_secure_get_resource(FAR struct rptun_dev_s *dev) +{ + FAR struct rptun_secure_dev_s *priv = (FAR struct rptun_secure_dev_s *)dev; + return priv->rsc; +} + +static bool rptun_secure_is_autostart(FAR struct rptun_dev_s *dev) +{ + return true; +} + +static bool rptun_secure_is_master(FAR struct rptun_dev_s *dev) +{ + FAR struct rptun_secure_dev_s *priv = (FAR struct rptun_secure_dev_s *)dev; + return priv->master; +} + +static int rptun_secure_start(FAR struct rptun_dev_s *dev) +{ + return 0; +} + +static int rptun_secure_stop(FAR struct rptun_dev_s *dev) +{ + return 0; +} + +static int rptun_secure_notify(FAR struct rptun_dev_s *dev, uint32_t vqid) +{ + FAR struct rptun_secure_dev_s *priv = (FAR struct rptun_secure_dev_s *)dev; + cpu_set_t cpuset; + + CPU_ZERO(&cpuset); + CPU_SET(0, &cpuset); + up_trigger_irq(priv->irq_trigger, cpuset); + return 0; +} + +static int rptun_secure_register_callback(FAR struct rptun_dev_s *dev, + rptun_callback_t callback, + FAR void *arg) +{ + FAR struct rptun_secure_dev_s *priv = (FAR struct rptun_secure_dev_s *)dev; + + priv->callback = callback; + priv->arg = arg; + + if (callback) + { + up_enable_irq(priv->irq_event); + } + else + { + up_disable_irq(priv->irq_event); + } + + return 0; +} + +/**************************************************************************** + * Name: rprun_secure_interrupt + * + * Description: + * This is the interrupt handler. + * + * Input Parameters: + * irq - unused + * context - context, unused + * arg - private data pointer + * + * Returned Value: + * OK always + * + ****************************************************************************/ + +static int rprun_secure_interrupt(int irq, FAR void *context, FAR void *arg) +{ + FAR struct rptun_secure_dev_s *priv = arg; + + if (priv != NULL && priv->callback != NULL) + { + priv->callback(priv->arg, RPTUN_NOTIFY_ALL); + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int rptun_secure_init(FAR const char *cpuname, bool master, + FAR struct rptun_rsc_s *rsc, int irq_event, + int irq_trigger) +{ + FAR struct rptun_secure_dev_s *dev; + int ret; + + dev = kmm_zalloc(sizeof(*dev)); + if (dev == NULL) + { + return -ENOMEM; + } + + dev->master = master; + dev->irq_trigger = irq_trigger; + dev->irq_event = irq_event; + dev->rptun.ops = &g_rptun_secure_ops; + dev->rsc = rsc; + strlcpy(dev->cpuname, cpuname, sizeof(dev->cpuname)); + + ret = irq_attach(dev->irq_event, + rprun_secure_interrupt, dev); + if (ret < 0) + { + kmm_free(dev); + return ret; + } + + ret = rptun_initialize(&dev->rptun); + if (ret < 0) + { + irq_detach(dev->irq_event); + kmm_free(dev); + return ret; + } + + return ret; +} diff --git a/include/nuttx/rpmsg/rpmsg_virtio.h b/include/nuttx/rpmsg/rpmsg_virtio.h index ff7d6be7c67cc..7dc1b9358a9df 100644 --- a/include/nuttx/rpmsg/rpmsg_virtio.h +++ b/include/nuttx/rpmsg/rpmsg_virtio.h @@ -160,6 +160,8 @@ struct aligned_data(8) rpmsg_virtio_rsc_s struct fw_rsc_vdev_vring rpmsg_vring0; struct fw_rsc_vdev_vring rpmsg_vring1; struct fw_rsc_config config; + uint32_t cmd_master; + uint32_t cmd_slave; }; struct rpmsg_virtio_s; diff --git a/include/nuttx/rptun/rptun.h b/include/nuttx/rptun/rptun.h index 32e62f58cf004..cfc8e0531fba3 100644 --- a/include/nuttx/rptun/rptun.h +++ b/include/nuttx/rptun/rptun.h @@ -29,6 +29,7 @@ #ifdef CONFIG_RPTUN +#include #include #include #include @@ -46,6 +47,27 @@ #define RPTUN_NOTIFY_ALL (UINT32_MAX - 0) +#define RPTUN_CMD_DEFAULT 0x0 +#define RPTUN_CMD_PANIC 0x1 +#define RPTUN_CMD_STOP 0x2 +#define RPTUN_CMD_READY 0x3 +#define RPTUN_CMD_RESTART 0x4 +#define RPTUN_CMD_MASK 0xffff +#define RPTUN_CMD_SHIFT 16 + +#define RPTUN_CMD(c,v) (((c) << RPTUN_CMD_SHIFT) | ((v) & RPTUN_CMD_MASK)) +#define RPTUN_GET_CMD(c) ((c) >> RPTUN_CMD_SHIFT) +#define RPTUN_GET_CMD_VAL(c) ((c) & RPTUN_CMD_MASK) + +#define RPTUN_RSC2CMD(r) \ + ((FAR struct rptun_cmd_s *)&((FAR struct resource_table *)(r))->reserved[0]) + +#ifdef CONFIG_OPENAMP_CACHE +# define RPTUN_INVALIDATE(x) metal_cache_invalidate(&x, sizeof(x)) +#else +# define RPTUN_INVALIDATE(x) +#endif + /* Access macros ************************************************************/ /**************************************************************************** @@ -288,7 +310,7 @@ ****************************************************************************/ #define RPTUN_RESET(d,v) ((d)->ops->reset ? \ - (d)->ops->reset(d,v) : -ENOSYS) + (d)->ops->reset(d,v) : UNUSED(d)) /**************************************************************************** * Name: RPTUN_PANIC @@ -305,7 +327,7 @@ ****************************************************************************/ #define RPTUN_PANIC(d) ((d)->ops->panic ? \ - (d)->ops->panic(d) : -ENOSYS) + (d)->ops->panic(d) : UNUSED(d)) /**************************************************************************** * Public Types @@ -320,10 +342,16 @@ struct rptun_addrenv_s size_t size; }; +begin_packed_struct struct rptun_cmd_s +{ + uint32_t cmd_master; + uint32_t cmd_slave; +} end_packed_struct; + struct aligned_data(8) rptun_rsc_s { struct resource_table rsc_tbl_hdr; - unsigned int offset[2]; + uint32_t offset[2]; struct fw_rsc_trace log_trace; struct fw_rsc_vdev rpmsg_vdev; struct fw_rsc_vdev_vring rpmsg_vring0; diff --git a/include/nuttx/rptun/rptun_secure.h b/include/nuttx/rptun/rptun_secure.h new file mode 100644 index 0000000000000..e62e42482d48e --- /dev/null +++ b/include/nuttx/rptun/rptun_secure.h @@ -0,0 +1,70 @@ +/**************************************************************************** + * include/nuttx/rptun/rptun_secure.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_RPTUN_RPTUN_SECURE_H +#define __INCLUDE_NUTTX_RPTUN_RPTUN_SECURE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: rptun_secure_init + * + * Description: + * Initializes the rptun device. + * + * Input Parameters: + * cpuname - Local CPU name + * master - If is master + * rsc - The resource for shared memory + * irq_event - Interrupt ID to attach + * irq_trigger - Interrupt ID to trigger + * + * Returned Value: + * OK on success, negated errno on failure + * + ****************************************************************************/ + +int rptun_secure_init(FAR const char *cpuname, bool master, + FAR struct rptun_rsc_s *rsc, int irq_event, + int irq_trigger); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_RPTUN_RPTUN_SECURE_H */