OSDN Git Service

tee: add tee_shm_alloc_user_buf()
authorJens Wiklander <jens.wiklander@linaro.org>
Fri, 4 Feb 2022 09:33:52 +0000 (10:33 +0100)
committerJens Wiklander <jens.wiklander@linaro.org>
Wed, 16 Feb 2022 06:49:41 +0000 (07:49 +0100)
Adds a new function tee_shm_alloc_user_buf() for user mode allocations,
replacing passing the flags TEE_SHM_MAPPED | TEE_SHM_DMA_BUF to
tee_shm_alloc().

Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
drivers/tee/tee_core.c
drivers/tee/tee_private.h
drivers/tee/tee_shm.c
drivers/tee/tee_shm_pool.c
include/linux/tee_drv.h

index 3fc426d..a15812b 100644 (file)
@@ -297,7 +297,7 @@ static int tee_ioctl_shm_alloc(struct tee_context *ctx,
        if (data.flags)
                return -EINVAL;
 
-       shm = tee_shm_alloc(ctx, data.size, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF);
+       shm = tee_shm_alloc_user_buf(ctx, data.size);
        if (IS_ERR(shm))
                return PTR_ERR(shm);
 
index e55204d..e09c8aa 100644 (file)
@@ -68,4 +68,6 @@ void tee_device_put(struct tee_device *teedev);
 void teedev_ctx_get(struct tee_context *ctx);
 void teedev_ctx_put(struct tee_context *ctx);
 
+struct tee_shm *tee_shm_alloc_user_buf(struct tee_context *ctx, size_t size);
+
 #endif /*TEE_PRIVATE_H*/
index 499fccb..7e7e762 100644 (file)
@@ -128,6 +128,23 @@ err_dev_put:
 EXPORT_SYMBOL_GPL(tee_shm_alloc);
 
 /**
+ * tee_shm_alloc_user_buf() - Allocate shared memory for user space
+ * @ctx:       Context that allocates the shared memory
+ * @size:      Requested size of shared memory
+ *
+ * Memory allocated as user space shared memory is automatically freed when
+ * the TEE file pointer is closed. The primary usage of this function is
+ * when the TEE driver doesn't support registering ordinary user space
+ * memory.
+ *
+ * @returns a pointer to 'struct tee_shm'
+ */
+struct tee_shm *tee_shm_alloc_user_buf(struct tee_context *ctx, size_t size)
+{
+       return tee_shm_alloc(ctx, size, TEE_SHM_MAPPED | TEE_SHM_DMA_BUF);
+}
+
+/**
  * tee_shm_alloc_kernel_buf() - Allocate shared memory for kernel buffer
  * @ctx:       Context that allocates the shared memory
  * @size:      Requested size of shared memory
index a9f9d50..54c11aa 100644 (file)
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2015, Linaro Limited
+ * Copyright (c) 2015 Linaro Limited
  */
 #include <linux/device.h>
 #include <linux/dma-buf.h>
index 6b0f0d0..a4393c8 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (c) 2015-2016, Linaro Limited
+ * Copyright (c) 2015-2016 Linaro Limited
  */
 
 #ifndef __TEE_DRV_H