From patchwork Sun Mar 3 15:01:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13579816 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 C0FE7C48BF6 for ; Sun, 3 Mar 2024 15:01:43 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=drrEHowZtxASnQQr4wdlxgt/hWHw8aKMHiEj5EEb9sg=; b=mm49GC2gQXwFgX mGD6X6JMWGq5mXfkMab+lHDvI5huq5Tab0MdOb+Iy61Xo3giH75MWCLlmKg+/wCweoGF44Qt2AaTt NTqEHFXohvh+BfgljQ6+y/zn/Y370Ev6D+W/U4oCY1rrp5Gz/IAhCZzy1G7LKA+iQLmME8A+7u5D0 SFFwaC56xzSTgZiDBHxhKOAnLTbEJf3XWwq1KHf6EYgwQvfky4Qz3zn9w/WNjnVgb4ZxtNXOy92W7 DW74ZGeyJ08Je8M7EtUq+HyP3OkxIWmTfIqRXiCaxq64uSOjK8VfnoVs5ilFauSUPvdpm8kkrkIcM /talHJEW2bQO1pKtmqlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgnLJ-000000068HQ-2IMV; Sun, 03 Mar 2024 15:01:33 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rgnLC-000000068CY-3XCU for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2024 15:01:28 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-56715a6aa55so772597a12.2 for ; Sun, 03 Mar 2024 07:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1709478085; x=1710082885; darn=lists.infradead.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=9f0fZ+mvuobwqRmEJ6FMeGs/lhMedUb8b4lbCQGk2+4=; b=UGOBZX+98u7oIgbFdsLIy3izPvfVdiNjleB4FrYRR48MtzfBjNWtkR7H2AMA2AuNtv Gu80mxE08AOpsErSPCaQ5AAO4GI66TXAeDdkQcgmXhesEZIc6iyID9KnbISEUtc5TkOT R2oounZkojAIs0oDoGhp6G8Ts9DlBz1OrE0bp6+mXLFtYlBxgBrEsPuKM2KGxfO0eFKH bQnE8XGPhTgdZWZVFqBIdONe78d4cH/L0dlCx6J6tUhSczA5Qhgs2v0h4yMzNu7TNmzb bjkoXJs+VaL4+Mb9cwlTThzEJTXnawTnCyrhbOxaRt3G/MhQEoC4uBvF9vypl0b6nCSa Jn9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709478085; x=1710082885; 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=9f0fZ+mvuobwqRmEJ6FMeGs/lhMedUb8b4lbCQGk2+4=; b=FvspimJZJnsQ7s6rYZfHGyLUb5CtDVDF/kyiK/oNQeksrLOKHyvnkMnO5suHkm6gr7 AyFR5gtb6//j8uLddf7WJRWVxRkQNJnik34j66PSWitjtjWrpYUvtu+FWQJZ6lRmxoyh C0lB4PmokRlPfaNeB6pdf99B+Nc1RFKa/flVICmOCaLls0Gvhj3ngSbkAI2J4UxofLT2 TwE0sGE3f2dn1IGqTDEoHq6OSZPZBWYKlaM5R+3QZs+sSywgG573Tk4A0plW7Y+cMsot kGfxlD08uMJyLhBuEmJFDIjl7LmjWtG2qScIKjcvon1awKf0Yysrc9+kX2Ptp7T8Dy7/ Pu6g== X-Forwarded-Encrypted: i=1; AJvYcCVWvMVf6pZXSyspyWmyG/AfLFwmf5q3MEa8RLCGBvGYffvQrND+4ioybTyfSvmGr8wIUkMVsNfmyaPscWnCvqaJLBg+j2wVrxf4JFoWdmRN3K4s/Hk= X-Gm-Message-State: AOJu0YwDeSsMb7sIXvZfAXGEEDDqg/mAVxBOOyqNkzxUuuI8feJN5B6T winCAK6I1gBQBHCRPSDX9fCtW9rcPy21Zpyhwp+YsXhq+Bm5s3TldfAPP9vTZy4= X-Google-Smtp-Source: AGHT+IGx+UAn5om3k3T5rx4lM6IEAlIbTzf7XS1OK8hZ2qhS6tn94N+XdFsJhI4ljzF0dHMof1lz3Q== X-Received: by 2002:a17:907:7677:b0:a3f:98e4:7dc9 with SMTP id kk23-20020a170907767700b00a3f98e47dc9mr4853658ejc.28.1709478085081; Sun, 03 Mar 2024 07:01:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 07:01:24 -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 02/12] firmware: qcom: scm: enable the TZ mem allocator Date: Sun, 3 Mar 2024 16:01:05 +0100 Message-Id: <20240303150115.133633-3-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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240303_070126_941622_5C91C939 X-CRM114-Status: GOOD ( 18.72 ) 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 520de9b5633a..2245ec8278e0 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -8,8 +8,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -20,9 +22,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); @@ -41,6 +45,8 @@ struct qcom_scm { int scm_vote_count; u64 dload_mode_addr; + + struct qcom_tzmem_pool *mempool; }; struct qcom_scm_current_perm_info { @@ -1812,6 +1818,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; @@ -1887,6 +1894,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. *