Restructure, improve target support for qcom_scm driver
v2 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-5 improve macro names, reorder macros/functions, and prune unused
macros/functions. No functional changes were introduced.
Patches 6-10 clears up the SCM abstraction in qcom_scm-64.
Patches 11-15 clears up the SCM abstraction in qcom_scm-32.
Patches 10 and 16-18 enable dynamically using the different calling conventions.
This series is based on https://lore.kernel.org/patchwork/cover/1129991/
Changes since v1:
- Renamed functions/variables per Vinod's suggestions
- Split v1 01/17 into v2 [01,02,03]/18 per Vinod's suggestion
- Fix suggestions by Bjorn in v1 09/18 (now v2 10/18)
- Refactor last 3 commits per Bjorn suggestions in v1 17/18 and v1 10/18
Changes since RFC:
- Fixed missing return values in qcom_scm_call_smccc
- Fixed order of arguments in qcom_scm_set_warm_boot_addr
- Adjusted logic of SMC convention to properly support older QCOM secure worlds
- Boot tested on IFC6410 based on linaro kernel tag:
debian-qcom-dragonboard410c-18.01 (which does basic verification of legacy SCM calls: at least warm_boot_addr, cold_boot_addr, and power_down)
Elliot Berman (18):
firmware: qcom_scm: Rename macros and structures
firmware: qcom_scm: Add funcnum IDs
firmware: qcom_scm-64: Make SMCCC macros less magical
firmware: qcom_scm: Apply consistent naming scheme to command IDs
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: Remove thin wrappers
firmware: qcom_scm: Dynamically support SMCCC and legacy conventions
firmware: qcom_scm: Order functions, definitions by service/command
drivers/firmware/Kconfig | 8 - drivers/firmware/Makefile | 5 +- drivers/firmware/qcom_scm-32.c | 621 -------------------------------- drivers/firmware/qcom_scm-64.c | 567 ----------------------------- drivers/firmware/qcom_scm-legacy.c | 233 ++++++++++++ drivers/firmware/qcom_scm-smccc.c | 141 ++++++++ drivers/firmware/qcom_scm.c | 708 +++++++++++++++++++++++++++++-------- drivers/firmware/qcom_scm.h | 166 +++++---- include/linux/qcom_scm.h | 99 +++--- 9 files changed, 1086 insertions(+), 1462 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-legacy.c create mode 100644 drivers/firmware/qcom_scm-smccc.c
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 1/18 firmware: qcom_scm: Rename macros and structures
Rename legacy-specific structures and macros with legacy prefix; rename smccc-specific structures and macros with smccc prefix.
--- drivers/firmware/qcom_scm-32.c | 70 ++++++++++++++++++++++-------------------- drivers/firmware/qcom_scm-64.c | 53 ++++++++++++++++---------------- 2 files changed, 64 insertions(+), 59 deletions(-)
drivers/firmware/qcom_scm-32.c +37 -33
@@ -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. */
@@ -39,22 +39,22 @@ static struct qcom_scm_entry qcom_scm_wb[] = {static DEFINE_MUTEX (qcom_scm_lock);/** -* struct qcom_scm_command - one SCM command buffer +* struct qcom_scm_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 qcom_scm_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 qcom_scm_legacy_response and +* | response header | legacy_command_to_response() +* ------------------- <--- legacy_get_response_buffer() * | response buffer | * ------------------- *
@@ -62,7 +62,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 qcom_scm_legacy_command {__le32 len;__le32 buf_offset;__le32 resp_hdr_offset;
@@ -71,52 +71,55 @@ struct qcom_scm_command { };/** -* struct qcom_scm_response - one SCM response buffer +* struct qcom_scm_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 +* qcom_scm_legacy_response * @is_complete: indicates if the command has finished processing */ -struct qcom_scm_response { +struct qcom_scm_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 qcom_scm_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 qcom_scm_legacy_response *legacy_command_to_response ( +const struct qcom_scm_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 qcom_scm_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 qcom_scm_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 +167,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 qcom_scm_legacy_command *cmd; +struct qcom_scm_legacy_response *rsp;size_t alloc_len =sizeof (*cmd) + cmd_len +sizeof (*rsp) + resp_len;dma_addr_t cmd_phys;
@@ -179,9 +182,9 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, cmd->id =cpu_to_le32 ((svc_id <<10 ) | 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 +193,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 +209,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,11 +218,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 | \ +#define LEGACY_CLASS_REGISTER (0x2 << 8) +#define LEGACY_MASK_IRQS BIT(5) +#define LEGACY_ATOMIC_ID (svc, cmd, n) \ + (((((svc) << 10)|((cmd) & 0x3ff)) << 12) | \ + LEGACY_CLASS_REGISTER | \ + LEGACY_MASK_IRQS | \ (n & 0xf))/**
@@ -235,7 +239,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_ID(svc, cmd, 1); register u32 r1 asm("r1") = (u32)&context_id; register u32 r2 asm("r2") = arg1;
@@ -268,7 +272,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_ID(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 -26
143 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
Re: [PATCH v2 01/18] firmware: qcom_scm: Rename macros and structures
Quoting Elliot Berman (2019-11-12 13:22:37)
Quoted 2 lines
Rename legacy-specific structures and macros with legacy prefix; rename smccc-specific structures and macros with smccc prefix.
Yes that's what's happening in the patch, but there isn't the most important part in the commit text here, which is _why_ this change is meaningful. Presumably the reason is to clearly separate the original SCM calling convention from the newer SCM calling conventions.
Quoted 13 lines
Signed-off-by Elliot Berman <[email protected]>--- drivers/firmware/qcom_scm-32.c | 70 ++++++++++++++++++++++-------------------- drivers/firmware/qcom_scm-64.c | 53 ++++++++++++++++---------------- 2 files changed, 64 insertions(+), 59 deletions(-)drivers/firmware/qcom_scm-32.c +0
-0@@ -39,22 +39,22 @@ static struct qcom_scm_entry qcom_scm_wb[] = {static DEFINE_MUTEX (qcom_scm_lock);
drivers/firmware/qcom_scm-32.c static struct qcom_scm_entry qcom_scm_wb[] = { · line 47
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +2
-2/** -* struct qcom_scm_command - one SCM command buffer +* struct qcom_scm_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()
I'd prefer to keep qcom_ or at least scm_ somewhere in the name. Just plain legacy_ is too generic.
Quoted 19 lines
drivers/firmware/qcom_scm-32.c +5
-5* * An SCM command is laid out in memory as follows: * -* ------------------- <--- struct qcom_scm_command +* ------------------- <--- struct qcom_scm_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 qcom_scm_legacy_response and +* | response header | legacy_command_to_response() +* ------------------- <--- legacy_get_response_buffer() * | response buffer | * ------------------- *
drivers/firmware/qcom_scm-32.c static DEFINE_MUTEX(qcom_scm_lock); · line 62
Quoted 1 line
drivers/firmware/qcom_scm-32.c +0
-0@@ -62,7 +62,7 @@ static DEFINE_MUTEX(qcom_scm_lock);* you should always use the appropriate qcom_scm_get_*_buffer() routines
Shouldn't this comment be updated too to say "legacy"?
drivers/firmware/qcom_scm-32.c static DEFINE_MUTEX(qcom_scm_lock); · line 65
Quoted 4 lines
drivers/firmware/qcom_scm-32.c +1
-1* to access the buffers in a safe manner. */ -struct qcom_scm_command { +struct qcom_scm_legacy_command {
Like here, it's called qcom_scm_legacy_<foo> so maybe that should be how it works.
Quoted 94 lines
drivers/firmware/qcom_scm-32.c +18
-15__le32 len;__le32 buf_offset;__le32 resp_hdr_offset;@@ -71,52 +71,55 @@ struct qcom_scm_command { };/** -* struct qcom_scm_response - one SCM response buffer +* struct qcom_scm_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 +* qcom_scm_legacy_response * @is_complete: indicates if the command has finished processing */ -struct qcom_scm_response { +struct qcom_scm_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 qcom_scm_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 qcom_scm_legacy_response *legacy_command_to_response ( +const struct qcom_scm_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 qcom_scm_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 qcom_scm_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 +167,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 qcom_scm_legacy_command *cmd; +struct qcom_scm_legacy_response *rsp;size_t alloc_len =sizeof (*cmd) + cmd_len +sizeof (*rsp) + resp_len;dma_addr_t cmd_phys;@@ -179,9 +182,9 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, cmd->id =cpu_to_le32 ((svc_id <<10 ) | 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)) {
drivers/firmware/qcom_scm-32.c static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, · line 196
Quoted 5 lines
drivers/firmware/qcom_scm-32.c +1
-1@@ -190,7 +193,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);
What is this change about? Is it confusing to have a function called 'smc'? Please mention why this should change in the commit text.
Quoted 40 lines
drivers/firmware/qcom_scm-32.c +8
-7if (ret <0 ) ret =qcom_scm_remap_error (ret);mutex_unlock (&qcom_scm_lock);@@ -206,7 +209,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,11 +218,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 | \ +#define LEGACY_CLASS_REGISTER (0x2 << 8) +#define LEGACY_MASK_IRQS BIT(5) +#define LEGACY_ATOMIC_ID (svc, cmd, n) \ + (((((svc) << 10)|((cmd) & 0x3ff)) << 12) | \ + LEGACY_CLASS_REGISTER | \ + LEGACY_MASK_IRQS | \ (n & 0xf))/** @@ -235,7 +239,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_ID(svc, cmd, 1); register u32 r1 asm("r1") = (u32)&context_id; register u32 r2 asm("r2") = arg1;
drivers/firmware/qcom_scm-32.c static s32 qcom_scm_call_atomic2(u32 svc, u32 cmd, u32 arg1, u32 arg2) · line 278
Quoted 8 lines
drivers/firmware/qcom_scm-32.c +1
-1@@ -268,7 +272,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_ID(svc, cmd, 2); register u32 r1 asm("r1") = (u32)&context_id; register u32 r2 asm("r2") = arg1; register u32 r3 asm("r3") = arg2;
Is this hunk really necessary? The defines are local to the file.
drivers/firmware/qcom_scm-64.c line 17
Quoted 10 lines
drivers/firmware/qcom_scm-64.c +1
-1@@ -14,7 +14,7 @@#include "qcom_scm.h" -#define QCOM_SCM_FNID (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF)) +#define SMCCC_FUNCNUM (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF))
Is this generic? Maybe it should go into the SMCCC file then if it isn't qcom specific? Otherwise, please leave QCOM in the name.
Quoted 9 lines
drivers/firmware/qcom_scm-64.c +0
-2#define MAX_QCOM_SCM_ARGS 10#define MAX_QCOM_SCM_RETS 3@@ -58,11 +58,11 @@ static DEFINE_MUTEX(qcom_scm_lock);#define QCOM_SCM_EBUSY_WAIT_MS 30#define QCOM_SCM_EBUSY_MAX_RETRY 20 -#define N_EXT_QCOM_SCM_ARGS 7 -#define FIRST_EXT_ARG_IDX 3
drivers/firmware/qcom_scm-64.c static DEFINE_MUTEX(qcom_scm_lock); · line 68
Quoted 10 lines
drivers/firmware/qcom_scm-64.c +4
-2-#define N_REGISTER_ARGS (MAX_QCOM_SCM_ARGS - N_EXT_QCOM_SCM_ARGS + 1) +#define SMCCC_N_EXT_ARGS 7 +#define SMCCC_FIRST_EXT_IDX 3 +#define SMCCC_N_REG_ARGS (MAX_QCOM_SCM_ARGS - SMCCC_N_EXT_ARGS + 1) -static void __qcom_scm_call_do (const struct qcom_scm_desc *desc, +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) {
From here....
Quoted 114 lines
drivers/firmware/qcom_scm-64.c +20
-19@@ -85,22 +85,23 @@ static void __qcom_scm_call_do(const struct qcom_scm_desc *desc, }while (res->a0 ==QCOM_SCM_INTERRUPTED ); } -static void qcom_scm_call_do (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) {int retry_count =0 ;if (atomic) { -__qcom_scm_call_do (desc, res, fn_id, x5,ARM_SMCCC_FAST_CALL ); +__qcom_scm_call_do_quirk (desc, res, fn_id, x5, +ARM_SMCCC_FAST_CALL );return ; } do { mutex_lock(&qcom_scm_lock); - __qcom_scm_call_do(desc, res, fn_id, x5, - ARM_SMCCC_STD_CALL); + __qcom_scm_call_do_quirk(desc, res, fn_id, x5, + ARM_SMCCC_STD_CALL); mutex_unlock(&qcom_scm_lock);@@ -112,21 +113,21 @@ static void qcom_scm_call_do(const struct qcom_scm_desc *desc, }while (res->a0 ==QCOM_SCM_V2_EBUSY ); } -static int ___qcom_scm_call (struct device *dev,u32 svc_id,u32 cmd_id, -const struct qcom_scm_desc *desc, -struct arm_smccc_res *res,bool atomic) +static int ___qcom_scm_call_smccc (struct device *dev,u32 svc_id,u32 cmd_id, +const struct qcom_scm_desc *desc, +struct arm_smccc_res *res,bool atomic) {int arglen = desc->arginfo &0xf ;int i; -u32 fn_id =QCOM_SCM_FNID (svc_id, cmd_id); -u64 x5 = desc->args[FIRST_EXT_ARG_IDX ]; +u32 fn_id =SMCCC_FUNCNUM (svc_id, cmd_id); +u64 x5 = desc->args[SMCCC_FIRST_EXT_IDX ];dma_addr_t args_phys =0 ;void *args_virt =NULL ;size_t alloc_len;gfp_t flag = atomic ?GFP_ATOMIC :GFP_KERNEL ; -if (unlikely (arglen >N_REGISTER_ARGS )) { - alloc_len =N_EXT_QCOM_SCM_ARGS *sizeof (u64); +if (unlikely (arglen >SMCCC_N_REG_ARGS )) { + alloc_len =SMCCC_N_EXT_ARGS *sizeof (u64); args_virt =kzalloc (PAGE_ALIGN (alloc_len), flag);if (!args_virt)@@ -135,15 +136,15 @@ static int ___qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id,if (qcom_smccc_convention ==ARM_SMCCC_SMC_32 ) {__le32 *args = args_virt; -for (i =0 ; i <N_EXT_QCOM_SCM_ARGS ; i++) +for (i =0 ; i <SMCCC_N_EXT_ARGS ; i++) args[i] =cpu_to_le32 (desc->args[i + -FIRST_EXT_ARG_IDX ]); +SMCCC_FIRST_EXT_IDX ]); }else {__le64 *args = args_virt; -for (i =0 ; i <N_EXT_QCOM_SCM_ARGS ; i++) +for (i =0 ; i <SMCCC_N_EXT_ARGS ; i++) args[i] =cpu_to_le64 (desc->args[i + -FIRST_EXT_ARG_IDX ]); +SMCCC_FIRST_EXT_IDX ]); } args_phys = dma_map_single(dev, args_virt, alloc_len,@@ -157,7 +158,7 @@ static int ___qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, x5 = args_phys; } -qcom_scm_call_do (desc, res, fn_id, x5, atomic); +qcom_scm_call_do_smccc (desc, res, fn_id, x5, atomic);if (args_virt) {dma_unmap_single (dev, args_phys, alloc_len,DMA_TO_DEVICE );@@ -185,7 +186,7 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, struct arm_smccc_res *res) {might_sleep (); -return ___qcom_scm_call (dev, svc_id, cmd_id, desc, res, false); +return ___qcom_scm_call_smccc (dev, svc_id, cmd_id, desc, res, false); }/** @@ -203,7 +204,7 @@ static int qcom_scm_call_atomic(struct device *dev, u32 svc_id, u32 cmd_id,const struct qcom_scm_desc *desc, struct arm_smccc_res *res) { - return ___qcom_scm_call(dev, svc_id, cmd_id, desc, res, true); + return ___qcom_scm_call_smccc(dev, svc_id, cmd_id, desc, res, true); }/** @@ -253,7 +254,7 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id)struct arm_smccc_res res; desc.arginfo =QCOM_SCM_ARGS (1 ); - desc.args[0 ] =QCOM_SCM_FNID (svc_id, 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,
drivers/firmware/qcom_scm-64.c void __qcom_scm_init(void) · line 302
Quoted 8 lines
drivers/firmware/qcom_scm-64.c +1
-1@@ -295,7 +296,7 @@ void __qcom_scm_init(void) {u64 cmd;struct arm_smccc_res res; -u32 function =QCOM_SCM_FNID (QCOM_SCM_SVC_INFO ,QCOM_IS_CALL_AVAIL_CMD ); +u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO ,QCOM_IS_CALL_AVAIL_CMD );/* First try a SMC64 call */ cmd = ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64,
... to here I don't understand why any of it needs to change. It looks like a bunch of churn and it conflates qcom SCM calls with SMCCC which is not desirable. Those two concepts are different.
Re: [PATCH v2 01/18] firmware: qcom_scm: Rename macros and structures
Quoted 3 lines · Stephen Boyd
... to here I don't understand why any of it needs to change. It looks like a bunch of churn and it conflates qcom SCM calls with SMCCC which is not desirable. Those two concepts are different.
I can see the confusion. The goal with this patch is to make it more clear which macros and structures are for SCM interface from those which deal with the implementation of how an SCM call is implemented with the smc instruction. It's not presently clear that struct qcom_scm_response (for instance) is only relevant in the context of legacy convention.
I choose the name "legacy" since only older firmwares use it and having "scm_buffer_get_command_buffer" seems even more confusing to me! "SMCCC" was chosen for lack of a better name.
Additionally, the concern with having qcom_scm_ prefix on these functions (especially legacy_get_*_buffer()) is you get long function names which didn't seem desirable. If the long names are preferable, I can update series with the longer form of the names.
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 01/18] firmware: qcom_scm: Rename macros and structures
Quoting [email protected] (2019-11-15 17:19:13)
Quoted 19 lines · Stephen Boyd
Quoted 3 lines
... to here I don't understand why any of it needs to change. It looks like a bunch of churn and it conflates qcom SCM calls with SMCCC which is not desirable. Those two concepts are different.
I can see the confusion. The goal with this patch is to make it more clear which
macros and structures are for SCM interface from those which deal with the
implementation of how an SCM call is implemented with the smc instruction. It's
not presently clear that structqcom_scm_response(for instance) is only relevant in the context of legacy convention.I choose the name "legacy" since only older firmwares use it and having "
scm_buffer_get_command_buffer" seems even more confusing to me! "SMCCC" was
chosen for lack of a better name.
Quoted 8 lines
Additionally, the concern with having
qcom_scm_prefix on these functions
(especially legacy_get_*_buffer()) is you get long function names which didn't
seem desirable. If the long names are preferable, I can update series with the
longer form of the names.
This is the hardest problem in computer science. Figuring out a name. ;-)
Maybe call it scm_buffer_*? Because it _is_ scm communication with shared buffers? The newer calling convention passes arguments in registers, but the original calling convention passed a buffer around from non-secure to secure world and then back again and had a embryonic register based calling convention. That buffer passing still sort of happens with the new style but it isn't done unless the register count is larger than 5 or so and the return buffer isn't unbounded in size like it was done. It also sort of follows the ARM SMC Calling Convection spec now.
PATCH v2 2/18 firmware: qcom_scm: Add funcnum IDs
In reply to Elliot BermanAdd LEGACY_FUNCNUM to qcom_scm-32.c and move SMCCC_FUNCNUM closer to other smccc-specific macros.
--- drivers/firmware/qcom_scm-32.c | 8 +++++--- drivers/firmware/qcom_scm-64.c | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/firmware/qcom_scm-32.c +5 -3
@@ -38,6 +38,8 @@ 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_legacy_command - one SCM command buffer * @len: total available memory for command and response
@@ -180,7 +182,7 @@ 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 (legacy_get_command_buffer (cmd), cmd_buf, cmd_len);
@@ -221,7 +223,7 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id,#define LEGACY_CLASS_REGISTER (0x2 << 8)#define LEGACY_MASK_IRQS BIT(5)#define LEGACY_ATOMIC_ID (svc, cmd, n) \ - (((((svc) << 10)|((cmd) & 0x3ff)) << 12) | \ + ((LEGACY_FUNCNUM(svc, cmd) << 12) | \ LEGACY_CLASS_REGISTER | \ LEGACY_MASK_IRQS | \ (n & 0xf))
@@ -424,7 +426,7 @@ void __qcom_scm_cpu_power_down(u32 flags)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 svc_cmd =cpu_to_le32 (LEGACY_FUNCNUM (svc_id, cmd_id));__le32 ret_val =0 ; ret = qcom_scm_call(dev, QCOM_SCM_SVC_INFO, QCOM_IS_CALL_AVAIL_CMD,
drivers/firmware/qcom_scm-64.c +1 -2
@@ -14,8 +14,6 @@#include "qcom_scm.h" -#define SMCCC_FUNCNUM (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF)) -#define MAX_QCOM_SCM_ARGS 10#define MAX_QCOM_SCM_RETS 3
@@ -58,6 +56,7 @@ static DEFINE_MUTEX(qcom_scm_lock);#define QCOM_SCM_EBUSY_WAIT_MS 30#define QCOM_SCM_EBUSY_MAX_RETRY 20 +#define SMCCC_FUNCNUM (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF))#define SMCCC_N_EXT_ARGS 7#define SMCCC_FIRST_EXT_IDX 3#define SMCCC_N_REG_ARGS (MAX_QCOM_SCM_ARGS - SMCCC_N_EXT_ARGS + 1)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 02/18] firmware: qcom_scm: Add funcnum IDs
Quoting Elliot Berman (2019-11-12 13:22:38)
Quoted 14 lines
Add
LEGACY_FUNCNUMtoqcom_scm-32.cand moveSMCCC_FUNCNUMcloser to other smccc-specific macros.Signed-off-by Elliot Berman <[email protected]>--- drivers/firmware/qcom_scm-32.c | 8 +++++--- drivers/firmware/qcom_scm-64.c | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-)drivers/firmware/qcom_scm-32.c +0
-0
drivers/firmware/qcom_scm-32.c static struct qcom_scm_entry qcom_scm_wb[] = { · line 41
Quoted 4 lines
drivers/firmware/qcom_scm-32.c +1
-0@@ -38,6 +38,8 @@ static struct qcom_scm_entry qcom_scm_wb[] = {static DEFINE_MUTEX (qcom_scm_lock); +#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff))
Same name comment here. Otherwise
PATCH v2 3/18 firmware: qcom_scm-64: Make SMCCC macros less magical
In reply to Elliot BermanImprove understandability of SMCCC macros as they are all functions of how many arguments can be shoved in registers and how many SCM arguments are supported.
--- drivers/firmware/qcom_scm-64.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/firmware/qcom_scm-64.c +3 -3
@@ -57,9 +57,9 @@ static DEFINE_MUTEX(qcom_scm_lock);#define QCOM_SCM_EBUSY_MAX_RETRY 20#define SMCCC_FUNCNUM (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF)) -#define SMCCC_N_EXT_ARGS 7 -#define SMCCC_FIRST_EXT_IDX 3 -#define SMCCC_N_REG_ARGS (MAX_QCOM_SCM_ARGS - SMCCC_N_EXT_ARGS + 1) +#define SMCCC_N_REG_ARGS 4 +#define SMCCC_FIRST_EXT_IDX (SMCCC_N_REG_ARGS - 1) +#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,
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 03/18] firmware: qcom_scm-64: Make SMCCC macros less magical
Quoting Elliot Berman (2019-11-12 13:22:39)
Quoted 3 lines
Improve understandability of SMCCC macros as they are all functions of how many arguments can be shoved in registers and how many SCM arguments are supported.
By reversing the logic to build up these defines based on the number of register arguments instead of subtract them out of number of total arguments? Might be worth mentioning that.
Quoted 3 lines
Signed-off-by Elliot Berman <[email protected]>---
Quoted 19 lines
drivers/firmware/qcom_scm-64.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/firmware/qcom_scm-64.c +3
-3@@ -57,9 +57,9 @@ static DEFINE_MUTEX(qcom_scm_lock);#define QCOM_SCM_EBUSY_MAX_RETRY 20#define SMCCC_FUNCNUM (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF)) -#define SMCCC_N_EXT_ARGS 7 -#define SMCCC_FIRST_EXT_IDX 3 -#define SMCCC_N_REG_ARGS (MAX_QCOM_SCM_ARGS - SMCCC_N_EXT_ARGS + 1) +#define SMCCC_N_REG_ARGS 4 +#define SMCCC_FIRST_EXT_IDX (SMCCC_N_REG_ARGS - 1) +#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,
PATCH v2 4/18 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 | 13 +++++-------- drivers/firmware/qcom_scm.h | 43 +++++++++++++++++++----------------------- 4 files changed, 57 insertions(+), 65 deletions(-)
drivers/firmware/qcom_scm-32.c +14 -14
@@ -360,7 +360,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)); }
@@ -399,7 +399,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)
@@ -419,7 +419,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 ); }
@@ -429,7 +429,7 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id)__le32 svc_cmd =cpu_to_le32 (LEGACY_FUNCNUM (svc_id, 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_SCM_INFO_IS_CALL_AVAIL , &svc_cmd,sizeof (svc_cmd), &ret_val,sizeof (ret_val));if (ret)
@@ -444,7 +444,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)); }
@@ -460,7 +460,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));
@@ -481,7 +481,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));
@@ -504,7 +504,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));
@@ -519,7 +519,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));
@@ -534,7 +534,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));
@@ -547,7 +547,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));
@@ -556,8 +556,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)
@@ -572,7 +572,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_SCM_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_SCM_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_SCM_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 +5 -8
@@ -1,8 +1,5 @@// SPDX-License-Identifier: GPL-2.0-only -/* -* 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>
@@ -142,7 +139,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 +180,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 +367,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 +19 -24
91 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
Re: [PATCH v2 04/18] firmware: qcom_scm: Apply consistent naming scheme to command IDs
Quoting Elliot Berman (2019-11-12 13:22:40)
Quoted 9 lines
Create 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, andQCOM_SCM_BOOT_ADDR_MC.Reviewed-by Bjorn Andersson <[email protected]>Reviewed-by Vinod Koul <[email protected]>Signed-off-by Elliot Berman <[email protected]>---
Would be nice to state that the object file is the same before and after this patch is applied, confirmed by compiling the file before and after and diffing the output.
PATCH v2 5/18 firmware: qcom_scm: Remove unused qcom_scm_get_version
In reply to Elliot BermanRemove 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
@@ -295,42 +295,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
@@ -53,7 +53,6 @@ extern int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz,const struct qcom_scm_vmperm *newvm, unsigned int dest_cnt);extern void qcom_scm_cpu_power_down (u32 flags); -extern u32 qcom_scm_get_version (void );extern int qcom_scm_set_remote_state (u32 state,u32 id);extern int qcom_scm_restore_sec_cfg (u32 device_id,u32 spare);extern int qcom_scm_iommu_secure_ptbl_size (u32 spare,size_t *size);
@@ -92,7 +91,6 @@ static inline int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz,const struct qcom_scm_vmperm *newvm, unsigned int dest_cnt) { return -ENODEV; }static inline void qcom_scm_cpu_power_down (u32 flags) {} -static inline u32 qcom_scm_get_version (void ) {return 0 ; }static inline u32 qcom_scm_set_remote_state (u32 state,u32 id) {return -ENODEV ; }static inline int qcom_scm_restore_sec_cfg (u32 device_id,u32 spare) {return -ENODEV ; }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 05/18] firmware: qcom_scm: Remove unused qcom_scm_get_version
Quoting Elliot Berman (2019-11-12 13:22:41)
Quoted 6 lines
Remove unused
qcom_scm_get_version.Reviewed-by Bjorn Andersson <[email protected]>Reviewed-by Vinod Koul <[email protected]>Signed-off-by Elliot Berman <[email protected]>---
PATCH v2 6/18 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 | 192 +++++++++++++++++++++++++---------------- 1 file changed, 120 insertions(+), 72 deletions(-)
drivers/firmware/qcom_scm-64.c +120 -72
@@ -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,13 +114,12 @@ 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) {int arglen = desc->arginfo &0xf ;int i; -u32 fn_id =SMCCC_FUNCNUM (svc_id, cmd_id);u64 x5 = desc->args[SMCCC_FIRST_EXT_IDX ];dma_addr_t args_phys =0 ;void *args_virt =NULL ;
@@ -157,7 +158,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 +181,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 +199,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); }/**
@@ -249,15 +249,18 @@ void __qcom_scm_cpu_power_down(u32 flags)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_SCM_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_SCM_INFO_IS_CALL_AVAIL , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -266,7 +269,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 )
@@ -284,8 +291,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;
@@ -313,15 +319,17 @@ void __qcom_scm_init(void)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; }
@@ -330,15 +338,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; }
@@ -347,7 +358,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;
@@ -355,8 +370,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; }
@@ -364,15 +378,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; }
@@ -380,21 +396,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;
@@ -402,15 +425,18 @@ 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; }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;
@@ -418,8 +444,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_BOOT_SET_REMOTE_STATE , - &desc, &res); + ret =qcom_scm_call (dev, &desc, &res);return ret ? : res.a1; }
@@ -429,7 +454,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_SCM_MP_ASSIGN , + .owner =ARM_SMCCC_OWNER_SIP , + };struct arm_smccc_res res; desc.args[0 ] = mem_region;
@@ -444,16 +473,18 @@ 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_SCM_MP_ASSIGN , - &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;
@@ -461,8 +492,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; }
@@ -470,15 +500,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;
@@ -489,7 +522,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;
@@ -499,8 +536,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 )
@@ -511,29 +547,35 @@ int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,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); }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;
@@ -542,26 +584,32 @@ 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_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); }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 06/18] firmware: qcom_scm-64: Move svc/cmd/owner into qcom_scm_desc
Quoting Elliot Berman (2019-11-12 13:22:42)
drivers/firmware/qcom_scm-64.c enum qcom_scm_arg_types { · line 53
Quoted 13 lines
drivers/firmware/qcom_scm-64.c +3
-0@@ -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;
Owner is always the same. Why move it to the qcom_scm_desc structure? I can understand svc and cmd but there's no justification for this struct member.
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +0
-0};static u64 qcom_smccc_convention =-1 ;
[...]
Quoted 5 lines
drivers/firmware/qcom_scm-64.c +0
-1@@ -542,26 +584,32 @@ 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 };
drivers/firmware/qcom_scm-64.c int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, · line 596
Quoted 10 lines
drivers/firmware/qcom_scm-64.c +5
-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 );
The style is weird here. Half of the struct is initialized during declaration and the arguments are set here with individual statements. Can we have one way or the other and not both?
Quoted 6 lines
drivers/firmware/qcom_scm-64.c +1
-2-return qcom_scm_call (dev,QCOM_SCM_SVC_IO ,QCOM_SCM_IO_WRITE , - &desc, &res); +return qcom_scm_call (dev, &desc, &res); }
PATCH v2 7/18 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 | 105 ++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 60 deletions(-)
drivers/firmware/qcom_scm-64.c +45 -60
@@ -50,6 +50,7 @@ struct qcom_scm_desc {u32 cmd;u32 arginfo;u64 args[MAX_QCOM_SCM_ARGS ]; +u64 result[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;
@@ -125,6 +125,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);
@@ -158,15 +159,19 @@ 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); + desc->result[0 ] = res.a1; + desc->result[1 ] = res.a2; + desc->result[2 ] = res.a3; + +if (res.a0 <0 ) +return qcom_scm_remap_error (res.a0);return 0 ; }
@@ -181,11 +186,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); }/**
@@ -199,11 +203,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,15 +256,14 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id) .cmd = QCOM_SCM_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.result[0 ]; } int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req,
@@ -274,7 +275,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 ;
@@ -291,8 +291,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.result[0 ];return ret; }
@@ -324,14 +324,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.result[0 ]; } int __qcom_scm_pas_init_image(struct device *dev, u32 peripheral,
@@ -343,15 +342,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.result[0 ]; } int __qcom_scm_pas_mem_setup(struct device *dev, u32 peripheral,
@@ -363,16 +361,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.result[0 ]; }int __qcom_scm_pas_auth_and_reset (struct device *dev,u32 peripheral)
@@ -383,14 +380,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.result[0 ]; }int __qcom_scm_pas_shutdown (struct device *dev,u32 peripheral)
@@ -401,14 +397,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.result[0 ]; }int __qcom_scm_pas_mss_reset (struct device *dev,bool reset)
@@ -418,16 +413,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.result[0 ]; }int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id)
@@ -437,16 +431,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.result[0 ]; } int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region,
@@ -459,7 +452,6 @@ int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region, .cmd = QCOM_SCM_MP_ASSIGN, .owner = ARM_SMCCC_OWNER_SIP, }; -struct arm_smccc_res res; desc.args[0 ] = mem_region; desc.args[1 ] = mem_sz;
@@ -473,9 +465,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.result[0 ]; }int __qcom_scm_restore_sec_cfg (struct device *dev,u32 device_id,u32 spare)
@@ -485,16 +477,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.result[0 ]; } int __qcom_scm_iommu_secure_ptbl_size(struct device *dev, u32 spare,
@@ -505,18 +496,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.result[0 ]; -return ret ? : res.a2; +return ret ? : desc.result[1 ]; } int __qcom_scm_iommu_secure_ptbl_init(struct device *dev, u64 addr, u32 size,
@@ -527,7 +517,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;
@@ -536,7 +525,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 )
@@ -552,13 +541,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); } int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr,
@@ -569,15 +557,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.result[0 ];return ret <0 ? ret :0 ; }
@@ -589,13 +576,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_qsmmu500_wait_safe_toggle (struct device *dev,bool en)
@@ -605,11 +591,10 @@ 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); }
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 07/18] firmware: qcom_scm-64: Add SCM results to descriptor
Quoting Elliot Berman (2019-11-12 13:22:43)
Quoted 4 lines
Remove knowledge of
arm_smccc_resstruct from client wrappers so that client wrappers only work QCOM SCM data structures. SCM calls may have up to 3 arguments, soqcom_scm_call_smcccis responsible now for filling those 3 arguments accordingly.
Why? Now we can't mark the descriptor 'const'. That looks like a step backwards from before where we had an input structure 'desc' and an output structure 'res'. If anything, we should make the output structure 'res' optional in cases where nobody cares to look at the result.
PATCH v2 8/18 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) {
@@ -159,7 +134,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
Re: [PATCH v2 08/18] firmware: qcom_scm-64: Remove qcom_scm_call_do_smccc
Quoting Elliot Berman (2019-11-12 13:22:44)
Quoted 5 lines
Remove thin wrapper to
qcom_scm_call_do_smcccbecause it doesn't do enough of anything interesting to dedicate its own function.Signed-off-by Elliot Berman <[email protected]>---
I don't see the need for this patch. The function was split out in a patch earlier this year because it was too nested in the calling function.
Quoted 8 lines
drivers/firmware/qcom_scm-64.c | 46 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-)drivers/firmware/qcom_scm-64.c +0
-0
drivers/firmware/qcom_scm-64.c static void __qcom_scm_call_do_quirk(const struct qcom_scm_desc *desc, · line 96
Quoted 7 lines
drivers/firmware/qcom_scm-64.c +0
-4@@ -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 ;
Maybe this can be unsigned given that it's a counter that only increments.
Quoted 24 lines
drivers/firmware/qcom_scm-64.c +0
-21- -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) {
PATCH v2 9/18 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 | 45 +++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-)
drivers/firmware/qcom_scm-64.c +27 -18
@@ -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,24 @@ static DEFINE_MUTEX(qcom_scm_lock);#define SMCCC_N_REG_ARGS 4#define SMCCC_FIRST_EXT_IDX (SMCCC_N_REG_ARGS - 1)#define SMCCC_N_EXT_ARGS (MAX_QCOM_SCM_ARGS - SMCCC_N_REG_ARGS + 1) +#define SMCCC_FIRST_REG_IDX 2 +#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,12 +95,22 @@ static int ___qcom_scm_call_smccc(struct device *dev, {int arglen = desc->arginfo &0xf ;int i; -u64 x5 = desc->args[SMCCC_FIRST_EXT_IDX ];dma_addr_t args_phys =0 ;void *args_virt =NULL ;size_t alloc_len;gfp_t flag = atomic ?GFP_ATOMIC :GFP_KERNEL ; +u32 smccc_call_type = atomic ?ARM_SMCCC_FAST_CALL :ARM_SMCCC_STD_CALL ;struct arm_smccc_res res; +struct arm_smccc_args smc = {0 }; + + smc.a[0 ] =ARM_SMCCC_CALL_VAL ( + smccc_call_type, + 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);
@@ -131,19 +141,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
Re: [PATCH v2 09/18] firmware: qcom_scm-64: Move SMC register filling to qcom_scm_call_smccc
Quoting Elliot Berman (2019-11-12 13:22:45)
drivers/firmware/qcom_scm-64.c struct qcom_scm_desc { · line 58
Quoted 10 lines
drivers/firmware/qcom_scm-64.c +2
-0@@ -54,6 +54,10 @@ struct qcom_scm_desc {u32 owner; }; +struct arm_smccc_args { +unsigned long a[8 ];
Please call it 'args', not just 'a'.
Quoted 42 lines
drivers/firmware/qcom_scm-64.c +15
-3+}; +static u64 qcom_smccc_convention =-1 ;static DEFINE_MUTEX (qcom_scm_lock);@@ -95,12 +95,22 @@ static int ___qcom_scm_call_smccc(struct device *dev, {int arglen = desc->arginfo &0xf ;int i; -u64 x5 = desc->args[SMCCC_FIRST_EXT_IDX ];dma_addr_t args_phys =0 ;void *args_virt =NULL ;size_t alloc_len;gfp_t flag = atomic ?GFP_ATOMIC :GFP_KERNEL ; +u32 smccc_call_type = atomic ?ARM_SMCCC_FAST_CALL :ARM_SMCCC_STD_CALL ;struct arm_smccc_res res; +struct arm_smccc_args smc = {0 }; + + smc.a[0 ] =ARM_SMCCC_CALL_VAL ( + smccc_call_type, + 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);@@ -131,19 +141,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 ;
drivers/firmware/qcom_scm-64.c static int ___qcom_scm_call_smccc(struct device *dev, · line 158
Quoted 10 lines
drivers/firmware/qcom_scm-64.c +1
-2do { 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);
Maybe we need to restructure this whole function to be a few steps
setup_and_map_args() do_call() unmap_args() remap_error()
And pass some set of args to those functions. That would probably provide clarity to this monstrously large function.
PATCH v2 10/18 firmware: qcom_scm-64: Improve SMC convention detection
In reply to Elliot BermanImprove the calling convention detection to use __qcom_scm_is_call_available() and not blindly assume 32-bit mode if the checks fails.
--- drivers/firmware/qcom_scm-64.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/firmware/qcom_scm-64.c +14 -15
@@ -302,21 +302,20 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req,void __qcom_scm_init (void ) { -u64 cmd; -struct arm_smccc_res res; -u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO ,QCOM_SCM_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_smccc_convention =ARM_SMCCC_SMC_64 ; +if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO , +QCOM_SCM_INFO_IS_CALL_AVAIL ) ==1 ) + goto out; + + qcom_smccc_convention =ARM_SMCCC_SMC_32 ; +if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO , +QCOM_SCM_INFO_IS_CALL_AVAIL ) ==1 ) + goto out; + + qcom_smccc_convention =-1 ; +BUG (); +out: +pr_debug ("QCOM SCM SMC Convention: %llu\n" , qcom_smccc_convention); }bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 10/18] firmware: qcom_scm-64: Improve SMC convention detection
Quoting Elliot Berman (2019-11-12 13:22:46)
Quoted 16 lines
drivers/firmware/qcom_scm-64.c +0
-8@@ -302,21 +302,20 @@ int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req,void __qcom_scm_init (void ) { -u64 cmd; -struct arm_smccc_res res; -u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO ,QCOM_SCM_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); -
drivers/firmware/qcom_scm-64.c int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, · line 307
Quoted 10 lines
drivers/firmware/qcom_scm-64.c +3
-7-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_smccc_convention =ARM_SMCCC_SMC_64 ; +if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO , +QCOM_SCM_INFO_IS_CALL_AVAIL ) ==1 )
Is this asking if the "is call available function" is available by using the is call available function? That is recursive. Isn't that why we make a manually open coded SMC call to see if it works? If this isn't going to work we may want to just have a property in DT that tells us what to do.
drivers/firmware/qcom_scm-64.c int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, · line 316
Quoted 9 lines
drivers/firmware/qcom_scm-64.c +9
-0+ goto out; + + qcom_smccc_convention =ARM_SMCCC_SMC_32 ; +if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO , +QCOM_SCM_INFO_IS_CALL_AVAIL ) ==1 ) + goto out; + + qcom_smccc_convention =-1 ; +BUG ();
This BUG() is new and not mentioned in the commit text. Why can't we just start failing all scm calls if we can't detect the calling convention?
drivers/firmware/qcom_scm-64.c int __qcom_scm_hdcp_req(struct device *dev, struct qcom_scm_hdcp_req *req, · line 318
Quoted 2 lines
drivers/firmware/qcom_scm-64.c +2
-0+out: +pr_debug ("QCOM SCM SMC Convention: %llu\n" , qcom_smccc_convention);
Maybe pr_info() is more appropriate. PSCI currently prints out the version info so maybe printing something like "QCOM SCM SMC_64 calling convention" will be useful for early debugging.
Re: [PATCH v2 10/18] firmware: qcom_scm-64: Improve SMC convention detection
Quoted 29 lines · Stephen Boyd
Quoting Elliot Berman (2019-11-12 13:22:46)
Quoted 28 lines
drivers/firmware/qcom_scm-64.c +1
-15@@ -302,21 +302,20 @@ int __qcom_scm_hdcp_req(struct device *dev,struct qcom_scm_hdcp_req *req, void __qcom_scm_init(void) { - u64 cmd; -struct arm_smccc_res res; -u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO , QCOM_SCM_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_smccc_convention =ARM_SMCCC_SMC_64 ;
Quoted 8 lines
drivers/firmware/qcom_scm-64.c
Quoted 2 lines
drivers/firmware/qcom_scm-64.c +2
-0+if (__qcom_scm_is_call_available (NULL ,QCOM_SCM_SVC_INFO , +QCOM_SCM_INFO_IS_CALL_AVAIL ) ==1 )Is this asking if the "is call available function" is available by using the is call available function? That is recursive. Isn't that why we make a manually open coded SMC call to see if it works? If this isn't going to work we may want to just have a property in DT that tells us what to do.
Yes. The reason the open coded SMC call was made was because a fast call works better here. __qcom_scm_is_call_available uses standard call, and I'll address this in v3.
Quoted 5 lines
Quoted 1 line
+
BUG();This
BUG()is new and not mentioned in the commit text. Why can't we just start failing all scm calls if we can't detect the calling convention?
Bjorn has requested that the BUG was introduced in v1:
https://lore.kernel.org/patchwork/patch/1148619/#1350062
Quoted 7 lines
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +2
-0+out: + pr_debug("QCOM SCM SMC Convention: %llu\n",
qcom_smccc_convention);Maybe
pr_info()is more appropriate. PSCI currently prints out the version info so maybe printing something like "QCOM SCMSMC_64calling convention" will be useful for early debugging.
Sure, will do.
Thanks,
Elliot
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 10/18] firmware: qcom_scm-64: Improve SMC convention detection
Quoting [email protected] (2019-11-15 17:29:03)
Quoted 41 lines · Stephen Boyd
Quoted 31 lines
Quoting Elliot Berman (2019-11-12 13:22:46)
Quoted 30 lines
drivers/firmware/qcom_scm-64.c +2
-15@@ -302,21 +302,20 @@ int __qcom_scm_hdcp_req(struct device *dev,struct qcom_scm_hdcp_req *req, void __qcom_scm_init(void) { - u64 cmd; -struct arm_smccc_res res; -u32 function =SMCCC_FUNCNUM (QCOM_SCM_SVC_INFO , QCOM_SCM_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_smccc_convention =ARM_SMCCC_SMC_64 ; + if (__qcom_scm_is_call_available(NULL, QCOM_SCM_SVC_INFO,Quoted 8 lines
Quoted 1 line
+
QCOM_SCM_INFO_IS_CALL_AVAIL) == 1)Is this asking if the "is call available function" is available by using
the is call available function? That is recursive. Isn't that why we make a manually open coded SMC call to see if it works? If this isn't going to work we may want to just have a property in DT that tells us what to do.
Quoted 3 lines
Yes. The reason the open coded SMC call was made was because a fast call works better here.
__qcom_scm_is_call_availableuses standard call, and I'll address this in v3.
So there will be a patch before this that makes __qcom_scm_is_call_available use SMCCC? I still don't get how it won't be recursive but I'll have to wait until v3 I guess.
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
+
BUG();This
BUG()is new and not mentioned in the commit text. Why can't we just start failing all scm calls if we can't detect the calling convention?Bjorn has requested that the BUG was introduced in v1:
https://lore.kernel.org/patchwork/patch/1148619/#1350062
Ok. I'd prefer a WARN_ON() instead but it's not really up to me. At least mention this in the commit text.
PATCH v2 11/18 firmware: qcom_scm-32: Use SMC arch wrappers
In reply to Elliot BermanUse SMC arch wrappers instead of inline assembly.
--- drivers/firmware/Makefile | 1 - drivers/firmware/qcom_scm-32.c | 71 ++++++++++-------------------------------- 2 files changed, 17 insertions(+), 55 deletions(-)
drivers/firmware/Makefile +0 -1
@@ -20,7 +20,6 @@ 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_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 +17 -54
98 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
Re: [PATCH v2 11/18] firmware: qcom_scm-32: Use SMC arch wrappers
Quoting Elliot Berman (2019-11-12 13:22:47)
Quoted 4 lines
Use SMC arch wrappers instead of inline assembly.
Signed-off-by Elliot Berman <[email protected]>---
Nice. Can this come earlier in the series?
Quoted 23 lines
drivers/firmware/qcom_scm-32.c +2
-5@@ -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" @@ -124,25 +125,13 @@ static inline void *legacy_get_response_buffer(static 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 { - asm volatile( - __asmeq("%0", "r0")
drivers/firmware/qcom_scm-32.c static inline void *legacy_get_response_buffer( · line 142
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +0
-10- __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");
I assume that the clobber list is not a problem? i.e. r12 is going to get clobbered and that's not a problem.
Quoted 5 lines
drivers/firmware/qcom_scm-32.c +2
-3- }while (r0 ==QCOM_SCM_INTERRUPTED ); - -return r0; +arm_smccc_smc (1 , (unsigned long )&context_id, cmd_addr, +0 ,0 ,0 ,0 ,0 , &res);
Re: [PATCH v2 11/18] firmware: qcom_scm-32: Use SMC arch wrappers
Quoted 1 line · Stephen Boyd
Nice. Can this come earlier in the series?
This patch is the first in this series that applies only to qcom_scm-32. Patches 1-5 were some common changes, 6-10 clean up qcom_scm-64, 11-15 clean up qcom_scm-32, and 16-18 merges the two. I'd rather not move this patch earlier in the series as it breaks that organization of patches.
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 12/18 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 | 283 +++++++++++++++++++++++++---------------- 1 file changed, 172 insertions(+), 111 deletions(-)
drivers/firmware/qcom_scm-32.c +172 -111
@@ -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 result[MAX_QCOM_SCM_RETS ]; +u32 owner; +}; +#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff))/**
@@ -135,16 +175,8 @@ static u32 __qcom_scm_call_do(u32 cmd_addr) }/** -* qcom_scm_call() - 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. +* qcom_scm_call() - 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
@@ -153,15 +185,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 qcom_scm_legacy_command *cmd;struct qcom_scm_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)
@@ -170,10 +206,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);
@@ -196,13 +233,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->result[i] =le32_to_cpu (res_buf[i]); out:dma_unmap_single (dev, cmd_phys, alloc_len,DMA_TO_DEVICE );kfree (cmd);
@@ -305,10 +342,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
@@ -324,10 +361,11 @@ 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 ] = flags; + desc.args[1 ] =virt_to_phys (entry); + desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev, &desc);if (!ret) {for_each_cpu (cpu, cpus) qcom_scm_wb[cpu].entry = entry;
@@ -353,26 +391,47 @@ void __qcom_scm_cpu_power_down(u32 flags)int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) {int ret; -__le32 svc_cmd =cpu_to_le32 (LEGACY_FUNCNUM (svc_id, cmd_id)); -__le32 ret_val =0 ; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_INFO , + .cmd =QCOM_SCM_INFO_IS_CALL_AVAIL , + .args[0 ] =LEGACY_FUNCNUM (svc_id, cmd_id), + .arginfo =QCOM_SCM_ARGS (1 ), + }; - ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_SCM_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.result[0 ]; }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 (10 ); + + ret =qcom_scm_call (dev, &desc); + *resp = desc.result[0 ]; + +return ret; }void __qcom_scm_init (void )
@@ -381,104 +440,107 @@ void __qcom_scm_init(void)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.result[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.result[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.result[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.result[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 ); -return ret ? :le32_to_cpu (out); + ret =qcom_scm_call (dev, &desc); + +return ret ? : desc.result[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 ); -return ret ? :le32_to_cpu (out); + ret =qcom_scm_call (dev, &desc); + +return ret ? : desc.result[0 ]; }int __qcom_scm_set_dload_mode (struct device *dev,bool enable)
@@ -489,20 +551,19 @@ int __qcom_scm_set_dload_mode(struct device *dev, bool enable)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; - 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.result[0 ]; } int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region,
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 12/18] firmware: qcom_scm-32: Use qcom_scm_desc in non-atomic calls
Quoting Elliot Berman (2019-11-12 13:22:48)
Quoted 36 lines
Use
qcom_scm_descin non-atomic calls to remove legacy convention details from every SCM wrapper function.Signed-off-by Elliot Berman <[email protected]>--- drivers/firmware/qcom_scm-32.c | 283 +++++++++++++++++++++++++---------------- 1 file changed, 172 insertions(+), 111 deletions(-)drivers/firmware/qcom_scm-32.c +20
-0@@ -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) | \
drivers/firmware/qcom_scm-32.c static struct qcom_scm_entry qcom_scm_wb[] = { · line 71
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +10
-0+ (((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
Please document all fields. 'res' looks like 'result' actually.
drivers/firmware/qcom_scm-32.c static struct qcom_scm_entry qcom_scm_wb[] = { · line 78
Quoted 7 lines
drivers/firmware/qcom_scm-32.c +7
-0+*/ +struct qcom_scm_desc { +u32 svc; +u32 cmd; +u32 arginfo; +u64 args[MAX_QCOM_SCM_ARGS ]; +u64 result[MAX_QCOM_SCM_RETS ];
I would split this out to be a pointer argument to the function so that some callers can pass NULL and we can not waste time converting junk. It would be good to also indicate how many result values we're expecting back so that we don't try to access junk that hasn't changed.
Quoted 12 lines
drivers/firmware/qcom_scm-32.c +3
-2+u32 owner; +}; +#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff))/** @@ -135,16 +175,8 @@ static u32 __qcom_scm_call_do(u32 cmd_addr) }/** -* qcom_scm_call() - Send an SCM command -* @dev: struct device
drivers/firmware/qcom_scm-32.c static u32 __qcom_scm_call_do(u32 cmd_addr) · line 179
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +2
-8-* @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. +* qcom_scm_call() - Sends a command to the SCM and waits for the command to +* finish processing.
Please document arguments to this function.
drivers/firmware/qcom_scm-32.c static u32 __qcom_scm_call_do(u32 cmd_addr) · line 190
Quoted 13 lines
drivers/firmware/qcom_scm-32.c +2
-3* * A note on cache maintenance: * Note that any buffers that are expected to be accessed by the secure world @@ -153,15 +185,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 ;
unsigned int? Or even u8?
drivers/firmware/qcom_scm-32.c static u32 __qcom_scm_call_do(u32 cmd_addr) · line 192
Quoted 2 lines
drivers/firmware/qcom_scm-32.c +1
-0int ret; +size_t i;
Should be unsigned int and not size_t. size_t is for sizes.
drivers/firmware/qcom_scm-32.c static u32 __qcom_scm_call_do(u32 cmd_addr) · line 200
Quoted 8 lines
drivers/firmware/qcom_scm-32.c +4
-0struct qcom_scm_legacy_command *cmd;struct qcom_scm_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;
const res_buf?
Quoted 55 lines
drivers/firmware/qcom_scm-32.c +15
-14cmd =kzalloc (PAGE_ALIGN (alloc_len),GFP_KERNEL );if (!cmd)@@ -170,10 +206,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);@@ -196,13 +233,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->result[i] =le32_to_cpu (res_buf[i]); out:dma_unmap_single (dev, cmd_phys, alloc_len,DMA_TO_DEVICE );kfree (cmd);@@ -305,10 +342,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
drivers/firmware/qcom_scm-32.c int __qcom_scm_set_warm_boot_addr(struct device *dev, void *entry, · line 366
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +3
-4@@ -324,10 +361,11 @@ 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 ] = flags; + desc.args[1 ] =virt_to_phys (entry); + desc.arginfo =QCOM_SCM_ARGS (2 );
Would be good to only have on way of filling in the descriptor.
Quoted 44 lines
drivers/firmware/qcom_scm-32.c +17
-10+ + ret =qcom_scm_call (dev, &desc);if (!ret) {for_each_cpu (cpu, cpus) qcom_scm_wb[cpu].entry = entry;@@ -353,26 +391,47 @@ void __qcom_scm_cpu_power_down(u32 flags)int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) {int ret; -__le32 svc_cmd =cpu_to_le32 (LEGACY_FUNCNUM (svc_id, cmd_id)); -__le32 ret_val =0 ; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_INFO , + .cmd =QCOM_SCM_INFO_IS_CALL_AVAIL , + .args[0 ] =LEGACY_FUNCNUM (svc_id, cmd_id), + .arginfo =QCOM_SCM_ARGS (1 ), + }; - ret =qcom_scm_call (dev,QCOM_SCM_SVC_INFO ,QCOM_SCM_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.result[0 ]; }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));
drivers/firmware/qcom_scm-32.c void __qcom_scm_cpu_power_down(u32 flags) · line 428
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +10
-0+ 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;
Is req_cnt always 5? Shouldn't this be some sort of while loop over req_cnt to pack two values into desc.args[] from req?
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +6
-0+ desc.arginfo =QCOM_SCM_ARGS (10 ); + + ret =qcom_scm_call (dev, &desc); + *resp = desc.result[0 ]; + +return ret; }void __qcom_scm_init (void )
drivers/firmware/qcom_scm-32.c void __qcom_scm_init(void) · line 447
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +4
-2@@ -381,104 +440,107 @@ void __qcom_scm_init(void)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 ,
owner was passed before? Where is this coming from?
Quoted 16 lines
drivers/firmware/qcom_scm-32.c +6
-6+ }; - 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.result[0 ]; }
PATCH v2 13/18 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 result[MAX_QCOM_SCM_RETS ];u32 owner; }; +struct arm_smccc_args { +unsigned long a[8 ]; +};#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff))
@@ -162,16 +165,13 @@ static inline void *legacy_get_response_buffer(return (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 ); }/**
@@ -188,10 +188,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 qcom_scm_legacy_command *cmd;struct qcom_scm_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;
@@ -220,10 +222,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;
@@ -266,10 +272,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_ID (svc, cmd,1 ), (unsigned long )&context_id, - arg1,0 ,0 ,0 ,0 ,0 , &res); + smc.a[0 ] =LEGACY_ATOMIC_ID (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; }
@@ -287,10 +297,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_ID (svc, cmd,2 ), (unsigned long )&context_id, - arg1, arg2,0 ,0 ,0 ,0 , &res); + smc.a[0 ] =LEGACY_ATOMIC_ID (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
Re: [PATCH v2 13/18] firmware: qcom_scm-32: Move SMCCC register filling to qcom_scm_call
Quoting Elliot Berman (2019-11-12 13:22:49)
Quoted 3 lines
- Move SMCCC register filling to
qcom_scm_callso thatqcom_scm_call_doonly needs to concern itself with retry mechanism.
- Usearm_smccc_argsstruct in atomic variants as well.
This is two things. Please split the patch.
Quoted 25 lines
drivers/firmware/qcom_scm-32.c +7
-3@@ -266,10 +272,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_ID (svc, cmd,1 ), (unsigned long )&context_id, - arg1,0 ,0 ,0 ,0 ,0 , &res); + smc.a[0 ] =LEGACY_ATOMIC_ID (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; }@@ -287,10 +297,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_ID(svc, cmd, 2), (unsigned long)&context_id,
drivers/firmware/qcom_scm-32.c static s32 qcom_scm_call_atomic1(u32 svc, u32 cmd, u32 arg1) · line 311
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +6
-1- arg1, arg2, 0, 0, 0, 0, &res); + smc.a[0 ] =LEGACY_ATOMIC_ID (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; }
Why are we changing the above two hunks? It's the same code with more lines right?
PATCH v2 14/18 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
@@ -252,6 +252,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_ID (svc, cmd, n) \
@@ -261,52 +263,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_ID (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); +BUG_ON (arglen >LEGACY_ATOMIC_N_REG_ARGS ); -return res.a0; -} + smc.a[0 ] =LEGACY_ATOMIC_ID (desc->svc, desc->cmd, arglen); + smc.a[1 ] = (unsigned long )&context_id; -/** -* 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; +for (i =0 ; i < arglen; i++) + smc.a[i +LEGACY_ATOMIC_FIRST_REG_IDX ] = desc->args[i]; - smc.a[0 ] =LEGACY_ATOMIC_ID (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->result[0 ] = res.a1; + desc->result[1 ] = res.a2; + desc->result[2 ] = res.a3; +return res.a0; }
@@ -328,6 +312,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 ;
@@ -339,8 +328,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); }/**
@@ -399,8 +391,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_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id)
@@ -560,8 +559,17 @@ 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_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); }int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id)
@@ -610,18 +618,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.result[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_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
Re: [PATCH v2 14/18] firmware: qcom_scm-32: Create common legacy atomic call
Quoting Elliot Berman (2019-11-12 13:22:50)
Quoted 2 lines
Per [1], legacy calling convention supports up to 5 arguments and 3 return values. Create one function to support this combination.
And remove the other functions in its place?
It would be nice to have some motivation here in the commit text.
Quoted 17 lines
drivers/firmware/qcom_scm-32.c +2
-0@@ -252,6 +252,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_ID (svc, cmd, n) \
drivers/firmware/qcom_scm-32.c static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc) · line 268
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +2
-4@@ -261,52 +263,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 *
Please document arguments.
drivers/firmware/qcom_scm-32.c static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc) · line 272
Quoted 5 lines
drivers/firmware/qcom_scm-32.c +1
-1* 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)
Can desc be const?
Quoted 18 lines
drivers/firmware/qcom_scm-32.c +4
-7{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_ID (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); +BUG_ON (arglen >LEGACY_ATOMIC_N_REG_ARGS ); -return res.a0; -} + smc.a[0 ] =LEGACY_ATOMIC_ID (desc->svc, desc->cmd, arglen); + smc.a[1 ] = (unsigned long )&context_id;
[...]
Quoted 5 lines
int
__qcom_scm_io_writel(struct device *dev, phys_addr_t addr, unsigned int val){drivers/firmware/qcom_scm-32.c +1
-2-return qcom_scm_call_atomic2 (QCOM_SCM_SVC_IO ,QCOM_SCM_IO_WRITE , - addr, val); +struct qcom_scm_desc desc = {
drivers/firmware/qcom_scm-32.c int __qcom_scm_io_readl(struct device *dev, phys_addr_t addr, · line 649
Quoted 10 lines
drivers/firmware/qcom_scm-32.c +10
-0+ .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);
So what is the benefit of this conversion? Now callers have to construct a descriptor on the stack and call the function that would otherwise accept some number of arguments. Are we going to be adding more register based APIs? It would seem simpler to just have a similar interface that smccc has that takes some fixed number of registers and then suffer the few extra register moves of some random value like 0 when they're not used by the secure world.
PATCH v2 15/18 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 | 17 +++++++++-------- drivers/firmware/qcom_scm-64.c | 5 +++-- drivers/firmware/qcom_scm.c | 5 +++-- drivers/firmware/qcom_scm.h | 5 +++-- 4 files changed, 18 insertions(+), 14 deletions(-)
drivers/firmware/qcom_scm-32.c +9 -8
@@ -269,7 +269,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 };
@@ -302,7 +302,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;
@@ -332,7 +333,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); }/**
@@ -389,7 +390,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 ,
@@ -399,7 +400,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_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id)
@@ -569,7 +570,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); }int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id)
@@ -627,7 +628,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_atomic (&desc); + ret =qcom_scm_call_atomic (dev, &desc);if (ret >=0 ) *val = desc.result[0 ];
@@ -646,7 +647,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_qsmmu500_wait_safe_toggle (struct device *dev,bool enable)
drivers/firmware/qcom_scm-64.c +3 -2
@@ -219,7 +219,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 ; }
@@ -247,7 +248,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 +3 -2
@@ -94,7 +94,8 @@ 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 ? __scm->dev :NULL , entry, + cpus); }EXPORT_SYMBOL (qcom_scm_set_cold_boot_addr);
@@ -122,7 +123,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 ? __scm->dev :NULL , flags); }EXPORT_SYMBOL (qcom_scm_cpu_power_down);
drivers/firmware/qcom_scm.h +3 -2
@@ -13,11 +13,12 @@ extern int __qcom_scm_set_dload_mode(struct device *dev, bool enable);extern int __qcom_scm_set_warm_boot_addr (struct device *dev,void *entry,const cpumask_t *cpus); -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);#define QCOM_SCM_BOOT_TERMINATE_PC 0x2#define QCOM_SCM_FLUSH_FLAG_MASK 0x3 -extern void __qcom_scm_cpu_power_down (u32 flags); +extern void __qcom_scm_cpu_power_down (struct device *dev,u32 flags);#define QCOM_SCM_SVC_IO 0x5#define QCOM_SCM_IO_READ 0x1
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 15/18] firmware: qcom_scm-32: Add device argument to atomic calls
Quoting Elliot Berman (2019-11-12 13:22:51)
Quoted 2 lines
Add this unused parameter to reduce merge friction between SMCCC and legacy based conventions.
in an upcoming patch.
Quoted 14 lines
Signed-off-by Elliot Berman <[email protected]>--- drivers/firmware/qcom_scm-32.c | 17 +++++++++-------- drivers/firmware/qcom_scm-64.c | 5 +++-- drivers/firmware/qcom_scm.c | 5 +++-- drivers/firmware/qcom_scm.h | 5 +++-- 4 files changed, 18 insertions(+), 14 deletions(-)drivers/firmware/qcom_scm-32.c +0
-0
drivers/firmware/qcom_scm-32.c static int qcom_scm_call(struct device *dev, struct qcom_scm_desc *desc) · line 272
Quoted 5 lines
drivers/firmware/qcom_scm-32.c +1
-1@@ -269,7 +269,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)
If the argument is unused, how about call it 'struct device *unused' so we can ignore it?
Quoted 3 lines
drivers/firmware/qcom_scm-32.c +0
-0{int context_id;struct arm_smccc_args smc = {0 };
PATCH v2 16/18 firmware: qcom_scm: Remove thin wrappers
In reply to Elliot Bermanqcom_scm-32 and qcom_scm-64 implementations are nearly identical, so make qcom_scm_call and qcom_scm_call_atomic unique to each. There are the following catches:
- __qcom_scm_is_call_available is still in each -32,-64 implementation as the argument is unique to each convention
- For some functions, only one implementation was provided in -32 or -64. The actual implementation was moved into qcom_scm.c
- io_writel and io_readl in -64 were not atomic and -32 they were. Atomic is the better option, so use it.
--- drivers/firmware/qcom_scm-32.c | 407 +---------------------------------------- drivers/firmware/qcom_scm-64.c | 399 +--------------------------------------- drivers/firmware/qcom_scm.c | 359 +++++++++++++++++++++++++++++++++--- drivers/firmware/qcom_scm.h | 75 ++++---- 4 files changed, 382 insertions(+), 858 deletions(-)
drivers/firmware/qcom_scm-32.c +2 -405
@@ -15,69 +15,8 @@#include "qcom_scm.h" -#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 - -#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 }, -}; -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 result[MAX_QCOM_SCM_RETS ]; -u32 owner; -};struct arm_smccc_args {unsigned long a[8 ]; };
@@ -185,7 +124,7 @@ static void __qcom_scm_call_do(const struct arm_smccc_args *smc,* 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,struct qcom_scm_desc *desc) +int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc) {int arglen = desc->arginfo &0xf ;int ret =0 , context_id;
@@ -269,7 +208,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 device *dev,struct qcom_scm_desc *desc) +int qcom_scm_call_atomic (struct device *dev,struct qcom_scm_desc *desc) {int context_id;struct arm_smccc_args smc = {0 };
@@ -294,115 +233,6 @@ static int qcom_scm_call_atomic(struct device *dev, struct qcom_scm_desc *desc)return res.a0; } -/** -* qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus -* @entry: Entry point function for the cpus -* @cpus: The cpumask of cpus that will use the entry point -* -* 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 (struct device *dev,void *entry, -const cpumask_t *cpus) -{ -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); -} - -/** -* qcom_scm_set_warm_boot_addr() - Set the warm boot address for cpus -* @entry: Entry point function for the cpus -* @cpus: The cpumask of cpus that will use the entry point -* -* Set the Linux entry point for the SCM to transfer control to when coming -* out of a power down. CPU power down may be executed on cpuidle or hotplug. -*/ -int __qcom_scm_set_warm_boot_addr (struct device *dev,void *entry, -const cpumask_t *cpus) -{ -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 ] = flags; - desc.args[1 ] =virt_to_phys (entry); - desc.arginfo =QCOM_SCM_ARGS (2 ); - - ret =qcom_scm_call (dev, &desc); -if (!ret) { -for_each_cpu (cpu, cpus) - qcom_scm_wb[cpu].entry = entry; - } - -return ret; -} - -/** -* qcom_scm_cpu_power_down() - Power down the cpu -* @flags - Flags to flush cache -* -* This is an end point to power down cpu. If there was a pending interrupt, -* 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 (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_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) {int ret;
@@ -418,239 +248,6 @@ int __qcom_scm_is_call_available(struct device *dev, u32 svc_id, u32 cmd_id)return ret ? : desc.result[0 ]; } -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 ; - - 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 (10 ); - - ret =qcom_scm_call (dev, &desc); - *resp = desc.result[0 ]; - -return ret; -} -void __qcom_scm_init (void ) { } - -bool __qcom_scm_pas_supported (struct device *dev,u32 peripheral) -{ -int ret; -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_PIL , - .cmd =QCOM_SCM_PIL_PAS_IS_SUPPORTED , - .owner =ARM_SMCCC_OWNER_SIP , - }; - - desc.args[0 ] = peripheral; - desc.arginfo =QCOM_SCM_ARGS (1 ); - - ret =qcom_scm_call (dev, &desc); - -return ret ? false : !!desc.result[0 ]; -} - -int __qcom_scm_pas_init_image (struct device *dev,u32 peripheral, -dma_addr_t metadata_phys) -{ -int ret; -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_PIL , - .cmd =QCOM_SCM_PIL_PAS_INIT_IMAGE , - .owner =ARM_SMCCC_OWNER_SIP , - }; - - 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); - -return ret ? : desc.result[0 ]; -} - -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 = { - .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.result[0 ]; -} - -int __qcom_scm_pas_auth_and_reset (struct device *dev,u32 peripheral) -{ -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 , - }; - - ret =qcom_scm_call (dev, &desc); - -return ret ? : desc.result[0 ]; -} - -int __qcom_scm_pas_shutdown (struct device *dev,u32 peripheral) -{ -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_PIL , - .cmd =QCOM_SCM_PIL_PAS_SHUTDOWN , - .owner =ARM_SMCCC_OWNER_SIP , - }; -int ret; - - desc.args[0 ] = peripheral; - desc.arginfo =QCOM_SCM_ARGS (1 ); - - ret =qcom_scm_call (dev, &desc); - -return ret ? : desc.result[0 ]; -} - -int __qcom_scm_pas_mss_reset (struct device *dev,bool 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; - - desc.args[0 ] = reset; - desc.args[1 ] =0 ; - desc.arginfo =QCOM_SCM_ARGS (2 ); - - ret =qcom_scm_call (dev, &desc); - -return ret ? : desc.result[0 ]; -} - -int __qcom_scm_set_dload_mode (struct device *dev,bool enable) -{ -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 (dev, &desc); -} - -int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) -{ -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_BOOT , - .cmd =QCOM_SCM_BOOT_SET_REMOTE_STATE , - .owner =ARM_SMCCC_OWNER_SIP , - }; -int ret; - - desc.args[0 ] = state; - desc.args[1 ] = id; - - ret =qcom_scm_call (dev, &desc); - -return ret ? : desc.result[0 ]; -} - -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) -{ -return -ENODEV ; -} - -int __qcom_scm_restore_sec_cfg (struct device *dev,u32 device_id, -u32 spare) -{ -return -ENODEV ; -} - -int __qcom_scm_iommu_secure_ptbl_size (struct device *dev,u32 spare, -size_t *size) -{ -return -ENODEV ; -} - -int __qcom_scm_iommu_secure_ptbl_init (struct device *dev,u64 addr,u32 size, -u32 spare) -{ -return -ENODEV ; -} - -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_atomic (dev, &desc); -if (ret >=0 ) - *val = desc.result[0 ]; - -return ret <0 ? ret :0 ; -} - -int __qcom_scm_io_writel (struct device *dev,phys_addr_t addr,unsigned int 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 (dev, &desc); -} - -int __qcom_scm_qsmmu500_wait_safe_toggle (struct device *dev,bool enable) -{ -return -ENODEV ; -}
drivers/firmware/qcom_scm-64.c +2 -397
430 lines not on this page · raw message
drivers/firmware/qcom_scm.c +335 -24
524 lines not on this page · raw message
drivers/firmware/qcom_scm.h +43 -32
115 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
PATCH v2 17/18 firmware: qcom_scm: Dynamically support SMCCC and legacy conventions
In reply to Elliot BermanDynamically support SMCCCC and legacy conventions by detecting which convention to use at runtime. qcom_scm_call_atomic and qcom_scm_call can then be moved in qcom_scm.c and use underlying convention backend as appropriate. Thus, rename qcom_scm-64,-32 to reflect that they are backends for -smccc and -legacy, respectively.
---
drivers/firmware/Kconfig | 8 --
drivers/firmware/Makefile | 4 +-
.../firmware/{qcom_scm-32.c => qcom_scm-legacy.c} | 24 +----
.../firmware/{qcom_scm-64.c => qcom_scm-smccc.c} | 77 +-------------
drivers/firmware/qcom_scm.c | 113 ++++++++++++++++++++-
drivers/firmware/qcom_scm.h | 23 +++--
6 files changed, 137 insertions(+), 112 deletions(-)
rename drivers/firmware/{qcom_scm-32.c => qcom_scm-legacy.c} (92%)
rename drivers/firmware/{qcom_scm-64.c => qcom_scm-smccc.c} (60%)drivers/firmware/Kconfig +0 -8
@@ -239,14 +239,6 @@ config QCOM_SCM depends on ARM || ARM64 select RESET_CONTROLLER -config QCOM_SCM_32 - def_bool y - depends on QCOM_SCM && ARM - -config QCOM_SCM_64 - def_bool y - depends on QCOM_SCM && ARM64 - config QCOM_SCM_DOWNLOAD_MODE_DEFAULT bool "Qualcomm download mode enabled by default" depends on QCOM_SCM
drivers/firmware/Makefile +1 -3
@@ -17,9 +17,7 @@ obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o 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 +obj-$(CONFIG_QCOM_SCM) += qcom_scm.o qcom_scm-smccc.o qcom_scm-legacy.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-legacy.c renamed from drivers/firmware/qcom_scm-32.c +2 -22
@@ -21,7 +21,6 @@ struct arm_smccc_args {unsigned long a[8 ]; }; -#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff))/** * struct qcom_scm_legacy_command - one SCM command buffer
@@ -124,7 +123,7 @@ static void __qcom_scm_call_do(const struct arm_smccc_args *smc,* 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. */ -int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc) +int qcom_scm_call_legacy (struct device *dev,struct qcom_scm_desc *desc) {int arglen = desc->arginfo &0xf ;int ret =0 , context_id;
@@ -208,7 +207,7 @@ 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. */ -int qcom_scm_call_atomic (struct device *dev,struct qcom_scm_desc *desc) +int qcom_scm_call_legacy_atomic (struct device *dev,struct qcom_scm_desc *desc) {int context_id;struct arm_smccc_args smc = {0 };
@@ -232,22 +231,3 @@ int qcom_scm_call_atomic(struct device *dev, struct qcom_scm_desc *desc)return res.a0; } - -int __qcom_scm_is_call_available (struct device *dev,u32 svc_id,u32 cmd_id) -{ -int ret; -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_INFO , - .cmd =QCOM_SCM_INFO_IS_CALL_AVAIL , - .args[0 ] =LEGACY_FUNCNUM (svc_id, cmd_id), - .arginfo =QCOM_SCM_ARGS (1 ), - }; - - ret =qcom_scm_call (dev, &desc); - -return ret ? : desc.result[0 ]; -} - -void __qcom_scm_init (void ) -{ -}
drivers/firmware/qcom_scm-smccc.c renamed from drivers/firmware/qcom_scm-64.c +5 -72
103 lines not on this page · raw message
drivers/firmware/qcom_scm.c +112 -1
125 lines not on this page · raw message
drivers/firmware/qcom_scm.h +17 -6
@@ -4,6 +4,15 @@#ifndef __QCOM_SCM_INT_H#define __QCOM_SCM_INT_H +enum qcom_scm_convention { +SMC_CONVENTION_UNKNOWN , +SMC_CONVENTION_LEGACY , +SMC_CONVENTION_ARM_32 , +SMC_CONVENTION_ARM_64 , +}; + +extern enum qcom_scm_convention qcom_scm_convention; +#define MAX_QCOM_SCM_ARGS 10#define MAX_QCOM_SCM_RETS 3
@@ -44,8 +53,14 @@ struct qcom_scm_desc {u32 owner; }; -extern int qcom_scm_call (struct device *dev,struct qcom_scm_desc *desc); -extern int qcom_scm_call_atomic (struct device *dev,struct qcom_scm_desc *desc); +#define SMCCC_FUNCNUM (s, c) ((((s) & 0xFF) << 8) | ((c) & 0xFF)) +extern int qcom_scm_call_smccc (struct device *dev,struct qcom_scm_desc *desc, +bool atomic); + +#define LEGACY_FUNCNUM (s, c) (((s) << 10) | ((c) & 0x3ff)) +extern int qcom_scm_call_legacy_atomic (struct device *dev, +struct qcom_scm_desc *desc); +extern int qcom_scm_call_legacy (struct device *dev,struct qcom_scm_desc *desc);#define QCOM_SCM_SVC_BOOT 0x1#define QCOM_SCM_BOOT_SET_ADDR 0x1
@@ -61,14 +76,10 @@ extern int qcom_scm_call_atomic(struct device *dev, struct qcom_scm_desc *desc);#define QCOM_SCM_SVC_INFO 0x6#define QCOM_SCM_INFO_IS_CALL_AVAIL 0x1 -extern int __qcom_scm_is_call_available (struct device *dev,u32 svc_id, -u32 cmd_id);#define QCOM_SCM_SVC_HDCP 0x11#define QCOM_SCM_HDCP_INVOKE 0x01 -extern void __qcom_scm_init (void ); -#define QCOM_SCM_SVC_PIL 0x2#define QCOM_SCM_PIL_PAS_INIT_IMAGE 0x1#define QCOM_SCM_PIL_PAS_MEM_SETUP 0x2
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 18/18 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.c | 524 ++++++++++++++++++++++---------------------- drivers/firmware/qcom_scm.h | 54 +++-- include/linux/qcom_scm.h | 97 ++++---- 3 files changed, 344 insertions(+), 331 deletions(-)
drivers/firmware/qcom_scm.c +264 -260
@@ -37,19 +37,6 @@ struct qcom_scm {u64 dload_mode_addr; }; -struct qcom_scm_current_perm_info { -__le32 vmid; -__le32 perm; -__le64 ctx; -__le32 ctx_size; -__le32 unused; -}; - -struct qcom_scm_mem_map_info { -__le64 mem_addr; -__le64 mem_size; -}; -static struct qcom_scm *__scm;static int qcom_scm_clk_enable (void )
@@ -166,36 +153,6 @@ static int qcom_scm_call_atomic(struct device *dev, struct qcom_scm_desc *desc) } } -static int __qcom_scm_is_call_available (struct device *dev,u32 svc_id, -u32 cmd_id) -{ -int ret; -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_INFO , - .cmd =QCOM_SCM_INFO_IS_CALL_AVAIL , - .owner =ARM_SMCCC_OWNER_SIP , - }; - - desc.arginfo =QCOM_SCM_ARGS (1 ); -switch (__get_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); - -return ret ? : desc.result[0 ]; -} -#define QCOM_SCM_FLAG_COLDBOOT_CPU0 0x00#define QCOM_SCM_FLAG_COLDBOOT_CPU1 0x01#define QCOM_SCM_FLAG_COLDBOOT_CPU2 0x08
@@ -306,6 +263,8 @@ int qcom_scm_set_warm_boot_addr(void *entry, const cpumask_t *cpus) }EXPORT_SYMBOL (qcom_scm_set_warm_boot_addr); +#define QCOM_SCM_FLUSH_FLAG_MASK 0x03 +/** * qcom_scm_cpu_power_down() - Power down the cpu * @flags - Flags to flush cache
@@ -328,101 +287,61 @@ void qcom_scm_cpu_power_down(u32 flags) }EXPORT_SYMBOL (qcom_scm_cpu_power_down); -/** -* qcom_scm_hdcp_available() - Check if secure environment supports HDCP. -* -* Return true if HDCP is supported, false if not. -*/ -bool qcom_scm_hdcp_available (void ) -{ -int ret =qcom_scm_clk_enable (); - -if (ret) -return ret; - - ret =__qcom_scm_is_call_available (__scm->dev,QCOM_SCM_SVC_HDCP , -QCOM_SCM_HDCP_INVOKE ); - -qcom_scm_clk_disable (); - -return ret >0 ? true : false; -} -EXPORT_SYMBOL (qcom_scm_hdcp_available); - -/** -* qcom_scm_hdcp_req() - Send HDCP request. -* @req: HDCP request array -* @req_cnt: HDCP request array count -* @resp: response buffer passed to SCM -* -* Write HDCP register(s) through SCM. -*/ -int qcom_scm_hdcp_req (struct qcom_scm_hdcp_req *req,u32 req_cnt,u32 *resp) +int qcom_scm_set_remote_state (u32 state,u32 id) { -int ret;struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_HDCP , - .cmd =QCOM_SCM_HDCP_INVOKE , + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_REMOTE_STATE , .owner =ARM_SMCCC_OWNER_SIP , }; +int ret; -if (req_cnt >QCOM_SCM_HDCP_MAX_REQ_CNT ) -return -ERANGE ; - - ret =qcom_scm_clk_enable (); -if (ret) -return ret; - - 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 (10 ); + desc.args[0 ] = state; + desc.args[1 ] = id; + desc.arginfo =QCOM_SCM_ARGS (2 ); ret =qcom_scm_call (__scm->dev, &desc); - *resp = desc.result[0 ]; - -qcom_scm_clk_disable (); -return ret; +return ret ? : desc.result[0 ]; } -EXPORT_SYMBOL (qcom_scm_hdcp_req); +EXPORT_SYMBOL (qcom_scm_set_remote_state); -/** -* qcom_scm_pas_supported() - Check if the peripheral authentication service is -* available for the given peripherial -* @peripheral: peripheral id -* -* Returns true if PAS is supported for this peripheral, otherwise false. -*/ -bool qcom_scm_pas_supported (u32 peripheral) +static int __qcom_scm_set_dload_mode (struct device *dev,bool enable) { -int ret;struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_PIL , - .cmd =QCOM_SCM_PIL_PAS_IS_SUPPORTED , + .svc =QCOM_SCM_SVC_BOOT , + .cmd =QCOM_SCM_BOOT_SET_DLOAD_MODE , .owner =ARM_SMCCC_OWNER_SIP , }; - ret =__qcom_scm_is_call_available (__scm->dev,QCOM_SCM_SVC_PIL , -QCOM_SCM_PIL_PAS_IS_SUPPORTED ); -if (ret <=0 ) -return false; + 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 ); - desc.args[0 ] = peripheral; - desc.arginfo =QCOM_SCM_ARGS (1 ); +return qcom_scm_call (__scm->dev, &desc); +} - ret =qcom_scm_call (__scm->dev, &desc); +static void qcom_scm_set_download_mode (bool enable) +{ +bool avail; +int ret =0 ; -return ret ? false : !!desc.result[0 ]; + avail =__qcom_scm_is_call_available (__scm->dev, +QCOM_SCM_SVC_BOOT , +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->dload_mode_addr, + enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ); + }else { +dev_err (__scm->dev, +"No available mechanism for setting download mode\n" ); + } + +if (ret) +dev_err (__scm->dev,"failed to set download mode: %d\n" , ret); } -EXPORT_SYMBOL (qcom_scm_pas_supported);/** * qcom_scm_pas_init_image() - Initialize peripheral authentication service
@@ -569,6 +488,36 @@ int qcom_scm_pas_shutdown(u32 peripheral) }EXPORT_SYMBOL (qcom_scm_pas_shutdown); +/** +* qcom_scm_pas_supported() - Check if the peripheral authentication service is +* available for the given peripherial +* @peripheral: peripheral id +* +* Returns true if PAS is supported for this peripheral, otherwise false. +*/ +bool qcom_scm_pas_supported (u32 peripheral) +{ +int ret; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_PIL , + .cmd =QCOM_SCM_PIL_PAS_IS_SUPPORTED , + .owner =ARM_SMCCC_OWNER_SIP , + }; + + ret =__qcom_scm_is_call_available (__scm->dev,QCOM_SCM_SVC_PIL , +QCOM_SCM_PIL_PAS_IS_SUPPORTED ); +if (ret <=0 ) +return false; + + desc.args[0 ] = peripheral; + desc.arginfo =QCOM_SCM_ARGS (1 ); + + ret =qcom_scm_call (__scm->dev, &desc); + +return ret ? false : !!desc.result[0 ]; +} +EXPORT_SYMBOL (qcom_scm_pas_supported); +static int __qcom_scm_pas_mss_reset (struct device *dev,bool reset) {struct qcom_scm_desc desc = {
@@ -610,6 +559,72 @@ static const struct reset_control_ops qcom_scm_pas_reset_ops = { .deassert = qcom_scm_pas_reset_deassert, }; +int qcom_scm_io_readl (phys_addr_t addr,unsigned int *val) +{ +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_IO , + .cmd =QCOM_SCM_IO_READ , + .owner =ARM_SMCCC_OWNER_SIP , + }; +int ret; + + desc.args[0 ] = addr; + desc.arginfo =QCOM_SCM_ARGS (1 ); + + ret =qcom_scm_call (__scm->dev, &desc); +if (ret >=0 ) + *val = desc.result[0 ]; + +return ret <0 ? ret :0 ; +} +EXPORT_SYMBOL (qcom_scm_io_readl); + +int qcom_scm_io_writel (phys_addr_t addr,unsigned int 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 (__scm->dev, &desc); +} +EXPORT_SYMBOL (qcom_scm_io_writel); + +static int __qcom_scm_is_call_available (struct device *dev,u32 svc_id, +u32 cmd_id) +{ +int ret; +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_INFO , + .cmd =QCOM_SCM_INFO_IS_CALL_AVAIL , + .owner =ARM_SMCCC_OWNER_SIP , + }; + + desc.arginfo =QCOM_SCM_ARGS (1 ); +switch (__get_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); + +return ret ? : desc.result[0 ]; +} +int qcom_scm_restore_sec_cfg (u32 device_id,u32 spare) {struct qcom_scm_desc desc = {
@@ -675,148 +690,18 @@ int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) }EXPORT_SYMBOL (qcom_scm_iommu_secure_ptbl_init); -int qcom_scm_qsmmu500_wait_safe_toggle (bool en) -{ -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_SMMU_PROGRAM , - .cmd =QCOM_SCM_SMMU_CONFIG_ERRATA1 , - .owner =ARM_SMCCC_OWNER_SIP , - }; - - 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 (__scm->dev, &desc); -} -EXPORT_SYMBOL (qcom_scm_qsmmu500_wait_safe_toggle); - -int qcom_scm_io_readl (phys_addr_t addr,unsigned int *val) -{ -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_IO , - .cmd =QCOM_SCM_IO_READ , - .owner =ARM_SMCCC_OWNER_SIP , - }; -int ret; - - desc.args[0 ] = addr; - desc.arginfo =QCOM_SCM_ARGS (1 ); - - ret =qcom_scm_call (__scm->dev, &desc); -if (ret >=0 ) - *val = desc.result[0 ]; - -return ret <0 ? ret :0 ; -} -EXPORT_SYMBOL (qcom_scm_io_readl); - -int qcom_scm_io_writel (phys_addr_t addr,unsigned int 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 (__scm->dev, &desc); -} -EXPORT_SYMBOL (qcom_scm_io_writel); - -static int __qcom_scm_set_dload_mode (struct device *dev,bool enable) -{ -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 (__scm->dev, &desc); -} - -static void qcom_scm_set_download_mode (bool enable) -{ -bool avail; -int ret =0 ; - - avail =__qcom_scm_is_call_available (__scm->dev, -QCOM_SCM_SVC_BOOT , -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->dload_mode_addr, - enable ?QCOM_SCM_BOOT_SET_DLOAD_MODE :0 ); - }else { -dev_err (__scm->dev, -"No available mechanism for setting download mode\n" ); - } - -if (ret) -dev_err (__scm->dev,"failed to set download mode: %d\n" , ret); -} - -static int qcom_scm_find_dload_address (struct device *dev,u64 *addr) -{ -struct device_node *tcsr; -struct device_node *np = dev->of_node; -struct resource res; -u32 offset; -int ret; - - tcsr =of_parse_phandle (np,"qcom,dload-mode" ,0 ); -if (!tcsr) -return 0 ; - - ret =of_address_to_resource (tcsr,0 , &res); -of_node_put (tcsr); -if (ret) -return ret; - - ret =of_property_read_u32_index (np,"qcom,dload-mode" ,1 , &offset); -if (ret <0 ) -return ret; - - *addr = res.start + offset; - -return 0 ; -} - -/** -* qcom_scm_is_available() - Checks if SCM is available -*/ -bool qcom_scm_is_available (void ) -{ -return !!__scm; -} -EXPORT_SYMBOL (qcom_scm_is_available); - -int qcom_scm_set_remote_state (u32 state,u32 id) -{ -struct qcom_scm_desc desc = { - .svc =QCOM_SCM_SVC_BOOT , - .cmd =QCOM_SCM_BOOT_SET_REMOTE_STATE , - .owner =ARM_SMCCC_OWNER_SIP , - }; -int ret; - - desc.args[0 ] = state; - desc.args[1 ] = id; - desc.arginfo =QCOM_SCM_ARGS (2 ); - - ret =qcom_scm_call (__scm->dev, &desc); +struct qcom_scm_current_perm_info { +__le32 vmid; +__le32 perm; +__le64 ctx; +__le32 ctx_size; +__le32 unused; +}; -return ret ? : desc.result[0 ]; -} -EXPORT_SYMBOL (qcom_scm_set_remote_state); +struct qcom_scm_mem_map_info { +__le64 mem_addr; +__le64 mem_size; +}; static 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,
@@ -928,6 +813,125 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, }EXPORT_SYMBOL (qcom_scm_assign_mem); +/** +* qcom_scm_hdcp_available() - Check if secure environment supports HDCP. +* +* Return true if HDCP is supported, false if not. +*/ +bool qcom_scm_hdcp_available (void ) +{ +int ret =qcom_scm_clk_enable (); + +if (ret) +return ret; + + ret =__qcom_scm_is_call_available (__scm->dev,QCOM_SCM_SVC_HDCP , +QCOM_SCM_HDCP_INVOKE ); + +qcom_scm_clk_disable (); + +return ret >0 ? true : false; +} +EXPORT_SYMBOL (qcom_scm_hdcp_available); + +/** +* qcom_scm_hdcp_req() - Send HDCP request. +* @req: HDCP request array +* @req_cnt: HDCP request array count +* @resp: response buffer passed to SCM +* +* Write HDCP register(s) through SCM. +*/ +int qcom_scm_hdcp_req (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 ; + + ret =qcom_scm_clk_enable (); +if (ret) +return ret; + + 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 (10 ); + + ret =qcom_scm_call (__scm->dev, &desc); + *resp = desc.result[0 ]; + + +qcom_scm_clk_disable (); + +return ret; +} +EXPORT_SYMBOL (qcom_scm_hdcp_req); + +#define QCOM_SCM_SMMU_CONFIG_ERRATA1_CLIENT_ALL 0x02 +int qcom_scm_qsmmu500_wait_safe_toggle (bool en) +{ +struct qcom_scm_desc desc = { + .svc =QCOM_SCM_SVC_SMMU_PROGRAM , + .cmd =QCOM_SCM_SMMU_CONFIG_ERRATA1 , + .owner =ARM_SMCCC_OWNER_SIP , + }; + + 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 (__scm->dev, &desc); +} +EXPORT_SYMBOL (qcom_scm_qsmmu500_wait_safe_toggle); + +static int qcom_scm_find_dload_address (struct device *dev,u64 *addr) +{ +struct device_node *tcsr; +struct device_node *np = dev->of_node; +struct resource res; +u32 offset; +int ret; + + tcsr =of_parse_phandle (np,"qcom,dload-mode" ,0 ); +if (!tcsr) +return 0 ; + + ret =of_address_to_resource (tcsr,0 , &res); +of_node_put (tcsr); +if (ret) +return ret; + + ret =of_property_read_u32_index (np,"qcom,dload-mode" ,1 , &offset); +if (ret <0 ) +return ret; + + *addr = res.start + offset; + +return 0 ; +} + +/** +* qcom_scm_is_available() - Checks if SCM is available +*/ +bool qcom_scm_is_available (void ) +{ +return !!__scm; +} +EXPORT_SYMBOL (qcom_scm_is_available); +static int qcom_scm_probe (struct platform_device *pdev) {struct qcom_scm *scm;
drivers/firmware/qcom_scm.h +26 -28
70 lines not on this page · raw message
include/linux/qcom_scm.h +54 -43
128 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