xref: /optee_os/core/include/kernel/ts_store.h (revision ef44161f847bb1f17e6c803e70047d749e7b394e)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015-2019, Linaro Limited
4  * Copyright (c) 2020, Arm Limited.
5  */
6 #ifndef __KERNEL_TS_STORE_H
7 #define __KERNEL_TS_STORE_H
8 
9 #include <tee_api_types.h>
10 
11 struct ts_store_handle;
12 struct ts_store_ops {
13 	/*
14 	 * Human-readable string to describe where the TS comes from.
15 	 * For debug purposes only.
16 	 */
17 	const char *description;
18 	/*
19 	 * Open a TS. Does not guarantee that the TS is valid or even exists.
20 	 */
21 	TEE_Result (*open)(const TEE_UUID *uuid,
22 			   struct ts_store_handle **h);
23 	/*
24 	 * Return the size of the unencrypted TS binary, that is: the TS
25 	 * header (struct ta_head or sp_head) plus the ELF data.
26 	 */
27 	TEE_Result (*get_size)(const struct ts_store_handle *h,
28 			       size_t *size);
29 
30 	/*
31 	 * Return the tag or hash of the TS binary. Used to uniquely
32 	 * identify the binary also if the binary happens to be updated.
33 	 */
34 	TEE_Result (*get_tag)(const struct ts_store_handle *h,
35 			      uint8_t *tag, unsigned int *tag_len);
36 	/*
37 	 * Read the TS sequentially, from the start of the TS header (struct
38 	 * ta_head or sp_head) up to the end of the ELF.
39 	 * The TEE core is expected to read *exactly* get_size() bytes in total
40 	 * unless an error occurs. Therefore, an implementation may rely on the
41 	 * condition (current offset == total size) to detect the last call to
42 	 * this function.
43 	 * @data_core: pointer to secure memory where the TS bytes should be
44 	 *             copied.
45 	 * @data_user: pointer to user memory where the TS bytes should be
46 	 *             copied.
47 	 * At least one of @data_core and @data_user are normally NULL, but
48 	 * both are also permitted to be non-NULL.
49 	 * If @data_core == NULL and @data_user == NULL and @len != 0, the
50 	 * function should just skip @len bytes.
51 	 */
52 	TEE_Result (*read)(struct ts_store_handle *h, void *data_core,
53 			   void *data_user, size_t len);
54 	/*
55 	 * Close a TS handle. Do nothing if @h == NULL.
56 	 */
57 	void (*close)(struct ts_store_handle *h);
58 };
59 
60 /*
61  * Registers a TA storage.
62  *
63  * A TA is loaded from the first TA storage in which the TA can be found.
64  * TA storage is searched in order of priority, where lower values are
65  * tried first.
66  *
67  * Note prio must be unique per storage in order to avoid dependency on
68  * registration order. This is enforced by a deliberate linker error in
69  * case of conflict.
70  *
71  * Also note that TA storage is sorted lexicographically instead of
72  * numerically.
73  */
74 #define REGISTER_TA_STORE(prio) \
75 	int __tee_ta_store_##prio __unused; \
76 	SCATTERED_ARRAY_DEFINE_PG_ITEM_ORDERED(ta_stores, prio, \
77 					       struct ts_store_ops)
78 
79 /*
80  * Registers a SP storage.
81  *
82  * The SP store is separate from the TA store. The user of the stores knows if
83  * it needs to access the TA store or if it needs to access the SP one.
84  */
85 #define REGISTER_SP_STORE(prio) \
86 	int __tee_sp_store_##prio __unused; \
87 	SCATTERED_ARRAY_DEFINE_PG_ITEM_ORDERED(sp_stores, prio, \
88 					       struct ts_store_ops)
89 #endif /*__KERNEL_TS_STORE_H*/
90