xref: /optee_os/core/include/tee/tee_fs_rpc.h (revision 1bb929836182ecb96d2d9d268daa807c67596396)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2016, Linaro Limited
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * Interface with tee-supplicant for file operations
31  */
32 
33 #ifndef TEE_FS_RPC_H
34 #define TEE_FS_RPC_H
35 
36 #include <stdbool.h>
37 #include <stddef.h>
38 #include <tee_api_types.h>
39 #include <tee/tee_fs.h>
40 #include <kernel/thread.h>
41 
42 struct tee_fs_rpc_operation {
43 	uint32_t id;
44 	struct optee_msg_param params[THREAD_RPC_MAX_NUM_PARAMS];
45 	size_t num_params;
46 };
47 
48 struct tee_fs_dirfile_fileh;
49 
50 TEE_Result tee_fs_rpc_open(uint32_t id, struct tee_pobj *po, int *fd);
51 TEE_Result tee_fs_rpc_open_dfh(uint32_t id,
52 			       const struct tee_fs_dirfile_fileh *dfh, int *fd);
53 TEE_Result tee_fs_rpc_create(uint32_t id, struct tee_pobj *po, int *fd);
54 TEE_Result tee_fs_rpc_create_dfh(uint32_t id,
55 				 const struct tee_fs_dirfile_fileh *dfh,
56 				 int *fd);
57 TEE_Result tee_fs_rpc_close(uint32_t id, int fd);
58 
59 TEE_Result tee_fs_rpc_read_init(struct tee_fs_rpc_operation *op,
60 				uint32_t id, int fd, tee_fs_off_t offset,
61 				size_t data_len, void **out_data);
62 TEE_Result tee_fs_rpc_read_final(struct tee_fs_rpc_operation *op,
63 				 size_t *data_len);
64 
65 TEE_Result tee_fs_rpc_write_init(struct tee_fs_rpc_operation *op,
66 				 uint32_t id, int fd, tee_fs_off_t offset,
67 				 size_t data_len, void **data);
68 TEE_Result tee_fs_rpc_write_final(struct tee_fs_rpc_operation *op);
69 
70 
71 TEE_Result tee_fs_rpc_truncate(uint32_t id, int fd, size_t len);
72 TEE_Result tee_fs_rpc_remove(uint32_t id, struct tee_pobj *po);
73 TEE_Result tee_fs_rpc_remove_dfh(uint32_t id,
74 				 const struct tee_fs_dirfile_fileh *dfh);
75 TEE_Result tee_fs_rpc_rename(uint32_t id, struct tee_pobj *old,
76 			     struct tee_pobj *new, bool overwrite);
77 
78 TEE_Result tee_fs_rpc_opendir(uint32_t id, const TEE_UUID *uuid,
79 				  struct tee_fs_dir **d);
80 TEE_Result tee_fs_rpc_closedir(uint32_t id, struct tee_fs_dir *d);
81 TEE_Result tee_fs_rpc_readdir(uint32_t id, struct tee_fs_dir *d,
82 			      struct tee_fs_dirent **ent);
83 
84 struct thread_specific_data;
85 #if defined(CFG_WITH_USER_TA) && (defined(CFG_REE_FS) || defined(CFG_RPMB_FS))
86 /* Frees the cache of allocated FS RPC memory */
87 void tee_fs_rpc_cache_clear(struct thread_specific_data *tsd);
88 #else
89 static inline void tee_fs_rpc_cache_clear(
90 			struct thread_specific_data *tsd __unused)
91 {
92 }
93 #endif
94 
95 /*
96  * Returns a pointer to the cached FS RPC memory. Each thread has a unique
97  * cache. The pointer is guaranteed to point to a large enough area or to
98  * be NULL.
99  */
100 void *tee_fs_rpc_cache_alloc(size_t size, struct mobj **mobj, uint64_t *cookie);
101 
102 #endif /* TEE_FS_RPC_H */
103