Skip to content

Commit 733db7c

Browse files
committed
Merge: firmware: qcom: Backport SHM bridge
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6129 JIRA: https://issues.redhat.com/browse/RHEL-73299 This backport is primarily for the patch series from "firmware: qcom: implement support for and enable SHM bridge", including all 3 patches that were merged into upstream from the v5 thread and 14 of the 15 patches that were merged into upstream from the v10 thread (omitting only one documentation change). To minimize conflicts, I pulled in various other changes in `drivers/firmware/qcom`, most notably the QSEECOM driver. - SHM bridge v5 thread: https://lore.kernel.org/all/20231017092732.19983-1-brgl@bgdev.pl/ - SHM bridge v10 thread: https://lore.kernel.org/all/20240527-shm-bridge-v10-0-ce7afaa58d3a@linaro.org/ - QSEECOM thread: https://lore.kernel.org/all/20230827211408.689076-1-luzmaximilian@gmail.com/ The TrustZone memory allocator adds a config choice relevant to aarch64: `QCOM_TZMEM_MODE_GENERIC` or `QCOM_TZMEM_MODE_SHMBRIDGE`. I brought over the config for these from kernel-ark, which selects `QCOM_TZMEM_MODE_GENERIC`. I also left the QSEECOM driver disabled, same as it currently is in kernel-ark. Signed-off-by: Jennifer Berringer <jberring@redhat.com> Approved-by: Brian Masney <bmasney@redhat.com> Approved-by: Eric Chanudet <echanude@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Patrick Talbert <ptalbert@redhat.com>
2 parents 4cdb2b3 + 1d3d35b commit 733db7c

File tree

23 files changed

+2579
-194
lines changed

23 files changed

+2579
-194
lines changed

MAINTAINERS

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16158,6 +16158,18 @@ S: Maintained
1615816158
F: Documentation/devicetree/bindings/regulator/vqmmc-ipq4019-regulator.yaml
1615916159
F: drivers/regulator/vqmmc-ipq4019-regulator.c
1616016160

16161+
QUALCOMM QSEECOM DRIVER
16162+
M: Maximilian Luz <luzmaximilian@gmail.com>
16163+
L: linux-arm-msm@vger.kernel.org
16164+
S: Maintained
16165+
F: drivers/firmware/qcom/qcom_qseecom.c
16166+
16167+
QUALCOMM QSEECOM UEFISECAPP DRIVER
16168+
M: Maximilian Luz <luzmaximilian@gmail.com>
16169+
L: linux-arm-msm@vger.kernel.org
16170+
S: Maintained
16171+
F: drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
16172+
1616116173
QUALCOMM RMNET DRIVER
1616216174
M: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
1616316175
M: Sean Tranchetti <stranche@codeaurora.org>
@@ -16167,6 +16179,14 @@ F: Documentation/networking/device_drivers/cellular/qualcomm/rmnet.rst
1616716179
F: drivers/net/ethernet/qualcomm/rmnet/
1616816180
F: include/linux/if_rmnet.h
1616916181

16182+
QUALCOMM TRUST ZONE MEMORY ALLOCATOR
16183+
M: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
16184+
L: linux-arm-msm@vger.kernel.org
16185+
S: Maintained
16186+
F: drivers/firmware/qcom/qcom_tzmem.c
16187+
F: drivers/firmware/qcom/qcom_tzmem.h
16188+
F: include/linux/firmware/qcom/qcom_tzmem.h
16189+
1617016190
QUALCOMM TSENS THERMAL DRIVER
1617116191
M: Amit Kucheria <amitk@kernel.org>
1617216192
M: Thara Gopinath <thara.gopinath@linaro.org>

arch/arm64/boot/dts/qcom/sa8775p.dtsi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
firmware {
189189
scm {
190190
compatible = "qcom,scm-sa8775p", "qcom,scm";
191+
memory-region = <&tz_ffi_mem>;
191192
};
192193
};
193194

@@ -398,6 +399,12 @@
398399
no-map;
399400
};
400401

402+
tz_ffi_mem: tz-ffi@91c00000 {
403+
compatible = "shared-dma-pool";
404+
reg = <0x0 0x91c00000 0x0 0x1400000>;
405+
no-map;
406+
};
407+
401408
lpass_machine_learning_mem: lpass-machine-learning@93b00000 {
402409
reg = <0x0 0x93b00000 0x0 0xf00000>;
403410
no-map;

arch/arm64/configs/defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ CONFIG_HISILICON_LPC=y
246246
CONFIG_SIMPLE_PM_BUS=y
247247
CONFIG_FSL_MC_BUS=y
248248
CONFIG_TEGRA_ACONNECT=m
249+
CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE=y
249250
CONFIG_GNSS=m
250251
CONFIG_GNSS_MTK_SERIAL=m
251252
CONFIG_MTD=y

drivers/firmware/Kconfig

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,6 @@ config INTEL_STRATIX10_RSU
203203

204204
Say Y here if you want Intel RSU support.
205205

206-
config QCOM_SCM
207-
tristate
208-
209-
config QCOM_SCM_DOWNLOAD_MODE_DEFAULT
210-
bool "Qualcomm download mode enabled by default"
211-
depends on QCOM_SCM
212-
help
213-
A device with "download mode" enabled will upon an unexpected
214-
warm-restart enter a special debug mode that allows the user to
215-
"download" memory content over USB for offline postmortem analysis.
216-
The feature can be enabled/disabled on the kernel command line.
217-
218-
Say Y here to enable "download mode" by default.
219206

220207
config SYSFB
221208
bool
@@ -303,6 +290,7 @@ source "drivers/firmware/efi/Kconfig"
303290
source "drivers/firmware/imx/Kconfig"
304291
source "drivers/firmware/meson/Kconfig"
305292
source "drivers/firmware/psci/Kconfig"
293+
source "drivers/firmware/qcom/Kconfig"
306294
source "drivers/firmware/smccc/Kconfig"
307295
source "drivers/firmware/tegra/Kconfig"
308296
source "drivers/firmware/xilinx/Kconfig"

drivers/firmware/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o
1717
obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o
1818
obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o
1919
obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o
20-
obj-$(CONFIG_QCOM_SCM) += qcom-scm.o
21-
qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o
2220
obj-$(CONFIG_SYSFB) += sysfb.o
2321
obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o
2422
obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
@@ -34,6 +32,7 @@ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/
3432
obj-y += efi/
3533
obj-y += imx/
3634
obj-y += psci/
35+
obj-y += qcom/
3736
obj-y += smccc/
3837
obj-y += tegra/
3938
obj-y += xilinx/

drivers/firmware/qcom/Kconfig

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# For a description of the syntax of this configuration file,
4+
# see Documentation/kbuild/kconfig-language.rst.
5+
#
6+
7+
menu "Qualcomm firmware drivers"
8+
9+
config QCOM_SCM
10+
select QCOM_TZMEM
11+
tristate
12+
13+
config QCOM_TZMEM
14+
tristate
15+
select GENERIC_ALLOCATOR
16+
17+
choice
18+
prompt "TrustZone interface memory allocator mode"
19+
depends on QCOM_TZMEM
20+
default QCOM_TZMEM_MODE_GENERIC
21+
help
22+
Selects the mode of the memory allocator providing memory buffers of
23+
suitable format for sharing with the TrustZone. If in doubt, select
24+
'Generic'.
25+
26+
config QCOM_TZMEM_MODE_GENERIC
27+
bool "Generic"
28+
help
29+
Use the generic allocator mode. The memory is page-aligned, non-cachable
30+
and physically contiguous.
31+
32+
config QCOM_TZMEM_MODE_SHMBRIDGE
33+
bool "SHM Bridge"
34+
help
35+
Use Qualcomm Shared Memory Bridge. The memory has the same alignment as
36+
in the 'Generic' allocator but is also explicitly marked as an SHM Bridge
37+
buffer.
38+
39+
With this selected, all buffers passed to the TrustZone must be allocated
40+
using the TZMem allocator or else the TrustZone will refuse to use them.
41+
42+
endchoice
43+
44+
config QCOM_QSEECOM
45+
bool "Qualcomm QSEECOM interface driver"
46+
depends on QCOM_SCM=y
47+
select AUXILIARY_BUS
48+
help
49+
Various Qualcomm SoCs have a Secure Execution Environment (SEE) running
50+
in the Trust Zone. This module provides an interface to that via the
51+
QSEECOM mechanism, using SCM calls.
52+
53+
The QSEECOM interface allows, among other things, access to applications
54+
running in the SEE. An example of such an application is 'uefisecapp',
55+
which is required to access UEFI variables on certain systems. If
56+
selected, the interface will also attempt to detect and register client
57+
devices for supported applications.
58+
59+
Select Y here to enable the QSEECOM interface driver.
60+
61+
config QCOM_QSEECOM_UEFISECAPP
62+
bool "Qualcomm SEE UEFI Secure App client driver"
63+
depends on QCOM_QSEECOM
64+
depends on EFI
65+
help
66+
Various Qualcomm SoCs do not allow direct access to EFI variables.
67+
Instead, these need to be accessed via the UEFI Secure Application
68+
(uefisecapp), residing in the Secure Execution Environment (SEE).
69+
70+
This module provides a client driver for uefisecapp, installing efivar
71+
operations to allow the kernel accessing EFI variables, and via that also
72+
provide user-space with access to EFI variables via efivarfs.
73+
74+
Select Y here to provide access to EFI variables on the aforementioned
75+
platforms.
76+
77+
endmenu

drivers/firmware/qcom/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Makefile for the linux kernel.
4+
#
5+
6+
obj-$(CONFIG_QCOM_SCM) += qcom-scm.o
7+
qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o
8+
obj-$(CONFIG_QCOM_TZMEM) += qcom_tzmem.o
9+
obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o
10+
obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Driver for Qualcomm Secure Execution Environment (SEE) interface (QSEECOM).
4+
* Responsible for setting up and managing QSEECOM client devices.
5+
*
6+
* Copyright (C) 2023 Maximilian Luz <luzmaximilian@gmail.com>
7+
*/
8+
#include <linux/auxiliary_bus.h>
9+
#include <linux/module.h>
10+
#include <linux/platform_device.h>
11+
#include <linux/slab.h>
12+
#include <linux/types.h>
13+
14+
#include <linux/firmware/qcom/qcom_qseecom.h>
15+
#include <linux/firmware/qcom/qcom_scm.h>
16+
17+
struct qseecom_app_desc {
18+
const char *app_name;
19+
const char *dev_name;
20+
};
21+
22+
static void qseecom_client_release(struct device *dev)
23+
{
24+
struct qseecom_client *client;
25+
26+
client = container_of(dev, struct qseecom_client, aux_dev.dev);
27+
kfree(client);
28+
}
29+
30+
static void qseecom_client_remove(void *data)
31+
{
32+
struct qseecom_client *client = data;
33+
34+
auxiliary_device_delete(&client->aux_dev);
35+
auxiliary_device_uninit(&client->aux_dev);
36+
}
37+
38+
static int qseecom_client_register(struct platform_device *qseecom_dev,
39+
const struct qseecom_app_desc *desc)
40+
{
41+
struct qseecom_client *client;
42+
u32 app_id;
43+
int ret;
44+
45+
/* Try to find the app ID, skip device if not found */
46+
ret = qcom_scm_qseecom_app_get_id(desc->app_name, &app_id);
47+
if (ret)
48+
return ret == -ENOENT ? 0 : ret;
49+
50+
dev_info(&qseecom_dev->dev, "setting up client for %s\n", desc->app_name);
51+
52+
/* Allocate and set-up the client device */
53+
client = kzalloc(sizeof(*client), GFP_KERNEL);
54+
if (!client)
55+
return -ENOMEM;
56+
57+
client->aux_dev.name = desc->dev_name;
58+
client->aux_dev.dev.parent = &qseecom_dev->dev;
59+
client->aux_dev.dev.release = qseecom_client_release;
60+
client->app_id = app_id;
61+
62+
ret = auxiliary_device_init(&client->aux_dev);
63+
if (ret) {
64+
kfree(client);
65+
return ret;
66+
}
67+
68+
ret = auxiliary_device_add(&client->aux_dev);
69+
if (ret) {
70+
auxiliary_device_uninit(&client->aux_dev);
71+
return ret;
72+
}
73+
74+
ret = devm_add_action_or_reset(&qseecom_dev->dev, qseecom_client_remove, client);
75+
if (ret)
76+
return ret;
77+
78+
return 0;
79+
}
80+
81+
/*
82+
* List of supported applications. One client device will be created per entry,
83+
* assuming the app has already been loaded (usually by firmware bootloaders)
84+
* and its ID can be queried successfully.
85+
*/
86+
static const struct qseecom_app_desc qcom_qseecom_apps[] = {
87+
{ "qcom.tz.uefisecapp", "uefisecapp" },
88+
};
89+
90+
static int qcom_qseecom_probe(struct platform_device *qseecom_dev)
91+
{
92+
int ret;
93+
int i;
94+
95+
/* Set up client devices for each base application */
96+
for (i = 0; i < ARRAY_SIZE(qcom_qseecom_apps); i++) {
97+
ret = qseecom_client_register(qseecom_dev, &qcom_qseecom_apps[i]);
98+
if (ret)
99+
return ret;
100+
}
101+
102+
return 0;
103+
}
104+
105+
static struct platform_driver qcom_qseecom_driver = {
106+
.driver = {
107+
.name = "qcom_qseecom",
108+
},
109+
.probe = qcom_qseecom_probe,
110+
};
111+
112+
static int __init qcom_qseecom_init(void)
113+
{
114+
return platform_driver_register(&qcom_qseecom_driver);
115+
}
116+
subsys_initcall(qcom_qseecom_init);
117+
118+
MODULE_AUTHOR("Maximilian Luz <luzmaximilian@gmail.com>");
119+
MODULE_DESCRIPTION("Driver for the Qualcomm SEE (QSEECOM) interface");
120+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)