From patchwork Mon Mar 25 10:03:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13601733 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 C811EC54E58 for ; Mon, 25 Mar 2024 10:04:36 +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=5oCR2UvtPyVE75n/cE1TgQyk/vr6pVizRmsCS58naGs=; b=HwuYxB+n44ctML g3YKcXYkdlw/YAHly3Fawojf0mf0GPYtALDFBBymyR9fEWwp6BNCl+oWfqhJnxq28G82S7tah5+2J +O1P3s6r2d/xdexhR1uaCl7FwlYwLmuikOjbWhrY3M63pBwQOVK8zYdskPU/w7kfsgOa099XzSpoQ lOn3BmiQ2IprrOnk9UVvKraqyS/UQHY6k0stQSsW7aUZRPMkNmeVYhaS4APwscOXkS+CbvjCC2D9M dxzxVzGqyEPisf3zBbQA32EOAvKQ+oN5tf1RmFbaLGj4dTpnYBcnSi6sbfR/sLAC7bftnJDHaIs8g 0Nk6PL+zwdrDE70jB+9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohBj-0000000GcVU-25Jl; Mon, 25 Mar 2024 10:04:19 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohBZ-0000000GcPG-1nUG for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2024 10:04:10 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-515a81928faso1171416e87.1 for ; Mon, 25 Mar 2024 03:04:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1711361047; x=1711965847; 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=Ng5BrcKH2u1PepcO4ehhcz1HLdaVac5+yYLHKNMA3sg=; b=VsXxJbm6LLJJaKRta+n1XN4Mbm4Ptec7OPB3I5L40oGzbX57a6H8L0NqmXyYEGqQ88 7BNHXvhlSkkq0K+ADJaQmKN57p072YknA5yOdHnwm6v0VSPHGSceIxYwNWCMzsjNfGjX 5Lilm61CWQvK/6d9i5mdiV9aaB1VOIdULFa7Sx7qIh2T9P0EuuDgE8vRccDI/HKv6hJk WNddGfmw4NdqNgXDXfw73B9t4lSujmjaHjp8vbxCtfCKVvW2I1YoghuRNAOWFGsPI1i/ eHq9GMgwBsVvcvwgPYYoFEFG3YWnczdNy8MB3HpHsl22h1RV1A7RiGjdLoy7FDZ6mhK3 5wBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711361047; x=1711965847; 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=Ng5BrcKH2u1PepcO4ehhcz1HLdaVac5+yYLHKNMA3sg=; b=rsRKrJQHr6mHET5Y1SOmdunBMQ5g/3Kjlzj//rCi6XP6vFGkkr5es+fUcpIZeJ+/lm fJ2e0H7CtCbFxBrO0tp4UyGrHg7BuCNxTO9XaKYykgbmfP5TEgIxGEaFU71af1vDOhG5 M1nRTAjAVBJg+COmenyYaYBqhMEsVO5w3Fe53fNwUI0AJhWmIHVObpV/A09xpAB/01xb NNsOmduwqr/Po3r+INf+W+xz0N3OLApL82b35uwV+vJNAvBYVBForusKlXTK5VPeS7oY 5E2ZRRVECBeF2zHYu6loh/igCJZbPkO3WprsR7UxD77bG9Y/TZIjgS3QTv9ne2rSqn7F gAIw== X-Forwarded-Encrypted: i=1; AJvYcCVihqqnnhoAliHOYspaY3qhJz4IDxvnInD/BLncyiRy7X2QnzexfKFzPLrY3tY55OcW/jmHhUJ3rqko0dX8cDuoAJd07tVclVGlkvImcJJ5vJ7GcVg= X-Gm-Message-State: AOJu0YwfxYC7vIEAgYmm0hdExq2aOcgBsxmXFpOeV84tFLmQokPoal9e EQNA+JdlOBzDp02aWJBjjfDliLkM/Tn3ldlS/iXM17hBUNuqrRkZKe93EqaYQ9w= X-Google-Smtp-Source: AGHT+IFEJpqqE6ui66dDlnqFDRywEMJTVQ3MapnxjqRVVRpO8lm8MMBDsWCpEajgc0lhG+7z2EIHIQ== X-Received: by 2002:a19:8c04:0:b0:513:cff2:fe4e with SMTP id o4-20020a198c04000000b00513cff2fe4emr3935924lfd.8.1711361047092; Mon, 25 Mar 2024 03:04:07 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:75a:e000:861d:8b72:a859:4ce9]) by smtp.gmail.com with ESMTPSA id dv13-20020a0560000d8d00b0033e25c39ac3sm9086874wrb.80.2024.03.25.03.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:04:06 -0700 (PDT) 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 v9 02/13] firmware: qcom: scm: enable the TZ mem allocator Date: Mon, 25 Mar 2024 11:03:48 +0100 Message-Id: <20240325100359.17001-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240325100359.17001-1-brgl@bgdev.pl> References: <20240325100359.17001-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240325_030409_524528_6034B728 X-CRM114-Status: GOOD ( 19.10 ) 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 49ddbcab0680..ebb1141f8be4 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 { @@ -1815,6 +1821,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; @@ -1890,6 +1897,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. *