xref: /optee_os/core/include/tee/tee_fs_rpc.h (revision 1955df60859295baad31f23e90e7b0cd1943c776)
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 /*
41  * Return values:
42  *   < 0: error. The actual value is meaningless (see below).
43  *  >= 0: success. The value may be a file descriptor, a number of bytes, or
44  *        simply 0 depending on the function.
45  *
46  * The return value is the status set by the normal world (tee-supplicant) or
47  * -1 in case of communication error. To facilitate debugging, tee-supplicant
48  * uses -(errno) when an error code from libc is available. Therefore the
49  * values are non-portable and specific values must not be tested in the code.
50  */
51 int tee_fs_rpc_access(int id, const char *name, int mode);
52 int tee_fs_rpc_begin_transaction(int id);
53 int tee_fs_rpc_close(int id, int fd);
54 int tee_fs_rpc_end_transaction(int id, bool rollback);
55 int tee_fs_rpc_ftruncate(int id, int fd, tee_fs_off_t length);
56 int tee_fs_rpc_link(int id, const char *old, const char *nw);
57 tee_fs_off_t tee_fs_rpc_lseek(int id, int fd, tee_fs_off_t offset,
58 				  int whence);
59 int tee_fs_rpc_mkdir(int id, const char *path, tee_fs_mode_t mode);
60 int tee_fs_rpc_open(int id, const char *file, int flags);
61 struct tee_fs_dir *tee_fs_rpc_opendir(int id, const char *name);
62 int tee_fs_rpc_read(int id, int fd, void *buf, size_t len);
63 struct tee_fs_dirent *tee_fs_rpc_readdir(int id, struct tee_fs_dir *d);
64 int tee_fs_rpc_rename(int id, const char *old, const char *nw);
65 int tee_fs_rpc_write(int id, int fd, const void *buf, size_t len);
66 int tee_fs_rpc_closedir(int id, struct tee_fs_dir *d);
67 int tee_fs_rpc_rmdir(int id, const char *name);
68 int tee_fs_rpc_unlink(int id, const char *file);
69 
70 struct thread_specific_data;
71 #if defined(CFG_WITH_USER_TA) && \
72 	(defined(CFG_REE_FS) || defined(CFG_SQL_FS) || defined(CFG_RPMB_FS))
73 /* Frees the cache of allocated FS RPC memory */
74 void tee_fs_rpc_cache_clear(struct thread_specific_data *tsd);
75 #else
76 static inline void tee_fs_rpc_cache_clear(
77 			struct thread_specific_data *tsd __unused)
78 {
79 }
80 #endif
81 
82 /*
83  * Returns a pointer to the cached FS RPC memory. Each thread has a unique
84  * cache. The pointer is guaranteed to point to a large enough area or to
85  * be NULL.
86  */
87 void *tee_fs_rpc_cache_alloc(size_t size, paddr_t *pa, uint64_t *cookie);
88 
89 #endif /* TEE_FS_RPC_H */
90