From patchwork Mon May 27 12:55:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13675205 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 2CE1DC25B7E for ; Mon, 27 May 2024 12:58:30 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qGtMOH705f7nU/DQm0PK93RkeFcEn+ijzUQve0wQAiI=; b=ZD73z/MlVx0B0Y 4qdHaAY41yCUTuOYucpPzjXMXWoBWY2taKTjwS56islnUzcTFni8Agsqe8Zyo3X+BnWTj/uSInFu2 OgAXm/mXDPte9tXtlWSWMzwwvGLwoTaajkTTlek7qCI74Ipiy6UAhfT2D8PZ8wropyL7EUeb4kI66 n7QdGmgbKq92iDLapwiUJ+aULsHVJDriqd/WTNfnFK7PRJBvhOjRWT0mDo+wQeeV2DOsyXWhAmhxz CEye/23JQMKfCTOL9qxbyYGZC/lQNLwEP96xhwCn63QTDvJTM+LU7JoECBZeSzFJyQ9S0E4exCwnA ITXErux2VHc95QOcj/BA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBZvc-0000000EyQD-3so8; Mon, 27 May 2024 12:58:16 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBZuL-0000000Exdc-0rTi for linux-arm-kernel@lists.infradead.org; Mon, 27 May 2024 12:56:58 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4211a86f124so1290205e9.0 for ; Mon, 27 May 2024 05:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1716814614; x=1717419414; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ksQbuUv3wvF1KrbncOR0XgoHg0w7/4eT/UR2a/c0TAc=; b=HDU1gW9w91tFW/W9eIhAy+p5e8GpF1TtrFCo99mmXe7zObU+kBZSMwWJWRdIDsKy8I 5NAgh7W7U0ugKIC3D5gGL3vqpm55GKYqTrn4T3KaC4T9g0DdG6SY641Wp4JIG1Pkq28Y KuQwjRBx9+vuj1NAicpQSqNu6u1h11AFfQQxNp/KxPB9AJot5eFNE2ybhFgwmNyKRZWa P9Q7rik3Yi2Eii2pnWe8KddBUGP2NZz0ysCdHYxklvu1HPSYkLJ8H7esbWAdpvHLCRpe mfHT9Jmq85IwzCD6JUZMhHuWamgWv3P4mALQBQ8Dhi9EBg7d680bY0UHVkatcummCWXV IPIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716814614; x=1717419414; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ksQbuUv3wvF1KrbncOR0XgoHg0w7/4eT/UR2a/c0TAc=; b=xRncYdhfAxQKt+fzZmKNmw0NKMsmh3C3ykUmkLO3W3qTIhZ/XL87w2MPluoswYvJZo jJD9uRHtVbtcMxINrwjHUkvcSbZ96IPTrgK4kNvw/impmElTl9Mc7PRz1Dl/JQy5osdI 9G+ZI25GpoBmgWWgAeWSNqfmilS6BjM6pbkpctIjNpEDpKEArXPrFkACEpRwEbNGixDx 9rnp5ZIRaJpitsEDO7iTwjcG5ajq1OdlRYNI1IXO37IQkxqDWfjOJ+0UimgSiXgcNnLT wsHzqlr1i87T/iwmZpgG4yQk6zKMT12g3uI7MX24OZLsRY3Tmap/nteB7CJjfsciPhsN 86QA== X-Forwarded-Encrypted: i=1; AJvYcCWuFBlxY/zzv63ZX5CGlUq8LQXTzL1MfuS8IlqvSxC1YwOHPwP3LjmelE5LRKksnEaZrF2sVMRVhQdJ5Tts2aeJcqBjxQ3pn7PwxlzO2PAKyOE77u0= X-Gm-Message-State: AOJu0Yx9SMJwxEg11bXNRZdSGqIGk78BiKsw47k+yHqjsO5yzQ/KhlpE M+FP5rX6NVA/DOLzOqCxs2ZyMpwGYsrTtXWkjykhwhAv7iqMrnyzCuA2hByCLCA= X-Google-Smtp-Source: AGHT+IG6j65E+SjTVgHro64hQyB1RnR2cw++Ee1P82qfXrQBW5PaNGbV71QC/6llE+OdIsaU008igg== X-Received: by 2002:a05:600c:68d7:b0:416:605b:5868 with SMTP id 5b1f17b1804b1-42108a21415mr83248855e9.35.1716814614473; Mon, 27 May 2024 05:56:54 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:75a:e000:c322:131e:ff9d:ef41]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42100f64f98sm138753635e9.24.2024.05.27.05.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 05:56:54 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 27 May 2024 14:55:00 +0200 Subject: [PATCH v10 10/15] firmware: qcom: scm: add support for SHM bridge operations MIME-Version: 1.0 Message-Id: <20240527-shm-bridge-v10-10-ce7afaa58d3a@linaro.org> References: <20240527-shm-bridge-v10-0-ce7afaa58d3a@linaro.org> In-Reply-To: <20240527-shm-bridge-v10-0-ce7afaa58d3a@linaro.org> To: Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Robert Marko , Das Srinagesh , Bartosz Golaszewski , Maximilian Luz , Catalin Marinas , Will Deacon , Srini Kandagatla , Arnd Bergmann , Elliot Berman , Alex Elder Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Andrew Halaney , Deepti Jaggi X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4340; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=+iNGZ5V/p/53bNnp6+mOwcvRHK3V9jzsewmxOel2Jas=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBmVIMKyUP2NGnM341pjVvgYTdtROR6DcmIhzlzp pp1R4Tr/iyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCZlSDCgAKCRARpy6gFHHX cq1jD/wMkIWv5Lxsx5yZpCRSv1sYL8sA5UF3M3R+RdaZ4LMlFAlCuQ58GUHD/xLM98TNabA5qy3 QTmQR4JVNYhirdptI/QgIFCNSVU/uQr26X57ddA89wjd/apXnt+eajGIL1a8Jp7lxUBHraM0lem 6oUR441nF6/LyRUXSwV6RVbJO2pfHLYsijLy8LjO0c3YHyq+gkC+0AuI90rauDBIumjm3i78Y4d NdxcG3uAuy9UzVEV5/DiPBg4ogPMl3MyweHfDyG9oRHlD7kuObK6Aqn5Kc3ZoCRuZjRcMd0CAAT lmcWFSvaZ6IsZuXqN4vZgzhSZRtX0dl+NNa5/ZMW3V/6TfiFCnv1hZuIKWCL2TdMbYONZsjkuJd Mb3JtMHtQVNvKcIOMR492d5RauFEl+yN3f4I6jnL5ZyfjAptK4vp4Fea3Dv3PVQtZI7MPiU8RYs C0ykf9TV/41iOYk5UMseS0DUJg9xJJZElSqysxRvnBUPQcfF0HlGHb2YrO++98vDh6xe5iWqn1Z vXmw/3BgB6WcUC5Kx9i6JMhir+8+uRKp9+MgZmIslM1Q04yeceLKq1blifDwLzI/D5UeNRe17TW nolkKHIMW/bnrs+crSD2sTDLzKmut8neOOC2Vpu0FUT+Z9r06vh5/H8BxgT/WsRmgyWNsm/pGfx q8QBX8HzQt/fqTw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240527_055657_531690_90D49021 X-CRM114-Status: GOOD ( 13.70 ) 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 SHM Bridge is a safety mechanism allowing to limit the amount of memory shared between the kernel and the TrustZone to regions explicitly marked as such. Add low-level primitives for enabling SHM bridge support as well as creating and destroying SHM bridges to qcom-scm. Signed-off-by: Bartosz Golaszewski Acked-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm.c | 60 ++++++++++++++++++++++++++++++++++ drivers/firmware/qcom/qcom_scm.h | 3 ++ include/linux/firmware/qcom/qcom_scm.h | 6 ++++ 3 files changed, 69 insertions(+) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 04131e60b63a..94c34cde8179 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1344,6 +1344,66 @@ bool qcom_scm_lmh_dcvsh_available(void) } EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh_available); +int qcom_scm_shm_bridge_enable(void) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_SHM_BRIDGE_ENABLE, + .owner = ARM_SMCCC_OWNER_SIP + }; + + struct qcom_scm_res res; + + if (!__qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_MP, + QCOM_SCM_MP_SHM_BRIDGE_ENABLE)) + return -EOPNOTSUPP; + + return qcom_scm_call(__scm->dev, &desc, &res) ?: res.result[0]; +} +EXPORT_SYMBOL_GPL(qcom_scm_shm_bridge_enable); + +int qcom_scm_shm_bridge_create(struct device *dev, u64 pfn_and_ns_perm_flags, + u64 ipfn_and_s_perm_flags, u64 size_and_flags, + u64 ns_vmids, u64 *handle) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_SHM_BRIDGE_CREATE, + .owner = ARM_SMCCC_OWNER_SIP, + .args[0] = pfn_and_ns_perm_flags, + .args[1] = ipfn_and_s_perm_flags, + .args[2] = size_and_flags, + .args[3] = ns_vmids, + .arginfo = QCOM_SCM_ARGS(4, QCOM_SCM_VAL, QCOM_SCM_VAL, + QCOM_SCM_VAL, QCOM_SCM_VAL), + }; + + struct qcom_scm_res res; + int ret; + + ret = qcom_scm_call(__scm->dev, &desc, &res); + + if (handle && !ret) + *handle = res.result[1]; + + return ret ?: res.result[0]; +} +EXPORT_SYMBOL_GPL(qcom_scm_shm_bridge_create); + +int qcom_scm_shm_bridge_delete(struct device *dev, u64 handle) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_SHM_BRIDGE_DELETE, + .owner = ARM_SMCCC_OWNER_SIP, + .args[0] = handle, + .arginfo = QCOM_SCM_ARGS(1, QCOM_SCM_VAL), + }; + + return qcom_scm_call(__scm->dev, &desc, NULL); +} +EXPORT_SYMBOL_GPL(qcom_scm_shm_bridge_delete); + int qcom_scm_lmh_profile_change(u32 profile_id) { struct qcom_scm_desc desc = { diff --git a/drivers/firmware/qcom/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h index aa7d06939f8e..cb7273aa0a5e 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -116,6 +116,9 @@ struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void); #define QCOM_SCM_MP_IOMMU_SET_CP_POOL_SIZE 0x05 #define QCOM_SCM_MP_VIDEO_VAR 0x08 #define QCOM_SCM_MP_ASSIGN 0x16 +#define QCOM_SCM_MP_SHM_BRIDGE_ENABLE 0x1c +#define QCOM_SCM_MP_SHM_BRIDGE_DELETE 0x1d +#define QCOM_SCM_MP_SHM_BRIDGE_CREATE 0x1e #define QCOM_SCM_SVC_OCMEM 0x0f #define QCOM_SCM_OCMEM_LOCK_CMD 0x01 diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h index 2c51987fb70a..767bffe20766 100644 --- a/include/linux/firmware/qcom/qcom_scm.h +++ b/include/linux/firmware/qcom/qcom_scm.h @@ -115,6 +115,12 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, int qcom_scm_lmh_profile_change(u32 profile_id); bool qcom_scm_lmh_dcvsh_available(void); +int qcom_scm_shm_bridge_enable(void); +int qcom_scm_shm_bridge_create(struct device *dev, u64 pfn_and_ns_perm_flags, + u64 ipfn_and_s_perm_flags, u64 size_and_flags, + u64 ns_vmids, u64 *handle); +int qcom_scm_shm_bridge_delete(struct device *dev, u64 handle); + #ifdef CONFIG_QCOM_QSEECOM int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id);