From patchwork Sun Mar 3 15:01:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13579805 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC1CA67C4A for ; Sun, 3 Mar 2024 15:01:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709478089; cv=none; b=TvqzDlj3iV4ZI5MuREw0R3/wHF9CCcPD+QNgsvzt3KOz7FG2+7xtd9UemNMU7rJrzbzpV1E7Ij5IUfnbjCBZJrSjk2q3/QAIveV1vuOjIwJ3bgVuHAa50qI4bAf25qeHoi4GKTruUVXKdTVh7XwxgaXcIbB4yEClj0pcXOnNBok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709478089; c=relaxed/simple; bh=pS036l+x82Llg2p1uvJEt9ipJarTOiZ0UoUxwLijsek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pFl2Db0VIoa0zGjFIMgiN1JLWNsuutXpYlZcF9fo9faPbVS+MuW6m5+SuX0yh6mKyIMU1sLKmxhhRNSpCF5cF7q2nYQqCpWsdtIEKedz2al9w5Ndsks1vwTAVYXgeZX3KPaLs4oHhbWK+RtQ49Gf1rG66qnJCXm888XbnC/rS0Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=P1AO/Fye; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="P1AO/Fye" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a3ed9cae56fso876779166b.1 for ; Sun, 03 Mar 2024 07:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1709478086; x=1710082886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+rx6WhoOKHd930tN5aNHnayXx6/+P2ppH5dnNIXc394=; b=P1AO/Fye0PHA7KtHk8tlNl6Z+z9KesP3NaUOBiFIRSyyagcaSlzCHX8ElJu9KuuLFU 2Q3dOZfvIg7xJhpxceC6qoCf7GaUAGmvTPJc7GDdwQQJlEzKZiHXlMSvyCyem3sYQYw/ UTSL8pvdpU0duuOd2E9w7B8GX6eW+B0Yux8iRbAxIk7AylwAVLizJwN2KAoEoDaZ8DE/ BMXFLXKjq2QYFSFtWE782YW4Ac9SXJ9UsGBVRNqtSjJ9DLl46ep8gPSpTH7LWXfr5XaW IPjyk/wCfEg7uRrPa1cFN00eenj5IcC6oF+Mtn2z4weeBkK0vrRO6OhauR8e5oSkhsOf r8lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709478086; x=1710082886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+rx6WhoOKHd930tN5aNHnayXx6/+P2ppH5dnNIXc394=; b=EjC5pWXlH+EMEbPOh3/MCzMaJkpzNm1gSEGpuIyaG3S8MvWOXV2ATkm/DdzMTmCEHL Kxi1DUlDTTRemBDavuq8sH056wIbjCUcQ8Td7nk/UqYqibWgKeNV/nJ7Zs71H+Amu3Re Du4DNYqruYJMkvMNNIKn60WLfjS0WgEelZzI9Pww0k6ZRKcozOWN19b5uIxSpNFn6q0t 8Y8DlC77lILpywmCdjn0zb5X5nN32tedzwkzrBGPAqG2YmLGeiFcSV8SBxDXNYDbTdCj z77ZsLwApta6cNqkG/83YQYbDAAOiCOSxi18Cba2ZGYBY/aekQF0xoO1r997WvW4Jwoo uAGg== X-Gm-Message-State: AOJu0YyKA9DWSJXZWvX4VEOej2hw5tU0Nbf9DtihUyPdPAeYXB1LGYEO rSR4dyviD7nEj9LqnwQfSumzFp4GdivaDJKh980ZGew0b0nkJpKl3mA0dqVEc1Q= X-Google-Smtp-Source: AGHT+IEFw76mgrpMh6IeOkCj0OFPooV98kmqRrBujSc3qj3cEutdadkohNDk2tLT2hL3o3DDycNy9Q== X-Received: by 2002:a17:906:2c12:b0:a43:acbd:db59 with SMTP id e18-20020a1709062c1200b00a43acbddb59mr6020253ejh.3.1709478086154; Sun, 03 Mar 2024 07:01:26 -0800 (PST) Received: from brgl-uxlite.. ([77.241.232.10]) by smtp.gmail.com with ESMTPSA id ch14-20020a170906c2ce00b00a42ea946917sm3740293ejb.130.2024.03.03.07.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 07:01:25 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski , Deepti Jaggi Subject: [PATCH v8 03/12] firmware: qcom: scm: smc: switch to using the SCM allocator Date: Sun, 3 Mar 2024 16:01:06 +0100 Message-Id: <20240303150115.133633-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240303150115.133633-1-brgl@bgdev.pl> References: <20240303150115.133633-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski We need to allocate, map and pass a buffer to the trustzone if we have more than 4 arguments for a given SCM call. Let's use the new TrustZone allocator for that memory and shrink the code in process. As this code lives in a different compilation unit than the rest of the SCM code, we need to provide a helper in the form of qcom_scm_get_tzmem_pool() that allows the SMC low-level routines to access the SCM memory pool. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm-smc.c | 30 ++++++++-------------------- drivers/firmware/qcom/qcom_scm.c | 5 +++++ drivers/firmware/qcom/qcom_scm.h | 3 +++ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c index 16cf88acfa8e..dca5f3f1883b 100644 --- a/drivers/firmware/qcom/qcom_scm-smc.c +++ b/drivers/firmware/qcom/qcom_scm-smc.c @@ -2,6 +2,7 @@ /* Copyright (c) 2015,2019 The Linux Foundation. All rights reserved. */ +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include @@ -150,11 +152,10 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, enum qcom_scm_convention qcom_convention, struct qcom_scm_res *res, bool atomic) { + struct qcom_tzmem_pool *mempool = qcom_scm_get_tzmem_pool(); int arglen = desc->arginfo & 0xf; int i, ret; - dma_addr_t args_phys = 0; - void *args_virt = NULL; - size_t alloc_len; + void *args_virt __free(qcom_tzmem) = NULL; gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL; u32 smccc_call_type = atomic ? ARM_SMCCC_FAST_CALL : ARM_SMCCC_STD_CALL; u32 qcom_smccc_convention = (qcom_convention == SMC_CONVENTION_ARM_32) ? @@ -172,9 +173,9 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, smc.args[i + SCM_SMC_FIRST_REG_IDX] = desc->args[i]; 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); - + args_virt = qcom_tzmem_alloc(mempool, + SCM_SMC_N_EXT_ARGS * sizeof(u64), + flag); if (!args_virt) return -ENOMEM; @@ -192,25 +193,10 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, SCM_SMC_FIRST_EXT_IDX]); } - args_phys = dma_map_single(dev, args_virt, alloc_len, - DMA_TO_DEVICE); - - if (dma_mapping_error(dev, args_phys)) { - kfree(args_virt); - return -ENOMEM; - } - - smc.args[SCM_SMC_LAST_REG_IDX] = args_phys; + smc.args[SCM_SMC_LAST_REG_IDX] = qcom_tzmem_to_phys(args_virt); } - /* ret error check follows after args_virt cleanup*/ ret = __scm_smc_do(dev, &smc, &smc_res, atomic); - - if (args_virt) { - dma_unmap_single(dev, args_phys, alloc_len, DMA_TO_DEVICE); - kfree(args_virt); - } - if (ret) return ret; diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 2245ec8278e0..c1c4809b154c 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -201,6 +201,11 @@ static void qcom_scm_bw_disable(void) enum qcom_scm_convention qcom_scm_convention = SMC_CONVENTION_UNKNOWN; static DEFINE_SPINLOCK(scm_query_lock); +struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void) +{ + return __scm->mempool; +} + static enum qcom_scm_convention __get_convention(void) { unsigned long flags; diff --git a/drivers/firmware/qcom/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h index 4532907e8489..aa7d06939f8e 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -5,6 +5,7 @@ #define __QCOM_SCM_INT_H struct device; +struct qcom_tzmem_pool; enum qcom_scm_convention { SMC_CONVENTION_UNKNOWN, @@ -78,6 +79,8 @@ int scm_legacy_call_atomic(struct device *dev, const struct qcom_scm_desc *desc, int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc, struct qcom_scm_res *res); +struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void); + #define QCOM_SCM_SVC_BOOT 0x01 #define QCOM_SCM_BOOT_SET_ADDR 0x01 #define QCOM_SCM_BOOT_TERMINATE_PC 0x02