mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
tee: add close_context to TEE driver operation
The tee_context can be used to manage TEE user resources, including those allocated by the driver for the TEE on behalf of the user. The release() callback is invoked only when all resources, such as tee_shm, are released and there are no references to the tee_context. When a user closes the device file, the driver should notify the TEE to release any resources it may hold and drop the context references. To achieve this, a close_context() callback is introduced to initiate resource release in the TEE driver when the device file is closed. Relocate teedev_ctx_get, teedev_ctx_put, tee_device_get, and tee_device_get functions to tee_core.h to make them accessible outside the TEE subsystem. Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com> Tested-by: Neil Armstrong <neil.armstrong@linaro.org> Tested-by: Harshal Dev <quic_hdev@quicinc.com> Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
This commit is contained in:
committed by
Jens Wiklander
parent
6dbcd5a9ab
commit
0cbaf65c91
@@ -80,6 +80,7 @@ void teedev_ctx_get(struct tee_context *ctx)
|
||||
|
||||
kref_get(&ctx->refcount);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(teedev_ctx_get);
|
||||
|
||||
static void teedev_ctx_release(struct kref *ref)
|
||||
{
|
||||
@@ -97,11 +98,15 @@ void teedev_ctx_put(struct tee_context *ctx)
|
||||
|
||||
kref_put(&ctx->refcount, teedev_ctx_release);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(teedev_ctx_put);
|
||||
|
||||
void teedev_close_context(struct tee_context *ctx)
|
||||
{
|
||||
struct tee_device *teedev = ctx->teedev;
|
||||
|
||||
if (teedev->desc->ops->close_context)
|
||||
teedev->desc->ops->close_context(ctx);
|
||||
|
||||
teedev_ctx_put(ctx);
|
||||
tee_device_put(teedev);
|
||||
}
|
||||
@@ -1112,6 +1117,7 @@ void tee_device_put(struct tee_device *teedev)
|
||||
}
|
||||
mutex_unlock(&teedev->mutex);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tee_device_put);
|
||||
|
||||
bool tee_device_get(struct tee_device *teedev)
|
||||
{
|
||||
@@ -1124,6 +1130,7 @@ bool tee_device_get(struct tee_device *teedev)
|
||||
mutex_unlock(&teedev->mutex);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(tee_device_get);
|
||||
|
||||
/**
|
||||
* tee_device_unregister() - Removes a TEE device
|
||||
|
||||
@@ -23,12 +23,6 @@ struct tee_shm_dmabuf_ref {
|
||||
|
||||
int tee_shm_get_fd(struct tee_shm *shm);
|
||||
|
||||
bool tee_device_get(struct tee_device *teedev);
|
||||
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);
|
||||
struct tee_shm *tee_shm_register_user_buf(struct tee_context *ctx,
|
||||
unsigned long addr, size_t length);
|
||||
|
||||
Reference in New Issue
Block a user