drivers/misc/optee: Fix GP API compatibility

Previous implementation was not compatible with GlobalPlatform
API in the following ways:
 - Registered mem IDs would begin from negatives when it should
   have been greater than or equal to 0
 - Register IOCTL would return 0 on success, when it should have
   been returning a file descriptor.
 - Register IOCTL would expect the user-space client to specify
   TEE_SHM_* flags dictating its behaviour when in fact, libteec
   never specifies flags.

This commit fixes all those issues. It uses nuttx/idr.h instead
of a linked list, and it uses `file_allocate` to provide file
descriptors for registered shared memory. Upon close(fd), the
memory is de-registered and freed accordingly. It also updates
the documentation accordingly.

Signed-off-by: George Poulios <gpoulios@census-labs.com>
This commit is contained in:
George Poulios 2025-05-10 14:40:26 +03:00 • committed by Xiang Xiao
parent c497ee249b
commit a2a689fee0
5 changed files with 235 additions and 175 deletions

View file

@ -378,12 +378,10 @@ struct tee_iocl_supp_send_arg
#define TEE_IOC_SUPPL_SEND _IOC(TEE_IOC_MAGIC << 8, TEE_IOC_BASE + 7)
/* Shared memory specific defines */
/* Shared memory-specific defines */
#define TEE_SHM_REGISTER (1 << 0) /* In list of shared memory */
#define TEE_SHM_SEC_REGISTER (1 << 1) /* TEE notified of this memory */
#define TEE_SHM_ALLOC (1 << 2) /* The memory is malloced() and must
* be freed() */
#define TEE_SHM_ALLOC (1 << 0) /* Kernel-malloced and must freed */
#define TEE_SHM_REGISTER (1 << 1) /* Registered with TEE OS */
/* struct tee_ioctl_shm_register_data - Shared memory register argument
* addr: [in] Start address of shared memory to register