diff --git a/drivers/aml_tee/optee/log.c b/drivers/aml_tee/optee/log.c index 30c3e92c3..3a6b12129 100644 --- a/drivers/aml_tee/optee/log.c +++ b/drivers/aml_tee/optee/log.c @@ -45,6 +45,7 @@ struct loopbuffer_ctl_s { static void *log_buf_va; static u8 line_buff[OPTEE_LOG_LINE_MAX]; +static bool logger_initialized; struct delayed_work log_work; static struct workqueue_struct *log_workqueue; @@ -147,6 +148,9 @@ int optee_log_init(void) struct arm_smccc_res smccc = { 0 }; struct loopbuffer_ctl_s *log_ctl = NULL; + if (logger_initialized) + return 0; + arm_smccc_smc(OPTEE_SMC_GET_LOGGER_CONFIG, 0, 0, 0, 0, 0, 0, 0, &smccc); if (smccc.a0 == TEEC_SUCCESS) { /* v3, get log buffer config from BL32 */ @@ -202,6 +206,8 @@ int optee_log_init(void) goto err; } + logger_initialized = true; + return rc; err: @@ -214,10 +220,20 @@ void optee_log_uninit(void) { struct arm_smccc_res smccc; + if (!logger_initialized) + return; + if (log_workqueue) { cancel_delayed_work_sync(&log_work); destroy_workqueue(log_workqueue); } + if (log_buf_va) { + iounmap(log_buf_va); + log_buf_va = NULL; + } + arm_smccc_smc(OPTEE_SMC_ENABLE_LOGGER, 0, 0, 0, 0, 0, 0, 0, &smccc); + + logger_initialized = false; } diff --git a/drivers/aml_tee/optee/smc_abi.c b/drivers/aml_tee/optee/smc_abi.c index 6fe9c4fca..8134d953f 100644 --- a/drivers/aml_tee/optee/smc_abi.c +++ b/drivers/aml_tee/optee/smc_abi.c @@ -1600,6 +1600,25 @@ err_free_pool: return rc; } +#ifdef CONFIG_PM +static int optee_restore(struct device *dev) +{ + optee_log_init(); + return 0; +} + +static int optee_freeze(struct device *dev) +{ + optee_log_uninit(); + return 0; +} + +static const struct dev_pm_ops optee_pm_ops = { + .freeze = optee_freeze, + .restore = optee_restore, +}; +#endif + static const struct of_device_id optee_dt_match[] = { { .compatible = "linaro,optee-tz" }, {}, @@ -1613,6 +1632,9 @@ static struct platform_driver optee_driver = { .driver = { .name = "optee", .of_match_table = optee_dt_match, +#ifdef CONFIG_PM + .pm = &optee_pm_ops, +#endif }, };