diff mbox series

[07/11] firmware: qcom-scm: use SHM bridge if available

Message ID 20230828192507.117334-8-bartosz.golaszewski@linaro.org (mailing list archive)
State New, archived
Headers show
Series arm64: qcom: add and enable SHM Bridge support | expand

Commit Message

Bartosz Golaszewski Aug. 28, 2023, 7:25 p.m. UTC
Allocate the memory for SCM call arguments from the Shared Memory Bridge
if it's available.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/firmware/qcom_scm-smc.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

Comments

kernel test robot Aug. 29, 2023, 5:32 a.m. UTC | #1
Hi Bartosz,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on arm64/for-next/core linus/master v6.5]
[cannot apply to next-20230828]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/firmware-qcom-scm-drop-unneeded-extern-specifiers/20230829-032930
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230828192507.117334-8-bartosz.golaszewski%40linaro.org
patch subject: [PATCH 07/11] firmware: qcom-scm: use SHM bridge if available
config: m68k-randconfig-r006-20230829 (https://download.01.org/0day-ci/archive/20230829/202308291359.QP042fIw-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230829/202308291359.QP042fIw-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308291359.QP042fIw-lkp@intel.com/

All errors (new ones prefixed by >>):

   m68k-linux-ld: drivers/firmware/qcom_scm-smc.o: in function `__scm_smc_call':
>> drivers/firmware/qcom_scm-smc.c:179:(.text+0xa8): undefined reference to `qcom_shm_bridge_alloc'
>> m68k-linux-ld: drivers/firmware/qcom_scm-smc.c:221:(.text+0x1ac): undefined reference to `qcom_shm_bridge_free'
   m68k-linux-ld: drivers/firmware/qcom_scm-smc.c:206:(.text+0x23a): undefined reference to `qcom_shm_bridge_free'


vim +179 drivers/firmware/qcom_scm-smc.c

   148	
   149	
   150	int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
   151			   enum qcom_scm_convention qcom_convention,
   152			   struct qcom_scm_res *res, bool atomic)
   153	{
   154		int arglen = desc->arginfo & 0xf;
   155		int i, ret;
   156		dma_addr_t args_phys = 0;
   157		void *args_virt = NULL;
   158		size_t alloc_len;
   159		gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL;
   160		u32 smccc_call_type = atomic ? ARM_SMCCC_FAST_CALL : ARM_SMCCC_STD_CALL;
   161		u32 qcom_smccc_convention = (qcom_convention == SMC_CONVENTION_ARM_32) ?
   162					    ARM_SMCCC_SMC_32 : ARM_SMCCC_SMC_64;
   163		struct arm_smccc_res smc_res;
   164		struct arm_smccc_args smc = {0};
   165		bool using_shm_bridge = qcom_scm_shm_bridge_available();
   166	
   167		smc.args[0] = ARM_SMCCC_CALL_VAL(
   168			smccc_call_type,
   169			qcom_smccc_convention,
   170			desc->owner,
   171			SCM_SMC_FNID(desc->svc, desc->cmd));
   172		smc.args[1] = desc->arginfo;
   173		for (i = 0; i < SCM_SMC_N_REG_ARGS; i++)
   174			smc.args[i + SCM_SMC_FIRST_REG_IDX] = desc->args[i];
   175	
   176		if (unlikely(arglen > SCM_SMC_N_REG_ARGS)) {
   177			alloc_len = SCM_SMC_N_EXT_ARGS * sizeof(u64);
   178			if (using_shm_bridge)
 > 179				args_virt = qcom_shm_bridge_alloc(NULL,
   180								  PAGE_ALIGN(alloc_len),
   181								  flag);
   182			else
   183				args_virt = kzalloc(PAGE_ALIGN(alloc_len), flag);
   184			if (!args_virt)
   185				return -ENOMEM;
   186	
   187			if (qcom_smccc_convention == ARM_SMCCC_SMC_32) {
   188				__le32 *args = args_virt;
   189	
   190				for (i = 0; i < SCM_SMC_N_EXT_ARGS; i++)
   191					args[i] = cpu_to_le32(desc->args[i +
   192							      SCM_SMC_FIRST_EXT_IDX]);
   193			} else {
   194				__le64 *args = args_virt;
   195	
   196				for (i = 0; i < SCM_SMC_N_EXT_ARGS; i++)
   197					args[i] = cpu_to_le64(desc->args[i +
   198							      SCM_SMC_FIRST_EXT_IDX]);
   199			}
   200	
   201			args_phys = dma_map_single(dev, args_virt, alloc_len,
   202						   DMA_TO_DEVICE);
   203	
   204			if (dma_mapping_error(dev, args_phys)) {
   205				if (using_shm_bridge)
   206					qcom_shm_bridge_free(args_virt);
   207				else
   208					kfree(args_virt);
   209				return -ENOMEM;
   210			}
   211	
   212			smc.args[SCM_SMC_LAST_REG_IDX] = args_phys;
   213		}
   214	
   215		/* ret error check follows after args_virt cleanup*/
   216		ret = __scm_smc_do(dev, &smc, &smc_res, atomic);
   217	
   218		if (args_virt) {
   219			dma_unmap_single(dev, args_phys, alloc_len, DMA_TO_DEVICE);
   220			if (using_shm_bridge)
 > 221				qcom_shm_bridge_free(args_virt);
   222			else
   223				kfree(args_virt);
   224		}
   225	
   226		if (ret)
   227			return ret;
   228	
   229		if (res) {
   230			res->result[0] = smc_res.a1;
   231			res->result[1] = smc_res.a2;
   232			res->result[2] = smc_res.a3;
   233		}
   234	
   235		return (long)smc_res.a0 ? qcom_scm_remap_error(smc_res.a0) : 0;
   236
kernel test robot Aug. 29, 2023, 5:43 a.m. UTC | #2
Hi Bartosz,

kernel test robot noticed the following build errors:

[auto build test ERROR on robh/for-next]
[also build test ERROR on arm64/for-next/core linus/master v6.5]
[cannot apply to next-20230828]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/firmware-qcom-scm-drop-unneeded-extern-specifiers/20230829-032930
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link:    https://lore.kernel.org/r/20230828192507.117334-8-bartosz.golaszewski%40linaro.org
patch subject: [PATCH 07/11] firmware: qcom-scm: use SHM bridge if available
config: arm-defconfig (https://download.01.org/0day-ci/archive/20230829/202308291337.PSyslzRx-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230829/202308291337.PSyslzRx-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308291337.PSyslzRx-lkp@intel.com/

All errors (new ones prefixed by >>):

   arm-linux-gnueabi-ld: drivers/firmware/qcom_scm-smc.o: in function `__scm_smc_call':
>> qcom_scm-smc.c:(.text+0x39c): undefined reference to `qcom_shm_bridge_free'
>> arm-linux-gnueabi-ld: qcom_scm-smc.c:(.text+0x3f0): undefined reference to `qcom_shm_bridge_alloc'
>> arm-linux-gnueabi-ld: qcom_scm-smc.c:(.text+0x53c): undefined reference to `qcom_shm_bridge_free'
diff mbox series

Patch

diff --git a/drivers/firmware/qcom_scm-smc.c b/drivers/firmware/qcom_scm-smc.c
index 16cf88acfa8e..6045be600c2a 100644
--- a/drivers/firmware/qcom_scm-smc.c
+++ b/drivers/firmware/qcom_scm-smc.c
@@ -11,6 +11,7 @@ 
 #include <linux/firmware/qcom/qcom_scm.h>
 #include <linux/arm-smccc.h>
 #include <linux/dma-mapping.h>
+#include <linux/firmware/qcom/shm-bridge.h>
 
 #include "qcom_scm.h"
 
@@ -161,6 +162,7 @@  int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
 				    ARM_SMCCC_SMC_32 : ARM_SMCCC_SMC_64;
 	struct arm_smccc_res smc_res;
 	struct arm_smccc_args smc = {0};
+	bool using_shm_bridge = qcom_scm_shm_bridge_available();
 
 	smc.args[0] = ARM_SMCCC_CALL_VAL(
 		smccc_call_type,
@@ -173,8 +175,12 @@  int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
 
 	if (unlikely(arglen > SCM_SMC_N_REG_ARGS)) {
 		alloc_len = SCM_SMC_N_EXT_ARGS * sizeof(u64);
-		args_virt = kzalloc(PAGE_ALIGN(alloc_len), flag);
-
+		if (using_shm_bridge)
+			args_virt = qcom_shm_bridge_alloc(NULL,
+							  PAGE_ALIGN(alloc_len),
+							  flag);
+		else
+			args_virt = kzalloc(PAGE_ALIGN(alloc_len), flag);
 		if (!args_virt)
 			return -ENOMEM;
 
@@ -196,7 +202,10 @@  int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
 					   DMA_TO_DEVICE);
 
 		if (dma_mapping_error(dev, args_phys)) {
-			kfree(args_virt);
+			if (using_shm_bridge)
+				qcom_shm_bridge_free(args_virt);
+			else
+				kfree(args_virt);
 			return -ENOMEM;
 		}
 
@@ -208,7 +217,10 @@  int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
 
 	if (args_virt) {
 		dma_unmap_single(dev, args_phys, alloc_len, DMA_TO_DEVICE);
-		kfree(args_virt);
+		if (using_shm_bridge)
+			qcom_shm_bridge_free(args_virt);
+		else
+			kfree(args_virt);
 	}
 
 	if (ret)