From dc1e47c1bc28177d420bcf47a9274cd6760eca91 Mon Sep 17 00:00:00 2001 From: Preeti Nagar Date: Thu, 20 Aug 2020 16:47:14 +0530 Subject: [PATCH] qcom: scm: Milestone call to enable kernel memory protection Invoke milestone call to QHEE as soc specific early initcall to enable protection of kernel's memory regions in stage 2 memory mappings. Change-Id: I3298cfebc3a5e5e64bf6a696a0a259c4059197b3 Signed-off-by: Preeti Nagar --- drivers/firmware/qcom_scm-smc.c | 32 ++++++++++++++++++++++++++++++++ drivers/firmware/qcom_scm.c | 9 +++++++++ drivers/firmware/qcom_scm.h | 7 +++++++ 3 files changed, 48 insertions(+) diff --git a/drivers/firmware/qcom_scm-smc.c b/drivers/firmware/qcom_scm-smc.c index 70bd93e30991..3f8b1369fce7 100644 --- a/drivers/firmware/qcom_scm-smc.c +++ b/drivers/firmware/qcom_scm-smc.c @@ -2086,6 +2086,38 @@ int __qcom_scm_qseecom_do(struct device *dev, u32 cmd_id, struct scm_desc *desc, return _ret; } +#ifdef CONFIG_QCOM_RTIC + +#define TZ_RTIC_ENABLE_MEM_PROTECTION 0x4 +int __init scm_mem_protection_init_do(struct device *dev) +{ + int ret = 0, resp; + struct qcom_scm_desc desc = { + .svc = SCM_SVC_RTIC, + .cmd = TZ_RTIC_ENABLE_MEM_PROTECTION, + .owner = ARM_SMCCC_OWNER_SIP, + }; + + desc.args[0] = 0; + desc.arginfo = 0; + + ret = qcom_scm_call(dev, &desc); + resp = desc.res[0]; + + if (ret == -1) { + pr_err("%s: SCM call not supported\n", __func__); + return ret; + } else if (ret || resp) { + pr_err("%s: SCM call failed\n", __func__); + if (ret) + return ret; + else + return resp; + } + return resp; +} +#endif + void __qcom_scm_init(void) { __query_convention(); diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index 780fa1ed6e6a..349fb56dea2c 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -1165,6 +1165,15 @@ static int __init qcom_scm_init(void) } subsys_initcall(qcom_scm_init); +#ifdef CONFIG_QCOM_RTIC +static int __init scm_mem_protection_init(void) +{ + return scm_mem_protection_init_do(__scm ? __scm->dev : NULL); +} + +early_initcall(scm_mem_protection_init); +#endif + #if IS_MODULE(CONFIG_QCOM_SCM) static void __exit qcom_scm_exit(void) { diff --git a/drivers/firmware/qcom_scm.h b/drivers/firmware/qcom_scm.h index 9a3ab3945dce..5f38a4f99661 100644 --- a/drivers/firmware/qcom_scm.h +++ b/drivers/firmware/qcom_scm.h @@ -269,6 +269,13 @@ extern int __qcom_scm_invoke_callback_response(struct device *dev, extern void __qcom_scm_init(void); +#ifdef CONFIG_QCOM_RTIC + +#define SCM_SVC_RTIC 0x19 +extern int __init scm_mem_protection_init_do(struct device *dev); + +#endif + /* common error codes */ #define QCOM_SCM_V2_EBUSY -12 #define QCOM_SCM_ENOMEM -5