From bea316fb9c6650da97c8469aa492459ad444ed6a Mon Sep 17 00:00:00 2001 From: Siddharth Gupta Date: Thu, 26 Sep 2019 13:50:16 -0700 Subject: [PATCH] platform: msm: Migrate SCM calls in IPAv3 Adding API to upstream driver to get secure dump state and protect memory regions. Migrating SCM calls used in the IPA driver. Change-Id: Ia61436d8c18ddda49c411e06f147cdae345a23af Signed-off-by: Siddharth Gupta Signed-off-by: Elliot Berman --- drivers/firmware/qcom_scm-smc.c | 36 +++++++++++++++++++++++ drivers/firmware/qcom_scm.c | 13 +++++++++ drivers/firmware/qcom_scm.h | 7 +++++ drivers/platform/msm/ipa/ipa_v3/ipa.c | 38 ++++++++++--------------- drivers/platform/msm/ipa/ipa_v3/ipa_i.h | 1 - include/linux/qcom_scm.h | 6 ++++ 6 files changed, 77 insertions(+), 24 deletions(-) diff --git a/drivers/firmware/qcom_scm-smc.c b/drivers/firmware/qcom_scm-smc.c index c2e92b68b7c5..b4b64b925409 100644 --- a/drivers/firmware/qcom_scm-smc.c +++ b/drivers/firmware/qcom_scm-smc.c @@ -806,6 +806,23 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) return ret ? : desc.res[0]; } +int __qcom_scm_get_sec_dump_state(struct device *dev, u32 *dump_state) +{ + int ret; + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_UTIL, + .cmd = QCOM_SCM_UTIL_GET_SEC_DUMP_STATE, + .owner = ARM_SMCCC_OWNER_SIP + }; + + ret = qcom_scm_call(dev, &desc); + + if (dump_state) + *dump_state = desc.res[0]; + + return ret; +} + int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, unsigned int *val) { @@ -972,6 +989,25 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, return ret; } +int __qcom_scm_mem_protect_region_id(struct device *dev, phys_addr_t paddr, + size_t size) +{ + int ret; + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_MEM_PROTECT_REGION_ID, + .owner = ARM_SMCCC_OWNER_SIP + }; + + desc.args[0] = paddr; + desc.args[1] = size; + desc.arginfo = QCOM_SCM_ARGS(2); + + ret = qcom_scm_call(dev, &desc); + + return ret; +} + int __qcom_scm_iommu_secure_map(struct device *dev, phys_addr_t sg_list_addr, size_t num_sg, size_t sg_block_size, u64 sec_id, int cbndx, unsigned long iova, size_t total_len) diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index 0f23479e107d..1eab6f19fc6d 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -322,6 +322,13 @@ static const struct reset_control_ops qcom_scm_pas_reset_ops = { .deassert = qcom_scm_pas_reset_deassert, }; +int qcom_scm_get_sec_dump_state(u32 *dump_state) +{ + return __qcom_scm_get_sec_dump_state(__scm->dev, + dump_state); +} +EXPORT_SYMBOL(qcom_scm_get_sec_dump_state); + int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val) { return __qcom_scm_io_readl(__scm->dev, addr, val); @@ -365,6 +372,12 @@ int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) } EXPORT_SYMBOL(qcom_scm_iommu_secure_ptbl_init); +int qcom_scm_mem_protect_region_id(phys_addr_t paddr, size_t size) +{ + return __qcom_scm_mem_protect_region_id(__scm->dev, paddr, size); +} +EXPORT_SYMBOL(qcom_scm_mem_protect_region_id); + int qcom_scm_iommu_secure_map(phys_addr_t sg_list_addr, size_t num_sg, size_t sg_block_size, u64 sec_id, int cbndx, unsigned long iova, size_t total_len) diff --git a/drivers/firmware/qcom_scm.h b/drivers/firmware/qcom_scm.h index b2c897b8933c..47c8b8f8174b 100644 --- a/drivers/firmware/qcom_scm.h +++ b/drivers/firmware/qcom_scm.h @@ -37,6 +37,10 @@ extern int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 peripheral); extern int __qcom_scm_pas_shutdown(struct device *dev, u32 peripheral); extern int __qcom_scm_pas_mss_reset(struct device *dev, bool reset); +#define QCOM_SCM_SVC_UTIL 0x03 +#define QCOM_SCM_UTIL_GET_SEC_DUMP_STATE 0x10 +extern int __qcom_scm_get_sec_dump_state(struct device *dev, u32 *dump_state); + #define QCOM_SCM_SVC_IO 0x05 #define QCOM_SCM_IO_READ 0x01 #define QCOM_SCM_IO_WRITE 0x02 @@ -60,6 +64,7 @@ extern void __qcom_scm_mmu_sync(struct device *dev, bool sync); #define QCOM_SCM_MP_RESTORE_SEC_CFG 0x02 #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE 0x03 #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT 0x04 +#define QCOM_SCM_MP_MEM_PROTECT_REGION_ID 0x10 #define QCOM_SCM_MP_IOMMU_SECURE_MAP2_FLAT 0x12 #define QCOM_SCM_MP_IOMMU_SECURE_UNMAP2_FLAT 0x13 #define QCOM_SCM_MP_ASSIGN 0x16 @@ -69,6 +74,8 @@ extern int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare, size_t *size); extern int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, u32 spare); +extern int __qcom_scm_mem_protect_region_id(struct device *dev, + phys_addr_t paddr, size_t size); extern int __qcom_scm_iommu_secure_map(struct device *dev, phys_addr_t sg_list_addr, size_t num_sg, size_t sg_block_size, u64 sec_id, int cbndx, diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa.c b/drivers/platform/msm/ipa/ipa_v3/ipa.c index 575b537251c0..2880bfa1f2ff 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa.c +++ b/drivers/platform/msm/ipa/ipa_v3/ipa.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -91,7 +91,6 @@ struct ipa_ioc_nat_ipv6ct_table_alloc32 { #endif /* #ifdef CONFIG_COMPAT */ #define IPA_TZ_UNLOCK_ATTRIBUTE 0x0C0311 -#define TZ_MEM_PROTECT_REGION_ID 0x10 struct tz_smmu_ipa_protect_region_iovec_s { u64 input_addr; @@ -6241,10 +6240,10 @@ static ssize_t ipa3_write(struct file *file, const char __user *buf, */ int ipa3_tz_unlock_reg(struct ipa_tz_unlock_reg_info *reg_info, u16 num_regs) { - int i, size, ret; + int i, ret; + compat_size_t size; struct tz_smmu_ipa_protect_region_iovec_s *ipa_tz_unlock_vec; struct tz_smmu_ipa_protect_region_s cmd_buf; - struct scm_desc desc = {0}; if (reg_info == NULL || num_regs == 0) { IPAERR("Bad parameters\n"); @@ -6269,17 +6268,15 @@ int ipa3_tz_unlock_reg(struct ipa_tz_unlock_reg_info *reg_info, u16 num_regs) cmd_buf.iovec_buf = virt_to_phys((void *)ipa_tz_unlock_vec); cmd_buf.size_bytes = size; - desc.args[0] = virt_to_phys((void *)ipa_tz_unlock_vec); - desc.args[1] = size; - desc.arginfo = SCM_ARGS(2); - ret = scm_call2(SCM_SIP_FNID(SCM_SVC_MP, - TZ_MEM_PROTECT_REGION_ID), &desc); + ret = qcom_scm_mem_protect_region_id( + virt_to_phys((void *)ipa_tz_unlock_vec), + size); - if (ret) { - IPAERR("scm call SCM_SVC_MP failed: %d\n", ret); - kfree(ipa_tz_unlock_vec); - return -EFAULT; - } + if (ret) { + IPAERR("scm call SCM_SVC_MP failed: %d\n", ret); + kfree(ipa_tz_unlock_vec); + return -EFAULT; + } kfree(ipa_tz_unlock_vec); return 0; } @@ -6337,24 +6334,19 @@ static int ipa3_alloc_pkt_init(void) * Returns true in secure dump allowed. * Return false when secure dump not allowed. */ -#define TZ_UTIL_GET_SEC_DUMP_STATE 0x10 static bool ipa_is_mem_dump_allowed(void) { - struct scm_desc desc = {0}; - int ret = 0; + int ret; + u32 dump_state; - desc.args[0] = 0; - desc.arginfo = 0; + ret = qcom_scm_get_sec_dump_state(&dump_state); - ret = scm_call2( - SCM_SIP_FNID(SCM_SVC_UTIL, TZ_UTIL_GET_SEC_DUMP_STATE), - &desc); if (ret) { IPAERR("SCM DUMP_STATE call failed\n"); return false; } - return (desc.ret[0] == 1); + return (dump_state == 1); } static int ipa3_lan_poll(struct napi_struct *napi, int budget) diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa_i.h b/drivers/platform/msm/ipa/ipa_v3/ipa_i.h index 83456f22e1b8..97c80c8feff0 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa_i.h +++ b/drivers/platform/msm/ipa/ipa_v3/ipa_i.h @@ -426,7 +426,6 @@ enum { #endif /* #ifdef CONFIG_COMPAT */ #define IPA_TZ_UNLOCK_ATTRIBUTE 0x0C0311 -#define TZ_MEM_PROTECT_REGION_ID 0x10 #define MBOX_TOUT_MS 100 diff --git a/include/linux/qcom_scm.h b/include/linux/qcom_scm.h index 9a38f9ce12b0..ea3ca01baad6 100644 --- a/include/linux/qcom_scm.h +++ b/include/linux/qcom_scm.h @@ -47,6 +47,7 @@ extern int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr, phys_addr_t size); extern int qcom_scm_pas_auth_and_reset(u32 peripheral); extern int qcom_scm_pas_shutdown(u32 peripheral); +extern int qcom_scm_get_sec_dump_state(u32 *dump_state); extern int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val); extern int qcom_scm_io_writel(phys_addr_t addr, unsigned int val); extern int qcom_scm_get_jtag_etm_feat_id(u64 *version); @@ -54,6 +55,7 @@ extern void qcom_scm_mmu_sync(bool sync); extern int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare); extern int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size); extern int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare); +extern int qcom_scm_mem_protect_region_id(phys_addr_t paddr, size_t size); extern int qcom_scm_iommu_secure_map(phys_addr_t sg_list_addr, size_t num_sg, size_t sg_block_size, u64 sec_id, int cbndx, unsigned long iova, size_t total_len); @@ -91,6 +93,8 @@ static inline int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr, static inline int qcom_scm_pas_auth_and_reset(u32 peripheral) { return -ENODEV; } static inline int qcom_scm_pas_shutdown(u32 peripheral) { return -ENODEV; } +static inline int qcom_scm_get_sec_dump_state(u32 *dump_state) + {return -ENODEV; } static inline int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val) { return -ENODEV; } static inline int qcom_scm_io_writel(phys_addr_t addr, unsigned int val) @@ -104,6 +108,8 @@ static inline int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size) { return -ENODEV; } static inline int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) { return -ENODEV; } +static inline int qcom_scm_mem_protect_region_id(phys_addr_t paddr, size_t size) + { return -ENODEV; } static inline int qcom_scm_iommu_secure_map(phys_addr_t sg_list_addr, size_t num_sg, size_t sg_block_size, u64 sec_id, int cbndx, unsigned long iova, size_t total_len) { return -ENODEV; }