Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4279979ooa; Tue, 14 Aug 2018 03:57:40 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwtF7EnQqZCrxU5p092hwgodBQYvtk8VBjtiXKc370Nb5Vy8aW71Xf90OOQiSgLjZI8p3Oi X-Received: by 2002:a63:9f0a:: with SMTP id g10-v6mr20583846pge.324.1534244259999; Tue, 14 Aug 2018 03:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534244259; cv=none; d=google.com; s=arc-20160816; b=J4XRfr8Nt0WRDqmf01crDqxiS3yJUFDviXFvWRkb9Xq4n0tIuiVflSCTKqapRGcR38 uKCxqDbsCydwSbI4fXXB8Pooobdul/oc2ccC4ChjB8hFeMsXvDnW0gb1/O4/8eWU/Iy0 AHbnUBT5jxKOQJluE5F0HwXHckeIRbUVj9LOwPditycPDu1PF/UnxqoBnOy0LUncfN+m 750aoZN8f2DOO4tiJY7bseAthatDoGfZZakX/Bw+bHlfRx0J0sZ+dOCnYFenLRwzwhp2 WXItISZHp28nPX6RgzZWGIquxN1Mo3NUfhnhpJGQF2TcstD4r4X7Tw5egytNmXbzUJfl G79A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=LvYelZC3qusa2JutTziI+qvE6c0nT7x0/Be8qAYPqq0=; b=RFfi5ifPbdMGER0rSQjGzzRvAriXtaXMkQykWPKd/ZMW5+ZR70IZ862Nn8NqJOVzmp 5EIzZQw8b32h9QO4+yaarRF2ysdmG7oVKIHmOjszLi187OBWl0XLEuT3VQAWvhtdYOfD U84dvFPuBuwJIr6Katud3WzcMkdoy/kWfMZumzzHLdceXKqB14pK2hQACR2WBYkRofiT dW9mi0NTpU2bJ60YD1lyU2l4EpIxZcjgMcoSxYRzJ7hkO6W1J+HnuZlO6AQ8s95uFfiy ZAzxwMLejbrXPT1Lf7Rt+Of+6lS/5DcSCh8bKqGECXI4vN4C4J6uONhvtBkUmL8X9pl2 IiUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="G2/G4N3y"; dkim=pass header.i=@codeaurora.org header.s=default header.b=TXRJusJ0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e15-v6si17376721pli.149.2018.08.14.03.57.25; Tue, 14 Aug 2018 03:57:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b="G2/G4N3y"; dkim=pass header.i=@codeaurora.org header.s=default header.b=TXRJusJ0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732154AbeHNNm0 (ORCPT + 99 others); Tue, 14 Aug 2018 09:42:26 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:51786 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbeHNNmZ (ORCPT ); Tue, 14 Aug 2018 09:42:25 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 42ADF60807; Tue, 14 Aug 2018 10:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1534244146; bh=jbGwEGvIboJmsJey8JBBw2mYvZ7/OZ3on0hIwl7XBaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G2/G4N3yavzSqQpZNo5oEwPIqLij2HlL2+s33O2Eb+zZUrm942A7WmpWhdnkpq3wx kAThXgiHc4H2jSQjms+g1eiQFAOnBhhOE6ruH355keuE93BpVr/Pb9t/l97YSvVz6s cyS92wkPWLQmYk9P/xg1M0UDS+BBsRlLhzEhlmLY= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from blr-ubuntu-41.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D8A1C60807; Tue, 14 Aug 2018 10:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1534244145; bh=jbGwEGvIboJmsJey8JBBw2mYvZ7/OZ3on0hIwl7XBaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TXRJusJ0wdgZ3sLPPtswoQ0KiAMXJrkluG6hbUV61pglwG4kXRkCoA0p8TmgU4e1r QhGHnOtmtxrh7iILkYbUOXhDt3pQZryWbMHD0DcbRPqTmQB2X5TKTy00AF3TXUwJnl opVdK+w8qIan8Isb/aXIKMA4knICg1/fbyDsPRDQ= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D8A1C60807 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: joro@8bytes.org, andy.gross@linaro.org, will.deacon@arm.com, robin.murphy@arm.com, bjorn.andersson@linaro.org, iommu@lists.linux-foundation.org Cc: mark.rutland@arm.com, david.brown@linaro.org, tfiga@chromium.org, swboyd@chromium.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Vivek Gautam Subject: [PATCH 1/5] firmware: qcom_scm-64: Add atomic version of qcom_scm_call Date: Tue, 14 Aug 2018 16:25:24 +0530 Message-Id: <20180814105528.20592-2-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 2.16.1.72.g5be1f00a9a70 In-Reply-To: <20180814105528.20592-1-vivek.gautam@codeaurora.org> References: <20180814105528.20592-1-vivek.gautam@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are scnenarios where drivers are required to make a scm call in atomic context, such as in one of the qcom's arm-smmu-500 errata [1]. [1] ("https://source.codeaurora.org/quic/la/kernel/msm-4.9/ tree/drivers/iommu/arm-smmu.c?h=msm-4.9#n4842") Signed-off-by: Vivek Gautam --- drivers/firmware/qcom_scm-64.c | 136 ++++++++++++++++++++++++++++------------- 1 file changed, 92 insertions(+), 44 deletions(-) diff --git a/drivers/firmware/qcom_scm-64.c b/drivers/firmware/qcom_scm-64.c index 688525dd4aee..3a8c867cdf51 100644 --- a/drivers/firmware/qcom_scm-64.c +++ b/drivers/firmware/qcom_scm-64.c @@ -70,32 +70,71 @@ static DEFINE_MUTEX(qcom_scm_lock); #define FIRST_EXT_ARG_IDX 3 #define N_REGISTER_ARGS (MAX_QCOM_SCM_ARGS - N_EXT_QCOM_SCM_ARGS + 1) -/** - * qcom_scm_call() - Invoke a syscall in the secure world - * @dev: device - * @svc_id: service identifier - * @cmd_id: command identifier - * @desc: Descriptor structure containing arguments and return values - * - * 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, - struct arm_smccc_res *res) +static void __qcom_scm_call_do(const struct qcom_scm_desc *desc, + struct arm_smccc_res *res, u32 fn_id, + 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); + + 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); + + if (res->a0 == QCOM_SCM_INTERRUPTED) + cmd = res->a0; + + } while (res->a0 == QCOM_SCM_INTERRUPTED); +} + +static void qcom_scm_call_do(const struct qcom_scm_desc *desc, + struct arm_smccc_res *res, u32 fn_id, + u64 x5, bool atomic) +{ + int retry_count = 0; + + if (!atomic) { + do { + mutex_lock(&qcom_scm_lock); + + __qcom_scm_call_do(desc, res, fn_id, 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); + } else { + __qcom_scm_call_do(desc, res, fn_id, x5, ARM_SMCCC_FAST_CALL); + } +} + +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) { int arglen = desc->arginfo & 0xf; - int retry_count = 0, i; + int i; u32 fn_id = QCOM_SCM_FNID(svc_id, cmd_id); - u64 cmd, x5 = desc->args[FIRST_EXT_ARG_IDX]; + u64 x5 = desc->args[FIRST_EXT_ARG_IDX]; dma_addr_t args_phys = 0; void *args_virt = NULL; size_t alloc_len; - struct arm_smccc_quirk quirk = {.id = ARM_SMCCC_QUIRK_QCOM_A6}; + gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL; if (unlikely(arglen > N_REGISTER_ARGS)) { alloc_len = N_EXT_QCOM_SCM_ARGS * sizeof(u64); - args_virt = kzalloc(PAGE_ALIGN(alloc_len), GFP_KERNEL); + args_virt = kzalloc(PAGE_ALIGN(alloc_len), flag); if (!args_virt) return -ENOMEM; @@ -125,33 +164,7 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, x5 = args_phys; } - do { - mutex_lock(&qcom_scm_lock); - - cmd = ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, - qcom_smccc_convention, - ARM_SMCCC_OWNER_SIP, fn_id); - - 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); - - if (res->a0 == QCOM_SCM_INTERRUPTED) - cmd = res->a0; - - } while (res->a0 == QCOM_SCM_INTERRUPTED); - - 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); + qcom_scm_call_do(desc, res, fn_id, x5, atomic); if (args_virt) { dma_unmap_single(dev, args_phys, alloc_len, DMA_TO_DEVICE); @@ -164,6 +177,41 @@ static int qcom_scm_call(struct device *dev, u32 svc_id, u32 cmd_id, return 0; } +/** + * qcom_scm_call() - Invoke a syscall in the secure world + * @dev: device + * @svc_id: service identifier + * @cmd_id: command identifier + * @desc: Descriptor structure containing arguments and return values + * + * 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, + struct arm_smccc_res *res) +{ + return ___qcom_scm_call(dev, svc_id, cmd_id, desc, res, false); +} + +/** + * qcom_scm_call_atomic() - atomic variation of qcom_scm_call() + * @dev: device + * @svc_id: service identifier + * @cmd_id: command identifier + * @desc: Descriptor structure containing arguments and return values + * @res: Structure containing results from SMC/HVC call + * + * Sends a command to the SCM and waits for the command to finish processing. + * This should be called in atomic context only. + */ +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); +} + /** * qcom_scm_set_cold_boot_addr() - Set the cold boot address for cpus * @entry: Entry point function for the cpus -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation