xref: /optee_os/core/include/tee/tee_fs_rpc.h (revision c3b3c4de602ccd7690bcbd65181d43d622b017e4)
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 
40 /* TEE FS operation */
41 #define TEE_FS_OPEN       1
42 #define TEE_FS_CLOSE      2
43 #define TEE_FS_READ       3
44 #define TEE_FS_WRITE      4
45 #define TEE_FS_SEEK       5
46 #define TEE_FS_UNLINK     6
47 #define TEE_FS_RENAME     7
48 #define TEE_FS_TRUNC      8
49 #define TEE_FS_MKDIR      9
50 #define TEE_FS_OPENDIR   10
51 #define TEE_FS_CLOSEDIR  11
52 #define TEE_FS_READDIR   12
53 #define TEE_FS_RMDIR     13
54 #define TEE_FS_ACCESS    14
55 #define TEE_FS_LINK      15
56 #define TEE_FS_BEGIN     16 /* SQL FS: begin transaction */
57 #define TEE_FS_END       17 /* SQL FS: end transaction */
58 
59 /* sql_fs_send_cmd 'mode' */
60 #define TEE_FS_MODE_NONE 0
61 #define TEE_FS_MODE_IN   1
62 #define TEE_FS_MODE_OUT  2
63 
64 struct tee_fs_rpc {
65 	int op;
66 	int flags;
67 	int arg;
68 	int fd;
69 	uint32_t len;
70 	int res;
71 };
72 
73 /*
74  * Return values:
75  *   < 0: error. The actual value is meaningless (see below).
76  *  >= 0: success. The value may be a file descriptor, a number of bytes, or
77  *        simply 0 depending on the function.
78  *
79  * The return value is the status set by the normal world (tee-supplicant) or
80  * -1 in case of communication error. To facilitate debugging, tee-supplicant
81  * uses -(errno) when an error code from libc is available. Therefore the
82  * values are non-portable and specific values must not be tested in the code.
83  */
84 int tee_fs_rpc_access(int id, const char *name, int mode);
85 int tee_fs_rpc_begin_transaction(int id);
86 int tee_fs_rpc_close(int id, int fd);
87 int tee_fs_rpc_end_transaction(int id, bool rollback);
88 int tee_fs_rpc_ftruncate(int id, int fd, tee_fs_off_t length);
89 int tee_fs_rpc_link(int id, const char *old, const char *nw);
90 tee_fs_off_t tee_fs_rpc_lseek(int id, int fd, tee_fs_off_t offset,
91 				  int whence);
92 int tee_fs_rpc_mkdir(int id, const char *path, tee_fs_mode_t mode);
93 int tee_fs_rpc_open(int id, const char *file, int flags);
94 struct tee_fs_dir *tee_fs_rpc_opendir(int id, const char *name);
95 int tee_fs_rpc_read(int id, int fd, void *buf, size_t len);
96 struct tee_fs_dirent *tee_fs_rpc_readdir(int id, struct tee_fs_dir *d);
97 int tee_fs_rpc_rename(int id, const char *old, const char *nw);
98 int tee_fs_rpc_write(int id, int fd, const void *buf, size_t len);
99 int tee_fs_rpc_closedir(int id, struct tee_fs_dir *d);
100 int tee_fs_rpc_rmdir(int id, const char *name);
101 int tee_fs_rpc_unlink(int id, const char *file);
102 
103 struct thread_specific_data;
104 #if defined(CFG_WITH_USER_TA) && \
105 	(defined(CFG_REE_FS) || defined(CFG_SQL_FS) || defined(CFG_RPMB_FS))
106 /* Frees the cache of allocated FS RPC memory */
107 void tee_fs_rpc_cache_clear(struct thread_specific_data *tsd);
108 #else
109 static inline void tee_fs_rpc_cache_clear(
110 			struct thread_specific_data *tsd __unused)
111 {
112 }
113 #endif
114 
115 /*
116  * Returns a pointer to the cached FS RPC memory. Each thread has a unique
117  * cache. The pointer is guaranteed to point to a large enough area or to
118  * be NULL.
119  */
120 void *tee_fs_rpc_cache_alloc(size_t size, paddr_t *pa, uint64_t *cookie);
121 
122 #endif /* TEE_FS_RPC_H */
123