Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2740382lqp; Mon, 25 Mar 2024 08:02:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYSyMnugAW8YH2JCER9Sr1yOKyfmiG7epaeIziDMN7rd7jNCt7oJFoUjdx9C1zCAeCuX6/WYz6w692dk2YyxuaVp9377vGjGF+yIuJLg== X-Google-Smtp-Source: AGHT+IHNaepAVcPZl+mRlVCQCqJ4vV3RztggntyVQKRxPka+UBYkJiN5OYoC6ZMLmZniq8MbMoob X-Received: by 2002:a05:620a:1991:b0:78a:575b:ecb3 with SMTP id bm17-20020a05620a199100b0078a575becb3mr3711642qkb.78.1711378945601; Mon, 25 Mar 2024 08:02:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711378945; cv=pass; d=google.com; s=arc-20160816; b=JCJADv84EpYEdDdqI0St5M5eaa1VhLeL8t2YF+Kae0qM/3/zkJXWgBjJjEi6PCuyAN xqbMYJd+vqLZXRUd5DXQYy+bkL6cTTe19o6ygAzuFX2BbcNoGKaJ8zeWS77A3G62Nj9C g5xYoQ3oCBg7g6R2nCLm8UbfuCWiwOyuitfw0DQB5sraO+YF60+mNFxh0TEspCDopHvW BSx579E3IVePLGeaZbRT0bn61/nxLquQHZ5EOHsoLtUYo5O1171Q01afCIPRozhkRyNB 3cVGWK0swoXhMABGvm0CbNoS9rFq6DZM3jzWfiy0iRbBJ/xpq4C3BpzDM+Qb/gmJYz0u 50+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+4+dJf6arGYhNMNbnDj3J5bx1sPusy2X6VNsV11mqig=; fh=WBqi2A9LrClu7t+4nSrIj3H8fTmyt2xesgbUYUJFW+c=; b=NUBwjGGAPST0kr0yI0g7dv3mG3haoww3FXQlvWuSoJXVIyU23I776UCvFUaHQcZOAe ndTPQWIkzmFTP6EyW4pOAxXnWqmfm4VhMb+owa1oKPzQc4mP/249ti/+Vf/WC4VG1o7+ zjCiNQ8/YIhEQa2kB8AkTp2lhc36igSni/u7zR1D7/h23ZvpT+MA8hcY3yI8t4gcvb2e WSavosrUS18iKVnMBAKE/Cp0n3nxvEqP9q/zzRtglrfrsHc5eZZFJKNszYwLzNVN1xXy G9uGyjCJLnve7yRhBXtI8lyWqESE06RNovX2MshjHHu5Gl3yVbCbGf9+OOLaPjo64Gz7 ovIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=F6F4BGRf; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-116784-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116784-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n15-20020a05620a222f00b00789ffd3c981si5156013qkh.323.2024.03.25.08.02.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 08:02:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116784-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=F6F4BGRf; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-116784-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116784-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0D7081C3A6CE for ; Mon, 25 Mar 2024 14:14:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65CF9181832; Mon, 25 Mar 2024 10:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="F6F4BGRf" Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 779CC1966A4 for ; Mon, 25 Mar 2024 10:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711361061; cv=none; b=jdQ/hi+GAmK+6pl2G3tzdablIHeSLsqogK/2LgNgzpcdHbDupaOQyHekYc+PLHlqdG+caEyhh0mY/t0Sb4FpnVOAHs3iyRZsSKZKVHQC50XJsoypT0yjlgeWtf5oe3cRcEGorGwOi5Rs/z2iNu7Zzec4zyOhKerqczJnAC6BvJY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711361061; c=relaxed/simple; bh=lSgjcgnvH6aUwQLw5EoB/MQVa1YpVl7Vq0vuihO2tqo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aMLpM2dwW5RvaaT30XuiSWWvlzvyVhfZQFxGEWHCg6EOja/+7uKp28Xme47FxSoWQz4IUBtypiv98tMKX1N55m0MqauYS2mzSzeLEbSYOEwLfMRRZbNP/c2riKzqsR9IUb5rDe8gMH5bS/w5QvN1ZQa+R1QlEjydQs9KYo5naOA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=F6F4BGRf; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-341cce3e5f0so795802f8f.1 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=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=+4+dJf6arGYhNMNbnDj3J5bx1sPusy2X6VNsV11mqig=; b=F6F4BGRflLydi5oF0hw0lB9gXq8sZGByqAQO7PgZHIICm1QJroPUN3uCktzlvkDM6Z gp29seOQvuucQeVIYx9oCSEMtMXzmW3KmmOfRZC1yYnsFarp0JSFg8J2gJ8AUXAEXsad s7XyYcnLER3t1UMyQVvQBQQLz8fGPR4s9ACTpL6jiXZTV1LsGwUbdAC40b7WjPavZULV BQJpczIxJiSaeYS6q6gI+Gbi2JAYXJ8xXS7xZiVKU0p9V4LeETEJ5pV23+PKxOz1dd4t 2XhYqsBubP7fXjopGKPkG+j1SOL4FjszQ5t/vLST+FUDe/TOkhrNAdPBcPvqSag44oUm F2tQ== 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=IeflROKI1dDeBw1tcuHBiX1V4xq1M+jm2N+2pL/na5APE3x0MbPsaSVcvRHUSpRmoH vDrwUZM7PTvUxxnSaJMBQSZY5pUbCuagWPTwGPH6yNBgFXEC7boesNdE9TcTAPB4SHv9 PAGnMG/m8Sqkcq84+sVoInD63XPqMYJbK6MHByfmSQTSwvBKRvnp7bJDnwRgGtYV9nfR 0kUanE5Mifng0ESoAAlQved3RjaI7nd+SxQzdhoCAklhu5jlsZ+SzKbWEuVtFOFAq4ui 0en46xeHO0r7WaCS4Zu+UQRIw99IlRA/6G5U5LldnfgMx7N+FvO7zoKGoggeGVE638KJ w2OQ== X-Forwarded-Encrypted: i=1; AJvYcCVhI0WbO43jC0EiM5uI4aDky+XdgoGWfCa6kIQVY1u/Q2p/odt3f+QtcN10ohtYTCnT+fmRJjC0NYho+R7DNwr90P9y+6qFVoOznW33 X-Gm-Message-State: AOJu0Yz53ORG2K9EAhwD/7XpI+3rMrOYxM3+mRnlocgTcw/s3BZ4xL/Z M1DWkFtWxEBrp2jFt0QVQpoM2UlPzobvcWq0mBA4ziezPIVvCMCpOlEcxW+lcds= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.40.1