From patchwork Thu Sep 28 09:20:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402373 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8667CE7B12 for ; Thu, 28 Sep 2023 09:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231614AbjI1JVL (ORCPT ); Thu, 28 Sep 2023 05:21:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231570AbjI1JVJ (ORCPT ); Thu, 28 Sep 2023 05:21:09 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3D7C180 for ; Thu, 28 Sep 2023 02:21:02 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40652e5718cso2326185e9.3 for ; Thu, 28 Sep 2023 02:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892861; x=1696497661; 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=ZM/a/+V3p5AIwbNsZKgGbA5ufrscHGvXeuqTdYg9svM=; b=z/WYaGG7eX2uwET6RaaIJ+PafKNFbNsyAlAzbahzqr/lfeajIRMMD2aqjC5bo403Hg YMdKcnn+HWtqnFfnnKwPnd5pxO4F6lZ7FTaa3BYeKuRFuSY3QgjfXF1j+/o4TtjvXJ2D wqRSShAhDn8Ic9sL9nmmybdE5z/XySid7YoBeUX7e0dUg1ldb6w8V5QPedsUfkkQJdqF Zj1VB5LPeCL+H81+a9m72CWlMjWOooueBvu6jVPRc6nqlAgkq9wXtFIN4SAcQho60DKQ lWhNhK5KcveK0gA77I5PvErgMWWCHUO+j4o6lbB4By0QS4Yzn+//r927za6F2iY/tWpV 1NuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892861; x=1696497661; 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=ZM/a/+V3p5AIwbNsZKgGbA5ufrscHGvXeuqTdYg9svM=; b=dQAWdWJpOXmBzz+WLR1cq0cB4TzeNOgtCBRUNS0AcAaqxvCwo4jnDE7da5/ZTvUHCC pWbqiGGqqIhme0QOBagODhgqHvSggK+Nyj2M+RFql2gqhobOkHpfUy6yC99CTUsbY6Ic vpsxwU162svdSPSpZJKF9bk2NCrKrhtlkwFZvi9AnxA58On6AuYp0mFqiZXUXsGmSZ90 /9/8a95z0RmIGZJz33/P2eTBntXy8tNsuAdXcDy70dNO01wmVW64owdHIFrB5+vHPp8t vBPNVTx6xUzWbXJVjwxXhdW1aNMOwyfEaBk+zYG/MoVxUS6geIjgmexZ1G0MZyN8gzyW XI/A== X-Gm-Message-State: AOJu0Yz79Lyam9hAnsYnPLoBB/G0YESC0e91pDFNb1kL2yfC9WdRtKA/ ps4WB1sGshbpr6F2/ayaImDd3g== X-Google-Smtp-Source: AGHT+IHhFLv4bVcddNImrQFdy4LHQLiifmm7KbUsOlGmkTHzYZCNQ+x3wbaR2X4ghkNRrDOV7KQ4Yw== X-Received: by 2002:a05:600c:3658:b0:406:517f:ac71 with SMTP id y24-20020a05600c365800b00406517fac71mr766709wmq.29.1695892861085; Thu, 28 Sep 2023 02:21:01 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:00 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 01/11] firmware: qcom: move Qualcomm code into its own directory Date: Thu, 28 Sep 2023 11:20:30 +0200 Message-Id: <20230928092040.9420-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski We're getting more and more qcom specific .c files in drivers/firmware/ and about to get even more. Create a separate directory for Qualcomm firmware drivers and move existing sources in there. Signed-off-by: Bartosz Golaszewski Acked-by: Elliot Berman Reviewed-by: Krzysztof Kozlowski --- MAINTAINERS | 4 +- drivers/firmware/Kconfig | 48 +--------------- drivers/firmware/Makefile | 5 +- drivers/firmware/qcom/Kconfig | 56 +++++++++++++++++++ drivers/firmware/qcom/Makefile | 9 +++ drivers/firmware/{ => qcom}/qcom_qseecom.c | 0 .../{ => qcom}/qcom_qseecom_uefisecapp.c | 0 drivers/firmware/{ => qcom}/qcom_scm-legacy.c | 0 drivers/firmware/{ => qcom}/qcom_scm-smc.c | 0 drivers/firmware/{ => qcom}/qcom_scm.c | 0 drivers/firmware/{ => qcom}/qcom_scm.h | 0 11 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 drivers/firmware/qcom/Kconfig create mode 100644 drivers/firmware/qcom/Makefile rename drivers/firmware/{ => qcom}/qcom_qseecom.c (100%) rename drivers/firmware/{ => qcom}/qcom_qseecom_uefisecapp.c (100%) rename drivers/firmware/{ => qcom}/qcom_scm-legacy.c (100%) rename drivers/firmware/{ => qcom}/qcom_scm-smc.c (100%) rename drivers/firmware/{ => qcom}/qcom_scm.c (100%) rename drivers/firmware/{ => qcom}/qcom_scm.h (100%) diff --git a/MAINTAINERS b/MAINTAINERS index 861a16b4586c..88c2186b4975 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17887,13 +17887,13 @@ QUALCOMM QSEECOM DRIVER M: Maximilian Luz L: linux-arm-msm@vger.kernel.org S: Maintained -F: drivers/firmware/qcom_qseecom.c +F: drivers/firmware/qcom/qcom_qseecom.c QUALCOMM QSEECOM UEFISECAPP DRIVER M: Maximilian Luz L: linux-arm-msm@vger.kernel.org S: Maintained -F: drivers/firmware/qcom_qseecom_uefisecapp.c +F: drivers/firmware/qcom/qcom_qseecom_uefisecapp.c QUALCOMM RMNET DRIVER M: Subash Abhinov Kasiviswanathan diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 817e011a8945..74d00b0c83fe 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -188,53 +188,6 @@ config MTK_ADSP_IPC ADSP exists on some mtk processors. Client might use shared memory to exchange information with ADSP. -config QCOM_SCM - tristate - -config QCOM_SCM_DOWNLOAD_MODE_DEFAULT - bool "Qualcomm download mode enabled by default" - depends on QCOM_SCM - help - A device with "download mode" enabled will upon an unexpected - warm-restart enter a special debug mode that allows the user to - "download" memory content over USB for offline postmortem analysis. - The feature can be enabled/disabled on the kernel command line. - - Say Y here to enable "download mode" by default. - -config QCOM_QSEECOM - bool "Qualcomm QSEECOM interface driver" - depends on QCOM_SCM=y - select AUXILIARY_BUS - help - Various Qualcomm SoCs have a Secure Execution Environment (SEE) running - in the Trust Zone. This module provides an interface to that via the - QSEECOM mechanism, using SCM calls. - - The QSEECOM interface allows, among other things, access to applications - running in the SEE. An example of such an application is 'uefisecapp', - which is required to access UEFI variables on certain systems. If - selected, the interface will also attempt to detect and register client - devices for supported applications. - - Select Y here to enable the QSEECOM interface driver. - -config QCOM_QSEECOM_UEFISECAPP - bool "Qualcomm SEE UEFI Secure App client driver" - depends on QCOM_QSEECOM - depends on EFI - help - Various Qualcomm SoCs do not allow direct access to EFI variables. - Instead, these need to be accessed via the UEFI Secure Application - (uefisecapp), residing in the Secure Execution Environment (SEE). - - This module provides a client driver for uefisecapp, installing efivar - operations to allow the kernel accessing EFI variables, and via that also - provide user-space with access to EFI variables via efivarfs. - - Select Y here to provide access to EFI variables on the aforementioned - platforms. - config SYSFB bool select BOOT_VESA_SUPPORT @@ -320,6 +273,7 @@ source "drivers/firmware/efi/Kconfig" source "drivers/firmware/imx/Kconfig" source "drivers/firmware/meson/Kconfig" source "drivers/firmware/psci/Kconfig" +source "drivers/firmware/qcom/Kconfig" source "drivers/firmware/smccc/Kconfig" source "drivers/firmware/tegra/Kconfig" source "drivers/firmware/xilinx/Kconfig" diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index cb18fd8882dc..5f9dab82e1a0 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -17,10 +17,6 @@ obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o obj-$(CONFIG_MTK_ADSP_IPC) += mtk-adsp-ipc.o obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o -obj-$(CONFIG_QCOM_SCM) += qcom-scm.o -qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o -obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o -obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o obj-$(CONFIG_SYSFB) += sysfb.o obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o @@ -36,6 +32,7 @@ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ obj-y += efi/ obj-y += imx/ obj-y += psci/ +obj-y += qcom/ obj-y += smccc/ obj-y += tegra/ obj-y += xilinx/ diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig new file mode 100644 index 000000000000..3f05d9854ddf --- /dev/null +++ b/drivers/firmware/qcom/Kconfig @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/kconfig-language.rst. +# + +menu "Qualcomm firmware drivers" + +config QCOM_SCM + tristate + +config QCOM_SCM_DOWNLOAD_MODE_DEFAULT + bool "Qualcomm download mode enabled by default" + depends on QCOM_SCM + help + A device with "download mode" enabled will upon an unexpected + warm-restart enter a special debug mode that allows the user to + "download" memory content over USB for offline postmortem analysis. + The feature can be enabled/disabled on the kernel command line. + + Say Y here to enable "download mode" by default. + +config QCOM_QSEECOM + bool "Qualcomm QSEECOM interface driver" + depends on QCOM_SCM=y + select AUXILIARY_BUS + help + Various Qualcomm SoCs have a Secure Execution Environment (SEE) running + in the Trust Zone. This module provides an interface to that via the + QSEECOM mechanism, using SCM calls. + + The QSEECOM interface allows, among other things, access to applications + running in the SEE. An example of such an application is 'uefisecapp', + which is required to access UEFI variables on certain systems. If + selected, the interface will also attempt to detect and register client + devices for supported applications. + + Select Y here to enable the QSEECOM interface driver. + +config QCOM_QSEECOM_UEFISECAPP + bool "Qualcomm SEE UEFI Secure App client driver" + depends on QCOM_QSEECOM + depends on EFI + help + Various Qualcomm SoCs do not allow direct access to EFI variables. + Instead, these need to be accessed via the UEFI Secure Application + (uefisecapp), residing in the Secure Execution Environment (SEE). + + This module provides a client driver for uefisecapp, installing efivar + operations to allow the kernel accessing EFI variables, and via that also + provide user-space with access to EFI variables via efivarfs. + + Select Y here to provide access to EFI variables on the aforementioned + platforms. + +endmenu diff --git a/drivers/firmware/qcom/Makefile b/drivers/firmware/qcom/Makefile new file mode 100644 index 000000000000..c9f12ee8224a --- /dev/null +++ b/drivers/firmware/qcom/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the linux kernel. +# + +obj-$(CONFIG_QCOM_SCM) += qcom-scm.o +qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o +obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o +obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o diff --git a/drivers/firmware/qcom_qseecom.c b/drivers/firmware/qcom/qcom_qseecom.c similarity index 100% rename from drivers/firmware/qcom_qseecom.c rename to drivers/firmware/qcom/qcom_qseecom.c diff --git a/drivers/firmware/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c similarity index 100% rename from drivers/firmware/qcom_qseecom_uefisecapp.c rename to drivers/firmware/qcom/qcom_qseecom_uefisecapp.c diff --git a/drivers/firmware/qcom_scm-legacy.c b/drivers/firmware/qcom/qcom_scm-legacy.c similarity index 100% rename from drivers/firmware/qcom_scm-legacy.c rename to drivers/firmware/qcom/qcom_scm-legacy.c diff --git a/drivers/firmware/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c similarity index 100% rename from drivers/firmware/qcom_scm-smc.c rename to drivers/firmware/qcom/qcom_scm-smc.c diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c similarity index 100% rename from drivers/firmware/qcom_scm.c rename to drivers/firmware/qcom/qcom_scm.c diff --git a/drivers/firmware/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h similarity index 100% rename from drivers/firmware/qcom_scm.h rename to drivers/firmware/qcom/qcom_scm.h From patchwork Thu Sep 28 09:20:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402374 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CDA7CE7B11 for ; Thu, 28 Sep 2023 09:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231623AbjI1JVN (ORCPT ); Thu, 28 Sep 2023 05:21:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231594AbjI1JVJ (ORCPT ); Thu, 28 Sep 2023 05:21:09 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18E06194 for ; Thu, 28 Sep 2023 02:21:04 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4056ce55e7eso95471805e9.2 for ; Thu, 28 Sep 2023 02:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892862; x=1696497662; 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=nNsWyjWC2KILQ6F2y3+8u8Tzek7qyiCAnIFfqnam7kU=; b=zgRxP7rkh+9hH2pVaQ3+zo+yXjMhu//mQdL/h8JEc7x+qDdRL5Iw/sIlcMTXLF9Tu1 6cSaS1DlfJPrP4d3CGcWQiuJxA91W9RQzuXtHfvnx5wOra4DwY6gzZGUAk+f3pOobyh6 9rjYmyqt84X9e1b/gTKnFyEEyKVD5+yJRI8Kyz474vxVcbizenVzDZ/HteaO92V8qHmc cLOMnwl2TI2sy80roqYIU8I8DwMOKb4Km/uHArUAgiChfaSIsjRay6xiI4oHVFV71vXV pg4mpqkDhbrqc/yipibwKZxvkhXHrdkaK3JCu/+27rGXvA6/Iw25jj4piAYIdetYK1sQ DGFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892862; x=1696497662; 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=nNsWyjWC2KILQ6F2y3+8u8Tzek7qyiCAnIFfqnam7kU=; b=glLzw4E2k8wT6tShEPQesan5cE1XarwD1zobdvKiww9zMTO0nbNVopwZQMNVxIKS30 e84BR/tCSuiUwUqg/hL7js7WTzNvJDMJjOiCPesrOny3D8YA8ZWsnvoBwfC8j/QiAh/3 EkDcA4zfrmhwuZILCR6NmlMFMbHOeEXyZAAPLhoybyxxwGSs4j9/Gn/4EhfpmaZW9FuT 6mXJR/6+z8CPz04mDjd4gFc4T1xZm1yMgGDygR/qSN8sXFESoHZ7iQum0BjYG73e4wak NDUDoC+zHixA0KhMJl3x2R3JdiPDReTcSD1zKARdqQZAbxXKmAOB3tLr0LrnPIU7t4LP kNEQ== X-Gm-Message-State: AOJu0YwHN9chnJeG/u0Gq2PLMNqnAn+bOn7a9WXhs1dGhn3r1DvSb+tV 39TaG+Mt9UCzfcvD2CPVRoQVOA== X-Google-Smtp-Source: AGHT+IGErik4GB0DX/LD8k7UI+HrXtS8QQ+fAL2DZtgakvSe42h30GC6IAtMfeKkSokNwJ0Mencl2A== X-Received: by 2002:a5d:4f8e:0:b0:320:aea6:abb9 with SMTP id d14-20020a5d4f8e000000b00320aea6abb9mr645907wru.6.1695892862383; Thu, 28 Sep 2023 02:21:02 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:01 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 02/11] firmware: qcom: scm: add a dedicated SCM memory allocator Date: Thu, 28 Sep 2023 11:20:31 +0200 Message-Id: <20230928092040.9420-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski We have several SCM calls that require passing buffers to the trustzone on top of the SMC core which allocated memory for calls that require more than 4 arguments. Currently every user does their own thing which leads to code duplication. Many users call dma_alloc_coherent() for every call which is terribly unperformant (speed- and size-wise). As all but one calls allocate memory just for the duration of the call, we don't need a lot of memory. A single pool for that purpose is enough. Let's create a genalloc pool dealing out chunks of coherent, page-aligned memory suitable for SCM calls that also provides a function for mapping virtual to physical addresses. Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/Makefile | 2 +- drivers/firmware/qcom/qcom_scm-mem.c | 134 +++++++++++++++++++++++++ drivers/firmware/qcom/qcom_scm.c | 5 + drivers/firmware/qcom/qcom_scm.h | 7 ++ include/linux/firmware/qcom/qcom_scm.h | 7 ++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/qcom/qcom_scm-mem.c diff --git a/drivers/firmware/qcom/Makefile b/drivers/firmware/qcom/Makefile index c9f12ee8224a..b9b117f22e9f 100644 --- a/drivers/firmware/qcom/Makefile +++ b/drivers/firmware/qcom/Makefile @@ -4,6 +4,6 @@ # obj-$(CONFIG_QCOM_SCM) += qcom-scm.o -qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o +qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o qcom_scm-mem.o obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o diff --git a/drivers/firmware/qcom/qcom_scm-mem.c b/drivers/firmware/qcom/qcom_scm-mem.c new file mode 100644 index 000000000000..eafecbe23770 --- /dev/null +++ b/drivers/firmware/qcom/qcom_scm-mem.c @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qcom_scm.h" + +static size_t qcom_scm_mem_pool_size = SZ_2M; +module_param_named(qcom_scm_mem_pool_size, qcom_scm_mem_pool_size, + ulong, 0400); + +struct { + struct device *dev; + void *vbase; + phys_addr_t pbase; + size_t size; + struct gen_pool *pool; + struct radix_tree_root chunks; + spinlock_t lock; +} qcom_scm_mem; + +struct qcom_scm_mem_chunk { + phys_addr_t paddr; + size_t size; +}; + +void *qcom_scm_mem_alloc(size_t size, gfp_t gfp) +{ + struct qcom_scm_mem_chunk *chunk; + unsigned long vaddr; + int ret; + + if (!size) + return ZERO_SIZE_PTR; + + size = roundup(size, 1 << PAGE_SHIFT); + + chunk = kzalloc(sizeof(*chunk), gfp); + if (!chunk) + return NULL; + + vaddr = gen_pool_alloc(qcom_scm_mem.pool, size); + if (!vaddr) { + kfree(chunk); + return NULL; + } + + chunk->paddr = gen_pool_virt_to_phys(qcom_scm_mem.pool, + (unsigned long)vaddr); + chunk->size = size; + + scoped_guard(spinlock_irqsave, &qcom_scm_mem.lock) { + ret = radix_tree_insert(&qcom_scm_mem.chunks, vaddr, chunk); + if (ret) { + gen_pool_free(qcom_scm_mem.pool, (unsigned long)vaddr, + chunk->size); + kfree(chunk); + return NULL; + } + } + + return (void *)vaddr; +} +EXPORT_SYMBOL_GPL(qcom_scm_mem_alloc); + +void qcom_scm_mem_free(void *vaddr) +{ + struct qcom_scm_mem_chunk *chunk; + + if (!vaddr) + return; + + scoped_guard(spinlock_irqsave, &qcom_scm_mem.lock) + chunk = radix_tree_delete_item(&qcom_scm_mem.chunks, + (unsigned long)vaddr, NULL); + + if (!chunk) { + WARN(1, "Virtual address %p not allocated for SCM", vaddr); + return; + } + + gen_pool_free(qcom_scm_mem.pool, (unsigned long)vaddr, chunk->size); + kfree(chunk); +} +EXPORT_SYMBOL_GPL(qcom_scm_mem_free); + +phys_addr_t qcom_scm_mem_to_phys(void *vaddr) +{ + struct qcom_scm_mem_chunk *chunk; + + guard(spinlock_irqsave)(&qcom_scm_mem.lock); + + chunk = radix_tree_lookup(&qcom_scm_mem.chunks, (unsigned long)vaddr); + if (!chunk) + return 0; + + return chunk->paddr; +} + +int qcom_scm_mem_enable(struct device *dev) +{ + INIT_RADIX_TREE(&qcom_scm_mem.chunks, GFP_ATOMIC); + spin_lock_init(&qcom_scm_mem.lock); + qcom_scm_mem.dev = dev; + qcom_scm_mem.size = qcom_scm_mem_pool_size; + + qcom_scm_mem.vbase = dmam_alloc_coherent(dev, qcom_scm_mem.size, + &qcom_scm_mem.pbase, + GFP_KERNEL); + if (!qcom_scm_mem.vbase) + return -ENOMEM; + + qcom_scm_mem.pool = devm_gen_pool_create(dev, PAGE_SHIFT, -1, + "qcom-scm-mem"); + if (!qcom_scm_mem.pool) + return -ENOMEM; + + gen_pool_set_algo(qcom_scm_mem.pool, gen_pool_best_fit, NULL); + + return gen_pool_add_virt(qcom_scm_mem.pool, + (unsigned long)qcom_scm_mem.vbase, + qcom_scm_mem.pbase, qcom_scm_mem.size, -1); +} diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index c2c7fafef34b..258aa0782754 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1880,6 +1880,11 @@ static int qcom_scm_probe(struct platform_device *pdev) if (of_property_read_bool(pdev->dev.of_node, "qcom,sdi-enabled")) qcom_scm_disable_sdi(); + ret = qcom_scm_mem_enable(scm->dev); + if (ret) + return dev_err_probe(scm->dev, ret, + "Failed to enable SCM memory\n"); + /* * Initialize the QSEECOM interface. * diff --git a/drivers/firmware/qcom/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h index 7b68fa820495..8c97e3906afa 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -4,6 +4,10 @@ #ifndef __QCOM_SCM_INT_H #define __QCOM_SCM_INT_H +#include + +struct device; + enum qcom_scm_convention { SMC_CONVENTION_UNKNOWN, SMC_CONVENTION_LEGACY, @@ -165,4 +169,7 @@ static inline int qcom_scm_remap_error(int err) return -EINVAL; } +int qcom_scm_mem_enable(struct device *dev); +phys_addr_t qcom_scm_mem_to_phys(void *vaddr); + #endif diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h index ccaf28846054..291ef8fd21b0 100644 --- a/include/linux/firmware/qcom/qcom_scm.h +++ b/include/linux/firmware/qcom/qcom_scm.h @@ -5,7 +5,9 @@ #ifndef __QCOM_SCM_H #define __QCOM_SCM_H +#include #include +#include #include #include @@ -61,6 +63,11 @@ enum qcom_scm_ice_cipher { bool qcom_scm_is_available(void); +void *qcom_scm_mem_alloc(size_t size, gfp_t gfp); +void qcom_scm_mem_free(void *vaddr); + +DEFINE_FREE(qcom_scm_mem, void *, if (_T) qcom_scm_mem_free(_T)); + int qcom_scm_set_cold_boot_addr(void *entry); int qcom_scm_set_warm_boot_addr(void *entry); void qcom_scm_cpu_power_down(u32 flags); From patchwork Thu Sep 28 09:20:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402372 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA080CE7B10 for ; Thu, 28 Sep 2023 09:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231615AbjI1JVM (ORCPT ); Thu, 28 Sep 2023 05:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231577AbjI1JVJ (ORCPT ); Thu, 28 Sep 2023 05:21:09 -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 DBDFC196 for ; Thu, 28 Sep 2023 02:21:04 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-32008e339adso11780183f8f.2 for ; Thu, 28 Sep 2023 02:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892863; x=1696497663; 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=Bhvnh9OE997tswH9jSZ8GJnXlXkzgsgO3a5Q/DPonFc=; b=rvFi8Fj8kRtdFRgW6wXh3179g3cMjGHxkNRoATwjwng8kbLqBx+JJNNqzjHt0P0LBB cV8mMkePJka1Ib6SlbVlRclzX+34BIys67X1FehYJvuImv22zkPim20wNH3clLSqEELt 51YP9pbaIPwLxcSSwvclA/Zom94D/6FMkFyW0yafwHDipLaMHnYsF6qyPup+e8oBcfal dZ2zncJxXDll7AM+bSwoFOSXfQTzRfWjS7ryOtECZ4ogFBw4YemmBbeUvJy4C0ZnPFXb EoFUXb52iPkCO80aL6shXYYREAadXUpFzn3nJCJpetwa8IJNgOgkRozOI8hCxUxJIi33 G6Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892863; x=1696497663; 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=Bhvnh9OE997tswH9jSZ8GJnXlXkzgsgO3a5Q/DPonFc=; b=AnMDFkv5COtuQeYyDSupjt3hv+7D+AFf5z3GfENtSqp3JT40igWwkIXYvCiQEucB2C O52WfytwKPTVWiO6z17Io+k2cNKpjzAqVZ3xPYmyhUgfmkGzwwo5d7oIKl74keph3/8l 6Iz9e8hWC46RC2mUANe0Sj9GPwWDXUcj8TikHVbEB6uXwqbNz92NsG09YyldPR87XrVN ah55ntyUamLKJSiG5/MGiHaucaHF6dnowtMUJdenMkQ2draVzV5/Z029gmyEWE84er5i bB6JQhCAF8SXA4pJzlLjojnd1lJ0sXuCCoxyQcs2lDNRNm5MYAKferytfr9aNE9dH+dE lCvQ== X-Gm-Message-State: AOJu0Ywr9JFxU2qWuI7k78ufzO5oN6rQOhe66t3zS5kI2zNSRwK2AMH3 djIC9F13BphTw6QHuDnzbAGfPg== X-Google-Smtp-Source: AGHT+IGQyggTMr9G3lck9DdE2/M/2/aJTExkk54GkglOS8vF8v+T6QNbn/6+dVleA/C2S/3U7G2ykQ== X-Received: by 2002:a5d:414e:0:b0:320:1d1:71c4 with SMTP id c14-20020a5d414e000000b0032001d171c4mr646792wrq.23.1695892863407; Thu, 28 Sep 2023 02:21:03 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:02 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 03/11] firmware: qcom: scm: switch to using the SCM allocator Date: Thu, 28 Sep 2023 11:20:32 +0200 Message-Id: <20230928092040.9420-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski We need to allocate, map and pass a buffer to the trustzone if we have more than 4 arguments for a given SCM calls. Let's use the new SCM allocator for that memory and shrink the code in process. Signed-off-by: Bartosz Golaszewski Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm-smc.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c index 16cf88acfa8e..0d5554df1321 100644 --- a/drivers/firmware/qcom/qcom_scm-smc.c +++ b/drivers/firmware/qcom/qcom_scm-smc.c @@ -2,6 +2,7 @@ /* Copyright (c) 2015,2019 The Linux Foundation. All rights reserved. */ +#include #include #include #include @@ -152,8 +153,7 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, { int arglen = desc->arginfo & 0xf; int i, ret; - dma_addr_t args_phys = 0; - void *args_virt = NULL; + void *args_virt __free(qcom_scm_mem) = NULL; size_t alloc_len; gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL; u32 smccc_call_type = atomic ? ARM_SMCCC_FAST_CALL : ARM_SMCCC_STD_CALL; @@ -173,7 +173,7 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, if (unlikely(arglen > SCM_SMC_N_REG_ARGS)) { alloc_len = SCM_SMC_N_EXT_ARGS * sizeof(u64); - args_virt = kzalloc(PAGE_ALIGN(alloc_len), flag); + args_virt = qcom_scm_mem_alloc(PAGE_ALIGN(alloc_len), flag); if (!args_virt) return -ENOMEM; @@ -192,25 +192,12 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, SCM_SMC_FIRST_EXT_IDX]); } - args_phys = dma_map_single(dev, args_virt, alloc_len, - DMA_TO_DEVICE); - - if (dma_mapping_error(dev, args_phys)) { - kfree(args_virt); - return -ENOMEM; - } - - smc.args[SCM_SMC_LAST_REG_IDX] = args_phys; + smc.args[SCM_SMC_LAST_REG_IDX] = qcom_scm_mem_to_phys(args_virt); } /* ret error check follows after args_virt cleanup*/ ret = __scm_smc_do(dev, &smc, &smc_res, atomic); - if (args_virt) { - dma_unmap_single(dev, args_phys, alloc_len, DMA_TO_DEVICE); - kfree(args_virt); - } - if (ret) return ret; From patchwork Thu Sep 28 09:20:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402371 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE587CE7B0F for ; Thu, 28 Sep 2023 09:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231612AbjI1JVK (ORCPT ); Thu, 28 Sep 2023 05:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231576AbjI1JVJ (ORCPT ); Thu, 28 Sep 2023 05:21:09 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA0C199 for ; Thu, 28 Sep 2023 02:21:06 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-313e742a787so8460827f8f.1 for ; Thu, 28 Sep 2023 02:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892864; x=1696497664; 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=N+8cU6fa0dkOhujc4CdFNdtWDl3dgQeMzHDKVHwQ4Uk=; b=dhOblrfEXhCc8eGhlP1uuRUkq/MRbKiM3rBOvnXbMhGbkurjaNlolnkxz+WsT9X/j+ PXdTYxYLp6bjl6jI/k2QMS4PvcRi98icXp7QPr+pEfl0nODKi+sfPnhDWmc/VyLYqO2G KBXpkq19mSIa6wu+DwhjFdJ9PFYhauOZ4eOdcEYwK/b8BTn3HSjBIx5IFHaXT+g5cglQ jqtmNDMQ5Q65p+ffG5WMQbeSgpf2es1pcJ32+LoMlk1n2pW5qOS4py77sb6mGLn1+fnY mDGvLmmJRnVqD74BbXuzYQQj9rs+WyGA7Cy7fGt6aHNYBn2j+gOxEahgvDAX6YH9keJB wqEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892864; x=1696497664; 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=N+8cU6fa0dkOhujc4CdFNdtWDl3dgQeMzHDKVHwQ4Uk=; b=bmYv+q2ayZyPiZooiMbGj+crvsPYRl8FTypeLj87juLeu0dh0yK+mj8gdVrqn/cE0W B67Qx0JlS4PxtpzbkCnW5uZ5BbovVFyHKw2FhKQ3ewda8uxVmUMmh//KkecMU9K0vB3W QpscdaHMED6ZrypIEmY0gkyoem0G2sL2l1pijIjTJ8lbwnTX6kZnUt5QyiUAxCxIKIXY TeO+tyrZ5lpzv5cs4HkekrgyRnSZYmn20XK+2PR5GnI8lsCur8SXV0YyDFpl+bjCXEnU ruCne4qG0HStHR8fPW7s6qfu9PiNB8tlXyBhl7r9Z/VTGwIxeJs9iiMYH1qcWsRuCBc0 AZTQ== X-Gm-Message-State: AOJu0YxtnxxAp5YU5JZUKfyk7w+HcdemaPBnywF/IbmwNaadE7Fzehuc Mc/2CfwPc+7xovpJh4yxIGfhYQ== X-Google-Smtp-Source: AGHT+IGVetIztwUx9e5fsOM8aoZ5wMthqjBBfRyYVH2TEGcRvOzHPG/fdnn5hKofi6FzRNpM0cutzg== X-Received: by 2002:a5d:5265:0:b0:314:314e:fdda with SMTP id l5-20020a5d5265000000b00314314efddamr759882wrc.23.1695892864488; Thu, 28 Sep 2023 02:21:04 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:03 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 04/11] firmware: qcom: scm: make qcom_scm_assign_mem() use the SCM allocator Date: Thu, 28 Sep 2023 11:20:33 +0200 Message-Id: <20230928092040.9420-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Let's use the new SCM memory allocator to obtain a buffer for this call instead of using dma_alloc_coherent(). Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 258aa0782754..0c532e794b92 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -980,14 +981,13 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, struct qcom_scm_mem_map_info *mem_to_map; phys_addr_t mem_to_map_phys; phys_addr_t dest_phys; - dma_addr_t ptr_phys; + phys_addr_t ptr_phys; size_t mem_to_map_sz; size_t dest_sz; size_t src_sz; size_t ptr_sz; int next_vm; __le32 *src; - void *ptr; int ret, i, b; u64 srcvm_bits = *srcvm; @@ -997,10 +997,12 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, ptr_sz = ALIGN(src_sz, SZ_64) + ALIGN(mem_to_map_sz, SZ_64) + ALIGN(dest_sz, SZ_64); - ptr = dma_alloc_coherent(__scm->dev, ptr_sz, &ptr_phys, GFP_KERNEL); + void *ptr __free(qcom_scm_mem) = qcom_scm_mem_alloc(ptr_sz, GFP_KERNEL); if (!ptr) return -ENOMEM; + ptr_phys = qcom_scm_mem_to_phys(ptr); + /* Fill source vmid detail */ src = ptr; i = 0; @@ -1029,7 +1031,6 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, ret = __qcom_scm_assign_mem(__scm->dev, mem_to_map_phys, mem_to_map_sz, ptr_phys, src_sz, dest_phys, dest_sz); - dma_free_coherent(__scm->dev, ptr_sz, ptr, ptr_phys); if (ret) { dev_err(__scm->dev, "Assign memory protection call failed %d\n", ret); From patchwork Thu Sep 28 09:20:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402378 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E916CE7B0F for ; Thu, 28 Sep 2023 09:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231621AbjI1JVV (ORCPT ); Thu, 28 Sep 2023 05:21:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231620AbjI1JVM (ORCPT ); Thu, 28 Sep 2023 05:21:12 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA45819E for ; Thu, 28 Sep 2023 02:21:06 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3231d67aff2so9067065f8f.0 for ; Thu, 28 Sep 2023 02:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892865; x=1696497665; 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=9ZW43V/v3JWndTZOC7qgio7lrKv8+8C3I99C3oqf4j4=; b=aPvgkqbsvfVwIlxZ5kifPEF6X1I6p/Ui9LLR1DB0nUyIlD6CVGUI1GzbWmV3GYOQ2i z0iY41FSlTPuDhyzTOit1BDfZ6cQRNe9/71fYVQLO6ehGP+NIxxPeEfVzF+xGcT2BDvJ XScbx0+yazklQ3oAzmpQrZzGq8zY8GbjKNAxaLnP8D38xt9/mOvWxOgcSK8Fj6c4gGX5 hwFfPQjCdWpew9HnghopB9QpPCXwNkbjjfb5nXtP5UhT8YHoFZXgsWcbkV0CiG4DGAsl tVNpe0FCNZeQi/x9hNjRzL7EBaqlBT4oCJP76OX26Udcax/ExwHlxUZBY/WH+x2N4vwm rnmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892865; x=1696497665; 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=9ZW43V/v3JWndTZOC7qgio7lrKv8+8C3I99C3oqf4j4=; b=cU096fwim/wu5ro4sHx5OGX6b36QWfNcPytsQMYuX8hMqmq1OA8o07Kivt3sYRSKkE VVbYglMRbNphetQqt/aX3y2Po1CbIXdHqbGGgUt3ewOGMX75aJrrJ8Vv9sMzpW3RVkCF FASTsnZUaunah4CzpV5BZQMZBa8lQ81L5lwJzuNCTAQ6/Rd/O0/c+6ijHpn54RSYlFGg ZxPMorn2B3LjRs8U/Zhr5MX2ShTHzAFifQu77G9oxwiGDY0L2ZtU7NO84wVlPGUemvYz fBkpd7xLx4Q5oGHl5bGLh7vq/Fm1QXJvjbbAT3wPf3juwXgNtpj1IiysitBqIYhj3KrU scmQ== X-Gm-Message-State: AOJu0Yyty+hG+3y9u4/5jRdwoCGSViNMURzTuul9/0eehxJcRXSbF9Pz MgdQe64tHdKy3UQCRWAVPIveJA== X-Google-Smtp-Source: AGHT+IGU8fq0UfbdbTwUDInx0JxJRpcIfEfLXVz++58oYsMwLcj0wCKrGqT2OMwI2QS2w+e8UDnaBA== X-Received: by 2002:adf:e912:0:b0:31a:d8c0:cb8b with SMTP id f18-20020adfe912000000b0031ad8c0cb8bmr517938wrm.25.1695892865407; Thu, 28 Sep 2023 02:21:05 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:04 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 05/11] firmware: qcom: scm: make qcom_scm_ice_set_key() use the SCM allocator Date: Thu, 28 Sep 2023 11:20:34 +0200 Message-Id: <20230928092040.9420-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Let's use the new SCM memory allocator to obtain a buffer for this call instead of using dma_alloc_coherent(). Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 0c532e794b92..02a773ba1383 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1178,32 +1178,20 @@ int qcom_scm_ice_set_key(u32 index, const u8 *key, u32 key_size, .args[4] = data_unit_size, .owner = ARM_SMCCC_OWNER_SIP, }; - void *keybuf; - dma_addr_t key_phys; + int ret; - /* - * 'key' may point to vmalloc()'ed memory, but we need to pass a - * physical address that's been properly flushed. The sanctioned way to - * do this is by using the DMA API. But as is best practice for crypto - * keys, we also must wipe the key after use. This makes kmemdup() + - * dma_map_single() not clearly correct, since the DMA API can use - * bounce buffers. Instead, just use dma_alloc_coherent(). Programming - * keys is normally rare and thus not performance-critical. - */ - - keybuf = dma_alloc_coherent(__scm->dev, key_size, &key_phys, - GFP_KERNEL); + void *keybuf __free(qcom_scm_mem) = qcom_scm_mem_alloc(key_size, + GFP_KERNEL); if (!keybuf) return -ENOMEM; memcpy(keybuf, key, key_size); - desc.args[1] = key_phys; + desc.args[1] = qcom_scm_mem_to_phys(keybuf); ret = qcom_scm_call(__scm->dev, &desc, NULL); memzero_explicit(keybuf, key_size); - dma_free_coherent(__scm->dev, key_size, keybuf, key_phys); return ret; } EXPORT_SYMBOL_GPL(qcom_scm_ice_set_key); From patchwork Thu Sep 28 09:20:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402376 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 993D7CE7B13 for ; Thu, 28 Sep 2023 09:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231604AbjI1JVP (ORCPT ); Thu, 28 Sep 2023 05:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbjI1JVJ (ORCPT ); Thu, 28 Sep 2023 05:21:09 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EB2A91 for ; Thu, 28 Sep 2023 02:21:08 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3215f19a13aso12511419f8f.3 for ; Thu, 28 Sep 2023 02:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892866; x=1696497666; 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=nxuIylgD4O5skgVzMv0zVAkT/q/ETWmaZKIykuazMpk=; b=QsZQMhMR3GBlsKJ7Hh7RI2aRGHO/11F+Zwd3LGwooLhEF9xpYgSdM3YZKHCuA3LTH0 pY3AuWOHLJmI3j/pyBmu5avFSn9jqc6wUDK5UmCDZ3vE6OeoC51UGWYj4lz8HHH7zqhv 1Y3FnQImB+qkBxQNrbPKvsRchdc9j+z43X9h/yVD++PpY9SX3O/f6u1OPiYpU5jnX7Jm lw74P8IZDMlNPlk73nRG896X8r4SuyqB8s1bRccr6oINpNlge11A4BVeoMfhqGBWAH+6 Kgqz1kN8uU3gDZxTA7M91vFsL15dZMKb07d1SqRCAAMyFXKoJDiDcw+PeJAeMy4Y9zAe oJbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892866; x=1696497666; 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=nxuIylgD4O5skgVzMv0zVAkT/q/ETWmaZKIykuazMpk=; b=kMncGoD7/4aLUKp6os0Way30E1ha9Bvgfm9iMNdGSWhTHFWyW0YJaSFXp6RHPM7mH8 qeH0/sDnxIR2k8inbsw28v2FAqTMjoLJ+O9Ctmi+N5v+DXp3ERuTX5+UAQBlZXqsziVm 46IU2fd+0RU5nKZiILml3Bd04YYUXOaOmcJdbqp24XH6iCrB1JbcvOMKuaW35gh5oAJj C/hCdZ4ULk1y8Xl0nesWcgl3UjiA8MTRdiGnfOQTQeSXsPVqv8OaFtsV2HtJl3h9/ttY OGJnwlQai5Z+/8HPNWpfwt6w/TUPvgxIZMX/lCty776MlSfhdZFbXvXxKv34eVYa6Drq ZHaA== X-Gm-Message-State: AOJu0YwuSrDEWlmL4ztbyU4+XBp6NDSFAC01PvN2QNrbzA1gRJjny+TV 36NQkrn3XvLSlTTk3LvorQKevA== X-Google-Smtp-Source: AGHT+IFVdk+4oowEHrdz9K3WGGEAaEyXcokWoURuedmb7qV3jLDHDso0F0EVxA9ZdUmIT+q0OGu50Q== X-Received: by 2002:a05:6000:11c7:b0:321:6005:8979 with SMTP id i7-20020a05600011c700b0032160058979mr787869wrx.17.1695892866569; Thu, 28 Sep 2023 02:21:06 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:06 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 06/11] firmware: qcom: scm: make qcom_scm_pas_init_image() use the SCM allocator Date: Thu, 28 Sep 2023 11:20:35 +0200 Message-Id: <20230928092040.9420-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Let's use the new SCM memory allocator to obtain a buffer for this call instead of using dma_alloc_coherent(). Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 02a773ba1383..c0eb81069847 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -532,7 +532,7 @@ static void qcom_scm_set_download_mode(bool enable) int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, struct qcom_scm_pas_metadata *ctx) { - dma_addr_t mdata_phys; + phys_addr_t mdata_phys; void *mdata_buf; int ret; struct qcom_scm_desc desc = { @@ -544,13 +544,7 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, }; struct qcom_scm_res res; - /* - * During the scm call memory protection will be enabled for the meta - * data blob, so make sure it's physically contiguous, 4K aligned and - * non-cachable to avoid XPU violations. - */ - mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys, - GFP_KERNEL); + mdata_buf = qcom_scm_mem_alloc(size, GFP_KERNEL); if (!mdata_buf) { dev_err(__scm->dev, "Allocation of metadata buffer failed.\n"); return -ENOMEM; @@ -574,10 +568,10 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, out: if (ret < 0 || !ctx) { - dma_free_coherent(__scm->dev, size, mdata_buf, mdata_phys); + qcom_scm_mem_free(mdata_buf); } else if (ctx) { ctx->ptr = mdata_buf; - ctx->phys = mdata_phys; + ctx->phys = qcom_scm_mem_to_phys(mdata_buf); ctx->size = size; } @@ -594,7 +588,7 @@ void qcom_scm_pas_metadata_release(struct qcom_scm_pas_metadata *ctx) if (!ctx->ptr) return; - dma_free_coherent(__scm->dev, ctx->size, ctx->ptr, ctx->phys); + qcom_scm_mem_free(ctx->ptr); ctx->ptr = NULL; ctx->phys = 0; From patchwork Thu Sep 28 09:20:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402375 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5E39CE7B0F for ; Thu, 28 Sep 2023 09:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231594AbjI1JVO (ORCPT ); Thu, 28 Sep 2023 05:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231604AbjI1JVK (ORCPT ); Thu, 28 Sep 2023 05:21:10 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA17AC for ; Thu, 28 Sep 2023 02:21:08 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40651a726acso4141145e9.1 for ; Thu, 28 Sep 2023 02:21:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892867; x=1696497667; 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=cMUOZtKJMrzKTINi50r8H43dxWG3CrCNn5eWPcC1U+s=; b=V6KJhyv+CI1ywrMLPvGcD5Kg/O+5RBC9BjqQbRquufFGbdKhhYRWWMUFoLPQO5tKKi 1UjVua8wPZcqUHIvV5X1oOAprepfb9Er5C53j3R8u5mgANladoYEM9+N7b43ES8U7vEw Kjq6coVL6ZgScV3/0SetYdM+FtmRezxvMDn+KwlHoaD9nOBiPv256aI9GvZvwWZcPBnU Zkg2cNamY25VJJyzzOEv9nP7UPw0cdKEgVUzyIWcLyVOGV+S28RzHK0balzXcsalUDph ouq8diM+9uYwQrCCTv16AtJI7OvVDZi1KLUzp0a/k1mmJg1vtc3DaG1tpZdBV4o230Xx zy0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892867; x=1696497667; 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=cMUOZtKJMrzKTINi50r8H43dxWG3CrCNn5eWPcC1U+s=; b=bs0OIGDGpoSBi9eC0UnI08qKINtlmSgBYo0AwSGm7AFj1hlfemlxAfr3uIdOuf9nQV Jy+icIHO+Gcs/D0IhaXeolN/NIbJpOJzPRGuZO48SUQQaJJHQGZ8IX1B5rKph/jRA7QL mJeprLvM6tmsr8O7MbuhSdoWrE5tei5SWoReqRZyV2/IaHI+aDFTlgYr1ZNHgeCEduci 0FlTKLDLVSaSO/YI+rD8TGi5Sdi22lkW45VL10ocgQFe6ZMRGPvhu//X+3D0mXYUv+o+ Hqkm6l6vHu2kf96OyTo3gRQUn4SI7oLOgnf/a414UFlEfxBhxVeWHFd9A3C+HqMT0KnM SlOA== X-Gm-Message-State: AOJu0Ywpb7eu5+8SBrYItPiJAjChltNv3/dQInzsvv+V9GKXJIiCeBqQ L90R0RRbANH+Vn3nvxytnThw3Q== X-Google-Smtp-Source: AGHT+IHNm24nnyzc21GioxW/QCUjRtrrlArL8lDqRdbG7DKp4ukJxT99U9KptV/WZL8/gUs8oQNJww== X-Received: by 2002:a05:6000:109:b0:317:f70b:3156 with SMTP id o9-20020a056000010900b00317f70b3156mr674945wrx.28.1695892867487; Thu, 28 Sep 2023 02:21:07 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:07 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 07/11] firmware: qcom: scm: make qcom_scm_lmh_dcvsh() use the SCM allocator Date: Thu, 28 Sep 2023 11:20:36 +0200 Message-Id: <20230928092040.9420-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Let's use the new SCM memory allocator to obtain a buffer for this call instead of using dma_alloc_coherent(). Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index c0eb81069847..41095bf1d4d7 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1314,8 +1314,6 @@ EXPORT_SYMBOL_GPL(qcom_scm_lmh_profile_change); int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, u64 limit_node, u32 node_id, u64 version) { - dma_addr_t payload_phys; - u32 *payload_buf; int ret, payload_size = 5 * sizeof(u32); struct qcom_scm_desc desc = { @@ -1330,7 +1328,8 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, .owner = ARM_SMCCC_OWNER_SIP, }; - payload_buf = dma_alloc_coherent(__scm->dev, payload_size, &payload_phys, GFP_KERNEL); + u32 *payload_buf __free(qcom_scm_mem) = + qcom_scm_mem_alloc(payload_size, GFP_KERNEL); if (!payload_buf) return -ENOMEM; @@ -1340,11 +1339,10 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, payload_buf[3] = 1; payload_buf[4] = payload_val; - desc.args[0] = payload_phys; + desc.args[0] = qcom_scm_mem_to_phys(payload_buf); ret = qcom_scm_call(__scm->dev, &desc, NULL); - dma_free_coherent(__scm->dev, payload_size, payload_buf, payload_phys); return ret; } EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh); From patchwork Thu Sep 28 09:20:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402377 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DC8FCE7B14 for ; Thu, 28 Sep 2023 09:21:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231571AbjI1JVQ (ORCPT ); Thu, 28 Sep 2023 05:21:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231593AbjI1JVL (ORCPT ); Thu, 28 Sep 2023 05:21:11 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E64B3C0 for ; Thu, 28 Sep 2023 02:21:09 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-323ef9a8b59so3194547f8f.3 for ; Thu, 28 Sep 2023 02:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892868; x=1696497668; 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=K7e3uVvAU/9XxRD0WWB/UR6KH+g5Ytg3FZjMRpb3BmQ=; b=W9T4z9ZQ+Qcn35oxemG3I1bDWjfrEMLol/kezXmKOKgPMscV43tFkENsSp1gEgUVuU FUAP2hVvYqPn3ptc/4699PpDsG+btbJMlAEVQ1UdcoB5V6w53/S2KZDsb1Nl4i9vaWy2 lgEL7ajqywW5RwL3uUnHC0XjyT1nhQQfnDJ5/ACnc+b1ljnJpb+tInkhXvDQLagWZOzO QfT3YAaqJoVUGbupp6lYyyNuExhhqvJHSJrzXhmaTD9FMTyIWGvGRcFy9CvVZll+57or tYE8l43JKlvPMYyvsHfkNSstQwM+jd8Ec26jabqxZ9pauQwTyWt1NUhmPYcYvO1ghjfb N20A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892868; x=1696497668; 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=K7e3uVvAU/9XxRD0WWB/UR6KH+g5Ytg3FZjMRpb3BmQ=; b=iVObaQyJUzv3mW+wpeLAdsC03I1YMbDS2WsqAozazX0ZzhSdceR1LXU78Yffb+5ZDL qbtLYjb1liMMRaEZhzFth1JagNhG7QZpiWlPC/9tQCS3yFgmiiNytaVBRfRVwjN5ktaR 4Ro1JuExsg7UNW6e7sFRgw2p6HtswQXJzCDXL2+LB/WxwFoutdlTe3ft+ov0oKfCl7Hd PyE7fgYunQvjVMV9KYNAJmWvsZYiN2/R6I6lBj9xbM9Hj8/CWY9eWVXE25KQ+6jEItkr FVIhMOXzi8XO23Z4YGlYqwzNE4PKgBZzRpZKyt9toSaHgkQYMTqnINs89atC35NK1UVQ rE5g== X-Gm-Message-State: AOJu0YwQAoDIyom4bqhrC803QHQjcJ7LoHFQKdchsDfQ5xEBNhUhRU6b 5TrY2G7/PpyG9pvSRfhT1xXuqQ== X-Google-Smtp-Source: AGHT+IHvPdg1US9zOhiS3vntMewiD0dIhRhPvx/9zL+4s/NAyPLZSQZEFla7sCsnTQM4eWM79WOwvA== X-Received: by 2002:a5d:6188:0:b0:321:707a:8ca5 with SMTP id j8-20020a5d6188000000b00321707a8ca5mr681117wru.38.1695892868485; Thu, 28 Sep 2023 02:21:08 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:08 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [RFT PATCH v2 08/11] firmware: qcom: scm: make qcom_scm_qseecom_app_get_id() use the SCM allocator Date: Thu, 28 Sep 2023 11:20:37 +0200 Message-Id: <20230928092040.9420-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Let's use the new SCM memory allocator to obtain a buffer for this call instead of manually kmalloc()ing it and then mapping to physical space. Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 41095bf1d4d7..37e876437a3e 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1498,37 +1498,26 @@ int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id) unsigned long app_name_len = strlen(app_name); struct qcom_scm_desc desc = {}; struct qcom_scm_qseecom_resp res = {}; - dma_addr_t name_buf_phys; - char *name_buf; int status; if (app_name_len >= name_buf_size) return -EINVAL; - name_buf = kzalloc(name_buf_size, GFP_KERNEL); + char *name_buf __free(qcom_scm_mem) = qcom_scm_mem_alloc(name_buf_size, + GFP_KERNEL); if (!name_buf) return -ENOMEM; memcpy(name_buf, app_name, app_name_len); - name_buf_phys = dma_map_single(__scm->dev, name_buf, name_buf_size, DMA_TO_DEVICE); - status = dma_mapping_error(__scm->dev, name_buf_phys); - if (status) { - kfree(name_buf); - dev_err(__scm->dev, "qseecom: failed to map dma address\n"); - return status; - } - desc.owner = QSEECOM_TZ_OWNER_QSEE_OS; desc.svc = QSEECOM_TZ_SVC_APP_MGR; desc.cmd = QSEECOM_TZ_CMD_APP_LOOKUP; desc.arginfo = QCOM_SCM_ARGS(2, QCOM_SCM_RW, QCOM_SCM_VAL); - desc.args[0] = name_buf_phys; + desc.args[0] = qcom_scm_mem_to_phys(name_buf); desc.args[1] = app_name_len; status = qcom_scm_qseecom_call(&desc, &res); - dma_unmap_single(__scm->dev, name_buf_phys, name_buf_size, DMA_TO_DEVICE); - kfree(name_buf); if (status) return status; From patchwork Thu Sep 28 09:20:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402379 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B990CE7B10 for ; Thu, 28 Sep 2023 09:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231681AbjI1JVW (ORCPT ); Thu, 28 Sep 2023 05:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbjI1JVU (ORCPT ); Thu, 28 Sep 2023 05:21:20 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDF758E for ; Thu, 28 Sep 2023 02:21:10 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-307d20548adso11139670f8f.0 for ; Thu, 28 Sep 2023 02:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892869; x=1696497669; 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=DChZlKiRZBb+j9T+a7xaqTe29l5ns2EGQ+8Evv55SQ0=; b=VGhcNMGLASdza++zjFMauVKYRrcfGSkWDYO01/+Uv4R/4gY6YG7G4g7XdTciEuk5GZ 9/OOfY93zl8jLqoY8Iaiv1YmadoYnY+sS2zpvbouUjre/aiKnS7oH6XB/3j9hiIl1M/H TaxDEuLPhwTvr2gxYR7hcukjoAsYyicYtFmyUZ6nxTGZmRiVIE6ZRFXnjb217WahXvja g1Kn4fxg5ZDflcrLeBwEG+S/4LrNJ3WABfqT0+Ctb8tf6nFRS86wW/coJCwCcPP1VKwI LZPABht6nA5r2RPsKv0JWOEN2tnL6dBX/vHi1Orli7h0EyIpnuDQ+GZqoUW5pWfKRrIA bbXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892869; x=1696497669; 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=DChZlKiRZBb+j9T+a7xaqTe29l5ns2EGQ+8Evv55SQ0=; b=qWq41DA2Emomvm4nW+v8UXFMVXQvCxGi/jNAZcGQUPiuz78gmULVuoP1YQYWYUj3e6 PPsb8WyEfFu1pha6MNb6h5ufMAB2mo0nA01Edmtu9XRZufjDSWEoEonhgMJ45XxsGaFl S9LTJFbLDn7E9cjlyruJAD9Pnau7lA6wHoTqUWObb7vB+7LoaovKt52MKyHJq1MMMG8T G/xAiyuDBkcKWmDjX8+/zt0tVxXArcnneBHznj+U9DwImPqpKSbQ4+FcDrxVyCznZZvE 0TFNr5qOPX2SbI5a4gg+u5jF061qw0vvfInVkvClVfpXHExyV2Iwaxhn7DnOWwOlc2J5 K8dg== X-Gm-Message-State: AOJu0YymczrTOZ3ZH5dMELGIqecXcw7mJxS0mmMAxdVixi0JdqFrhN3L iKEvAUlSQaToXxn7jlWha9dLkw== X-Google-Smtp-Source: AGHT+IEAP7K95Ly9Ht0h5K6DYb82jnr0aCxin44ahWlMIIyaupj/cgxOA20sBwxNMoVTZAFK/dBK+A== X-Received: by 2002:adf:e683:0:b0:321:6f5f:789f with SMTP id r3-20020adfe683000000b003216f5f789fmr689014wrm.39.1695892869429; Thu, 28 Sep 2023 02:21:09 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:09 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [RFT PATCH v2 09/11] firmware: qcom: qseecom: convert to using the SCM allocator Date: Thu, 28 Sep 2023 11:20:38 +0200 Message-Id: <20230928092040.9420-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Drop the DMA mapping operations from qcom_scm_qseecom_app_send() and convert all users of it in the qseecom module to using the SCM allocator for creating SCM call buffers. Together with using the cleanup macros, it has the added benefit of a significant code shrink Signed-off-by: Bartosz Golaszewski --- .../firmware/qcom/qcom_qseecom_uefisecapp.c | 251 ++++++------------ drivers/firmware/qcom/qcom_scm.c | 31 +-- include/linux/firmware/qcom/qcom_qseecom.h | 4 +- 3 files changed, 94 insertions(+), 192 deletions(-) diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c index a33acdaf7b78..59193716161d 100644 --- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c +++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c @@ -7,6 +7,7 @@ * Copyright (C) 2023 Maximilian Luz */ +#include #include #include #include @@ -18,6 +19,7 @@ #include #include +#include /* -- Qualcomm "uefisecapp" interface definitions. -------------------------- */ @@ -272,11 +274,11 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e const efi_guid_t *guid, u32 *attributes, unsigned long *data_size, void *data) { - struct qsee_req_uefi_get_variable *req_data; - struct qsee_rsp_uefi_get_variable *rsp_data; + struct qsee_req_uefi_get_variable *req_data __free(qcom_scm_mem) = NULL; + struct qsee_rsp_uefi_get_variable *rsp_data __free(qcom_scm_mem) = NULL; unsigned long buffer_size = *data_size; - efi_status_t efi_status = EFI_SUCCESS; unsigned long name_length; + efi_status_t efi_status; size_t guid_offs; size_t name_offs; size_t req_size; @@ -304,17 +306,13 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e __array(u8, buffer_size) ); - req_data = kzalloc(req_size, GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_scm_mem_alloc(req_size, GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(rsp_size, GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_scm_mem_alloc(rsp_size, GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_GET_VARIABLE; req_data->data_size = buffer_size; @@ -331,20 +329,14 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e memcpy(((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); status = qcom_qseecom_app_send(qcuefi->client, req_data, req_size, rsp_data, rsp_size); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_GET_VARIABLE) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_GET_VARIABLE) + return EFI_DEVICE_ERROR; - if (rsp_data->length < sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length < sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", @@ -358,18 +350,14 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e *attributes = rsp_data->attributes; } - goto out_free; + return efi_status; } - if (rsp_data->length > rsp_size) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length > rsp_size) + return EFI_DEVICE_ERROR; - if (rsp_data->data_offset + rsp_data->data_size > rsp_data->length) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->data_offset + rsp_data->data_size > rsp_data->length) + return EFI_DEVICE_ERROR; /* * Note: We need to set attributes and data size even if the buffer is @@ -392,33 +380,23 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e if (attributes) *attributes = rsp_data->attributes; - if (buffer_size == 0 && !data) { - efi_status = EFI_SUCCESS; - goto out_free; - } + if (buffer_size == 0 && !data) + return EFI_SUCCESS; - if (buffer_size < rsp_data->data_size) { - efi_status = EFI_BUFFER_TOO_SMALL; - goto out_free; - } + if (buffer_size < rsp_data->data_size) + return EFI_BUFFER_TOO_SMALL; memcpy(data, ((void *)rsp_data) + rsp_data->data_offset, rsp_data->data_size); -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const efi_char16_t *name, const efi_guid_t *guid, u32 attributes, unsigned long data_size, const void *data) { - struct qsee_req_uefi_set_variable *req_data; - struct qsee_rsp_uefi_set_variable *rsp_data; - efi_status_t efi_status = EFI_SUCCESS; + struct qsee_req_uefi_set_variable *req_data __free(qcom_scm_mem) = NULL; + struct qsee_rsp_uefi_set_variable *rsp_data __free(qcom_scm_mem) = NULL; unsigned long name_length; size_t name_offs; size_t guid_offs; @@ -448,17 +426,13 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e __array_offs(u8, data_size, &data_offs) ); - req_data = kzalloc(req_size, GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_scm_mem_alloc(req_size, GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(sizeof(*rsp_data), GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_scm_mem_alloc(sizeof(*rsp_data), GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_SET_VARIABLE; req_data->attributes = attributes; @@ -481,42 +455,31 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e status = qcom_qseecom_app_send(qcuefi->client, req_data, req_size, rsp_data, sizeof(*rsp_data)); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_SET_VARIABLE) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_SET_VARIABLE) + return EFI_DEVICE_ERROR; - if (rsp_data->length != sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length != sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", __func__, rsp_data->status); - efi_status = qsee_uefi_status_to_efi(rsp_data->status); + return qsee_uefi_status_to_efi(rsp_data->status); } -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, unsigned long *name_size, efi_char16_t *name, efi_guid_t *guid) { - struct qsee_req_uefi_get_next_variable *req_data; - struct qsee_rsp_uefi_get_next_variable *rsp_data; - efi_status_t efi_status = EFI_SUCCESS; + struct qsee_req_uefi_get_next_variable *req_data __free(qcom_scm_mem) = NULL; + struct qsee_rsp_uefi_get_next_variable *rsp_data __free(qcom_scm_mem) = NULL; + efi_status_t efi_status; size_t guid_offs; size_t name_offs; size_t req_size; @@ -541,17 +504,13 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, __array(*name, *name_size / sizeof(*name)) ); - req_data = kzalloc(req_size, GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_scm_mem_alloc(req_size, GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(rsp_size, GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_scm_mem_alloc(rsp_size, GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_GET_NEXT_VARIABLE; req_data->guid_offset = guid_offs; @@ -567,20 +526,14 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, return EFI_INVALID_PARAMETER; status = qcom_qseecom_app_send(qcuefi->client, req_data, req_size, rsp_data, rsp_size); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_GET_NEXT_VARIABLE) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_GET_NEXT_VARIABLE) + return EFI_DEVICE_ERROR; - if (rsp_data->length < sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length < sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", @@ -595,77 +548,57 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, if (efi_status == EFI_BUFFER_TOO_SMALL) *name_size = rsp_data->name_size; - goto out_free; + return efi_status; } - if (rsp_data->length > rsp_size) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length > rsp_size) + return EFI_DEVICE_ERROR; - if (rsp_data->name_offset + rsp_data->name_size > rsp_data->length) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->name_offset + rsp_data->name_size > rsp_data->length) + return EFI_DEVICE_ERROR; - if (rsp_data->guid_offset + rsp_data->guid_size > rsp_data->length) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->guid_offset + rsp_data->guid_size > rsp_data->length) + return EFI_DEVICE_ERROR; if (rsp_data->name_size > *name_size) { *name_size = rsp_data->name_size; - efi_status = EFI_BUFFER_TOO_SMALL; - goto out_free; + return EFI_BUFFER_TOO_SMALL; } - if (rsp_data->guid_size != sizeof(*guid)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->guid_size != sizeof(*guid)) + return EFI_DEVICE_ERROR; memcpy(guid, ((void *)rsp_data) + rsp_data->guid_offset, rsp_data->guid_size); status = ucs2_strscpy(name, ((void *)rsp_data) + rsp_data->name_offset, rsp_data->name_size / sizeof(*name)); *name_size = rsp_data->name_size; - if (status < 0) { + if (status < 0) /* * Return EFI_DEVICE_ERROR here because the buffer size should * have already been validated above, causing this function to * bail with EFI_BUFFER_TOO_SMALL. */ return EFI_DEVICE_ERROR; - } -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } static efi_status_t qsee_uefi_query_variable_info(struct qcuefi_client *qcuefi, u32 attr, u64 *storage_space, u64 *remaining_space, u64 *max_variable_size) { - struct qsee_req_uefi_query_variable_info *req_data; - struct qsee_rsp_uefi_query_variable_info *rsp_data; - efi_status_t efi_status = EFI_SUCCESS; + struct qsee_req_uefi_query_variable_info *req_data __free(qcom_scm_mem) = NULL; + struct qsee_rsp_uefi_query_variable_info *rsp_data __free(qcom_scm_mem) = NULL; int status; - req_data = kzalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_scm_mem_alloc(sizeof(*req_data), GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(sizeof(*rsp_data), GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_scm_mem_alloc(sizeof(*rsp_data), GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_QUERY_VARIABLE_INFO; req_data->attributes = attr; @@ -673,26 +606,19 @@ static efi_status_t qsee_uefi_query_variable_info(struct qcuefi_client *qcuefi, status = qcom_qseecom_app_send(qcuefi->client, req_data, sizeof(*req_data), rsp_data, sizeof(*rsp_data)); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_QUERY_VARIABLE_INFO) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_QUERY_VARIABLE_INFO) + return EFI_DEVICE_ERROR; - if (rsp_data->length != sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length != sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", __func__, rsp_data->status); - efi_status = qsee_uefi_status_to_efi(rsp_data->status); - goto out_free; + return qsee_uefi_status_to_efi(rsp_data->status); } if (storage_space) @@ -704,12 +630,7 @@ static efi_status_t qsee_uefi_query_variable_info(struct qcuefi_client *qcuefi, if (max_variable_size) *max_variable_size = rsp_data->max_variable_size; -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } /* -- Global efivar interface. ---------------------------------------------- */ diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 37e876437a3e..1fa27c44f472 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -1539,9 +1538,9 @@ EXPORT_SYMBOL_GPL(qcom_scm_qseecom_app_get_id); /** * qcom_scm_qseecom_app_send() - Send to and receive data from a given QSEE app. * @app_id: The ID of the target app. - * @req: Request buffer sent to the app (must be DMA-mappable). + * @req: Request buffer sent to the app (must be SCM memory) * @req_size: Size of the request buffer. - * @rsp: Response buffer, written to by the app (must be DMA-mappable). + * @rsp: Response buffer, written to by the app (must be SCM memory) * @rsp_size: Size of the response buffer. * * Sends a request to the QSEE app associated with the given ID and read back @@ -1557,26 +1556,12 @@ int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp, { struct qcom_scm_qseecom_resp res = {}; struct qcom_scm_desc desc = {}; - dma_addr_t req_phys; - dma_addr_t rsp_phys; + phys_addr_t req_phys; + phys_addr_t rsp_phys; int status; - /* Map request buffer */ - req_phys = dma_map_single(__scm->dev, req, req_size, DMA_TO_DEVICE); - status = dma_mapping_error(__scm->dev, req_phys); - if (status) { - dev_err(__scm->dev, "qseecom: failed to map request buffer\n"); - return status; - } - - /* Map response buffer */ - rsp_phys = dma_map_single(__scm->dev, rsp, rsp_size, DMA_FROM_DEVICE); - status = dma_mapping_error(__scm->dev, rsp_phys); - if (status) { - dma_unmap_single(__scm->dev, req_phys, req_size, DMA_TO_DEVICE); - dev_err(__scm->dev, "qseecom: failed to map response buffer\n"); - return status; - } + req_phys = qcom_scm_mem_to_phys(req); + rsp_phys = qcom_scm_mem_to_phys(rsp); /* Set up SCM call data */ desc.owner = QSEECOM_TZ_OWNER_TZ_APPS; @@ -1594,10 +1579,6 @@ int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp, /* Perform call */ status = qcom_scm_qseecom_call(&desc, &res); - /* Unmap buffers */ - dma_unmap_single(__scm->dev, rsp_phys, rsp_size, DMA_FROM_DEVICE); - dma_unmap_single(__scm->dev, req_phys, req_size, DMA_TO_DEVICE); - if (status) return status; diff --git a/include/linux/firmware/qcom/qcom_qseecom.h b/include/linux/firmware/qcom/qcom_qseecom.h index b531547e1dc9..9b9803f78f03 100644 --- a/include/linux/firmware/qcom/qcom_qseecom.h +++ b/include/linux/firmware/qcom/qcom_qseecom.h @@ -23,9 +23,9 @@ struct qseecom_client { /** * qcom_qseecom_app_send() - Send to and receive data from a given QSEE app. * @client: The QSEECOM client associated with the target app. - * @req: Request buffer sent to the app (must be DMA-mappable). + * @req: Request buffer sent to the app (must be SCM memory). * @req_size: Size of the request buffer. - * @rsp: Response buffer, written to by the app (must be DMA-mappable). + * @rsp: Response buffer, written to by the app (must be SCM memory). * @rsp_size: Size of the response buffer. * * Sends a request to the QSEE app associated with the given client and read From patchwork Thu Sep 28 09:20:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402381 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1D69CE7B12 for ; Thu, 28 Sep 2023 09:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231648AbjI1JVX (ORCPT ); Thu, 28 Sep 2023 05:21:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231641AbjI1JVU (ORCPT ); Thu, 28 Sep 2023 05:21:20 -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 D4241C0 for ; Thu, 28 Sep 2023 02:21:11 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-323168869daso9874909f8f.2 for ; Thu, 28 Sep 2023 02:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892870; x=1696497670; 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=SVQfW/DeQMI23e+YZyvWhEKH7q5MhV/xZYEf73p8CUQ=; b=mOnMowzHxOVocJapqlph1HxIsiyxYNQNB8lK7eAHon55nk0uLBATrSiVGY452MsUh+ 6agFX9OJx4UdV4f4drO+0LPr+a9I7WeoEUWYUoUUmzrt/IVP40xUyyr26Z4/Lq4e6Yxe BaHemXivf27EXHZwf4rzjLJfvp1OhJxCWU4w9ggNFt0vMKoHdjFAE2VwGuAGkxT+2t5Q oiPMINTLglzLl2b9Od1ZV5q+5BewrOh+huB30PPcDm7gB6CABeDc1kMgvDLcOmFuobvV L+pMC1jXHxSB9TlY+P4yxLvZ3aXqa72lKOoqG3F7sB88bgueiyNbZYR1xFCH6hbPEdDs 1qZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892870; x=1696497670; 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=SVQfW/DeQMI23e+YZyvWhEKH7q5MhV/xZYEf73p8CUQ=; b=r4UzMtOv/Qh+XitA5xW9HR/jj9ps3apUPPL2N85vZgD3g15Z+bQUwYBf4qIodYx8+Z 38/YpoFzjrcdzIfe5ZRnJv+1PDaEEIZpTs0givkrxGSmhRx0BYETC7w2SV6Xcyat8RvW f2H9yPxzPhE2m1+GN4Rbi9JtTUJC6HwIoxNBTYJSG3qnZGtm2NWGL71k/HosyFPrLWJO CarzpDKwf5VLGcponfa+uf7QFnbCo+JD3CQzhxxhJVvTeeFQGd/pOn1uDLsw1zzRfVoJ IFpzgr+Zt19gGIGyca45RTNpRFViLxWJfpJCsMYDfgQ54LM86GDkL6UVnTHGTM0rXJn8 IYYw== X-Gm-Message-State: AOJu0Yx591ZfS8ve/Zzfd0a9dnQScah92GEY4Wn2bBceiZg6Qsf/Irz+ +qFnVU91PM4moWDPJG2JDGtXUA== X-Google-Smtp-Source: AGHT+IGnIdQ7yRyr+P4vm1MevwoFHAaWWIkJWJQ3V2SUXU7ZGOwJ4AfaOd/+nsR9l3kYJBUO/oO4hQ== X-Received: by 2002:a05:6000:10c4:b0:319:77dd:61f9 with SMTP id b4-20020a05600010c400b0031977dd61f9mr632629wrx.35.1695892870380; Thu, 28 Sep 2023 02:21:10 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:09 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 10/11] firmware: qcom-scm: add support for SHM bridge operations Date: Thu, 28 Sep 2023 11:20:39 +0200 Message-Id: <20230928092040.9420-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Add low-level primitives for enabling SHM bridge support, creating SHM bridge pools and testing the availability of SHM bridges to qcom-scm. We don't yet provide a way to destroy the bridges as the first user will not require it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm.c | 43 ++++++++++++++++++++++++++ drivers/firmware/qcom/qcom_scm.h | 2 ++ include/linux/firmware/qcom/qcom_scm.h | 6 ++++ 3 files changed, 51 insertions(+) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 1fa27c44f472..5969ff0c0beb 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1296,6 +1296,49 @@ bool qcom_scm_lmh_dcvsh_available(void) } EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh_available); +int qcom_scm_enable_shm_bridge(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_enable_shm_bridge); + +int qcom_scm_create_shm_bridge(struct device *dev, u64 pfn_and_ns_perm_flags, + u64 ipfn_and_s_perm_flags, u64 size_and_flags, + u64 ns_vmids) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_SHM_BRDIGE_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); + + return ret ?: res.result[0]; +} +EXPORT_SYMBOL_GPL(qcom_scm_create_shm_bridge); + 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 8c97e3906afa..f5a29bc0f549 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -116,6 +116,8 @@ extern int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc, #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_BRDIGE_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 291ef8fd21b0..dc26cfd6d011 100644 --- a/include/linux/firmware/qcom/qcom_scm.h +++ b/include/linux/firmware/qcom/qcom_scm.h @@ -6,6 +6,7 @@ #define __QCOM_SCM_H #include +#include #include #include #include @@ -122,6 +123,11 @@ 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_enable_shm_bridge(void); +int qcom_scm_create_shm_bridge(struct device *dev, u64 pfn_and_ns_perm_flags, + u64 ipfn_and_s_perm_flags, u64 size_and_flags, + u64 ns_vmids); + #ifdef CONFIG_QCOM_QSEECOM int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id); From patchwork Thu Sep 28 09:20:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13402380 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9354CE7B10 for ; Thu, 28 Sep 2023 09:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231577AbjI1JVX (ORCPT ); Thu, 28 Sep 2023 05:21:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231654AbjI1JVV (ORCPT ); Thu, 28 Sep 2023 05:21:21 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4614195 for ; Thu, 28 Sep 2023 02:21:12 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-32003aae100so9290845f8f.0 for ; Thu, 28 Sep 2023 02:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695892871; x=1696497671; 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=bwhz75YMPOq4qEC9+ip9OVp9daQY2HSr3vN/IaeFnqw=; b=ZdFDth24YL6VP5Sf68aAW8r37uMQJFqqSeWLlHNT60ZZwMRLJLmztpN2sC5ES1hr22 YLrnccYBdJoTe/3xD4rLP4gK9jYfIQwhSDPkcTsEz42Fsf/mA9zxww0I99nHpu9ibuGX gmVaEC8Qze5sMMlGLvWeUx7l7CGW914AZaNpoqhsTDtMbJ1ueW8WQco9+IO3xpoxEM+Q CGiwaZCzSPUR4curXfdiGNWm79c0MfqFEVfTrwzlmXErt6rBk4dxW3dO2d41B/VOQ7Hj T7/uLsj9JHSV/LlZjGlKZklaBqtNUptZV7v7IgN48pSlW9qmtgmyB7xHOuY7hF86xNNY 9QYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695892871; x=1696497671; 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=bwhz75YMPOq4qEC9+ip9OVp9daQY2HSr3vN/IaeFnqw=; b=jq/cGeup+gIFhgmDjRX/aGf0WfZbPRkcvsAYQR9U6IVKGXdFne1ASFA0Wr2vV/LKy5 AMnwZdqI9S8dyba/OznQFpFv0L888XpAW5SBHfeF+UXbR4nweyXQto6FlbYKjWfl8Tdi Hm9JeXPAGrFkCUqejv69A0TAMdzMNNvhuIyYdyrQ18LdQj98rvX0nbRUGC6gsNu6yhIp Y6M69+ABta2loGrohTcCGuoe9AkjDzvRGFVPNGppM7262xwS6DItogEgeSF4fd2CL9N5 QMt4rUWo6g+jSrMYTj3bWaTC2rQuuBlPnMBgBDrrTMUhrAwdHKZCVihTzCHvRBxoebSK 6UTg== X-Gm-Message-State: AOJu0YwTvnD0rZb2quZKgJdqTygD5l23g59C6hYyExPmwVpkzfK7enV+ iHt8aeUHDa0Eriu6kZWrrddkRA== X-Google-Smtp-Source: AGHT+IE3GsANY81UVfUlFWZkTjFrKFj1hDWRsy6MTw6h1c+EJ5jbfuVPbu8WWRLFLFkKE7PwmPfr8w== X-Received: by 2002:a5d:574f:0:b0:319:6997:9432 with SMTP id q15-20020a5d574f000000b0031969979432mr783332wrw.1.1695892871336; Thu, 28 Sep 2023 02:21:11 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:6e4c:e3c1:5cb8:b60e]) by smtp.gmail.com with ESMTPSA id e9-20020adfe7c9000000b003197efd1e7bsm5009156wrn.114.2023.09.28.02.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:21:10 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v2 11/11] firmware: qcom: scm: enable SHM bridge Date: Thu, 28 Sep 2023 11:20:40 +0200 Message-Id: <20230928092040.9420-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230928092040.9420-1-brgl@bgdev.pl> References: <20230928092040.9420-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Bartosz Golaszewski Extens the SCM memory allocator with using the SHM Bridge feature if available on the platform. This makes the trustzone only use dedicated buffers for SCM calls. We map the entire SCM genpool as a bridge. Signed-off-by: Bartosz Golaszewski --- drivers/firmware/qcom/qcom_scm-mem.c | 42 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm-mem.c b/drivers/firmware/qcom/qcom_scm-mem.c index eafecbe23770..12b12b15f46f 100644 --- a/drivers/firmware/qcom/qcom_scm-mem.c +++ b/drivers/firmware/qcom/qcom_scm-mem.c @@ -16,6 +16,8 @@ #include "qcom_scm.h" +#define QCOM_SHM_BRIDGE_NUM_VM_SHIFT 9 + static size_t qcom_scm_mem_pool_size = SZ_2M; module_param_named(qcom_scm_mem_pool_size, qcom_scm_mem_pool_size, ulong, 0400); @@ -108,8 +110,24 @@ phys_addr_t qcom_scm_mem_to_phys(void *vaddr) return chunk->paddr; } +static int qcom_scm_mem_shm_bridge_create(void) +{ + uint64_t pfn_and_ns_perm, ipfn_and_s_perm, size_and_flags, ns_perms; + + ns_perms = (QCOM_SCM_PERM_WRITE | QCOM_SCM_PERM_READ); + pfn_and_ns_perm = (u64)qcom_scm_mem.pbase | ns_perms; + ipfn_and_s_perm = (u64)qcom_scm_mem.pbase | ns_perms; + size_and_flags = qcom_scm_mem.size | (1 << QCOM_SHM_BRIDGE_NUM_VM_SHIFT); + + return qcom_scm_create_shm_bridge(qcom_scm_mem.dev, pfn_and_ns_perm, + ipfn_and_s_perm, size_and_flags, + QCOM_SCM_VMID_HLOS); +} + int qcom_scm_mem_enable(struct device *dev) { + int ret; + INIT_RADIX_TREE(&qcom_scm_mem.chunks, GFP_ATOMIC); spin_lock_init(&qcom_scm_mem.lock); qcom_scm_mem.dev = dev; @@ -128,7 +146,25 @@ int qcom_scm_mem_enable(struct device *dev) gen_pool_set_algo(qcom_scm_mem.pool, gen_pool_best_fit, NULL); - return gen_pool_add_virt(qcom_scm_mem.pool, - (unsigned long)qcom_scm_mem.vbase, - qcom_scm_mem.pbase, qcom_scm_mem.size, -1); + ret = gen_pool_add_virt(qcom_scm_mem.pool, + (unsigned long)qcom_scm_mem.vbase, + qcom_scm_mem.pbase, qcom_scm_mem.size, -1); + if (ret) + return ret; + + ret = qcom_scm_enable_shm_bridge(); + if (ret) { + if (ret == EOPNOTSUPP) + dev_info(dev, "SHM Bridge not supported\n"); + else + return ret; + } else { + ret = qcom_scm_mem_shm_bridge_create(); + if (ret) + return ret; + + dev_info(dev, "SHM Bridge enabled\n"); + } + + return 0; }