From patchwork Mon May 27 12:54:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13675196 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8068C25B74 for ; Mon, 27 May 2024 12:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4LBWQ6nSGdY/yZljWoOqgTLLuprHavZ+0YjTjsRxzgw=; b=vzr6Nwm9zyt0MP s2UcWAzERI5SpysKvqc6uOOd6ApqgRin0pKFtWG4XyKE+DubHlotbw8cq0p5sG/CdKJZqhltW3ema t2XR0fSMGvj9bXnXMpkjR0s39ziOlRfPU+RyyrrrU3+DclCDhEKT31gNRyCwk5IjQW7uKY/saTg/d hgmQmv3pRRM6fNTruKwPp2TxfSLd9nk4RgLYvQeMk3Z+Dm9qk0timmSw7lEuMUZENwtMcyJO4QuVr nxm3viBs1jyNIGC/vShO1jaVND6QtzrixpilkPBtfQI5zwdS1G+lDLPJwmiHyszzzKWCRFsol6kCZ TkIWoMov+6ZoB/eGpcAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBZuV-0000000ExmU-2DIV; Mon, 27 May 2024 12:57:07 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBZuH-0000000ExZR-0m6B for linux-arm-kernel@lists.infradead.org; Mon, 27 May 2024 12:56:54 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-529b4011070so518800e87.1 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=lists.infradead.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=H+cLvo74QVnhzgz8Xflm3n4b7nMWc8jqZkEXgEWJK9g=; b=qKZNO/V80OKornJ7chH9856vQpMvvYpFAhITujI8WC3lyYGGrqiKwIo9H9CT7KcVKE 5nyCQX6EvfBxCWC7/GsIcQ9xof4Man2YEAhuvouNBWcIb19hcHMR6qg6UIORPZJ4WoKn 4Bv7T4ejV7ycCKU53Ej8dA5ywwJmSB67LZIRQjorwVnNUXpfaaqsatfaKHVRYvPiEPBX p4RX+NcvRBeE9vJhbQyp8jHf/MyDM1iSuWBk8/JZSHx1FB+F6WKAsfWI7klBYYZw+PdK yNEDRk7gCHiqdah/WLs26M86ai1MzmuUaEcwlgEsoZC0ptV0QLY4F8SZdN1jrGqQYYRp WhbA== 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=H+cLvo74QVnhzgz8Xflm3n4b7nMWc8jqZkEXgEWJK9g=; b=iDWMSalSAd5m1F1afIWATfbiaknUvNC/lCg/1N9cZcvcDclMqb2HRca2fnukJMft0W cZ7p5MrBXNvH+ZsbhkP1EXZadgkZE2w/Z+l+8M+WDEBV+waVhJEMCbTaX9VBdVh6501e YUT0y8yYg5oV0OiNA0k00sLKW28EabKRTdIehCw28fR9xV1g4PBjuYGQDlKF06SN5YWR 7eosGjaSTegaB0C7orNf9GxmDdtq/0tWCKsrjSLbRiyhSBmXgYdMboQiF8xYF3ZEnSUq uLlQFhcw8J23MPExV2OO68Epc8RBA1W6l656x3NqNhVN8XaQdD9JHkW3ULo9uv6XaT3I UI8w== X-Forwarded-Encrypted: i=1; AJvYcCVHqtrt+19Ll1raqQZogetMSloADxKpgF94ylhPZgn0VjcPvyMAS5Z04Cy2sM6m0dG3Fi+kwdqEBNjzqvDimIC0QlJPJb33CyHgXKpdXlIj6OdVi54= X-Gm-Message-State: AOJu0YwdsxpheuSIZEaXX8cpuAl/6N5s5m2soYK3b6Dca1w7jGdOLN6z C0ECw75vmgbAC824A5+APqKjjAylXxSRMdbm465uCQQNDyMJyKh/4zhRD+vQ2J0= X-Google-Smtp-Source: AGHT+IHQ8ItaW+iFK5OlRvGfWq9EA4HNWzDi5E9PtyhLZERWJa54SDX5gErpbt5Wh8NI7hgohYlWHg== X-Received: by 2002:a19:8c07:0:b0:519:5df9:d945 with SMTP id 2adb3069b0e04-529642048d7mr5320820e87.4.1716814607620; Mon, 27 May 2024 05:56:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:56:47 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 27 May 2024 14:54:53 +0200 Subject: [PATCH v10 03/15] firmware: qcom: scm: enable the TZ mem allocator MIME-Version: 1.0 Message-Id: <20240527-shm-bridge-v10-3-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=3441; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=VMZSfmk3eqpWY9NL2dFp3h21LWVeHTxpNDflrZ1eZOM=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBmVIMITyNKHp5skdmBs6KrCE/1XNv7+uwrxG3r+ wU+iovCRPOJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZlSDCAAKCRARpy6gFHHX cowGEADgV7KVfui358E++tzUTQN3sMCwCUSy7jyWtCxHOOyGfyLAH9Tyy54loxpX2KuPJMAp8XL 3TNTe8VbUq8C5btZUZzivDiObnKDb/r6mKy0VIIXmzCTN+R9tpPVLCYrnsKTFgRkchSXqT6pVkH 579wmhzUMWRDSMMhgLRG32LpWG4lfeCqpBTUzt+A4VuN/y7MRO4/LD+0cpa7RKiYRThG8UgEJf/ nqkOR1fEP8rarhb9NCd+su7Xid31VX6Nmhe6d+6tkGLo32UDzVpJvC9CULkUBPRE41TIuvqt8WM GWTVtDYOe/23q/PBQTAr9RGjoiHbw5LeiSpGYxOAHivq3F3Lse81h1jm9+24g5x9azaePNN2fx5 PuesDthSkdfBdA7BzHnru6p2XTNIl0xWbQJQbNiDVBoUJ48sm7DoVWvbKJzJUvmjsoQlfNfpNFF MqDzdLyRM3MkJSvXFACc/YmBNLrbzWrQOcMiRYPOmSVdPMHNZYPYLDnJaG0MT1aVvZ4hHOXE4/Z Q/nRTUop3ZZDiFCw5d4t/CyPCiU2z6Bpv2QpK+sCw8kEZZdaE366AdJPlUQRIleN9/VLUVGQDiU MJGkTnIkIo3nppSe/UgvlzBQ5ETN4O9jRFGLYkAYCaspvnvDx7CasHvjI60bit8IemPFj7aXYep v6XkJxmG2+pp3lg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240527_055653_274524_4169F7E1 X-CRM114-Status: GOOD ( 18.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Select the TrustZone memory allocator in Kconfig and create a pool of memory shareable with the TrustZone when probing the SCM driver. This will allow a gradual conversion of all relevant SCM calls to using the dedicated allocator. The policy used for the pool is "on-demand" and the initial size is 0 as - depending on the config - it's possible that no SCM calls needing to allocate memory will be called. The sizes of possible allocations also vary substiantially further warranting the "on-demand" approach. 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/Kconfig | 1 + drivers/firmware/qcom/qcom_scm.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index 3c495f8698e1..4634f8cecc7b 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -7,6 +7,7 @@ menu "Qualcomm firmware drivers" config QCOM_SCM + select QCOM_TZMEM tristate config QCOM_TZMEM diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 68f4df7e6c3c..0e7b1813e4a7 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -10,8 +10,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -22,9 +24,11 @@ #include #include #include +#include #include #include "qcom_scm.h" +#include "qcom_tzmem.h" static bool download_mode = IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT); module_param(download_mode, bool, 0); @@ -43,6 +47,8 @@ struct qcom_scm { int scm_vote_count; u64 dload_mode_addr; + + struct qcom_tzmem_pool *mempool; }; struct qcom_scm_current_perm_info { @@ -1810,6 +1816,7 @@ static irqreturn_t qcom_scm_irq_handler(int irq, void *data) static int qcom_scm_probe(struct platform_device *pdev) { + struct qcom_tzmem_pool_config pool_config; struct qcom_scm *scm; int irq, ret; @@ -1885,6 +1892,21 @@ static int qcom_scm_probe(struct platform_device *pdev) if (of_property_read_bool(pdev->dev.of_node, "qcom,sdi-enabled")) qcom_scm_disable_sdi(); + ret = qcom_tzmem_enable(__scm->dev); + if (ret) + return dev_err_probe(__scm->dev, ret, + "Failed to enable the TrustZone memory allocator\n"); + + memset(&pool_config, 0, sizeof(pool_config)); + pool_config.initial_size = 0; + pool_config.policy = QCOM_TZMEM_POLICY_ON_DEMAND; + pool_config.max_size = SZ_256K; + + __scm->mempool = devm_qcom_tzmem_pool_new(__scm->dev, &pool_config); + if (IS_ERR(__scm->mempool)) + return dev_err_probe(__scm->dev, PTR_ERR(__scm->mempool), + "Failed to create the SCM memory pool\n"); + /* * Initialize the QSEECOM interface. *