xref: /optee_os/core/include/tee/tee_fs_rpc.h (revision 7f4173d82bfb3f631c7d45deef39ee8ce736dcbb)
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_close(int id, int fd);
55 int tee_fs_rpc_end_transaction(int id, bool rollback);
56 int tee_fs_rpc_ftruncate(int id, int fd, tee_fs_off_t length);
57 int tee_fs_rpc_link(int id, const char *old, const char *nw);
58 tee_fs_off_t tee_fs_rpc_lseek(int id, int fd, tee_fs_off_t offset,
59 				  int whence);
60 int tee_fs_rpc_mkdir(int id, const char *path, tee_fs_mode_t mode);
61 int tee_fs_rpc_open(int id, const char *file, int flags);
62 struct tee_fs_dir *tee_fs_rpc_opendir(int id, const char *name);
63 int tee_fs_rpc_read(int id, int fd, void *buf, size_t len);
64 struct tee_fs_dirent *tee_fs_rpc_readdir(int id, struct tee_fs_dir *d);
65 int tee_fs_rpc_rename(int id, const char *old, const char *nw);
66 int tee_fs_rpc_write(int id, int fd, const void *buf, size_t len);
67 int tee_fs_rpc_closedir(int id, struct tee_fs_dir *d);
68 int tee_fs_rpc_rmdir(int id, const char *name);
69 int tee_fs_rpc_unlink(int id, const char *file);
70 
71 struct tee_fs_rpc_operation {
72 	uint32_t id;
73 	struct optee_msg_param params[THREAD_RPC_MAX_NUM_PARAMS];
74 	size_t num_params;
75 };
76 
77 TEE_Result tee_fs_rpc_new_open(uint32_t id, const char *fname, int *fd);
78 TEE_Result tee_fs_rpc_new_create(uint32_t id, const char *fname, int *fd);
79 TEE_Result tee_fs_rpc_new_close(uint32_t id, int fd);
80 
81 TEE_Result tee_fs_rpc_new_read_init(struct tee_fs_rpc_operation *op,
82 				    uint32_t id, int fd, tee_fs_off_t offset,
83 				    size_t data_len, void **out_data);
84 TEE_Result tee_fs_rpc_new_read_final(struct tee_fs_rpc_operation *op,
85 				     size_t *data_len);
86 
87 TEE_Result tee_fs_rpc_new_write_init(struct tee_fs_rpc_operation *op,
88 				     uint32_t id, int fd, tee_fs_off_t offset,
89 				     size_t data_len, void **data);
90 TEE_Result tee_fs_rpc_new_write_final(struct tee_fs_rpc_operation *op);
91 
92 
93 TEE_Result tee_fs_rpc_new_truncate(uint32_t id, int fd, size_t len);
94 TEE_Result tee_fs_rpc_new_remove(uint32_t id, const char *fname);
95 TEE_Result tee_fs_rpc_new_rename(uint32_t id, const char *old_fname,
96 				 const char *new_fname, bool overwrite);
97 
98 TEE_Result tee_fs_rpc_new_opendir(uint32_t id, const char *name,
99 				  struct tee_fs_dir **d);
100 TEE_Result tee_fs_rpc_new_closedir(uint32_t id, struct tee_fs_dir *d);
101 TEE_Result tee_fs_rpc_new_readdir(uint32_t id, struct tee_fs_dir *d,
102 				  struct tee_fs_dirent **ent);
103 
104 TEE_Result tee_fs_rpc_new_begin_transaction(uint32_t id);
105 TEE_Result tee_fs_rpc_new_end_transaction(uint32_t id, bool rollback);
106 
107 struct thread_specific_data;
108 #if defined(CFG_WITH_USER_TA) && \
109 	(defined(CFG_REE_FS) || defined(CFG_SQL_FS) || defined(CFG_RPMB_FS))
110 /* Frees the cache of allocated FS RPC memory */
111 void tee_fs_rpc_cache_clear(struct thread_specific_data *tsd);
112 #else
113 static inline void tee_fs_rpc_cache_clear(
114 			struct thread_specific_data *tsd __unused)
115 {
116 }
117 #endif
118 
119 /*
120  * Returns a pointer to the cached FS RPC memory. Each thread has a unique
121  * cache. The pointer is guaranteed to point to a large enough area or to
122  * be NULL.
123  */
124 void *tee_fs_rpc_cache_alloc(size_t size, paddr_t *pa, uint64_t *cookie);
125 
126 #endif /* TEE_FS_RPC_H */
127