aboutsummaryrefslogtreecommitdiffstats
path: root/include/uapi
diff options
context:
space:
mode:
Diffstat (limited to 'include/uapi')
-rw-r--r--include/uapi/linux/tee.h346
1 files changed, 346 insertions, 0 deletions
diff --git a/include/uapi/linux/tee.h b/include/uapi/linux/tee.h
new file mode 100644
index 000000000000..370d8845ab21
--- /dev/null
+++ b/include/uapi/linux/tee.h
@@ -0,0 +1,346 @@
1/*
2 * Copyright (c) 2015-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#ifndef __TEE_H
29#define __TEE_H
30
31#include <linux/ioctl.h>
32#include <linux/types.h>
33
34/*
35 * This file describes the API provided by a TEE driver to user space.
36 *
37 * Each TEE driver defines a TEE specific protocol which is used for the
38 * data passed back and forth using TEE_IOC_CMD.
39 */
40
41/* Helpers to make the ioctl defines */
42#define TEE_IOC_MAGIC 0xa4
43#define TEE_IOC_BASE 0
44
45/* Flags relating to shared memory */
46#define TEE_IOCTL_SHM_MAPPED 0x1 /* memory mapped in normal world */
47#define TEE_IOCTL_SHM_DMA_BUF 0x2 /* dma-buf handle on shared memory */
48
49#define TEE_MAX_ARG_SIZE 1024
50
51#define TEE_GEN_CAP_GP (1 << 0)/* GlobalPlatform compliant TEE */
52
53/*
54 * TEE Implementation ID
55 */
56#define TEE_IMPL_ID_OPTEE 1
57
58/*
59 * OP-TEE specific capabilities
60 */
61#define TEE_OPTEE_CAP_TZ (1 << 0)
62
63/**
64 * struct tee_ioctl_version_data - TEE version
65 * @impl_id: [out] TEE implementation id
66 * @impl_caps: [out] Implementation specific capabilities
67 * @gen_caps: [out] Generic capabilities, defined by TEE_GEN_CAPS_* above
68 *
69 * Identifies the TEE implementation, @impl_id is one of TEE_IMPL_ID_* above.
70 * @impl_caps is implementation specific, for example TEE_OPTEE_CAP_*
71 * is valid when @impl_id == TEE_IMPL_ID_OPTEE.
72 */
73struct tee_ioctl_version_data {
74 __u32 impl_id;
75 __u32 impl_caps;
76 __u32 gen_caps;
77};
78
79/**
80 * TEE_IOC_VERSION - query version of TEE
81 *
82 * Takes a tee_ioctl_version_data struct and returns with the TEE version
83 * data filled in.
84 */
85#define TEE_IOC_VERSION _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 0, \
86 struct tee_ioctl_version_data)
87
88/**
89 * struct tee_ioctl_shm_alloc_data - Shared memory allocate argument
90 * @size: [in/out] Size of shared memory to allocate
91 * @flags: [in/out] Flags to/from allocation.
92 * @id: [out] Identifier of the shared memory
93 *
94 * The flags field should currently be zero as input. Updated by the call
95 * with actual flags as defined by TEE_IOCTL_SHM_* above.
96 * This structure is used as argument for TEE_IOC_SHM_ALLOC below.
97 */
98struct tee_ioctl_shm_alloc_data {
99 __u64 size;
100 __u32 flags;
101 __s32 id;
102};
103
104/**
105 * TEE_IOC_SHM_ALLOC - allocate shared memory
106 *
107 * Allocates shared memory between the user space process and secure OS.
108 *
109 * Returns a file descriptor on success or < 0 on failure
110 *
111 * The returned file descriptor is used to map the shared memory into user
112 * space. The shared memory is freed when the descriptor is closed and the
113 * memory is unmapped.
114 */
115#define TEE_IOC_SHM_ALLOC _IOWR(TEE_IOC_MAGIC, TEE_IOC_BASE + 1, \
116 struct tee_ioctl_shm_alloc_data)
117
118/**
119 * struct tee_ioctl_buf_data - Variable sized buffer
120 * @buf_ptr: [in] A __user pointer to a buffer
121 * @buf_len: [in] Length of the buffer above
122 *
123 * Used as argument for TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE,
124 * TEE_IOC_SUPPL_RECV, and TEE_IOC_SUPPL_SEND below.
125 */
126struct tee_ioctl_buf_data {
127 __u64 buf_ptr;
128 __u64 buf_len;
129};
130
131/*
132 * Attributes for struct tee_ioctl_param, selects field in the union
133 */
134#define TEE_IOCTL_PARAM_ATTR_TYPE_NONE 0 /* parameter not used */
135
136/*
137 * These defines value parameters (struct tee_ioctl_param_value)
138 */
139#define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT 1
140#define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT 2
141#define TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT 3 /* input and output */
142
143/*
144 * These defines shared memory reference parameters (struct
145 * tee_ioctl_param_memref)
146 */
147#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT 5
148#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT 6
149#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT 7 /* input and output */
150
151/*
152 * Mask for the type part of the attribute, leaves room for more types
153 */
154#define TEE_IOCTL_PARAM_ATTR_TYPE_MASK 0xff
155
156/*
157 * Matches TEEC_LOGIN_* in GP TEE Client API
158 * Are only defined for GP compliant TEEs
159 */
160#define TEE_IOCTL_LOGIN_PUBLIC 0
161#define TEE_IOCTL_LOGIN_USER 1
162#define TEE_IOCTL_LOGIN_GROUP 2
163#define TEE_IOCTL_LOGIN_APPLICATION 4
164#define TEE_IOCTL_LOGIN_USER_APPLICATION 5
165#define TEE_IOCTL_LOGIN_GROUP_APPLICATION 6
166
167/**
168 * struct tee_ioctl_param - parameter
169 * @attr: attributes
170 * @a: if a memref, offset into the shared memory object, else a value parameter
171 * @b: if a memref, size of the buffer, else a value parameter
172 * @c: if a memref, shared memory identifier, else a value parameter
173 *
174 * @attr & TEE_PARAM_ATTR_TYPE_MASK indicates if memref or value is used in
175 * the union. TEE_PARAM_ATTR_TYPE_VALUE_* indicates value and
176 * TEE_PARAM_ATTR_TYPE_MEMREF_* indicates memref. TEE_PARAM_ATTR_TYPE_NONE
177 * indicates that none of the members are used.
178 *
179 * Shared memory is allocated with TEE_IOC_SHM_ALLOC which returns an
180 * identifier representing the shared memory object. A memref can reference
181 * a part of a shared memory by specifying an offset (@a) and size (@b) of
182 * the object. To supply the entire shared memory object set the offset
183 * (@a) to 0 and size (@b) to the previously returned size of the object.
184 */
185struct tee_ioctl_param {
186 __u64 attr;
187 __u64 a;
188 __u64 b;
189 __u64 c;
190};
191
192#define TEE_IOCTL_UUID_LEN 16
193
194/**
195 * struct tee_ioctl_open_session_arg - Open session argument
196 * @uuid: [in] UUID of the Trusted Application
197 * @clnt_uuid: [in] UUID of client
198 * @clnt_login: [in] Login class of client, TEE_IOCTL_LOGIN_* above
199 * @cancel_id: [in] Cancellation id, a unique value to identify this request
200 * @session: [out] Session id
201 * @ret: [out] return value
202 * @ret_origin [out] origin of the return value
203 * @num_params [in] number of parameters following this struct
204 */
205struct tee_ioctl_open_session_arg {
206 __u8 uuid[TEE_IOCTL_UUID_LEN];
207 __u8 clnt_uuid[TEE_IOCTL_UUID_LEN];
208 __u32 clnt_login;
209 __u32 cancel_id;
210 __u32 session;
211 __u32 ret;
212 __u32 ret_origin;
213 __u32 num_params;
214 /* num_params tells the actual number of element in params */
215 struct tee_ioctl_param params[];
216};
217