tkaratapanis commented on code in PR #16734: URL: https://github.com/apache/nuttx/pull/16734#discussion_r2221511866
########## drivers/misc/optee_supplicant.h: ########## @@ -0,0 +1,73 @@ +/**************************************************************************** + * drivers/misc/optee_supplicant.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __DRIVERS_MISC_OPTEE_SUPPLICANT_H +#define __DRIVERS_MISC_OPTEE_SUPPLICANT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include "optee.h" + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +void optee_supplicant_init(void); +void optee_supplicant_uninit(void); +bool optee_supplicant_running(void); + +FAR struct idr_s *optee_supplicant_get_shm_idr(void); +FAR struct idr_s *optee_supplicant_init_shm_idr(void); Review Comment: The nuttx Client Applications (CAs) open `/dev/tee0`, the optee_supplicant (another nuttx application) opens` /dev/teepriv0`. They have different inodes and they can't share shm ids through the `inode::i_private`. What I am doing currently through the inode's private data is to assign a role, so each application that opens `/dev/tee0` is assigned `OPTEE_ROLE_CA`, the supplicant application (only one can open` /dev/teepriv0`) is assigned `OPTEE_ROLE_SUPPLICANT`. ``` int optee_register(void) { int ret; ret = optee_transport_init(); if (ret < 0) { return ret; } #ifdef CONFIG_DEV_OPTEE_SUPPLICANT ret = register_driver(OPTEE_SUPPLICANT_DEV_PATH, &g_optee_ops, 0666, (FAR void *)OPTEE_ROLE_SUPPLICANT); if (ret != 0) { return ret; } #endif return register_driver(OPTEE_DEV_PATH, &g_optee_ops, 0666, (FAR void *)OPTEE_ROLE_CA); } ``` Then this role is checked in some parts and the code diverges between the supplicant and a typical CA, e.g: ``` static int optee_ioctl_shm_register(FAR struct optee_priv_data *priv, FAR struct tee_ioctl_shm_register_data *rdata) { [...] if (priv->role == OPTEE_ROLE_CA) { ret = optee_shm_alloc(priv, (FAR void *)(uintptr_t)rdata->addr, rdata->length, TEE_SHM_REGISTER, &shm); } #ifdef CONFIG_DEV_OPTEE_SUPPLICANT else if (priv->role == OPTEE_ROLE_SUPPLICANT) { ret = optee_shm_register_supplicant(priv, (uintptr_t)rdata->addr, rdata->length, &shm); rdata->flags = shm->flags; } #endif else { return -ENODEV; } [...] ``` The idea to use `priv->shms` to get the supplicant's idr is to keep the code with minimal changes: ``` priv->shms = optee_supplicant_get_shm_idr(); ``` The alternative to what I am doing is this: 1) Add an extra argument to `optee_supplicant_init()` so I pass `&priv->shms` and set it there. 2) Add an extra function that searches in the supplicant's `idr_s` and returns a pointer to the shared memory if that id is found. 3) Remove the getter function would you like me to do that? -- 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