From patchwork Mon Feb 5 18:28:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546024 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 A18ECC48297 for ; Mon, 5 Feb 2024 18:28:54 +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=d6dqrImdIsfmPIBWcIrkSzyKlP2zyYVisCNopJtUzd4=; b=GUvb1ImWOOTINk a8p3NP/v03RofzMY/nm1KYL1HPoAafgGZs7KaRsgCKOdCym27kNCAxKOVNwqA7lZAC+yLETASUBcI l9bFKWlanIjzTlQNDfpvRP9ebQraqXaqIddHIHYnMErYAuB4+CUaXhBrJpZ65WeeOFXohPYLLO05N CrKBzJmTFOlez2TxDbZNej0k3A5lRl/6Dw14cuOQuEnb0Q8u3M3s6JHWIEo4YlMipyTVYTkvYr6jE LkKSZ+j8PFFVuaOR7M8LQSFWGE83kGx0CqlBSpyvQ+iEVTgRftKYMdvQQOkNnKvwGcdvNSErMBYCi ok3SUgE6L1PxOfTpEimQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3i0-00000004N3U-0Wra; Mon, 05 Feb 2024 18:28:44 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3ho-00000004MuQ-1jKD for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:34 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40fc52c2ae4so31531725e9.3 for ; Mon, 05 Feb 2024 10:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157711; x=1707762511; 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=un7cEtb3KJw1A3qP7llM4B4OwSm9CqRxp4DvgeD9Ir4=; b=kDQUNu46h6uDY7+nulxG3ADrnOQGyar9T/mm/ietA+4zB1MKOjIBVR6IsaSHMt2c9N DnXSkmttCaRk1VAiEqSuUc4OkQDPO/ykH5NtYOg4i1wV3TmRNkp9sAJz2qqJiCEf7ENM 1LoZD7HFb2YnGy99eYopL+oB3VqKrYbmGujnw43v6Ji5HkvOY208Qbaokh+21UXgZfAM wogcVP/WHLVUOlK5L8q+HYBGduFvmlBSgYp8G0YFPr34jDvlB39xoiLOjg4cx+85f5WD lUFtA8r5p1e2/QB589iPc5CClvQ+n8NDe64IUtLTIZqZCQakz5D+fZfcN90vuMJZeTDd eC7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157711; x=1707762511; 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=un7cEtb3KJw1A3qP7llM4B4OwSm9CqRxp4DvgeD9Ir4=; b=qbnQmPLBEnhfM6EJmAPcvhhnMPboGzckRHsgQe+hEpVQAsdDBZ4p24vjgbxRQVyL8D kvyQE2qvSF4gkusO8gD4hywt4QGKcOe9H2MoGNBrAmh6dLkZi1fQvZ9/KHmKLSJU+eBa rm3KnqV+FWWFUpO2AtlUvxz2uHtDl9Ccxz8pNwaFeIk2zSqoGcoqxRTf6jIbvS8EcWBL +so4ODSW7DUCNld1Yx2V68wYcDZ3z/ze6OyArYptFpFXIY3MIf6HXyA1WFEZ2yk7FyZl wGhqT8jgADCRyrtSr6KBGncTKLueKS3eSa9hpSkFpLEYArTiA977ooyfAfhD4w2bGB+z x/ww== X-Gm-Message-State: AOJu0YxTPLaMwX3exwiMt32ISYk2ImxtzO8mC+yawH6aWaYY4QL4ksHY Z+RDE+SK8U2bGdTsNDgVmXEUNwIyjkHvqOk+ThcbOdSAPDvgYA+P3wWZ+lVrp6Y= X-Google-Smtp-Source: AGHT+IH+YlBI22schHQmMqidb7q3KHo+sRIdEP+Vmn6IUjpvEfBRLsCLSdwDp6ZXMGp2snNBJadkvQ== X-Received: by 2002:a5d:6d0c:0:b0:33b:1390:d952 with SMTP id e12-20020a5d6d0c000000b0033b1390d952mr317743wrq.19.1707157711039; Mon, 05 Feb 2024 10:28:31 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCW3Htlt/5bJrrn9O1UdvEw6ixuei44u/CC58MhspOd6vqORlCnuOqqkZRF/NxTIONM6zbOXlvoYSv8sRFYaRSmgezLya4CjuF8V4Fwi2n0I/uwG94mUnku1SWSzhUHZ9noFevkniE46GT4gPJcHOukfnAxIfA9YToOrnaj7oSfmpueTu7Y4nkoLj0y+8rhzpOrKZ3EQkCj7kxdyaNNcwzrZDWd4J4TVv4sfQE6J85/AyBa/SnUjrcZ8nSHzN6sp8fY67PvOMFb4wsCx9g5OlB6yrRLetTGOlLgPTFrXQIAc78SPR+36t00yAIRlHspeFwprkDwhNdDHoAVxFr2EidtezBV1sA8YWz6P1TBm0LJ3MLnQGFOyfWL115nhVpXnjSGQUvcvRK5r4MZAVAuNY9GtHZcLWvqk05Aozm+sgzAf+v5360wJEQJPu/doQA5zik1GDidf32ZJEbBohor3t4B/xo99XPqdH1IxVA3B7iXr/1VCN6He3r3prGNJWmXVLzqyAprt/jeMy3CkHhIeAZp/m6/jTDCkr7iN6EILhf5J9wm8Qen9Q01uMcCbxp/exNs= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:30 -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 v7 10/12] firmware: qcom: tzmem: enable SHM Bridge support Date: Mon, 5 Feb 2024 19:28:08 +0100 Message-Id: <20240205182810.58382-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102832_563341_10E4928F X-CRM114-Status: GOOD ( 17.40 ) 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 Add a new Kconfig option for selecting the SHM Bridge mode of operation for the TrustZone memory allocator. If enabled at build-time, it will still be checked for availability at run-time. If the architecture doesn't support SHM Bridge, the allocator will work just like in the default mode. Signed-off-by: Bartosz Golaszewski Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/Kconfig | 10 +++++ drivers/firmware/qcom/qcom_tzmem.c | 65 +++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index d24d83223867..af6f895c5adf 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -28,6 +28,16 @@ config QCOM_TZMEM_MODE_DEFAULT Use the default allocator mode. The memory is page-aligned, non-cachable and contiguous. +config QCOM_TZMEM_MODE_SHMBRIDGE + bool "SHM Bridge" + help + Use Qualcomm Shared Memory Bridge. The memory has the same alignment as + in the 'Default' allocator but is also explicitly marked as an SHM Bridge + buffer. + + With this selected, all buffers passed to the TrustZone must be allocated + using the TZMem allocator or else the TrustZone will refuse to use them. + endchoice config QCOM_SCM_DOWNLOAD_MODE_DEFAULT diff --git a/drivers/firmware/qcom/qcom_tzmem.c b/drivers/firmware/qcom/qcom_tzmem.c index 44a062f2abd4..1ca3773263e5 100644 --- a/drivers/firmware/qcom/qcom_tzmem.c +++ b/drivers/firmware/qcom/qcom_tzmem.c @@ -55,7 +55,70 @@ static void qcom_tzmem_cleanup_pool(struct qcom_tzmem_pool *pool) } -#endif /* CONFIG_QCOM_TZMEM_MODE_DEFAULT */ +#elif IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE) + +#include + +#define QCOM_SHM_BRIDGE_NUM_VM_SHIFT 9 + +static bool qcom_tzmem_using_shm_bridge; + +static int qcom_tzmem_init(void) +{ + int ret; + + ret = qcom_scm_shm_bridge_enable(); + if (ret == -EOPNOTSUPP) { + dev_info(qcom_tzmem_dev, "SHM Bridge not supported\n"); + return 0; + } + + if (!ret) + qcom_tzmem_using_shm_bridge = true; + + return ret; +} + +static int qcom_tzmem_init_pool(struct qcom_tzmem_pool *pool) +{ + u64 pfn_and_ns_perm, ipfn_and_s_perm, size_and_flags, ns_perms; + int ret; + + if (!qcom_tzmem_using_shm_bridge) + return 0; + + ns_perms = (QCOM_SCM_PERM_WRITE | QCOM_SCM_PERM_READ); + pfn_and_ns_perm = (u64)pool->pbase | ns_perms; + ipfn_and_s_perm = (u64)pool->pbase | ns_perms; + size_and_flags = pool->size | (1 << QCOM_SHM_BRIDGE_NUM_VM_SHIFT); + + u64 *handle __free(kfree) = kzalloc(sizeof(*handle), GFP_KERNEL); + if (!handle) + return -ENOMEM; + + ret = qcom_scm_shm_bridge_create(qcom_tzmem_dev, pfn_and_ns_perm, + ipfn_and_s_perm, size_and_flags, + QCOM_SCM_VMID_HLOS, handle); + if (ret) + return ret; + + pool->priv = no_free_ptr(handle); + + return 0; +} + +static void qcom_tzmem_cleanup_pool(struct qcom_tzmem_pool *pool) +{ + u64 *handle = pool->priv; + + if (!qcom_tzmem_using_shm_bridge) + return; + + qcom_scm_shm_bridge_delete(qcom_tzmem_dev, *handle); + kfree(handle); +} + +#endif /* CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE */ /** * qcom_tzmem_pool_new() - Create a new TZ memory pool.