Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1973958rdb; Mon, 9 Oct 2023 08:36:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGNEM3hi97vWSinWm4uJdW0l/yl+ImXOffxPCNRXc1HSk5t/k/sGJh6JEOb6Xuo46HgWJX X-Received: by 2002:a17:902:e84c:b0:1bc:4f04:17f4 with SMTP id t12-20020a170902e84c00b001bc4f0417f4mr17908328plg.30.1696865790149; Mon, 09 Oct 2023 08:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696865790; cv=none; d=google.com; s=arc-20160816; b=gnBoPhVAlq1vRWwDTeAa/TXULtAy6eebeCQm3triZIFKnc0kc/8EWYx3mUCRJ65O44 B4ZUr0r+/8glYu5u5Deok3wUyKcEGBj0fvgQphHvedVMieLS0EeAdALF5Dy8BpXqbFea hfXvwoT6EajeJzv9j0z01w52EdjiCR+PFUoEz/imnpmAgWOrz3cdMfR/YbeXDBzQVgCQ gZhXp5pnUcttILZReO9fKrxwzsrpfRQqBNUg7yaWTF2LgPXWO6nX6zpmHDZmmUGoo+79 t8fQE9GmGmPEM1Yrf5T7xbVzW2N0ZNRGx/z9ZiETg5TvjwLl49CG6mbmzS+bNsXF+a6H 0xvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bf2AqtKJ/+ji6DGMnGdvnoiBlKH8gD5Uamvdkv0NVy0=; fh=lirm1ccAeXZZB1cIo+N1DqklpgcFmD/vJ7PCWNIL0HU=; b=M6/E3gqWDR/fSfC4HM6nXztzBSqkexkWPqMdMcDpnVsWgh4hUqFJA/j5vv3MGYzwK6 kpC/NexfcwbfjzWyK8k5r7Pjw5wbmJtTcbn00ICRNGO4g63P+d4+8yGxpxrhBxism4Ca XP8LEDeBRKx47hD48dMalpHDhTRZauAftad3ECEYEs56JaPAImYLpe4bqEAZg+jrZvoK c/8e4Q5iCnVSMreEbdgzpVQ26jlKS/dufjTrRCDsNkMceRqffTDDpKRLlu+y1rlCGrF5 QJ/+BBQbfXfZ97T4M7+0BIE6AygugsC9BxDyItvtP1rO1reKVavucFLJ/GCtmn7Qu2Pj vW4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=I+qUoC4N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t14-20020a17090340ce00b001c6223e5675si9619249pld.188.2023.10.09.08.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:36:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=I+qUoC4N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 14F7D80301FA; Mon, 9 Oct 2023 08:36:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376984AbjJIPfo (ORCPT + 99 others); Mon, 9 Oct 2023 11:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377735AbjJIPfZ (ORCPT ); Mon, 9 Oct 2023 11:35:25 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F677125 for ; Mon, 9 Oct 2023 08:34:58 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3248e90f032so4639894f8f.1 for ; Mon, 09 Oct 2023 08:34:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1696865696; x=1697470496; darn=vger.kernel.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=bf2AqtKJ/+ji6DGMnGdvnoiBlKH8gD5Uamvdkv0NVy0=; b=I+qUoC4N3GfMwbwX6itAhk5/f67zdJW99P9ZnOl279uU+K/NMtetG+oD3pT3Ucj3ic bquJ3nDIirDvYYRHMmMIgqvr+mHb34ms9miNYDjTh0Lz5HfvpA/cYTceqM5zNSmRqcnO WvVloMxnKxQWMoZ3x+lHbOo55x3JuN37rA60l5b+mv/7scqrA2A+Roya+6a4SYi/dUgO QfVgi9Qiie50iH/JSTJeAF41g+c4PqGRcQy29nKQha/y18Qt3EQ9+wgEE01jOLDNXyqM OG0BTQDT5d4oJoPPsaWCxusqH/F3MNh9pKHY/TWcobpQbITB7rvxyh7unVUQS3eu2KLe Q3FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696865696; x=1697470496; 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=bf2AqtKJ/+ji6DGMnGdvnoiBlKH8gD5Uamvdkv0NVy0=; b=AWkvvdYCQGVHV/dCI05TDir0Zh853hsV6ByrPIVS65iAohmvcFIkqQ38dOj3XsbvQb iOOWxL4EMGeLC5vkO6CPFeHViugjmPYjsMznsX2COlpmY/Lz7WeZtnrgRaILTu/d9Oc9 H6+odFyyY5EbTs7aDsFr4GsBYYDC63wLsdIe6QD6wmhYkWsclK7dzBDqlk7aVJvmnWHx IVVcnT1tQJwxq5vgTlG9M8ffjcSG9IG08F5JOwFObMrXKeqz3V7ZLTnNLu8LXB9OJ3LW T+aG2QFV+DBWClTSTXTGmnywTW3UG6h0cReFY/g8pQDuj4d9tb3PQnJdSBaIKKrgCSB6 jt4g== X-Gm-Message-State: AOJu0Yxip2Qc1Navsn9SSsT0KALnFmOmRhRm0nHIfvPneBmwvgfKHR8I pA7y2It9F7abfeX4DqJwXNKp8g== X-Received: by 2002:a5d:6909:0:b0:317:70da:abdd with SMTP id t9-20020a5d6909000000b0031770daabddmr14203281wru.59.1696865696468; Mon, 09 Oct 2023 08:34:56 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f20d:2959:7545:e99f]) by smtp.gmail.com with ESMTPSA id b3-20020adff243000000b0031431fb40fasm10016521wrp.89.2023.10.09.08.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:34:56 -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 Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v3 13/15] firmware: qcom: tzmem: enable SHM Bridge support Date: Mon, 9 Oct 2023 17:34:25 +0200 Message-Id: <20231009153427.20951-14-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009153427.20951-1-brgl@bgdev.pl> References: <20231009153427.20951-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:36:26 -0700 (PDT) X-Spam-Level: ** 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 --- drivers/firmware/qcom/Kconfig | 10 +++++ drivers/firmware/qcom/qcom_tzmem.c | 67 +++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index 237da40de832..e01407e31ae4 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -27,6 +27,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 eee51fed756e..b3137844fe43 100644 --- a/drivers/firmware/qcom/qcom_tzmem.c +++ b/drivers/firmware/qcom/qcom_tzmem.c @@ -55,7 +55,72 @@ 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"); + ret = 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, *handle; + 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); + + handle = 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) { + kfree(handle); + return ret; + } + + pool->priv = 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. -- 2.39.2