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 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 struct tee_fs_rpc_operation { 42 uint32_t id; 43 struct optee_msg_param params[THREAD_RPC_MAX_NUM_PARAMS]; 44 size_t num_params; 45 }; 46 47 struct tee_fs_dirfile_fileh; 48 49 TEE_Result tee_fs_rpc_open(uint32_t id, struct tee_pobj *po, int *fd); 50 TEE_Result tee_fs_rpc_open_dfh(uint32_t id, 51 const struct tee_fs_dirfile_fileh *dfh, int *fd); 52 TEE_Result tee_fs_rpc_create(uint32_t id, struct tee_pobj *po, int *fd); 53 TEE_Result tee_fs_rpc_create_dfh(uint32_t id, 54 const struct tee_fs_dirfile_fileh *dfh, 55 int *fd); 56 TEE_Result tee_fs_rpc_close(uint32_t id, int fd); 57 58 TEE_Result tee_fs_rpc_read_init(struct tee_fs_rpc_operation *op, 59 uint32_t id, int fd, tee_fs_off_t offset, 60 size_t data_len, void **out_data); 61 TEE_Result tee_fs_rpc_read_final(struct tee_fs_rpc_operation *op, 62 size_t *data_len); 63 64 TEE_Result tee_fs_rpc_write_init(struct tee_fs_rpc_operation *op, 65 uint32_t id, int fd, tee_fs_off_t offset, 66 size_t data_len, void **data); 67 TEE_Result tee_fs_rpc_write_final(struct tee_fs_rpc_operation *op); 68 69 70 TEE_Result tee_fs_rpc_truncate(uint32_t id, int fd, size_t len); 71 TEE_Result tee_fs_rpc_remove(uint32_t id, struct tee_pobj *po); 72 TEE_Result tee_fs_rpc_remove_dfh(uint32_t id, 73 const struct tee_fs_dirfile_fileh *dfh); 74 TEE_Result tee_fs_rpc_rename(uint32_t id, struct tee_pobj *old, 75 struct tee_pobj *new, bool overwrite); 76 77 TEE_Result tee_fs_rpc_opendir(uint32_t id, const TEE_UUID *uuid, 78 struct tee_fs_dir **d); 79 TEE_Result tee_fs_rpc_closedir(uint32_t id, struct tee_fs_dir *d); 80 TEE_Result tee_fs_rpc_readdir(uint32_t id, struct tee_fs_dir *d, 81 struct tee_fs_dirent **ent); 82 83 struct thread_specific_data; 84 #if defined(CFG_WITH_USER_TA) && (defined(CFG_REE_FS) || defined(CFG_RPMB_FS)) 85 /* Frees the cache of allocated FS RPC memory */ 86 void tee_fs_rpc_cache_clear(struct thread_specific_data *tsd); 87 #else 88 static inline void tee_fs_rpc_cache_clear( 89 struct thread_specific_data *tsd __unused) 90 { 91 } 92 #endif 93 94 /* 95 * Returns a pointer to the cached FS RPC memory. Each thread has a unique 96 * cache. The pointer is guaranteed to point to a large enough area or to 97 * be NULL. 98 */ 99 void *tee_fs_rpc_cache_alloc(size_t size, struct mobj **mobj, uint64_t *cookie); 100 101 #endif /* TEE_FS_RPC_H */ 102