nuttx/dirvers: Add secure rptun file
rptun secure is a rptun driver used for the rpmsg communication between (Non-Secure) REE and (Secure) TEE environments. Signed-off-by: yanghuatao <yanghuatao@xiaomi.com> Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
parent
381e7f225d
commit
520bb6544e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <nuttx/rptun/rptun.h>
|
||||
#include <nuttx/rptun/rptun_secure.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
}
|
|
@ -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 <nuttx/config.h>
|
||||
#include <nuttx/rptun/rptun.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
Loading…
Reference in New Issue