[PATCH RFC 03/18] accel/qda: Add RPMsg transport for Qualcomm DSP accelerator
From: Ekansh Gupta
Date: Mon Feb 23 2026 - 14:12:23 EST
Extend the Qualcomm DSP accelerator (QDA) driver with an RPMsg-based
transport used to discover and manage DSP instances.
This patch introduces:
- A core qda_dev structure with basic device state (rpmsg device,
device pointer, lock, removal flag, DSP name).
- Logging helpers that integrate with dev_* when a device is available
and fall back to pr_* otherwise.
- An RPMsg client driver that binds to the Qualcomm FastRPC service and
allocates a qda_dev instance using devm_kzalloc().
- Basic device initialization and teardown paths wired into the module
init/exit.
The RPMsg driver currently sets the DSP name from a "label" property in
the device tree, which will be used by subsequent patches to distinguish
between different DSP domains (e.g. ADSP, CDSP).
Signed-off-by: Ekansh Gupta <ekansh.gupta@xxxxxxxxxxxxxxxx>
---
drivers/accel/qda/Kconfig | 1 +
drivers/accel/qda/Makefile | 4 +-
drivers/accel/qda/qda_drv.c | 41 ++++++++++++++-
drivers/accel/qda/qda_drv.h | 91 ++++++++++++++++++++++++++++++++
drivers/accel/qda/qda_rpmsg.c | 119 ++++++++++++++++++++++++++++++++++++++++++
drivers/accel/qda/qda_rpmsg.h | 17 ++++++
6 files changed, 270 insertions(+), 3 deletions(-)
diff --git a/drivers/accel/qda/Kconfig b/drivers/accel/qda/Kconfig
index 3c78ff6189e0..484d21ff1b55 100644
--- a/drivers/accel/qda/Kconfig
+++ b/drivers/accel/qda/Kconfig
@@ -7,6 +7,7 @@ config DRM_ACCEL_QDA
tristate "Qualcomm DSP accelerator"
depends on DRM_ACCEL
depends on ARCH_QCOM || COMPILE_TEST
+ depends on RPMSG
help
Enables the DRM-based accelerator driver for Qualcomm's Hexagon DSPs.
This driver provides a standardized interface for offloading computational
diff --git a/drivers/accel/qda/Makefile b/drivers/accel/qda/Makefile
index 573711af1d28..e7f23182589b 100644
--- a/drivers/accel/qda/Makefile
+++ b/drivers/accel/qda/Makefile
@@ -5,4 +5,6 @@
obj-$(CONFIG_DRM_ACCEL_QDA) := qda.o
-qda-y := qda_drv.o
+qda-y := \
+ qda_drv.o \
+ qda_rpmsg.o \
diff --git a/drivers/accel/qda/qda_drv.c b/drivers/accel/qda/qda_drv.c
index 18b0d3fb1598..389c66a9ad4f 100644
--- a/drivers/accel/qda/qda_drv.c
+++ b/drivers/accel/qda/qda_drv.c
@@ -2,16 +2,53 @@
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/atomic.h>
+#include "qda_drv.h"
+#include "qda_rpmsg.h"
+
+static void cleanup_device_resources(struct qda_dev *qdev)
+{
+ mutex_destroy(&qdev->lock);
+}
+
+void qda_deinit_device(struct qda_dev *qdev)
+{
+ cleanup_device_resources(qdev);
+}
+
+/* Initialize device resources */
+static void init_device_resources(struct qda_dev *qdev)
+{
+ qda_dbg(qdev, "Initializing device resources\n");
+
+ mutex_init(&qdev->lock);
+ atomic_set(&qdev->removing, 0);
+}
+
+int qda_init_device(struct qda_dev *qdev)
+{
+ init_device_resources(qdev);
+
+ qda_dbg(qdev, "QDA device initialized successfully\n");
+ return 0;
+}
static int __init qda_core_init(void)
{
- pr_info("QDA: driver initialization complete\n");
+ int ret;
+
+ ret = qda_rpmsg_register();
+ if (ret)
+ return ret;
+
+ qda_info(NULL, "QDA driver initialization complete\n");
return 0;
}
static void __exit qda_core_exit(void)
{
- pr_info("QDA: driver exit complete\n");
+ qda_rpmsg_unregister();
+ qda_info(NULL, "QDA driver exit complete\n");
}
module_init(qda_core_init);
diff --git a/drivers/accel/qda/qda_drv.h b/drivers/accel/qda/qda_drv.h
new file mode 100644
index 000000000000..bec2d31ca1bb
--- /dev/null
+++ b/drivers/accel/qda/qda_drv.h
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef __QDA_DRV_H__
+#define __QDA_DRV_H__
+
+#include <linux/device.h>
+#include <linux/mutex.h>
+#include <linux/rpmsg.h>
+#include <linux/xarray.h>
+
+/* Driver identification */
+#define DRIVER_NAME "qda"
+
+/* struct qda_dev - Main device structure for QDA driver */
+struct qda_dev {
+ /* RPMsg device for communication with remote processor */
+ struct rpmsg_device *rpdev;
+ /* Underlying device structure */
+ struct device *dev;
+ /* Mutex protecting device state */
+ struct mutex lock;
+ /* Flag indicating device removal in progress */
+ atomic_t removing;
+ /* Name of the DSP (e.g., "cdsp", "adsp") */
+ char dsp_name[16];
+};
+
+/**
+ * qda_get_log_device - Get appropriate device for logging
+ * @qdev: QDA device structure
+ *
+ * Returns the most appropriate device structure for logging messages.
+ * Prefers qdev->dev, or returns NULL if the device is being removed
+ * or invalid.
+ */
+static inline struct device *qda_get_log_device(struct qda_dev *qdev)
+{
+ if (!qdev || atomic_read(&qdev->removing))
+ return NULL;
+
+ if (qdev->dev)
+ return qdev->dev;
+
+ return NULL;
+}
+
+/*
+ * Logging macros
+ *
+ * These macros provide consistent logging across the driver with automatic
+ * function name inclusion. They use dev_* functions when a device is available,
+ * falling back to pr_* functions otherwise.
+ */
+
+/* Error logging - always logs and tracks errors */
+#define qda_err(qdev, fmt, ...) do { \
+ struct device *__dev = qda_get_log_device(qdev); \
+ if (__dev) \
+ dev_err(__dev, "[%s] " fmt, __func__, ##__VA_ARGS__); \
+ else \
+ pr_err(DRIVER_NAME ": [%s] " fmt, __func__, ##__VA_ARGS__); \
+} while (0)
+
+/* Info logging - always logs, can be filtered via loglevel */
+#define qda_info(qdev, fmt, ...) do { \
+ struct device *__dev = qda_get_log_device(qdev); \
+ if (__dev) \
+ dev_info(__dev, "[%s] " fmt, __func__, ##__VA_ARGS__); \
+ else \
+ pr_info(DRIVER_NAME ": [%s] " fmt, __func__, ##__VA_ARGS__); \
+} while (0)
+
+/* Debug logging - controlled via dynamic debug (CONFIG_DYNAMIC_DEBUG) */
+#define qda_dbg(qdev, fmt, ...) do { \
+ struct device *__dev = qda_get_log_device(qdev); \
+ if (__dev) \
+ dev_dbg(__dev, "[%s] " fmt, __func__, ##__VA_ARGS__); \
+ else \
+ pr_debug(DRIVER_NAME ": [%s] " fmt, __func__, ##__VA_ARGS__); \
+} while (0)
+
+/*
+ * Core device management functions
+ */
+int qda_init_device(struct qda_dev *qdev);
+void qda_deinit_device(struct qda_dev *qdev);
+
+#endif /* __QDA_DRV_H__ */
diff --git a/drivers/accel/qda/qda_rpmsg.c b/drivers/accel/qda/qda_rpmsg.c
new file mode 100644
index 000000000000..a8b24a99ca13
--- /dev/null
+++ b/drivers/accel/qda/qda_rpmsg.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+#include <linux/module.h>
+#include <linux/rpmsg.h>
+#include <linux/of_platform.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include "qda_drv.h"
+#include "qda_rpmsg.h"
+
+static int qda_rpmsg_init(struct qda_dev *qdev)
+{
+ dev_set_drvdata(&qdev->rpdev->dev, qdev);
+ return 0;
+}
+
+/* Utility function to allocate and initialize qda_dev */
+static struct qda_dev *alloc_and_init_qdev(struct rpmsg_device *rpdev)
+{
+ struct qda_dev *qdev;
+
+ qdev = devm_kzalloc(&rpdev->dev, sizeof(*qdev), GFP_KERNEL);
+ if (!qdev)
+ return ERR_PTR(-ENOMEM);
+
+ qdev->dev = &rpdev->dev;
+ qdev->rpdev = rpdev;
+
+ qda_dbg(qdev, "Allocated and initialized qda_dev\n");
+ return qdev;
+}
+
+static int qda_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src)
+{
+ /* Dummy function for rpmsg driver */
+ return 0;
+}
+
+static void qda_rpmsg_remove(struct rpmsg_device *rpdev)
+{
+ struct qda_dev *qdev = dev_get_drvdata(&rpdev->dev);
+
+ qda_info(qdev, "Removing RPMsg device\n");
+
+ atomic_set(&qdev->removing, 1);
+
+ mutex_lock(&qdev->lock);
+ qdev->rpdev = NULL;
+ mutex_unlock(&qdev->lock);
+
+ qda_deinit_device(qdev);
+
+ qda_info(qdev, "RPMsg device removed\n");
+}
+
+static int qda_rpmsg_probe(struct rpmsg_device *rpdev)
+{
+ struct qda_dev *qdev;
+ int ret;
+ const char *label;
+
+ qda_dbg(NULL, "QDA RPMsg probe starting\n");
+
+ qdev = alloc_and_init_qdev(rpdev);
+ if (IS_ERR(qdev))
+ return PTR_ERR(qdev);
+
+ ret = of_property_read_string(rpdev->dev.of_node, "label", &label);
+ if (!ret) {
+ strscpy(qdev->dsp_name, label, sizeof(qdev->dsp_name));
+ } else {
+ qda_info(qdev, "QDA DSP label not found in DT\n");
+ return ret;
+ }
+
+ ret = qda_rpmsg_init(qdev);
+ if (ret) {
+ qda_err(qdev, "RPMsg init failed: %d\n", ret);
+ return ret;
+ }
+
+ ret = qda_init_device(qdev);
+ if (ret)
+ return ret;
+
+ qda_info(qdev, "QDA RPMsg probe completed successfully for %s\n", qdev->dsp_name);
+ return 0;
+}
+
+static const struct of_device_id qda_rpmsg_id_table[] = {
+ { .compatible = "qcom,fastrpc" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, qda_rpmsg_id_table);
+
+static struct rpmsg_driver qda_rpmsg_driver = {
+ .probe = qda_rpmsg_probe,
+ .remove = qda_rpmsg_remove,
+ .callback = qda_rpmsg_cb,
+ .drv = {
+ .name = "qcom,fastrpc",
+ .of_match_table = qda_rpmsg_id_table,
+ },
+};
+
+int qda_rpmsg_register(void)
+{
+ int ret = register_rpmsg_driver(&qda_rpmsg_driver);
+
+ if (ret)
+ qda_err(NULL, "Failed to register RPMsg driver: %d\n", ret);
+
+ return ret;
+}
+
+void qda_rpmsg_unregister(void)
+{
+ unregister_rpmsg_driver(&qda_rpmsg_driver);
+}
diff --git a/drivers/accel/qda/qda_rpmsg.h b/drivers/accel/qda/qda_rpmsg.h
new file mode 100644
index 000000000000..348827bff255
--- /dev/null
+++ b/drivers/accel/qda/qda_rpmsg.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+
+#ifndef __QDA_RPMSG_H__
+#define __QDA_RPMSG_H__
+
+#include "qda_drv.h"
+
+/*
+ * Transport layer registration
+ */
+int qda_rpmsg_register(void);
+void qda_rpmsg_unregister(void);
+
+#endif /* __QDA_RPMSG_H__ */
--
2.34.1