Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2032201lqb; Mon, 27 May 2024 05:58:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9wxu4tLW9p7zAyPlhpeM8VyYYSv75VwJXNYhVz4ppACLTZdWDCuSKCSqUVRenSIYKRhrs9HI2L8OOBesZUXG5Q3KUWSVkRdpICz5qRg== X-Google-Smtp-Source: AGHT+IGr3jDhnDa4yeBdFqsdsUYxzVGjmsj8i0ql1q+hnY25bFkGr2I7ObubvV9Km9VCzX2Mukuh X-Received: by 2002:a05:6214:590b:b0:6ab:8a43:9ae4 with SMTP id 6a1803df08f44-6abccfad2cdmr116509356d6.52.1716814711690; Mon, 27 May 2024 05:58:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716814711; cv=pass; d=google.com; s=arc-20160816; b=ECJhiOG1UOG55YrtztOFOK+BGn26aLOzVzsGKj8/LS9oiUTJGWdKbeFDV45rqftuSn qXvtIuqb6x6vaccBzp0/jnwasV/Xt0QyU2RKhDx0pEJ1MG6k+HwxpsPTfpx/R5uxrJch HNABmQDhBgZbBLnEClss1sTsgOEr41kzWcFP8Jc3M25frN2T8LWggBHdfCxeUzQ1EtJK Db8/NtDHfTe76FyTG+rJSBjLoXrYw6ShaSDqvbLcjGxJuwro2PneXF7mVS50642eFPPd OqsnyP3TljyxPXsiw4kgP8Qx3/GhpyZHyo6TLceoHATU8+6Uj7z0yXNzpKqQdH+IGj2G fZNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=WF/896sdGC2fcFcBLtp8Wafg57BR7Ezd4qNrSg9FQvk=; fh=gv3qC3quS+8FdGsdv/rDTdOgOGdYsbsfVxkr3uh4/yg=; b=qSgn+lA2ikdl3njaZUzBt3DRMSp95OiaDhToz/Mvogk8cyPegKVztI/MwFKZJcY7v+ aKDU2yoc/DaGI4BroKiCWpMMVb/ALFlD6A+0cnLCnP5jQYalft3ysPHTIGRwdHD2TMrN ONkf/ed/eNB+wIIBfzhwliiHCxzUP38H3crtRo4j63Fwk0yyIEKfrHvtxAKN0HZQMhas h0rSWPL0qaJqVP97WVDZ58Q0+/7hnLm/l73IDeiesZOQQthPmXl5sHRshHX/kymxR9v7 Cf1pwNIajasrdEz1c94AiOeufVstZDb1pCytEoAi8a881UTLcu+GdN85tAT8UeK4tPHL aWOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=BwN7a7pB; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-190628-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190628-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac162b3837si79431076d6.438.2024.05.27.05.58.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:58:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190628-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=BwN7a7pB; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-190628-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190628-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 303921C228EC for ; Mon, 27 May 2024 12:58:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A24115FA6D; Mon, 27 May 2024 12:56:53 +0000 (UTC) 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="BwN7a7pB" Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 EDAF815F324 for ; Mon, 27 May 2024 12:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716814611; cv=none; b=kro/7kZclY1SNHVMXURQkh0uUaE4fP4IUlW17Ir+aLG4Q4zjOPesrmQl59o4d3hI55mvu26rmdeMayZCPTwx5/2iuBXGnDmyciQxZooxwG8j7F2RYCXxaiW49GZ2E4AqGSQ2aklsgHom8sJbJ6QJDAo9wAUNwXGGGvCVQYXiv9o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716814611; c=relaxed/simple; bh=IA1NluuyWIC8/XotvFbpj4DqgZjTYuJun/bo3v6zFBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HzcPEUE8KmM9nbn6t2G4E0Zzmz1/6ZZA9vFUbC7LGqqKekoVxULGgihBLq2+KyRI3UhKHcSXAGi0hlfGA3QHzzGnp5UNmKDjzFt6k33dfgn/zVXXOt0AG8viVnkSEatil2yvRjzrBCyKzlb35wDC3pPMFJmqyCinZ+rORB89Yu0= 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=BwN7a7pB; arc=none smtp.client-ip=209.85.128.41 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 Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-421124a04d6so9549775e9.3 for ; Mon, 27 May 2024 05:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1716814608; x=1717419408; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WF/896sdGC2fcFcBLtp8Wafg57BR7Ezd4qNrSg9FQvk=; b=BwN7a7pBxyMNT2BPrOB6//1t4gazuGS0ola5489MnPgkYFfHLf/LayfkbNmsaJ9NHz qL6mY09AnVwYf+/GpbTTN55+vsHFpFDzKDjav/oETT3mDaY7dar6jVikQr6UEL96IY5K jJ0Jod2BqYtcwi1W44/8nU+VVneU79Qu0nohZbQlc0/wBGoHuJruU+GGSUrsjvIpsl// kigZYE8gPVcQSMvfyPicbbae8yDTbD6b75fD7KTeOyntJCBt2RMgE/5IM0xDJBlBfunL mfxOQbXzYmgoFkwtXmeLY15wNNacsOJeasMv5YUM1SHkesOqkAqFOcROCLC6a3T+6ic1 ycdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716814608; x=1717419408; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WF/896sdGC2fcFcBLtp8Wafg57BR7Ezd4qNrSg9FQvk=; b=pUdWk0snbWRnsZrGjMwqGbQ3FvjvvSmyaEKfVC7Fxh7V6Ws/ipRpaoA2vrvju4deve bBULQfVBL5jKhDIhftUNGOQ3myC4acodT1uKHOGt8uVJIVsl3otOaQszHqD4XYowAJsy tPtluTwMgQEtO5Nuuov/2pnFU/yyCgKC+8dgsHYQvT1yGPVXq9bu+f08iANCgHSBehEv jTvLEZmMbvzbAPAFrp1X05z2EJ0tFym5ivB+Nv5GnIPqwKkZXJW2VnYdvaLp/JS2fMPZ 9ickyGB8rCIhshFXfiIc7x2ZSP0jvUoRrJJZC7ixn0skuHDJ3KhQc6fE8wSAxHPEa5wH XBtQ== X-Forwarded-Encrypted: i=1; AJvYcCUNIyPSgon3l16VU1yqcQrlfMzinz6ASSAVu/lWHe0skuXY+sms3G4QKeByDm8HM8FA5sn0Qo+izxHNhxnVF3DEXPghTCg3/zW09YjQ X-Gm-Message-State: AOJu0YwqYWD8WQif5MmMuK/TxLS9/xffld6MJnHaRLihQh5JsRqpF6L3 MAlG1tjGycvfoBnFT5ZaPzTzXGe5heOAT47ctJYbjVTX1A1qJxnrKLWD4iNK9Y4= X-Received: by 2002:a05:600c:5103:b0:420:1a3:dd04 with SMTP id 5b1f17b1804b1-421089eeb0emr77231195e9.24.1716814608651; Mon, 27 May 2024 05:56:48 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:75a:e000:c322:131e:ff9d:ef41]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f64f98sm138753635e9.24.2024.05.27.05.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:56:48 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 27 May 2024 14:54:54 +0200 Subject: [PATCH v10 04/15] firmware: qcom: scm: smc: switch to using the SCM allocator Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240527-shm-bridge-v10-4-ce7afaa58d3a@linaro.org> References: <20240527-shm-bridge-v10-0-ce7afaa58d3a@linaro.org> In-Reply-To: <20240527-shm-bridge-v10-0-ce7afaa58d3a@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Marko , Das Srinagesh , Bartosz Golaszewski , Maximilian Luz , Catalin Marinas , Will Deacon , Srini Kandagatla , Arnd Bergmann , Elliot Berman , Alex Elder Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Andrew Halaney , Deepti Jaggi X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4759; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=h5olK4FER0ASPIH9I24ILYd6rhf4aQB9nxqDbU4jzPQ=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBmVIMIyg5jo/L/Pq/AFrA6tqCdM/FV+kOCl9Jvh 9x10vovHz6JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZlSDCAAKCRARpy6gFHHX crPBEADcf+aTOBUDz3TteutQQXSR2p0IkTWki6VzWv78A4/keZyujHuYKtncGvbAuj+6ZKyKgMS 5sf+bvySqH8yFjx+92RWsjsEuaT8zZyFPs3sBnXGP/gzvhaGOZCAQwALHTFhJMfTbnuULIadXGf N3EmwU+nq+C5C1tA83qr2bTIc8GD8SiJMKzuT/POGAeNEKIR8EBl3n0D7U1Sna2uL/cBPltdlRi AQ5rjhLsVBGP0ISuAbA9E9EyoMFXaJVKwneZPh/yaApP/DPuFyf5BrBGautvBjPmmjXcaDV9D7X DixeVaP0uwD6B8H781xIIqrGw7HQ5Hhdm9cbXUK2fJ662TFXbBpTE7mowYiM7iV1hgIm6FkT+jC pS0IihiMPowRhrZevczmdsNs5UrIyOf/qb/i//WOiH/DPE1cYUCX3H4XPo+I7oumnPyOBmNrXuo MSUV4PhrBjHIG+pYM4Ums4XpuATvQn5gXYMLY1gGxYO/4Etxz8qpk8gzBjLxKn9a98ZpgOkTw+y kTM8l7VDe34XO/aAnTgqAmwpdnuKeUJYxHQpfBooNwgqjlzpxHEcrF3X1iE5NZjQQ3sSi6Rh94r 0B0M4JW0ase1UWp3zIvpA77sIH0nohTmnHDT6n/hiaOwAURP0yXY1yhP5WMdY+DhiWxXjBYH2xG A5JGP5lDbaY1dIQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 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 0e7b1813e4a7..1d207c14afc8 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -204,6 +204,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 -- 2.43.0