This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 4f4b36a1163 drivers/tee: add dummy OP-TEE server driver
4f4b36a1163 is described below

commit 4f4b36a1163368e96aa12a2f0ee666d95b230f0c
Author: hujun5 <[email protected]>
AuthorDate: Fri Aug 21 20:24:19 2026 +0800

    drivers/tee: add dummy OP-TEE server driver
    
    Add an OP-TEE server-side driver that announces the RPMsg service channel 
without creating a TEE character device.
    
    Signed-off-by: hujun5 <[email protected]>
---
 Documentation/guides/security/optee.rst |   6 ++
 drivers/tee/CMakeLists.txt              |   4 +-
 drivers/tee/Kconfig                     |  24 ++++-
 drivers/tee/Make.defs                   |   4 +-
 drivers/tee/optee_dummy.c               | 154 ++++++++++++++++++++++++++++++++
 5 files changed, 186 insertions(+), 6 deletions(-)

diff --git a/Documentation/guides/security/optee.rst 
b/Documentation/guides/security/optee.rst
index 4260506e0fb..20b834c70bd 100644
--- a/Documentation/guides/security/optee.rst
+++ b/Documentation/guides/security/optee.rst
@@ -63,6 +63,12 @@ Successful registration of the driver can be verified by 
looking into
 incompatibility with the TEE OS running in the system, will prevent the
 ``/dev/tee0`` character device from being registered.
 
+.. note::
+   The same choice also offers ``CONFIG_DEV_OPTEE_DUMMY``, which registers
+   no character device at all. It is meant for the side that runs the OP-TEE
+   server itself, and only announces the RPMsg channel that a REE binds its
+   own TEE driver to.
+
 IOCTLs supported
 ================
 
diff --git a/drivers/tee/CMakeLists.txt b/drivers/tee/CMakeLists.txt
index 1a473392086..06fbe962553 100644
--- a/drivers/tee/CMakeLists.txt
+++ b/drivers/tee/CMakeLists.txt
@@ -21,7 +21,9 @@
 # 
##############################################################################
 set(SRCS)
 
-if(NOT CONFIG_DEV_OPTEE_NONE)
+if(CONFIG_DEV_OPTEE_DUMMY)
+  list(APPEND SRCS optee_dummy.c)
+elseif(NOT CONFIG_DEV_OPTEE_NONE)
   list(APPEND SRCS optee.c)
   if(CONFIG_DEV_OPTEE_SMC)
     list(APPEND SRCS optee_smc.c)
diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig
index 67978acd7cb..7c8b983883a 100644
--- a/drivers/tee/Kconfig
+++ b/drivers/tee/Kconfig
@@ -14,6 +14,9 @@ choice
                the cpu and uses either RPMsg cross-core communication or arm 
SMCs.
                Warning: SMC implementation has only been tested on arm64.
 
+               DEV_OPTEE_DUMMY is not one of them: select it on the side that
+               runs the server itself, which needs no client of its own.
+
 config DEV_OPTEE_LOCAL
        bool "OPTEE Local Socket Support"
        depends on NET_LOCAL
@@ -32,6 +35,22 @@ config DEV_OPTEE_SMC
        depends on FS_ANONMAP
        depends on ALLOW_BSD_COMPONENTS
 
+config DEV_OPTEE_DUMMY
+       bool "OP-TEE RPMSG channel announcement"
+       depends on RPMSG
+       ---help---
+               Select this on the side that runs the OP-TEE server, rather than
+               on a client of /dev/tee0.
+
+               A TEE that shares memory with a REE over rpmsg has to make 
itself
+               visible to that REE first: the REE binds its TEE backend to a 
named
+               rpmsg channel, and binding is what hands that backend the rpmsg
+               device it allocates the shared memory from.
+
+               The channel carries no traffic of its own, as the requests
+               themselves travel over the OP-TEE service socket, so the 
endpoint
+               this creates is a sink.
+
 config DEV_OPTEE_NONE
        bool "Disable OP-TEE driver"
 
@@ -42,13 +61,10 @@ config DEV_OPTEE_SUPPLICANT
        default n
        depends on DEV_OPTEE_SMC
 
-if DEV_OPTEE_RPMSG
-
 config OPTEE_REMOTE_CPU_NAME
        string "The cpuname on which the OP-TEE server runs"
        default "tee"
-
-endif # DEV_OPTEE_RPMSG
+       depends on DEV_OPTEE_RPMSG
 
 if DEV_OPTEE_SMC
 
diff --git a/drivers/tee/Make.defs b/drivers/tee/Make.defs
index a80e945baeb..906152d7de3 100644
--- a/drivers/tee/Make.defs
+++ b/drivers/tee/Make.defs
@@ -20,7 +20,9 @@
 #
 ############################################################################
 
-ifneq ($(CONFIG_DEV_OPTEE_NONE),y)
+ifeq ($(CONFIG_DEV_OPTEE_DUMMY),y)
+  CSRCS += optee_dummy.c
+else ifneq ($(CONFIG_DEV_OPTEE_NONE),y)
   CSRCS += optee.c
   ifeq ($(CONFIG_DEV_OPTEE_SMC),y)
     CSRCS += optee_smc.c
diff --git a/drivers/tee/optee_dummy.c b/drivers/tee/optee_dummy.c
new file mode 100644
index 00000000000..4be789cc278
--- /dev/null
+++ b/drivers/tee/optee_dummy.c
@@ -0,0 +1,154 @@
+/****************************************************************************
+ * drivers/tee/optee_dummy.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/rpmsg/rpmsg.h>
+#include <nuttx/drivers/optee.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Name of the channel this announces.  It is part of the interface between
+ * the two operating systems rather than an internal constant, as the REE
+ * matches it through the id_table of its own rpmsg TEE driver.
+ */
+
+#define OPTEE_DUMMY_EPT_NAME "rpmsg-tee"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: optee_dummy_ept_cb
+ *
+ * Description:
+ *   Sink for the announcement endpoint.  Nothing is expected on the channel
+ *   itself: the REE allocates the memory it shares with the TEE out of the
+ *   rpmsg buffer pool and names the result in its own requests, which reach
+ *   the TEE over the OP-TEE service socket rather than here.  A callback
+ *   still has to be supplied, as rpmsg_create_ept() rejects a NULL one.
+ *
+ ****************************************************************************/
+
+static int optee_dummy_ept_cb(FAR struct rpmsg_endpoint *ept,
+                              FAR void *data, size_t len,
+                              uint32_t src, FAR void *priv)
+{
+  return 0;
+}
+
+/****************************************************************************
+ * Name: optee_dummy_ept_release
+ *
+ * Description:
+ *   Free the endpoint once the last reference to it is gone.  Tearing the
+ *   rpmsg device down destroys the endpoints attached to it, which is what
+ *   drops that reference.
+ *
+ ****************************************************************************/
+
+static void optee_dummy_ept_release(FAR struct rpmsg_endpoint *ept)
+{
+  kmm_free(ept);
+}
+
+/****************************************************************************
+ * Name: optee_dummy_device_created
+ *
+ * Description:
+ *   Announce the channel as soon as an rpmsg device shows up.  Any remote
+ *   processor that binds to the channel is served, so no name is matched
+ *   here.  The announcement cannot be made from optee_register(), as no
+ *   rpmsg device exists yet at that point.
+ *
+ ****************************************************************************/
+
+static void optee_dummy_device_created(FAR struct rpmsg_device *rdev,
+                                       FAR void *priv)
+{
+  FAR struct rpmsg_endpoint *ept;
+  int ret;
+
+  ept = kmm_zalloc(sizeof(*ept));
+  if (ept == NULL)
+    {
+      return;
+    }
+
+  ret = rpmsg_create_ept(ept, rdev, OPTEE_DUMMY_EPT_NAME,
+                         RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
+                         optee_dummy_ept_cb, rpmsg_destroy_ept);
+  if (ret < 0)
+    {
+      _err("Failed to announce %s to %s: %d\n",
+           OPTEE_DUMMY_EPT_NAME, rpmsg_get_cpuname(rdev), ret);
+      kmm_free(ept);
+      return;
+    }
+
+  /* Installed only once registration has succeeded.  A late failure inside
+   * rpmsg_create_ept() drops the reference it took, which would run this
+   * callback and free the endpoint that the error path above frees too.
+   */
+
+  ept->release_cb = optee_dummy_ept_release;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: optee_register
+ *
+ * Description:
+ *   Announce the channel to whichever remote processor binds to it, so that
+ *   the TEE backend running there can reach this side.  Binding hands that
+ *   backend an rpmsg device, which is what it needs to allocate out of the
+ *   memory shared with this side.
+ *
+ * Returned Value:
+ *   OK on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int optee_register(void)
+{
+  /* rpmsg_register_callback() also runs the callback for a device that is
+   * already up, so this works whichever side of rptun initialisation it is
+   * called from.
+   */
+
+  return rpmsg_register_callback(NULL,
+                                 optee_dummy_device_created,
+                                 NULL,
+                                 NULL,
+                                 NULL);
+}

Reply via email to