Update from upstream to 2.4.0 version
[platform/core/security/tef-optee_os.git] / core / arch / arm / include / kernel / pseudo_ta.h
1 /*
2  * Copyright (c) 2015, 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 #ifndef KERNEL_PSEUDO_TA_H
28 #define KERNEL_PSEUDO_TA_H
29
30 #include <assert.h>
31 #include <compiler.h>
32 #include <kernel/tee_ta_manager.h>
33 #include <tee_api_types.h>
34 #include <user_ta_header.h>
35 #include <util.h>
36
37 #define PTA_MANDATORY_FLAGS     (TA_FLAG_SINGLE_INSTANCE | \
38                                 TA_FLAG_MULTI_SESSION | \
39                                 TA_FLAG_INSTANCE_KEEP_ALIVE)
40
41 #define PTA_ALLOWED_FLAGS       (PTA_MANDATORY_FLAGS | \
42                                 TA_FLAG_SECURE_DATA_PATH)
43
44 #define PTA_DEFAULT_FLAGS       PTA_MANDATORY_FLAGS
45
46 struct pseudo_ta_head {
47         TEE_UUID uuid;
48         const char *name;
49         uint32_t flags;
50
51         TEE_Result (*create_entry_point)(void);
52         void (*destroy_entry_point)(void);
53         TEE_Result (*open_session_entry_point)(uint32_t nParamTypes,
54                         TEE_Param pParams[TEE_NUM_PARAMS],
55                         void **ppSessionContext);
56         void (*close_session_entry_point)(void *pSessionContext);
57         TEE_Result (*invoke_command_entry_point)(void *pSessionContext,
58                         uint32_t nCommandID, uint32_t nParamTypes,
59                         TEE_Param pParams[TEE_NUM_PARAMS]);
60 };
61
62 #define pseudo_ta_register(...) static const struct pseudo_ta_head __head \
63                         __used __section("ta_head_section") = { __VA_ARGS__ }
64
65
66 struct pseudo_ta_ctx {
67         const struct pseudo_ta_head *pseudo_ta;
68         struct tee_ta_ctx ctx;
69 };
70
71 static inline bool is_pseudo_ta_ctx(struct tee_ta_ctx *ctx)
72 {
73         return !(ctx->flags & TA_FLAG_USER_MODE);
74 }
75
76 static inline struct pseudo_ta_ctx *to_pseudo_ta_ctx(struct tee_ta_ctx *ctx)
77 {
78         assert(is_pseudo_ta_ctx(ctx));
79         return container_of(ctx, struct pseudo_ta_ctx, ctx);
80 }
81
82 TEE_Result tee_ta_init_pseudo_ta_session(const TEE_UUID *uuid,
83                         struct tee_ta_session *s);
84
85 #endif /* KERNEL_PSEUDO_TA_H */
86