1 /* 2 * Copyright (c) 2016, Linaro Limited 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 28 /* 29 * Interface with tee-supplicant for POSIX-like file operations 30 */ 31 32 #ifndef TEE_FS_RPC_H 33 #define TEE_FS_RPC_H 34 35 #include <stdbool.h> 36 #include <stddef.h> 37 #include <tee_api_types.h> 38 #include <tee/tee_fs.h> 39 #include <kernel/thread.h> 40 41 /* 42 * Return values: 43 * < 0: error. The actual value is meaningless (see below). 44 * >= 0: success. The value may be a file descriptor, a number of bytes, or 45 * simply 0 depending on the function. 46 * 47 * The return value is the status set by the normal world (tee-supplicant) or 48 * -1 in case of communication error. To facilitate debugging, tee-supplicant 49 * uses -(errno) when an error code from libc is available. Therefore the 50 * values are non-portable and specific values must not be tested in the code. 51 */ 52 int tee_fs_rpc_access(int id, const char *name, int mode); 53 int tee_fs_rpc_begin_transaction(int id); 54 int tee_fs_rpc_end_transaction(int id, bool rollback); 55 int tee_fs_rpc_link(int id, const char *old, const char *nw); 56 int tee_fs_rpc_mkdir(int id, const char *path, tee_fs_mode_t mode); 57 struct tee_fs_dir *tee_fs_rpc_opendir(int id, const char *name); 58 struct tee_fs_dirent *tee_fs_rpc_readdir(int id, struct tee_fs_dir *d); 59 int tee_fs_rpc_rename(int id, const char *old, const char *nw); 60 int tee_fs_rpc_closedir(int id, struct tee_fs_dir *d); 61 int tee_fs_rpc_rmdir(int id, const char *name); 62 63 struct tee_fs_rpc_operation { 64 uint32_t id; 65 struct optee_msg_param params[THREAD_RPC_MAX_NUM_PARAMS]; 66 size_t num_params; 67 }; 68 69 TEE_Result tee_fs_rpc_new_open(uint32_t id, const char *fname, int *fd); 70 TEE_Result tee_fs_rpc_new_create(uint32_t id, const char *fname, int *fd); 71 TEE_Result tee_fs_rpc_new_close(uint32_t id, int fd); 72 73 TEE_Result tee_fs_rpc_new_read_init(struct tee_fs_rpc_operation *op, 74 uint32_t id, int fd, tee_fs_off_t offset, 75 size_t data_len, void **out_data); 76 TEE_Result tee_fs_rpc_new_read_final(struct tee_fs_rpc_operation *op, 77 size_t *data_len); 78 79 TEE_Result tee_fs_rpc_new_write_init(struct tee_fs_rpc_operation *op, 80 uint32_t id, int fd, tee_fs_off_t offset, 81 size_t data_len, void **data); 82 TEE_Result tee_fs_rpc_new_write_final(struct tee_fs_rpc_operation *op); 83 84 85 TEE_Result tee_fs_rpc_new_truncate(uint32_t id, int fd, size_t len); 86 TEE_Result tee_fs_rpc_new_remove(uint32_t id, const char *fname); 87 TEE_Result tee_fs_rpc_new_rename(uint32_t id, const char *old_fname, 88 const char *new_fname, bool overwrite); 89 90 TEE_Result tee_fs_rpc_new_opendir(uint32_t id, const char *name, 91 struct tee_fs_dir **d); 92 TEE_Result tee_fs_rpc_new_closedir(uint32_t id, struct tee_fs_dir *d); 93 TEE_Result tee_fs_rpc_new_readdir(uint32_t id, struct tee_fs_dir *d, 94 struct tee_fs_dirent **ent); 95 96 TEE_Result tee_fs_rpc_new_begin_transaction(uint32_t id); 97 TEE_Result tee_fs_rpc_new_end_transaction(uint32_t id, bool rollback); 98 99 struct thread_specific_data; 100 #if defined(CFG_WITH_USER_TA) && \ 101 (defined(CFG_REE_FS) || defined(CFG_SQL_FS) || defined(CFG_RPMB_FS)) 102 /* Frees the cache of allocated FS RPC memory */ 103 void tee_fs_rpc_cache_clear(struct thread_specific_data *tsd); 104 #else 105 static inline void tee_fs_rpc_cache_clear( 106 struct thread_specific_data *tsd __unused) 107 { 108 } 109 #endif 110 111 /* 112 * Returns a pointer to the cached FS RPC memory. Each thread has a unique 113 * cache. The pointer is guaranteed to point to a large enough area or to 114 * be NULL. 115 */ 116 void *tee_fs_rpc_cache_alloc(size_t size, paddr_t *pa, uint64_t *cookie); 117 118 #endif /* TEE_FS_RPC_H */ 119