Linux_SDK_V1.4.2

Signed-off-by: thead_admin <occ_thead@service.alibaba.com>
This commit is contained in:
thead_admin
2023-12-24 02:32:32 +00:00
committed by Han Gao/Revy/Rabenda
parent e17ac7bab2
commit d4c68ef2c1
164 changed files with 1943 additions and 24540 deletions

View File

@@ -6,6 +6,7 @@
#include <linux/device.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/freezer.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
@@ -23,6 +24,8 @@ struct optee_call_waiter {
struct completion c;
};
struct kref sess_refcount = KREF_INIT(1);
static void optee_cq_wait_init(struct optee_call_queue *cq,
struct optee_call_waiter *w)
{
@@ -51,7 +54,12 @@ static void optee_cq_wait_init(struct optee_call_queue *cq,
static void optee_cq_wait_for_completion(struct optee_call_queue *cq,
struct optee_call_waiter *w)
{
wait_for_completion(&w->c);
/*
* wait_for_completion but allow hibernation/suspend
* to freeze the waiting task
*/
while (wait_for_completion_interruptible(&w->c))
try_to_freeze();
mutex_lock(&cq->mutex);
@@ -273,6 +281,7 @@ int optee_open_session(struct tee_context *ctx,
mutex_lock(&ctxdata->mutex);
list_add(&sess->list_node, &ctxdata->sess_list);
mutex_unlock(&ctxdata->mutex);
kref_get(&sess_refcount);
} else {
kfree(sess);
}
@@ -293,6 +302,15 @@ out:
return rc;
}
static void session_release(struct kref *ref)
{
}
void session_put(void)
{
kref_put(&sess_refcount, session_release);
}
int optee_close_session(struct tee_context *ctx, u32 session)
{
struct optee_context_data *ctxdata = ctx->data;
@@ -320,6 +338,9 @@ int optee_close_session(struct tee_context *ctx, u32 session)
optee_do_call_with_arg(ctx, msg_parg);
tee_shm_free(shm);
session_put();
return 0;
}

View File

@@ -15,6 +15,7 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/suspend.h>
#include <linux/tee_drv.h>
#include <linux/types.h>
#include <linux/uaccess.h>
@@ -265,6 +266,8 @@ static int optee_open(struct tee_context *ctx)
return 0;
}
extern void session_put(void);
static void optee_release(struct tee_context *ctx)
{
struct optee_context_data *ctxdata = ctx->data;
@@ -301,6 +304,7 @@ static void optee_release(struct tee_context *ctx)
arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION;
arg->session = sess->session_id;
optee_do_call_with_arg(ctx, parg);
session_put();
}
kfree(sess);
}
@@ -606,6 +610,8 @@ static optee_invoke_fn *get_invoke_func(struct device *dev)
return ERR_PTR(-EINVAL);
}
extern struct kref sess_refcount;
static int optee_remove(struct platform_device *pdev)
{
struct optee *optee = platform_get_drvdata(pdev);
@@ -763,6 +769,47 @@ err:
return rc;
}
#ifdef CONFIG_PM
#ifdef CONFIG_SUSPEND
static int __maybe_unused tee_driver_suspend(struct device *dev)
{
int ret = 0;
unsigned int ref_count;
if (pm_suspend_target_state == PM_SUSPEND_MEM) {
pr_info("STR mode suspend in\r\n");
return 0;
} else {
ref_count = kref_read(&sess_refcount);
if (ref_count > 1) {
pr_info("tee_driver_suspend failed[%d] \r\n", ref_count);
ret = -1;
} else {
pr_info("tee_driver_suspend success[%d] \r\n", ref_count);
ret = 0;
}
}
return ret;
}
static int __maybe_unused tee_driver_resume(struct device *dev)
{
int ret = 0;
return ret;
}
#else
#define tee_driver_suspend NULL
#define tee_driver_resume NULL
#endif
static const struct dev_pm_ops tee_driver_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(tee_driver_suspend, tee_driver_resume)
};
#endif
static const struct of_device_id optee_dt_match[] = {
{ .compatible = "linaro,optee-tz" },
{},
@@ -775,10 +822,15 @@ static struct platform_driver optee_driver = {
.driver = {
.name = "optee",
.of_match_table = optee_dt_match,
#ifdef CONFIG_PM
.pm = &tee_driver_pm_ops,
#endif
},
};
module_platform_driver(optee_driver);
MODULE_AUTHOR("Linaro");
MODULE_DESCRIPTION("OP-TEE driver");
MODULE_VERSION("1.0");

View File

@@ -7,6 +7,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/freezer.h>
#include <linux/i2c.h>
#include <linux/io.h>
#include <linux/slab.h>
@@ -46,7 +47,6 @@ static void handle_rpc_func_cmd_get_time(struct optee_msg_arg *arg)
ktime_get_real_ts64(&ts);
arg->params[0].u.value.a = ts.tv_sec;
arg->params[0].u.value.b = ts.tv_nsec;
arg->ret = TEEC_SUCCESS;
return;
bad:
@@ -171,7 +171,12 @@ static void wq_sleep(struct optee_wait_queue *wq, u32 key)
struct wq_entry *w = wq_entry_get(wq, key);
if (w) {
wait_for_completion(&w->c);
/*
* wait_for_completion but allow hibernation/suspend
* to freeze the waiting task
*/
while (wait_for_completion_interruptible(&w->c))
try_to_freeze();
mutex_lock(&wq->mu);
list_del(&w->link);
mutex_unlock(&wq->mu);

View File

@@ -3,6 +3,7 @@
* Copyright (c) 2015, Linaro Limited
*/
#include <linux/device.h>
#include <linux/freezer.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include "optee_private.h"
@@ -141,6 +142,7 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
req->ret = TEEC_ERROR_COMMUNICATION;
break;
}
try_to_freeze();
}
ret = req->ret;