1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2014, STMicroelectronics International N.V. 4 * Copyright (c) 2020, Linaro Limited 5 */ 6 #ifndef __KERNEL_USER_ACCESS_H 7 #define __KERNEL_USER_ACCESS_H 8 9 #include <assert.h> 10 #include <kernel/user_access_arch.h> 11 #include <tee_api_types.h> 12 #include <types_ext.h> 13 14 #ifdef CFG_WITH_USER_TA 15 TEE_Result copy_from_user_private(void *kaddr, const void *uaddr, size_t len); 16 TEE_Result copy_from_user(void *kaddr, const void *uaddr, size_t len); 17 #else 18 static inline TEE_Result copy_from_user_private(void *kaddr __unused, 19 const void *uaddr __unused, 20 size_t len __unused) 21 { 22 return TEE_ERROR_NOT_SUPPORTED; 23 } 24 25 static inline TEE_Result copy_from_user(void *kaddr __unused, 26 const void *uaddr __unused, 27 size_t len __unused) 28 { 29 return TEE_ERROR_NOT_SUPPORTED; 30 } 31 32 #endif 33 34 /* 35 * bb_alloc() - Allocate a bounce buffer 36 * @len: Length of bounce buffer 37 * 38 * The bounce buffer is allocated from a per user TA context region reserved 39 * for bounce buffers. Buffers are allocated in a stack like fashion so 40 * only the last buffer can be free. Buffers generally don't have to be 41 * freed, all bounce buffer allocations are reset on each syscall entry. 42 * 43 * Return NULL on failure or a valid pointer on success. 44 */ 45 void *bb_alloc(size_t len); 46 47 /* 48 * bb_free() - Free a bounce buffer 49 * @bb: Buffer 50 * @len: Length of buffer 51 * 52 * The bounce buffer is only freed if it is last on the stack of allocated 53 * bounce buffers. This function does normally not need to be called, see 54 * description of bb_alloc(). 55 */ 56 void bb_free(void *bb, size_t len); 57 58 /* 59 * bb_reset() - Reset bounce buffer allocation 60 * 61 * Resets the bounce buffer allocatation state, old pointers allocated 62 * with bb_alloc() should not be used any longer. 63 */ 64 void bb_reset(void); 65 66 TEE_Result copy_to_user_private(void *uaddr, const void *kaddr, size_t len); 67 TEE_Result copy_to_user(void *uaddr, const void *kaddr, size_t len); 68 69 TEE_Result copy_kaddr_to_uref(uint32_t *uref, void *kaddr); 70 71 uint32_t kaddr_to_uref(void *kaddr); 72 vaddr_t uref_to_vaddr(uint32_t uref); 73 static inline void *uref_to_kaddr(uint32_t uref) 74 { 75 return (void *)uref_to_vaddr(uref); 76 } 77 78 #endif /*__KERNEL_USER_ACCESS_H*/ 79