Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tee: Refactor TEE subsystem header files

Since commit 25559c22cef8 ("tee: add kernel internal client interface"),
it has been a common include/linux/tee_drv.h header file which is shared
to hold TEE subsystem internal bits along with the APIs exposed to the
TEE client drivers. However, this practice is prone to TEE subsystem
internal APIs abuse and especially so with the new TEE implementation
drivers being added to reuse existing functionality.

In order to address this split TEE subsystem internal bits as a separate
header file: include/linux/tee_core.h which should be the one used by
TEE implementation drivers. With that include/linux/tee_drv.h lists only
APIs exposed by TEE subsystem to the TEE client drivers.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

authored by

Sumit Garg and committed by
Jens Wiklander
0439fcff 4cece764

+359 -321
+1
MAINTAINERS
··· 21684 21684 F: Documentation/tee/ 21685 21685 F: Documentation/userspace-api/tee.rst 21686 21686 F: drivers/tee/ 21687 + F: include/linux/tee_core.h 21687 21688 F: include/linux/tee_drv.h 21688 21689 F: include/uapi/linux/tee.h 21689 21690
+1 -1
drivers/tee/amdtee/amdtee_private.h
··· 9 9 10 10 #include <linux/mutex.h> 11 11 #include <linux/spinlock.h> 12 - #include <linux/tee_drv.h> 12 + #include <linux/tee_core.h> 13 13 #include <linux/kref.h> 14 14 #include <linux/types.h> 15 15 #include "amdtee_if.h"
+1 -1
drivers/tee/amdtee/call.c
··· 5 5 6 6 #include <linux/device.h> 7 7 #include <linux/tee.h> 8 - #include <linux/tee_drv.h> 8 + #include <linux/tee_core.h> 9 9 #include <linux/psp-tee.h> 10 10 #include <linux/slab.h> 11 11 #include <linux/psp.h>
+1 -2
drivers/tee/amdtee/core.c
··· 9 9 #include <linux/slab.h> 10 10 #include <linux/string.h> 11 11 #include <linux/device.h> 12 - #include <linux/tee_drv.h> 12 + #include <linux/tee_core.h> 13 13 #include <linux/types.h> 14 14 #include <linux/mm.h> 15 15 #include <linux/uaccess.h> 16 16 #include <linux/firmware.h> 17 17 #include "amdtee_private.h" 18 - #include "../tee_private.h" 19 18 #include <linux/psp-tee.h> 20 19 21 20 static struct amdtee_driver_data *drv_data;
+1 -1
drivers/tee/amdtee/shm_pool.c
··· 4 4 */ 5 5 6 6 #include <linux/slab.h> 7 - #include <linux/tee_drv.h> 7 + #include <linux/tee_core.h> 8 8 #include <linux/psp.h> 9 9 #include "amdtee_private.h" 10 10
+1 -1
drivers/tee/optee/call.c
··· 7 7 #include <linux/errno.h> 8 8 #include <linux/mm.h> 9 9 #include <linux/slab.h> 10 - #include <linux/tee_drv.h> 10 + #include <linux/tee_core.h> 11 11 #include <linux/types.h> 12 12 #include "optee_private.h" 13 13
+1 -1
drivers/tee/optee/core.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/slab.h> 15 15 #include <linux/string.h> 16 - #include <linux/tee_drv.h> 16 + #include <linux/tee_core.h> 17 17 #include <linux/types.h> 18 18 #include "optee_private.h" 19 19
+1 -1
drivers/tee/optee/device.c
··· 7 7 8 8 #include <linux/kernel.h> 9 9 #include <linux/slab.h> 10 - #include <linux/tee_drv.h> 10 + #include <linux/tee_core.h> 11 11 #include <linux/uuid.h> 12 12 #include "optee_private.h" 13 13
+1 -1
drivers/tee/optee/ffa_abi.c
··· 11 11 #include <linux/sched.h> 12 12 #include <linux/slab.h> 13 13 #include <linux/string.h> 14 - #include <linux/tee_drv.h> 14 + #include <linux/tee_core.h> 15 15 #include <linux/types.h> 16 16 #include "optee_private.h" 17 17 #include "optee_ffa.h"
+1 -1
drivers/tee/optee/notif.c
··· 9 9 #include <linux/errno.h> 10 10 #include <linux/slab.h> 11 11 #include <linux/spinlock.h> 12 - #include <linux/tee_drv.h> 12 + #include <linux/tee_core.h> 13 13 #include "optee_private.h" 14 14 15 15 struct notif_entry {
+1 -1
drivers/tee/optee/optee_private.h
··· 9 9 #include <linux/arm-smccc.h> 10 10 #include <linux/rhashtable.h> 11 11 #include <linux/semaphore.h> 12 - #include <linux/tee_drv.h> 12 + #include <linux/tee_core.h> 13 13 #include <linux/types.h> 14 14 #include "optee_msg.h" 15 15
+1 -1
drivers/tee/optee/rpc.c
··· 8 8 #include <linux/delay.h> 9 9 #include <linux/i2c.h> 10 10 #include <linux/slab.h> 11 - #include <linux/tee_drv.h> 11 + #include <linux/tee_core.h> 12 12 #include "optee_private.h" 13 13 #include "optee_rpc_cmd.h" 14 14
+1 -1
drivers/tee/optee/smc_abi.c
··· 23 23 #include <linux/sched.h> 24 24 #include <linux/slab.h> 25 25 #include <linux/string.h> 26 - #include <linux/tee_drv.h> 26 + #include <linux/tee_core.h> 27 27 #include <linux/types.h> 28 28 #include <linux/workqueue.h> 29 29 #include "optee_private.h"
+1 -1
drivers/tee/tee_core.c
··· 11 11 #include <linux/idr.h> 12 12 #include <linux/module.h> 13 13 #include <linux/slab.h> 14 - #include <linux/tee_drv.h> 14 + #include <linux/tee_core.h> 15 15 #include <linux/uaccess.h> 16 16 #include <crypto/hash.h> 17 17 #include <crypto/sha1.h>
-35
drivers/tee/tee_private.h
··· 12 12 #include <linux/mutex.h> 13 13 #include <linux/types.h> 14 14 15 - #define TEE_DEVICE_FLAG_REGISTERED 0x1 16 - #define TEE_MAX_DEV_NAME_LEN 32 17 - 18 - /** 19 - * struct tee_device - TEE Device representation 20 - * @name: name of device 21 - * @desc: description of device 22 - * @id: unique id of device 23 - * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above 24 - * @dev: embedded basic device structure 25 - * @cdev: embedded cdev 26 - * @num_users: number of active users of this device 27 - * @c_no_user: completion used when unregistering the device 28 - * @mutex: mutex protecting @num_users and @idr 29 - * @idr: register of user space shared memory objects allocated or 30 - * registered on this device 31 - * @pool: shared memory pool 32 - */ 33 - struct tee_device { 34 - char name[TEE_MAX_DEV_NAME_LEN]; 35 - const struct tee_desc *desc; 36 - int id; 37 - unsigned int flags; 38 - 39 - struct device dev; 40 - struct cdev cdev; 41 - 42 - size_t num_users; 43 - struct completion c_no_users; 44 - struct mutex mutex; /* protects num_users and idr */ 45 - 46 - struct idr idr; 47 - struct tee_shm_pool *pool; 48 - }; 49 - 50 15 int tee_shm_get_fd(struct tee_shm *shm); 51 16 52 17 bool tee_device_get(struct tee_device *teedev);
+1 -1
drivers/tee/tee_shm.c
··· 8 8 #include <linux/mm.h> 9 9 #include <linux/sched.h> 10 10 #include <linux/slab.h> 11 - #include <linux/tee_drv.h> 11 + #include <linux/tee_core.h> 12 12 #include <linux/uaccess.h> 13 13 #include <linux/uio.h> 14 14 #include <linux/highmem.h>
+1 -1
drivers/tee/tee_shm_pool.c
··· 6 6 #include <linux/dma-buf.h> 7 7 #include <linux/genalloc.h> 8 8 #include <linux/slab.h> 9 - #include <linux/tee_drv.h> 9 + #include <linux/tee_core.h> 10 10 #include "tee_private.h" 11 11 12 12 static int pool_op_gen_alloc(struct tee_shm_pool *pool, struct tee_shm *shm,
+296
include/linux/tee_core.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (c) 2024 Linaro Limited 4 + */ 5 + 6 + #ifndef __TEE_CORE_H 7 + #define __TEE_CORE_H 8 + 9 + #include <linux/cdev.h> 10 + #include <linux/device.h> 11 + #include <linux/idr.h> 12 + #include <linux/kref.h> 13 + #include <linux/list.h> 14 + #include <linux/tee.h> 15 + #include <linux/tee_drv.h> 16 + #include <linux/types.h> 17 + #include <linux/uuid.h> 18 + 19 + /* 20 + * The file describes the API provided by the generic TEE driver to the 21 + * specific TEE driver. 22 + */ 23 + 24 + #define TEE_SHM_DYNAMIC BIT(0) /* Dynamic shared memory registered */ 25 + /* in secure world */ 26 + #define TEE_SHM_USER_MAPPED BIT(1) /* Memory mapped in user space */ 27 + #define TEE_SHM_POOL BIT(2) /* Memory allocated from pool */ 28 + #define TEE_SHM_PRIV BIT(3) /* Memory private to TEE driver */ 29 + 30 + #define TEE_DEVICE_FLAG_REGISTERED 0x1 31 + #define TEE_MAX_DEV_NAME_LEN 32 32 + 33 + /** 34 + * struct tee_device - TEE Device representation 35 + * @name: name of device 36 + * @desc: description of device 37 + * @id: unique id of device 38 + * @flags: represented by TEE_DEVICE_FLAG_REGISTERED above 39 + * @dev: embedded basic device structure 40 + * @cdev: embedded cdev 41 + * @num_users: number of active users of this device 42 + * @c_no_user: completion used when unregistering the device 43 + * @mutex: mutex protecting @num_users and @idr 44 + * @idr: register of user space shared memory objects allocated or 45 + * registered on this device 46 + * @pool: shared memory pool 47 + */ 48 + struct tee_device { 49 + char name[TEE_MAX_DEV_NAME_LEN]; 50 + const struct tee_desc *desc; 51 + int id; 52 + unsigned int flags; 53 + 54 + struct device dev; 55 + struct cdev cdev; 56 + 57 + size_t num_users; 58 + struct completion c_no_users; 59 + struct mutex mutex; /* protects num_users and idr */ 60 + 61 + struct idr idr; 62 + struct tee_shm_pool *pool; 63 + }; 64 + 65 + /** 66 + * struct tee_driver_ops - driver operations vtable 67 + * @get_version: returns version of driver 68 + * @open: called when the device file is opened 69 + * @release: release this open file 70 + * @open_session: open a new session 71 + * @close_session: close a session 72 + * @system_session: declare session as a system session 73 + * @invoke_func: invoke a trusted function 74 + * @cancel_req: request cancel of an ongoing invoke or open 75 + * @supp_recv: called for supplicant to get a command 76 + * @supp_send: called for supplicant to send a response 77 + * @shm_register: register shared memory buffer in TEE 78 + * @shm_unregister: unregister shared memory buffer in TEE 79 + */ 80 + struct tee_driver_ops { 81 + void (*get_version)(struct tee_device *teedev, 82 + struct tee_ioctl_version_data *vers); 83 + int (*open)(struct tee_context *ctx); 84 + void (*release)(struct tee_context *ctx); 85 + int (*open_session)(struct tee_context *ctx, 86 + struct tee_ioctl_open_session_arg *arg, 87 + struct tee_param *param); 88 + int (*close_session)(struct tee_context *ctx, u32 session); 89 + int (*system_session)(struct tee_context *ctx, u32 session); 90 + int (*invoke_func)(struct tee_context *ctx, 91 + struct tee_ioctl_invoke_arg *arg, 92 + struct tee_param *param); 93 + int (*cancel_req)(struct tee_context *ctx, u32 cancel_id, u32 session); 94 + int (*supp_recv)(struct tee_context *ctx, u32 *func, u32 *num_params, 95 + struct tee_param *param); 96 + int (*supp_send)(struct tee_context *ctx, u32 ret, u32 num_params, 97 + struct tee_param *param); 98 + int (*shm_register)(struct tee_context *ctx, struct tee_shm *shm, 99 + struct page **pages, size_t num_pages, 100 + unsigned long start); 101 + int (*shm_unregister)(struct tee_context *ctx, struct tee_shm *shm); 102 + }; 103 + 104 + /** 105 + * struct tee_desc - Describes the TEE driver to the subsystem 106 + * @name: name of driver 107 + * @ops: driver operations vtable 108 + * @owner: module providing the driver 109 + * @flags: Extra properties of driver, defined by TEE_DESC_* below 110 + */ 111 + #define TEE_DESC_PRIVILEGED 0x1 112 + struct tee_desc { 113 + const char *name; 114 + const struct tee_driver_ops *ops; 115 + struct module *owner; 116 + u32 flags; 117 + }; 118 + 119 + /** 120 + * tee_device_alloc() - Allocate a new struct tee_device instance 121 + * @teedesc: Descriptor for this driver 122 + * @dev: Parent device for this device 123 + * @pool: Shared memory pool, NULL if not used 124 + * @driver_data: Private driver data for this device 125 + * 126 + * Allocates a new struct tee_device instance. The device is 127 + * removed by tee_device_unregister(). 128 + * 129 + * @returns a pointer to a 'struct tee_device' or an ERR_PTR on failure 130 + */ 131 + struct tee_device *tee_device_alloc(const struct tee_desc *teedesc, 132 + struct device *dev, 133 + struct tee_shm_pool *pool, 134 + void *driver_data); 135 + 136 + /** 137 + * tee_device_register() - Registers a TEE device 138 + * @teedev: Device to register 139 + * 140 + * tee_device_unregister() need to be called to remove the @teedev if 141 + * this function fails. 142 + * 143 + * @returns < 0 on failure 144 + */ 145 + int tee_device_register(struct tee_device *teedev); 146 + 147 + /** 148 + * tee_device_unregister() - Removes a TEE device 149 + * @teedev: Device to unregister 150 + * 151 + * This function should be called to remove the @teedev even if 152 + * tee_device_register() hasn't been called yet. Does nothing if 153 + * @teedev is NULL. 154 + */ 155 + void tee_device_unregister(struct tee_device *teedev); 156 + 157 + /** 158 + * tee_session_calc_client_uuid() - Calculates client UUID for session 159 + * @uuid: Resulting UUID 160 + * @connection_method: Connection method for session (TEE_IOCTL_LOGIN_*) 161 + * @connectuon_data: Connection data for opening session 162 + * 163 + * Based on connection method calculates UUIDv5 based client UUID. 164 + * 165 + * For group based logins verifies that calling process has specified 166 + * credentials. 167 + * 168 + * @return < 0 on failure 169 + */ 170 + int tee_session_calc_client_uuid(uuid_t *uuid, u32 connection_method, 171 + const u8 connection_data[TEE_IOCTL_UUID_LEN]); 172 + 173 + /** 174 + * struct tee_shm_pool - shared memory pool 175 + * @ops: operations 176 + * @private_data: private data for the shared memory manager 177 + */ 178 + struct tee_shm_pool { 179 + const struct tee_shm_pool_ops *ops; 180 + void *private_data; 181 + }; 182 + 183 + /** 184 + * struct tee_shm_pool_ops - shared memory pool operations 185 + * @alloc: called when allocating shared memory 186 + * @free: called when freeing shared memory 187 + * @destroy_pool: called when destroying the pool 188 + */ 189 + struct tee_shm_pool_ops { 190 + int (*alloc)(struct tee_shm_pool *pool, struct tee_shm *shm, 191 + size_t size, size_t align); 192 + void (*free)(struct tee_shm_pool *pool, struct tee_shm *shm); 193 + void (*destroy_pool)(struct tee_shm_pool *pool); 194 + }; 195 + 196 + /* 197 + * tee_shm_pool_alloc_res_mem() - Create a shm manager for reserved memory 198 + * @vaddr: Virtual address of start of pool 199 + * @paddr: Physical address of start of pool 200 + * @size: Size in bytes of the pool 201 + * 202 + * @returns pointer to a 'struct tee_shm_pool' or an ERR_PTR on failure. 203 + */ 204 + struct tee_shm_pool *tee_shm_pool_alloc_res_mem(unsigned long vaddr, 205 + phys_addr_t paddr, size_t size, 206 + int min_alloc_order); 207 + 208 + /** 209 + * tee_shm_pool_free() - Free a shared memory pool 210 + * @pool: The shared memory pool to free 211 + * 212 + * The must be no remaining shared memory allocated from this pool when 213 + * this function is called. 214 + */ 215 + static inline void tee_shm_pool_free(struct tee_shm_pool *pool) 216 + { 217 + pool->ops->destroy_pool(pool); 218 + } 219 + 220 + /** 221 + * tee_get_drvdata() - Return driver_data pointer 222 + * @returns the driver_data pointer supplied to tee_register(). 223 + */ 224 + void *tee_get_drvdata(struct tee_device *teedev); 225 + 226 + /** 227 + * tee_shm_alloc_priv_buf() - Allocate shared memory for private use by specific 228 + * TEE driver 229 + * @ctx: The TEE context for shared memory allocation 230 + * @size: Shared memory allocation size 231 + * @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure 232 + */ 233 + struct tee_shm *tee_shm_alloc_priv_buf(struct tee_context *ctx, size_t size); 234 + 235 + /** 236 + * tee_shm_is_dynamic() - Check if shared memory object is of the dynamic kind 237 + * @shm: Shared memory handle 238 + * @returns true if object is dynamic shared memory 239 + */ 240 + static inline bool tee_shm_is_dynamic(struct tee_shm *shm) 241 + { 242 + return shm && (shm->flags & TEE_SHM_DYNAMIC); 243 + } 244 + 245 + /** 246 + * tee_shm_put() - Decrease reference count on a shared memory handle 247 + * @shm: Shared memory handle 248 + */ 249 + void tee_shm_put(struct tee_shm *shm); 250 + 251 + /** 252 + * tee_shm_get_id() - Get id of a shared memory object 253 + * @shm: Shared memory handle 254 + * @returns id 255 + */ 256 + static inline int tee_shm_get_id(struct tee_shm *shm) 257 + { 258 + return shm->id; 259 + } 260 + 261 + /** 262 + * tee_shm_get_from_id() - Find shared memory object and increase reference 263 + * count 264 + * @ctx: Context owning the shared memory 265 + * @id: Id of shared memory object 266 + * @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure 267 + */ 268 + struct tee_shm *tee_shm_get_from_id(struct tee_context *ctx, int id); 269 + 270 + static inline bool tee_param_is_memref(struct tee_param *param) 271 + { 272 + switch (param->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) { 273 + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: 274 + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: 275 + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: 276 + return true; 277 + default: 278 + return false; 279 + } 280 + } 281 + 282 + /** 283 + * teedev_open() - Open a struct tee_device 284 + * @teedev: Device to open 285 + * 286 + * @return a pointer to struct tee_context on success or an ERR_PTR on failure. 287 + */ 288 + struct tee_context *teedev_open(struct tee_device *teedev); 289 + 290 + /** 291 + * teedev_close_context() - closes a struct tee_context 292 + * @ctx: The struct tee_context to close 293 + */ 294 + void teedev_close_context(struct tee_context *ctx); 295 + 296 + #endif /*__TEE_CORE_H*/
+47 -270
include/linux/tee_drv.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 2 /* 3 - * Copyright (c) 2015-2022 Linaro Limited 3 + * Copyright (c) 2015-2024 Linaro Limited 4 4 */ 5 5 6 6 #ifndef __TEE_DRV_H 7 7 #define __TEE_DRV_H 8 8 9 9 #include <linux/device.h> 10 - #include <linux/idr.h> 11 10 #include <linux/kref.h> 12 11 #include <linux/list.h> 13 12 #include <linux/mod_devicetable.h> 14 13 #include <linux/tee.h> 15 14 #include <linux/types.h> 16 - #include <linux/uuid.h> 17 15 18 16 /* 19 - * The file describes the API provided by the generic TEE driver to the 20 - * specific TEE driver. 17 + * The file describes the API provided by the TEE subsystem to the 18 + * TEE client drivers. 21 19 */ 22 20 23 - #define TEE_SHM_DYNAMIC BIT(0) /* Dynamic shared memory registered */ 24 - /* in secure world */ 25 - #define TEE_SHM_USER_MAPPED BIT(1) /* Memory mapped in user space */ 26 - #define TEE_SHM_POOL BIT(2) /* Memory allocated from pool */ 27 - #define TEE_SHM_PRIV BIT(3) /* Memory private to TEE driver */ 28 - 29 - struct device; 30 21 struct tee_device; 31 - struct tee_shm; 32 - struct tee_shm_pool; 33 22 34 23 /** 35 24 * struct tee_context - driver specific context on file pointer data 36 25 * @teedev: pointer to this drivers struct tee_device 37 - * @list_shm: List of shared memory object owned by this context 38 26 * @data: driver specific context data, managed by the driver 39 27 * @refcount: reference counter for this structure 40 28 * @releasing: flag that indicates if context is being released right now. ··· 43 55 bool releasing; 44 56 bool supp_nowait; 45 57 bool cap_memref_null; 58 + }; 59 + 60 + /** 61 + * struct tee_shm - shared memory object 62 + * @ctx: context using the object 63 + * @paddr: physical address of the shared memory 64 + * @kaddr: virtual address of the shared memory 65 + * @size: size of shared memory 66 + * @offset: offset of buffer in user space 67 + * @pages: locked pages from userspace 68 + * @num_pages: number of locked pages 69 + * @refcount: reference counter 70 + * @flags: defined by TEE_SHM_* in tee_core.h 71 + * @id: unique id of a shared memory object on this device, shared 72 + * with user space 73 + * @sec_world_id: 74 + * secure world assigned id of this shared memory object, not 75 + * used by all drivers 76 + */ 77 + struct tee_shm { 78 + struct tee_context *ctx; 79 + phys_addr_t paddr; 80 + void *kaddr; 81 + size_t size; 82 + unsigned int offset; 83 + struct page **pages; 84 + size_t num_pages; 85 + refcount_t refcount; 86 + u32 flags; 87 + int id; 88 + u64 sec_world_id; 46 89 }; 47 90 48 91 struct tee_param_memref { ··· 97 78 }; 98 79 99 80 /** 100 - * struct tee_driver_ops - driver operations vtable 101 - * @get_version: returns version of driver 102 - * @open: called when the device file is opened 103 - * @release: release this open file 104 - * @open_session: open a new session 105 - * @close_session: close a session 106 - * @system_session: declare session as a system session 107 - * @invoke_func: invoke a trusted function 108 - * @cancel_req: request cancel of an ongoing invoke or open 109 - * @supp_recv: called for supplicant to get a command 110 - * @supp_send: called for supplicant to send a response 111 - * @shm_register: register shared memory buffer in TEE 112 - * @shm_unregister: unregister shared memory buffer in TEE 81 + * tee_shm_alloc_kernel_buf() - Allocate kernel shared memory for a 82 + * particular TEE client driver 83 + * @ctx: The TEE context for shared memory allocation 84 + * @size: Shared memory allocation size 85 + * @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure 113 86 */ 114 - struct tee_driver_ops { 115 - void (*get_version)(struct tee_device *teedev, 116 - struct tee_ioctl_version_data *vers); 117 - int (*open)(struct tee_context *ctx); 118 - void (*release)(struct tee_context *ctx); 119 - int (*open_session)(struct tee_context *ctx, 120 - struct tee_ioctl_open_session_arg *arg, 121 - struct tee_param *param); 122 - int (*close_session)(struct tee_context *ctx, u32 session); 123 - int (*system_session)(struct tee_context *ctx, u32 session); 124 - int (*invoke_func)(struct tee_context *ctx, 125 - struct tee_ioctl_invoke_arg *arg, 126 - struct tee_param *param); 127 - int (*cancel_req)(struct tee_context *ctx, u32 cancel_id, u32 session); 128 - int (*supp_recv)(struct tee_context *ctx, u32 *func, u32 *num_params, 129 - struct tee_param *param); 130 - int (*supp_send)(struct tee_context *ctx, u32 ret, u32 num_params, 131 - struct tee_param *param); 132 - int (*shm_register)(struct tee_context *ctx, struct tee_shm *shm, 133 - struct page **pages, size_t num_pages, 134 - unsigned long start); 135 - int (*shm_unregister)(struct tee_context *ctx, struct tee_shm *shm); 136 - }; 137 - 138 - /** 139 - * struct tee_desc - Describes the TEE driver to the subsystem 140 - * @name: name of driver 141 - * @ops: driver operations vtable 142 - * @owner: module providing the driver 143 - * @flags: Extra properties of driver, defined by TEE_DESC_* below 144 - */ 145 - #define TEE_DESC_PRIVILEGED 0x1 146 - struct tee_desc { 147 - const char *name; 148 - const struct tee_driver_ops *ops; 149 - struct module *owner; 150 - u32 flags; 151 - }; 152 - 153 - /** 154 - * tee_device_alloc() - Allocate a new struct tee_device instance 155 - * @teedesc: Descriptor for this driver 156 - * @dev: Parent device for this device 157 - * @pool: Shared memory pool, NULL if not used 158 - * @driver_data: Private driver data for this device 159 - * 160 - * Allocates a new struct tee_device instance. The device is 161 - * removed by tee_device_unregister(). 162 - * 163 - * @returns a pointer to a 'struct tee_device' or an ERR_PTR on failure 164 - */ 165 - struct tee_device *tee_device_alloc(const struct tee_desc *teedesc, 166 - struct device *dev, 167 - struct tee_shm_pool *pool, 168 - void *driver_data); 169 - 170 - /** 171 - * tee_device_register() - Registers a TEE device 172 - * @teedev: Device to register 173 - * 174 - * tee_device_unregister() need to be called to remove the @teedev if 175 - * this function fails. 176 - * 177 - * @returns < 0 on failure 178 - */ 179 - int tee_device_register(struct tee_device *teedev); 180 - 181 - /** 182 - * tee_device_unregister() - Removes a TEE device 183 - * @teedev: Device to unregister 184 - * 185 - * This function should be called to remove the @teedev even if 186 - * tee_device_register() hasn't been called yet. Does nothing if 187 - * @teedev is NULL. 188 - */ 189 - void tee_device_unregister(struct tee_device *teedev); 190 - 191 - /** 192 - * tee_session_calc_client_uuid() - Calculates client UUID for session 193 - * @uuid: Resulting UUID 194 - * @connection_method: Connection method for session (TEE_IOCTL_LOGIN_*) 195 - * @connectuon_data: Connection data for opening session 196 - * 197 - * Based on connection method calculates UUIDv5 based client UUID. 198 - * 199 - * For group based logins verifies that calling process has specified 200 - * credentials. 201 - * 202 - * @return < 0 on failure 203 - */ 204 - int tee_session_calc_client_uuid(uuid_t *uuid, u32 connection_method, 205 - const u8 connection_data[TEE_IOCTL_UUID_LEN]); 206 - 207 - /** 208 - * struct tee_shm - shared memory object 209 - * @ctx: context using the object 210 - * @paddr: physical address of the shared memory 211 - * @kaddr: virtual address of the shared memory 212 - * @size: size of shared memory 213 - * @offset: offset of buffer in user space 214 - * @pages: locked pages from userspace 215 - * @num_pages: number of locked pages 216 - * @refcount: reference counter 217 - * @flags: defined by TEE_SHM_* in tee_drv.h 218 - * @id: unique id of a shared memory object on this device, shared 219 - * with user space 220 - * @sec_world_id: 221 - * secure world assigned id of this shared memory object, not 222 - * used by all drivers 223 - * 224 - * This pool is only supposed to be accessed directly from the TEE 225 - * subsystem and from drivers that implements their own shm pool manager. 226 - */ 227 - struct tee_shm { 228 - struct tee_context *ctx; 229 - phys_addr_t paddr; 230 - void *kaddr; 231 - size_t size; 232 - unsigned int offset; 233 - struct page **pages; 234 - size_t num_pages; 235 - refcount_t refcount; 236 - u32 flags; 237 - int id; 238 - u64 sec_world_id; 239 - }; 240 - 241 - /** 242 - * struct tee_shm_pool - shared memory pool 243 - * @ops: operations 244 - * @private_data: private data for the shared memory manager 245 - */ 246 - struct tee_shm_pool { 247 - const struct tee_shm_pool_ops *ops; 248 - void *private_data; 249 - }; 250 - 251 - /** 252 - * struct tee_shm_pool_ops - shared memory pool operations 253 - * @alloc: called when allocating shared memory 254 - * @free: called when freeing shared memory 255 - * @destroy_pool: called when destroying the pool 256 - */ 257 - struct tee_shm_pool_ops { 258 - int (*alloc)(struct tee_shm_pool *pool, struct tee_shm *shm, 259 - size_t size, size_t align); 260 - void (*free)(struct tee_shm_pool *pool, struct tee_shm *shm); 261 - void (*destroy_pool)(struct tee_shm_pool *pool); 262 - }; 263 - 264 - /* 265 - * tee_shm_pool_alloc_res_mem() - Create a shm manager for reserved memory 266 - * @vaddr: Virtual address of start of pool 267 - * @paddr: Physical address of start of pool 268 - * @size: Size in bytes of the pool 269 - * 270 - * @returns pointer to a 'struct tee_shm_pool' or an ERR_PTR on failure. 271 - */ 272 - struct tee_shm_pool *tee_shm_pool_alloc_res_mem(unsigned long vaddr, 273 - phys_addr_t paddr, size_t size, 274 - int min_alloc_order); 275 - 276 - /** 277 - * tee_shm_pool_free() - Free a shared memory pool 278 - * @pool: The shared memory pool to free 279 - * 280 - * The must be no remaining shared memory allocated from this pool when 281 - * this function is called. 282 - */ 283 - static inline void tee_shm_pool_free(struct tee_shm_pool *pool) 284 - { 285 - pool->ops->destroy_pool(pool); 286 - } 287 - 288 - /** 289 - * tee_get_drvdata() - Return driver_data pointer 290 - * @returns the driver_data pointer supplied to tee_register(). 291 - */ 292 - void *tee_get_drvdata(struct tee_device *teedev); 293 - 294 - struct tee_shm *tee_shm_alloc_priv_buf(struct tee_context *ctx, size_t size); 295 87 struct tee_shm *tee_shm_alloc_kernel_buf(struct tee_context *ctx, size_t size); 296 88 89 + /** 90 + * tee_shm_register_kernel_buf() - Register kernel shared memory for a 91 + * particular TEE client driver 92 + * @ctx: The TEE context for shared memory registration 93 + * @addr: Kernel buffer address 94 + * @length: Kernel buffer length 95 + * @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure 96 + */ 297 97 struct tee_shm *tee_shm_register_kernel_buf(struct tee_context *ctx, 298 98 void *addr, size_t length); 299 - 300 - /** 301 - * tee_shm_is_dynamic() - Check if shared memory object is of the dynamic kind 302 - * @shm: Shared memory handle 303 - * @returns true if object is dynamic shared memory 304 - */ 305 - static inline bool tee_shm_is_dynamic(struct tee_shm *shm) 306 - { 307 - return shm && (shm->flags & TEE_SHM_DYNAMIC); 308 - } 309 99 310 100 /** 311 101 * tee_shm_free() - Free shared memory 312 102 * @shm: Handle to shared memory to free 313 103 */ 314 104 void tee_shm_free(struct tee_shm *shm); 315 - 316 - /** 317 - * tee_shm_put() - Decrease reference count on a shared memory handle 318 - * @shm: Shared memory handle 319 - */ 320 - void tee_shm_put(struct tee_shm *shm); 321 105 322 106 /** 323 107 * tee_shm_get_va() - Get virtual address of a shared memory plus an offset ··· 173 351 { 174 352 return shm->offset; 175 353 } 176 - 177 - /** 178 - * tee_shm_get_id() - Get id of a shared memory object 179 - * @shm: Shared memory handle 180 - * @returns id 181 - */ 182 - static inline int tee_shm_get_id(struct tee_shm *shm) 183 - { 184 - return shm->id; 185 - } 186 - 187 - /** 188 - * tee_shm_get_from_id() - Find shared memory object and increase reference 189 - * count 190 - * @ctx: Context owning the shared memory 191 - * @id: Id of shared memory object 192 - * @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure 193 - */ 194 - struct tee_shm *tee_shm_get_from_id(struct tee_context *ctx, int id); 195 354 196 355 /** 197 356 * tee_client_open_context() - Open a TEE context ··· 273 470 int tee_client_cancel_req(struct tee_context *ctx, 274 471 struct tee_ioctl_cancel_arg *arg); 275 472 276 - static inline bool tee_param_is_memref(struct tee_param *param) 277 - { 278 - switch (param->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) { 279 - case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: 280 - case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: 281 - case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: 282 - return true; 283 - default: 284 - return false; 285 - } 286 - } 287 - 288 473 extern const struct bus_type tee_bus_type; 289 474 290 475 /** ··· 299 508 300 509 #define to_tee_client_driver(d) \ 301 510 container_of(d, struct tee_client_driver, driver) 302 - 303 - /** 304 - * teedev_open() - Open a struct tee_device 305 - * @teedev: Device to open 306 - * 307 - * @return a pointer to struct tee_context on success or an ERR_PTR on failure. 308 - */ 309 - struct tee_context *teedev_open(struct tee_device *teedev); 310 - 311 - /** 312 - * teedev_close_context() - closes a struct tee_context 313 - * @ctx: The struct tee_context to close 314 - */ 315 - void teedev_close_context(struct tee_context *ctx); 316 511 317 512 #endif /*__TEE_DRV_H*/