xiaoxiang781216 commented on code in PR #16734:
URL: https://github.com/apache/nuttx/pull/16734#discussion_r2255044906


##########
drivers/misc/optee_supplicant.c:
##########
@@ -0,0 +1,608 @@
+/****************************************************************************
+ * drivers/misc/optee_supplicant.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 <nuttx/mutex.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/queue.h>
+#include <nuttx/idr.h>
+#include <string.h>
+
+#include "optee.h"
+#include "optee_supplicant.h"
+#include "optee_msg.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* Request structure for RPCs serviced by the supplicant. */
+
+struct optee_supplicant_req
+{
+  sq_entry_t                  link;
+  uint32_t                    func;
+  uint32_t                    ret;
+  uint32_t                    num_params;
+  FAR struct tee_ioctl_param *params;
+  sem_t                       c;
+};
+
+struct optee_supplicant
+{
+  mutex_t           mutex;
+  int               req_id;
+  struct sq_queue_s reqs;
+  FAR struct idr_s *idr;
+  FAR struct idr_s *shm_idr;
+  sem_t             reqs_c;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct optee_supplicant g_optee_supp;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: pop_entry
+ *
+ * Description:
+ *   Pop the first request from the request queue, and create unique id.
+ *
+ * Parameters:
+ *   num_params - Number of parameters passed.
+ *   id         - Pointer to the unique request id.
+ *
+ * Returned Value:
+ *   A pointer to the request on success or NULL.
+ *
+ ****************************************************************************/
+
+static FAR struct optee_supplicant_req * pop_entry(uint32_t num_params,
+                                                   FAR int *id)
+{
+  FAR struct optee_supplicant_req *req;
+
+  if (g_optee_supp.req_id != -1)
+    {
+      /* Mixing sync/async not supported */
+
+      return NULL;
+    }
+
+  if (sq_empty(&g_optee_supp.reqs))
+    {
+      return NULL;
+    }
+
+  req = (struct optee_supplicant_req *)sq_remfirst(&g_optee_supp.reqs);
+
+  /* The request can't fit in the supplicant's supplied parameter buffer. */
+
+  if (num_params < req->num_params)
+    {
+      return NULL;
+    }
+
+  *id = idr_alloc(g_optee_supp.idr, req, 0, INT32_MAX);
+  if (*id < 0)
+    {
+      return NULL;
+    }
+
+  return req;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: optee_supplicant_init
+ *
+ * Description:
+ *   Initialize supplicant data.
+ *
+ * Parameters:
+ *   shm_idr - A pointer, passed by reference, to the optee driver's shm_idr.
+ *             The destruction of the shm_idr will be handled by
+ *             optee_close(), so we only need to initialize it in this
+ *             context.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void optee_supplicant_init(FAR struct idr_s **shm_idr)

Review Comment:
   this approach isn't perfect, let's merge this patch as the current state and 
refine later if we find the better method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to