* [PATCH 0/3] virtio: Add Qualcomm Display Co-Processor transport wrapper
@ 2026-11-26 6:23 Jayant Shekhar
2026-11-26 6:23 ` [PATCH 1/3] dt-bindings: virtio: Add Qualcomm DCP transport Jayant Shekhar
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Jayant Shekhar @ 2026-11-26 6:23 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov,
Flemin Jose
Cc: linux-arm-msm, virtualization, devicetree, linux-kernel,
Jayant Shekhar
The Qualcomm Display Co-Processor (DCP) firmware exposes its services
through a VirtIO function, but its MMIO registers must not be accessed
until the host sends an IPCC power-notify message and receives the
firmware acknowledgement. The generic virtio-mmio transport probes the
registers directly, so it cannot provide this required ordering or
coordinate the power handshake with system suspend and resume.
Add a Qualcomm platform transport that completes the IPCC handshake
before accessing the MMIO registers and registering the VirtIO device.
It reuses the standard virtio-mmio configuration and virtqueue
operations, while routing firmware notifications to the response queue
and ordering VirtIO freeze and restore around DCP power notifications.
The series adds a Device Tree binding for the transport resources, the
generic VIRTIO_ID_VENDOR device ID (proposed value 52), and the transport
and IPCC implementation. The transport handles device discovery, MMIO,
DMA, interrupts, queues, and power sequencing; display protocols and DRM
remain in the separate function driver.
The proposed VIRTIO_ID_VENDOR value 52 remains subject to VirtIO TC
allocation.
Dependencies
============
- The VPU IOMMU series provides the IOVA handling required by the DCP
VirtIO transport. The Hawi DT series provides the platform nodes and
IOMMU descriptions consumed by this series.
https://lore.kernel.org/all/20260926-vpu_iommu_iova_handling-v5-4-0322ca5dc10c@oss.qualcomm.com/
- The generic vendor-specific VirtIO device ID is being discussed with the
VirtIO TC:
https://lore.kernel.org/all/20261022091645-mutt-send-email-mst@kernel.org/
This series uses the proposed VIRTIO_ID_VENDOR value 52, which must not
be merged until the VirtIO TC allocates the device ID. The corresponding
DCP function driver must additionally match the Qualcomm vendor ID and
the DT-described Qualcomm transport.
Signed-off-by: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
---
Jayant Shekhar (3):
dt-bindings: virtio: Add Qualcomm DCP transport
virtio: Add vendor-specific device ID
virtio: Add Qualcomm VirtIO transport wrapper
.../bindings/virtio/qcom,dcp-virtio.yaml | 147 +++++++++++
drivers/virtio/Kconfig | 11 +
drivers/virtio/Makefile | 2 +
drivers/virtio/virtio_mmio.c | 17 +-
drivers/virtio/virtio_mmio.h | 21 ++
drivers/virtio/virtio_qcom_dcp.c | 273 +++++++++++++++++++++
drivers/virtio/virtio_qcom_dcp_ipcc.c | 193 +++++++++++++++
drivers/virtio/virtio_qcom_dcp_ipcc.h | 41 ++++
include/uapi/linux/virtio_ids.h | 1 +
9 files changed, 692 insertions(+), 14 deletions(-)
---
base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7
change-id: 20261112-jshekhar-qcom-virtio-dcp-e653604e05e8
prerequisite-patch-id: eecfd66a55b8f2b7b2fc7d76d815facca0489d00
Best regards,
--
Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/3] dt-bindings: virtio: Add Qualcomm DCP transport
2026-11-26 6:23 [PATCH 0/3] virtio: Add Qualcomm Display Co-Processor transport wrapper Jayant Shekhar
@ 2026-11-26 6:23 ` Jayant Shekhar
2026-11-26 6:36 ` sashiko-bot
2026-11-26 6:24 ` [PATCH 2/3] virtio: Add vendor-specific device ID Jayant Shekhar
2026-11-26 6:24 ` [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper Jayant Shekhar
2 siblings, 1 reply; 12+ messages in thread
From: Jayant Shekhar @ 2026-11-26 6:23 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov,
Flemin Jose
Cc: linux-arm-msm, virtualization, devicetree, linux-kernel,
Jayant Shekhar
Add a binding for the Qualcomm DCP VirtIO transport wrapper.
Document the IPCC power-notify resources, transport MMIO region and
interrupts, transport IOMMU context, firmware-visible IOVA range, and
mailbox channel required before the transport accesses its registers.
Signed-off-by: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
---
.../bindings/virtio/qcom,dcp-virtio.yaml | 147 +++++++++++++++++++++
1 file changed, 147 insertions(+)
diff --git a/Documentation/devicetree/bindings/virtio/qcom,dcp-virtio.yaml b/Documentation/devicetree/bindings/virtio/qcom,dcp-virtio.yaml
new file mode 100644
index 000000000000..46b0e53468be
--- /dev/null
+++ b/Documentation/devicetree/bindings/virtio/qcom,dcp-virtio.yaml
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/virtio/qcom,dcp-virtio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm DCP VirtIO transport
+
+maintainers:
+ - Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
+
+description: |
+ Qualcomm DCP VirtIO transport. The IPCC power-notify channel and
+ associated interrupts are required before the transport can access its
+ MMIO registers. This is a Qualcomm-specific transport and must not use the
+ generic virtio-mmio driver. The DCP VirtIO function is described as a child
+ node and is assigned to the registered VirtIO device by this transport.
+
+properties:
+ compatible:
+ const: qcom,dcp-virtio
+
+ reg:
+ maxItems: 1
+
+ interrupts-extended:
+ minItems: 2
+ maxItems: 2
+ description: The VirtIO-MMIO and DCP power-notify interrupts, in that order.
+
+ iommus:
+ maxItems: 1
+
+ iommu-ranges:
+ $ref: /schemas/types.yaml#/definitions/uint32-array
+ description: |
+ The firmware-visible IOVA range, specified using the parent bus's
+ #address-cells followed by its #size-cells. The DCP transport uses two
+ cells for each, encoding a 64-bit IOVA base followed by a 64-bit range
+ size.
+ items:
+ - description: IOVA base, high cell
+ $ref: /schemas/types.yaml#/definitions/uint32
+ - description: IOVA base, low cell
+ $ref: /schemas/types.yaml#/definitions/uint32
+ - description: IOVA range size, high cell
+ $ref: /schemas/types.yaml#/definitions/uint32
+ - description: IOVA range size, low cell
+ $ref: /schemas/types.yaml#/definitions/uint32
+
+ dma-coherent: true
+
+ mboxes:
+ maxItems: 1
+
+ mbox-names:
+ const: dcp-power-tx
+
+ display-subsystem:
+ $ref: ../display/msm/qcom,dcp.yaml#
+
+required:
+ - compatible
+ - reg
+ - interrupts-extended
+ - iommus
+ - iommu-ranges
+ - dma-coherent
+ - mboxes
+ - mbox-names
+ - display-subsystem
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+ #include <dt-bindings/interrupt-controller/irq.h>
+ #include <dt-bindings/mailbox/qcom-ipcc.h>
+
+ / {
+ compatible = "qcom,hawi-mtp", "qcom,hawi";
+ model = "Qualcomm Technologies, Inc. Hawi MTP";
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ virtio@9be8000 {
+ compatible = "qcom,dcp-virtio";
+ reg = <0x0 0x09be8000 0x0 0x1000>;
+ interrupts-extended = <&intc GIC_ESPI 956 IRQ_TYPE_LEVEL_HIGH>,
+ <&ipcc 13 5 IRQ_TYPE_EDGE_RISING>;
+ iommus = <&apps_smmu 0x15a3 0x0>;
+ iommu-ranges = <0x0 0x84000000 0x0 0x04000000>;
+ dma-coherent;
+ mboxes = <&ipcc 13 5>;
+ mbox-names = "dcp-power-tx";
+
+ display-subsystem {
+ compatible = "virtio,device34";
+ iommus = <&apps_smmu 0x400 0x2>;
+
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@1 {
+ reg = <1>;
+ dcp_intf1_out: endpoint {
+ remote-endpoint = <&panel_dcp_in>;
+ };
+ };
+ };
+
+ interface@1 {
+ reg = <1>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ dsi@0 {
+ reg = <0>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ panel@0 {
+ compatible = "novatek,nt37801";
+ reg = <0>;
+
+ vddio-supply = <&vreg_l12b_1p8>;
+ vci-supply = <&vreg_l13b_3p0>;
+ vdd-supply = <&display_panel_vdd>;
+ reset-gpios = <&tlmm 210 GPIO_ACTIVE_LOW>;
+
+ port {
+ panel_dcp_in: endpoint {
+ remote-endpoint = <&dcp_intf1_out>;
+ };
+ };
+ };
+ };
+ };
+ };
+ };
+ };
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/3] virtio: Add vendor-specific device ID
2026-11-26 6:23 [PATCH 0/3] virtio: Add Qualcomm Display Co-Processor transport wrapper Jayant Shekhar
2026-11-26 6:23 ` [PATCH 1/3] dt-bindings: virtio: Add Qualcomm DCP transport Jayant Shekhar
@ 2026-11-26 6:24 ` Jayant Shekhar
2026-11-26 6:27 ` Michael S. Tsirkin
2026-11-26 6:29 ` sashiko-bot
2026-11-26 6:24 ` [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper Jayant Shekhar
2 siblings, 2 replies; 12+ messages in thread
From: Jayant Shekhar @ 2026-11-26 6:24 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov,
Flemin Jose
Cc: linux-arm-msm, virtualization, devicetree, linux-kernel,
Jayant Shekhar
Define VIRTIO_ID_VENDOR with the proposed device ID value 52 for generic
vendor-specific VirtIO devices. This allows vendor-specific functions to
share one VirtIO device ID and be distinguished using their vendor ID and
platform description.
The value is proposed for VirtIO TC allocation and must not be merged
until the ID is formally allocated. The DCP function driver should match
the generic device ID together with Qualcomm vendor identification and
the DT-described transport.
Signed-off-by: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
---
include/uapi/linux/virtio_ids.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/uapi/linux/virtio_ids.h b/include/uapi/linux/virtio_ids.h
index f9056af0c622..9a8b6a6a03a4 100644
--- a/include/uapi/linux/virtio_ids.h
+++ b/include/uapi/linux/virtio_ids.h
@@ -70,6 +70,7 @@
#define VIRTIO_ID_GPIO 41 /* virtio gpio */
#define VIRTIO_ID_SPI 45 /* virtio spi */
#define VIRTIO_ID_MEDIA 48 /* virtio media */
+#define VIRTIO_ID_VENDOR 52 /* virtio vendor-specific device */
/*
* Virtio Transitional IDs
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper
2026-11-26 6:23 [PATCH 0/3] virtio: Add Qualcomm Display Co-Processor transport wrapper Jayant Shekhar
2026-11-26 6:23 ` [PATCH 1/3] dt-bindings: virtio: Add Qualcomm DCP transport Jayant Shekhar
2026-11-26 6:24 ` [PATCH 2/3] virtio: Add vendor-specific device ID Jayant Shekhar
@ 2026-11-26 6:24 ` Jayant Shekhar
2026-11-26 6:35 ` Michael S. Tsirkin
2026-11-26 6:44 ` sashiko-bot
2 siblings, 2 replies; 12+ messages in thread
From: Jayant Shekhar @ 2026-11-26 6:24 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov,
Flemin Jose
Cc: linux-arm-msm, virtualization, devicetree, linux-kernel,
Jayant Shekhar
Add the Qualcomm-specific VirtIO transport required by DCP firmware.
The transport sends an IPCC power notification before accessing the
VirtIO MMIO registers, then registers a VirtIO device directly.
Implement MMIO configuration access, feature negotiation, virtqueue
setup, interrupt handling, reset, DMA setup, and suspend/resume
sequencing in the transport. Keep power-management ordering in the
transport so VirtIO queues are quiesced before DCP power changes.
Assisted-by: LLM
Signed-off-by: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
---
drivers/virtio/Kconfig | 11 ++
drivers/virtio/Makefile | 2 +
drivers/virtio/virtio_mmio.c | 17 +--
drivers/virtio/virtio_mmio.h | 21 +++
drivers/virtio/virtio_qcom_dcp.c | 273 ++++++++++++++++++++++++++++++++++
drivers/virtio/virtio_qcom_dcp_ipcc.c | 193 ++++++++++++++++++++++++
drivers/virtio/virtio_qcom_dcp_ipcc.h | 41 +++++
7 files changed, 544 insertions(+), 14 deletions(-)
diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index ce5bc0d9ea28..838ae5671c28 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -160,6 +160,17 @@ config VIRTIO_MMIO
If unsure, say N.
+config VIRTIO_QCOM_DCP
+ tristate "Qualcomm DCP VirtIO transport"
+ depends on VIRTIO_MMIO
+ depends on QCOM_IPCC
+ depends on OF
+ help
+ This driver provides the Qualcomm DCP-specific platform transport for
+ QPSFI VirtIO devices. It reuses the standard VirtIO-MMIO configuration
+ and virtqueue support, and handles the IPCC power-notification channel
+ used to wake DCP and forward response notifications.
+
config VIRTIO_MMIO_CMDLINE_DEVICES
bool "Memory mapped virtio devices parameter parsing"
depends on VIRTIO_MMIO
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index eefcfe90d6b8..c922fb5bff16 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -3,6 +3,8 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
obj-$(CONFIG_VIRTIO_ANCHOR) += virtio_anchor.o
obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
+obj-$(CONFIG_VIRTIO_QCOM_DCP) += qcom_dcp_virtio.o
+qcom_dcp_virtio-y := virtio_qcom_dcp.o virtio_qcom_dcp_ipcc.o
obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index c403a025006e..348809b9ebfe 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -71,7 +71,7 @@
#include <uapi/linux/virtio_mmio.h>
#include <linux/virtio_ring.h>
-
+#include "virtio_mmio.h"
/* The alignment to use between consumer and producer parts of vring.
* Currently hardcoded to the page size. */
@@ -81,18 +81,6 @@
#define to_virtio_mmio_device(_plat_dev) \
container_of(_plat_dev, struct virtio_mmio_device, vdev)
-
-struct virtio_mmio_device {
- struct virtio_device vdev;
- struct platform_device *pdev;
-
- void __iomem *base;
- unsigned long version;
-
- /* True if enable_irq_wake() succeeded for the shared IRQ. */
- bool wake_irq_enabled;
-};
-
/* Configuration interface */
static u64 vm_get_features(struct virtio_device *vdev)
@@ -536,7 +524,7 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
return true;
}
-static const struct virtio_config_ops virtio_mmio_config_ops = {
+const struct virtio_config_ops virtio_mmio_config_ops = {
.get = vm_get,
.set = vm_set,
.generation = vm_generation,
@@ -551,6 +539,7 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
.get_shm_region = vm_get_shm_region,
.synchronize_cbs = vm_synchronize_cbs,
};
+EXPORT_SYMBOL_GPL(virtio_mmio_config_ops);
#ifdef CONFIG_PM_SLEEP
static int virtio_mmio_freeze(struct device *dev)
diff --git a/drivers/virtio/virtio_mmio.h b/drivers/virtio/virtio_mmio.h
new file mode 100644
index 000000000000..a80904ed73e2
--- /dev/null
+++ b/drivers/virtio/virtio_mmio.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _DRIVERS_VIRTIO_VIRTIO_MMIO_H
+#define _DRIVERS_VIRTIO_VIRTIO_MMIO_H
+
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+
+struct virtio_mmio_device {
+ struct virtio_device vdev;
+ struct platform_device *pdev;
+ void __iomem *base;
+ unsigned long version;
+ /* True if enable_irq_wake() succeeded for the shared IRQ. */
+ bool wake_irq_enabled;
+};
+
+extern const struct virtio_config_ops virtio_mmio_config_ops;
+
+#endif /* _DRIVERS_VIRTIO_VIRTIO_MMIO_H */
diff --git a/drivers/virtio/virtio_qcom_dcp.c b/drivers/virtio/virtio_qcom_dcp.c
new file mode 100644
index 000000000000..a5443f2dbc4b
--- /dev/null
+++ b/drivers/virtio/virtio_qcom_dcp.c
@@ -0,0 +1,273 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * Qualcomm DCP VirtIO transport.
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/virtio.h>
+#include <linux/virtio_config.h>
+#include <uapi/linux/virtio_mmio.h>
+
+#include "virtio_mmio.h"
+#include "virtio_qcom_dcp_ipcc.h"
+
+struct dcp_virtio_transport {
+ struct virtio_mmio_device mmio;
+ struct virtio_config_ops config_ops;
+ struct dcp_ipcc ipcc;
+};
+
+static struct dcp_virtio_transport *
+to_dcp_virtio_transport(struct virtio_mmio_device *mmio)
+{
+ return container_of(mmio, struct dcp_virtio_transport, mmio);
+}
+
+static void dcp_virtio_synchronize_cbs(struct virtio_device *vdev)
+{
+ struct virtio_mmio_device *mmio =
+ container_of(vdev, struct virtio_mmio_device, vdev);
+ struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
+
+ virtio_mmio_config_ops.synchronize_cbs(vdev);
+ dcp_ipcc_synchronize(&transport->ipcc);
+}
+
+static int dcp_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
+ struct virtqueue *vqs[],
+ struct virtqueue_info vqs_info[],
+ struct irq_affinity *desc)
+{
+ struct virtio_mmio_device *mmio =
+ container_of(vdev, struct virtio_mmio_device, vdev);
+ struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
+ unsigned int i;
+ int ret;
+
+ ret = virtio_mmio_config_ops.find_vqs(vdev, nvqs, vqs, vqs_info, desc);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < nvqs; i++) {
+ if (vqs[i] && vqs_info[i].name && !strcmp(vqs_info[i].name, "resp")) {
+ dcp_ipcc_set_resp_vq(&transport->ipcc, vqs[i]);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static void dcp_virtio_del_vqs(struct virtio_device *vdev)
+{
+ struct virtio_mmio_device *mmio =
+ container_of(vdev, struct virtio_mmio_device, vdev);
+ struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
+
+ dcp_ipcc_set_resp_vq(&transport->ipcc, NULL);
+ virtio_mmio_config_ops.del_vqs(vdev);
+}
+
+static void dcp_virtio_release_dev(struct device *dev)
+{
+ struct virtio_device *vdev = container_of(dev, struct virtio_device, dev);
+ struct virtio_mmio_device *mmio =
+ container_of(vdev, struct virtio_mmio_device, vdev);
+ struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
+
+ kfree(transport);
+}
+
+static int dcp_virtio_init_device(struct dcp_virtio_transport *transport,
+ struct platform_device *pdev)
+{
+ struct virtio_mmio_device *mmio = &transport->mmio;
+ unsigned long magic;
+ int ret;
+
+ mmio->vdev.dev.parent = &pdev->dev;
+ mmio->vdev.config = &transport->config_ops;
+ mmio->pdev = pdev;
+
+ mmio->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(mmio->base))
+ return PTR_ERR(mmio->base);
+
+ magic = readl(mmio->base + VIRTIO_MMIO_MAGIC_VALUE);
+ if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
+ dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
+ return -ENODEV;
+ }
+
+ mmio->version = readl(mmio->base + VIRTIO_MMIO_VERSION);
+ if (mmio->version < 1 || mmio->version > 3) {
+ dev_err(&pdev->dev, "Version %ld not supported!\n", mmio->version);
+ return -ENXIO;
+ }
+
+ mmio->vdev.id.device = readl(mmio->base + VIRTIO_MMIO_DEVICE_ID);
+ if (!mmio->vdev.id.device)
+ return -ENODEV;
+
+ mmio->vdev.id.vendor = readl(mmio->base + VIRTIO_MMIO_VENDOR_ID);
+
+ if (mmio->version == 1) {
+ writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
+ ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
+ if (!ret)
+ dma_set_coherent_mask(&pdev->dev,
+ DMA_BIT_MASK(32 + PAGE_SHIFT));
+ } else {
+ ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+ }
+ if (ret)
+ ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+ if (ret)
+ dev_warn(&pdev->dev,
+ "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
+
+ return 0;
+}
+
+static int dcp_virtio_transport_probe(struct platform_device *pdev)
+{
+ struct dcp_virtio_transport *transport;
+ struct virtio_mmio_device *mmio;
+ int ret;
+
+ transport = kzalloc_obj(*transport);
+ if (!transport)
+ return -ENOMEM;
+
+ mmio = &transport->mmio;
+ mmio->vdev.dev.release = dcp_virtio_release_dev;
+ transport->config_ops = virtio_mmio_config_ops;
+ transport->config_ops.find_vqs = dcp_virtio_find_vqs;
+ transport->config_ops.del_vqs = dcp_virtio_del_vqs;
+ transport->config_ops.synchronize_cbs = dcp_virtio_synchronize_cbs;
+
+ ret = dcp_ipcc_init(&transport->ipcc, &pdev->dev, 1);
+ if (ret) {
+ kfree(transport);
+ return ret;
+ }
+
+ /* Wake DCP before the first access to the VirtIO MMIO registers. */
+ ret = dcp_ipcc_send_power_notify(&transport->ipcc);
+ if (ret)
+ goto err_ipcc;
+
+ ret = dcp_virtio_init_device(transport, pdev);
+ if (ret)
+ goto err_ipcc;
+
+ platform_set_drvdata(pdev, transport);
+
+ ret = register_virtio_device(&mmio->vdev);
+ if (ret) {
+ platform_set_drvdata(pdev, NULL);
+ dcp_ipcc_deinit(&transport->ipcc);
+ put_device(&mmio->vdev.dev);
+ return ret;
+ }
+
+ return 0;
+
+err_ipcc:
+ dcp_ipcc_deinit(&transport->ipcc);
+ kfree(transport);
+ return ret;
+}
+
+static void dcp_virtio_transport_remove(struct platform_device *pdev)
+{
+ struct dcp_virtio_transport *transport = platform_get_drvdata(pdev);
+
+ /* Keep the embedded virtio_device alive until IPCC teardown is complete. */
+ get_device(&transport->mmio.vdev.dev);
+ unregister_virtio_device(&transport->mmio.vdev);
+ platform_set_drvdata(pdev, NULL);
+ dcp_ipcc_deinit(&transport->ipcc);
+ put_device(&transport->mmio.vdev.dev);
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int dcp_virtio_transport_suspend(struct device *dev)
+{
+ struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
+ int ret;
+
+ ret = virtio_device_freeze(&transport->mmio.vdev);
+ if (ret)
+ return ret;
+
+ ret = dcp_ipcc_enable_irq_wake(&transport->ipcc);
+ if (ret)
+ goto err_restore;
+
+ ret = dcp_ipcc_send_power_notify(&transport->ipcc);
+ if (ret) {
+ dcp_ipcc_disable_irq_wake(&transport->ipcc);
+ goto err_restore;
+ }
+
+ return 0;
+
+err_restore:
+ virtio_device_restore(&transport->mmio.vdev);
+ return ret;
+}
+
+static int dcp_virtio_transport_resume(struct device *dev)
+{
+ struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
+ struct virtio_mmio_device *mmio = &transport->mmio;
+ int ret;
+
+ ret = dcp_ipcc_send_power_notify(&transport->ipcc);
+ if (ret) {
+ dcp_ipcc_disable_irq_wake(&transport->ipcc);
+ return ret;
+ }
+
+ dcp_ipcc_disable_irq_wake(&transport->ipcc);
+ if (mmio->version == 1)
+ writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
+
+ return virtio_device_restore(&mmio->vdev);
+}
+
+#endif
+static const struct dev_pm_ops dcp_virtio_transport_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(dcp_virtio_transport_suspend,
+ dcp_virtio_transport_resume)
+};
+
+static const struct of_device_id dcp_virtio_transport_of_match[] = {
+ { .compatible = "qcom,dcp-virtio" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, dcp_virtio_transport_of_match);
+
+static struct platform_driver dcp_virtio_transport_driver = {
+ .probe = dcp_virtio_transport_probe,
+ .remove = dcp_virtio_transport_remove,
+ .driver = {
+ .name = "qcom-dcp-virtio",
+ .of_match_table = dcp_virtio_transport_of_match,
+ .pm = pm_sleep_ptr(&dcp_virtio_transport_pm_ops),
+ },
+};
+module_platform_driver(dcp_virtio_transport_driver);
+
+MODULE_DESCRIPTION("Qualcomm DCP VirtIO transport");
+MODULE_LICENSE("GPL");
diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.c b/drivers/virtio/virtio_qcom_dcp_ipcc.c
new file mode 100644
index 000000000000..1d83bcc69d5c
--- /dev/null
+++ b/drivers/virtio/virtio_qcom_dcp_ipcc.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * DCP IPCC power-notify mailbox client. It wakes DCP during power
+ * transitions and routes firmware notifications to the VirtIO response
+ * queue.
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/jiffies.h>
+#include <linux/interrupt.h>
+#include <linux/mailbox_client.h>
+#include <linux/mutex.h>
+#include <linux/of_irq.h>
+#include <linux/string.h>
+#include <linux/virtio.h>
+#include <linux/virtio_ring.h>
+
+#include "virtio_qcom_dcp_ipcc.h"
+
+#define DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS 10000
+
+static void dcp_ipcc_handle_rx(struct dcp_ipcc *ipcc)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&ipcc->state_lock, flags);
+ if (ipcc->shutting_down) {
+ spin_unlock_irqrestore(&ipcc->state_lock, flags);
+ return;
+ }
+
+ complete(&ipcc->power_notify_done);
+ if (ipcc->resp_vq)
+ vring_interrupt(0, ipcc->resp_vq);
+
+ spin_unlock_irqrestore(&ipcc->state_lock, flags);
+}
+
+static irqreturn_t dcp_ipcc_power_notify_irq(int irq, void *data)
+{
+ struct dcp_ipcc *ipcc = data;
+
+ dcp_ipcc_handle_rx(ipcc);
+
+ return IRQ_HANDLED;
+}
+
+static void dcp_ipcc_rx_callback(struct mbox_client *cl, void *data)
+{
+ struct dcp_ipcc *ipcc = container_of(cl, struct dcp_ipcc, client);
+
+ dcp_ipcc_handle_rx(ipcc);
+}
+
+static void dcp_ipcc_free_channel(void *data)
+{
+ mbox_free_channel(data);
+}
+
+int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index)
+{
+ int irq, ret;
+
+ memset(ipcc, 0, sizeof(*ipcc));
+ init_completion(&ipcc->power_notify_done);
+ mutex_init(&ipcc->power_notify_lock);
+ spin_lock_init(&ipcc->state_lock);
+
+ ipcc->client.dev = dev;
+ ipcc->client.tx_block = false;
+ ipcc->client.tx_tout = 0;
+ ipcc->client.knows_txdone = true;
+ ipcc->client.rx_callback = dcp_ipcc_rx_callback;
+
+ ipcc->power_chan = mbox_request_channel(&ipcc->client, 0);
+ if (IS_ERR(ipcc->power_chan)) {
+ ret = PTR_ERR(ipcc->power_chan);
+ if (ret != -EPROBE_DEFER)
+ dev_err(dev, "IPCC: failed to get DCP power channel: %d\n", ret);
+ return ret;
+ }
+
+ ret = devm_add_action_or_reset(dev, dcp_ipcc_free_channel,
+ ipcc->power_chan);
+ if (ret) {
+ ipcc->power_chan = NULL;
+ return ret;
+ }
+
+ irq = of_irq_get(dev->of_node, irq_index);
+ if (irq <= 0) {
+ ret = dev_err_probe(dev, irq ? irq : -EINVAL,
+ "failed to get required power notify IRQ\n");
+ goto err_free_channel;
+ }
+
+ ret = devm_request_irq(dev, irq, dcp_ipcc_power_notify_irq, 0,
+ "dcp-power-notify", ipcc);
+ if (ret) {
+ ret = dev_err_probe(dev, ret,
+ "failed to request power notify IRQ %d\n", irq);
+ goto err_free_channel;
+ }
+
+ ipcc->power_notify_irq = irq;
+
+ return 0;
+
+err_free_channel:
+ devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
+ ipcc->power_chan = NULL;
+ return ret;
+}
+
+void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&ipcc->state_lock, flags);
+ if (!ipcc->shutting_down)
+ ipcc->resp_vq = resp_vq;
+ spin_unlock_irqrestore(&ipcc->state_lock, flags);
+}
+
+void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&ipcc->state_lock, flags);
+ spin_unlock_irqrestore(&ipcc->state_lock, flags);
+}
+
+void dcp_ipcc_deinit(struct dcp_ipcc *ipcc)
+{
+ struct device *dev = ipcc->client.dev;
+ unsigned long flags;
+
+ mutex_lock(&ipcc->power_notify_lock);
+
+ spin_lock_irqsave(&ipcc->state_lock, flags);
+ ipcc->shutting_down = true;
+ ipcc->resp_vq = NULL;
+ spin_unlock_irqrestore(&ipcc->state_lock, flags);
+
+ devm_free_irq(dev, ipcc->power_notify_irq, ipcc);
+ devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
+ mutex_unlock(&ipcc->power_notify_lock);
+}
+
+int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc)
+{
+ return enable_irq_wake(ipcc->power_notify_irq);
+}
+
+void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc)
+{
+ disable_irq_wake(ipcc->power_notify_irq);
+}
+
+int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc)
+{
+ unsigned long timeout;
+ int ret;
+
+ mutex_lock(&ipcc->power_notify_lock);
+
+ reinit_completion(&ipcc->power_notify_done);
+
+ ret = mbox_send_message(ipcc->power_chan, NULL);
+ mbox_client_txdone(ipcc->power_chan, ret);
+ if (ret < 0) {
+ dev_err(ipcc->client.dev,
+ "IPCC TX: power notify failed: %d\n", ret);
+ goto out_unlock;
+ }
+
+ timeout = wait_for_completion_timeout(&ipcc->power_notify_done,
+ msecs_to_jiffies(DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS));
+ if (!timeout) {
+ dev_err(ipcc->client.dev,
+ "IPCC power notify acknowledgment timed out\n");
+ ret = -ETIMEDOUT;
+ } else {
+ ret = 0;
+ }
+
+out_unlock:
+ mutex_unlock(&ipcc->power_notify_lock);
+ return ret;
+}
diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.h b/drivers/virtio/virtio_qcom_dcp_ipcc.h
new file mode 100644
index 000000000000..f855fe8adec1
--- /dev/null
+++ b/drivers/virtio/virtio_qcom_dcp_ipcc.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * IPCC power-notify mailbox interface for DCP firmware.
+ *
+ */
+
+#ifndef __VIRTIO_QCOM_DCP_IPCC_H__
+#define __VIRTIO_QCOM_DCP_IPCC_H__
+
+#include <linux/completion.h>
+#include <linux/mailbox_client.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+
+struct device;
+struct virtqueue;
+
+struct dcp_ipcc {
+ struct mbox_client client;
+ struct mbox_chan *power_chan;
+ struct virtqueue *resp_vq;
+ struct completion power_notify_done;
+ /* Serializes concurrent power-notify transactions. */
+ struct mutex power_notify_lock;
+ /* Protects callback state and response queue access. */
+ spinlock_t state_lock;
+ bool shutting_down;
+ int power_notify_irq;
+};
+
+int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index);
+void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq);
+void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc);
+void dcp_ipcc_deinit(struct dcp_ipcc *ipcc);
+int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc);
+int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc);
+void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc);
+
+#endif /* __VIRTIO_QCOM_DCP_IPCC_H__ */
--
2.43.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 2/3] virtio: Add vendor-specific device ID
2026-11-26 6:24 ` [PATCH 2/3] virtio: Add vendor-specific device ID Jayant Shekhar
@ 2026-11-26 6:27 ` Michael S. Tsirkin
2026-11-26 6:29 ` sashiko-bot
1 sibling, 0 replies; 12+ messages in thread
From: Michael S. Tsirkin @ 2026-11-26 6:27 UTC (permalink / raw)
To: Jayant Shekhar
Cc: Jason Wang, Eugenio Pérez, Xuan Zhuo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov, Flemin Jose,
linux-arm-msm, virtualization, devicetree, linux-kernel
On Thu, Nov 26, 2026 at 11:54:00AM +0530, Jayant Shekhar wrote:
> Define VIRTIO_ID_VENDOR with the proposed device ID value 52 for generic
> vendor-specific VirtIO devices. This allows vendor-specific functions to
> share one VirtIO device ID and be distinguished using their vendor ID and
> platform description.
>
> The value is proposed for VirtIO TC allocation and must not be merged
> until the ID is formally allocated. The DCP function driver should match
> the generic device ID together with Qualcomm vendor identification and
> the DT-described transport.
>
> Signed-off-by: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
> ---
> include/uapi/linux/virtio_ids.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/uapi/linux/virtio_ids.h b/include/uapi/linux/virtio_ids.h
> index f9056af0c622..9a8b6a6a03a4 100644
> --- a/include/uapi/linux/virtio_ids.h
> +++ b/include/uapi/linux/virtio_ids.h
> @@ -70,6 +70,7 @@
> #define VIRTIO_ID_GPIO 41 /* virtio gpio */
> #define VIRTIO_ID_SPI 45 /* virtio spi */
> #define VIRTIO_ID_MEDIA 48 /* virtio media */
> +#define VIRTIO_ID_VENDOR 52 /* virtio vendor-specific device */
I am fine with this. But it has to get virtio tc approval or you risk
conflicting with someone else's id.
Please request a vote in the virtio tc going on this one and resubmit
once it's approved. takes a couple of weeks usually.
>
> /*
> * Virtio Transitional IDs
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/3] virtio: Add vendor-specific device ID
2026-11-26 6:24 ` [PATCH 2/3] virtio: Add vendor-specific device ID Jayant Shekhar
2026-11-26 6:27 ` Michael S. Tsirkin
@ 2026-11-26 6:29 ` sashiko-bot
1 sibling, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-26 6:29 UTC (permalink / raw)
To: Jayant Shekhar
Cc: virtualization, devicetree, robh, conor+dt, Michael S. Tsirkin,
Eugenio Perez
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] virtio: unallocated VIRTIO_ID_VENDOR added to UAPI
virtio_ids.h
--
commit 913884946279be0d6a387cfae4fb22c6ba81e67d
Author: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
virtio: Add vendor-specific device ID
This commit defines VIRTIO_ID_VENDOR (52) in include/uapi/linux/virtio_ids.h
for generic vendor-specific VirtIO devices.
> diff --git a/include/uapi/linux/virtio_ids.h b/include/uapi/linux/virtio_ids.h
> index f9056af0c6223..9a8b6a6a03a48 100644
> --- a/include/uapi/linux/virtio_ids.h
> +++ b/include/uapi/linux/virtio_ids.h
> @@ -70,6 +70,7 @@
> #define VIRTIO_ID_GPIO 41 /* virtio gpio */
> #define VIRTIO_ID_SPI 45 /* virtio spi */
> #define VIRTIO_ID_MEDIA 48 /* virtio media */
> +#define VIRTIO_ID_VENDOR 52 /* virtio vendor-specific device */
[Severity: Medium]
Should VIRTIO_ID_VENDOR be added to include/uapi/linux/virtio_ids.h before
device ID 52 is reserved in the VirtIO specification?
As noted in the commit message, value 52 is only proposed for VirtIO TC
allocation. Documentation/driver-api/virtio/writing_virtio_drivers.rst
requires device IDs to be at least reserved in the VirtIO specification
before being added to include/uapi/linux/virtio_ids.h, because exposing an
unallocated ID in the UAPI header risks an ABI conflict if the VirtIO TC
assigns 52 to another device type or assigns a different ID here.
In addition, temporary merge-blocking notes and commentary about future
driver matching belong below the --- tearline rather than in the permanent
commit changelog.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-jshekhar-qcom-virtio-dcp-v1-0-7b49bda74916@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper
2026-11-26 6:24 ` [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper Jayant Shekhar
@ 2026-11-26 6:35 ` Michael S. Tsirkin
2026-11-26 10:03 ` Jayant Shekhar
2026-11-26 6:44 ` sashiko-bot
1 sibling, 1 reply; 12+ messages in thread
From: Michael S. Tsirkin @ 2026-11-26 6:35 UTC (permalink / raw)
To: Jayant Shekhar
Cc: Jason Wang, Eugenio Pérez, Xuan Zhuo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov, Flemin Jose,
linux-arm-msm, virtualization, devicetree, linux-kernel
On Thu, Nov 26, 2026 at 11:54:01AM +0530, Jayant Shekhar wrote:
> Add the Qualcomm-specific VirtIO transport required by DCP firmware.
>
> The transport sends an IPCC power notification before accessing the
> VirtIO MMIO registers, then registers a VirtIO device directly.
>
> Implement MMIO configuration access, feature negotiation, virtqueue
> setup, interrupt handling, reset, DMA setup, and suspend/resume
> sequencing in the transport. Keep power-management ordering in the
> transport so VirtIO queues are quiesced before DCP power changes.
>
> Assisted-by: LLM
> Signed-off-by: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
So VIRTIO_ID_VENDOR you defined in patch 2 is completely unused?
Why did you bother?
> ---
> drivers/virtio/Kconfig | 11 ++
> drivers/virtio/Makefile | 2 +
> drivers/virtio/virtio_mmio.c | 17 +--
> drivers/virtio/virtio_mmio.h | 21 +++
> drivers/virtio/virtio_qcom_dcp.c | 273 ++++++++++++++++++++++++++++++++++
> drivers/virtio/virtio_qcom_dcp_ipcc.c | 193 ++++++++++++++++++++++++
> drivers/virtio/virtio_qcom_dcp_ipcc.h | 41 +++++
> 7 files changed, 544 insertions(+), 14 deletions(-)
Oh great a pile of vendor specific code in virtio, with the vendor
explicitly saying on the virtio ML that no specs will be published,
ever. And it seems to be your assumption that I'll be signing up to
maintain this?
>
> diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
> index ce5bc0d9ea28..838ae5671c28 100644
> --- a/drivers/virtio/Kconfig
> +++ b/drivers/virtio/Kconfig
> @@ -160,6 +160,17 @@ config VIRTIO_MMIO
>
> If unsure, say N.
>
> +config VIRTIO_QCOM_DCP
> + tristate "Qualcomm DCP VirtIO transport"
> + depends on VIRTIO_MMIO
> + depends on QCOM_IPCC
> + depends on OF
> + help
> + This driver provides the Qualcomm DCP-specific platform transport for
> + QPSFI VirtIO devices. It reuses the standard VirtIO-MMIO configuration
> + and virtqueue support, and handles the IPCC power-notification channel
> + used to wake DCP and forward response notifications.
> +
> config VIRTIO_MMIO_CMDLINE_DEVICES
> bool "Memory mapped virtio devices parameter parsing"
> depends on VIRTIO_MMIO
> diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
> index eefcfe90d6b8..c922fb5bff16 100644
> --- a/drivers/virtio/Makefile
> +++ b/drivers/virtio/Makefile
> @@ -3,6 +3,8 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
> obj-$(CONFIG_VIRTIO_ANCHOR) += virtio_anchor.o
> obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
> obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
> +obj-$(CONFIG_VIRTIO_QCOM_DCP) += qcom_dcp_virtio.o
> +qcom_dcp_virtio-y := virtio_qcom_dcp.o virtio_qcom_dcp_ipcc.o
> obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
> obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
> virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index c403a025006e..348809b9ebfe 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -71,7 +71,7 @@
> #include <uapi/linux/virtio_mmio.h>
> #include <linux/virtio_ring.h>
>
> -
> +#include "virtio_mmio.h"
>
> /* The alignment to use between consumer and producer parts of vring.
> * Currently hardcoded to the page size. */
> @@ -81,18 +81,6 @@
>
> #define to_virtio_mmio_device(_plat_dev) \
> container_of(_plat_dev, struct virtio_mmio_device, vdev)
> -
> -struct virtio_mmio_device {
> - struct virtio_device vdev;
> - struct platform_device *pdev;
> -
> - void __iomem *base;
> - unsigned long version;
> -
> - /* True if enable_irq_wake() succeeded for the shared IRQ. */
> - bool wake_irq_enabled;
> -};
> -
> /* Configuration interface */
>
> static u64 vm_get_features(struct virtio_device *vdev)
> @@ -536,7 +524,7 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
> return true;
> }
>
> -static const struct virtio_config_ops virtio_mmio_config_ops = {
> +const struct virtio_config_ops virtio_mmio_config_ops = {
> .get = vm_get,
> .set = vm_set,
> .generation = vm_generation,
> @@ -551,6 +539,7 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
> .get_shm_region = vm_get_shm_region,
> .synchronize_cbs = vm_synchronize_cbs,
> };
> +EXPORT_SYMBOL_GPL(virtio_mmio_config_ops);
>
> #ifdef CONFIG_PM_SLEEP
> static int virtio_mmio_freeze(struct device *dev)
> diff --git a/drivers/virtio/virtio_mmio.h b/drivers/virtio/virtio_mmio.h
> new file mode 100644
> index 000000000000..a80904ed73e2
> --- /dev/null
> +++ b/drivers/virtio/virtio_mmio.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef _DRIVERS_VIRTIO_VIRTIO_MMIO_H
> +#define _DRIVERS_VIRTIO_VIRTIO_MMIO_H
> +
> +#include <linux/io.h>
> +#include <linux/platform_device.h>
> +#include <linux/virtio.h>
> +#include <linux/virtio_config.h>
> +
> +struct virtio_mmio_device {
> + struct virtio_device vdev;
> + struct platform_device *pdev;
> + void __iomem *base;
> + unsigned long version;
> + /* True if enable_irq_wake() succeeded for the shared IRQ. */
> + bool wake_irq_enabled;
> +};
> +
> +extern const struct virtio_config_ops virtio_mmio_config_ops;
> +
> +#endif /* _DRIVERS_VIRTIO_VIRTIO_MMIO_H */
> diff --git a/drivers/virtio/virtio_qcom_dcp.c b/drivers/virtio/virtio_qcom_dcp.c
> new file mode 100644
> index 000000000000..a5443f2dbc4b
> --- /dev/null
> +++ b/drivers/virtio/virtio_qcom_dcp.c
> @@ -0,0 +1,273 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> + *
> + * Qualcomm DCP VirtIO transport.
> + */
> +
> +#include <linux/dma-mapping.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <linux/virtio.h>
> +#include <linux/virtio_config.h>
> +#include <uapi/linux/virtio_mmio.h>
> +
> +#include "virtio_mmio.h"
> +#include "virtio_qcom_dcp_ipcc.h"
> +
> +struct dcp_virtio_transport {
> + struct virtio_mmio_device mmio;
> + struct virtio_config_ops config_ops;
> + struct dcp_ipcc ipcc;
> +};
> +
> +static struct dcp_virtio_transport *
> +to_dcp_virtio_transport(struct virtio_mmio_device *mmio)
> +{
> + return container_of(mmio, struct dcp_virtio_transport, mmio);
> +}
> +
> +static void dcp_virtio_synchronize_cbs(struct virtio_device *vdev)
> +{
> + struct virtio_mmio_device *mmio =
> + container_of(vdev, struct virtio_mmio_device, vdev);
> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> +
> + virtio_mmio_config_ops.synchronize_cbs(vdev);
> + dcp_ipcc_synchronize(&transport->ipcc);
> +}
> +
> +static int dcp_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
> + struct virtqueue *vqs[],
> + struct virtqueue_info vqs_info[],
> + struct irq_affinity *desc)
> +{
> + struct virtio_mmio_device *mmio =
> + container_of(vdev, struct virtio_mmio_device, vdev);
> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> + unsigned int i;
> + int ret;
> +
> + ret = virtio_mmio_config_ops.find_vqs(vdev, nvqs, vqs, vqs_info, desc);
> + if (ret)
> + return ret;
> +
> + for (i = 0; i < nvqs; i++) {
> + if (vqs[i] && vqs_info[i].name && !strcmp(vqs_info[i].name, "resp")) {
> + dcp_ipcc_set_resp_vq(&transport->ipcc, vqs[i]);
> + break;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static void dcp_virtio_del_vqs(struct virtio_device *vdev)
> +{
> + struct virtio_mmio_device *mmio =
> + container_of(vdev, struct virtio_mmio_device, vdev);
> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> +
> + dcp_ipcc_set_resp_vq(&transport->ipcc, NULL);
> + virtio_mmio_config_ops.del_vqs(vdev);
> +}
> +
> +static void dcp_virtio_release_dev(struct device *dev)
> +{
> + struct virtio_device *vdev = container_of(dev, struct virtio_device, dev);
> + struct virtio_mmio_device *mmio =
> + container_of(vdev, struct virtio_mmio_device, vdev);
> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> +
> + kfree(transport);
> +}
> +
> +static int dcp_virtio_init_device(struct dcp_virtio_transport *transport,
> + struct platform_device *pdev)
> +{
> + struct virtio_mmio_device *mmio = &transport->mmio;
> + unsigned long magic;
> + int ret;
> +
> + mmio->vdev.dev.parent = &pdev->dev;
> + mmio->vdev.config = &transport->config_ops;
> + mmio->pdev = pdev;
> +
> + mmio->base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(mmio->base))
> + return PTR_ERR(mmio->base);
> +
> + magic = readl(mmio->base + VIRTIO_MMIO_MAGIC_VALUE);
> + if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
> + dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
> + return -ENODEV;
> + }
> +
> + mmio->version = readl(mmio->base + VIRTIO_MMIO_VERSION);
> + if (mmio->version < 1 || mmio->version > 3) {
> + dev_err(&pdev->dev, "Version %ld not supported!\n", mmio->version);
> + return -ENXIO;
> + }
> +
> + mmio->vdev.id.device = readl(mmio->base + VIRTIO_MMIO_DEVICE_ID);
> + if (!mmio->vdev.id.device)
> + return -ENODEV;
> +
> + mmio->vdev.id.vendor = readl(mmio->base + VIRTIO_MMIO_VENDOR_ID);
> +
> + if (mmio->version == 1) {
> + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
> + ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
> + if (!ret)
> + dma_set_coherent_mask(&pdev->dev,
> + DMA_BIT_MASK(32 + PAGE_SHIFT));
> + } else {
> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
> + }
> + if (ret)
> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> + if (ret)
> + dev_warn(&pdev->dev,
> + "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
> +
> + return 0;
> +}
> +
> +static int dcp_virtio_transport_probe(struct platform_device *pdev)
> +{
> + struct dcp_virtio_transport *transport;
> + struct virtio_mmio_device *mmio;
> + int ret;
> +
> + transport = kzalloc_obj(*transport);
> + if (!transport)
> + return -ENOMEM;
> +
> + mmio = &transport->mmio;
> + mmio->vdev.dev.release = dcp_virtio_release_dev;
> + transport->config_ops = virtio_mmio_config_ops;
> + transport->config_ops.find_vqs = dcp_virtio_find_vqs;
> + transport->config_ops.del_vqs = dcp_virtio_del_vqs;
> + transport->config_ops.synchronize_cbs = dcp_virtio_synchronize_cbs;
> +
> + ret = dcp_ipcc_init(&transport->ipcc, &pdev->dev, 1);
> + if (ret) {
> + kfree(transport);
> + return ret;
> + }
> +
> + /* Wake DCP before the first access to the VirtIO MMIO registers. */
> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
> + if (ret)
> + goto err_ipcc;
> +
> + ret = dcp_virtio_init_device(transport, pdev);
> + if (ret)
> + goto err_ipcc;
> +
> + platform_set_drvdata(pdev, transport);
> +
> + ret = register_virtio_device(&mmio->vdev);
> + if (ret) {
> + platform_set_drvdata(pdev, NULL);
> + dcp_ipcc_deinit(&transport->ipcc);
> + put_device(&mmio->vdev.dev);
> + return ret;
> + }
> +
> + return 0;
> +
> +err_ipcc:
> + dcp_ipcc_deinit(&transport->ipcc);
> + kfree(transport);
> + return ret;
> +}
> +
> +static void dcp_virtio_transport_remove(struct platform_device *pdev)
> +{
> + struct dcp_virtio_transport *transport = platform_get_drvdata(pdev);
> +
> + /* Keep the embedded virtio_device alive until IPCC teardown is complete. */
> + get_device(&transport->mmio.vdev.dev);
> + unregister_virtio_device(&transport->mmio.vdev);
> + platform_set_drvdata(pdev, NULL);
> + dcp_ipcc_deinit(&transport->ipcc);
> + put_device(&transport->mmio.vdev.dev);
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static int dcp_virtio_transport_suspend(struct device *dev)
> +{
> + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = virtio_device_freeze(&transport->mmio.vdev);
> + if (ret)
> + return ret;
> +
> + ret = dcp_ipcc_enable_irq_wake(&transport->ipcc);
> + if (ret)
> + goto err_restore;
> +
> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
> + if (ret) {
> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
> + goto err_restore;
> + }
> +
> + return 0;
> +
> +err_restore:
> + virtio_device_restore(&transport->mmio.vdev);
> + return ret;
> +}
> +
> +static int dcp_virtio_transport_resume(struct device *dev)
> +{
> + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
> + struct virtio_mmio_device *mmio = &transport->mmio;
> + int ret;
> +
> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
> + if (ret) {
> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
> + return ret;
> + }
> +
> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
> + if (mmio->version == 1)
> + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
> +
> + return virtio_device_restore(&mmio->vdev);
> +}
> +
> +#endif
> +static const struct dev_pm_ops dcp_virtio_transport_pm_ops = {
> + SET_SYSTEM_SLEEP_PM_OPS(dcp_virtio_transport_suspend,
> + dcp_virtio_transport_resume)
> +};
> +
> +static const struct of_device_id dcp_virtio_transport_of_match[] = {
> + { .compatible = "qcom,dcp-virtio" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, dcp_virtio_transport_of_match);
> +
> +static struct platform_driver dcp_virtio_transport_driver = {
> + .probe = dcp_virtio_transport_probe,
> + .remove = dcp_virtio_transport_remove,
> + .driver = {
> + .name = "qcom-dcp-virtio",
> + .of_match_table = dcp_virtio_transport_of_match,
> + .pm = pm_sleep_ptr(&dcp_virtio_transport_pm_ops),
> + },
> +};
> +module_platform_driver(dcp_virtio_transport_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm DCP VirtIO transport");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.c b/drivers/virtio/virtio_qcom_dcp_ipcc.c
> new file mode 100644
> index 000000000000..1d83bcc69d5c
> --- /dev/null
> +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.c
> @@ -0,0 +1,193 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> + *
> + * DCP IPCC power-notify mailbox client. It wakes DCP during power
> + * transitions and routes firmware notifications to the VirtIO response
> + * queue.
> + */
> +
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/jiffies.h>
> +#include <linux/interrupt.h>
> +#include <linux/mailbox_client.h>
> +#include <linux/mutex.h>
> +#include <linux/of_irq.h>
> +#include <linux/string.h>
> +#include <linux/virtio.h>
> +#include <linux/virtio_ring.h>
> +
> +#include "virtio_qcom_dcp_ipcc.h"
> +
> +#define DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS 10000
> +
> +static void dcp_ipcc_handle_rx(struct dcp_ipcc *ipcc)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ipcc->state_lock, flags);
> + if (ipcc->shutting_down) {
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> + return;
> + }
> +
> + complete(&ipcc->power_notify_done);
> + if (ipcc->resp_vq)
> + vring_interrupt(0, ipcc->resp_vq);
> +
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> +}
> +
> +static irqreturn_t dcp_ipcc_power_notify_irq(int irq, void *data)
> +{
> + struct dcp_ipcc *ipcc = data;
> +
> + dcp_ipcc_handle_rx(ipcc);
> +
> + return IRQ_HANDLED;
> +}
> +
> +static void dcp_ipcc_rx_callback(struct mbox_client *cl, void *data)
> +{
> + struct dcp_ipcc *ipcc = container_of(cl, struct dcp_ipcc, client);
> +
> + dcp_ipcc_handle_rx(ipcc);
> +}
> +
> +static void dcp_ipcc_free_channel(void *data)
> +{
> + mbox_free_channel(data);
> +}
> +
> +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index)
> +{
> + int irq, ret;
> +
> + memset(ipcc, 0, sizeof(*ipcc));
> + init_completion(&ipcc->power_notify_done);
> + mutex_init(&ipcc->power_notify_lock);
> + spin_lock_init(&ipcc->state_lock);
> +
> + ipcc->client.dev = dev;
> + ipcc->client.tx_block = false;
> + ipcc->client.tx_tout = 0;
> + ipcc->client.knows_txdone = true;
> + ipcc->client.rx_callback = dcp_ipcc_rx_callback;
> +
> + ipcc->power_chan = mbox_request_channel(&ipcc->client, 0);
> + if (IS_ERR(ipcc->power_chan)) {
> + ret = PTR_ERR(ipcc->power_chan);
> + if (ret != -EPROBE_DEFER)
> + dev_err(dev, "IPCC: failed to get DCP power channel: %d\n", ret);
> + return ret;
> + }
> +
> + ret = devm_add_action_or_reset(dev, dcp_ipcc_free_channel,
> + ipcc->power_chan);
> + if (ret) {
> + ipcc->power_chan = NULL;
> + return ret;
> + }
> +
> + irq = of_irq_get(dev->of_node, irq_index);
> + if (irq <= 0) {
> + ret = dev_err_probe(dev, irq ? irq : -EINVAL,
> + "failed to get required power notify IRQ\n");
> + goto err_free_channel;
> + }
> +
> + ret = devm_request_irq(dev, irq, dcp_ipcc_power_notify_irq, 0,
> + "dcp-power-notify", ipcc);
> + if (ret) {
> + ret = dev_err_probe(dev, ret,
> + "failed to request power notify IRQ %d\n", irq);
> + goto err_free_channel;
> + }
> +
> + ipcc->power_notify_irq = irq;
> +
> + return 0;
> +
> +err_free_channel:
> + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
> + ipcc->power_chan = NULL;
> + return ret;
> +}
> +
> +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ipcc->state_lock, flags);
> + if (!ipcc->shutting_down)
> + ipcc->resp_vq = resp_vq;
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> +}
> +
> +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ipcc->state_lock, flags);
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> +}
> +
> +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc)
> +{
> + struct device *dev = ipcc->client.dev;
> + unsigned long flags;
> +
> + mutex_lock(&ipcc->power_notify_lock);
> +
> + spin_lock_irqsave(&ipcc->state_lock, flags);
> + ipcc->shutting_down = true;
> + ipcc->resp_vq = NULL;
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> +
> + devm_free_irq(dev, ipcc->power_notify_irq, ipcc);
> + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
> + mutex_unlock(&ipcc->power_notify_lock);
> +}
> +
> +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc)
> +{
> + return enable_irq_wake(ipcc->power_notify_irq);
> +}
> +
> +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc)
> +{
> + disable_irq_wake(ipcc->power_notify_irq);
> +}
> +
> +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc)
> +{
> + unsigned long timeout;
> + int ret;
> +
> + mutex_lock(&ipcc->power_notify_lock);
> +
> + reinit_completion(&ipcc->power_notify_done);
> +
> + ret = mbox_send_message(ipcc->power_chan, NULL);
> + mbox_client_txdone(ipcc->power_chan, ret);
> + if (ret < 0) {
> + dev_err(ipcc->client.dev,
> + "IPCC TX: power notify failed: %d\n", ret);
> + goto out_unlock;
> + }
> +
> + timeout = wait_for_completion_timeout(&ipcc->power_notify_done,
> + msecs_to_jiffies(DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS));
> + if (!timeout) {
> + dev_err(ipcc->client.dev,
> + "IPCC power notify acknowledgment timed out\n");
> + ret = -ETIMEDOUT;
> + } else {
> + ret = 0;
> + }
> +
> +out_unlock:
> + mutex_unlock(&ipcc->power_notify_lock);
> + return ret;
> +}
> diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.h b/drivers/virtio/virtio_qcom_dcp_ipcc.h
> new file mode 100644
> index 000000000000..f855fe8adec1
> --- /dev/null
> +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.h
> @@ -0,0 +1,41 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> + *
> + * IPCC power-notify mailbox interface for DCP firmware.
> + *
> + */
> +
> +#ifndef __VIRTIO_QCOM_DCP_IPCC_H__
> +#define __VIRTIO_QCOM_DCP_IPCC_H__
> +
> +#include <linux/completion.h>
> +#include <linux/mailbox_client.h>
> +#include <linux/mutex.h>
> +#include <linux/spinlock.h>
> +
> +struct device;
> +struct virtqueue;
> +
> +struct dcp_ipcc {
> + struct mbox_client client;
> + struct mbox_chan *power_chan;
> + struct virtqueue *resp_vq;
> + struct completion power_notify_done;
> + /* Serializes concurrent power-notify transactions. */
> + struct mutex power_notify_lock;
> + /* Protects callback state and response queue access. */
> + spinlock_t state_lock;
> + bool shutting_down;
> + int power_notify_irq;
> +};
> +
> +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index);
> +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq);
> +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc);
> +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc);
> +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc);
> +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc);
> +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc);
> +
> +#endif /* __VIRTIO_QCOM_DCP_IPCC_H__ */
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/3] dt-bindings: virtio: Add Qualcomm DCP transport
2026-11-26 6:23 ` [PATCH 1/3] dt-bindings: virtio: Add Qualcomm DCP transport Jayant Shekhar
@ 2026-11-26 6:36 ` sashiko-bot
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-26 6:36 UTC (permalink / raw)
To: Jayant Shekhar
Cc: virtualization, devicetree, robh, conor+dt, Michael S. Tsirkin,
Eugenio Perez
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] dt-bindings: virtio: missing referenced qcom,dcp.yaml schema
- [Medium] dt-bindings: virtio: invalid per-item uint32 ref in
iommu-ranges
- [Low] dt-bindings: virtio: use per-entry items list for interrupts
- [Low] dt-bindings: virtio: DTS example fails dt-check-style strict
checks
--
commit 32acdab74d03f0d1136a352cb6b5c3095b26176f
Author: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
dt-bindings: virtio: Add Qualcomm DCP transport
This commit adds a Device Tree binding schema for the Qualcomm DCP VirtIO
transport wrapper.
> diff --git a/Documentation/devicetree/bindings/virtio/qcom,dcp-virtio.yaml b/Documentation/devicetree/bindings/virtio/qcom,dcp-virtio.yaml
> new file mode 100644
> index 0000000000000..46b0e53468be0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/virtio/qcom,dcp-virtio.yaml
> @@ -0,0 +1,147 @@
[ ... ]
> + interrupts-extended:
> + minItems: 2
> + maxItems: 2
> + description: The VirtIO-MMIO and DCP power-notify interrupts, in that order.
[Severity: Low]
When a property has a fixed set of ordered entries, DT binding schemas
describe each entry in an items list instead of using minItems/maxItems
with a combined description. Defining interrupts (in properties and
required) with two per-entry description items also lets dtschema accept
interrupts-extended automatically in DTS nodes and examples.
> +
> + iommus:
> + maxItems: 1
> +
> + iommu-ranges:
> + $ref: /schemas/types.yaml#/definitions/uint32-array
> + description: |
> + The firmware-visible IOVA range, specified using the parent bus's
> + #address-cells followed by its #size-cells. The DCP transport uses two
> + cells for each, encoding a 64-bit IOVA base followed by a 64-bit range
> + size.
> + items:
> + - description: IOVA base, high cell
> + $ref: /schemas/types.yaml#/definitions/uint32
> + - description: IOVA base, low cell
> + $ref: /schemas/types.yaml#/definitions/uint32
> + - description: IOVA range size, high cell
> + $ref: /schemas/types.yaml#/definitions/uint32
> + - description: IOVA range size, low cell
> + $ref: /schemas/types.yaml#/definitions/uint32
[Severity: Medium]
Does make dt_binding_check fail on the per-item uint32 $ref entries under
iommu-ranges?
Because iommu-ranges already has $ref:
/schemas/types.yaml#/definitions/uint32-array, each entry under items
describes a single 32-bit cell validated against meta-schemas/cell.yaml,
which does not permit $ref (and /schemas/types.yaml#/definitions/uint32 is
a property-level type). Dropping the per-item $ref lines and keeping only
the description entries avoids the schema validation failure.
> +
> + dma-coherent: true
> +
> + mboxes:
> + maxItems: 1
> +
> + mbox-names:
> + const: dcp-power-tx
> +
> + display-subsystem:
> + $ref: ../display/msm/qcom,dcp.yaml#
[Severity: Medium]
Does make dt_binding_check fail to resolve ../display/msm/qcom,dcp.yaml#?
Documentation/devicetree/bindings/display/msm/qcom,dcp.yaml is not present
in the tree, so validating this schema and the display-subsystem child
node in the example fails with an unresolvable reference error. The
qcom,dcp.yaml schema needs to be present before this binding (and
referenced as /schemas/display/msm/qcom,dcp.yaml#).
[ ... ]
> + / {
> + compatible = "qcom,hawi-mtp", "qcom,hawi";
> + model = "Qualcomm Technologies, Inc. Hawi MTP";
> + #address-cells = <2>;
> + #size-cells = <2>;
[ ... ]
> + port@1 {
> + reg = <1>;
> + dcp_intf1_out: endpoint {
> + remote-endpoint = <&panel_dcp_in>;
> + };
> + };
[Severity: Low]
In the example, scripts/dtc/dt-check-style --mode=strict reports two style
warnings: in a root node model should precede compatible (or a simple soc
bus node can be used instead of /), and in port@1 a blank line is needed
between reg = <1>; and the dcp_intf1_out: endpoint child node.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-jshekhar-qcom-virtio-dcp-v1-0-7b49bda74916@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper
2026-11-26 6:24 ` [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper Jayant Shekhar
2026-11-26 6:35 ` Michael S. Tsirkin
@ 2026-11-26 6:44 ` sashiko-bot
1 sibling, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-26 6:44 UTC (permalink / raw)
To: Jayant Shekhar
Cc: virtualization, devicetree, robh, conor+dt, Michael S. Tsirkin,
Eugenio Perez
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] virtio: dcp_ipcc_handle_rx() conflates power ACK and resp_vq
IRQs
- [Medium] virtio: unsafe restore in dcp_virtio_transport_suspend()
error path
- [Medium] virtio: concurrent vring_interrupt() on resp_vq from two IRQ
lines
- [Medium] virtio: missing synchronize_irq() in dcp_ipcc_synchronize()
- [Low] virtio: duplicated MMIO init in dcp_virtio_init_device()
--
commit 857816350f7692694cd906a59f8f5d13188d9138
Author: Jayant Shekhar <jayant.shekhar@oss.qualcomm.com>
virtio: Add Qualcomm VirtIO transport wrapper
This commit adds a Qualcomm DCP VirtIO transport driver that reuses
virtio_mmio_config_ops and integrates an IPCC mailbox client to send power
notifications and forward response virtqueue interrupts.
> diff --git a/drivers/virtio/virtio_qcom_dcp.c b/drivers/virtio/virtio_qcom_dcp.c
> new file mode 100644
> index 0000000000000..a5443f2dbc4b0
> --- /dev/null
> +++ b/drivers/virtio/virtio_qcom_dcp.c
> @@ -0,0 +1,273 @@
[ ... ]
> +static int dcp_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
> + struct virtqueue *vqs[],
> + struct virtqueue_info vqs_info[],
> + struct irq_affinity *desc)
> +{
> + struct virtio_mmio_device *mmio =
> + container_of(vdev, struct virtio_mmio_device, vdev);
> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> + unsigned int i;
> + int ret;
> +
> + ret = virtio_mmio_config_ops.find_vqs(vdev, nvqs, vqs, vqs_info, desc);
> + if (ret)
> + return ret;
> +
> + for (i = 0; i < nvqs; i++) {
> + if (vqs[i] && vqs_info[i].name && !strcmp(vqs_info[i].name, "resp")) {
> + dcp_ipcc_set_resp_vq(&transport->ipcc, vqs[i]);
> + break;
> + }
> + }
> +
> + return 0;
> +}
[Severity: Medium]
Can vm_interrupt() and dcp_ipcc_handle_rx() run vring_interrupt() on
resp_vq concurrently across two IRQ lines?
virtio_mmio_config_ops.find_vqs() registers vm_interrupt() on IRQ 0 and
keeps every created virtqueue, including "resp", on vdev->vqs. dcp_virtio_find_vqs()
then also assigns that queue to transport->ipcc.resp_vq, which is serviced
on IRQ 1 by dcp_ipcc_power_notify_irq():
CPU0 (IRQ 0) CPU1 (IRQ 1)
vm_interrupt() dcp_ipcc_power_notify_irq()
virtio_device_for_each_vq() dcp_ipcc_handle_rx()
vring_interrupt(irq, vq) spin_lock_irqsave(&ipcc->state_lock)
vq->vq.callback(&vq->vq) vring_interrupt(0, ipcc->resp_vq)
vq->vq.callback(&vq->vq)
<-- concurrent callback execution
vring_interrupt() has no internal lock, so if both interrupts fire at the
same time while a used buffer is pending, resp_vq->callback() runs on two
CPUs simultaneously.
[ ... ]
> +static int dcp_virtio_init_device(struct dcp_virtio_transport *transport,
> + struct platform_device *pdev)
> +{
> + struct virtio_mmio_device *mmio = &transport->mmio;
> + unsigned long magic;
> + int ret;
> +
> + mmio->vdev.dev.parent = &pdev->dev;
> + mmio->vdev.config = &transport->config_ops;
> + mmio->pdev = pdev;
> +
> + mmio->base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(mmio->base))
> + return PTR_ERR(mmio->base);
> +
> + magic = readl(mmio->base + VIRTIO_MMIO_MAGIC_VALUE);
> + if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
> + dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
> + return -ENODEV;
> + }
> +
> + mmio->version = readl(mmio->base + VIRTIO_MMIO_VERSION);
> + if (mmio->version < 1 || mmio->version > 3) {
> + dev_err(&pdev->dev, "Version %ld not supported!\n", mmio->version);
> + return -ENXIO;
> + }
> +
> + mmio->vdev.id.device = readl(mmio->base + VIRTIO_MMIO_DEVICE_ID);
> + if (!mmio->vdev.id.device)
> + return -ENODEV;
> +
> + mmio->vdev.id.vendor = readl(mmio->base + VIRTIO_MMIO_VENDOR_ID);
> +
> + if (mmio->version == 1) {
> + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
> + ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
> + if (!ret)
> + dma_set_coherent_mask(&pdev->dev,
> + DMA_BIT_MASK(32 + PAGE_SHIFT));
> + } else {
> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
> + }
> + if (ret)
> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> + if (ret)
> + dev_warn(&pdev->dev,
> + "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
> +
> + return 0;
> +}
[Severity: Low]
This isn't a bug, but dcp_virtio_init_device() duplicates the MMIO register
validation and DMA mask setup from virtio_mmio_probe() in
drivers/virtio/virtio_mmio.c. Since this patch already introduces
drivers/virtio/virtio_mmio.h to share struct virtio_mmio_device and
virtio_mmio_config_ops, could this initialization be factored into a shared
helper in virtio_mmio.c?
Also, the commit message says the transport implements MMIO configuration
access, feature negotiation, and reset, whereas it reuses
virtio_mmio_config_ops for those operations.
[ ... ]
> +#ifdef CONFIG_PM_SLEEP
> +static int dcp_virtio_transport_suspend(struct device *dev)
> +{
> + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = virtio_device_freeze(&transport->mmio.vdev);
> + if (ret)
> + return ret;
> +
> + ret = dcp_ipcc_enable_irq_wake(&transport->ipcc);
> + if (ret)
> + goto err_restore;
> +
> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
> + if (ret) {
> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
> + goto err_restore;
> + }
> +
> + return 0;
> +
> +err_restore:
> + virtio_device_restore(&transport->mmio.vdev);
> + return ret;
> +}
[Severity: Medium]
Is it safe for err_restore to call virtio_device_restore() directly after
dcp_ipcc_send_power_notify() fails?
If dcp_ipcc_send_power_notify() times out after mbox_send_message() has
already sent the sleep notification, DCP may already be powering down or
inaccessible when virtio_device_restore() accesses mmio->base to reset the
device and recreate virtqueues. In addition, unlike
dcp_virtio_transport_resume(), err_restore does not write PAGE_SIZE to
VIRTIO_MMIO_GUEST_PAGE_SIZE when mmio->version == 1 before calling
virtio_device_restore().
> diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.c b/drivers/virtio/virtio_qcom_dcp_ipcc.c
> new file mode 100644
> index 0000000000000..1d83bcc69d5cf
> --- /dev/null
> +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.c
> @@ -0,0 +1,193 @@
[ ... ]
> +static void dcp_ipcc_handle_rx(struct dcp_ipcc *ipcc)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ipcc->state_lock, flags);
> + if (ipcc->shutting_down) {
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> + return;
> + }
> +
> + complete(&ipcc->power_notify_done);
> + if (ipcc->resp_vq)
> + vring_interrupt(0, ipcc->resp_vq);
> +
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> +}
[Severity: Medium]
Does dcp_ipcc_handle_rx() conflate power-notification acknowledgments with
response virtqueue interrupts during suspend and resume?
ipcc->resp_vq is only cleared in dcp_virtio_del_vqs() and
dcp_ipcc_deinit(). If the bound VirtIO driver does not call del_vqs() in
its freeze callback (for example, virtio_rtc keeps its virtqueues across
freeze and deletes them in restore), ipcc->resp_vq remains non-NULL while
the device is frozen. When DCP acknowledges dcp_ipcc_send_power_notify()
during dcp_virtio_transport_suspend() (after virtio_device_freeze()) or
during dcp_virtio_transport_resume() (before virtio_device_restore()),
dcp_ipcc_handle_rx() invokes vring_interrupt(0, ipcc->resp_vq) on the
frozen device.
Conversely, because dcp_ipcc_send_power_notify() calls
reinit_completion(&ipcc->power_notify_done) while ipcc->power_notify_irq is
also used for response queue notifications, an in-flight response queue
interrupt arriving after reinit_completion() completes power_notify_done
and causes dcp_ipcc_send_power_notify() to return before DCP has
acknowledged the power transition.
[ ... ]
> +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ipcc->state_lock, flags);
> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> +}
[Severity: Medium]
Should dcp_ipcc_synchronize() call synchronize_irq(ipcc->power_notify_irq)
instead of only cycling ipcc->state_lock?
When virtio_reset_device() calls virtio_synchronize_cbs() ->
dcp_virtio_synchronize_cbs(), ipcc->shutting_down is still false and
ipcc->resp_vq is still set until del_vqs() is called later. If
power_notify_irq has fired on another CPU (or woken its IRQ thread under
threadirqs or PREEMPT_RT) but has not yet acquired ipcc->state_lock, cycling
the lock returns immediately and the handler then enters
dcp_ipcc_handle_rx() and calls vring_interrupt(0, ipcc->resp_vq) after
virtio_reset_device() has returned:
CPU0 CPU1 (<hardirq> / IRQ thread)
virtio_reset_device()
dev->config->reset(dev)
dcp_ipcc_power_notify_irq()
dcp_ipcc_handle_rx()
virtio_synchronize_cbs()
dcp_virtio_synchronize_cbs()
dcp_ipcc_synchronize()
spin_lock_irqsave(&ipcc->state_lock)
spin_unlock_irqrestore(&ipcc->state_lock)
spin_lock_irqsave(&ipcc->state_lock)
vring_interrupt(0, ipcc->resp_vq)
<-- callback runs after reset
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-jshekhar-qcom-virtio-dcp-v1-0-7b49bda74916@oss.qualcomm.com?part=3
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper
2026-11-26 6:35 ` Michael S. Tsirkin
@ 2026-11-26 10:03 ` Jayant Shekhar
2026-11-26 11:41 ` Michael S. Tsirkin
0 siblings, 1 reply; 12+ messages in thread
From: Jayant Shekhar @ 2026-11-26 10:03 UTC (permalink / raw)
To: Michael S. Tsirkin, Jayant Shekhar
Cc: Jason Wang, Eugenio Pérez, Xuan Zhuo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov, Flemin Jose,
linux-arm-msm, virtualization, devicetree, linux-kernel
On 26-11-2026 12:05, Michael S. Tsirkin wrote:
> On Thu, Nov 26, 2026 at 11:54:01AM +0530, Jayant Shekhar wrote:
>> Add the Qualcomm-specific VirtIO transport required by DCP firmware.
>>
>> The transport sends an IPCC power notification before accessing the
>> VirtIO MMIO registers, then registers a VirtIO device directly.
>>
>> Implement MMIO configuration access, feature negotiation, virtqueue
>> setup, interrupt handling, reset, DMA setup, and suspend/resume
>> sequencing in the transport. Keep power-management ordering in the
>> transport so VirtIO queues are quiesced before DCP power changes.
>>
>> Assisted-by: LLM
>> Signed-off-by: Jayant Shekhar<jayant.shekhar@oss.qualcomm.com>
> So VIRTIO_ID_VENDOR you defined in patch 2 is completely unused?
> Why did you bother?
>
I have split the DCP driver series into two:
1) Adds Add the Qualcomm-specific VirtIO transport (this one)
2) Add Qualcomm DCP display support (separate series)
https://lore.kernel.org/all/20261126-jshekhar-v3-dcp-v3-0-f1e9d7505039@oss.qualcomm.com/
Below patch uses the VIRTIO_ID_VENDOR
https://lore.kernel.org/all/20261126-jshekhar-v3-dcp-v3-18-f1e9d7505039@oss.qualcomm.com/
>> ---
>> drivers/virtio/Kconfig | 11 ++
>> drivers/virtio/Makefile | 2 +
>> drivers/virtio/virtio_mmio.c | 17 +--
>> drivers/virtio/virtio_mmio.h | 21 +++
>> drivers/virtio/virtio_qcom_dcp.c | 273 ++++++++++++++++++++++++++++++++++
>> drivers/virtio/virtio_qcom_dcp_ipcc.c | 193 ++++++++++++++++++++++++
>> drivers/virtio/virtio_qcom_dcp_ipcc.h | 41 +++++
>> 7 files changed, 544 insertions(+), 14 deletions(-)
> Oh great a pile of vendor specific code in virtio, with the vendor
> explicitly saying on the virtio ML that no specs will be published,
> ever. And it seems to be your assumption that I'll be signing up to
> maintain this?
>
>
The transport uses the standard VirtIO-MMIO register layout and
virtqueue operations; it does not define a new MMIO protocol. IPCC is a
Qualcomm platform sideband needed to wake DCP before MMIO access and to
signal response-queue notifications.
I agree that the maintenance ownership is separate concern that need to
be addressed.
>> diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
>> index ce5bc0d9ea28..838ae5671c28 100644
>> --- a/drivers/virtio/Kconfig
>> +++ b/drivers/virtio/Kconfig
>> @@ -160,6 +160,17 @@ config VIRTIO_MMIO
>>
>> If unsure, say N.
>>
>> +config VIRTIO_QCOM_DCP
>> + tristate "Qualcomm DCP VirtIO transport"
>> + depends on VIRTIO_MMIO
>> + depends on QCOM_IPCC
>> + depends on OF
>> + help
>> + This driver provides the Qualcomm DCP-specific platform transport for
>> + QPSFI VirtIO devices. It reuses the standard VirtIO-MMIO configuration
>> + and virtqueue support, and handles the IPCC power-notification channel
>> + used to wake DCP and forward response notifications.
>> +
>> config VIRTIO_MMIO_CMDLINE_DEVICES
>> bool "Memory mapped virtio devices parameter parsing"
>> depends on VIRTIO_MMIO
>> diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
>> index eefcfe90d6b8..c922fb5bff16 100644
>> --- a/drivers/virtio/Makefile
>> +++ b/drivers/virtio/Makefile
>> @@ -3,6 +3,8 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
>> obj-$(CONFIG_VIRTIO_ANCHOR) += virtio_anchor.o
>> obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
>> obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
>> +obj-$(CONFIG_VIRTIO_QCOM_DCP) += qcom_dcp_virtio.o
>> +qcom_dcp_virtio-y := virtio_qcom_dcp.o virtio_qcom_dcp_ipcc.o
>> obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
>> obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
>> virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
>> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
>> index c403a025006e..348809b9ebfe 100644
>> --- a/drivers/virtio/virtio_mmio.c
>> +++ b/drivers/virtio/virtio_mmio.c
>> @@ -71,7 +71,7 @@
>> #include <uapi/linux/virtio_mmio.h>
>> #include <linux/virtio_ring.h>
>>
>> -
>> +#include "virtio_mmio.h"
>>
>> /* The alignment to use between consumer and producer parts of vring.
>> * Currently hardcoded to the page size. */
>> @@ -81,18 +81,6 @@
>>
>> #define to_virtio_mmio_device(_plat_dev) \
>> container_of(_plat_dev, struct virtio_mmio_device, vdev)
>> -
>> -struct virtio_mmio_device {
>> - struct virtio_device vdev;
>> - struct platform_device *pdev;
>> -
>> - void __iomem *base;
>> - unsigned long version;
>> -
>> - /* True if enable_irq_wake() succeeded for the shared IRQ. */
>> - bool wake_irq_enabled;
>> -};
>> -
>> /* Configuration interface */
>>
>> static u64 vm_get_features(struct virtio_device *vdev)
>> @@ -536,7 +524,7 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
>> return true;
>> }
>>
>> -static const struct virtio_config_ops virtio_mmio_config_ops = {
>> +const struct virtio_config_ops virtio_mmio_config_ops = {
>> .get = vm_get,
>> .set = vm_set,
>> .generation = vm_generation,
>> @@ -551,6 +539,7 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
>> .get_shm_region = vm_get_shm_region,
>> .synchronize_cbs = vm_synchronize_cbs,
>> };
>> +EXPORT_SYMBOL_GPL(virtio_mmio_config_ops);
>>
>> #ifdef CONFIG_PM_SLEEP
>> static int virtio_mmio_freeze(struct device *dev)
>> diff --git a/drivers/virtio/virtio_mmio.h b/drivers/virtio/virtio_mmio.h
>> new file mode 100644
>> index 000000000000..a80904ed73e2
>> --- /dev/null
>> +++ b/drivers/virtio/virtio_mmio.h
>> @@ -0,0 +1,21 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +#ifndef _DRIVERS_VIRTIO_VIRTIO_MMIO_H
>> +#define _DRIVERS_VIRTIO_VIRTIO_MMIO_H
>> +
>> +#include <linux/io.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/virtio.h>
>> +#include <linux/virtio_config.h>
>> +
>> +struct virtio_mmio_device {
>> + struct virtio_device vdev;
>> + struct platform_device *pdev;
>> + void __iomem *base;
>> + unsigned long version;
>> + /* True if enable_irq_wake() succeeded for the shared IRQ. */
>> + bool wake_irq_enabled;
>> +};
>> +
>> +extern const struct virtio_config_ops virtio_mmio_config_ops;
>> +
>> +#endif /* _DRIVERS_VIRTIO_VIRTIO_MMIO_H */
>> diff --git a/drivers/virtio/virtio_qcom_dcp.c b/drivers/virtio/virtio_qcom_dcp.c
>> new file mode 100644
>> index 000000000000..a5443f2dbc4b
>> --- /dev/null
>> +++ b/drivers/virtio/virtio_qcom_dcp.c
>> @@ -0,0 +1,273 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
>> + *
>> + * Qualcomm DCP VirtIO transport.
>> + */
>> +
>> +#include <linux/dma-mapping.h>
>> +#include <linux/io.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/pm.h>
>> +#include <linux/slab.h>
>> +#include <linux/string.h>
>> +#include <linux/virtio.h>
>> +#include <linux/virtio_config.h>
>> +#include <uapi/linux/virtio_mmio.h>
>> +
>> +#include "virtio_mmio.h"
>> +#include "virtio_qcom_dcp_ipcc.h"
>> +
>> +struct dcp_virtio_transport {
>> + struct virtio_mmio_device mmio;
>> + struct virtio_config_ops config_ops;
>> + struct dcp_ipcc ipcc;
>> +};
>> +
>> +static struct dcp_virtio_transport *
>> +to_dcp_virtio_transport(struct virtio_mmio_device *mmio)
>> +{
>> + return container_of(mmio, struct dcp_virtio_transport, mmio);
>> +}
>> +
>> +static void dcp_virtio_synchronize_cbs(struct virtio_device *vdev)
>> +{
>> + struct virtio_mmio_device *mmio =
>> + container_of(vdev, struct virtio_mmio_device, vdev);
>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>> +
>> + virtio_mmio_config_ops.synchronize_cbs(vdev);
>> + dcp_ipcc_synchronize(&transport->ipcc);
>> +}
>> +
>> +static int dcp_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
>> + struct virtqueue *vqs[],
>> + struct virtqueue_info vqs_info[],
>> + struct irq_affinity *desc)
>> +{
>> + struct virtio_mmio_device *mmio =
>> + container_of(vdev, struct virtio_mmio_device, vdev);
>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>> + unsigned int i;
>> + int ret;
>> +
>> + ret = virtio_mmio_config_ops.find_vqs(vdev, nvqs, vqs, vqs_info, desc);
>> + if (ret)
>> + return ret;
>> +
>> + for (i = 0; i < nvqs; i++) {
>> + if (vqs[i] && vqs_info[i].name && !strcmp(vqs_info[i].name, "resp")) {
>> + dcp_ipcc_set_resp_vq(&transport->ipcc, vqs[i]);
>> + break;
>> + }
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static void dcp_virtio_del_vqs(struct virtio_device *vdev)
>> +{
>> + struct virtio_mmio_device *mmio =
>> + container_of(vdev, struct virtio_mmio_device, vdev);
>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>> +
>> + dcp_ipcc_set_resp_vq(&transport->ipcc, NULL);
>> + virtio_mmio_config_ops.del_vqs(vdev);
>> +}
>> +
>> +static void dcp_virtio_release_dev(struct device *dev)
>> +{
>> + struct virtio_device *vdev = container_of(dev, struct virtio_device, dev);
>> + struct virtio_mmio_device *mmio =
>> + container_of(vdev, struct virtio_mmio_device, vdev);
>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>> +
>> + kfree(transport);
>> +}
>> +
>> +static int dcp_virtio_init_device(struct dcp_virtio_transport *transport,
>> + struct platform_device *pdev)
>> +{
>> + struct virtio_mmio_device *mmio = &transport->mmio;
>> + unsigned long magic;
>> + int ret;
>> +
>> + mmio->vdev.dev.parent = &pdev->dev;
>> + mmio->vdev.config = &transport->config_ops;
>> + mmio->pdev = pdev;
>> +
>> + mmio->base = devm_platform_ioremap_resource(pdev, 0);
>> + if (IS_ERR(mmio->base))
>> + return PTR_ERR(mmio->base);
>> +
>> + magic = readl(mmio->base + VIRTIO_MMIO_MAGIC_VALUE);
>> + if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
>> + dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
>> + return -ENODEV;
>> + }
>> +
>> + mmio->version = readl(mmio->base + VIRTIO_MMIO_VERSION);
>> + if (mmio->version < 1 || mmio->version > 3) {
>> + dev_err(&pdev->dev, "Version %ld not supported!\n", mmio->version);
>> + return -ENXIO;
>> + }
>> +
>> + mmio->vdev.id.device = readl(mmio->base + VIRTIO_MMIO_DEVICE_ID);
>> + if (!mmio->vdev.id.device)
>> + return -ENODEV;
>> +
>> + mmio->vdev.id.vendor = readl(mmio->base + VIRTIO_MMIO_VENDOR_ID);
>> +
>> + if (mmio->version == 1) {
>> + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
>> + ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
>> + if (!ret)
>> + dma_set_coherent_mask(&pdev->dev,
>> + DMA_BIT_MASK(32 + PAGE_SHIFT));
>> + } else {
>> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
>> + }
>> + if (ret)
>> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
>> + if (ret)
>> + dev_warn(&pdev->dev,
>> + "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
>> +
>> + return 0;
>> +}
>> +
>> +static int dcp_virtio_transport_probe(struct platform_device *pdev)
>> +{
>> + struct dcp_virtio_transport *transport;
>> + struct virtio_mmio_device *mmio;
>> + int ret;
>> +
>> + transport = kzalloc_obj(*transport);
>> + if (!transport)
>> + return -ENOMEM;
>> +
>> + mmio = &transport->mmio;
>> + mmio->vdev.dev.release = dcp_virtio_release_dev;
>> + transport->config_ops = virtio_mmio_config_ops;
>> + transport->config_ops.find_vqs = dcp_virtio_find_vqs;
>> + transport->config_ops.del_vqs = dcp_virtio_del_vqs;
>> + transport->config_ops.synchronize_cbs = dcp_virtio_synchronize_cbs;
>> +
>> + ret = dcp_ipcc_init(&transport->ipcc, &pdev->dev, 1);
>> + if (ret) {
>> + kfree(transport);
>> + return ret;
>> + }
>> +
>> + /* Wake DCP before the first access to the VirtIO MMIO registers. */
>> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
>> + if (ret)
>> + goto err_ipcc;
>> +
>> + ret = dcp_virtio_init_device(transport, pdev);
>> + if (ret)
>> + goto err_ipcc;
>> +
>> + platform_set_drvdata(pdev, transport);
>> +
>> + ret = register_virtio_device(&mmio->vdev);
>> + if (ret) {
>> + platform_set_drvdata(pdev, NULL);
>> + dcp_ipcc_deinit(&transport->ipcc);
>> + put_device(&mmio->vdev.dev);
>> + return ret;
>> + }
>> +
>> + return 0;
>> +
>> +err_ipcc:
>> + dcp_ipcc_deinit(&transport->ipcc);
>> + kfree(transport);
>> + return ret;
>> +}
>> +
>> +static void dcp_virtio_transport_remove(struct platform_device *pdev)
>> +{
>> + struct dcp_virtio_transport *transport = platform_get_drvdata(pdev);
>> +
>> + /* Keep the embedded virtio_device alive until IPCC teardown is complete. */
>> + get_device(&transport->mmio.vdev.dev);
>> + unregister_virtio_device(&transport->mmio.vdev);
>> + platform_set_drvdata(pdev, NULL);
>> + dcp_ipcc_deinit(&transport->ipcc);
>> + put_device(&transport->mmio.vdev.dev);
>> +}
>> +
>> +#ifdef CONFIG_PM_SLEEP
>> +static int dcp_virtio_transport_suspend(struct device *dev)
>> +{
>> + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
>> + int ret;
>> +
>> + ret = virtio_device_freeze(&transport->mmio.vdev);
>> + if (ret)
>> + return ret;
>> +
>> + ret = dcp_ipcc_enable_irq_wake(&transport->ipcc);
>> + if (ret)
>> + goto err_restore;
>> +
>> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
>> + if (ret) {
>> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
>> + goto err_restore;
>> + }
>> +
>> + return 0;
>> +
>> +err_restore:
>> + virtio_device_restore(&transport->mmio.vdev);
>> + return ret;
>> +}
>> +
>> +static int dcp_virtio_transport_resume(struct device *dev)
>> +{
>> + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
>> + struct virtio_mmio_device *mmio = &transport->mmio;
>> + int ret;
>> +
>> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
>> + if (ret) {
>> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
>> + return ret;
>> + }
>> +
>> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
>> + if (mmio->version == 1)
>> + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
>> +
>> + return virtio_device_restore(&mmio->vdev);
>> +}
>> +
>> +#endif
>> +static const struct dev_pm_ops dcp_virtio_transport_pm_ops = {
>> + SET_SYSTEM_SLEEP_PM_OPS(dcp_virtio_transport_suspend,
>> + dcp_virtio_transport_resume)
>> +};
>> +
>> +static const struct of_device_id dcp_virtio_transport_of_match[] = {
>> + { .compatible = "qcom,dcp-virtio" },
>> + { }
>> +};
>> +MODULE_DEVICE_TABLE(of, dcp_virtio_transport_of_match);
>> +
>> +static struct platform_driver dcp_virtio_transport_driver = {
>> + .probe = dcp_virtio_transport_probe,
>> + .remove = dcp_virtio_transport_remove,
>> + .driver = {
>> + .name = "qcom-dcp-virtio",
>> + .of_match_table = dcp_virtio_transport_of_match,
>> + .pm = pm_sleep_ptr(&dcp_virtio_transport_pm_ops),
>> + },
>> +};
>> +module_platform_driver(dcp_virtio_transport_driver);
>> +
>> +MODULE_DESCRIPTION("Qualcomm DCP VirtIO transport");
>> +MODULE_LICENSE("GPL");
>> diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.c b/drivers/virtio/virtio_qcom_dcp_ipcc.c
>> new file mode 100644
>> index 000000000000..1d83bcc69d5c
>> --- /dev/null
>> +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.c
>> @@ -0,0 +1,193 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
>> + *
>> + * DCP IPCC power-notify mailbox client. It wakes DCP during power
>> + * transitions and routes firmware notifications to the VirtIO response
>> + * queue.
>> + */
>> +
>> +#include <linux/device.h>
>> +#include <linux/err.h>
>> +#include <linux/jiffies.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/mailbox_client.h>
>> +#include <linux/mutex.h>
>> +#include <linux/of_irq.h>
>> +#include <linux/string.h>
>> +#include <linux/virtio.h>
>> +#include <linux/virtio_ring.h>
>> +
>> +#include "virtio_qcom_dcp_ipcc.h"
>> +
>> +#define DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS 10000
>> +
>> +static void dcp_ipcc_handle_rx(struct dcp_ipcc *ipcc)
>> +{
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>> + if (ipcc->shutting_down) {
>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>> + return;
>> + }
>> +
>> + complete(&ipcc->power_notify_done);
>> + if (ipcc->resp_vq)
>> + vring_interrupt(0, ipcc->resp_vq);
>> +
>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>> +}
>> +
>> +static irqreturn_t dcp_ipcc_power_notify_irq(int irq, void *data)
>> +{
>> + struct dcp_ipcc *ipcc = data;
>> +
>> + dcp_ipcc_handle_rx(ipcc);
>> +
>> + return IRQ_HANDLED;
>> +}
>> +
>> +static void dcp_ipcc_rx_callback(struct mbox_client *cl, void *data)
>> +{
>> + struct dcp_ipcc *ipcc = container_of(cl, struct dcp_ipcc, client);
>> +
>> + dcp_ipcc_handle_rx(ipcc);
>> +}
>> +
>> +static void dcp_ipcc_free_channel(void *data)
>> +{
>> + mbox_free_channel(data);
>> +}
>> +
>> +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index)
>> +{
>> + int irq, ret;
>> +
>> + memset(ipcc, 0, sizeof(*ipcc));
>> + init_completion(&ipcc->power_notify_done);
>> + mutex_init(&ipcc->power_notify_lock);
>> + spin_lock_init(&ipcc->state_lock);
>> +
>> + ipcc->client.dev = dev;
>> + ipcc->client.tx_block = false;
>> + ipcc->client.tx_tout = 0;
>> + ipcc->client.knows_txdone = true;
>> + ipcc->client.rx_callback = dcp_ipcc_rx_callback;
>> +
>> + ipcc->power_chan = mbox_request_channel(&ipcc->client, 0);
>> + if (IS_ERR(ipcc->power_chan)) {
>> + ret = PTR_ERR(ipcc->power_chan);
>> + if (ret != -EPROBE_DEFER)
>> + dev_err(dev, "IPCC: failed to get DCP power channel: %d\n", ret);
>> + return ret;
>> + }
>> +
>> + ret = devm_add_action_or_reset(dev, dcp_ipcc_free_channel,
>> + ipcc->power_chan);
>> + if (ret) {
>> + ipcc->power_chan = NULL;
>> + return ret;
>> + }
>> +
>> + irq = of_irq_get(dev->of_node, irq_index);
>> + if (irq <= 0) {
>> + ret = dev_err_probe(dev, irq ? irq : -EINVAL,
>> + "failed to get required power notify IRQ\n");
>> + goto err_free_channel;
>> + }
>> +
>> + ret = devm_request_irq(dev, irq, dcp_ipcc_power_notify_irq, 0,
>> + "dcp-power-notify", ipcc);
>> + if (ret) {
>> + ret = dev_err_probe(dev, ret,
>> + "failed to request power notify IRQ %d\n", irq);
>> + goto err_free_channel;
>> + }
>> +
>> + ipcc->power_notify_irq = irq;
>> +
>> + return 0;
>> +
>> +err_free_channel:
>> + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
>> + ipcc->power_chan = NULL;
>> + return ret;
>> +}
>> +
>> +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq)
>> +{
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>> + if (!ipcc->shutting_down)
>> + ipcc->resp_vq = resp_vq;
>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>> +}
>> +
>> +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc)
>> +{
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>> +}
>> +
>> +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc)
>> +{
>> + struct device *dev = ipcc->client.dev;
>> + unsigned long flags;
>> +
>> + mutex_lock(&ipcc->power_notify_lock);
>> +
>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>> + ipcc->shutting_down = true;
>> + ipcc->resp_vq = NULL;
>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>> +
>> + devm_free_irq(dev, ipcc->power_notify_irq, ipcc);
>> + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
>> + mutex_unlock(&ipcc->power_notify_lock);
>> +}
>> +
>> +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc)
>> +{
>> + return enable_irq_wake(ipcc->power_notify_irq);
>> +}
>> +
>> +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc)
>> +{
>> + disable_irq_wake(ipcc->power_notify_irq);
>> +}
>> +
>> +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc)
>> +{
>> + unsigned long timeout;
>> + int ret;
>> +
>> + mutex_lock(&ipcc->power_notify_lock);
>> +
>> + reinit_completion(&ipcc->power_notify_done);
>> +
>> + ret = mbox_send_message(ipcc->power_chan, NULL);
>> + mbox_client_txdone(ipcc->power_chan, ret);
>> + if (ret < 0) {
>> + dev_err(ipcc->client.dev,
>> + "IPCC TX: power notify failed: %d\n", ret);
>> + goto out_unlock;
>> + }
>> +
>> + timeout = wait_for_completion_timeout(&ipcc->power_notify_done,
>> + msecs_to_jiffies(DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS));
>> + if (!timeout) {
>> + dev_err(ipcc->client.dev,
>> + "IPCC power notify acknowledgment timed out\n");
>> + ret = -ETIMEDOUT;
>> + } else {
>> + ret = 0;
>> + }
>> +
>> +out_unlock:
>> + mutex_unlock(&ipcc->power_notify_lock);
>> + return ret;
>> +}
>> diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.h b/drivers/virtio/virtio_qcom_dcp_ipcc.h
>> new file mode 100644
>> index 000000000000..f855fe8adec1
>> --- /dev/null
>> +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.h
>> @@ -0,0 +1,41 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +/*
>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
>> + *
>> + * IPCC power-notify mailbox interface for DCP firmware.
>> + *
>> + */
>> +
>> +#ifndef __VIRTIO_QCOM_DCP_IPCC_H__
>> +#define __VIRTIO_QCOM_DCP_IPCC_H__
>> +
>> +#include <linux/completion.h>
>> +#include <linux/mailbox_client.h>
>> +#include <linux/mutex.h>
>> +#include <linux/spinlock.h>
>> +
>> +struct device;
>> +struct virtqueue;
>> +
>> +struct dcp_ipcc {
>> + struct mbox_client client;
>> + struct mbox_chan *power_chan;
>> + struct virtqueue *resp_vq;
>> + struct completion power_notify_done;
>> + /* Serializes concurrent power-notify transactions. */
>> + struct mutex power_notify_lock;
>> + /* Protects callback state and response queue access. */
>> + spinlock_t state_lock;
>> + bool shutting_down;
>> + int power_notify_irq;
>> +};
>> +
>> +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index);
>> +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq);
>> +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc);
>> +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc);
>> +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc);
>> +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc);
>> +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc);
>> +
>> +#endif /* __VIRTIO_QCOM_DCP_IPCC_H__ */
>>
>> --
>> 2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper
2026-11-26 10:03 ` Jayant Shekhar
@ 2026-11-26 11:41 ` Michael S. Tsirkin
2026-11-26 12:18 ` Jayant Shekhar
0 siblings, 1 reply; 12+ messages in thread
From: Michael S. Tsirkin @ 2026-11-26 11:41 UTC (permalink / raw)
To: Jayant Shekhar
Cc: Jason Wang, Eugenio Pérez, Xuan Zhuo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov, Flemin Jose,
linux-arm-msm, virtualization, devicetree, linux-kernel
On Thu, Nov 26, 2026 at 03:33:53PM +0530, Jayant Shekhar wrote:
>
> On 26-11-2026 12:05, Michael S. Tsirkin wrote:
> > On Thu, Nov 26, 2026 at 11:54:01AM +0530, Jayant Shekhar wrote:
> > > Add the Qualcomm-specific VirtIO transport required by DCP firmware.
> > >
> > > The transport sends an IPCC power notification before accessing the
> > > VirtIO MMIO registers, then registers a VirtIO device directly.
> > >
> > > Implement MMIO configuration access, feature negotiation, virtqueue
> > > setup, interrupt handling, reset, DMA setup, and suspend/resume
> > > sequencing in the transport. Keep power-management ordering in the
> > > transport so VirtIO queues are quiesced before DCP power changes.
> > >
> > > Assisted-by: LLM
> > > Signed-off-by: Jayant Shekhar<jayant.shekhar@oss.qualcomm.com>
> > So VIRTIO_ID_VENDOR you defined in patch 2 is completely unused?
> > Why did you bother?
> >
>
> I have split the DCP driver series into two:
>
> 1) Adds Add the Qualcomm-specific VirtIO transport (this one)
>
> 2) Add Qualcomm DCP display support (separate series)
>
> https://lore.kernel.org/all/20261126-jshekhar-v3-dcp-v3-0-f1e9d7505039@oss.qualcomm.com/
>
> Below patch uses the VIRTIO_ID_VENDOR
>
> https://lore.kernel.org/all/20261126-jshekhar-v3-dcp-v3-18-f1e9d7505039@oss.qualcomm.com/
so move this patch there?
And this, from that patch:
+static const struct virtio_device_id dcp_virtio_id_table[] = {
+ { VIRTIO_ID_VENDOR, VIRTIO_DEV_ANY_ID },
+ { 0 },
+};
+MODULE_DEVICE_TABLE(virtio, dcp_virtio_id_table);
is not going to fly. Fill in your vendor ID please.
>
> > > ---
> > > drivers/virtio/Kconfig | 11 ++
> > > drivers/virtio/Makefile | 2 +
> > > drivers/virtio/virtio_mmio.c | 17 +--
> > > drivers/virtio/virtio_mmio.h | 21 +++
> > > drivers/virtio/virtio_qcom_dcp.c | 273 ++++++++++++++++++++++++++++++++++
> > > drivers/virtio/virtio_qcom_dcp_ipcc.c | 193 ++++++++++++++++++++++++
> > > drivers/virtio/virtio_qcom_dcp_ipcc.h | 41 +++++
> > > 7 files changed, 544 insertions(+), 14 deletions(-)
> > Oh great a pile of vendor specific code in virtio, with the vendor
> > explicitly saying on the virtio ML that no specs will be published,
> > ever. And it seems to be your assumption that I'll be signing up to
> > maintain this?
> >
> >
> The transport uses the standard VirtIO-MMIO register layout and virtqueue
> operations; it does not define a new MMIO protocol. IPCC is a Qualcomm
> platform sideband needed to wake DCP before MMIO access and to signal
> response-queue notifications.
>
> I agree that the maintenance ownership is separate concern that need to be
> addressed.
>
>
> > > diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
> > > index ce5bc0d9ea28..838ae5671c28 100644
> > > --- a/drivers/virtio/Kconfig
> > > +++ b/drivers/virtio/Kconfig
> > > @@ -160,6 +160,17 @@ config VIRTIO_MMIO
> > > If unsure, say N.
> > > +config VIRTIO_QCOM_DCP
> > > + tristate "Qualcomm DCP VirtIO transport"
> > > + depends on VIRTIO_MMIO
> > > + depends on QCOM_IPCC
> > > + depends on OF
> > > + help
> > > + This driver provides the Qualcomm DCP-specific platform transport for
> > > + QPSFI VirtIO devices. It reuses the standard VirtIO-MMIO configuration
> > > + and virtqueue support, and handles the IPCC power-notification channel
> > > + used to wake DCP and forward response notifications.
> > > +
> > > config VIRTIO_MMIO_CMDLINE_DEVICES
> > > bool "Memory mapped virtio devices parameter parsing"
> > > depends on VIRTIO_MMIO
> > > diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
> > > index eefcfe90d6b8..c922fb5bff16 100644
> > > --- a/drivers/virtio/Makefile
> > > +++ b/drivers/virtio/Makefile
> > > @@ -3,6 +3,8 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
> > > obj-$(CONFIG_VIRTIO_ANCHOR) += virtio_anchor.o
> > > obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
> > > obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
> > > +obj-$(CONFIG_VIRTIO_QCOM_DCP) += qcom_dcp_virtio.o
> > > +qcom_dcp_virtio-y := virtio_qcom_dcp.o virtio_qcom_dcp_ipcc.o
> > > obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
> > > obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
> > > virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
> > > diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> > > index c403a025006e..348809b9ebfe 100644
> > > --- a/drivers/virtio/virtio_mmio.c
> > > +++ b/drivers/virtio/virtio_mmio.c
> > > @@ -71,7 +71,7 @@
> > > #include <uapi/linux/virtio_mmio.h>
> > > #include <linux/virtio_ring.h>
> > > -
> > > +#include "virtio_mmio.h"
> > > /* The alignment to use between consumer and producer parts of vring.
> > > * Currently hardcoded to the page size. */
> > > @@ -81,18 +81,6 @@
> > > #define to_virtio_mmio_device(_plat_dev) \
> > > container_of(_plat_dev, struct virtio_mmio_device, vdev)
> > > -
> > > -struct virtio_mmio_device {
> > > - struct virtio_device vdev;
> > > - struct platform_device *pdev;
> > > -
> > > - void __iomem *base;
> > > - unsigned long version;
> > > -
> > > - /* True if enable_irq_wake() succeeded for the shared IRQ. */
> > > - bool wake_irq_enabled;
> > > -};
> > > -
> > > /* Configuration interface */
> > > static u64 vm_get_features(struct virtio_device *vdev)
> > > @@ -536,7 +524,7 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
> > > return true;
> > > }
> > > -static const struct virtio_config_ops virtio_mmio_config_ops = {
> > > +const struct virtio_config_ops virtio_mmio_config_ops = {
> > > .get = vm_get,
> > > .set = vm_set,
> > > .generation = vm_generation,
> > > @@ -551,6 +539,7 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
> > > .get_shm_region = vm_get_shm_region,
> > > .synchronize_cbs = vm_synchronize_cbs,
> > > };
> > > +EXPORT_SYMBOL_GPL(virtio_mmio_config_ops);
> > > #ifdef CONFIG_PM_SLEEP
> > > static int virtio_mmio_freeze(struct device *dev)
> > > diff --git a/drivers/virtio/virtio_mmio.h b/drivers/virtio/virtio_mmio.h
> > > new file mode 100644
> > > index 000000000000..a80904ed73e2
> > > --- /dev/null
> > > +++ b/drivers/virtio/virtio_mmio.h
> > > @@ -0,0 +1,21 @@
> > > +/* SPDX-License-Identifier: GPL-2.0-only */
> > > +#ifndef _DRIVERS_VIRTIO_VIRTIO_MMIO_H
> > > +#define _DRIVERS_VIRTIO_VIRTIO_MMIO_H
> > > +
> > > +#include <linux/io.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/virtio.h>
> > > +#include <linux/virtio_config.h>
> > > +
> > > +struct virtio_mmio_device {
> > > + struct virtio_device vdev;
> > > + struct platform_device *pdev;
> > > + void __iomem *base;
> > > + unsigned long version;
> > > + /* True if enable_irq_wake() succeeded for the shared IRQ. */
> > > + bool wake_irq_enabled;
> > > +};
> > > +
> > > +extern const struct virtio_config_ops virtio_mmio_config_ops;
> > > +
> > > +#endif /* _DRIVERS_VIRTIO_VIRTIO_MMIO_H */
> > > diff --git a/drivers/virtio/virtio_qcom_dcp.c b/drivers/virtio/virtio_qcom_dcp.c
> > > new file mode 100644
> > > index 000000000000..a5443f2dbc4b
> > > --- /dev/null
> > > +++ b/drivers/virtio/virtio_qcom_dcp.c
> > > @@ -0,0 +1,273 @@
> > > +// SPDX-License-Identifier: GPL-2.0-only
> > > +/*
> > > + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> > > + *
> > > + * Qualcomm DCP VirtIO transport.
> > > + */
> > > +
> > > +#include <linux/dma-mapping.h>
> > > +#include <linux/io.h>
> > > +#include <linux/module.h>
> > > +#include <linux/of.h>
> > > +#include <linux/platform_device.h>
> > > +#include <linux/pm.h>
> > > +#include <linux/slab.h>
> > > +#include <linux/string.h>
> > > +#include <linux/virtio.h>
> > > +#include <linux/virtio_config.h>
> > > +#include <uapi/linux/virtio_mmio.h>
> > > +
> > > +#include "virtio_mmio.h"
> > > +#include "virtio_qcom_dcp_ipcc.h"
> > > +
> > > +struct dcp_virtio_transport {
> > > + struct virtio_mmio_device mmio;
> > > + struct virtio_config_ops config_ops;
> > > + struct dcp_ipcc ipcc;
> > > +};
> > > +
> > > +static struct dcp_virtio_transport *
> > > +to_dcp_virtio_transport(struct virtio_mmio_device *mmio)
> > > +{
> > > + return container_of(mmio, struct dcp_virtio_transport, mmio);
> > > +}
> > > +
> > > +static void dcp_virtio_synchronize_cbs(struct virtio_device *vdev)
> > > +{
> > > + struct virtio_mmio_device *mmio =
> > > + container_of(vdev, struct virtio_mmio_device, vdev);
> > > + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> > > +
> > > + virtio_mmio_config_ops.synchronize_cbs(vdev);
> > > + dcp_ipcc_synchronize(&transport->ipcc);
> > > +}
> > > +
> > > +static int dcp_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
> > > + struct virtqueue *vqs[],
> > > + struct virtqueue_info vqs_info[],
> > > + struct irq_affinity *desc)
> > > +{
> > > + struct virtio_mmio_device *mmio =
> > > + container_of(vdev, struct virtio_mmio_device, vdev);
> > > + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> > > + unsigned int i;
> > > + int ret;
> > > +
> > > + ret = virtio_mmio_config_ops.find_vqs(vdev, nvqs, vqs, vqs_info, desc);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + for (i = 0; i < nvqs; i++) {
> > > + if (vqs[i] && vqs_info[i].name && !strcmp(vqs_info[i].name, "resp")) {
> > > + dcp_ipcc_set_resp_vq(&transport->ipcc, vqs[i]);
> > > + break;
> > > + }
> > > + }
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static void dcp_virtio_del_vqs(struct virtio_device *vdev)
> > > +{
> > > + struct virtio_mmio_device *mmio =
> > > + container_of(vdev, struct virtio_mmio_device, vdev);
> > > + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> > > +
> > > + dcp_ipcc_set_resp_vq(&transport->ipcc, NULL);
> > > + virtio_mmio_config_ops.del_vqs(vdev);
> > > +}
> > > +
> > > +static void dcp_virtio_release_dev(struct device *dev)
> > > +{
> > > + struct virtio_device *vdev = container_of(dev, struct virtio_device, dev);
> > > + struct virtio_mmio_device *mmio =
> > > + container_of(vdev, struct virtio_mmio_device, vdev);
> > > + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
> > > +
> > > + kfree(transport);
> > > +}
> > > +
> > > +static int dcp_virtio_init_device(struct dcp_virtio_transport *transport,
> > > + struct platform_device *pdev)
> > > +{
> > > + struct virtio_mmio_device *mmio = &transport->mmio;
> > > + unsigned long magic;
> > > + int ret;
> > > +
> > > + mmio->vdev.dev.parent = &pdev->dev;
> > > + mmio->vdev.config = &transport->config_ops;
> > > + mmio->pdev = pdev;
> > > +
> > > + mmio->base = devm_platform_ioremap_resource(pdev, 0);
> > > + if (IS_ERR(mmio->base))
> > > + return PTR_ERR(mmio->base);
> > > +
> > > + magic = readl(mmio->base + VIRTIO_MMIO_MAGIC_VALUE);
> > > + if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
> > > + dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
> > > + return -ENODEV;
> > > + }
> > > +
> > > + mmio->version = readl(mmio->base + VIRTIO_MMIO_VERSION);
> > > + if (mmio->version < 1 || mmio->version > 3) {
> > > + dev_err(&pdev->dev, "Version %ld not supported!\n", mmio->version);
> > > + return -ENXIO;
> > > + }
> > > +
> > > + mmio->vdev.id.device = readl(mmio->base + VIRTIO_MMIO_DEVICE_ID);
> > > + if (!mmio->vdev.id.device)
> > > + return -ENODEV;
> > > +
> > > + mmio->vdev.id.vendor = readl(mmio->base + VIRTIO_MMIO_VENDOR_ID);
> > > +
> > > + if (mmio->version == 1) {
> > > + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
> > > + ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
> > > + if (!ret)
> > > + dma_set_coherent_mask(&pdev->dev,
> > > + DMA_BIT_MASK(32 + PAGE_SHIFT));
> > > + } else {
> > > + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
> > > + }
> > > + if (ret)
> > > + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> > > + if (ret)
> > > + dev_warn(&pdev->dev,
> > > + "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static int dcp_virtio_transport_probe(struct platform_device *pdev)
> > > +{
> > > + struct dcp_virtio_transport *transport;
> > > + struct virtio_mmio_device *mmio;
> > > + int ret;
> > > +
> > > + transport = kzalloc_obj(*transport);
> > > + if (!transport)
> > > + return -ENOMEM;
> > > +
> > > + mmio = &transport->mmio;
> > > + mmio->vdev.dev.release = dcp_virtio_release_dev;
> > > + transport->config_ops = virtio_mmio_config_ops;
> > > + transport->config_ops.find_vqs = dcp_virtio_find_vqs;
> > > + transport->config_ops.del_vqs = dcp_virtio_del_vqs;
> > > + transport->config_ops.synchronize_cbs = dcp_virtio_synchronize_cbs;
> > > +
> > > + ret = dcp_ipcc_init(&transport->ipcc, &pdev->dev, 1);
> > > + if (ret) {
> > > + kfree(transport);
> > > + return ret;
> > > + }
> > > +
> > > + /* Wake DCP before the first access to the VirtIO MMIO registers. */
> > > + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
> > > + if (ret)
> > > + goto err_ipcc;
> > > +
> > > + ret = dcp_virtio_init_device(transport, pdev);
> > > + if (ret)
> > > + goto err_ipcc;
> > > +
> > > + platform_set_drvdata(pdev, transport);
> > > +
> > > + ret = register_virtio_device(&mmio->vdev);
> > > + if (ret) {
> > > + platform_set_drvdata(pdev, NULL);
> > > + dcp_ipcc_deinit(&transport->ipcc);
> > > + put_device(&mmio->vdev.dev);
> > > + return ret;
> > > + }
> > > +
> > > + return 0;
> > > +
> > > +err_ipcc:
> > > + dcp_ipcc_deinit(&transport->ipcc);
> > > + kfree(transport);
> > > + return ret;
> > > +}
> > > +
> > > +static void dcp_virtio_transport_remove(struct platform_device *pdev)
> > > +{
> > > + struct dcp_virtio_transport *transport = platform_get_drvdata(pdev);
> > > +
> > > + /* Keep the embedded virtio_device alive until IPCC teardown is complete. */
> > > + get_device(&transport->mmio.vdev.dev);
> > > + unregister_virtio_device(&transport->mmio.vdev);
> > > + platform_set_drvdata(pdev, NULL);
> > > + dcp_ipcc_deinit(&transport->ipcc);
> > > + put_device(&transport->mmio.vdev.dev);
> > > +}
> > > +
> > > +#ifdef CONFIG_PM_SLEEP
> > > +static int dcp_virtio_transport_suspend(struct device *dev)
> > > +{
> > > + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
> > > + int ret;
> > > +
> > > + ret = virtio_device_freeze(&transport->mmio.vdev);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + ret = dcp_ipcc_enable_irq_wake(&transport->ipcc);
> > > + if (ret)
> > > + goto err_restore;
> > > +
> > > + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
> > > + if (ret) {
> > > + dcp_ipcc_disable_irq_wake(&transport->ipcc);
> > > + goto err_restore;
> > > + }
> > > +
> > > + return 0;
> > > +
> > > +err_restore:
> > > + virtio_device_restore(&transport->mmio.vdev);
> > > + return ret;
> > > +}
> > > +
> > > +static int dcp_virtio_transport_resume(struct device *dev)
> > > +{
> > > + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
> > > + struct virtio_mmio_device *mmio = &transport->mmio;
> > > + int ret;
> > > +
> > > + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
> > > + if (ret) {
> > > + dcp_ipcc_disable_irq_wake(&transport->ipcc);
> > > + return ret;
> > > + }
> > > +
> > > + dcp_ipcc_disable_irq_wake(&transport->ipcc);
> > > + if (mmio->version == 1)
> > > + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
> > > +
> > > + return virtio_device_restore(&mmio->vdev);
> > > +}
> > > +
> > > +#endif
> > > +static const struct dev_pm_ops dcp_virtio_transport_pm_ops = {
> > > + SET_SYSTEM_SLEEP_PM_OPS(dcp_virtio_transport_suspend,
> > > + dcp_virtio_transport_resume)
> > > +};
> > > +
> > > +static const struct of_device_id dcp_virtio_transport_of_match[] = {
> > > + { .compatible = "qcom,dcp-virtio" },
> > > + { }
> > > +};
> > > +MODULE_DEVICE_TABLE(of, dcp_virtio_transport_of_match);
> > > +
> > > +static struct platform_driver dcp_virtio_transport_driver = {
> > > + .probe = dcp_virtio_transport_probe,
> > > + .remove = dcp_virtio_transport_remove,
> > > + .driver = {
> > > + .name = "qcom-dcp-virtio",
> > > + .of_match_table = dcp_virtio_transport_of_match,
> > > + .pm = pm_sleep_ptr(&dcp_virtio_transport_pm_ops),
> > > + },
> > > +};
> > > +module_platform_driver(dcp_virtio_transport_driver);
> > > +
> > > +MODULE_DESCRIPTION("Qualcomm DCP VirtIO transport");
> > > +MODULE_LICENSE("GPL");
> > > diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.c b/drivers/virtio/virtio_qcom_dcp_ipcc.c
> > > new file mode 100644
> > > index 000000000000..1d83bcc69d5c
> > > --- /dev/null
> > > +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.c
> > > @@ -0,0 +1,193 @@
> > > +// SPDX-License-Identifier: GPL-2.0-only
> > > +/*
> > > + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> > > + *
> > > + * DCP IPCC power-notify mailbox client. It wakes DCP during power
> > > + * transitions and routes firmware notifications to the VirtIO response
> > > + * queue.
> > > + */
> > > +
> > > +#include <linux/device.h>
> > > +#include <linux/err.h>
> > > +#include <linux/jiffies.h>
> > > +#include <linux/interrupt.h>
> > > +#include <linux/mailbox_client.h>
> > > +#include <linux/mutex.h>
> > > +#include <linux/of_irq.h>
> > > +#include <linux/string.h>
> > > +#include <linux/virtio.h>
> > > +#include <linux/virtio_ring.h>
> > > +
> > > +#include "virtio_qcom_dcp_ipcc.h"
> > > +
> > > +#define DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS 10000
> > > +
> > > +static void dcp_ipcc_handle_rx(struct dcp_ipcc *ipcc)
> > > +{
> > > + unsigned long flags;
> > > +
> > > + spin_lock_irqsave(&ipcc->state_lock, flags);
> > > + if (ipcc->shutting_down) {
> > > + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> > > + return;
> > > + }
> > > +
> > > + complete(&ipcc->power_notify_done);
> > > + if (ipcc->resp_vq)
> > > + vring_interrupt(0, ipcc->resp_vq);
> > > +
> > > + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> > > +}
> > > +
> > > +static irqreturn_t dcp_ipcc_power_notify_irq(int irq, void *data)
> > > +{
> > > + struct dcp_ipcc *ipcc = data;
> > > +
> > > + dcp_ipcc_handle_rx(ipcc);
> > > +
> > > + return IRQ_HANDLED;
> > > +}
> > > +
> > > +static void dcp_ipcc_rx_callback(struct mbox_client *cl, void *data)
> > > +{
> > > + struct dcp_ipcc *ipcc = container_of(cl, struct dcp_ipcc, client);
> > > +
> > > + dcp_ipcc_handle_rx(ipcc);
> > > +}
> > > +
> > > +static void dcp_ipcc_free_channel(void *data)
> > > +{
> > > + mbox_free_channel(data);
> > > +}
> > > +
> > > +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index)
> > > +{
> > > + int irq, ret;
> > > +
> > > + memset(ipcc, 0, sizeof(*ipcc));
> > > + init_completion(&ipcc->power_notify_done);
> > > + mutex_init(&ipcc->power_notify_lock);
> > > + spin_lock_init(&ipcc->state_lock);
> > > +
> > > + ipcc->client.dev = dev;
> > > + ipcc->client.tx_block = false;
> > > + ipcc->client.tx_tout = 0;
> > > + ipcc->client.knows_txdone = true;
> > > + ipcc->client.rx_callback = dcp_ipcc_rx_callback;
> > > +
> > > + ipcc->power_chan = mbox_request_channel(&ipcc->client, 0);
> > > + if (IS_ERR(ipcc->power_chan)) {
> > > + ret = PTR_ERR(ipcc->power_chan);
> > > + if (ret != -EPROBE_DEFER)
> > > + dev_err(dev, "IPCC: failed to get DCP power channel: %d\n", ret);
> > > + return ret;
> > > + }
> > > +
> > > + ret = devm_add_action_or_reset(dev, dcp_ipcc_free_channel,
> > > + ipcc->power_chan);
> > > + if (ret) {
> > > + ipcc->power_chan = NULL;
> > > + return ret;
> > > + }
> > > +
> > > + irq = of_irq_get(dev->of_node, irq_index);
> > > + if (irq <= 0) {
> > > + ret = dev_err_probe(dev, irq ? irq : -EINVAL,
> > > + "failed to get required power notify IRQ\n");
> > > + goto err_free_channel;
> > > + }
> > > +
> > > + ret = devm_request_irq(dev, irq, dcp_ipcc_power_notify_irq, 0,
> > > + "dcp-power-notify", ipcc);
> > > + if (ret) {
> > > + ret = dev_err_probe(dev, ret,
> > > + "failed to request power notify IRQ %d\n", irq);
> > > + goto err_free_channel;
> > > + }
> > > +
> > > + ipcc->power_notify_irq = irq;
> > > +
> > > + return 0;
> > > +
> > > +err_free_channel:
> > > + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
> > > + ipcc->power_chan = NULL;
> > > + return ret;
> > > +}
> > > +
> > > +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq)
> > > +{
> > > + unsigned long flags;
> > > +
> > > + spin_lock_irqsave(&ipcc->state_lock, flags);
> > > + if (!ipcc->shutting_down)
> > > + ipcc->resp_vq = resp_vq;
> > > + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> > > +}
> > > +
> > > +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc)
> > > +{
> > > + unsigned long flags;
> > > +
> > > + spin_lock_irqsave(&ipcc->state_lock, flags);
> > > + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> > > +}
> > > +
> > > +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc)
> > > +{
> > > + struct device *dev = ipcc->client.dev;
> > > + unsigned long flags;
> > > +
> > > + mutex_lock(&ipcc->power_notify_lock);
> > > +
> > > + spin_lock_irqsave(&ipcc->state_lock, flags);
> > > + ipcc->shutting_down = true;
> > > + ipcc->resp_vq = NULL;
> > > + spin_unlock_irqrestore(&ipcc->state_lock, flags);
> > > +
> > > + devm_free_irq(dev, ipcc->power_notify_irq, ipcc);
> > > + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
> > > + mutex_unlock(&ipcc->power_notify_lock);
> > > +}
> > > +
> > > +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc)
> > > +{
> > > + return enable_irq_wake(ipcc->power_notify_irq);
> > > +}
> > > +
> > > +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc)
> > > +{
> > > + disable_irq_wake(ipcc->power_notify_irq);
> > > +}
> > > +
> > > +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc)
> > > +{
> > > + unsigned long timeout;
> > > + int ret;
> > > +
> > > + mutex_lock(&ipcc->power_notify_lock);
> > > +
> > > + reinit_completion(&ipcc->power_notify_done);
> > > +
> > > + ret = mbox_send_message(ipcc->power_chan, NULL);
> > > + mbox_client_txdone(ipcc->power_chan, ret);
> > > + if (ret < 0) {
> > > + dev_err(ipcc->client.dev,
> > > + "IPCC TX: power notify failed: %d\n", ret);
> > > + goto out_unlock;
> > > + }
> > > +
> > > + timeout = wait_for_completion_timeout(&ipcc->power_notify_done,
> > > + msecs_to_jiffies(DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS));
> > > + if (!timeout) {
> > > + dev_err(ipcc->client.dev,
> > > + "IPCC power notify acknowledgment timed out\n");
> > > + ret = -ETIMEDOUT;
> > > + } else {
> > > + ret = 0;
> > > + }
> > > +
> > > +out_unlock:
> > > + mutex_unlock(&ipcc->power_notify_lock);
> > > + return ret;
> > > +}
> > > diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.h b/drivers/virtio/virtio_qcom_dcp_ipcc.h
> > > new file mode 100644
> > > index 000000000000..f855fe8adec1
> > > --- /dev/null
> > > +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.h
> > > @@ -0,0 +1,41 @@
> > > +/* SPDX-License-Identifier: GPL-2.0-only */
> > > +/*
> > > + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
> > > + *
> > > + * IPCC power-notify mailbox interface for DCP firmware.
> > > + *
> > > + */
> > > +
> > > +#ifndef __VIRTIO_QCOM_DCP_IPCC_H__
> > > +#define __VIRTIO_QCOM_DCP_IPCC_H__
> > > +
> > > +#include <linux/completion.h>
> > > +#include <linux/mailbox_client.h>
> > > +#include <linux/mutex.h>
> > > +#include <linux/spinlock.h>
> > > +
> > > +struct device;
> > > +struct virtqueue;
> > > +
> > > +struct dcp_ipcc {
> > > + struct mbox_client client;
> > > + struct mbox_chan *power_chan;
> > > + struct virtqueue *resp_vq;
> > > + struct completion power_notify_done;
> > > + /* Serializes concurrent power-notify transactions. */
> > > + struct mutex power_notify_lock;
> > > + /* Protects callback state and response queue access. */
> > > + spinlock_t state_lock;
> > > + bool shutting_down;
> > > + int power_notify_irq;
> > > +};
> > > +
> > > +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index);
> > > +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq);
> > > +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc);
> > > +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc);
> > > +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc);
> > > +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc);
> > > +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc);
> > > +
> > > +#endif /* __VIRTIO_QCOM_DCP_IPCC_H__ */
> > >
> > > --
> > > 2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper
2026-11-26 11:41 ` Michael S. Tsirkin
@ 2026-11-26 12:18 ` Jayant Shekhar
0 siblings, 0 replies; 12+ messages in thread
From: Jayant Shekhar @ 2026-11-26 12:18 UTC (permalink / raw)
To: Michael S. Tsirkin, Jayant Shekhar
Cc: Jason Wang, Eugenio Pérez, Xuan Zhuo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Dmitry Baryshkov, Flemin Jose,
linux-arm-msm, virtualization, devicetree, linux-kernel
On 26-11-2026 17:11, Michael S. Tsirkin wrote:
> On Thu, Nov 26, 2026 at 03:33:53PM +0530, Jayant Shekhar wrote:
>> On 26-11-2026 12:05, Michael S. Tsirkin wrote:
>>> On Thu, Nov 26, 2026 at 11:54:01AM +0530, Jayant Shekhar wrote:
>>>> Add the Qualcomm-specific VirtIO transport required by DCP firmware.
>>>>
>>>> The transport sends an IPCC power notification before accessing the
>>>> VirtIO MMIO registers, then registers a VirtIO device directly.
>>>>
>>>> Implement MMIO configuration access, feature negotiation, virtqueue
>>>> setup, interrupt handling, reset, DMA setup, and suspend/resume
>>>> sequencing in the transport. Keep power-management ordering in the
>>>> transport so VirtIO queues are quiesced before DCP power changes.
>>>>
>>>> Assisted-by: LLM
>>>> Signed-off-by: Jayant Shekhar<jayant.shekhar@oss.qualcomm.com>
>>> So VIRTIO_ID_VENDOR you defined in patch 2 is completely unused?
>>> Why did you bother?
>>>
>> I have split the DCP driver series into two:
>>
>> 1) Adds Add the Qualcomm-specific VirtIO transport (this one)
>>
>> 2) Add Qualcomm DCP display support (separate series)
>>
>> https://lore.kernel.org/all/20261126-jshekhar-v3-dcp-v3-0-f1e9d7505039@oss.qualcomm.com/
>>
>> Below patch uses the VIRTIO_ID_VENDOR
>>
>> https://lore.kernel.org/all/20261126-jshekhar-v3-dcp-v3-18-f1e9d7505039@oss.qualcomm.com/
>
> so move this patch there?
>
> And this, from that patch:
>
> +static const struct virtio_device_id dcp_virtio_id_table[] = {
> + { VIRTIO_ID_VENDOR, VIRTIO_DEV_ANY_ID },
> + { 0 },
> +};
> +MODULE_DEVICE_TABLE(virtio, dcp_virtio_id_table);
>
>
> is not going to fly. Fill in your vendor ID please.
>
Sure, I will move patch 2 to "Add Qualcomm DCP display support" series.
The Qualcomm vendor ID is still under discussion. I’ll update the DCP
driver’s match table with the agreed value and won’t use VIRTIO_DEV_ANY_ID.
>>>> ---
>>>> drivers/virtio/Kconfig | 11 ++
>>>> drivers/virtio/Makefile | 2 +
>>>> drivers/virtio/virtio_mmio.c | 17 +--
>>>> drivers/virtio/virtio_mmio.h | 21 +++
>>>> drivers/virtio/virtio_qcom_dcp.c | 273 ++++++++++++++++++++++++++++++++++
>>>> drivers/virtio/virtio_qcom_dcp_ipcc.c | 193 ++++++++++++++++++++++++
>>>> drivers/virtio/virtio_qcom_dcp_ipcc.h | 41 +++++
>>>> 7 files changed, 544 insertions(+), 14 deletions(-)
>>> Oh great a pile of vendor specific code in virtio, with the vendor
>>> explicitly saying on the virtio ML that no specs will be published,
>>> ever. And it seems to be your assumption that I'll be signing up to
>>> maintain this?
>>>
>>>
>> The transport uses the standard VirtIO-MMIO register layout and virtqueue
>> operations; it does not define a new MMIO protocol. IPCC is a Qualcomm
>> platform sideband needed to wake DCP before MMIO access and to signal
>> response-queue notifications.
>>
>> I agree that the maintenance ownership is separate concern that need to be
>> addressed.
>>
>>
>>>> diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
>>>> index ce5bc0d9ea28..838ae5671c28 100644
>>>> --- a/drivers/virtio/Kconfig
>>>> +++ b/drivers/virtio/Kconfig
>>>> @@ -160,6 +160,17 @@ config VIRTIO_MMIO
>>>> If unsure, say N.
>>>> +config VIRTIO_QCOM_DCP
>>>> + tristate "Qualcomm DCP VirtIO transport"
>>>> + depends on VIRTIO_MMIO
>>>> + depends on QCOM_IPCC
>>>> + depends on OF
>>>> + help
>>>> + This driver provides the Qualcomm DCP-specific platform transport for
>>>> + QPSFI VirtIO devices. It reuses the standard VirtIO-MMIO configuration
>>>> + and virtqueue support, and handles the IPCC power-notification channel
>>>> + used to wake DCP and forward response notifications.
>>>> +
>>>> config VIRTIO_MMIO_CMDLINE_DEVICES
>>>> bool "Memory mapped virtio devices parameter parsing"
>>>> depends on VIRTIO_MMIO
>>>> diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
>>>> index eefcfe90d6b8..c922fb5bff16 100644
>>>> --- a/drivers/virtio/Makefile
>>>> +++ b/drivers/virtio/Makefile
>>>> @@ -3,6 +3,8 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o
>>>> obj-$(CONFIG_VIRTIO_ANCHOR) += virtio_anchor.o
>>>> obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio_pci_modern_dev.o
>>>> obj-$(CONFIG_VIRTIO_PCI_LIB_LEGACY) += virtio_pci_legacy_dev.o
>>>> +obj-$(CONFIG_VIRTIO_QCOM_DCP) += qcom_dcp_virtio.o
>>>> +qcom_dcp_virtio-y := virtio_qcom_dcp.o virtio_qcom_dcp_ipcc.o
>>>> obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
>>>> obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
>>>> virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
>>>> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
>>>> index c403a025006e..348809b9ebfe 100644
>>>> --- a/drivers/virtio/virtio_mmio.c
>>>> +++ b/drivers/virtio/virtio_mmio.c
>>>> @@ -71,7 +71,7 @@
>>>> #include <uapi/linux/virtio_mmio.h>
>>>> #include <linux/virtio_ring.h>
>>>> -
>>>> +#include "virtio_mmio.h"
>>>> /* The alignment to use between consumer and producer parts of vring.
>>>> * Currently hardcoded to the page size. */
>>>> @@ -81,18 +81,6 @@
>>>> #define to_virtio_mmio_device(_plat_dev) \
>>>> container_of(_plat_dev, struct virtio_mmio_device, vdev)
>>>> -
>>>> -struct virtio_mmio_device {
>>>> - struct virtio_device vdev;
>>>> - struct platform_device *pdev;
>>>> -
>>>> - void __iomem *base;
>>>> - unsigned long version;
>>>> -
>>>> - /* True if enable_irq_wake() succeeded for the shared IRQ. */
>>>> - bool wake_irq_enabled;
>>>> -};
>>>> -
>>>> /* Configuration interface */
>>>> static u64 vm_get_features(struct virtio_device *vdev)
>>>> @@ -536,7 +524,7 @@ static bool vm_get_shm_region(struct virtio_device *vdev,
>>>> return true;
>>>> }
>>>> -static const struct virtio_config_ops virtio_mmio_config_ops = {
>>>> +const struct virtio_config_ops virtio_mmio_config_ops = {
>>>> .get = vm_get,
>>>> .set = vm_set,
>>>> .generation = vm_generation,
>>>> @@ -551,6 +539,7 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
>>>> .get_shm_region = vm_get_shm_region,
>>>> .synchronize_cbs = vm_synchronize_cbs,
>>>> };
>>>> +EXPORT_SYMBOL_GPL(virtio_mmio_config_ops);
>>>> #ifdef CONFIG_PM_SLEEP
>>>> static int virtio_mmio_freeze(struct device *dev)
>>>> diff --git a/drivers/virtio/virtio_mmio.h b/drivers/virtio/virtio_mmio.h
>>>> new file mode 100644
>>>> index 000000000000..a80904ed73e2
>>>> --- /dev/null
>>>> +++ b/drivers/virtio/virtio_mmio.h
>>>> @@ -0,0 +1,21 @@
>>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>>> +#ifndef _DRIVERS_VIRTIO_VIRTIO_MMIO_H
>>>> +#define _DRIVERS_VIRTIO_VIRTIO_MMIO_H
>>>> +
>>>> +#include <linux/io.h>
>>>> +#include <linux/platform_device.h>
>>>> +#include <linux/virtio.h>
>>>> +#include <linux/virtio_config.h>
>>>> +
>>>> +struct virtio_mmio_device {
>>>> + struct virtio_device vdev;
>>>> + struct platform_device *pdev;
>>>> + void __iomem *base;
>>>> + unsigned long version;
>>>> + /* True if enable_irq_wake() succeeded for the shared IRQ. */
>>>> + bool wake_irq_enabled;
>>>> +};
>>>> +
>>>> +extern const struct virtio_config_ops virtio_mmio_config_ops;
>>>> +
>>>> +#endif /* _DRIVERS_VIRTIO_VIRTIO_MMIO_H */
>>>> diff --git a/drivers/virtio/virtio_qcom_dcp.c b/drivers/virtio/virtio_qcom_dcp.c
>>>> new file mode 100644
>>>> index 000000000000..a5443f2dbc4b
>>>> --- /dev/null
>>>> +++ b/drivers/virtio/virtio_qcom_dcp.c
>>>> @@ -0,0 +1,273 @@
>>>> +// SPDX-License-Identifier: GPL-2.0-only
>>>> +/*
>>>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
>>>> + *
>>>> + * Qualcomm DCP VirtIO transport.
>>>> + */
>>>> +
>>>> +#include <linux/dma-mapping.h>
>>>> +#include <linux/io.h>
>>>> +#include <linux/module.h>
>>>> +#include <linux/of.h>
>>>> +#include <linux/platform_device.h>
>>>> +#include <linux/pm.h>
>>>> +#include <linux/slab.h>
>>>> +#include <linux/string.h>
>>>> +#include <linux/virtio.h>
>>>> +#include <linux/virtio_config.h>
>>>> +#include <uapi/linux/virtio_mmio.h>
>>>> +
>>>> +#include "virtio_mmio.h"
>>>> +#include "virtio_qcom_dcp_ipcc.h"
>>>> +
>>>> +struct dcp_virtio_transport {
>>>> + struct virtio_mmio_device mmio;
>>>> + struct virtio_config_ops config_ops;
>>>> + struct dcp_ipcc ipcc;
>>>> +};
>>>> +
>>>> +static struct dcp_virtio_transport *
>>>> +to_dcp_virtio_transport(struct virtio_mmio_device *mmio)
>>>> +{
>>>> + return container_of(mmio, struct dcp_virtio_transport, mmio);
>>>> +}
>>>> +
>>>> +static void dcp_virtio_synchronize_cbs(struct virtio_device *vdev)
>>>> +{
>>>> + struct virtio_mmio_device *mmio =
>>>> + container_of(vdev, struct virtio_mmio_device, vdev);
>>>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>>>> +
>>>> + virtio_mmio_config_ops.synchronize_cbs(vdev);
>>>> + dcp_ipcc_synchronize(&transport->ipcc);
>>>> +}
>>>> +
>>>> +static int dcp_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
>>>> + struct virtqueue *vqs[],
>>>> + struct virtqueue_info vqs_info[],
>>>> + struct irq_affinity *desc)
>>>> +{
>>>> + struct virtio_mmio_device *mmio =
>>>> + container_of(vdev, struct virtio_mmio_device, vdev);
>>>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>>>> + unsigned int i;
>>>> + int ret;
>>>> +
>>>> + ret = virtio_mmio_config_ops.find_vqs(vdev, nvqs, vqs, vqs_info, desc);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + for (i = 0; i < nvqs; i++) {
>>>> + if (vqs[i] && vqs_info[i].name && !strcmp(vqs_info[i].name, "resp")) {
>>>> + dcp_ipcc_set_resp_vq(&transport->ipcc, vqs[i]);
>>>> + break;
>>>> + }
>>>> + }
>>>> +
>>>> + return 0;
>>>> +}
>>>> +
>>>> +static void dcp_virtio_del_vqs(struct virtio_device *vdev)
>>>> +{
>>>> + struct virtio_mmio_device *mmio =
>>>> + container_of(vdev, struct virtio_mmio_device, vdev);
>>>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>>>> +
>>>> + dcp_ipcc_set_resp_vq(&transport->ipcc, NULL);
>>>> + virtio_mmio_config_ops.del_vqs(vdev);
>>>> +}
>>>> +
>>>> +static void dcp_virtio_release_dev(struct device *dev)
>>>> +{
>>>> + struct virtio_device *vdev = container_of(dev, struct virtio_device, dev);
>>>> + struct virtio_mmio_device *mmio =
>>>> + container_of(vdev, struct virtio_mmio_device, vdev);
>>>> + struct dcp_virtio_transport *transport = to_dcp_virtio_transport(mmio);
>>>> +
>>>> + kfree(transport);
>>>> +}
>>>> +
>>>> +static int dcp_virtio_init_device(struct dcp_virtio_transport *transport,
>>>> + struct platform_device *pdev)
>>>> +{
>>>> + struct virtio_mmio_device *mmio = &transport->mmio;
>>>> + unsigned long magic;
>>>> + int ret;
>>>> +
>>>> + mmio->vdev.dev.parent = &pdev->dev;
>>>> + mmio->vdev.config = &transport->config_ops;
>>>> + mmio->pdev = pdev;
>>>> +
>>>> + mmio->base = devm_platform_ioremap_resource(pdev, 0);
>>>> + if (IS_ERR(mmio->base))
>>>> + return PTR_ERR(mmio->base);
>>>> +
>>>> + magic = readl(mmio->base + VIRTIO_MMIO_MAGIC_VALUE);
>>>> + if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
>>>> + dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
>>>> + return -ENODEV;
>>>> + }
>>>> +
>>>> + mmio->version = readl(mmio->base + VIRTIO_MMIO_VERSION);
>>>> + if (mmio->version < 1 || mmio->version > 3) {
>>>> + dev_err(&pdev->dev, "Version %ld not supported!\n", mmio->version);
>>>> + return -ENXIO;
>>>> + }
>>>> +
>>>> + mmio->vdev.id.device = readl(mmio->base + VIRTIO_MMIO_DEVICE_ID);
>>>> + if (!mmio->vdev.id.device)
>>>> + return -ENODEV;
>>>> +
>>>> + mmio->vdev.id.vendor = readl(mmio->base + VIRTIO_MMIO_VENDOR_ID);
>>>> +
>>>> + if (mmio->version == 1) {
>>>> + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
>>>> + ret = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
>>>> + if (!ret)
>>>> + dma_set_coherent_mask(&pdev->dev,
>>>> + DMA_BIT_MASK(32 + PAGE_SHIFT));
>>>> + } else {
>>>> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
>>>> + }
>>>> + if (ret)
>>>> + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
>>>> + if (ret)
>>>> + dev_warn(&pdev->dev,
>>>> + "Failed to enable 64-bit or 32-bit DMA. Trying to continue, but this might not work.\n");
>>>> +
>>>> + return 0;
>>>> +}
>>>> +
>>>> +static int dcp_virtio_transport_probe(struct platform_device *pdev)
>>>> +{
>>>> + struct dcp_virtio_transport *transport;
>>>> + struct virtio_mmio_device *mmio;
>>>> + int ret;
>>>> +
>>>> + transport = kzalloc_obj(*transport);
>>>> + if (!transport)
>>>> + return -ENOMEM;
>>>> +
>>>> + mmio = &transport->mmio;
>>>> + mmio->vdev.dev.release = dcp_virtio_release_dev;
>>>> + transport->config_ops = virtio_mmio_config_ops;
>>>> + transport->config_ops.find_vqs = dcp_virtio_find_vqs;
>>>> + transport->config_ops.del_vqs = dcp_virtio_del_vqs;
>>>> + transport->config_ops.synchronize_cbs = dcp_virtio_synchronize_cbs;
>>>> +
>>>> + ret = dcp_ipcc_init(&transport->ipcc, &pdev->dev, 1);
>>>> + if (ret) {
>>>> + kfree(transport);
>>>> + return ret;
>>>> + }
>>>> +
>>>> + /* Wake DCP before the first access to the VirtIO MMIO registers. */
>>>> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
>>>> + if (ret)
>>>> + goto err_ipcc;
>>>> +
>>>> + ret = dcp_virtio_init_device(transport, pdev);
>>>> + if (ret)
>>>> + goto err_ipcc;
>>>> +
>>>> + platform_set_drvdata(pdev, transport);
>>>> +
>>>> + ret = register_virtio_device(&mmio->vdev);
>>>> + if (ret) {
>>>> + platform_set_drvdata(pdev, NULL);
>>>> + dcp_ipcc_deinit(&transport->ipcc);
>>>> + put_device(&mmio->vdev.dev);
>>>> + return ret;
>>>> + }
>>>> +
>>>> + return 0;
>>>> +
>>>> +err_ipcc:
>>>> + dcp_ipcc_deinit(&transport->ipcc);
>>>> + kfree(transport);
>>>> + return ret;
>>>> +}
>>>> +
>>>> +static void dcp_virtio_transport_remove(struct platform_device *pdev)
>>>> +{
>>>> + struct dcp_virtio_transport *transport = platform_get_drvdata(pdev);
>>>> +
>>>> + /* Keep the embedded virtio_device alive until IPCC teardown is complete. */
>>>> + get_device(&transport->mmio.vdev.dev);
>>>> + unregister_virtio_device(&transport->mmio.vdev);
>>>> + platform_set_drvdata(pdev, NULL);
>>>> + dcp_ipcc_deinit(&transport->ipcc);
>>>> + put_device(&transport->mmio.vdev.dev);
>>>> +}
>>>> +
>>>> +#ifdef CONFIG_PM_SLEEP
>>>> +static int dcp_virtio_transport_suspend(struct device *dev)
>>>> +{
>>>> + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
>>>> + int ret;
>>>> +
>>>> + ret = virtio_device_freeze(&transport->mmio.vdev);
>>>> + if (ret)
>>>> + return ret;
>>>> +
>>>> + ret = dcp_ipcc_enable_irq_wake(&transport->ipcc);
>>>> + if (ret)
>>>> + goto err_restore;
>>>> +
>>>> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
>>>> + if (ret) {
>>>> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
>>>> + goto err_restore;
>>>> + }
>>>> +
>>>> + return 0;
>>>> +
>>>> +err_restore:
>>>> + virtio_device_restore(&transport->mmio.vdev);
>>>> + return ret;
>>>> +}
>>>> +
>>>> +static int dcp_virtio_transport_resume(struct device *dev)
>>>> +{
>>>> + struct dcp_virtio_transport *transport = dev_get_drvdata(dev);
>>>> + struct virtio_mmio_device *mmio = &transport->mmio;
>>>> + int ret;
>>>> +
>>>> + ret = dcp_ipcc_send_power_notify(&transport->ipcc);
>>>> + if (ret) {
>>>> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
>>>> + return ret;
>>>> + }
>>>> +
>>>> + dcp_ipcc_disable_irq_wake(&transport->ipcc);
>>>> + if (mmio->version == 1)
>>>> + writel(PAGE_SIZE, mmio->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
>>>> +
>>>> + return virtio_device_restore(&mmio->vdev);
>>>> +}
>>>> +
>>>> +#endif
>>>> +static const struct dev_pm_ops dcp_virtio_transport_pm_ops = {
>>>> + SET_SYSTEM_SLEEP_PM_OPS(dcp_virtio_transport_suspend,
>>>> + dcp_virtio_transport_resume)
>>>> +};
>>>> +
>>>> +static const struct of_device_id dcp_virtio_transport_of_match[] = {
>>>> + { .compatible = "qcom,dcp-virtio" },
>>>> + { }
>>>> +};
>>>> +MODULE_DEVICE_TABLE(of, dcp_virtio_transport_of_match);
>>>> +
>>>> +static struct platform_driver dcp_virtio_transport_driver = {
>>>> + .probe = dcp_virtio_transport_probe,
>>>> + .remove = dcp_virtio_transport_remove,
>>>> + .driver = {
>>>> + .name = "qcom-dcp-virtio",
>>>> + .of_match_table = dcp_virtio_transport_of_match,
>>>> + .pm = pm_sleep_ptr(&dcp_virtio_transport_pm_ops),
>>>> + },
>>>> +};
>>>> +module_platform_driver(dcp_virtio_transport_driver);
>>>> +
>>>> +MODULE_DESCRIPTION("Qualcomm DCP VirtIO transport");
>>>> +MODULE_LICENSE("GPL");
>>>> diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.c b/drivers/virtio/virtio_qcom_dcp_ipcc.c
>>>> new file mode 100644
>>>> index 000000000000..1d83bcc69d5c
>>>> --- /dev/null
>>>> +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.c
>>>> @@ -0,0 +1,193 @@
>>>> +// SPDX-License-Identifier: GPL-2.0-only
>>>> +/*
>>>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
>>>> + *
>>>> + * DCP IPCC power-notify mailbox client. It wakes DCP during power
>>>> + * transitions and routes firmware notifications to the VirtIO response
>>>> + * queue.
>>>> + */
>>>> +
>>>> +#include <linux/device.h>
>>>> +#include <linux/err.h>
>>>> +#include <linux/jiffies.h>
>>>> +#include <linux/interrupt.h>
>>>> +#include <linux/mailbox_client.h>
>>>> +#include <linux/mutex.h>
>>>> +#include <linux/of_irq.h>
>>>> +#include <linux/string.h>
>>>> +#include <linux/virtio.h>
>>>> +#include <linux/virtio_ring.h>
>>>> +
>>>> +#include "virtio_qcom_dcp_ipcc.h"
>>>> +
>>>> +#define DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS 10000
>>>> +
>>>> +static void dcp_ipcc_handle_rx(struct dcp_ipcc *ipcc)
>>>> +{
>>>> + unsigned long flags;
>>>> +
>>>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>>>> + if (ipcc->shutting_down) {
>>>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>>>> + return;
>>>> + }
>>>> +
>>>> + complete(&ipcc->power_notify_done);
>>>> + if (ipcc->resp_vq)
>>>> + vring_interrupt(0, ipcc->resp_vq);
>>>> +
>>>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>>>> +}
>>>> +
>>>> +static irqreturn_t dcp_ipcc_power_notify_irq(int irq, void *data)
>>>> +{
>>>> + struct dcp_ipcc *ipcc = data;
>>>> +
>>>> + dcp_ipcc_handle_rx(ipcc);
>>>> +
>>>> + return IRQ_HANDLED;
>>>> +}
>>>> +
>>>> +static void dcp_ipcc_rx_callback(struct mbox_client *cl, void *data)
>>>> +{
>>>> + struct dcp_ipcc *ipcc = container_of(cl, struct dcp_ipcc, client);
>>>> +
>>>> + dcp_ipcc_handle_rx(ipcc);
>>>> +}
>>>> +
>>>> +static void dcp_ipcc_free_channel(void *data)
>>>> +{
>>>> + mbox_free_channel(data);
>>>> +}
>>>> +
>>>> +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index)
>>>> +{
>>>> + int irq, ret;
>>>> +
>>>> + memset(ipcc, 0, sizeof(*ipcc));
>>>> + init_completion(&ipcc->power_notify_done);
>>>> + mutex_init(&ipcc->power_notify_lock);
>>>> + spin_lock_init(&ipcc->state_lock);
>>>> +
>>>> + ipcc->client.dev = dev;
>>>> + ipcc->client.tx_block = false;
>>>> + ipcc->client.tx_tout = 0;
>>>> + ipcc->client.knows_txdone = true;
>>>> + ipcc->client.rx_callback = dcp_ipcc_rx_callback;
>>>> +
>>>> + ipcc->power_chan = mbox_request_channel(&ipcc->client, 0);
>>>> + if (IS_ERR(ipcc->power_chan)) {
>>>> + ret = PTR_ERR(ipcc->power_chan);
>>>> + if (ret != -EPROBE_DEFER)
>>>> + dev_err(dev, "IPCC: failed to get DCP power channel: %d\n", ret);
>>>> + return ret;
>>>> + }
>>>> +
>>>> + ret = devm_add_action_or_reset(dev, dcp_ipcc_free_channel,
>>>> + ipcc->power_chan);
>>>> + if (ret) {
>>>> + ipcc->power_chan = NULL;
>>>> + return ret;
>>>> + }
>>>> +
>>>> + irq = of_irq_get(dev->of_node, irq_index);
>>>> + if (irq <= 0) {
>>>> + ret = dev_err_probe(dev, irq ? irq : -EINVAL,
>>>> + "failed to get required power notify IRQ\n");
>>>> + goto err_free_channel;
>>>> + }
>>>> +
>>>> + ret = devm_request_irq(dev, irq, dcp_ipcc_power_notify_irq, 0,
>>>> + "dcp-power-notify", ipcc);
>>>> + if (ret) {
>>>> + ret = dev_err_probe(dev, ret,
>>>> + "failed to request power notify IRQ %d\n", irq);
>>>> + goto err_free_channel;
>>>> + }
>>>> +
>>>> + ipcc->power_notify_irq = irq;
>>>> +
>>>> + return 0;
>>>> +
>>>> +err_free_channel:
>>>> + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
>>>> + ipcc->power_chan = NULL;
>>>> + return ret;
>>>> +}
>>>> +
>>>> +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq)
>>>> +{
>>>> + unsigned long flags;
>>>> +
>>>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>>>> + if (!ipcc->shutting_down)
>>>> + ipcc->resp_vq = resp_vq;
>>>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>>>> +}
>>>> +
>>>> +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc)
>>>> +{
>>>> + unsigned long flags;
>>>> +
>>>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>>>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>>>> +}
>>>> +
>>>> +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc)
>>>> +{
>>>> + struct device *dev = ipcc->client.dev;
>>>> + unsigned long flags;
>>>> +
>>>> + mutex_lock(&ipcc->power_notify_lock);
>>>> +
>>>> + spin_lock_irqsave(&ipcc->state_lock, flags);
>>>> + ipcc->shutting_down = true;
>>>> + ipcc->resp_vq = NULL;
>>>> + spin_unlock_irqrestore(&ipcc->state_lock, flags);
>>>> +
>>>> + devm_free_irq(dev, ipcc->power_notify_irq, ipcc);
>>>> + devm_release_action(dev, dcp_ipcc_free_channel, ipcc->power_chan);
>>>> + mutex_unlock(&ipcc->power_notify_lock);
>>>> +}
>>>> +
>>>> +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc)
>>>> +{
>>>> + return enable_irq_wake(ipcc->power_notify_irq);
>>>> +}
>>>> +
>>>> +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc)
>>>> +{
>>>> + disable_irq_wake(ipcc->power_notify_irq);
>>>> +}
>>>> +
>>>> +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc)
>>>> +{
>>>> + unsigned long timeout;
>>>> + int ret;
>>>> +
>>>> + mutex_lock(&ipcc->power_notify_lock);
>>>> +
>>>> + reinit_completion(&ipcc->power_notify_done);
>>>> +
>>>> + ret = mbox_send_message(ipcc->power_chan, NULL);
>>>> + mbox_client_txdone(ipcc->power_chan, ret);
>>>> + if (ret < 0) {
>>>> + dev_err(ipcc->client.dev,
>>>> + "IPCC TX: power notify failed: %d\n", ret);
>>>> + goto out_unlock;
>>>> + }
>>>> +
>>>> + timeout = wait_for_completion_timeout(&ipcc->power_notify_done,
>>>> + msecs_to_jiffies(DCP_IPCC_POWER_NOTIFY_TIMEOUT_MS));
>>>> + if (!timeout) {
>>>> + dev_err(ipcc->client.dev,
>>>> + "IPCC power notify acknowledgment timed out\n");
>>>> + ret = -ETIMEDOUT;
>>>> + } else {
>>>> + ret = 0;
>>>> + }
>>>> +
>>>> +out_unlock:
>>>> + mutex_unlock(&ipcc->power_notify_lock);
>>>> + return ret;
>>>> +}
>>>> diff --git a/drivers/virtio/virtio_qcom_dcp_ipcc.h b/drivers/virtio/virtio_qcom_dcp_ipcc.h
>>>> new file mode 100644
>>>> index 000000000000..f855fe8adec1
>>>> --- /dev/null
>>>> +++ b/drivers/virtio/virtio_qcom_dcp_ipcc.h
>>>> @@ -0,0 +1,41 @@
>>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>>> +/*
>>>> + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
>>>> + *
>>>> + * IPCC power-notify mailbox interface for DCP firmware.
>>>> + *
>>>> + */
>>>> +
>>>> +#ifndef __VIRTIO_QCOM_DCP_IPCC_H__
>>>> +#define __VIRTIO_QCOM_DCP_IPCC_H__
>>>> +
>>>> +#include <linux/completion.h>
>>>> +#include <linux/mailbox_client.h>
>>>> +#include <linux/mutex.h>
>>>> +#include <linux/spinlock.h>
>>>> +
>>>> +struct device;
>>>> +struct virtqueue;
>>>> +
>>>> +struct dcp_ipcc {
>>>> + struct mbox_client client;
>>>> + struct mbox_chan *power_chan;
>>>> + struct virtqueue *resp_vq;
>>>> + struct completion power_notify_done;
>>>> + /* Serializes concurrent power-notify transactions. */
>>>> + struct mutex power_notify_lock;
>>>> + /* Protects callback state and response queue access. */
>>>> + spinlock_t state_lock;
>>>> + bool shutting_down;
>>>> + int power_notify_irq;
>>>> +};
>>>> +
>>>> +int dcp_ipcc_init(struct dcp_ipcc *ipcc, struct device *dev, unsigned int irq_index);
>>>> +void dcp_ipcc_set_resp_vq(struct dcp_ipcc *ipcc, struct virtqueue *resp_vq);
>>>> +void dcp_ipcc_synchronize(struct dcp_ipcc *ipcc);
>>>> +void dcp_ipcc_deinit(struct dcp_ipcc *ipcc);
>>>> +int dcp_ipcc_send_power_notify(struct dcp_ipcc *ipcc);
>>>> +int dcp_ipcc_enable_irq_wake(struct dcp_ipcc *ipcc);
>>>> +void dcp_ipcc_disable_irq_wake(struct dcp_ipcc *ipcc);
>>>> +
>>>> +#endif /* __VIRTIO_QCOM_DCP_IPCC_H__ */
>>>>
>>>> --
>>>> 2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-11-26 12:18 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 6:23 [PATCH 0/3] virtio: Add Qualcomm Display Co-Processor transport wrapper Jayant Shekhar
2026-11-26 6:23 ` [PATCH 1/3] dt-bindings: virtio: Add Qualcomm DCP transport Jayant Shekhar
2026-11-26 6:36 ` sashiko-bot
2026-11-26 6:24 ` [PATCH 2/3] virtio: Add vendor-specific device ID Jayant Shekhar
2026-11-26 6:27 ` Michael S. Tsirkin
2026-11-26 6:29 ` sashiko-bot
2026-11-26 6:24 ` [PATCH 3/3] virtio: Add Qualcomm VirtIO transport wrapper Jayant Shekhar
2026-11-26 6:35 ` Michael S. Tsirkin
2026-11-26 10:03 ` Jayant Shekhar
2026-11-26 11:41 ` Michael S. Tsirkin
2026-11-26 12:18 ` Jayant Shekhar
2026-11-26 6:44 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox