hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/linux/tee_drv.h
....@@ -1,25 +1,19 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (c) 2015-2016, Linaro Limited
3
- *
4
- * This software is licensed under the terms of the GNU General Public
5
- * License version 2, as published by the Free Software Foundation, and
6
- * may be copied, distributed, and modified under those terms.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
134 */
145
156 #ifndef __TEE_DRV_H
167 #define __TEE_DRV_H
178
18
-#include <linux/types.h>
9
+#include <linux/device.h>
1910 #include <linux/idr.h>
2011 #include <linux/kref.h>
2112 #include <linux/list.h>
13
+#include <linux/mod_devicetable.h>
2214 #include <linux/tee.h>
15
+#include <linux/types.h>
16
+#include <linux/uuid.h>
2317
2418 /*
2519 * The file describes the API provided by the generic TEE driver to the
....@@ -32,6 +26,8 @@
3226 #define TEE_SHM_REGISTER BIT(3) /* Memory registered in secure world */
3327 #define TEE_SHM_USER_MAPPED BIT(4) /* Memory mapped in user space */
3428 #define TEE_SHM_POOL BIT(5) /* Memory allocated from pool */
29
+#define TEE_SHM_KERNEL_MAPPED BIT(6) /* Memory mapped in kernel space */
30
+#define TEE_SHM_PRIV BIT(7) /* Memory private to TEE driver */
3531
3632 struct device;
3733 struct tee_device;
....@@ -47,13 +43,21 @@
4743 * @releasing: flag that indicates if context is being released right now.
4844 * It is needed to break circular dependency on context during
4945 * shared memory release.
46
+ * @supp_nowait: flag that indicates that requests in this context should not
47
+ * wait for tee-supplicant daemon to be started if not present
48
+ * and just return with an error code. It is needed for requests
49
+ * that arises from TEE based kernel drivers that should be
50
+ * non-blocking in nature.
51
+ * @cap_memref_null: flag indicating if the TEE Client support shared
52
+ * memory buffer with a NULL pointer.
5053 */
5154 struct tee_context {
5255 struct tee_device *teedev;
53
- struct list_head list_shm;
5456 void *data;
5557 struct kref refcount;
5658 bool releasing;
59
+ bool supp_nowait;
60
+ bool cap_memref_null;
5761 };
5862
5963 struct tee_param_memref {
....@@ -167,10 +171,24 @@
167171 void tee_device_unregister(struct tee_device *teedev);
168172
169173 /**
174
+ * tee_session_calc_client_uuid() - Calculates client UUID for session
175
+ * @uuid: Resulting UUID
176
+ * @connection_method: Connection method for session (TEE_IOCTL_LOGIN_*)
177
+ * @connectuon_data: Connection data for opening session
178
+ *
179
+ * Based on connection method calculates UUIDv5 based client UUID.
180
+ *
181
+ * For group based logins verifies that calling process has specified
182
+ * credentials.
183
+ *
184
+ * @return < 0 on failure
185
+ */
186
+int tee_session_calc_client_uuid(uuid_t *uuid, u32 connection_method,
187
+ const u8 connection_data[TEE_IOCTL_UUID_LEN]);
188
+
189
+/**
170190 * struct tee_shm - shared memory object
171
- * @teedev: device used to allocate the object
172
- * @ctx: context using the object, if NULL the context is gone
173
- * @link link element
191
+ * @ctx: context using the object
174192 * @paddr: physical address of the shared memory
175193 * @kaddr: virtual address of the shared memory
176194 * @size: size of shared memory
....@@ -185,9 +203,7 @@
185203 * subsystem and from drivers that implements their own shm pool manager.
186204 */
187205 struct tee_shm {
188
- struct tee_device *teedev;
189206 struct tee_context *ctx;
190
- struct list_head link;
191207 phys_addr_t paddr;
192208 void *kaddr;
193209 size_t size;
....@@ -317,18 +333,7 @@
317333 * @returns a pointer to 'struct tee_shm'
318334 */
319335 struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags);
320
-
321
-/**
322
- * tee_shm_priv_alloc() - Allocate shared memory privately
323
- * @dev: Device that allocates the shared memory
324
- * @size: Requested size of shared memory
325
- *
326
- * Allocates shared memory buffer that is not associated with any client
327
- * context. Such buffers are owned by TEE driver and used for internal calls.
328
- *
329
- * @returns a pointer to 'struct tee_shm'
330
- */
331
-struct tee_shm *tee_shm_priv_alloc(struct tee_device *teedev, size_t size);
336
+struct tee_shm *tee_shm_alloc_kernel_buf(struct tee_context *ctx, size_t size);
332337
333338 /**
334339 * tee_shm_register() - Register shared memory buffer
....@@ -453,6 +458,91 @@
453458 */
454459 struct tee_shm *tee_shm_get_from_id(struct tee_context *ctx, int id);
455460
461
+/**
462
+ * tee_client_open_context() - Open a TEE context
463
+ * @start: if not NULL, continue search after this context
464
+ * @match: function to check TEE device
465
+ * @data: data for match function
466
+ * @vers: if not NULL, version data of TEE device of the context returned
467
+ *
468
+ * This function does an operation similar to open("/dev/teeX") in user space.
469
+ * A returned context must be released with tee_client_close_context().
470
+ *
471
+ * Returns a TEE context of the first TEE device matched by the match()
472
+ * callback or an ERR_PTR.
473
+ */
474
+struct tee_context *
475
+tee_client_open_context(struct tee_context *start,
476
+ int (*match)(struct tee_ioctl_version_data *,
477
+ const void *),
478
+ const void *data, struct tee_ioctl_version_data *vers);
479
+
480
+/**
481
+ * tee_client_close_context() - Close a TEE context
482
+ * @ctx: TEE context to close
483
+ *
484
+ * Note that all sessions previously opened with this context will be
485
+ * closed when this function is called.
486
+ */
487
+void tee_client_close_context(struct tee_context *ctx);
488
+
489
+/**
490
+ * tee_client_get_version() - Query version of TEE
491
+ * @ctx: TEE context to TEE to query
492
+ * @vers: Pointer to version data
493
+ */
494
+void tee_client_get_version(struct tee_context *ctx,
495
+ struct tee_ioctl_version_data *vers);
496
+
497
+/**
498
+ * tee_client_open_session() - Open a session to a Trusted Application
499
+ * @ctx: TEE context
500
+ * @arg: Open session arguments, see description of
501
+ * struct tee_ioctl_open_session_arg
502
+ * @param: Parameters passed to the Trusted Application
503
+ *
504
+ * Returns < 0 on error else see @arg->ret for result. If @arg->ret
505
+ * is TEEC_SUCCESS the session identifier is available in @arg->session.
506
+ */
507
+int tee_client_open_session(struct tee_context *ctx,
508
+ struct tee_ioctl_open_session_arg *arg,
509
+ struct tee_param *param);
510
+
511
+/**
512
+ * tee_client_close_session() - Close a session to a Trusted Application
513
+ * @ctx: TEE Context
514
+ * @session: Session id
515
+ *
516
+ * Return < 0 on error else 0, regardless the session will not be
517
+ * valid after this function has returned.
518
+ */
519
+int tee_client_close_session(struct tee_context *ctx, u32 session);
520
+
521
+/**
522
+ * tee_client_invoke_func() - Invoke a function in a Trusted Application
523
+ * @ctx: TEE Context
524
+ * @arg: Invoke arguments, see description of
525
+ * struct tee_ioctl_invoke_arg
526
+ * @param: Parameters passed to the Trusted Application
527
+ *
528
+ * Returns < 0 on error else see @arg->ret for result.
529
+ */
530
+int tee_client_invoke_func(struct tee_context *ctx,
531
+ struct tee_ioctl_invoke_arg *arg,
532
+ struct tee_param *param);
533
+
534
+/**
535
+ * tee_client_cancel_req() - Request cancellation of the previous open-session
536
+ * or invoke-command operations in a Trusted Application
537
+ * @ctx: TEE Context
538
+ * @arg: Cancellation arguments, see description of
539
+ * struct tee_ioctl_cancel_arg
540
+ *
541
+ * Returns < 0 on error else 0 if the cancellation was successfully requested.
542
+ */
543
+int tee_client_cancel_req(struct tee_context *ctx,
544
+ struct tee_ioctl_cancel_arg *arg);
545
+
456546 static inline bool tee_param_is_memref(struct tee_param *param)
457547 {
458548 switch (param->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
....@@ -465,4 +555,45 @@
465555 }
466556 }
467557
558
+extern struct bus_type tee_bus_type;
559
+
560
+/**
561
+ * struct tee_client_device - tee based device
562
+ * @id: device identifier
563
+ * @dev: device structure
564
+ */
565
+struct tee_client_device {
566
+ struct tee_client_device_id id;
567
+ struct device dev;
568
+};
569
+
570
+#define to_tee_client_device(d) container_of(d, struct tee_client_device, dev)
571
+
572
+/**
573
+ * struct tee_client_driver - tee client driver
574
+ * @id_table: device id table supported by this driver
575
+ * @driver: driver structure
576
+ */
577
+struct tee_client_driver {
578
+ const struct tee_client_device_id *id_table;
579
+ struct device_driver driver;
580
+};
581
+
582
+#define to_tee_client_driver(d) \
583
+ container_of(d, struct tee_client_driver, driver)
584
+
585
+/**
586
+ * teedev_open() - Open a struct tee_device
587
+ * @teedev: Device to open
588
+ *
589
+ * @return a pointer to struct tee_context on success or an ERR_PTR on failure.
590
+ */
591
+struct tee_context *teedev_open(struct tee_device *teedev);
592
+
593
+/**
594
+ * teedev_close_context() - closes a struct tee_context
595
+ * @ctx: The struct tee_context to close
596
+ */
597
+void teedev_close_context(struct tee_context *ctx);
598
+
468599 #endif /*__TEE_DRV_H*/