4d73c4ba54dec74b364f5f27e525f3457ddc9e3c
[platform/core/security/tef-optee_os.git] / core / include / tee / tee_fs_rpc.h
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 TEE_Result tee_fs_rpc_open(uint32_t id, const char *fname, int *fd);
48 TEE_Result tee_fs_rpc_create(uint32_t id, const char *fname, int *fd);
49 TEE_Result tee_fs_rpc_close(uint32_t id, int fd);
50
51 TEE_Result tee_fs_rpc_read_init(struct tee_fs_rpc_operation *op,
52                                 uint32_t id, int fd, tee_fs_off_t offset,
53                                 size_t data_len, void **out_data);
54 TEE_Result tee_fs_rpc_read_final(struct tee_fs_rpc_operation *op,
55                                  size_t *data_len);
56
57 TEE_Result tee_fs_rpc_write_init(struct tee_fs_rpc_operation *op,
58                                  uint32_t id, int fd, tee_fs_off_t offset,
59                                  size_t data_len, void **data);
60 TEE_Result tee_fs_rpc_write_final(struct tee_fs_rpc_operation *op);
61
62
63 TEE_Result tee_fs_rpc_truncate(uint32_t id, int fd, size_t len);
64 TEE_Result tee_fs_rpc_remove(uint32_t id, const char *fname);
65 TEE_Result tee_fs_rpc_rename(uint32_t id, const char *old_fname,
66                              const char *new_fname, bool overwrite);
67
68 TEE_Result tee_fs_rpc_opendir(uint32_t id, const char *name,
69                                   struct tee_fs_dir **d);
70 TEE_Result tee_fs_rpc_closedir(uint32_t id, struct tee_fs_dir *d);
71 TEE_Result tee_fs_rpc_readdir(uint32_t id, struct tee_fs_dir *d,
72                               struct tee_fs_dirent **ent);
73
74 TEE_Result tee_fs_rpc_begin_transaction(uint32_t id);
75 TEE_Result tee_fs_rpc_end_transaction(uint32_t id, bool rollback);
76
77 struct thread_specific_data;
78 #if defined(CFG_WITH_USER_TA) && \
79         (defined(CFG_REE_FS) || defined(CFG_SQL_FS) || defined(CFG_RPMB_FS))
80 /* Frees the cache of allocated FS RPC memory */
81 void tee_fs_rpc_cache_clear(struct thread_specific_data *tsd);
82 #else
83 static inline void tee_fs_rpc_cache_clear(
84                         struct thread_specific_data *tsd __unused)
85 {
86 }
87 #endif
88
89 /*
90  * Returns a pointer to the cached FS RPC memory. Each thread has a unique
91  * cache. The pointer is guaranteed to point to a large enough area or to
92  * be NULL.
93  */
94 void *tee_fs_rpc_cache_alloc(size_t size, paddr_t *pa, uint64_t *cookie);
95
96 #endif /* TEE_FS_RPC_H */