gpoulios commented on code in PR #16309: URL: https://github.com/apache/nuttx/pull/16309#discussion_r2074773932
########## drivers/misc/optee.c: ########## @@ -145,10 +207,398 @@ static bool optee_safe_va_range(FAR void *va, size_t size) return false; } -#else +#else /* !CONFIG_ARCH_ADDRENV */ +static uintptr_t optee_va_to_pa(FAR void *va) +{ + return (uintptr_t)va; +} + #define optee_safe_va_range(addr, size) (true) #endif +/**************************************************************************** + * 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_p`. + * + * Parameters: + * shme - Shared memory entry to create a page list for. + * list_pa_p - 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_p) +{ + const size_t pgsize = OPTEE_MSG_NONCONTIG_PAGE_SIZE; + uintptr_t shm_pgoff; + uintptr_t shm_page; + uint32_t shm_total_pages; + uint32_t list_size; + FAR void *list; + FAR struct page_list_entry *list_entry; + uint32_t i; + + shm_pgoff = shme->shm.addr & (pgsize - 1); + shm_total_pages = (uint32_t) + (ALIGN_UP(shm_pgoff + shme->shm.length, pgsize) / pgsize); + list_size = div_round_up(shm_total_pages, PAGES_ARRAY_LEN) * pgsize; Review Comment: This is wrong. It is meant to be: ``` (<number of pages occupied by shm> / <number of page references in entry>) * sizeof(struct optee_page_list_entry) ``` The `* pgsize` is meant to be equivalent to `* sizeof(struct optee_page_list_entry)`. I'll change to that for readability. -- 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