gpoulios commented on code in PR #16309: URL: https://github.com/apache/nuttx/pull/16309#discussion_r2076570540
########## drivers/misc/optee.c: ########## @@ -154,6 +202,248 @@ static bool optee_is_valid_range(FAR void *va, size_t size) # define optee_is_valid_range(addr, size) (true) #endif +/**************************************************************************** + * Name: optee_msg_alloc + * + * Description: + * Allocate OP-TEE page-aligned memory for use as arguments to OP-TEE + * calls, large enough to fit `num_params` parameters. Initialize the + * buffer to 0, and set the `.num_params` field to the specified value. + * + * Use `kmm_free()` to free the memory returned. + * + * Parameters: + * priv - the driver's private data structure + * num_params - the number of arguments to allocate shared memory for. + * Can be zero. + * + * Returned Values: + * On success, pointer to OP-TEE message arguments struct initialized + * to 0 except for `.num_params`, which is initialized to the specified. + * On failure, NULL. + * + ****************************************************************************/ + +static FAR struct optee_msg_arg * +optee_msg_alloc(FAR struct optee_priv_data *priv, uint32_t num_params) +{ + FAR struct optee_msg_arg *msg; + + if (priv->alignment) + { + msg = kmm_memalign(priv->alignment, + OPTEE_MSG_GET_ARG_SIZE(num_params)); + } + else + { + msg = kmm_malloc(OPTEE_MSG_GET_ARG_SIZE(num_params)); + } + + if (msg == NULL) + { + return NULL; + } + + memset(msg, 0, OPTEE_MSG_GET_ARG_SIZE(num_params)); + msg->num_params = num_params; + + return msg; +} + +/**************************************************************************** + * Name: optee_shm_to_page_list + * + * Description: + * Provide a page list of a shared memory buffer. Secure world doesn't + * know about the address environment mapping of NuttX, so physical + * pointers are needed when sharing memory. This implementation enables + * sharing of physically non-contiguous buffers according to + * optee_msg.h#OPTEE_MSG_ATTR_NONCONTIG. + * Each entry in the generated page list is an array of the physical, + * potentially non-contiguous pages making up the actual buffer to + * represent. Note that this representation does not account for the page + * offset of the shared memory buffer. The offset is encoded in the + * physical address returned in `list_pa`. + * + * Parameters: + * shme - Shared memory entry to create a page list for. + * list_pa - If not NULL, will be set to the page list's physical + * address (which is aligned to + * OPTEE_MSG_NONCONTIG_PAGE_SIZE) added with shared memory + * page offset. + * + * Returned Values: + * A pointer to the kernel virtual address of the page list on success. + * NULL on failure. Caller responsible to free the returned list using + * `kmm_free()`. + * + ****************************************************************************/ + +FAR void *optee_shm_to_page_list(FAR struct optee_shm_entry *shme, + FAR uintptr_t *list_pa) +{ + size_t pgsize = OPTEE_MSG_NONCONTIG_PAGE_SIZE; + uintptr_t pgoff; + uintptr_t page; + uint32_t total_pages; + uint32_t list_size; + FAR void *list; + FAR struct optee_page_list_entry *list_entry; + uint32_t i = 0; Review Comment: Can you explain the reasoning? -- 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