[PATCH RFC 1/2] firmware: qcom: Introduce qcom_secure_log interface to display QTEE logs
From: Kuldeep Singh
Date: Tue Dec 01 2026 - 17:34:21 EST
Define an interface to basically map TZ diag ocimem physical address as
per soc family and ioremap further to map region for userspace access.
The ocimem address is roughly same over targets(few possible values
only) and hence, maintaining machine compatible list and size for target
family.
Signed-off-by: Kuldeep Singh <kuldeep.singh@xxxxxxxxxxxxxxxx>
---
drivers/firmware/qcom/Kconfig | 8 ++
drivers/firmware/qcom/Makefile | 1 +
drivers/firmware/qcom/qcom_secure_log.c | 228 ++++++++++++++++++++++++++++++++
3 files changed, 237 insertions(+)
diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig
index 3ad22f8fc3e5..8ca173677c64 100644
--- a/drivers/firmware/qcom/Kconfig
+++ b/drivers/firmware/qcom/Kconfig
@@ -46,6 +46,14 @@ config QCOM_TZMEM_MODE_SHMBRIDGE
With this selected, all buffers passed to the TrustZone must be allocated
using the TZMem allocator or else the TrustZone will refuse to use them.
+config QCOM_SECURE_LOG
+ tristate "Qualcomm secure-world log userspace interface"
+ depends on ARCH_QCOM || COMPILE_TEST
+ help
+ Provide a provisional userspace ABI for Qualcomm secure-world log
+ buffers. Userspace is expected to mmap supported log regions and
+ parse the firmware log format.
+
config QCOM_QSEECOM
bool "Qualcomm QSEECOM interface driver"
depends on QCOM_SCM=y
diff --git a/drivers/firmware/qcom/Makefile b/drivers/firmware/qcom/Makefile
index 88ce74d74c3e..bec90e13d0cb 100644
--- a/drivers/firmware/qcom/Makefile
+++ b/drivers/firmware/qcom/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_QCOM_SCM) += qcom-scm.o
qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o
CFLAGS_qcom_scm-smc.o := -I$(src)
obj-$(CONFIG_QCOM_TZMEM) += qcom_tzmem.o
+obj-$(CONFIG_QCOM_SECURE_LOG) += qcom_secure_log.o
obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o
obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o
obj-$(CONFIG_QCOM_PAS) += qcom_pas.o
diff --git a/drivers/firmware/qcom/qcom_secure_log.c b/drivers/firmware/qcom/qcom_secure_log.c
new file mode 100644
index 000000000000..7760ad46bd29
--- /dev/null
+++ b/drivers/firmware/qcom/qcom_secure_log.c
@@ -0,0 +1,228 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Qualcomm secure-world log userspace interface
+ *
+ * Copyright (c) 2026 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#include <linux/fs.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/miscdevice.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/of.h>
+
+#define QCOM_SECURE_LOG_SIZE 0x3000
+
+/**
+ * struct qcom_secure_log_config - target-specific secure log configuration
+ * @compatibles: NULL-terminated root machine compatible string list
+ * @imem_phys: physical IMEM address that stores the TZ diagnostic buffer base
+ * @size: TZ diagnostic buffer size
+ */
+struct qcom_secure_log_config {
+ const char * const *compatibles;
+ phys_addr_t imem_phys;
+ size_t size;
+};
+
+/**
+ * struct qcom_secure_log - secure-log device state
+ * @miscdev: userspace miscdevice
+ * @config: selected target-specific secure log configuration
+ * @imem_base: mapping of the IMEM pointer area
+ * @tz_diag_base: kernel mapping of the TZ diagnostic buffer
+ * @tz_diag_phys: physical start of the TZ diagnostic buffer
+ */
+struct qcom_secure_log {
+ struct miscdevice miscdev;
+ const struct qcom_secure_log_config *config;
+ void __iomem *imem_base;
+ void __iomem *tz_diag_base;
+ phys_addr_t tz_diag_phys;
+};
+
+static const char * const qcom_secure_log_c125720[] = {
+ "qcom,qcs8300",
+ NULL,
+};
+
+static const char * const qcom_secure_log_146bf720[] = {
+ "qcom,sm8150",
+ NULL,
+};
+
+static const char * const qcom_secure_log_14680720[] = {
+ "qcom,lanai",
+ "qcom,sm8750",
+ "qcom,kaanapali",
+ "qcom,hawi",
+ NULL,
+};
+
+static const char * const qcom_secure_log_146aa720[] = {
+ "qcom,qcm6490",
+ "qcom,hamoa",
+ NULL,
+};
+
+static const char * const qcom_secure_log_c11e720[] = {
+ "qcom,shikra",
+ NULL,
+};
+
+static const struct qcom_secure_log_config qcom_secure_log_configs[] = {
+ {
+ .compatibles = qcom_secure_log_c125720,
+ .imem_phys = 0x0c125720,
+ .size = QCOM_SECURE_LOG_SIZE,
+ },
+ {
+ .compatibles = qcom_secure_log_146bf720,
+ .imem_phys = 0x146bf720,
+ .size = QCOM_SECURE_LOG_SIZE,
+ },
+ {
+ .compatibles = qcom_secure_log_14680720,
+ .imem_phys = 0x14680720,
+ .size = QCOM_SECURE_LOG_SIZE,
+ },
+ {
+ .compatibles = qcom_secure_log_146aa720,
+ .imem_phys = 0x146aa720,
+ .size = QCOM_SECURE_LOG_SIZE,
+ },
+ {
+ .compatibles = qcom_secure_log_c11e720,
+ .imem_phys = 0x0c11e720,
+ .size = QCOM_SECURE_LOG_SIZE,
+ },
+};
+
+static struct qcom_secure_log qcom_secure_log;
+
+static int qcom_secure_log_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ struct qcom_secure_log *log = container_of(file->private_data,
+ struct qcom_secure_log,
+ miscdev);
+ unsigned long size = vma->vm_end - vma->vm_start;
+
+ if (vma->vm_flags & VM_WRITE)
+ return -EPERM;
+
+ if (vma->vm_pgoff)
+ return -EINVAL;
+
+ if (size != log->config->size)
+ return -EINVAL;
+
+ vm_flags_clear(vma, VM_MAYWRITE);
+ vm_flags_set(vma, VM_IO | VM_DONTDUMP | VM_DONTEXPAND);
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+ return remap_pfn_range(vma, vma->vm_start, PHYS_PFN(log->tz_diag_phys),
+ size, vma->vm_page_prot);
+}
+
+static const struct file_operations qcom_secure_log_fops = {
+ .owner = THIS_MODULE,
+ .mmap = qcom_secure_log_mmap,
+ .llseek = noop_llseek,
+};
+
+static const struct qcom_secure_log_config *qcom_secure_log_find_config(void)
+{
+ const struct qcom_secure_log_config *config;
+ const char * const *compatible;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(qcom_secure_log_configs); i++) {
+ config = &qcom_secure_log_configs[i];
+
+ for (compatible = config->compatibles; *compatible; compatible++) {
+ if (of_machine_is_compatible(*compatible))
+ return config;
+ }
+ }
+
+ return NULL;
+}
+
+static int qcom_secure_log_init_tz_diag(struct qcom_secure_log *log)
+{
+ phys_addr_t tz_diag_phys;
+
+ log->config = qcom_secure_log_find_config();
+ if (!log->config)
+ return -ENODEV;
+
+ log->imem_base = ioremap(log->config->imem_phys, log->config->size);
+ if (!log->imem_base)
+ return -ENOMEM;
+
+ tz_diag_phys = readl_relaxed(log->imem_base);
+ if (!tz_diag_phys || !PAGE_ALIGNED(tz_diag_phys))
+ goto err_unmap_imem;
+
+ log->tz_diag_base = ioremap(tz_diag_phys, log->config->size);
+ if (!log->tz_diag_base)
+ goto err_unmap_imem;
+
+ log->tz_diag_phys = tz_diag_phys;
+
+ return 0;
+
+err_unmap_imem:
+ iounmap(log->imem_base);
+ log->imem_base = NULL;
+ return -ENODEV;
+}
+
+static void qcom_secure_log_release_tz_diag(struct qcom_secure_log *log)
+{
+ if (log->tz_diag_base)
+ iounmap(log->tz_diag_base);
+
+ if (log->imem_base)
+ iounmap(log->imem_base);
+}
+
+static int __init qcom_secure_log_init(void)
+{
+ struct qcom_secure_log *log = &qcom_secure_log;
+ int ret;
+
+ ret = qcom_secure_log_init_tz_diag(log);
+ if (ret)
+ goto err_release_tz_diag;
+
+ log->miscdev.minor = MISC_DYNAMIC_MINOR;
+ log->miscdev.name = "secure_log";
+ log->miscdev.fops = &qcom_secure_log_fops;
+
+ ret = misc_register(&log->miscdev);
+ if (ret)
+ goto err_release_tz_diag;
+
+ return 0;
+
+err_release_tz_diag:
+ qcom_secure_log_release_tz_diag(log);
+ return ret;
+}
+
+static void __exit qcom_secure_log_exit(void)
+{
+ struct qcom_secure_log *log = &qcom_secure_log;
+
+ misc_deregister(&log->miscdev);
+ qcom_secure_log_release_tz_diag(log);
+}
+
+module_init(qcom_secure_log_init);
+module_exit(qcom_secure_log_exit);
+
+MODULE_DESCRIPTION("Qualcomm TZ diagnostic log");
+MODULE_LICENSE("GPL");
--
2.34.1