From patchwork Mon Mar 25 10:03:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13601740 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 EC7F1C54E64 for ; Mon, 25 Mar 2024 10:05:52 +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=R1BsmXML/ONBqIBFt9zsvOhZ/lm703KqSsi9wziovUo=; b=dLLxr92H8CWUHH 0fxQn3w5D2jnF6Jg7erlinztrKM4X4E/dEO4tRjY2hAOQdZGEgKOLy3qpQTtexkVqghtx2Mkk905y 7okul9TrL16I8qwjMWJ7uUT5A6wJPbS++s8HJ6D5QawDU1wf7Zq8Ag43NqT2bIdfw0z4S0HTx6Xrr XiEFj0RJKVKgHnL2C0IwtF2Z+dR7UzvGzvwzY5MDFc4o/V1At+EctHQkJ0QxkFPpoSVFi3NxoRE25 o1C7wfL1nZvoHV7N5+LxhUdDX1efdZgl81A2p0JNl4i6ujwt6QWQuRIYtPBW5PAAe+wZ136DHU/bX +GpB/2qSsRcFqcxp9Xcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohCy-0000000GdGZ-0iUN; Mon, 25 Mar 2024 10:05:36 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rohBi-0000000GcTh-2Zy1 for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2024 10:04:21 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-341cf77b86dso448806f8f.2 for ; Mon, 25 Mar 2024 03:04:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1711361057; x=1711965857; 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=+4+dJf6arGYhNMNbnDj3J5bx1sPusy2X6VNsV11mqig=; b=b/B00zsKwcdvfgzSZ1iRVCqdfY3QDdCI48C+I4sB+bTJr00OrY5MgnjkEKsmoAY0cC goljioZ3JOiAXOPaokUU/qvdbuKO9nr8YXxzAIJ5KLh6Mf5ljIRns35mn45GRKec3Q7q olyX/2ipCJeYf8qZOjWOc9qiZwFqxQXnmQAT3GqRQYR9Ku6UjEumU8bg5U2gW5s6/sni MkMVK3W4zOCbyYniPdr/AjoVlTmFvXZAzGItmSk+B844TNk2eVB8yCXusw/IPk2l6Cue InT5trzfgL4FZORKCJ42lKnk15A59VXcjyIj+7oC5J5oYQfUNqt+fpwZ4MiYXlKzprht bcQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711361057; x=1711965857; 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=+4+dJf6arGYhNMNbnDj3J5bx1sPusy2X6VNsV11mqig=; b=d2Q8z3snwpRIgWDB9JHcBcQtrEpXYKkSI+JuYsDyNFf9j5fGpb5OyJEOeWYZ1ryqCn E/Ntpx5zFFdMgG81YEqxuivNfQiofQKPSz+81hS+AE/wKlw0qyFmA6VwozULZBTa6KCN kwM7Y+1UYR/UqAU+d5aU5hsIeyIUlBIVkYZvtT0pOO8M/yQkvOSY1ScIzgraez9AzwqR RsYwIYDGfCeOuVTsUX5KSIY9Qz1BEHd1wFythapf4UFqd3S+T0/HUVV6tdg77pAwsRS9 joZ/Tu2lTX3ZErnIKr5/z/DBwgXe6/7SGrzibfA6K+bkb0pWXCytcubmc5J7YNVkOb6H d/Fg== X-Forwarded-Encrypted: i=1; AJvYcCUDDdLB3WsN/g29pT+GwagHEw6uIsXrZzUBr6HXVkIxKl89B+k+hVZc1aILmAA1hWg5RyK6br/yk7czFPbqFND+4pu8a3g7cd8KLhOwzoriO8sPGt4= X-Gm-Message-State: AOJu0YwE5YTvAWklAE08hvOmONIlF+LhllelMSYAsk/RFaTRViyPrZAw B/dezZnc49cqGYMz3IZmm1kyTzMj7O0luiJAnl/po4g6QExnTViDdM0KgawmU/0= X-Google-Smtp-Source: AGHT+IEkkZsBnp0pP6MAMwtPkvyKZCO/XD4p9hpMGTvLyBcd5Wa7WEDbnL4tGVoZ/jFZI8OhjLph3Q== X-Received: by 2002:adf:cd0b:0:b0:33e:72f4:2ae with SMTP id w11-20020adfcd0b000000b0033e72f402aemr5064875wrm.68.1711361056958; Mon, 25 Mar 2024 03:04:16 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 03:04:16 -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 10/13] firmware: qcom: scm: add support for SHM bridge operations Date: Mon, 25 Mar 2024 11:03:56 +0100 Message-Id: <20240325100359.17001-11-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_030418_796657_093B566D X-CRM114-Status: GOOD ( 14.00 ) 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 f871af4af829..7a8d67c7b71c 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1326,6 +1326,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 ccaf28846054..9b6054813f59 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);