Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3088267rdh; Mon, 27 Nov 2023 06:20:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2QSQOd7aIjeqsAzsep9mlLwPFbogzGU5vXlUA8c4Jaq1UuI8YD2EHpJRzeAgpBteWMNJJ X-Received: by 2002:a17:90b:4f45:b0:285:a628:57ff with SMTP id pj5-20020a17090b4f4500b00285a62857ffmr5882714pjb.38.1701094808208; Mon, 27 Nov 2023 06:20:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701094808; cv=none; d=google.com; s=arc-20160816; b=lQJZgpc0PswTOQXF43cQuzJb16FE6GZ42HBbzHIu0COCbfMHaXoetUCXbQdhHcZ7UH c5GoR3O/DXPi30Sy/wuF/EjA90xHCb5wc1G7tQH6bHtOK1HJ9eZUsaCeMzSB1CQ/CC3q 3yK3tbwOomdFOl3E7zPtVcJ50MC2SzsBmEGqhGG655UsS1Q8uByuUne3QKVGJQ6vnWDk 7CPwfBgwQLmKteTdkUlZjA5jUrs6U4iRjD9q3U1oRJcWQIMy19N/B0g7iJLEDk+gJcNP xSBoj5BPxu0VccOO/g5skyechxLwgfRWFyV1COZ3tBDibItRGm2PlUaA+XIrieJwiyO4 tH1A== 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=Mi8eKf9Bk+MHBCMvhATqbV/lq6r88mkgwcH/G87faK0=; fh=lirm1ccAeXZZB1cIo+N1DqklpgcFmD/vJ7PCWNIL0HU=; b=g0m0nJBR/tDPvPd3I5Pi/IPn2uMeOm0gUeK3wURM+1+lMCe120q8UdpR4Y/gQrAfmI 3NZSFh8WhpZ/Jg1k4+4BFnIKC5s3HNTkqprpizFXAdcEVRx6eOMB2cBn8km4DsVIT957 P5/yzOo1VP//m4weA1nySS32CMjOpEqeXhu6f638vSKLucP+PTq0rUU0awtELSJiVTJf A/8UuD0X4brfzfR8NdykaUxvYIlqcc0zqz6Lcczq0BtWPmRVzlmq6/4txc7+uYe9Ano6 +iatFseY8sUmxJXDBLSBDAU+SzUXFP7qiv7LRCS2jjCeB63hbM5HPZkbPOiyfiETXMuo yYsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=Yc1JaowH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d4-20020a17090a498400b00280479459f7si10382475pjh.50.2023.11.27.06.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:20:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=Yc1JaowH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id AFB5180A055B; Mon, 27 Nov 2023 06:20:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233808AbjK0OTr (ORCPT + 99 others); Mon, 27 Nov 2023 09:19:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233753AbjK0OSv (ORCPT ); Mon, 27 Nov 2023 09:18:51 -0500 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB1B3C16 for ; Mon, 27 Nov 2023 06:16:25 -0800 (PST) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2c8879a1570so54536161fa.1 for ; Mon, 27 Nov 2023 06:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701094583; x=1701699383; 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=Mi8eKf9Bk+MHBCMvhATqbV/lq6r88mkgwcH/G87faK0=; b=Yc1JaowH8yN3IYwp7jKq8C9mK4qs7w1oYBKTLVeO9TYqjHDZLuoQyxY1lCGY/KMy9F CXrFs2YH/4+tGz8vS6DQXCIGCnjHAYjYPmOWAjydRLjVXvEOZzGGtb0jbnZN8yveWW+y 8Crct/s5hMIaLyWt+ofoTwjNQ60H7MqXrx1xwNzUDLT/O7tTL/BCZRyP8APkewjaCeEE CTcffaIoBujDusGXadNulMlslyukMWZit1see3dDiIg0jhRHeWAafmAVuzjawHrpnJkD ExtyusDBAL0/2573b4clftsr5NHhJBUNHlRhg4//jCpcEQRz17z+DORm4IrWMD7RlH3n Kdlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701094583; x=1701699383; 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=Mi8eKf9Bk+MHBCMvhATqbV/lq6r88mkgwcH/G87faK0=; b=rF4hkRhvSIEV3UG+uIuR27u9Du7k2yZ6Uk4Eral+Bck/iVAgh+g6cKKQT3+H5g7oJ/ lmLLRktjkCS5Z1e9wsMWRg6+BkxnzLLQkkaPIlcZcRQ7Tkid8WcPSfZzhZBU9poPTDTq w7W2bcRW1Pai84ZAOHIKSDdnV1L1noOkhghUE3iEGpRKL/J9fdEJOiIeKfyhujtX3Y9C KOCOA8mlAVhKgG0Kx1y04vU8ESLUImHuSy4u93J0v94UDzIgc5CJ3OqHV1XDIjZ2id6D NqfXJsYkDHhKU7SKGur3nP7WA3DWem6k9+lKiCr8ZbSUoCxm/VN36znZdqqb6qd6qP9o 952w== X-Gm-Message-State: AOJu0Yz35grk+NNUcNUgv8Jx3nnh/dJhFG3BAzvOOjPYHbvTnouOIDvv X8L/EqcuBkSLAZxxc+D1Ov6LUzE0OUdd8bLv/vqCJQ== X-Received: by 2002:a2e:88c2:0:b0:2bc:c4af:36b9 with SMTP id a2-20020a2e88c2000000b002bcc4af36b9mr7465362ljk.52.1701094583228; Mon, 27 Nov 2023 06:16:23 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:bf33:77c7:8131:5e64]) by smtp.gmail.com with ESMTPSA id be7-20020a05600c1e8700b00405442edc69sm14658830wmb.14.2023.11.27.06.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:16:22 -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 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 v6 11/13] firmware: qcom: tzmem: enable SHM Bridge support Date: Mon, 27 Nov 2023 15:15:58 +0100 Message-Id: <20231127141600.20929-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231127141600.20929-1-brgl@bgdev.pl> References: <20231127141600.20929-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 06:20:06 -0800 (PST) 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 --- 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 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 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. -- 2.40.1