1 /* 2 * Copyright (c) 2014, STMicroelectronics International N.V. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 #ifndef TEE_SVC_H 28 #define TEE_SVC_H 29 30 #include <assert.h> 31 #include <stdint.h> 32 #include <types_ext.h> 33 #include <tee_api_types.h> 34 #include <utee_types.h> 35 36 extern vaddr_t tee_svc_uref_base; 37 38 struct tee_ta_session; 39 40 /* TA Properties */ 41 struct tee_props { 42 const char *name; 43 44 /* prop_type is of type enum user_ta_prop_type*/ 45 const uint32_t prop_type; 46 47 /* either get_prop_func or both data and len */ 48 TEE_Result (*get_prop_func)(struct tee_ta_session *sess, 49 void *buf, size_t *blen); 50 const void *data; 51 const size_t len; 52 }; 53 54 struct tee_vendor_props { 55 const struct tee_props *props; 56 size_t len; 57 }; 58 void syscall_sys_return(unsigned long ret); 59 60 void syscall_log(const void *buf, size_t len); 61 62 void syscall_panic(unsigned long code); 63 64 TEE_Result syscall_not_supported(void); 65 66 /* prop_set defined by enum utee_property */ 67 TEE_Result syscall_get_property(unsigned long prop_set, 68 unsigned long index, 69 void *name, uint32_t *name_len, 70 void *buf, uint32_t *blen, 71 uint32_t *prop_type); 72 TEE_Result syscall_get_property_name_to_index(unsigned long prop_set, 73 void *name, 74 unsigned long name_len, 75 uint32_t *index); 76 77 TEE_Result syscall_open_ta_session(const TEE_UUID *dest, 78 unsigned long cancel_req_to, struct utee_params *params, 79 uint32_t *sess, uint32_t *ret_orig); 80 81 TEE_Result syscall_close_ta_session(unsigned long sess); 82 83 TEE_Result syscall_invoke_ta_command(unsigned long sess, 84 unsigned long cancel_req_to, unsigned long cmd_id, 85 struct utee_params *params, uint32_t *ret_orig); 86 87 TEE_Result syscall_check_access_rights(unsigned long flags, const void *buf, 88 size_t len); 89 90 TEE_Result tee_svc_copy_from_user(void *kaddr, const void *uaddr, size_t len); 91 TEE_Result tee_svc_copy_to_user(void *uaddr, const void *kaddr, size_t len); 92 93 TEE_Result tee_svc_copy_kaddr_to_uref(uint32_t *uref, void *kaddr); 94 95 static inline uint32_t tee_svc_kaddr_to_uref(void *kaddr) 96 { 97 assert(((vaddr_t)kaddr - tee_svc_uref_base) < UINT32_MAX); 98 return (vaddr_t)kaddr - tee_svc_uref_base; 99 } 100 101 static inline vaddr_t tee_svc_uref_to_vaddr(uint32_t uref) 102 { 103 return tee_svc_uref_base + uref; 104 } 105 106 static inline void *tee_svc_uref_to_kaddr(uint32_t uref) 107 { 108 return (void *)tee_svc_uref_to_vaddr(uref); 109 } 110 111 TEE_Result syscall_get_cancellation_flag(uint32_t *cancel); 112 113 TEE_Result syscall_unmask_cancellation(uint32_t *old_mask); 114 115 TEE_Result syscall_mask_cancellation(uint32_t *old_mask); 116 117 TEE_Result syscall_wait(unsigned long timeout); 118 119 TEE_Result syscall_get_time(unsigned long cat, TEE_Time *time); 120 TEE_Result syscall_set_ta_time(const TEE_Time *time); 121 122 #endif /* TEE_SVC_H */ 123