1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2018-2019, Linaro Limited
4  * Copyright (c) 2020, Open Mobile Platform LLC
5  */
6 #ifndef __PTA_SYSTEM_H
7 #define __PTA_SYSTEM_H
8 
9 #include <util.h>
10 
11 /*
12  * Interface to the pseudo TA, which is provides misc. auxiliary services,
13  * extending existing GlobalPlatform Core API
14  */
15 
16 #define PTA_SYSTEM_UUID { 0x3a2f8978, 0x5dc0, 0x11e8, { \
17 			 0x9c, 0x2d, 0xfa, 0x7a, 0xe0, 0x1b, 0xbe, 0xbc } }
18 
19 /*
20  * Having keys with too few bits impose a potential security risk, hence set a
21  * lower bound of 128 bits.
22  */
23 #define TA_DERIVED_KEY_MIN_SIZE		16
24 
25 /* Same value as max in huk_subkey_derive */
26 #define TA_DERIVED_KEY_MAX_SIZE		32
27 
28 #define TA_DERIVED_EXTRA_DATA_MAX_SIZE	1024
29 
30 /*
31  * Add (re-seed) caller-provided entropy to the RNG pool. Keymaster
32  * implementations need to securely mix the provided entropy into their pool,
33  * which also must contain internally-generated entropy from a hardware random
34  * number generator.
35  *
36  * [in]     memref[0]: entropy input data
37  */
38 #define PTA_SYSTEM_ADD_RNG_ENTROPY	0
39 
40 /*
41  * Derives a device and TA unique key. The caller can also provide extra data
42  * that will be mixed together with existing device unique properties. If no
43  * extra data is provided, then the derived key will only use device unique
44  * properties and caller TA UUID.
45  *
46  * [in]  params[0].memref.buffer     Buffer for extra data
47  * [in]  params[0].memref.size       Size of extra data (max 1024 bytes)
48  * [out] params[1].memref.buffer     Buffer for the derived key
49  * [out] params[1].memref.size       Size of the derived key (16 to 32 bytes)
50  */
51 #define PTA_SYSTEM_DERIVE_TA_UNIQUE_KEY 1
52 
53 /* Memory can be shared with other TAs */
54 #define PTA_SYSTEM_MAP_FLAG_SHAREABLE	BIT32(0)
55 /* Read/write memory */
56 #define PTA_SYSTEM_MAP_FLAG_WRITEABLE	BIT32(1)
57 /* Executable memory */
58 #define PTA_SYSTEM_MAP_FLAG_EXECUTABLE	BIT32(2)
59 
60 /*
61  * Map zero initialized memory
62  *
63  * [in]	    value[0].a: Number of bytes
64  * [in]	    value[0].b: Flags, 0 or PTA_SYSTEM_MAP_FLAG_SHAREABLE
65  * [out]    value[1].a: Address upper 32-bits
66  * [out]    value[1].b: Address lower 32-bits
67  * [in]     value[2].a: Extra pad before memory range
68  * [in]     value[2].b: Extra pad after memory range
69  */
70 #define PTA_SYSTEM_MAP_ZI		2
71 
72 /*
73  * Unmap memory
74  *
75  * [in]	    value[0].a: Number of bytes
76  * [in]	    value[0].b: Must be 0
77  * [in]	    value[1].a: Address upper 32-bits
78  * [in]	    value[1].b: Address lower 32-bits
79  */
80 #define PTA_SYSTEM_UNMAP		3
81 
82 /*
83  * Find and opens an TA binary and return a handle
84  *
85  * [in]	    memref[0]:	UUID of TA binary
86  * [out]    value[1].a:	Handle to TA binary
87  * [out]    value[1].b:	0
88  */
89 #define PTA_SYSTEM_OPEN_TA_BINARY	4
90 
91 /*
92  * Close an TA binary handle
93  *
94  * When a TA is done mapping new parts of an TA binary it closes the handle
95  * to free resources, established mappings remains.
96  *
97  * [in]     value[1].a:	Handle to TA binary
98  * [in]     value[1].b:	Must be 0
99  *
100  * Returns TEE_SUCCESS if the TA binary was verified successfully.
101  */
102 #define PTA_SYSTEM_CLOSE_TA_BINARY	5
103 
104 /*
105  * Map segment of TA binary
106  *
107  * Different parts of an TA binary file needs different permissions.
108  * Read-write mapped parts are private to the TA, while read-only (which
109  * includes execute) mapped parts are shared with other TAs. This is
110  * transparent to the TA. If the supplied address in value[3] is 0 a
111  * suitable address is selected, else it will either be mapped at that
112  * address of an error is returned.
113  *
114  * [in]     value[0].a:	Handle to TA binary
115  * [in]     value[0].b:	Flags, PTA_SYSTEM_MAP_FLAG_*
116  * [in]     value[1].a:	Offset into TA binary, must be page aligned
117  * [in]     value[1].b:	Number of bytes, the last page will be zero
118  *			extended if not page aligned
119  * [in/out] value[2].a:	Address upper 32-bits
120  * [in/out] value[2].b:	Address lower 32-bits
121  * [in]     value[3].a: Extra pad before memory range
122  * [in]     value[3].b: Extra pad after memory range
123  */
124 #define PTA_SYSTEM_MAP_TA_BINARY	6
125 
126 /*
127  * Copy a memory range from TA binary
128  *
129  * [in]     value[0].a:	Handle to TA binary
130  * [in]     value[0].b:	Offset into TA binary
131  * [out]    memref[1]:	Destination
132  */
133 #define PTA_SYSTEM_COPY_FROM_TA_BINARY	7
134 
135 /*
136  * Set memory protection
137  *
138  * [in]	    value[0].a: Number of bytes
139  * [in]     value[0].b:	Flags, PTA_SYSTEM_MAP_FLAG_*
140  * [in]	    value[1].a: Address upper 32-bits
141  * [in]	    value[1].b: Address lower 32-bits
142  */
143 #define PTA_SYSTEM_SET_PROT		8
144 
145 /*
146  * Remap a segment of a TA mapping
147  *
148  * Moves an already mapped segment of a TA to a new address. If the
149  * supplied new address is 0 a suitable address is selected, else it will
150  * either be mapped at that address or an error is returned.
151  *
152  * [in]	    value[0].a: Number of bytes, must match length rounded up to
153  *			closest page of original mapping
154  * [in]     value[0].b:	Must be 0
155  * [in]	    value[1].a:	Old address upper 32-bits
156  * [in]     value[1].b:	Old address lower 32-bits
157  * [in/out] value[2].a:	New address upper 32-bits
158  * [in/out] value[2].b:	New address lower 32-bits
159  * [in]     value[3].a: Extra pad before memory range
160  * [in]     value[3].b: Extra pad after memory range
161  */
162 #define PTA_SYSTEM_REMAP		9
163 
164 /*
165  * Load a shared library
166  *
167  * [in]     memref[0]: the UUID of the shared library (@filename)
168  * [in]     value[1].a: @flags, must be (RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE)
169  *
170  * Used by: (libdl) dlopen(const char *filename, int flags)
171  */
172 #define PTA_SYSTEM_DLOPEN               10
173 
174 /*
175  * Resolve a symbol in a previously loaded shared library or in the whole TA
176  *
177  * [in]     memref[0]: the UUID of the shared library, or the nil UUID to
178  *                     search the whole TA
179  * [in]     memref[1]: symbol name (@symbol)
180  * [out]    value[2]: address of the symbol or NULL
181  *
182  * Used by: (libdl) dlsym(void *handle, const char *symbol)
183  */
184 #define PTA_SYSTEM_DLSYM                11
185 
186 /*
187  * Retrieves a copy of the TPM Event log held in secure memory.
188  *
189  * [out]    memref[0]: Pointer to the buffer where to store the event log.
190  */
191 #define PTA_SYSTEM_GET_TPM_EVENT_LOG	12
192 
193 /*
194  * Invoke a tee-supplicant's plugin
195  *
196  * [in]     memref[0]        uuid of the plugin (TEE_UUID)
197  * [in]     value[1].a       command for the plugin
198  * [in]     value[1].b       sub_command for the plugin
199  * [in/out] memref[2]        additional data for the plugin
200  * [out]    value[3].a       output length of data
201  */
202 #define PTA_SYSTEM_SUPP_PLUGIN_INVOKE	13
203 
204 #endif /* __PTA_SYSTEM_H */
205