Restructure, improve target support for qcom_scm driver
cover Restructure, improve target support for qcom_scm driver
This series improves support for 32-bit Qualcomm targets on qcom_scm driver.
Currently, the qcom_scm driver supports only 64-bit Qualcomm targets and very old 32-bit Qualcomm targets. Newer 32-bit targets use ARM's SMC Calling Convention to communicate with secure world. Older 32-bit targets use a "buffer-based" legacy approach for communicating with secure world (as implemented in qcom_scm-32.c). All arm64 Qualcomm targets use ARM SMCCC. Currently, SMCCC-based communication is enabled only on ARM64 config and buffer-based communication only on ARM config. This patch-series combines SMCCC and legacy conventions and selects the correct convention by querying the secure world [1].
We decided to take the opportunity as well to clean up the driver rather than try to patch together qcom_scm-32 and qcom_scm-64.
Patches 1-4 improve macro names, reorder macros/functions, and prune unused
macros/functions. No functional changes were introduced.
Patches 5-9 clears up the SCM abstraction in qcom_scm-64.
Patches 10-14 clears up the SCM abstraction in qcom_scm-32. Patches 9 and 15-16 enable dynamically using the different calling conventions.
This series is based on https://lore.kernel.org/patchwork/cover/1129991/
Elliot Berman (17):
firmware: qcom_scm: Rename macros and structures
firmware: qcom_scm: Apply consistent naming scheme to command IDs
firmware: qcom_scm: Order functions, definitions by service/command
firmware: qcom_scm: Remove unused qcom_scm_get_version
firmware: qcom_scm-64: Move svc/cmd/owner into qcom_scm_desc
firmware: qcom_scm-64: Add SCM results to descriptor
firmware: qcom_scm-64: Remove qcom_scm_call_do_smccc
firmware: qcom_scm-64: Move SMC register filling to
qcom_scm_call_smccc
firmware: qcom_scm-64: Improve SMC convention detection
firmware: qcom_scm-32: Use SMC arch wrappers
firmware: qcom_scm-32: Use qcom_scm_desc in non-atomic calls
firmware: qcom_scm-32: Move SMCCC register filling to qcom_scm_call
firmware: qcom_scm-32: Create common legacy atomic call
firmware: qcom_scm-32: Add device argument to atomic calls
firmware: qcom_scm: Merge legacy and SMCCC conventions
firmware: qcom_scm: Enable legacy calling convention in qcom_scm-64.c
firmware: qcom_scm: Rename -64 -> -smc, remove -32
drivers/firmware/Kconfig | 18 +- drivers/firmware/Makefile | 4 +- drivers/firmware/qcom_scm-32.c | 621 -------------------------- drivers/firmware/qcom_scm-64.c | 567 ------------------------ drivers/firmware/qcom_scm-smc.c | 938 ++++++++++++++++++++++++++++++++++++++++ drivers/firmware/qcom_scm.c | 232 +++++----- drivers/firmware/qcom_scm.h | 117 +++-- include/linux/qcom_scm.h | 74 ++-- 8 files changed, 1159 insertions(+), 1412 deletions(-) delete mode 100644 drivers/firmware/qcom_scm-32.c delete mode 100644 drivers/firmware/qcom_scm-64.c create mode 100644 drivers/firmware/qcom_scm-smc.c
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 4/17 firmware: qcom_scm: Remove unused qcom_scm_get_version
Remove unused qcom_scm_get_version.
--- drivers/firmware/qcom_scm-32.c | 36 ------------------------------------ include/linux/qcom_scm.h | 2 -- 2 files changed, 38 deletions(-)
drivers/firmware/qcom_scm-32.c +0 -36
@@ -291,42 +291,6 @@ static s32 qcom_scm_call_atomic2(u32 svc, u32 cmd, u32 arg1, u32 arg2)return r0; } -u32 qcom_scm_get_version (void ) -{ -int context_id; -static u32 version =-1 ; - registeru32 r0 asm("r0" ); - registeru32 r1 asm("r1" ); - -if (version !=-1 ) -return version; - -mutex_lock (&qcom_scm_lock); - - r0 =0x1 <<8 ; - r1 = (u32)&context_id; -do { - asmvolatile ( - __asmeq("%0", "r0") - __asmeq("%1", "r1") - __asmeq("%2", "r0") - __asmeq("%3", "r1") -#ifdef REQUIRES_SEC - ".arch_extension sec\n" -#endif - "smc #0 @ switch to secure world\n" - : "=r" (r0), "=r" (r1) - : "r" (r0), "r" (r1) - : "r2", "r3", "r12"); - }while (r0 ==QCOM_SCM_INTERRUPTED ); - - version = r1; -mutex_unlock (&qcom_scm_lock); - -return version; -} -EXPORT_SYMBOL (qcom_scm_get_version); -/** * qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus * @entry: Entry point function for the cpus
include/linux/qcom_scm.h +0 -2
@@ -59,7 +59,6 @@ extern bool qcom_scm_hdcp_available(void);extern int qcom_scm_hdcp_req (struct qcom_scm_hdcp_req *req,u32 req_cnt,u32 *resp);extern int qcom_scm_qsmmu500_wait_safe_toggle (bool en); -extern u32 qcom_scm_get_version (void );extern bool qcom_scm_is_available (void );#else
@@ -101,7 +100,6 @@ static inline int qcom_scm_hdcp_req(struct qcom_scm_hdcp_req *req, u32 req_cnt, u32 *resp) { return -ENODEV; }static inline int qcom_scm_qsmmu500_wait_safe_toggle (bool en) {return -ENODEV ; } -static inline u32 qcom_scm_get_version (void ) {return 0 ; }static inline bool qcom_scm_is_available (void ) {return false; }#endif #endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 5/17 firmware: qcom_scm-64: Move svc/cmd/owner into qcom_scm_desc
In reply to Elliot BermanService, command, and owner IDs are all part of qcom_scm_desc struct and have no special reason to be a function argument (or hard-coded in the case of owner). Moving them to be part of qcom_scm_desc struct improves readability.
--- drivers/firmware/qcom_scm-64.c | 191 ++++++++++++++++++++++++++--------------- 1 file changed, 120 insertions(+), 71 deletions(-)
drivers/firmware/qcom_scm-64.c +120 -71
@@ -46,8 +46,11 @@ enum qcom_scm_arg_types {* @res: The values returned by the secure syscall */ struct qcom_scm_desc { +u32 svc; +u32 cmd;u32 arginfo;u64 args[MAX_QCOM_SCM_ARGS ]; +u32 owner; };static u64 qcom_smccc_convention =-1 ;
@@ -62,14 +65,16 @@ static DEFINE_MUTEX(qcom_scm_lock);#define SMCCC_N_EXT_ARGS (MAX_QCOM_SCM_ARGS - SMCCC_N_REG_ARGS + 1)static void __qcom_scm_call_do_quirk (const struct qcom_scm_desc *desc, -struct arm_smccc_res *res,u32 fn_id, -u64 x5,u32 type) +struct arm_smccc_res *res,u64 x5,u32 type) {u64 cmd;struct arm_smccc_quirk quirk = { .id =ARM_SMCCC_QUIRK_QCOM_A6 }; - cmd =ARM_SMCCC_CALL_VAL (type, qcom_smccc_convention, -ARM_SMCCC_OWNER_SIP , fn_id); + cmd =ARM_SMCCC_CALL_VAL ( + type, + qcom_smccc_convention, + desc->owner, +SMCCC_FUNCNUM (desc->svc, desc->cmd)); quirk.state.a6 =0 ;
@@ -85,22 +90,19 @@ static void __qcom_scm_call_do_quirk(const struct qcom_scm_desc *desc, }static void qcom_scm_call_do_smccc (const struct qcom_scm_desc *desc, -struct arm_smccc_res *res,u32 fn_id, -u64 x5,bool atomic) +struct arm_smccc_res *res,u64 x5,bool atomic) {int retry_count =0 ;if (atomic) { -__qcom_scm_call_do_quirk (desc, res, fn_id, x5, -ARM_SMCCC_FAST_CALL ); +__qcom_scm_call_do_quirk (desc, res, x5,ARM_SMCCC_FAST_CALL );return ; } do { mutex_lock(&qcom_scm_lock); - __qcom_scm_call_do_quirk(desc, res, fn_id, x5, - ARM_SMCCC_STD_CALL); + __qcom_scm_call_do_quirk(desc, res, x5, ARM_SMCCC_STD_CALL); mutex_unlock(&qcom_scm_lock);
@@ -112,7 +114,7 @@ static void qcom_scm_call_do_smccc(const struct qcom_scm_desc *desc, }while (res->a0 ==QCOM_SCM_V2_EBUSY ); } -static int ___qcom_scm_call_smccc (struct device *dev,u32 svc_id,u32 cmd_id, +static int ___qcom_scm_call_smccc (struct device *dev,const struct qcom_scm_desc *desc,struct arm_smccc_res *res,bool atomic) {
@@ -157,7 +159,7 @@ static int ___qcom_scm_call_smccc(struct device *dev, u32 svc_id, u32 cmd_id, x5 = args_phys; } -qcom_scm_call_do_smccc (desc, res, fn_id, x5, atomic); +qcom_scm_call_do_smccc (desc, res, x5, atomic);if (args_virt) {dma_unmap_single (dev, args_phys, alloc_len,DMA_TO_DEVICE );
@@ -180,12 +182,11 @@ static int ___qcom_scm_call_smccc(struct device *dev, u32 svc_id, u32 cmd_id,* Sends a command to the SCM and waits for the command to finish processing. * This should *only* be called in pre-emptible context. */ -static int qcom_scm_call (struct device *dev,u32 svc_id,u32 cmd_id, -const struct qcom_scm_desc *desc, +static int qcom_scm_call (struct device *dev,const struct qcom_scm_desc *desc,struct arm_smccc_res *res) {might_sleep (); -return ___qcom_scm_call_smccc (dev, svc_id, cmd_id, desc, res, false); +return ___qcom_scm_call_smccc (dev, desc, res, false); }/**
@@ -199,11 +200,11 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id,* Sends a command to the SCM and waits for the command to finish processing. * This can be called in atomic context. */ -static int qcom_scm_call_atomic (struct device *dev,u32 svc_id,u32 cmd_id, +static int qcom_scm_call_atomic (struct device *dev,const struct qcom_scm_desc *desc,struct arm_smccc_res *res) { -return ___qcom_scm_call_smccc (dev, svc_id, cmd_id, desc, res, true); +return ___qcom_scm_call_smccc (dev, desc, res, true); }/**
@@ -248,7 +249,11 @@ void __qcom_scm_cpu_power_down(u32 flags)int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_REMOTE_STATE , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res;int ret;
@@ -256,37 +261,41 @@ int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id) desc.args[1 ] = id; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_REMOTE_STATE , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }int __qcom_scm_set_dload_mode (struct device *dev,bool enable) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_DLOAD_MODE , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] =QCOM_SCM_BOOT_SET_DLOAD_MODE ; desc.args[1 ] = enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_DLOAD_MODE , - &desc, &res); +return qcom_scm_call (dev, &desc, &res); }bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral) {int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_IS_SUPPORTED , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_IS_SUPPORTED , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? false : !!res.a1; }
@@ -295,15 +304,18 @@ int __qcom_scm_pas_init_image(struct device *dev, u32 peripheral, dma_addr_t metadata_phys) {int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_INIT_IMAGE , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.args[1 ] = metadata_phys; desc.arginfo =QCOM_SCM_ARGS (2 ,QCOM_SCM_VAL ,QCOM_SCM_RW ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_INIT_IMAGE , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -312,7 +324,11 @@ int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral, phys_addr_t addr, phys_addr_t size) { int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_MEM_SETUP , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = peripheral;
@@ -320,8 +336,7 @@ int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral, desc.args[2 ] = size; desc.arginfo =QCOM_SCM_ARGS (3 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_MEM_SETUP , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -329,15 +344,17 @@ int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral,int __qcom_scm_pas_auth_and_reset (struct device *dev,u32 peripheral) {int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_AUTH_AND_RESET , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_AUTH_AND_RESET , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -345,21 +362,28 @@ int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 peripheral)int __qcom_scm_pas_shutdown (struct device *dev,u32 peripheral) {int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_SHUTDOWN , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_SHUTDOWN , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }int __qcom_scm_pas_mss_reset (struct device *dev,bool reset) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_MSS_RESET , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res;int ret;
@@ -367,8 +391,7 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) desc.args[1 ] =0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_MSS_RESET , &desc, - &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -376,15 +399,18 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)int __qcom_scm_io_readl (struct device *dev,phys_addr_t addr,unsigned int *val) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_IO , + .cmd =QCOM_SCM_IO_READ , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res;int ret; desc.args[0 ] = addr; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_IO ,QCOM_SCM_IO_READ , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);if (ret >=0 ) *val = res.a1;
@@ -393,36 +419,46 @@ int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,int __qcom_scm_io_writel (struct device *dev,phys_addr_t addr,unsigned int val) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_IO , + .cmd =QCOM_SCM_IO_WRITE , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = addr; desc.args[1 ] = val; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call (dev,QCOM_SCM_SVC_IO ,QCOM_SCM_IO_WRITE , - &desc, &res); +return qcom_scm_call (dev, &desc, &res); }int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) {int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_INFO , + .cmd =QCOM_INFO_IS_CALL_AVAIL , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.arginfo =QCOM_SCM_ARGS (1 ); desc.args[0 ] =SMCCC_FUNCNUM (svc_id, cmd_id) | (ARM_SMCCC_OWNER_SIP <<ARM_SMCCC_OWNER_SHIFT ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }int __qcom_scm_restore_sec_cfg (struct device *dev,u32 device_id,u32 spare) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_MP , + .cmd =QCOM_SCM_MP_RESTORE_SEC_CFG , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res;int ret;
@@ -430,8 +466,7 @@ int __qcom_scm_restore_sec_cfg(struct device *dev, u32 device_id, u32 spare) desc.args[1 ] = spare; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP ,QCOM_SCM_MP_RESTORE_SEC_CFG , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -439,15 +474,18 @@ int __qcom_scm_restore_sec_cfg(struct device *dev, u32 device_id, u32 spare)int __qcom_scm_iommu_secure_ptbl_size (struct device *dev,u32 spare,size_t *size) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_MP , + .cmd =QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res;int ret; desc.args[0 ] = spare; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP , -QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE , &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);if (size) *size = res.a1;
@@ -458,7 +496,11 @@ int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare,int __qcom_scm_iommu_secure_ptbl_init (struct device *dev,u64 addr,u32 size,u32 spare) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_MP , + .cmd =QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res;int ret;
@@ -468,8 +510,7 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, desc.arginfo =QCOM_SCM_ARGS (3 ,QCOM_SCM_RW ,QCOM_SCM_VAL ,QCOM_SCM_VAL ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP , -QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT , &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);/* the pg table has been initialized already, ignore the error */ if (ret == -EPERM )
@@ -483,7 +524,11 @@ int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region, phys_addr_t dest, size_t dest_sz) { int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_MP , + .cmd =QCOM_MP_ASSIGN , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = mem_region;
@@ -498,9 +543,7 @@ int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region,QCOM_SCM_RO ,QCOM_SCM_VAL ,QCOM_SCM_RO , QCOM_SCM_VAL, QCOM_SCM_VAL); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP , -QCOM_MP_ASSIGN , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -509,7 +552,11 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, u32 req_cnt, u32 *resp) { int ret; -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_HDCP , + .cmd =QCOM_SCM_HDCP_INVOKE , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res;if (req_cnt >QCOM_SCM_HDCP_MAX_REQ_CNT )
@@ -527,8 +574,7 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, desc.args[9 ] = req[4 ].val; desc.arginfo =QCOM_SCM_ARGS (10 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_HDCP_INVOKE , &desc, - &res); + ret =qcom_scm_call (dev, &desc, &res); *resp = res.a1;return ret;
@@ -536,15 +582,18 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req,int __qcom_scm_qsmmu500_wait_safe_toggle (struct device *dev,bool en) { -struct qcom_scm_desc desc = {0 }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_SMMU_PROGRAM , + .cmd =QCOM_SCM_SMMU_CONFIG_ERRATA1 , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] =QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL ; desc.args[1 ] = en; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call_atomic (dev,QCOM_SCM_SVC_SMMU_PROGRAM , -QCOM_SCM_SMMU_CONFIG_ERRATA1 , &desc, &res); +return qcom_scm_call_atomic (dev, &desc, &res); }void __qcom_scm_init (void )
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 6/17 firmware: qcom_scm-64: Add SCM results to descriptor
In reply to Elliot BermanRemove knowledge of arm_smccc_res struct from client wrappers so that client wrappers only work QCOM SCM data structures. SCM calls may have up to 3 arguments, so qcom_scm_call_smccc is responsible now for filling those 3 arguments accordingly.
--- drivers/firmware/qcom_scm-64.c | 101 +++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 60 deletions(-)
drivers/firmware/qcom_scm-64.c +41 -60
@@ -50,6 +50,7 @@ struct qcom_scm_desc {u32 cmd;u32 arginfo;u64 args[MAX_QCOM_SCM_ARGS ]; +u64 res[MAX_QCOM_SCM_RETS ];u32 owner; };
@@ -115,8 +116,7 @@ static void qcom_scm_call_do_smccc(const struct qcom_scm_desc *desc, }static int ___qcom_scm_call_smccc (struct device *dev, -const struct qcom_scm_desc *desc, -struct arm_smccc_res *res,bool atomic) +struct qcom_scm_desc *desc,bool atomic) {int arglen = desc->arginfo &0xf ;int i;
@@ -126,6 +126,7 @@ static int ___qcom_scm_call_smccc(struct device *dev,void *args_virt =NULL ;size_t alloc_len;gfp_t flag = atomic ?GFP_ATOMIC :GFP_KERNEL ; +struct arm_smccc_res res;if (unlikely (arglen >SMCCC_N_REG_ARGS )) { alloc_len =SMCCC_N_EXT_ARGS *sizeof (u64);
@@ -159,15 +160,15 @@ static int ___qcom_scm_call_smccc(struct device *dev, x5 = args_phys; } -qcom_scm_call_do_smccc (desc, res, x5, atomic); +qcom_scm_call_do_smccc (desc, &res, x5, atomic);if (args_virt) {dma_unmap_single (dev, args_phys, alloc_len,DMA_TO_DEVICE );kfree (args_virt); } -if (res->a0 <0 ) -return qcom_scm_remap_error (res->a0); +if (res.a0 <0 ) +return qcom_scm_remap_error (res.a0);return 0 ; }
@@ -182,11 +183,10 @@ static int ___qcom_scm_call_smccc(struct device *dev,* Sends a command to the SCM and waits for the command to finish processing. * This should *only* be called in pre-emptible context. */ -static int qcom_scm_call (struct device *dev,const struct qcom_scm_desc *desc, -struct arm_smccc_res *res) +static int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc) {might_sleep (); -return ___qcom_scm_call_smccc (dev, desc, res, false); +return ___qcom_scm_call_smccc (dev, desc, false); }/**
@@ -200,11 +200,9 @@ static int qcom_scm_call(struct device *dev, const struct qcom_scm_desc *desc,* Sends a command to the SCM and waits for the command to finish processing. * This can be called in atomic context. */ -static int qcom_scm_call_atomic (struct device *dev, -const struct qcom_scm_desc *desc, -struct arm_smccc_res *res) +static int qcom_scm_call_atomic (struct device *dev,struct qcom_scm_desc *desc) { -return ___qcom_scm_call_smccc (dev, desc, res, true); +return ___qcom_scm_call_smccc (dev, desc, true); }/**
@@ -254,16 +252,15 @@ int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id) .cmd = QCOM_SCM_BOOT_SET_REMOTE_STATE, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res;int ret; desc.args[0 ] = state; desc.args[1 ] = id; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; }int __qcom_scm_set_dload_mode (struct device *dev,bool enable)
@@ -273,13 +270,12 @@ int __qcom_scm_set_dload_mode(struct device *dev, bool enable) .cmd = QCOM_SCM_BOOT_SET_DLOAD_MODE, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] =QCOM_SCM_BOOT_SET_DLOAD_MODE ; desc.args[1 ] = enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call (dev, &desc, &res); +return qcom_scm_call (dev, &desc); }bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral)
@@ -290,14 +286,13 @@ bool __qcom_scm_pas_supported(struct device *dev, u32 peripheral) .cmd = QCOM_SCM_PIL_PAS_IS_SUPPORTED, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? false : !!res.a1; +return ret ? false : !!desc.res[0 ]; } int __qcom_scm_pas_init_image(struct device *dev, u32 peripheral,
@@ -309,15 +304,14 @@ int __qcom_scm_pas_init_image(struct device *dev, u32 peripheral, .cmd = QCOM_SCM_PIL_PAS_INIT_IMAGE, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.args[1 ] = metadata_phys; desc.arginfo =QCOM_SCM_ARGS (2 ,QCOM_SCM_VAL ,QCOM_SCM_RW ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; } int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral,
@@ -329,16 +323,15 @@ int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral, .cmd = QCOM_SCM_PIL_PAS_MEM_SETUP, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.args[1 ] = addr; desc.args[2 ] = size; desc.arginfo =QCOM_SCM_ARGS (3 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; }int __qcom_scm_pas_auth_and_reset (struct device *dev,u32 peripheral)
@@ -349,14 +342,13 @@ int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 peripheral) .cmd = QCOM_SCM_PIL_PAS_AUTH_AND_RESET, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; }int __qcom_scm_pas_shutdown (struct device *dev,u32 peripheral)
@@ -367,14 +359,13 @@ int __qcom_scm_pas_shutdown(struct device *dev, u32 peripheral) .cmd = QCOM_SCM_PIL_PAS_SHUTDOWN, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = peripheral; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; }int __qcom_scm_pas_mss_reset (struct device *dev,bool reset)
@@ -384,16 +375,15 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) .cmd = QCOM_SCM_PIL_PAS_MSS_RESET, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res;int ret; desc.args[0 ] = reset; desc.args[1 ] =0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; } int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
@@ -404,15 +394,14 @@ int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, .cmd = QCOM_SCM_IO_READ, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res;int ret; desc.args[0 ] = addr; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc);if (ret >=0 ) - *val = res.a1; + *val = desc.res[0 ];return ret <0 ? ret :0 ; }
@@ -424,13 +413,12 @@ int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val) .cmd = QCOM_SCM_IO_WRITE, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = addr; desc.args[1 ] = val; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call (dev, &desc, &res); +return qcom_scm_call (dev, &desc); }int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id)
@@ -441,15 +429,14 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id) .cmd = QCOM_INFO_IS_CALL_AVAIL, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.arginfo =QCOM_SCM_ARGS (1 ); desc.args[0 ] =SMCCC_FUNCNUM (svc_id, cmd_id) | (ARM_SMCCC_OWNER_SIP <<ARM_SMCCC_OWNER_SHIFT ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; }int __qcom_scm_restore_sec_cfg (struct device *dev,u32 device_id,u32 spare)
@@ -459,16 +446,15 @@ int __qcom_scm_restore_sec_cfg(struct device *dev, u32 device_id, u32 spare) .cmd = QCOM_SCM_MP_RESTORE_SEC_CFG, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res;int ret; desc.args[0 ] = device_id; desc.args[1 ] = spare; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; } int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare,
@@ -479,18 +465,17 @@ int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare, .cmd = QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res;int ret; desc.args[0 ] = spare; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc);if (size) - *size = res.a1; + *size = desc.res[0 ]; -return ret ? : res.a2; +return ret ? : desc.res[1 ]; } int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,
@@ -501,7 +486,6 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, .cmd = QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res;int ret; desc.args[0 ] = addr;
@@ -510,7 +494,7 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, desc.arginfo =QCOM_SCM_ARGS (3 ,QCOM_SCM_RW ,QCOM_SCM_VAL ,QCOM_SCM_VAL ); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc);/* the pg table has been initialized already, ignore the error */ if (ret == -EPERM )
@@ -529,7 +513,6 @@ int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region, .cmd = QCOM_MP_ASSIGN, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = mem_region; desc.args[1 ] = mem_sz;
@@ -543,9 +526,9 @@ int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region,QCOM_SCM_RO ,QCOM_SCM_VAL ,QCOM_SCM_RO , QCOM_SCM_VAL, QCOM_SCM_VAL); - ret =qcom_scm_call (dev, &desc, &res); + ret =qcom_scm_call (dev, &desc); -return ret ? : res.a1; +return ret ? : desc.res[0 ]; } int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req,
@@ -557,7 +540,6 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, .cmd = QCOM_SCM_HDCP_INVOKE, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res;if (req_cnt >QCOM_SCM_HDCP_MAX_REQ_CNT )return -ERANGE ;
@@ -574,8 +556,8 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, desc.args[9 ] = req[4 ].val; desc.arginfo =QCOM_SCM_ARGS (10 ); - ret =qcom_scm_call (dev, &desc, &res); - *resp = res.a1; + ret =qcom_scm_call (dev, &desc); + *resp = desc.res[0 ];return ret; }
@@ -587,13 +569,12 @@ int __qcom_scm_qsmmu500_wait_safe_toggle(struct device *dev, bool en) .cmd = QCOM_SCM_SMMU_CONFIG_ERRATA1, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] =QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL ; desc.args[1 ] = en; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call_atomic (dev, &desc, &res); +return qcom_scm_call_atomic (dev, &desc); }void __qcom_scm_init (void )
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 13/17 firmware: qcom_scm-32: Create common legacy atomic call
In reply to Elliot BermanPer [1], legacy calling convention supports up to 5 arguments and 3 return values. Create one function to support this combination.
--- drivers/firmware/qcom_scm-32.c | 107 +++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 41 deletions(-)
drivers/firmware/qcom_scm-32.c +66 -41
@@ -257,6 +257,8 @@ static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc)return ret; } +#define LEGACY_ATOMIC_N_REG_ARGS 5 +#define LEGACY_ATOMIC_FIRST_REG_IDX 2#define LEGACY_CLASS_REGISTER (0x2 << 8)#define LEGACY_MASK_IRQS BIT(5)#define LEGACY_ATOMIC (svc, cmd, n) ((LEGACY_FUNCNUM(svc, cmd) << 12) | \
@@ -265,52 +267,34 @@ static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc) (n & 0xf))/** -* qcom_scm_call_atomic1() - Send an atomic SCM command with one argument -* @svc_id: service identifier -* @cmd_id: command identifier -* @arg1: first argument +* qcom_scm_call_atomic() - Send an atomic SCM command with up to 5 arguments +* and 3 return values * * This shall only be used with commands that are guaranteed to be * uninterruptable, atomic and SMP safe. */ -static s32 qcom_scm_call_atomic1 (u32 svc,u32 cmd,u32 arg1) +static int qcom_scm_call_atomic (struct qcom_scm_desc *desc) {int context_id;struct arm_smccc_args smc = {0 };struct arm_smccc_res res; +size_t i, arglen = desc->arginfo &0xf ; - smc.a[0 ] =LEGACY_ATOMIC (svc, cmd,1 ); +BUG_ON (arglen >LEGACY_ATOMIC_N_REG_ARGS ); + + smc.a[0 ] =LEGACY_ATOMIC (desc->svc, desc->cmd, arglen); smc.a[1 ] = (unsigned long )&context_id; - smc.a[2 ] = arg1; -arm_smccc_smc (smc.a[0 ], smc.a[1 ], smc.a[2 ], smc.a[3 ], - smc.a[4 ], smc.a[5 ], smc.a[6 ], smc.a[7 ], &res); -return res.a0; -} +for (i =0 ; i < arglen; i++) + smc.a[i +LEGACY_ATOMIC_FIRST_REG_IDX ] = desc->args[i]; -/** -* qcom_scm_call_atomic2() - Send an atomic SCM command with two arguments -* @svc_id: service identifier -* @cmd_id: command identifier -* @arg1: first argument -* @arg2: second argument -* -* This shall only be used with commands that are guaranteed to be -* uninterruptable, atomic and SMP safe. -*/ -static s32 qcom_scm_call_atomic2 (u32 svc,u32 cmd,u32 arg1,u32 arg2) -{ -int context_id; -struct arm_smccc_args smc = {0 }; -struct arm_smccc_res res; - - smc.a[0 ] =LEGACY_ATOMIC (svc, cmd,2 ); - smc.a[1 ] = (unsigned long )&context_id; - smc.a[2 ] = arg1; - smc.a[3 ] = arg2;arm_smccc_smc (smc.a[0 ], smc.a[1 ], smc.a[2 ], smc.a[3 ], smc.a[4 ], smc.a[5 ], smc.a[6 ], smc.a[7 ], &res); + desc->res[0 ] = res.a1; + desc->res[1 ] = res.a2; + desc->res[2 ] = res.a3; +return res.a0; }
@@ -332,6 +316,11 @@ int __qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus)QCOM_SCM_FLAG_COLDBOOT_CPU2 , QCOM_SCM_FLAG_COLDBOOT_CPU3, }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_ADDR , + .owner =ARM_SMCCC_OWNER_SIP , + };if (!cpus || (cpus &&cpumask_empty (cpus)))return -EINVAL ;
@@ -343,8 +332,11 @@ int __qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus)set_cpu_present (cpu, false); } -return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_ADDR , - flags,virt_to_phys (entry)); + desc.args[0 ] = flags; + desc.args[1 ] =virt_to_phys (entry); + desc.arginfo =QCOM_SCM_ARGS (2 ); + +return qcom_scm_call_atomic (&desc); }/**
@@ -401,8 +393,15 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,*/ void __qcom_scm_cpu_power_down (u32 flags) { -qcom_scm_call_atomic1 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_TERMINATE_PC , - flags &QCOM_SCM_FLUSH_FLAG_MASK ); +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_TERMINATE_PC , + .args[0 ] = flags &QCOM_SCM_FLUSH_FLAG_MASK , + .arginfo =QCOM_SCM_ARGS (1 ), + .owner =ARM_SMCCC_OWNER_SIP , + }; + +qcom_scm_call_atomic (&desc); }int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id)
@@ -425,8 +424,17 @@ int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id)int __qcom_scm_set_dload_mode (struct device *dev,bool enable) { -return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_DLOAD_MODE , - enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ,0 ); +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_DLOAD_MODE , + .owner =ARM_SMCCC_OWNER_SIP , + }; + + desc.args[0 ] =QCOM_SCM_BOOT_SET_DLOAD_MODE ; + desc.args[1 ] = enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ; + desc.arginfo =QCOM_SCM_ARGS (2 ); + +return qcom_scm_call_atomic (&desc); }bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral)
@@ -538,18 +546,35 @@ int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, unsigned int *val) {int ret; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_IO , + .cmd =QCOM_SCM_IO_READ , + .owner =ARM_SMCCC_OWNER_SIP , + }; + + desc.args[0 ] = addr; + desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call_atomic1 (QCOM_SCM_SVC_IO ,QCOM_SCM_IO_READ , addr); + ret =qcom_scm_call_atomic (&desc);if (ret >=0 ) - *val = ret; + *val = desc.res[0 ];return ret <0 ? ret :0 ; }int __qcom_scm_io_writel (struct device *dev,phys_addr_t addr,unsigned int val) { -return qcom_scm_call_atomic2 (QCOM_SCM_SVC_IO ,QCOM_SCM_IO_WRITE , - addr, val); +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_IO , + .cmd =QCOM_SCM_IO_WRITE , + .owner =ARM_SMCCC_OWNER_SIP , + }; + + desc.args[0 ] = addr; + desc.args[1 ] = val; + desc.arginfo =QCOM_SCM_ARGS (2 ); + +return qcom_scm_call_atomic (&desc); }int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 14/17 firmware: qcom_scm-32: Add device argument to atomic calls
In reply to Elliot BermanAdd this unused parameter to reduce merge friction between SMCCC and legacy based conventions.
--- drivers/firmware/qcom_scm-32.c | 18 ++++++++++-------- drivers/firmware/qcom_scm-64.c | 5 +++-- drivers/firmware/qcom_scm.c | 4 ++-- drivers/firmware/qcom_scm.h | 5 +++-- 4 files changed, 18 insertions(+), 14 deletions(-)
drivers/firmware/qcom_scm-32.c +10 -8
@@ -273,7 +273,7 @@ static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc)* This shall only be used with commands that are guaranteed to be * uninterruptable, atomic and SMP safe. */ -static int qcom_scm_call_atomic (struct qcom_scm_desc *desc) +static int qcom_scm_call_atomic (struct device *dev,struct qcom_scm_desc *desc) {int context_id;struct arm_smccc_args smc = {0 };
@@ -306,7 +306,8 @@ static int qcom_scm_call_atomic(struct qcom_scm_desc *desc)* Set the cold boot address of the cpus. Any cpu outside the supported * range would be removed from the cpu present mask. */ -int __qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus) +int __qcom_scm_set_cold_boot_addr (struct device *dev,void *entry, +const cpumask_t *cpus) {int flags =0 ;int cpu;
@@ -336,7 +337,7 @@ int __qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus) desc.args[1 ] =virt_to_phys (entry); desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call_atomic (&desc); +return qcom_scm_call_atomic (dev, &desc); }/**
@@ -391,7 +392,7 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,* the control would return from this function, otherwise, the cpu jumps to the * warm boot entry point set for this cpu upon reset. */ -void __qcom_scm_cpu_power_down (u32 flags) +void __qcom_scm_cpu_power_down (struct device *dev,u32 flags) {struct qcom_scm_desc desc = { .svc =QCOM_SCM_SVC_BOOT ,
@@ -401,7 +402,7 @@ void __qcom_scm_cpu_power_down(u32 flags) .owner = ARM_SMCCC_OWNER_SIP, }; -qcom_scm_call_atomic (&desc); +qcom_scm_call_atomic (dev, &desc); }int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id)
@@ -434,7 +435,7 @@ int __qcom_scm_set_dload_mode(struct device *dev, bool enable) desc.args[1 ] = enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call_atomic (&desc); +return qcom_scm_call_atomic (dev, &desc); }bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral)
@@ -555,11 +556,12 @@ int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, desc.args[0 ] = addr; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call_atomic (&desc); + ret =qcom_scm_call_atomic (dev, &desc);if (ret >=0 ) *val = desc.res[0 ];return ret <0 ? ret :0 ; + }int __qcom_scm_io_writel (struct device *dev,phys_addr_t addr,unsigned int val)
@@ -574,7 +576,7 @@ int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val) desc.args[1 ] = val; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call_atomic (&desc); +return qcom_scm_call_atomic (dev, &desc); }int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id)
drivers/firmware/qcom_scm-64.c +3 -2
@@ -221,7 +221,8 @@ static int qcom_scm_call_atomic(struct device *dev, struct qcom_scm_desc *desc)* Set the cold boot address of the cpus. Any cpu outside the supported * range would be removed from the cpu present mask. */ -int __qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus) +int __qcom_scm_set_cold_boot_addr (struct device *dev,void *entry, +const cpumask_t *cpus) {return -ENOTSUPP ; }
@@ -249,7 +250,7 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,* the control would return from this function, otherwise, the cpu jumps to the * warm boot entry point set for this cpu upon reset. */ -void __qcom_scm_cpu_power_down (u32 flags) +void __qcom_scm_cpu_power_down (struct device *dev,u32 flags) { }
drivers/firmware/qcom_scm.c +2 -2
@@ -97,7 +97,7 @@ static void qcom_scm_clk_disable(void)*/ int qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus) { -return __qcom_scm_set_cold_boot_addr (entry, cpus); +return __qcom_scm_set_cold_boot_addr (__scm->dev, entry, cpus); }EXPORT_SYMBOL (qcom_scm_set_cold_boot_addr);
@@ -125,7 +125,7 @@ EXPORT_SYMBOL(qcom_scm_set_warm_boot_addr);*/ void qcom_scm_cpu_power_down (u32 flags) { -__qcom_scm_cpu_power_down (flags); +__qcom_scm_cpu_power_down (__scm->dev, flags); }EXPORT_SYMBOL (qcom_scm_cpu_power_down);
drivers/firmware/qcom_scm.h +3 -2
@@ -9,10 +9,11 @@#define QCOM_SCM_BOOT_TERMINATE_PC 0x02#define QCOM_SCM_BOOT_SET_REMOTE_STATE 0x0a#define QCOM_SCM_BOOT_SET_DLOAD_MODE 0x10 -extern int __qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus); +extern int __qcom_scm_set_cold_boot_addr (struct device *dev,void *entry, +const cpumask_t *cpus);extern int __qcom_scm_set_warm_boot_addr (struct device *dev,void *entry,const cpumask_t *cpus); -extern void __qcom_scm_cpu_power_down (u32 flags); +extern void __qcom_scm_cpu_power_down (struct device *dev,u32 flags);extern int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id);extern int __qcom_scm_set_dload_mode (struct device *dev,bool enable);#define QCOM_SCM_FLUSH_FLAG_MASK 0x3
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 16/17 firmware: qcom_scm: Enable legacy calling convention in qcom_scm-64.c
In reply to Elliot BermanEnable legacy calling convention in qcom_scm-64. Update is_call_available to use legacy function numbers when using legacy convention.
--- drivers/firmware/qcom_scm-64.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-)
drivers/firmware/qcom_scm-64.c +35 -5
@@ -60,6 +60,7 @@ struct arm_smccc_args {enum qcom_smc_convention {SMC_CONVENTION_UNKNOWN , +SMC_CONVENTION_LEGACY ,SMC_CONVENTION_ARM_32 ,SMC_CONVENTION_ARM_64 , };
@@ -411,7 +412,16 @@ static int qcom_scm_call_atomic_legacy(struct device *dev,static int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc) {might_sleep (); -return qcom_scm_call_smccc (dev, desc, false); +switch (qcom_smc_convention) { +case SMC_CONVENTION_ARM_32 : +case SMC_CONVENTION_ARM_64 : +return qcom_scm_call_smccc (dev, desc, false); +case SMC_CONVENTION_LEGACY : +return qcom_scm_call_legacy (dev, desc); +default : +pr_err ("Unknown current SCM calling convention.\n" ); +return -EINVAL ; + } }/**
@@ -427,7 +437,16 @@ static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc)*/ static int qcom_scm_call_atomic (struct device *dev,struct qcom_scm_desc *desc) { -return qcom_scm_call_smccc (dev, desc, true); +switch (qcom_smc_convention) { +case SMC_CONVENTION_ARM_32 : +case SMC_CONVENTION_ARM_64 : +return qcom_scm_call_smccc (dev, desc, true); +case SMC_CONVENTION_LEGACY : +return qcom_scm_call_atomic_legacy (dev, desc); +default : +pr_err ("Unknown current SCM calling convention.\n" ); +return -EINVAL ; + } }#define QCOM_SCM_FLAG_COLDBOOT_CPU0 0x00
@@ -746,8 +765,19 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id) }; desc.arginfo =QCOM_SCM_ARGS (1 ); - desc.args[0 ] =SMCCC_FUNCNUM (svc_id, cmd_id) | - (ARM_SMCCC_OWNER_SIP <<ARM_SMCCC_OWNER_SHIFT ); +switch (qcom_smc_convention) { +case SMC_CONVENTION_ARM_32 : +case SMC_CONVENTION_ARM_64 : + desc.args[0 ] =SMCCC_FUNCNUM (svc_id, cmd_id) | + (ARM_SMCCC_OWNER_SIP <<ARM_SMCCC_OWNER_SHIFT ); +break ; +case SMC_CONVENTION_LEGACY : + desc.args[0 ] =LEGACY_FUNCNUM (svc_id, cmd_id); +break ; +default : +pr_err ("Unknown SMC convention being used\n" ); +return -EINVAL ; + } ret =qcom_scm_call (dev, &desc);
@@ -902,7 +932,7 @@ void __qcom_scm_init(void) qcom_smc_convention =SMC_CONVENTION_ARM_32 ;if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL ) <=0 ) { - qcom_smc_convention =SMC_CONVENTION_UNKNOWN ; + qcom_smc_convention =SMC_CONVENTION_LEGACY ; } } }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 17/17 firmware: qcom_scm: Rename -64 -> -smc, remove -32
In reply to Elliot Berman- Rename qcom_scm-64.c to qcom_scm-smc as it supports SMC-based calling conventions for 32 and 64-bit targets
- Remove qcom_scm-32.c as it has been superceded by qcom_scm-smc.c
- Update Kconfig to select QCOM_SCM_TRANSPORT_SMC on ARM and ARM64 targets
--- drivers/firmware/Kconfig | 18 +- drivers/firmware/Makefile | 4 +- drivers/firmware/qcom_scm-32.c | 660 ---------------------------- drivers/firmware/qcom_scm-64.c | 938 ---------------------------------------- drivers/firmware/qcom_scm-smc.c | 938 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 950 insertions(+), 1608 deletions(-) delete mode 100644 drivers/firmware/qcom_scm-32.c delete mode 100644 drivers/firmware/qcom_scm-64.c create mode 100644 drivers/firmware/qcom_scm-smc.c
drivers/firmware/Kconfig +11 -7
@@ -236,16 +236,20 @@ config INTEL_STRATIX10_RSU config QCOM_SCM bool - depends on ARM || ARM64 + depends on QCOM_SCM_TRANSPORT_SMC select RESET_CONTROLLER + help + This option enables support for communicating with + Qualcomm secure worlds. -config QCOM_SCM_32 - def_bool y - depends on QCOM_SCM && ARM - -config QCOM_SCM_64 +config QCOM_SCM_TRANSPORT_SMC def_bool y - depends on QCOM_SCM && ARM64 + depends on ARM || ARM64 + help + This option enables support for communicating with + Qualcomm secure worlds via the SMC instruction, using + either ARM SMCCC or legacy calling convention by querying + the Qualcomm secure world. config QCOM_SCM_DOWNLOAD_MODE_DEFAULT bool "Qualcomm download mode enabled by default"
drivers/firmware/Makefile +1 -3
@@ -18,9 +18,7 @@ obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o obj-$(CONFIG_QCOM_SCM) += qcom_scm.o -obj-$(CONFIG_QCOM_SCM_64) += qcom_scm-64.o -obj-$(CONFIG_QCOM_SCM_32) += qcom_scm-32.o -CFLAGS_qcom_scm-32.o :=$(call as-instr,.arch armv7-a\n.arch_extension sec,-DREQUIRES_SEC=1) -march=armv7-a +obj-$(CONFIG_QCOM_SCM_TRANSPORT_SMC) += qcom_scm-smc.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o obj-$(CONFIG_TURRIS_MOX_RWTM) += turris-mox-rwtm.o
drivers/firmware/qcom_scm-32.c deleted +0 -660
661 lines not on this page · raw message
drivers/firmware/qcom_scm-64.c deleted +0 -938
938 lines not on this page · raw message
drivers/firmware/qcom_scm-smc.c new file +938 -0
938 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 15/17 firmware: qcom_scm: Merge legacy and SMCCC conventions
In reply to Elliot BermanCopy/paste legacy SCM driver into qcom_scm-64 with the following notes:
- Renamed qcom_scm_call in qcom_scm-32 to qcom_scm_call_legacy in the copy.
- Renamed qcom_scm_call_atomic in qcom_scm 32 to qcom_scm_call_atomic_legacy in the copy.
- Rename __qcom_scm_call_smccc to qcom_scm_call_smccc.
- Filled in implementations set_cold_boot_addr, set_warm_boot_addr, and cpu_power_down from qcom_scm-32.c.
- set_dload_mode, io_writel, io_readl now use atomic variants as in qcom_scm-32.
--- drivers/firmware/qcom_scm-64.c | 322 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 314 insertions(+), 8 deletions(-)
drivers/firmware/qcom_scm-64.c +314 -8
@@ -95,7 +95,7 @@ static void __qcom_scm_call_do_quirk(const struct arm_smccc_args *smc, }while (res->a0 ==QCOM_SCM_INTERRUPTED ); } -static int ___qcom_scm_call_smccc (struct device *dev, +static int qcom_scm_call_smccc (struct device *dev,struct qcom_scm_desc *desc,bool atomic) {int arglen = desc->arginfo &0xf ;
@@ -181,6 +181,223 @@ static int ___qcom_scm_call_smccc(struct device *dev,return 0 ; } +#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff)) + +/** +* struct legacy_command - one SCM command buffer +* @len: total available memory for command and response +* @buf_offset: start of command buffer +* @resp_hdr_offset: start of response buffer +* @id: command to be executed +* @buf: buffer returned from legacy_get_command_buffer() +* +* An SCM command is laid out in memory as follows: +* +* ------------------- <--- struct legacy_command +* | command header | +* ------------------- <--- legacy_get_command_buffer() +* | command buffer | +* ------------------- <--- struct legacy_response and +* | response header | legacy_command_to_response() +* ------------------- <--- legacy_get_response_buffer() +* | response buffer | +* ------------------- +* +* There can be arbitrary padding between the headers and buffers so +* you should always use the appropriate qcom_scm_get_*_buffer() routines +* to access the buffers in a safe manner. +*/ +struct legacy_command { +__le32 len; +__le32 buf_offset; +__le32 resp_hdr_offset; +__le32 id; +__le32 buf[0 ]; +}; + +/** +* struct legacy_response - one SCM response buffer +* @len: total available memory for response +* @buf_offset: start of response data relative to start of legacy_response +* @is_complete: indicates if the command has finished processing +*/ +struct legacy_response { +__le32 len; +__le32 buf_offset; +__le32 is_complete; +}; + +/** +* legacy_command_to_response() - Get a pointer to a legacy_response +* @cmd: command +* +* Returns a pointer to a response for a command. +*/ +static inline struct legacy_response *legacy_command_to_response ( +const struct legacy_command *cmd) +{ +return (void *)cmd +le32_to_cpu (cmd->resp_hdr_offset); +} + +/** +* legacy_get_command_buffer() - Get a pointer to a command buffer +* @cmd: command +* +* Returns a pointer to the command buffer of a command. +*/ +static inline void *legacy_get_command_buffer (const struct legacy_command *cmd) +{ +return (void *)cmd->buf; +} + +/** +* legacy_get_response_buffer() - Get a pointer to a response buffer +* @rsp: response +* +* Returns a pointer to a response buffer of a response. +*/ +static inline void *legacy_get_response_buffer (const struct legacy_response *rsp) +{ +return (void *)rsp +le32_to_cpu (rsp->buf_offset); +} + +static void __qcom_scm_call_do (const struct arm_smccc_args *smc, +struct arm_smccc_res *res) +{ +do { +arm_smccc_smc (smc->a[0 ], smc->a[1 ], smc->a[2 ], smc->a[3 ], + smc->a[4 ], smc->a[5 ], smc->a[6 ], smc->a[7 ], res); + }while (res->a0 ==QCOM_SCM_INTERRUPTED ); +} + +/** +* qcom_scm_call_legacy() - Send an SCM command +* @dev: struct device +* @svc_id: service identifier +* @cmd_id: command identifier +* @cmd_buf: command buffer +* @cmd_len: length of the command buffer +* @resp_buf: response buffer +* @resp_len: length of the response buffer +* +* Sends a command to the SCM and waits for the command to finish processing. +* +* A note on cache maintenance: +* Note that any buffers that are expected to be accessed by the secure world +* must be flushed before invoking qcom_scm_call and invalidated in the cache +* immediately after qcom_scm_call returns. Cache maintenance on the command +* and response buffers is taken care of by qcom_scm_call; however, callers are +* responsible for any other cached buffers passed over to the secure world. +*/ +static int qcom_scm_call_legacy (struct device *dev,struct qcom_scm_desc *desc) +{ +int arglen = desc->arginfo &0xf ; +int ret =0 , context_id; +size_t i; +struct legacy_command *cmd; +struct legacy_response *rsp; +struct arm_smccc_args smc = {0 }; +struct arm_smccc_res res; +const size_t cmd_len = arglen *sizeof (__le32); +const size_t resp_len =MAX_QCOM_SCM_RETS *sizeof (__le32); +size_t alloc_len =sizeof (*cmd) + cmd_len +sizeof (*rsp) + resp_len; +dma_addr_t cmd_phys; +__le32 *arg_buf; +__le32 *res_buf; + + cmd =kzalloc (PAGE_ALIGN (alloc_len),GFP_KERNEL ); +if (!cmd) +return -ENOMEM ; + + cmd->len =cpu_to_le32 (alloc_len); + cmd->buf_offset =cpu_to_le32 (sizeof (*cmd)); + cmd->resp_hdr_offset =cpu_to_le32 (sizeof (*cmd) + cmd_len); + cmd->id =cpu_to_le32 (LEGACY_FUNCNUM (desc->svc, desc->cmd)); + + arg_buf =legacy_get_command_buffer (cmd); +for (i =0 ; i < arglen; i++) + arg_buf[i] =cpu_to_le32 (desc->args[i]); + + rsp =legacy_command_to_response (cmd); + + cmd_phys =dma_map_single (dev, cmd, alloc_len,DMA_TO_DEVICE ); +if (dma_mapping_error (dev, cmd_phys)) { +kfree (cmd); +return -ENOMEM ; + } + + smc.a[0 ] =1 ; + smc.a[1 ] = (unsigned long )&context_id; + smc.a[2 ] = cmd_phys; + +mutex_lock (&qcom_scm_lock); +__qcom_scm_call_do (&smc, &res); +if (res.a0 <0 ) + ret =qcom_scm_remap_error (res.a0); +mutex_unlock (&qcom_scm_lock); +if (ret) + goto out; + +do { +dma_sync_single_for_cpu (dev, cmd_phys +sizeof (*cmd) + cmd_len, +sizeof (*rsp),DMA_FROM_DEVICE ); + }while (!rsp->is_complete); + +dma_sync_single_for_cpu (dev, cmd_phys +sizeof (*cmd) + cmd_len + +le32_to_cpu (rsp->buf_offset), + resp_len,DMA_FROM_DEVICE ); + + res_buf =legacy_get_response_buffer (rsp); +for (i =0 ; i <MAX_QCOM_SCM_RETS ; i++) + desc->res[i] =le32_to_cpu (res_buf[i]); +out: +dma_unmap_single (dev, cmd_phys, alloc_len,DMA_TO_DEVICE ); +kfree (cmd); +return ret; +} + +#define LEGACY_ATOMIC_N_REG_ARGS 5 +#define LEGACY_ATOMIC_FIRST_REG_IDX 2 +#define LEGACY_CLASS_REGISTER (0x2 << 8) +#define LEGACY_MASK_IRQS BIT(5) +#define LEGACY_ATOMIC (svc, cmd, n) ((LEGACY_FUNCNUM(svc, cmd) << 12) | \ + LEGACY_CLASS_REGISTER | \ + LEGACY_MASK_IRQS | \ + (n & 0xf)) + +/** +* qcom_scm_call_atomic_legacy() - Send an atomic SCM command with up to +* 5 arguments and 3 return values +* +* This shall only be used with commands that are guaranteed to be +* uninterruptable, atomic and SMP safe. +*/ +static int qcom_scm_call_atomic_legacy (struct device *dev, +struct qcom_scm_desc *desc) +{ +int context_id; +struct arm_smccc_args smc = {0 }; +struct arm_smccc_res res; +size_t i, arglen = desc->arginfo &0xf ; + +BUG_ON (arglen >LEGACY_ATOMIC_N_REG_ARGS ); + + smc.a[0 ] =LEGACY_ATOMIC (desc->svc, desc->cmd, arglen); + smc.a[1 ] = (unsigned long )&context_id; + +for (i =0 ; i < arglen; i++) + smc.a[i +LEGACY_ATOMIC_FIRST_REG_IDX ] = desc->args[i]; + +arm_smccc_smc (smc.a[0 ], smc.a[1 ], smc.a[2 ], smc.a[3 ], + smc.a[4 ], smc.a[5 ], smc.a[6 ], smc.a[7 ], &res); + + desc->res[0 ] = res.a1; + desc->res[1 ] = res.a2; + desc->res[2 ] = res.a3; + +return res.a0; +} +/** * qcom_scm_call() - Invoke a syscall in the secure world * @dev: device
@@ -194,7 +411,7 @@ static int ___qcom_scm_call_smccc(struct device *dev,static int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc) {might_sleep (); -return ___qcom_scm_call_smccc (dev, desc, false); +return qcom_scm_call_smccc (dev, desc, false); }/**
@@ -210,9 +427,14 @@ static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc)*/ static int qcom_scm_call_atomic (struct device *dev,struct qcom_scm_desc *desc) { -return ___qcom_scm_call_smccc (dev, desc, true); +return qcom_scm_call_smccc (dev, desc, true); } +#define QCOM_SCM_FLAG_COLDBOOT_CPU0 0x00 +#define QCOM_SCM_FLAG_COLDBOOT_CPU1 0x01 +#define QCOM_SCM_FLAG_COLDBOOT_CPU2 0x08 +#define QCOM_SCM_FLAG_COLDBOOT_CPU3 0x20 +/** * qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus * @entry: Entry point function for the cpus
@@ -224,9 +446,54 @@ static int qcom_scm_call_atomic(struct device *dev, struct qcom_scm_desc *desc)int __qcom_scm_set_cold_boot_addr (struct device *dev,void *entry,const cpumask_t *cpus) { -return -ENOTSUPP ; +int flags =0 ; +int cpu; +int scm_cb_flags[] = { +QCOM_SCM_FLAG_COLDBOOT_CPU0 , +QCOM_SCM_FLAG_COLDBOOT_CPU1 , +QCOM_SCM_FLAG_COLDBOOT_CPU2 , +QCOM_SCM_FLAG_COLDBOOT_CPU3 , + }; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_ADDR , + .owner =ARM_SMCCC_OWNER_SIP , + }; + +if (!cpus || (cpus &&cpumask_empty (cpus))) +return -EINVAL ; + +for_each_cpu (cpu, cpus) { +if (cpu <ARRAY_SIZE (scm_cb_flags)) + flags |= scm_cb_flags[cpu]; +else +set_cpu_present (cpu, false); + } + + desc.args[0 ] = flags; + desc.args[1 ] =virt_to_phys (entry); + desc.arginfo =QCOM_SCM_ARGS (2 ); + +return qcom_scm_call_atomic (dev, &desc); } +#define QCOM_SCM_FLAG_WARMBOOT_CPU0 0x04 +#define QCOM_SCM_FLAG_WARMBOOT_CPU1 0x02 +#define QCOM_SCM_FLAG_WARMBOOT_CPU2 0x10 +#define QCOM_SCM_FLAG_WARMBOOT_CPU3 0x40 + +struct qcom_scm_entry { +int flag; +void *entry; +}; + +static struct qcom_scm_entry qcom_scm_wb[] = { + { .flag =QCOM_SCM_FLAG_WARMBOOT_CPU0 }, + { .flag =QCOM_SCM_FLAG_WARMBOOT_CPU1 }, + { .flag =QCOM_SCM_FLAG_WARMBOOT_CPU2 }, + { .flag =QCOM_SCM_FLAG_WARMBOOT_CPU3 }, +}; +/** * qcom_scm_set_warm_boot_addr() - Set the warm boot address for cpus * @dev: Device pointer
@@ -239,7 +506,37 @@ int __qcom_scm_set_cold_boot_addr(struct device *dev, void *entry,int __qcom_scm_set_warm_boot_addr (struct device *dev,void *entry,const cpumask_t *cpus) { -return -ENOTSUPP ; +int ret; +int flags =0 ; +int cpu; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_ADDR , + }; + +/* +* Reassign only if we are switching from hotplug entry point +* to cpuidle entry point or vice versa. +*/ +for_each_cpu (cpu, cpus) { +if (entry == qcom_scm_wb[cpu].entry) +continue ; + flags |= qcom_scm_wb[cpu].flag; + } + +/* No change in entry function */ +if (!flags) +return 0 ; + + desc.args[0 ] =virt_to_phys (entry); + desc.args[1 ] = flags; + ret =qcom_scm_call (dev, &desc); +if (!ret) { +for_each_cpu (cpu, cpus) + qcom_scm_wb[cpu].entry = entry; + } + +return ret; }/**
@@ -252,6 +549,15 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,*/ void __qcom_scm_cpu_power_down (struct device *dev,u32 flags) { +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_TERMINATE_PC , + .args[0 ] = flags &QCOM_SCM_FLUSH_FLAG_MASK , + .arginfo =QCOM_SCM_ARGS (1 ), + .owner =ARM_SMCCC_OWNER_SIP , + }; + +qcom_scm_call_atomic (dev, &desc); }int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id)
@@ -284,7 +590,7 @@ int __qcom_scm_set_dload_mode(struct device *dev, bool enable) desc.args[1 ] = enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call (dev, &desc); +return qcom_scm_call_atomic (dev, &desc); }bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral)
@@ -408,7 +714,7 @@ int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, desc.args[0 ] = addr; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev, &desc); + ret =qcom_scm_call_atomic (dev, &desc);if (ret >=0 ) *val = desc.res[0 ];
@@ -427,7 +733,7 @@ int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val) desc.args[1 ] = val; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call (dev, &desc); +return qcom_scm_call_atomic (dev, &desc); }int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 11/17 firmware: qcom_scm-32: Use qcom_scm_desc in non-atomic calls
In reply to Elliot BermanUse qcom_scm_desc in non-atomic calls to remove legacy convention details from every SCM wrapper function.
--- drivers/firmware/qcom_scm-32.c | 270 ++++++++++++++++++++++++++--------------- 1 file changed, 169 insertions(+), 101 deletions(-)
drivers/firmware/qcom_scm-32.c +169 -101
@@ -39,6 +39,46 @@ static struct qcom_scm_entry qcom_scm_wb[] = {static DEFINE_MUTEX (qcom_scm_lock); +#define MAX_QCOM_SCM_ARGS 10 +#define MAX_QCOM_SCM_RETS 3 + +enum qcom_scm_arg_types { +QCOM_SCM_VAL , +QCOM_SCM_RO , +QCOM_SCM_RW , +QCOM_SCM_BUFVAL , +}; + +#define QCOM_SCM_ARGS_IMPL (num, a, b, c, d, e, f, g, h, i, j, ...) (\ + (((a) & 0x3) << 4) | \ + (((b) & 0x3) << 6) | \ + (((c) & 0x3) << 8) | \ + (((d) & 0x3) << 10) | \ + (((e) & 0x3) << 12) | \ + (((f) & 0x3) << 14) | \ + (((g) & 0x3) << 16) | \ + (((h) & 0x3) << 18) | \ + (((i) & 0x3) << 20) | \ + (((j) & 0x3) << 22) | \ + ((num) & 0xf)) + +#define QCOM_SCM_ARGS (...) QCOM_SCM_ARGS_IMPL(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + +/** +* struct qcom_scm_desc +* @arginfo: Metadata describing the arguments in args[] +* @args: The array of arguments for the secure syscall +* @res: The values returned by the secure syscall +*/ +struct qcom_scm_desc { +u32 svc; +u32 cmd; +u32 arginfo; +u64 args[MAX_QCOM_SCM_ARGS ]; +u64 res[MAX_QCOM_SCM_RETS ]; +u32 owner; +}; +#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff))/**
@@ -150,15 +190,19 @@ static u32 __qcom_scm_call_do(u32 cmd_addr)* and response buffers is taken care of by qcom_scm_call; however, callers are * responsible for any other cached buffers passed over to the secure world. */ -static int qcom_scm_call (struct device *dev,u32 svc_id,u32 cmd_id, -const void *cmd_buf,size_t cmd_len,void *resp_buf, -size_t resp_len) +static int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc) { +int arglen = desc->arginfo &0xf ;int ret; +size_t i;struct legacy_command *cmd;struct legacy_response *rsp; +const size_t cmd_len = arglen *sizeof (__le32); +const size_t resp_len =MAX_QCOM_SCM_RETS *sizeof (__le32);size_t alloc_len =sizeof (*cmd) + cmd_len +sizeof (*rsp) + resp_len;dma_addr_t cmd_phys; +__le32 *arg_buf; +__le32 *res_buf; cmd =kzalloc (PAGE_ALIGN (alloc_len),GFP_KERNEL );if (!cmd)
@@ -167,10 +211,11 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, cmd->len =cpu_to_le32 (alloc_len); cmd->buf_offset =cpu_to_le32 (sizeof (*cmd)); cmd->resp_hdr_offset =cpu_to_le32 (sizeof (*cmd) + cmd_len); + cmd->id =cpu_to_le32 (LEGACY_FUNCNUM (desc->svc, desc->cmd)); - cmd->id =cpu_to_le32 (LEGACY_FUNCNUM (svc_id, cmd_id)); -if (cmd_buf) -memcpy (legacy_get_command_buffer (cmd), cmd_buf, cmd_len); + arg_buf =legacy_get_command_buffer (cmd); +for (i =0 ; i < arglen; i++) + arg_buf[i] =cpu_to_le32 (desc->args[i]); rsp =legacy_command_to_response (cmd);
@@ -193,13 +238,13 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, sizeof(*rsp), DMA_FROM_DEVICE); }while (!rsp->is_complete); -if (resp_buf) { -dma_sync_single_for_cpu (dev, cmd_phys +sizeof (*cmd) + cmd_len + -le32_to_cpu (rsp->buf_offset), - resp_len,DMA_FROM_DEVICE ); -memcpy (resp_buf,legacy_get_response_buffer (rsp), - resp_len); - } +dma_sync_single_for_cpu (dev, cmd_phys +sizeof (*cmd) + cmd_len + +le32_to_cpu (rsp->buf_offset), + resp_len,DMA_FROM_DEVICE ); + + res_buf =legacy_get_response_buffer (rsp); +for (i =0 ; i <MAX_QCOM_SCM_RETS ; i++) + desc->res[i] =le32_to_cpu (res_buf[i]); out:dma_unmap_single (dev, cmd_phys, alloc_len,DMA_TO_DEVICE );kfree (cmd);
@@ -301,10 +346,10 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,int ret;int flags =0 ;int cpu; -struct { -__le32 flags; -__le32 addr; - } cmd; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_ADDR , + };/* * Reassign only if we are switching from hotplug entry point
@@ -320,10 +365,9 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,if (!flags)return 0 ; - cmd.addr =cpu_to_le32 (virt_to_phys (entry)); - cmd.flags =cpu_to_le32 (flags); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_ADDR , - &cmd,sizeof (cmd),NULL ,0 ); + desc.args[0 ] =virt_to_phys (entry); + desc.args[1 ] = flags; + ret =qcom_scm_call (dev, &desc);if (!ret) {for_each_cpu (cpu, cpus) qcom_scm_wb[cpu].entry = entry;
@@ -348,20 +392,20 @@ void __qcom_scm_cpu_power_down(u32 flags)int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) { -struct { -__le32 state; -__le32 id; - } req; -__le32 scm_ret =0 ; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_REMOTE_STATE , + .owner =ARM_SMCCC_OWNER_SIP , + };int ret; - req.state =cpu_to_le32 (state); - req.id =cpu_to_le32 (id); + desc.args[0 ] = state; + desc.args[1 ] = id; + desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_REMOTE_STATE , - &req,sizeof (req), &scm_ret,sizeof (scm_ret)); + ret =qcom_scm_call (dev, &desc); -return ret ? :le32_to_cpu (scm_ret); +return ret ? : desc.res[0 ]; }int __qcom_scm_set_dload_mode (struct device *dev,bool enable)
@@ -372,104 +416,107 @@ int __qcom_scm_set_dload_mode(struct device *dev, bool enable)bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral) { -__le32 out; -__le32 in;int ret; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_IS_SUPPORTED , + .owner =ARM_SMCCC_OWNER_SIP , + }; - in =cpu_to_le32 (peripheral); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_IS_SUPPORTED , - &in,sizeof (in), - &out,sizeof (out)); + desc.args[0 ] = peripheral; + desc.arginfo =QCOM_SCM_ARGS (1 ); -return ret ? false : !!out; + ret =qcom_scm_call (dev, &desc); + +return ret ? false : !!desc.res[0 ]; }int __qcom_scm_pas_init_image (struct device *dev,u32 peripheral,dma_addr_t metadata_phys) { -__le32 scm_ret;int ret; -struct { -__le32 proc; -__le32 image_addr; - } request; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_INIT_IMAGE , + .owner =ARM_SMCCC_OWNER_SIP , + }; - request.proc =cpu_to_le32 (peripheral); - request.image_addr =cpu_to_le32 (metadata_phys); + desc.args[0 ] = peripheral; + desc.args[1 ] = metadata_phys; + desc.arginfo =QCOM_SCM_ARGS (2 ,QCOM_SCM_VAL ,QCOM_SCM_RW ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_INIT_IMAGE , - &request,sizeof (request), - &scm_ret,sizeof (scm_ret)); + ret =qcom_scm_call (dev, &desc); -return ret ? :le32_to_cpu (scm_ret); +return ret ? : desc.res[0 ]; }int __qcom_scm_pas_mem_setup (struct device *dev,u32 peripheral, -phys_addr_t addr,phys_addr_t size) +phys_addr_t addr,phys_addr_t size) { -__le32 scm_ret;int ret; -struct { -__le32 proc; -__le32 addr; -__le32 len; - } request; - - request.proc =cpu_to_le32 (peripheral); - request.addr =cpu_to_le32 (addr); - request.len =cpu_to_le32 (size); - - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_MEM_SETUP , - &request,sizeof (request), - &scm_ret,sizeof (scm_ret)); - -return ret ? :le32_to_cpu (scm_ret); +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_MEM_SETUP , + .owner =ARM_SMCCC_OWNER_SIP , + }; + + desc.args[0 ] = peripheral; + desc.args[1 ] = addr; + desc.args[2 ] = size; + desc.arginfo =QCOM_SCM_ARGS (3 ); + + ret =qcom_scm_call (dev, &desc); + +return ret ? : desc.res[0 ]; }int __qcom_scm_pas_auth_and_reset (struct device *dev,u32 peripheral) { -__le32 out; -__le32 in;int ret; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_AUTH_AND_RESET , + .owner =ARM_SMCCC_OWNER_SIP , + }; - in =cpu_to_le32 (peripheral); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_AUTH_AND_RESET , - &in,sizeof (in), - &out,sizeof (out)); + ret =qcom_scm_call (dev, &desc); -return ret ? :le32_to_cpu (out); +return ret ? : desc.res[0 ]; }int __qcom_scm_pas_shutdown (struct device *dev,u32 peripheral) { -__le32 out; -__le32 in; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_SHUTDOWN , + .owner =ARM_SMCCC_OWNER_SIP , + };int ret; - in =cpu_to_le32 (peripheral); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_SHUTDOWN , - &in,sizeof (in), - &out,sizeof (out)); + desc.args[0 ] = peripheral; + desc.arginfo =QCOM_SCM_ARGS (1 ); + + ret =qcom_scm_call (dev, &desc); -return ret ? :le32_to_cpu (out); +return ret ? : desc.res[0 ]; }int __qcom_scm_pas_mss_reset (struct device *dev,bool reset) { -__le32 out; -__le32 in =cpu_to_le32 (reset); +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_MSS_RESET , + .owner =ARM_SMCCC_OWNER_SIP , + };int ret; - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_MSS_RESET , - &in,sizeof (in), - &out,sizeof (out)); + desc.args[0 ] = reset; + desc.args[1 ] =0 ; + desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev, &desc); -return ret ? :le32_to_cpu (out); +return ret ? : desc.res[0 ]; } int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
@@ -493,16 +540,16 @@ int __qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val)int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) {int ret; -__le32 svc_cmd =cpu_to_le32 ((svc_id <<10 ) | cmd_id); -__le32 ret_val =0 ; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_INFO , + .cmd =QCOM_INFO_IS_CALL_AVAIL , + .args[0 ] = (svc_id <<10 ) | cmd_id, + .arginfo =QCOM_SCM_ARGS (1 ), + }; - ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL , - &svc_cmd,sizeof (svc_cmd), &ret_val, -sizeof (ret_val)); -if (ret) -return ret; + ret =qcom_scm_call (dev, &desc); -return le32_to_cpu (ret_val); +return ret ? : desc.res[0 ]; } int __qcom_scm_restore_sec_cfg(struct device *dev, u32 device_id,
@@ -533,11 +580,32 @@ int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region,int __qcom_scm_hdcp_req (struct device *dev,struct qcom_scm_hdcp_req *req,u32 req_cnt,u32 *resp) { +int ret; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_HDCP , + .cmd =QCOM_SCM_HDCP_INVOKE , + .owner =ARM_SMCCC_OWNER_SIP , + }; +if (req_cnt >QCOM_SCM_HDCP_MAX_REQ_CNT )return -ERANGE ; -return qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_HDCP_INVOKE , - req, req_cnt *sizeof (*req), resp,sizeof (*resp)); + desc.args[0 ] = req[0 ].addr; + desc.args[1 ] = req[0 ].val; + desc.args[2 ] = req[1 ].addr; + desc.args[3 ] = req[1 ].val; + desc.args[4 ] = req[2 ].addr; + desc.args[5 ] = req[2 ].val; + desc.args[6 ] = req[3 ].addr; + desc.args[7 ] = req[3 ].val; + desc.args[8 ] = req[4 ].addr; + desc.args[9 ] = req[4 ].val; + desc.arginfo =QCOM_SCM_ARGS (req_cnt *2 ); + + ret =qcom_scm_call (dev, &desc); + *resp = desc.res[0 ]; + +return ret; }int __qcom_scm_qsmmu500_wait_safe_toggle (struct device *dev,bool enable)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 12/17 firmware: qcom_scm-32: Move SMCCC register filling to qcom_scm_call
In reply to Elliot Berman- Move SMCCC register filling to qcom_scm_call so that qcom_scm_call_do only needs to concern itself with retry mechanism.
- Use arm_smccc_args struct in atomic variants as well.
--- drivers/firmware/qcom_scm-32.c | 47 ++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 16 deletions(-)
drivers/firmware/qcom_scm-32.c +31 -16
@@ -78,6 +78,9 @@ struct qcom_scm_desc {u64 res[MAX_QCOM_SCM_RETS ];u32 owner; }; +struct arm_smccc_args { +unsigned long a[8 ]; +};#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff))
@@ -159,16 +162,13 @@ static inline void *legacy_get_response_buffer(const struct legacy_response *rspreturn (void *)rsp +le32_to_cpu (rsp->buf_offset); } -static u32 __qcom_scm_call_do (u32 cmd_addr) +static void __qcom_scm_call_do (const struct arm_smccc_args *smc, +struct arm_smccc_res *res) { -int context_id; -struct arm_smccc_res res;do { -arm_smccc_smc (1 , (unsigned long )&context_id, cmd_addr, -0 ,0 ,0 ,0 ,0 , &res); - }while (res.a0 ==QCOM_SCM_INTERRUPTED ); - -return res.a0; +arm_smccc_smc (smc->a[0 ], smc->a[1 ], smc->a[2 ], smc->a[3 ], + smc->a[4 ], smc->a[5 ], smc->a[6 ], smc->a[7 ], res); + }while (res->a0 ==QCOM_SCM_INTERRUPTED ); }/**
@@ -193,10 +193,12 @@ static u32 __qcom_scm_call_do(u32 cmd_addr)static int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc) {int arglen = desc->arginfo &0xf ; -int ret; +int ret =0 , context_id;size_t i;struct legacy_command *cmd;struct legacy_response *rsp; +struct arm_smccc_args smc = {0 }; +struct arm_smccc_res res;const size_t cmd_len = arglen *sizeof (__le32);const size_t resp_len =MAX_QCOM_SCM_RETS *sizeof (__le32);size_t alloc_len =sizeof (*cmd) + cmd_len +sizeof (*rsp) + resp_len;
@@ -225,10 +227,14 @@ static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc)return -ENOMEM ; } + smc.a[0 ] =1 ; + smc.a[1 ] = (unsigned long )&context_id; + smc.a[2 ] = cmd_phys; +mutex_lock (&qcom_scm_lock); - ret =__qcom_scm_call_do (cmd_phys); -if (ret <0 ) - ret =qcom_scm_remap_error (ret); +__qcom_scm_call_do (&smc, &res); +if (res.a0 <0 ) + ret =qcom_scm_remap_error (res.a0);mutex_unlock (&qcom_scm_lock);if (ret) goto out;
@@ -270,10 +276,14 @@ static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc)static s32 qcom_scm_call_atomic1 (u32 svc,u32 cmd,u32 arg1) {int context_id; +struct arm_smccc_args smc = {0 };struct arm_smccc_res res; -arm_smccc_smc (LEGACY_ATOMIC (svc, cmd,1 ), (unsigned long )&context_id, - arg1,0 ,0 ,0 ,0 ,0 , &res); + smc.a[0 ] =LEGACY_ATOMIC (svc, cmd,1 ); + smc.a[1 ] = (unsigned long )&context_id; + smc.a[2 ] = arg1; +arm_smccc_smc (smc.a[0 ], smc.a[1 ], smc.a[2 ], smc.a[3 ], + smc.a[4 ], smc.a[5 ], smc.a[6 ], smc.a[7 ], &res);return res.a0; }
@@ -291,10 +301,15 @@ static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1)static s32 qcom_scm_call_atomic2 (u32 svc,u32 cmd,u32 arg1,u32 arg2) {int context_id; +struct arm_smccc_args smc = {0 };struct arm_smccc_res res; -arm_smccc_smc (LEGACY_ATOMIC (svc, cmd,2 ), (unsigned long )&context_id, - arg1, arg2,0 ,0 ,0 ,0 , &res); + smc.a[0 ] =LEGACY_ATOMIC (svc, cmd,2 ); + smc.a[1 ] = (unsigned long )&context_id; + smc.a[2 ] = arg1; + smc.a[3 ] = arg2; +arm_smccc_smc (smc.a[0 ], smc.a[1 ], smc.a[2 ], smc.a[3 ], + smc.a[4 ], smc.a[5 ], smc.a[6 ], smc.a[7 ], &res);return res.a0; }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 1/17 firmware: qcom_scm: Rename macros and structures
In reply to Elliot Berman- Rename legacy-specific structures and macros with "legacy_" prefix.
- Rename smccc-specific structures and macros with "smccc_" prefix.
- Flip calculation of SMCCC_N_EXT_ARGS to be a function of N_REG_ARGS (not the other way around). N_REG_ARGS is fixed based off the SMC instruction and shouldn't be computed from the SCM abstraction.
- Move SMCCC_FUNCNUM closer to other smccc-specific macros.
- Add LEGACY_FUNCNUM macro to qcom_scm-32.c
--- drivers/firmware/qcom_scm-32.c | 72 ++++++++++++++++++++++-------------------- drivers/firmware/qcom_scm-64.c | 54 +++++++++++++++---------------- drivers/firmware/qcom_scm.c | 2 +- drivers/firmware/qcom_scm.h | 2 +- include/linux/qcom_scm.h | 2 +- 5 files changed, 67 insertions(+), 65 deletions(-)
drivers/firmware/qcom_scm-32.c +37 -35
@@ -1,5 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2010,2015, The Linux Foundation. All rights reserved. +/* Copyright (c) 2010,2015,2019 The Linux Foundation. All rights reserved. * Copyright (C) 2015 Linaro Ltd. */
@@ -38,23 +38,25 @@ static struct qcom_scm_entry qcom_scm_wb[] = {static DEFINE_MUTEX (qcom_scm_lock); +#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff)) +/** -* struct qcom_scm_command - one SCM command buffer +* struct legacy_command - one SCM command buffer * @len: total available memory for command and response * @buf_offset: start of command buffer * @resp_hdr_offset: start of response buffer * @id: command to be executed -* @buf: buffer returned from qcom_scm_get_command_buffer() +* @buf: buffer returned from legacy_get_command_buffer() * * An SCM command is laid out in memory as follows: * -* ------------------- <--- struct qcom_scm_command +* ------------------- <--- struct legacy_command * | command header | -* ------------------- <--- qcom_scm_get_command_buffer() +* ------------------- <--- legacy_get_command_buffer() * | command buffer | -* ------------------- <--- struct qcom_scm_response and -* | response header | qcom_scm_command_to_response() -* ------------------- <--- qcom_scm_get_response_buffer() +* ------------------- <--- struct legacy_response and +* | response header | legacy_command_to_response() +* ------------------- <--- legacy_get_response_buffer() * | response buffer | * ------------------- *
@@ -62,7 +64,7 @@ static DEFINE_MUTEX(qcom_scm_lock);* you should always use the appropriate qcom_scm_get_*_buffer() routines * to access the buffers in a safe manner. */ -struct qcom_scm_command { +struct legacy_command {__le32 len;__le32 buf_offset;__le32 resp_hdr_offset;
@@ -71,52 +73,52 @@ struct qcom_scm_command { };/** -* struct qcom_scm_response - one SCM response buffer +* struct legacy_response - one SCM response buffer * @len: total available memory for response -* @buf_offset: start of response data relative to start of qcom_scm_response +* @buf_offset: start of response data relative to start of legacy_response * @is_complete: indicates if the command has finished processing */ -struct qcom_scm_response { +struct legacy_response {__le32 len;__le32 buf_offset;__le32 is_complete; };/** -* qcom_scm_command_to_response() - Get a pointer to a qcom_scm_response +* legacy_command_to_response() - Get a pointer to a legacy_response * @cmd: command * * Returns a pointer to a response for a command. */ -static inline struct qcom_scm_response *qcom_scm_command_to_response ( -const struct qcom_scm_command *cmd) +static inline struct legacy_response *legacy_command_to_response ( +const struct legacy_command *cmd) {return (void *)cmd +le32_to_cpu (cmd->resp_hdr_offset); }/** -* qcom_scm_get_command_buffer() - Get a pointer to a command buffer +* legacy_get_command_buffer() - Get a pointer to a command buffer * @cmd: command * * Returns a pointer to the command buffer of a command. */ -static inline void *qcom_scm_get_command_buffer (const struct qcom_scm_command *cmd) +static inline void *legacy_get_command_buffer (const struct legacy_command *cmd) {return (void *)cmd->buf; }/** -* qcom_scm_get_response_buffer() - Get a pointer to a response buffer +* legacy_get_response_buffer() - Get a pointer to a response buffer * @rsp: response * * Returns a pointer to a response buffer of a response. */ -static inline void *qcom_scm_get_response_buffer (const struct qcom_scm_response *rsp) +static inline void *legacy_get_response_buffer (const struct legacy_response *rsp) {return (void *)rsp +le32_to_cpu (rsp->buf_offset); } -static u32 smc (u32 cmd_addr) +static u32 __qcom_scm_call_do (u32 cmd_addr) {int context_id; register u32 r0 asm("r0") = 1;
@@ -164,8 +166,8 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, size_t resp_len) {int ret; -struct qcom_scm_command *cmd; -struct qcom_scm_response *rsp; +struct legacy_command *cmd; +struct legacy_response *rsp;size_t alloc_len =sizeof (*cmd) + cmd_len +sizeof (*rsp) + resp_len;dma_addr_t cmd_phys;
@@ -177,11 +179,11 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, cmd->buf_offset =cpu_to_le32 (sizeof (*cmd)); cmd->resp_hdr_offset =cpu_to_le32 (sizeof (*cmd) + cmd_len); - cmd->id =cpu_to_le32 ((svc_id <<10 ) | cmd_id); + cmd->id =cpu_to_le32 (LEGACY_FUNCNUM (svc_id, cmd_id));if (cmd_buf) -memcpy (qcom_scm_get_command_buffer (cmd), cmd_buf, cmd_len); +memcpy (legacy_get_command_buffer (cmd), cmd_buf, cmd_len); - rsp =qcom_scm_command_to_response (cmd); + rsp =legacy_command_to_response (cmd); cmd_phys =dma_map_single (dev, cmd, alloc_len,DMA_TO_DEVICE );if (dma_mapping_error (dev, cmd_phys)) {
@@ -190,7 +192,7 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, }mutex_lock (&qcom_scm_lock); - ret =smc (cmd_phys); + ret =__qcom_scm_call_do (cmd_phys);if (ret <0 ) ret =qcom_scm_remap_error (ret);mutex_unlock (&qcom_scm_lock);
@@ -206,7 +208,7 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id,dma_sync_single_for_cpu (dev, cmd_phys +sizeof (*cmd) + cmd_len +le32_to_cpu (rsp->buf_offset), resp_len,DMA_FROM_DEVICE ); -memcpy (resp_buf,qcom_scm_get_response_buffer (rsp), +memcpy (resp_buf,legacy_get_response_buffer (rsp), resp_len); } out:
@@ -215,12 +217,12 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id,return ret; } -#define SCM_CLASS_REGISTER (0x2 << 8) -#define SCM_MASK_IRQS BIT(5) -#define SCM_ATOMIC (svc, cmd, n) (((((svc) << 10)|((cmd) & 0x3ff)) << 12) | \ - SCM_CLASS_REGISTER | \ - SCM_MASK_IRQS | \ - (n & 0xf)) +#define LEGACY_CLASS_REGISTER (0x2 << 8) +#define LEGACY_MASK_IRQS BIT(5) +#define LEGACY_ATOMIC (svc, cmd, n) ((LEGACY_FUNCNUM(svc, cmd) << 12) | \ + LEGACY_CLASS_REGISTER | \ + LEGACY_MASK_IRQS | \ + (n & 0xf))/** * qcom_scm_call_atomic1() - Send an atomic SCM command with one argument
@@ -235,7 +237,7 @@ static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1) {int context_id; - register u32 r0 asm("r0") = SCM_ATOMIC(svc, cmd, 1); + register u32 r0 asm("r0") = LEGACY_ATOMIC(svc, cmd, 1); register u32 r1 asm("r1") = (u32)&context_id; register u32 r2 asm("r2") = arg1;
@@ -268,7 +270,7 @@ static s32 qcom_scm_call_atomic2(u32 svc, u32 cmd, u32 arg1, u32 arg2) {int context_id; - register u32 r0 asm("r0") = SCM_ATOMIC(svc, cmd, 2); + register u32 r0 asm("r0") = LEGACY_ATOMIC(svc, cmd, 2); register u32 r1 asm("r1") = (u32)&context_id; register u32 r2 asm("r2") = arg1; register u32 r3 asm("r3") = arg2;
drivers/firmware/qcom_scm-64.c +27 -27
144 lines not on this page · raw message
drivers/firmware/qcom_scm.c +1 -1
@@ -2,7 +2,7 @@/* * Qualcomm SCM driver * -* Copyright (c) 2010,2015, The Linux Foundation. All rights reserved. +* Copyright (c) 2010,2015,2019 The Linux Foundation. All rights reserved. * Copyright (C) 2015 Linaro Ltd. */ #include <linux/platform_device.h>
drivers/firmware/qcom_scm.h +1 -1
@@ -1,5 +1,5 @@/* SPDX-License-Identifier: GPL-2.0-only */ -/* Copyright (c) 2010-2015, The Linux Foundation. All rights reserved. +/* Copyright (c) 2010-2015,2019 The Linux Foundation. All rights reserved. */ #ifndef __QCOM_SCM_INT_H#define __QCOM_SCM_INT_H
include/linux/qcom_scm.h +1 -1
@@ -1,5 +1,5 @@/* SPDX-License-Identifier: GPL-2.0-only */ -/* Copyright (c) 2010-2015, 2018, The Linux Foundation. All rights reserved. +/* Copyright (c) 2010-2015,2019 The Linux Foundation. All rights reserved. * Copyright (C) 2015 Linaro Ltd. */ #ifndef __QCOM_SCM_H
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 10/17 firmware: qcom_scm-32: Use SMC arch wrappers
In reply to Elliot BermanUse SMC arch wrappers instead of inline assembly.
--- drivers/firmware/qcom_scm-32.c | 71 ++++++++++-------------------------------- 1 file changed, 17 insertions(+), 54 deletions(-)
drivers/firmware/qcom_scm-32.c +17 -54
@@ -10,6 +10,7 @@#include <linux/errno.h> #include <linux/err.h> #include <linux/qcom_scm.h> +#include <linux/arm-smccc.h> #include <linux/dma-mapping.h> #include "qcom_scm.h"
@@ -121,25 +122,13 @@ static inline void *legacy_get_response_buffer(const struct legacy_response *rspstatic u32 __qcom_scm_call_do (u32 cmd_addr) {int context_id; - register u32 r0 asm("r0") = 1; - register u32 r1 asm("r1") = (u32)&context_id; - register u32 r2 asm("r2") = cmd_addr; +struct arm_smccc_res res;do { - asmvolatile ( - __asmeq("%0", "r0") - __asmeq("%1", "r0") - __asmeq("%2", "r1") - __asmeq("%3", "r2") -#ifdef REQUIRES_SEC - ".arch_extension sec\n" -#endif - "smc #0 @ switch to secure world\n" - : "=r" (r0) - : "r" (r0), "r" (r1), "r" (r2) - : "r3", "r12"); - }while (r0 ==QCOM_SCM_INTERRUPTED ); - -return r0; +arm_smccc_smc (1 , (unsigned long )&context_id, cmd_addr, +0 ,0 ,0 ,0 ,0 , &res); + }while (res.a0 ==QCOM_SCM_INTERRUPTED ); + +return res.a0; }/**
@@ -236,24 +225,12 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id,static s32 qcom_scm_call_atomic1 (u32 svc,u32 cmd,u32 arg1) {int context_id; +struct arm_smccc_res res; + +arm_smccc_smc (LEGACY_ATOMIC (svc, cmd,1 ), (unsigned long )&context_id, + arg1,0 ,0 ,0 ,0 ,0 , &res); - register u32 r0 asm("r0") = LEGACY_ATOMIC(svc, cmd, 1); - register u32 r1 asm("r1") = (u32)&context_id; - register u32 r2 asm("r2") = arg1; - - asm volatile( - __asmeq("%0", "r0") - __asmeq("%1", "r0") - __asmeq("%2", "r1") - __asmeq("%3", "r2") -#ifdef REQUIRES_SEC - ".arch_extension sec\n" -#endif - "smc #0 @ switch to secure world\n" - : "=r" (r0) - : "r" (r0), "r" (r1), "r" (r2) - : "r3", "r12"); -return r0; +return res.a0; }/**
@@ -269,26 +246,12 @@ static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1)static s32 qcom_scm_call_atomic2 (u32 svc,u32 cmd,u32 arg1,u32 arg2) {int context_id; +struct arm_smccc_res res; + +arm_smccc_smc (LEGACY_ATOMIC (svc, cmd,2 ), (unsigned long )&context_id, + arg1, arg2,0 ,0 ,0 ,0 , &res); - register u32 r0 asm("r0") = LEGACY_ATOMIC(svc, cmd, 2); - register u32 r1 asm("r1") = (u32)&context_id; - register u32 r2 asm("r2") = arg1; - register u32 r3 asm("r3") = arg2; - - asm volatile( - __asmeq("%0", "r0") - __asmeq("%1", "r0") - __asmeq("%2", "r1") - __asmeq("%3", "r2") - __asmeq("%4", "r3") -#ifdef REQUIRES_SEC - ".arch_extension sec\n" -#endif - "smc #0 @ switch to secure world\n" - : "=r" (r0) - : "r" (r0), "r" (r1), "r" (r2), "r" (r3) - : "r12"); -return r0; +return res.a0; }/**
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 8/17 firmware: qcom_scm-64: Move SMC register filling to qcom_scm_call_smccc
In reply to Elliot Bermanqcom_scm_call_smccc should be responsible for converting qcom_scm_desc into arguments for smc call. Consolidate the dispersed logic to convert qcom_scm_desc into smc arguments inside qcom_scm_call_smccc.
--- drivers/firmware/qcom_scm-64.c | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-)
drivers/firmware/qcom_scm-64.c +25 -19
@@ -54,6 +54,10 @@ struct qcom_scm_desc {u32 owner; }; +struct arm_smccc_args { +unsigned long a[8 ]; +}; +static u64 qcom_smccc_convention =-1 ;static DEFINE_MUTEX (qcom_scm_lock);
@@ -64,28 +68,23 @@ static DEFINE_MUTEX(qcom_scm_lock);#define SMCCC_N_REG_ARGS 4#define SMCCC_FIRST_REG_IDX 2#define SMCCC_N_EXT_ARGS (MAX_QCOM_SCM_ARGS - SMCCC_N_REG_ARGS + 1) +#define SMCCC_LAST_REG_IDX (SMCCC_FIRST_REG_IDX + SMCCC_N_REG_ARGS - 1) -static void __qcom_scm_call_do_quirk (const struct qcom_scm_desc *desc, -struct arm_smccc_res *res,u64 x5,u32 type) +static void __qcom_scm_call_do_quirk (const struct arm_smccc_args *smc, +struct arm_smccc_res *res) { -u64 cmd; +unsigned long a0 = smc->a[0 ];struct arm_smccc_quirk quirk = { .id =ARM_SMCCC_QUIRK_QCOM_A6 }; - cmd =ARM_SMCCC_CALL_VAL ( - type, - qcom_smccc_convention, - desc->owner, -SMCCC_FUNCNUM (desc->svc, desc->cmd)); - quirk.state.a6 =0 ;do { -arm_smccc_smc_quirk (cmd, desc->arginfo, desc->args[0 ], - desc->args[1 ], desc->args[2 ], x5, - quirk.state.a6,0 , res, &quirk); +arm_smccc_smc_quirk (a0, smc->a[1 ], smc->a[2 ], smc->a[3 ], + smc->a[4 ], smc->a[5 ], quirk.state.a6, + smc->a[7 ], res, &quirk);if (res->a0 ==QCOM_SCM_INTERRUPTED ) - cmd = res->a0; + a0 = res->a0; }while (res->a0 ==QCOM_SCM_INTERRUPTED ); }
@@ -95,13 +94,21 @@ static int ___qcom_scm_call_smccc(struct device *dev, {int arglen = desc->arginfo &0xf ;int i; -u32 fn_id =SMCCC_FUNCNUM (svc_id, cmd_id); -u64 x5 = desc->args[SMCCC_N_REG_ARGS -1 ];dma_addr_t args_phys =0 ;void *args_virt =NULL ;size_t alloc_len;gfp_t flag = atomic ?GFP_ATOMIC :GFP_KERNEL ;struct arm_smccc_res res; +struct arm_smccc_args smc = {0 }; + + smc.a[0 ] =ARM_SMCCC_CALL_VAL ( + atomic ?ARM_SMCCC_FAST_CALL :ARM_SMCCC_STD_CALL , + qcom_smccc_convention, + desc->owner, +SMCCC_FUNCNUM (desc->svc, desc->cmd)); + smc.a[1 ] = desc->arginfo; +for (i =0 ; i <SMCCC_N_REG_ARGS ; i++) + smc.a[i +SMCCC_FIRST_REG_IDX ] = desc->args[i];if (unlikely (arglen >SMCCC_N_REG_ARGS )) { alloc_len =SMCCC_N_EXT_ARGS *sizeof (u64);
@@ -132,19 +139,18 @@ static int ___qcom_scm_call_smccc(struct device *dev,return -ENOMEM ; } - x5 = args_phys; + smc.a[SMCCC_LAST_REG_IDX ] = args_phys; }if (atomic) { -__qcom_scm_call_do_quirk (desc, &res, x5,ARM_SMCCC_FAST_CALL ); +__qcom_scm_call_do_quirk (&smc, &res); }else {int retry_count =0 ; do { mutex_lock(&qcom_scm_lock); - __qcom_scm_call_do_quirk(desc, &res, x5, - ARM_SMCCC_STD_CALL); + __qcom_scm_call_do_quirk(&smc, &res); mutex_unlock(&qcom_scm_lock);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 9/17 firmware: qcom_scm-64: Improve SMC convention detection
In reply to Elliot Berman- Use enum to describe SMC convention.
- Improve SMC convention detection to use __qcom_scm_is_call_available instead of circumventing qcom_scm_call_smccc.
- Improve SMC convention detection to check that SMCCC-32 works, instead of just assuming it does of SMCCC-64 does not.
--- drivers/firmware/qcom_scm-64.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-)
drivers/firmware/qcom_scm-64.c +21 -17
@@ -58,7 +58,13 @@ struct arm_smccc_args {unsigned long a[8 ]; }; -static u64 qcom_smccc_convention =-1 ; +enum qcom_smc_convention { +SMC_CONVENTION_UNKNOWN , +SMC_CONVENTION_ARM_32 , +SMC_CONVENTION_ARM_64 , +}; + +static enum qcom_smc_convention qcom_smc_convention =SMC_CONVENTION_UNKNOWN ;static DEFINE_MUTEX (qcom_scm_lock);#define QCOM_SCM_EBUSY_WAIT_MS 30
@@ -103,7 +109,9 @@ static int ___qcom_scm_call_smccc(struct device *dev, smc.a[0 ] =ARM_SMCCC_CALL_VAL ( atomic ?ARM_SMCCC_FAST_CALL :ARM_SMCCC_STD_CALL , - qcom_smccc_convention, + (qcom_smc_convention ==SMC_CONVENTION_ARM_64 ) ? +ARM_SMCCC_SMC_64 : +ARM_SMCCC_SMC_32 , desc->owner,SMCCC_FUNCNUM (desc->svc, desc->cmd)); smc.a[1 ] = desc->arginfo;
@@ -117,7 +125,7 @@ static int ___qcom_scm_call_smccc(struct device *dev,if (!args_virt)return -ENOMEM ; -if (qcom_smccc_convention ==ARM_SMCCC_SMC_32 ) { +if (qcom_smc_convention ==SMC_CONVENTION_ARM_32 ) {__le32 *args = args_virt;for (i =0 ; i <SMCCC_N_EXT_ARGS ; i++)
@@ -579,19 +587,15 @@ int __qcom_scm_qsmmu500_wait_safe_toggle(struct device *dev, bool en)void __qcom_scm_init (void ) { -u64 cmd; -struct arm_smccc_res res; -u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL ); -/* First try a SMC64 call */ - cmd =ARM_SMCCC_CALL_VAL (ARM_SMCCC_FAST_CALL ,ARM_SMCCC_SMC_64 , -ARM_SMCCC_OWNER_SIP , function); - -arm_smccc_smc (cmd,QCOM_SCM_ARGS (1 ), cmd & (~BIT (ARM_SMCCC_TYPE_SHIFT )), -0 ,0 ,0 ,0 ,0 , &res); - -if (!res.a0 && res.a1) - qcom_smccc_convention =ARM_SMCCC_SMC_64 ; -else - qcom_smccc_convention =ARM_SMCCC_SMC_32 ; + qcom_smc_convention =SMC_CONVENTION_ARM_64 ; +if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO , +QCOM_INFO_IS_CALL_AVAIL ) <=0 ) { +/* Now try a SMC32 call */ + qcom_smc_convention =SMC_CONVENTION_ARM_32 ; +if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO , +QCOM_INFO_IS_CALL_AVAIL ) <=0 ) { + qcom_smc_convention =SMC_CONVENTION_UNKNOWN ; + } + } }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 2/17 firmware: qcom_scm: Apply consistent naming scheme to command IDs
In reply to Elliot BermanCreate a consistent naming scheme for command IDs. The scheme is QCOM_SCM_##svc_##cmd. Remove unused macros QCOM_SCM_FLAG_HLOS, QCOM_SCM_FLAG_COLDBOOT_MC, QCOM_SCM_FLAG_WARMBOOT_MC, QCOM_SCM_CMD_CORE_HOTPLUGGED, and QCOM_SCM_BOOT_ADDR_MC.
--- drivers/firmware/qcom_scm-32.c | 28 ++++++++++++++-------------- drivers/firmware/qcom_scm-64.c | 38 +++++++++++++++++++------------------- drivers/firmware/qcom_scm.c | 8 ++++---- drivers/firmware/qcom_scm.h | 41 ++++++++++++++++++----------------------- 4 files changed, 55 insertions(+), 60 deletions(-)
drivers/firmware/qcom_scm-32.c +14 -14
@@ -356,7 +356,7 @@ int __qcom_scm_set_cold_boot_addr(void *entry, const cpumask_t *cpus)set_cpu_present (cpu, false); } -return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_ADDR , +return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_ADDR , flags,virt_to_phys (entry)); }
@@ -395,7 +395,7 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry, cmd.addr =cpu_to_le32 (virt_to_phys (entry)); cmd.flags =cpu_to_le32 (flags); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_ADDR , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_ADDR , &cmd,sizeof (cmd),NULL ,0 );if (!ret) {for_each_cpu (cpu, cpus)
@@ -415,7 +415,7 @@ int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry,*/ void __qcom_scm_cpu_power_down (u32 flags) { -qcom_scm_call_atomic1 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_CMD_TERMINATE_PC , +qcom_scm_call_atomic1 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_TERMINATE_PC , flags &QCOM_SCM_FLUSH_FLAG_MASK ); }
@@ -425,7 +425,7 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id)__le32 svc_cmd =cpu_to_le32 ((svc_id <<10 ) | cmd_id);__le32 ret_val =0 ; - ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_IS_CALL_AVAIL_CMD , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL , &svc_cmd,sizeof (svc_cmd), &ret_val,sizeof (ret_val));if (ret)
@@ -440,7 +440,7 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req,if (req_cnt >QCOM_SCM_HDCP_MAX_REQ_CNT )return -ERANGE ; -return qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_CMD_HDCP , +return qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_HDCP_INVOKE , req, req_cnt *sizeof (*req), resp,sizeof (*resp)); }
@@ -456,7 +456,7 @@ bool __qcom_scm_pas_supported(struct device *dev, u32 peripheral) in =cpu_to_le32 (peripheral); ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_IS_SUPPORTED_CMD , +QCOM_SCM_PIL_PAS_IS_SUPPORTED , &in,sizeof (in), &out,sizeof (out));
@@ -477,7 +477,7 @@ int __qcom_scm_pas_init_image(struct device *dev, u32 peripheral, request.image_addr =cpu_to_le32 (metadata_phys); ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_INIT_IMAGE_CMD , +QCOM_SCM_PIL_PAS_INIT_IMAGE , &request,sizeof (request), &scm_ret,sizeof (scm_ret));
@@ -500,7 +500,7 @@ int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral, request.len =cpu_to_le32 (size); ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_MEM_SETUP_CMD , +QCOM_SCM_PIL_PAS_MEM_SETUP , &request,sizeof (request), &scm_ret,sizeof (scm_ret));
@@ -515,7 +515,7 @@ int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 peripheral) in =cpu_to_le32 (peripheral); ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_AUTH_AND_RESET_CMD , +QCOM_SCM_PIL_PAS_AUTH_AND_RESET , &in,sizeof (in), &out,sizeof (out));
@@ -530,7 +530,7 @@ int __qcom_scm_pas_shutdown(struct device *dev, u32 peripheral) in =cpu_to_le32 (peripheral); ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_SHUTDOWN_CMD , +QCOM_SCM_PIL_PAS_SHUTDOWN , &in,sizeof (in), &out,sizeof (out));
@@ -543,7 +543,7 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)__le32 in =cpu_to_le32 (reset);int ret; - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PAS_MSS_RESET , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_MSS_RESET , &in,sizeof (in), &out,sizeof (out));
@@ -552,8 +552,8 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)int __qcom_scm_set_dload_mode (struct device *dev,bool enable) { -return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_DLOAD_MODE , - enable ?QCOM_SCM_SET_DLOAD_MODE :0 ,0 ); +return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_DLOAD_MODE , + enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ,0 ); }int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id)
@@ -568,7 +568,7 @@ int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id) req.state =cpu_to_le32 (state); req.id =cpu_to_le32 (id); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_REMOTE_STATE , &req,sizeof (req), &scm_ret,sizeof (scm_ret));return ret ? :le32_to_cpu (scm_ret);
drivers/firmware/qcom_scm-64.c +19 -19
@@ -256,7 +256,7 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id) desc.args[0 ] =SMCCC_FUNCNUM (svc_id, cmd_id) | (ARM_SMCCC_OWNER_SIP <<ARM_SMCCC_OWNER_SHIFT ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_IS_CALL_AVAIL_CMD , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL , &desc, &res);return ret ? : res.a1;
@@ -284,7 +284,7 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, desc.args[9 ] = req[4 ].val; desc.arginfo =QCOM_SCM_ARGS (10 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_CMD_HDCP , &desc, + ret =qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_HDCP_INVOKE , &desc, &res); *resp = res.a1;
@@ -295,7 +295,7 @@ void __qcom_scm_init(void) {u64 cmd;struct arm_smccc_res res; -u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO ,QCOM_IS_CALL_AVAIL_CMD ); +u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL );/* First try a SMC64 call */ cmd = ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64,
@@ -320,7 +320,7 @@ bool __qcom_scm_pas_supported(struct device *dev, u32 peripheral) desc.arginfo =QCOM_SCM_ARGS (1 ); ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_IS_SUPPORTED_CMD , +QCOM_SCM_PIL_PAS_IS_SUPPORTED , &desc, &res);return ret ? false : !!res.a1;
@@ -337,7 +337,7 @@ int __qcom_scm_pas_init_image(struct device *dev, u32 peripheral, desc.args[1 ] = metadata_phys; desc.arginfo =QCOM_SCM_ARGS (2 ,QCOM_SCM_VAL ,QCOM_SCM_RW ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PAS_INIT_IMAGE_CMD , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_INIT_IMAGE , &desc, &res);return ret ? : res.a1;
@@ -355,7 +355,7 @@ int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral, desc.args[2 ] = size; desc.arginfo =QCOM_SCM_ARGS (3 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PAS_MEM_SETUP_CMD , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_MEM_SETUP , &desc, &res);return ret ? : res.a1;
@@ -371,7 +371,7 @@ int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 peripheral) desc.arginfo =QCOM_SCM_ARGS (1 ); ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_AUTH_AND_RESET_CMD , +QCOM_SCM_PIL_PAS_AUTH_AND_RESET , &desc, &res);return ret ? : res.a1;
@@ -386,7 +386,7 @@ int __qcom_scm_pas_shutdown(struct device *dev, u32 peripheral) desc.args[0 ] = peripheral; desc.arginfo =QCOM_SCM_ARGS (1 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PAS_SHUTDOWN_CMD , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_SHUTDOWN , &desc, &res);return ret ? : res.a1;
@@ -402,7 +402,7 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) desc.args[1 ] =0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PAS_MSS_RESET , &desc, + ret =qcom_scm_call (dev,QCOM_SCM_SVC_PIL ,QCOM_SCM_PIL_PAS_MSS_RESET , &desc, &res);return ret ? : res.a1;
@@ -418,7 +418,7 @@ int __qcom_scm_set_remote_state(struct device *dev, u32 state, u32 id) desc.args[1 ] = id; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_REMOTE_STATE , &desc, &res);return ret ? : res.a1;
@@ -445,7 +445,7 @@ int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region, QCOM_SCM_VAL, QCOM_SCM_VAL); ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP , -QCOM_MEM_PROT_ASSIGN_ID , +QCOM_MP_ASSIGN , &desc, &res);return ret ? : res.a1;
@@ -461,7 +461,7 @@ int __qcom_scm_restore_sec_cfg(struct device *dev, u32 device_id, u32 spare) desc.args[1 ] = spare; desc.arginfo =QCOM_SCM_ARGS (2 ); - ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP ,QCOM_SCM_RESTORE_SEC_CFG , + ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP ,QCOM_SCM_MP_RESTORE_SEC_CFG , &desc, &res);return ret ? : res.a1;
@@ -478,7 +478,7 @@ int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare, desc.arginfo =QCOM_SCM_ARGS (1 ); ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP , -QCOM_SCM_IOMMU_SECURE_PTBL_SIZE , &desc, &res); +QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE , &desc, &res);if (size) *size = res.a1;
@@ -500,7 +500,7 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size, QCOM_SCM_VAL); ret =qcom_scm_call (dev,QCOM_SCM_SVC_MP , -QCOM_SCM_IOMMU_SECURE_PTBL_INIT , &desc, &res); +QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT , &desc, &res);/* the pg table has been initialized already, ignore the error */ if (ret == -EPERM )
@@ -514,11 +514,11 @@ int __qcom_scm_set_dload_mode(struct device *dev, bool enable)struct qcom_scm_desc desc = {0 };struct arm_smccc_res res; - desc.args[0 ] =QCOM_SCM_SET_DLOAD_MODE ; - desc.args[1 ] = enable ?QCOM_SCM_SET_DLOAD_MODE :0 ; + desc.args[0 ] =QCOM_SCM_BOOT_SET_DLOAD_MODE ; + desc.args[1 ] = enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ; desc.arginfo =QCOM_SCM_ARGS (2 ); -return qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_DLOAD_MODE , +return qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_DLOAD_MODE , &desc, &res); }
@@ -558,10 +558,10 @@ int __qcom_scm_qsmmu500_wait_safe_toggle(struct device *dev, bool en)struct qcom_scm_desc desc = {0 };struct arm_smccc_res res; - desc.args[0 ] =QCOM_SCM_CONFIG_ERRATA1_CLIENT_ALL ; + desc.args[0 ] =QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL ; desc.args[1 ] = en; desc.arginfo =QCOM_SCM_ARGS (2 );return qcom_scm_call_atomic (dev,QCOM_SCM_SVC_SMMU_PROGRAM , -QCOM_SCM_CONFIG_ERRATA1 , &desc, &res); +QCOM_SCM_SMMU_CONFIG_ERRATA1 , &desc, &res); }
drivers/firmware/qcom_scm.c +4 -4
@@ -142,7 +142,7 @@ bool qcom_scm_hdcp_available(void)return ret; ret =__qcom_scm_is_call_available (__scm->dev,QCOM_SCM_SVC_HDCP , -QCOM_SCM_CMD_HDCP ); +QCOM_SCM_HDCP_INVOKE );qcom_scm_clk_disable ();
@@ -183,7 +183,7 @@ bool qcom_scm_pas_supported(u32 peripheral)int ret; ret =__qcom_scm_is_call_available (__scm->dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PAS_IS_SUPPORTED_CMD ); +QCOM_SCM_PIL_PAS_IS_SUPPORTED );if (ret <=0 )return false;
@@ -370,12 +370,12 @@ static void qcom_scm_set_download_mode(bool enable) avail =__qcom_scm_is_call_available (__scm->dev,QCOM_SCM_SVC_BOOT , -QCOM_SCM_SET_DLOAD_MODE ); +QCOM_SCM_BOOT_SET_DLOAD_MODE );if (avail) { ret =__qcom_scm_set_dload_mode (__scm->dev, enable); }else if (__scm->dload_mode_addr) { ret =__qcom_scm_io_writel (__scm->dev, __scm->dload_mode_addr, - enable ?QCOM_SCM_SET_DLOAD_MODE :0 ); + enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ); }else {dev_err (__scm->dev,"No available mechanism for setting download mode\n" );
drivers/firmware/qcom_scm.h +18 -23
86 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 7/17 firmware: qcom_scm-64: Remove qcom_scm_call_do_smccc
In reply to Elliot BermanRemove thin wrapper to qcom_scm_call_do_smccc because it doesn't do enough of anything interesting to dedicate its own function.
--- drivers/firmware/qcom_scm-64.c | 46 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-)
drivers/firmware/qcom_scm-64.c +20 -26
@@ -90,31 +90,6 @@ static void __qcom_scm_call_do_quirk(const struct qcom_scm_desc *desc, }while (res->a0 ==QCOM_SCM_INTERRUPTED ); } -static void qcom_scm_call_do_smccc (const struct qcom_scm_desc *desc, -struct arm_smccc_res *res,u64 x5,bool atomic) -{ -int retry_count =0 ; - -if (atomic) { -__qcom_scm_call_do_quirk (desc, res, x5,ARM_SMCCC_FAST_CALL ); -return ; - } - -do { -mutex_lock (&qcom_scm_lock); - -__qcom_scm_call_do_quirk (desc, res, x5,ARM_SMCCC_STD_CALL ); - -mutex_unlock (&qcom_scm_lock); - -if (res->a0 ==QCOM_SCM_V2_EBUSY ) { -if (retry_count++ >QCOM_SCM_EBUSY_MAX_RETRY ) -break ; -msleep (QCOM_SCM_EBUSY_WAIT_MS ); - } - }while (res->a0 ==QCOM_SCM_V2_EBUSY ); -} -static int ___qcom_scm_call_smccc (struct device *dev,struct qcom_scm_desc *desc,bool atomic) {
@@ -160,7 +135,26 @@ static int ___qcom_scm_call_smccc(struct device *dev, x5 = args_phys; } -qcom_scm_call_do_smccc (desc, &res, x5, atomic); +if (atomic) { +__qcom_scm_call_do_quirk (desc, &res, x5,ARM_SMCCC_FAST_CALL ); + }else { +int retry_count =0 ; + +do { +mutex_lock (&qcom_scm_lock); + +__qcom_scm_call_do_quirk (desc, &res, x5, +ARM_SMCCC_STD_CALL ); + +mutex_unlock (&qcom_scm_lock); + +if (res.a0 ==QCOM_SCM_V2_EBUSY ) { +if (retry_count++ >QCOM_SCM_EBUSY_MAX_RETRY ) +break ; +msleep (QCOM_SCM_EBUSY_WAIT_MS ); + } + }while (res.a0 ==QCOM_SCM_V2_EBUSY ); + }if (args_virt) {dma_unmap_single (dev, args_phys, alloc_len,DMA_TO_DEVICE );
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
RFC 3/17 firmware: qcom_scm: Order functions, definitions by service/command
In reply to Elliot BermanDefinitions throughout qcom_scm are loosely grouped and loosely ordered. Sort all the functions/definitions by service ID/command ID to improve sanity when needing to add new functionality to this driver.
--- drivers/firmware/qcom_scm-32.c | 104 +++++++++---------- drivers/firmware/qcom_scm-64.c | 192 +++++++++++++++++------------------ drivers/firmware/qcom_scm.c | 224 ++++++++++++++++++++--------------------- drivers/firmware/qcom_scm.h | 107 ++++++++++---------- include/linux/qcom_scm.h | 72 ++++++------- 5 files changed, 350 insertions(+), 349 deletions(-)
drivers/firmware/qcom_scm-32.c +52 -52
@@ -419,33 +419,28 @@ void __qcom_scm_cpu_power_down(u32 flags) flags & QCOM_SCM_FLUSH_FLAG_MASK); } -int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) +int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) { +struct { +__le32 state; +__le32 id; + } req; +__le32 scm_ret =0 ;int ret; -__le32 svc_cmd =cpu_to_le32 ((svc_id <<10 ) | cmd_id); -__le32 ret_val =0 ; - - ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL , - &svc_cmd,sizeof (svc_cmd), &ret_val, -sizeof (ret_val)); -if (ret) -return ret; -return le32_to_cpu (ret_val); -} + req.state =cpu_to_le32 (state); + req.id =cpu_to_le32 (id); -int __qcom_scm_hdcp_req (struct device *dev,struct qcom_scm_hdcp_req *req, -u32 req_cnt,u32 *resp) -{ -if (req_cnt >QCOM_SCM_HDCP_MAX_REQ_CNT ) -return -ERANGE ; + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_REMOTE_STATE , + &req,sizeof (req), &scm_ret,sizeof (scm_ret)); -return qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_HDCP_INVOKE , - req, req_cnt *sizeof (*req), resp,sizeof (*resp)); +return ret ? :le32_to_cpu (scm_ret); } -void __qcom_scm_init (void ) +int __qcom_scm_set_dload_mode (struct device *dev,bool enable) { +return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_DLOAD_MODE , + enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ,0 ); }bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral)
@@ -550,35 +545,37 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? :le32_to_cpu (out); } -int __qcom_scm_set_dload_mode (struct device *dev,bool enable) -{ -return qcom_scm_call_atomic2 (QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_DLOAD_MODE , - enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ,0 ); -} - -int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) +int __qcom_scm_io_readl (struct device *dev,phys_addr_t addr, +unsigned int *val) { -struct { -__le32 state; -__le32 id; - } req; -__le32 scm_ret =0 ;int ret; - req.state =cpu_to_le32 (state); - req.id =cpu_to_le32 (id); + ret =qcom_scm_call_atomic1 (QCOM_SCM_SVC_IO ,QCOM_SCM_IO_READ , addr); +if (ret >=0 ) + *val = ret; - ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_BOOT_SET_REMOTE_STATE , - &req,sizeof (req), &scm_ret,sizeof (scm_ret)); +return ret <0 ? ret :0 ; +} -return ret ? :le32_to_cpu (scm_ret); +int __qcom_scm_io_writel (struct device *dev,phys_addr_t addr,unsigned int val) +{ +return qcom_scm_call_atomic2 (QCOM_SCM_SVC_IO ,QCOM_SCM_IO_WRITE , + addr, val); } -int __qcom_scm_assign_mem (struct device *dev,phys_addr_t mem_region, -size_t mem_sz,phys_addr_t src,size_t src_sz, -phys_addr_t dest,size_t dest_sz) +int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) { -return -ENODEV ; +int ret; +__le32 svc_cmd =cpu_to_le32 ((svc_id <<10 ) | cmd_id); +__le32 ret_val =0 ; + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_INFO_IS_CALL_AVAIL , + &svc_cmd,sizeof (svc_cmd), &ret_val, +sizeof (ret_val)); +if (ret) +return ret; + +return le32_to_cpu (ret_val); } int __qcom_scm_restore_sec_cfg(struct device *dev, u32 device_id,
@@ -599,25 +596,28 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,return -ENODEV ; } -int __qcom_scm_io_readl (struct device *dev,phys_addr_t addr, -unsigned int *val) +int __qcom_scm_assign_mem (struct device *dev,phys_addr_t mem_region, +size_t mem_sz,phys_addr_t src,size_t src_sz, +phys_addr_t dest,size_t dest_sz) { -int ret; - - ret =qcom_scm_call_atomic1 (QCOM_SCM_SVC_IO ,QCOM_SCM_IO_READ , addr); -if (ret >=0 ) - *val = ret; - -return ret <0 ? ret :0 ; +return -ENODEV ; } -int __qcom_scm_io_writel (struct device *dev,phys_addr_t addr,unsigned int val) +int __qcom_scm_hdcp_req (struct device *dev,struct qcom_scm_hdcp_req *req, +u32 req_cnt,u32 *resp) { -return qcom_scm_call_atomic2 (QCOM_SCM_SVC_IO ,QCOM_SCM_IO_WRITE , - addr, val); +if (req_cnt >QCOM_SCM_HDCP_MAX_REQ_CNT ) +return -ERANGE ; + +return qcom_scm_call (dev,QCOM_SCM_SVC_HDCP ,QCOM_SCM_HDCP_INVOKE , + req, req_cnt *sizeof (*req), resp,sizeof (*resp)); }int __qcom_scm_qsmmu500_wait_safe_toggle (struct device *dev,bool enable) {return -ENODEV ; } + +void __qcom_scm_init (void ) +{ +}
drivers/firmware/qcom_scm-64.c +96 -96
259 lines not on this page · raw message
drivers/firmware/qcom_scm.c +112 -112
263 lines not on this page · raw message
drivers/firmware/qcom_scm.h +53 -54
132 lines not on this page · raw message
include/linux/qcom_scm.h +37 -35
105 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project