Skip to contentSkip to conversation

virtio: Parse virtio-device nodes from DT

PATCH In review Viresh Kumar 5 participants 25 messages Jul 13, 2021 – Jul 19, 2021

Subsystems (5)
lore
Share & tools
lore

Viresh Kumar

author maintainer
#0 lore raw

cover virtio: Parse virtio-device nodes from DT

Hi,

Currently the DT only provides support for following node types for virtio-mmio nodes:

	virtio_mmio@a000000 {
		dma-coherent;
		interrupts = <0x00 0x10 0x01>;
		reg = <0x00 0xa000000 0x00 0x200>;
		compatible = "virtio,mmio";
	};

And each virtio-mmio corresponds to a virtio-device. But there is no way for other users in the DT to show their dependency on virtio devices.

This patchset provides that support.

The first patch update virtio,mmio bindings to allow for device subnodes to be present and the second patch updates the virtio-mmio driver to update the of_node.

Other patches add bindings for i2c and gpio virtio devices (they have some dependencies, mentioned in the patches).

Tested on x86 with qemu for arm64.

--
Viresh

Viresh Kumar (5):
dt-bindings: virtio: mmio: Add support for device subnode
virtio_mmio: Bind virtio device to device-tree node
dt-bindings: i2c: Add bindings for i2c-virtio
i2c: virtio: Update i2c-adapter's of_node
dt-bindings: gpio: Add bindings for gpio-virtio

 .../devicetree/bindings/gpio/gpio-virtio.yaml | 67 +++++++++++++++++++
 .../devicetree/bindings/i2c/i2c-virtio.yaml   | 59 ++++++++++++++++
 .../devicetree/bindings/virtio/mmio.yaml      | 41 ++++++++++++
 drivers/i2c/busses/i2c-virtio.c               |  1 +
 drivers/virtio/virtio_mmio.c                  | 44 ++++++++++++
 include/dt-bindings/virtio/virtio_ids.h       |  1 +
 6 files changed, 213 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-virtio.yaml
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-virtio.yaml
 create mode 120000 include/dt-bindings/virtio/virtio_ids.h
Signature · 1 line
2.31.1.272.g89b43f80a514
author maintainer
#1 lore raw

PATCH 1/5 dt-bindings: virtio: mmio: Add support for device subnode

Allow virtio,mmio nodes to contain device specific subnodes. Since each virtio,mmio node can represent a single virtio device, each virtio node is allowed to contain a maximum of one device specific subnode.

The device subnode must have the "reg" property, and its value must match the virtio device ID used by the virtio mmio node.

A phandle to this device subnode can then be used by the users of the virtio device.

Also add a symbolic link to uapi/linux/virtio_ids.h in order to use the definitions here.

---
 .../devicetree/bindings/virtio/mmio.yaml      | 41 +++++++++++++++++++
 include/dt-bindings/virtio/virtio_ids.h       |  1 +
 2 files changed, 42 insertions(+)
 create mode 120000 include/dt-bindings/virtio/virtio_ids.h
Documentation/devicetree/bindings/virtio/mmio.yaml +41 -0
index d46597028cf1..e5f9fe6ecb5e 100644
@@ -31,6 +31,31 @@ title: virtio memory mapped devices
     description: Required for devices making accesses thru an IOMMU.
     maxItems: 1
 
+  "#address-cells":
+    const: 1
+    description:
+      The cell is the device ID if a device subnode is used.
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  '^[a-z0-9]+-virtio@[0-9]+$':
+    type: object
+    description: |
+      Exactly one node describing the virtio device. The name of the node isn't
+      significant but its phandle can be used to by an user of the virtio
+      device.
+
+    properties:
+      reg:
+        description:
+          Must contain the Virtio ID of the device.
+        $ref: /schemas/types.yaml#/definitions/uint32
+
+    required:
+      - reg
+
 required:
   - compatible
   - reg
@@ -57,4 +82,20 @@ additionalProperties: false
         #iommu-cells = <1>;
     };
 
+  - |
+    #include <dt-bindings/virtio/virtio_ids.h>
+
+    virtio@3200 {
+        compatible = "virtio,mmio";
+        reg = <0x3200 0x100>;
+        interrupts = <43>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        i2c-virtio@0 {
+            reg = <VIRTIO_ID_I2C_ADAPTER>;
+        };
+    };
+
 ...
include/dt-bindings/virtio/virtio_ids.h new file +1 -0
new file mode 120000
index 000000000000..6e59ba332216
@@ -0,0 +1 @@
+../../uapi/linux/virtio_ids.h
\ No newline at end of file
Signature · 1 line
2.31.1.272.g89b43f80a514
#2 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Documentation/devicetree/bindings/virtio/mmio.yaml additionalProperties: false · line 99

Quoted 13 lines · Viresh Kumar
Documentation/devicetree/bindings/virtio/mmio.yaml +13 -0
+
+    virtio@3200 {
+        compatible = "virtio,mmio";
+        reg = <0x3200 0x100>;
+        interrupts = <43>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        i2c-virtio@0 {
+            reg = <VIRTIO_ID_I2C_ADAPTER>;
+        };
+    };

This works, but it seems oddly inconsistent with the way we do the same thing for PCI, USB and MMC devices that normally don't need device tree properties but can optionally have those.

All of the above use the "compatible" property to identify the device, rather than
using the "reg" property. Neither of them is actually great here, since we already
know what the device is and how to talk to it, but I'd still prefer doing this with

       compatible = "virtio,34";

or similar, where 34 is the numerical value of VIRTIO_ID_I2C_ADAPTER. This would then be required in the virtio-i2c binding.
I think you can skip the #address-cells/#size-cells then.

Arnd

author maintainer
#3 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 27 lines · Arnd Bergmann

Documentation/devicetree/bindings/virtio/mmio.yaml additionalProperties: false · line 99

Quoted 13 lines · Viresh Kumar
Documentation/devicetree/bindings/virtio/mmio.yaml +13 -0
+
+    virtio@3200 {
+        compatible = "virtio,mmio";
+        reg = <0x3200 0x100>;
+        interrupts = <43>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        i2c-virtio@0 {
+            reg = <VIRTIO_ID_I2C_ADAPTER>;
+        };
+    };

This works, but it seems oddly inconsistent with the way we do the same thing for PCI, USB and MMC devices that normally don't need device tree properties but can optionally have those.

All of the above use the "compatible" property to identify the device, rather than
using the "reg" property. Neither of them is actually great here, since we already
know what the device is and how to talk to it, but I'd still prefer doing this with

Quoted 5 lines
       compatible = "virtio,34";

or similar, where 34 is the numerical value of VIRTIO_ID_I2C_ADAPTER. This would then be required in the virtio-i2c binding.
I think you can skip the #address-cells/#size-cells then.

That works, sure.

I think I misunderstood it when you said it earlier and thought that you are asking to add compatible in the parent node itself and so did it this way.

Though that may be the way we will end up doing it now :)

Signature · 1 line
viresh
#4 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

In reply to Viresh Kumar
Quoted 4 lines · Viresh Kumar

Allow virtio,mmio nodes to contain device specific subnodes. Since each virtio,mmio node can represent a single virtio device, each virtio node is allowed to contain a maximum of one device specific subnode.

Doesn't sound like we need 2 nodes here. Just add I2C devices as child nodes. You could add a more specific compatible string, but the protocol is discoverable, so that shouldn't be necessary.

BTW, what's the usecase for these protocols? A standard interface to firmware controlled I2C, GPIO, etc.?

Quoted 79 lines

The device subnode must have the "reg" property, and its value must match the virtio device ID used by the virtio mmio node.

A phandle to this device subnode can then be used by the users of the virtio device.

Also add a symbolic link to uapi/linux/virtio_ids.h in order to use the definitions here.

---
 .../devicetree/bindings/virtio/mmio.yaml      | 41 +++++++++++++++++++
 include/dt-bindings/virtio/virtio_ids.h       |  1 +
 2 files changed, 42 insertions(+)
 create mode 120000 include/dt-bindings/virtio/virtio_ids.h
Documentation/devicetree/bindings/virtio/mmio.yaml +41 -0
index d46597028cf1..e5f9fe6ecb5e 100644
@@ -31,6 +31,31 @@ title: virtio memory mapped devices
     description: Required for devices making accesses thru an IOMMU.
     maxItems: 1
 
+  "#address-cells":
+    const: 1
+    description:
+      The cell is the device ID if a device subnode is used.
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  '^[a-z0-9]+-virtio@[0-9]+$':
+    type: object
+    description: |
+      Exactly one node describing the virtio device. The name of the node isn't
+      significant but its phandle can be used to by an user of the virtio
+      device.
+
+    properties:
+      reg:
+        description:
+          Must contain the Virtio ID of the device.
+        $ref: /schemas/types.yaml#/definitions/uint32
+
+    required:
+      - reg
+
 required:
   - compatible
   - reg
@@ -57,4 +82,20 @@ additionalProperties: false
         #iommu-cells = <1>;
     };
 
+  - |
+    #include <dt-bindings/virtio/virtio_ids.h>
+
+    virtio@3200 {
+        compatible = "virtio,mmio";
+        reg = <0x3200 0x100>;
+        interrupts = <43>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        i2c-virtio@0 {
+            reg = <VIRTIO_ID_I2C_ADAPTER>;
+        };
+    };
+
...
include/dt-bindings/virtio/virtio_ids.h new file +0 -0
new file mode 120000
index 000000000000..6e59ba332216

include/dt-bindings/virtio/virtio_ids.h line 1

Quoted 1 line
include/dt-bindings/virtio/virtio_ids.h new file +1 -0
@@ -0,0 +1 @@
+../../uapi/linux/virtio_ids.h

This will break the devicetree-rebasing tree I think. DT files shouldn't reference kernel files.

Rob

author maintainer
#5 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 9 lines · Rob Herring
Quoted 4 lines · Viresh Kumar

Allow virtio,mmio nodes to contain device specific subnodes. Since each virtio,mmio node can represent a single virtio device, each virtio node is allowed to contain a maximum of one device specific subnode.

Doesn't sound like we need 2 nodes here. Just add I2C devices as child nodes. You could add a more specific compatible string, but the protocol is discoverable, so that shouldn't be necessary.

I am not sure if it will be a problem, but you can clarify it better.

The parent node (virtio,mmio) is used to create a platform device, virtio-mmio, (and so assigned as its of_node) and we create the virtio-device from probe() of this virtio-mmio device.

Is it going to be a problem if two devices in kernel use the same of_node ? Are there cases where we would need to get the device pointer from the of_node ? Then we will have two here.

Quoted 2 lines

BTW, what's the usecase for these protocols? A standard interface to firmware controlled I2C, GPIO, etc.?

Right now we are looking to control devices in the host machine from guests. That's what Linaro's project stratos is doing. There are other people who want to use this for other kind of remote control stuff, maybe from firmware.

Quoted 10 lines

include/dt-bindings/virtio/virtio_ids.h line 1

Quoted 7 lines
include/dt-bindings/virtio/virtio_ids.h new file +1 -0
new file mode 120000
index 000000000000..6e59ba332216
@@ -0,0 +1 @@
+../../uapi/linux/virtio_ids.h

This will break the devicetree-rebasing tree I think. DT files shouldn't reference kernel files.

We already do this for linux-event-codes.h and so I thought it is the right way of doing it :)

Else we can create a new copy, which will be a mess, or use hardcoded values.

Signature · 1 line
viresh
#6 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 12 lines · Viresh Kumar
Quoted 9 lines · Rob Herring
Quoted 4 lines · Viresh Kumar

Allow virtio,mmio nodes to contain device specific subnodes. Since each virtio,mmio node can represent a single virtio device, each virtio node is allowed to contain a maximum of one device specific subnode.

Doesn't sound like we need 2 nodes here. Just add I2C devices as child nodes. You could add a more specific compatible string, but the protocol is discoverable, so that shouldn't be necessary.

Quoted 8 lines

I am not sure if it will be a problem, but you can clarify it better.

The parent node (virtio,mmio) is used to create a platform device, virtio-mmio, (and so assigned as its of_node) and we create the virtio-device from probe() of this virtio-mmio device.

Is it going to be a problem if two devices in kernel use the same of_node ?

There shouldn't be. We have nodes be multiple providers (e.g clocks and resets) already.

Quoted 2 lines

Are there cases where we would need to get the device pointer from the of_node ? Then we will have two here.

Rarely...

In any case, should these potential kernel issues be dictating the DT binding design? No!

Quoted 8 lines
Quoted 3 lines

BTW, what's the usecase for these protocols? A standard interface to firmware controlled I2C, GPIO, etc.?

Right now we are looking to control devices in the host machine from guests. That's what Linaro's project stratos is doing. There are other people who want to use this for other kind of remote control stuff, maybe from firmware.

Project stratos means nothing to me.

Direct userspace access to I2C, GPIO, etc. has its issues, we're going to repeat that with guests?

Quoted 11 lines
Quoted 10 lines

include/dt-bindings/virtio/virtio_ids.h line 1

Quoted 7 lines
include/dt-bindings/virtio/virtio_ids.h new file +1 -0
new file mode 120000
index 000000000000..6e59ba332216
@@ -0,0 +1 @@
+../../uapi/linux/virtio_ids.h

This will break the devicetree-rebasing tree I think. DT files shouldn't reference kernel files.

Quoted 2 lines

We already do this for linux-event-codes.h and so I thought it is the right way of doing it :)

Humm, maybe it's okay. Please double check then...

Quoted 2 lines

Else we can create a new copy, which will be a mess, or use hardcoded values.

Though you may not need the header based on what Arnd and I have suggested.

Rob

#7 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 19 lines · Rob Herring
Quoted 18 lines · Viresh Kumar
Quoted 9 lines · Rob Herring
Quoted 4 lines · Viresh Kumar

Allow virtio,mmio nodes to contain device specific subnodes. Since each virtio,mmio node can represent a single virtio device, each virtio node is allowed to contain a maximum of one device specific subnode.

Doesn't sound like we need 2 nodes here. Just add I2C devices as child nodes. You could add a more specific compatible string, but the protocol is discoverable, so that shouldn't be necessary.

I am not sure if it will be a problem, but you can clarify it better.

The parent node (virtio,mmio) is used to create a platform device, virtio-mmio, (and so assigned as its of_node) and we create the virtio-device from probe() of this virtio-mmio device.

Quoted 5 lines
Quoted 2 lines

Is it going to be a problem if two devices in kernel use the same of_node ?

There shouldn't be. We have nodes be multiple providers (e.g clocks and resets) already.

I think this would be a little different, but it can still work. There is in fact already some precedent of doing this, with Jean-Philippe's virtio-iommu binding, which is documented in both

Documentation/devicetree/bindings/virtio/iommu.txt Documentation/devicetree/bindings/virtio/mmio.txt

Unfortunately, those are still slightly different from where I think we should be going here, but it's probably close enough to fit into the general system.

What we have with virtio-iommu is two special hacks:
- on virtio-mmio, a node with 'compatible="virtio,mmio"' may optionally have an '#iommu-cells=<1>', in which case we assume it's an iommu.
- for virtio-pci, the node has the standard PCI 'reg' property but a special 'compatible="virtio,pci-iommu"' property that I think is different from any other PCI node.

I think for other virtio devices, we should come up with a way to define a binding per device (i2c, gpio, ...) without needing to cram this into the "virtio,mmio" binding or coming up with special compatible strings for PCI devices.

Having a child device for the virtio device type gives a better separation here, since it lets you have two nodes with 'compatible' strings that each make sense for their respective parent buses: The parent is either a PCI device or a plain mmio based device, and the child is a virtio device with its own namespace for compatible values. As you say, the downside is that this requires an extra node that is redundant because there is always a 1:1 relation with its parent.

Having a combined node gets rid of the redundancy but if we want to identify the device for the purpose of defining a custom binding, it would have to have two compatible strings, something like

compatible="virtio,mmio", "virtio,device34";

for a virtio-mmio device of device-id 34 (i2c), or a PCI device with

compatible="pci1af4,1041", "virtio,device34";

which also does not quite feel right.

Quoted 13 lines
Quoted 5 lines · Viresh Kumar
Quoted 1 line · Rob Herring

On Tue, Jul 13, 2021 at 4:50 AM Viresh Kumar <[email protected]> wrote:

Quoted 7 lines
Quoted 2 lines

BTW, what's the usecase for these protocols? A standard interface to firmware controlled I2C, GPIO, etc.?

Right now we are looking to control devices in the host machine from guests. That's what Linaro's project stratos is doing. There are other people who want to use this for other kind of remote control stuff, maybe from firmware.

Quoted 4 lines

Project stratos means nothing to me.

Direct userspace access to I2C, GPIO, etc. has its issues, we're going to repeat that with guests?

Passing through the i2c or gpio access from a Linux host is just one way to use it, you could do the same with an emulated i2c device from qemu, and you could have a fake i2c device behind a virtio-i2c controller.

Arnd

author maintainer
#8 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 39 lines · Arnd Bergmann
Quoted 2 lines · Rob Herring

There shouldn't be. We have nodes be multiple providers (e.g clocks and resets) already.

I think this would be a little different, but it can still work. There is in fact already some precedent of doing this, with Jean-Philippe's virtio-iommu binding, which is documented in both

Documentation/devicetree/bindings/virtio/iommu.txt Documentation/devicetree/bindings/virtio/mmio.txt

Unfortunately, those are still slightly different from where I think we should be going here, but it's probably close enough to fit into the general system.

What we have with virtio-iommu is two special hacks:
- on virtio-mmio, a node with 'compatible="virtio,mmio"' may optionally have an '#iommu-cells=<1>', in which case we assume it's an iommu.
- for virtio-pci, the node has the standard PCI 'reg' property but a special 'compatible="virtio,pci-iommu"' property that I think is different from any other PCI node.

I think for other virtio devices, we should come up with a way to define a binding per device (i2c, gpio, ...) without needing to cram this into the "virtio,mmio" binding or coming up with special compatible strings for PCI devices.

Having a child device for the virtio device type gives a better separation here, since it lets you have two nodes with 'compatible' strings that each make sense for their respective parent buses: The parent is either a PCI device or a plain mmio based device, and the child is a virtio device with its own namespace for compatible values. As you say, the downside is that this requires an extra node that is redundant because there is always a 1:1 relation with its parent.

Having a combined node gets rid of the redundancy but if we want to identify the device for the purpose of defining a custom binding, it would have to have two compatible strings, something like

Quoted 7 lines

compatible="virtio,mmio", "virtio,device34";

for a virtio-mmio device of device-id 34 (i2c), or a PCI device with

compatible="pci1af4,1041", "virtio,device34";

which also does not quite feel right.

I agree that even if the device is discoverable at runtime, we should still have some sort of stuff in DT to distinguish the devices, and "virtio,deviceDID" sounds good enough for that, considering that we already do it for USB, etc.

And I am fine with both the ways, a new node or just using the parent node. So whatever you guys decide is fine.

Quoted 7 lines
Quoted 2 lines

Direct userspace access to I2C, GPIO, etc. has its issues, we're going to repeat that with guests?

Passing through the i2c or gpio access from a Linux host is just one way to use it, you could do the same with an emulated i2c device from qemu, and you could have a fake i2c device behind a virtio-i2c controller.

Or it can be firmware controlled device as well, as Rob said earlier. I think that's what Vincent will be doing for SCMI.

Though all I have tested until now is direct userspace access.

Signature · 1 line
viresh
author maintainer
#9 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 7 lines · Viresh Kumar

I agree that even if the device is discoverable at runtime, we should still have some sort of stuff in DT to distinguish the devices, and "virtio,deviceDID" sounds good enough for that, considering that we already do it for USB, etc.

And I am fine with both the ways, a new node or just using the parent node. So whatever you guys decide is fine.

I tried to write and see what it would look like after using the existing nodes for mmio/pci and here is what I got. (I couldn't find any virtio-pci bindings and so stayed away from adding any reference to it here).

Does that look better ?

Signature · 3 lines
viresh

-------------------------8<-------------------------
Documentation/devicetree/bindings/virtio/mmio.yaml +3 -2
index d46597028cf1..324b810e51a5 100644
@@ -15,7 +15,8 @@ title: virtio memory mapped devices
 
 properties:
   compatible:
-    const: virtio,mmio
+    contains:
+      const: virtio,mmio
 
   reg:
     maxItems: 1
@@ -36,7 +37,7 @@ title: virtio memory mapped devices
   - reg
   - interrupts
 
-additionalProperties: false
+additionalProperties: true
 
 examples:
   - |
Documentation/devicetree/bindings/virtio/virtio-device.yaml new file +49 -0

49 lines not on this page · raw message

Documentation/devicetree/bindings/gpio/gpio-virtio.yaml new file +63 -0

63 lines not on this page · raw message

Documentation/devicetree/bindings/i2c/i2c-virtio.yaml new file +54 -0

54 lines not on this page · raw message

#10 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

In reply to Arnd Bergmann
Quoted 17 lines · Arnd Bergmann
Quoted 5 lines
Quoted 2 lines

Is it going to be a problem if two devices in kernel use the same of_node ?

There shouldn't be. We have nodes be multiple providers (e.g clocks and resets) already.

I think this would be a little different, but it can still work. There is in fact already some precedent of doing this, with Jean-Philippe's virtio-iommu binding, which is documented in both

Documentation/devicetree/bindings/virtio/iommu.txt Documentation/devicetree/bindings/virtio/mmio.txt

Unfortunately, those are still slightly different from where I think we should be going here, but it's probably close enough to fit into the general system.

Quoted 6 lines

What we have with virtio-iommu is two special hacks:
- on virtio-mmio, a node with 'compatible="virtio,mmio"' may optionally have an '#iommu-cells=<1>', in which case we assume it's an iommu.
- for virtio-pci, the node has the standard PCI 'reg' property but a special 'compatible="virtio,pci-iommu"' property that I think is different from any other PCI node.

Yes in retrospect I don't think the compatible property on the PCI endpoint node is necessary nor useful, we could deprecate it. The OS gets the IOMMU topology information early from 'iommus', 'iommu-map' and '#iommu-cells' properties, which is the only reason we need this PCI endpoint explicitly described in DT. The rest is discovered while probing just like virtio-mmio.

Thanks,
Jean

#11 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

In reply to Arnd Bergmann
Quoted 38 lines · Arnd Bergmann
Quoted 19 lines · Rob Herring
Quoted 18 lines · Viresh Kumar
Quoted 9 lines · Rob Herring
Quoted 4 lines · Viresh Kumar

Allow virtio,mmio nodes to contain device specific subnodes. Since each virtio,mmio node can represent a single virtio device, each virtio node is allowed to contain a maximum of one device specific subnode.

Doesn't sound like we need 2 nodes here. Just add I2C devices as child nodes. You could add a more specific compatible string, but the protocol is discoverable, so that shouldn't be necessary.

I am not sure if it will be a problem, but you can clarify it better.

The parent node (virtio,mmio) is used to create a platform device, virtio-mmio, (and so assigned as its of_node) and we create the virtio-device from probe() of this virtio-mmio device.

Quoted 5 lines
Quoted 2 lines

Is it going to be a problem if two devices in kernel use the same of_node ?

There shouldn't be. We have nodes be multiple providers (e.g clocks and resets) already.

I think this would be a little different, but it can still work. There is in fact already some precedent of doing this, with Jean-Philippe's virtio-iommu binding, which is documented in both

Documentation/devicetree/bindings/virtio/iommu.txt Documentation/devicetree/bindings/virtio/mmio.txt

Unfortunately, those are still slightly different from where I think we should be going here, but it's probably close enough to fit into the general system.

Quoted 6 lines

What we have with virtio-iommu is two special hacks:
- on virtio-mmio, a node with 'compatible="virtio,mmio"' may optionally have an '#iommu-cells=<1>', in which case we assume it's an iommu.
- for virtio-pci, the node has the standard PCI 'reg' property but a special 'compatible="virtio,pci-iommu"' property that I think is different from any other PCI node.

How is that different? PCI device can be a VID/PID compatible or omitted, but can also be a "typical" compatible string.

Quoted 13 lines

I think for other virtio devices, we should come up with a way to define a binding per device (i2c, gpio, ...) without needing to cram this into the "virtio,mmio" binding or coming up with special compatible strings for PCI devices.

Having a child device for the virtio device type gives a better separation here, since it lets you have two nodes with 'compatible' strings that each make sense for their respective parent buses: The parent is either a PCI device or a plain mmio based device, and the child is a virtio device with its own namespace for compatible values. As you say, the downside is that this requires an extra node that is redundant because there is always a 1:1 relation with its parent.

Quoted 5 lines

Having a combined node gets rid of the redundancy but if we want to identify the device for the purpose of defining a custom binding, it would have to have two compatible strings, something like

compatible="virtio,mmio", "virtio,device34";

The order seems backwards here. 'virtio,device34' is more specific. Though I guess the meanings are orthogonal.

Quoted 3 lines

for a virtio-mmio device of device-id 34 (i2c), or a PCI device with

compatible="pci1af4,1041", "virtio,device34";

But this seems the right order. Though does '1041' have any specific meaning or device IDs are just dynamically assigned? It seems to be the latter from my brief scan of the code.

Quoted 1 line

which also does not quite feel right.

I guess it comes down to is 'virtio,mmio' providing a bus or is it just a device? I guess a bus (so 2 nodes) does make sense here. 'virtio,mmio' defines how you access/discover the virtio queues (the bus) and the functional device (i2c, gpio, iommu, etc.) is accessed via the virtio queues.

Rob

#12 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 10 lines · Rob Herring
Quoted 8 lines · Arnd Bergmann

On Tue, Jul 13, 2021 at 9:35 PM Rob Herring <[email protected]> wrote:

What we have with virtio-iommu is two special hacks:
- on virtio-mmio, a node with 'compatible="virtio,mmio"' may optionally have an '#iommu-cells=<1>', in which case we assume it's an iommu.
- for virtio-pci, the node has the standard PCI 'reg' property but a special 'compatible="virtio,pci-iommu"' property that I think is different from any other PCI node.

Quoted 2 lines

How is that different? PCI device can be a VID/PID compatible or omitted, but can also be a "typical" compatible string.

Ok, my mistake then, I though the VID/PID compatible was mandated

Quoted 13 lines
Quoted 13 lines

I think for other virtio devices, we should come up with a way to define a binding per device (i2c, gpio, ...) without needing to cram this into the "virtio,mmio" binding or coming up with special compatible strings for PCI devices.

Having a child device for the virtio device type gives a better separation here, since it lets you have two nodes with 'compatible' strings that each make sense for their respective parent buses: The parent is either a PCI device or a plain mmio based device, and the child is a virtio device with its own namespace for compatible values. As you say, the downside is that this requires an extra node that is redundant because there is always a 1:1 relation with its parent.

Quoted 8 lines
Quoted 5 lines

Having a combined node gets rid of the redundancy but if we want to identify the device for the purpose of defining a custom binding, it would have to have two compatible strings, something like

compatible="virtio,mmio", "virtio,device34";

The order seems backwards here. 'virtio,device34' is more specific. Though I guess the meanings are orthogonal.

Right, one defines the transport and the other defines the device behind the transport.

Quoted 7 lines
Quoted 3 lines

for a virtio-mmio device of device-id 34 (i2c), or a PCI device with

compatible="pci1af4,1041", "virtio,device34";

But this seems the right order. Though does '1041' have any specific meaning or device IDs are just dynamically assigned? It seems to be the latter from my brief scan of the code.

It's the assigned PCI vendor/device pair for virtio, all virtio-pci devices have to be "pci1af4,1041", just like all virtio-mmio devices are "virtio,mmio".

Quoted 7 lines
Quoted 1 line

which also does not quite feel right.

I guess it comes down to is 'virtio,mmio' providing a bus or is it just a device? I guess a bus (so 2 nodes) does make sense here. 'virtio,mmio' defines how you access/discover the virtio queues (the bus) and the functional device (i2c, gpio, iommu, etc.) is accessed via the virtio queues.

It's not really a bus since there is only ever one device behind it. A better analogy would be your 'serdev' framework: You could have a 8250 or a pl011 uart, and behind that have a mouse, GPS receiver or bluetooth dongle.

In Documentation/devicetree/bindings/serial/serial.yaml, you also have two nodes for a single device, so we could follow that example.

Arnd

author maintainer
#13 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Rob Herring

I guess it comes down to is 'virtio,mmio' providing a bus or is it just a device? I guess a bus (so 2 nodes) does make sense here. 'virtio,mmio' defines how you access/discover the virtio queues (the bus) and the functional device (i2c, gpio, iommu, etc.) is accessed via the virtio queues.

Quoted 8 lines

It's not really a bus since there is only ever one device behind it. A better analogy would be your 'serdev' framework: You could have a 8250 or a pl011 uart, and behind that have a mouse, GPS receiver or bluetooth dongle.

In Documentation/devicetree/bindings/serial/serial.yaml, you also have two nodes for a single device, so we could follow that example.

So two device nodes is final then ? Pretty much like how this patchset did it already ? I need to get rid of reg thing and use "virtio,DID" though.

Signature · 1 line
viresh
#14 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

Quoted 13 lines · Viresh Kumar
Quoted 12 lines · Arnd Bergmann
Quoted 5 lines · Rob Herring

I guess it comes down to is 'virtio,mmio' providing a bus or is it just a device? I guess a bus (so 2 nodes) does make sense here. 'virtio,mmio' defines how you access/discover the virtio queues (the bus) and the functional device (i2c, gpio, iommu, etc.) is accessed via the virtio queues.

It's not really a bus since there is only ever one device behind it. A better analogy would be your 'serdev' framework: You could have a 8250 or a pl011 uart, and behind that have a mouse, GPS receiver or bluetooth dongle.

Quoted 6 lines
Quoted 3 lines

In Documentation/devicetree/bindings/serial/serial.yaml, you also have two nodes for a single device, so we could follow that example.

So two device nodes is final then ? Pretty much like how this patchset did it already ? I need to get rid of reg thing and use "virtio,DID" though.

Let's give Rob another day to reply here. I think two nodes is easier to get working than one node, even when we continue supporting the current iommu binding that relies on a single node, but we could make it work either way if necessary.

Arnd

author maintainer
#15 lore raw

Re: [PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode

In reply to Rob Herring
Quoted 10 lines · Rob Herring
Quoted 2 lines · Viresh Kumar

We already do this for linux-event-codes.h and so I thought it is the right way of doing it :)

Humm, maybe it's okay. Please double check then...

Quoted 2 lines

Else we can create a new copy, which will be a mess, or use hardcoded values.

Though you may not need the header based on what Arnd and I have suggested.

Yeah, we may not need it at all. New node or not, reg property will get converted to a compatible anyway..

Thanks.

Signature · 1 line
viresh
author maintainer
#16 lore raw

PATCH 2/5 virtio_mmio: Bind virtio device to device-tree node

In reply to Viresh Kumar

Bind the virtio device with its device protocol's sub-node. This will help users of the virtio device to mention their dependencies on the device in the DT file itself. Like GPIO pin users can use the phandle of the device node, or the node may contain more subnodes to add i2c or spi eeproms and other users.

---
 drivers/virtio/virtio_mmio.c | 44 ++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
drivers/virtio/virtio_mmio.c +44 -0
index 56128b9c46eb..ae40546a66a3 100644
@@ -551,11 +551,51 @@ static void virtio_mmio_release_dev(struct device *_d)
 	struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
 	struct platform_device *pdev = vm_dev->pdev;
 
+	of_node_put(vdev->dev.of_node);
 	devm_kfree(&pdev->dev, vm_dev);
 }
 
 /* Platform device */
 
+static int virtio_mmio_of_init(struct virtio_device *vdev)
+{
+	struct device_node *np, *pnode = vdev->dev.parent->of_node;
+	int ret, count;
+	u32 reg;
+
+	if (!pnode)
+		return 0;
+
+	count = of_get_available_child_count(pnode);
+	if (!count)
+		return 0;
+
+	/* There can be only 1 child node */
+	if (WARN_ON(count > 1))
+		return -EINVAL;
+
+	np = of_get_next_available_child(pnode, NULL);
+	if (WARN_ON(!np))
+		return -ENODEV;
+
+	ret = of_property_read_u32(np, "reg", &reg);
+	if (ret < 0)
+		goto out;
+
+	/* The reg field should match the device id */
+	if (WARN_ON(reg != vdev->id.device)) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	vdev->dev.of_node = np;
+	return 0;
+
+out:
+	of_node_put(np);
+	return ret;
+}
+
 static int virtio_mmio_probe(struct platform_device *pdev)
 {
 	struct virtio_mmio_device *vm_dev;
@@ -621,6 +661,10 @@ static int virtio_mmio_probe(struct platform_device *pdev)
 	if (rc)
 		dev_warn(&pdev->dev, "Failed to enable 64-bit or 32-bit DMA.  Trying to continue, but this might not work.\n");
 
+	rc = virtio_mmio_of_init(&vm_dev->vdev);
+	if (rc)
+		return rc;
+
 	platform_set_drvdata(pdev, vm_dev);
 
 	rc = register_virtio_device(&vm_dev->vdev);
Signature · 1 line
2.31.1.272.g89b43f80a514
#17 lore raw

Re: [PATCH 2/5] virtio_mmio: Bind virtio device to device-tree node

Quoted 11 lines · Viresh Kumar

Bind the virtio device with its device protocol's sub-node. This will help users of the virtio device to mention their dependencies on the device in the DT file itself. Like GPIO pin users can use the phandle of the device node, or the node may contain more subnodes to add i2c or spi eeproms and other users.

---
 drivers/virtio/virtio_mmio.c | 44 ++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Hi Viresh,

I don't see anything in this patch that is specific to virtio-mmio, as opposed to
virtio-pci. It would be better to move this into the virtio core code so it can be called independently of the transport that is used for virtio.

The PCI code has similar code that will set vdev->dev.parent->of_node for a virtio-pci device, as long as that node is present.

Arnd

author maintainer
#18 lore raw

Re: [PATCH 2/5] virtio_mmio: Bind virtio device to device-tree node

Quoted 15 lines · Arnd Bergmann
Quoted 11 lines · Viresh Kumar

Bind the virtio device with its device protocol's sub-node. This will help users of the virtio device to mention their dependencies on the device in the DT file itself. Like GPIO pin users can use the phandle of the device node, or the node may contain more subnodes to add i2c or spi eeproms and other users.

---
 drivers/virtio/virtio_mmio.c | 44 ++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Hi Viresh,

Quoted 7 lines

I don't see anything in this patch that is specific to virtio-mmio, as opposed to
virtio-pci. It would be better to move this into the virtio core code so it can be called independently of the transport that is used for virtio.

The PCI code has similar code that will set vdev->dev.parent->of_node for a virtio-pci device, as long as that node is present.

Sure.

Signature · 1 line
viresh
author maintainer
#19 lore raw

PATCH 3/5 dt-bindings: i2c: Add bindings for i2c-virtio

In reply to Viresh Kumar

i2c-virtio represents a virtio I2C device and this patch adds binding for the same. The i2c-virtio subnode can be part of a virtio,mmio node and is based on its binding.

---
 .../devicetree/bindings/i2c/i2c-virtio.yaml   | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-virtio.yaml
Documentation/devicetree/bindings/i2c/i2c-virtio.yaml new file +59 -0
new file mode 100644
index 000000000000..6b6538f9a3d8
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/i2c/i2c-virtio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Virtio memory mapped I2C Adapter
+
+maintainers:
+  - Viresh Kumar <[email protected]>
+
+description:
+  Virtio I2C device, see /schemas/virtio/mmio.yaml for more details.
+
+allOf:
+  - $ref: /schemas/i2c/i2c-controller.yaml#
+
+properties:
+  $nodename:
+    pattern: '^i2c-virtio@[0-9]+$'
+
+  reg:
+    description:
+      The cell is the device ID of the I2C device (VIRTIO_ID_I2C_ADAPTER) as per
+      dt-bindings/virtio/virtio_ids.h.
+    const: 34
+    $ref: /schemas/virtio/mmio.yaml#/properties/reg
+
+required:
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/virtio/virtio_ids.h>
+
+    virtio@3000 {
+        compatible = "virtio,mmio";
+        reg = <0x3000 0x100>;
+        interrupts = <41>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        i2c-virtio@0 {
+            reg = <VIRTIO_ID_I2C_ADAPTER>;
+
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            light-sensor@1c {
+                compatible = "dynaimage,al3320a";
+                reg = <0x20>;
+            };
+        };
+    };
+
+...
Signature · 1 line
2.31.1.272.g89b43f80a514
maintainer
#20 lore raw

Re: [PATCH 3/5] dt-bindings: i2c: Add bindings for i2c-virtio

Quoted 11 lines · Viresh Kumar

i2c-virtio represents a virtio I2C device and this patch adds binding for the same. The i2c-virtio subnode can be part of a virtio,mmio node and is based on its binding.

---
 .../devicetree/bindings/i2c/i2c-virtio.yaml   | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-virtio.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Unknown file referenced: [Errno 2] No such file or directory: '/usr/local/lib/python3.8/dist-packages/dtschema/schemas/virtio/mmio.yaml'
xargs: dt-doc-validate: exited with status 255; aborting Documentation/devicetree/bindings/i2c/i2c-virtio.example.dts:19:18: fatal error: dt-bindings/virtio/virtio_ids.h: No such file or directory
19 | #include <dt-bindings/virtio/virtio_ids.h>

      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[1]: *** [scripts/Makefile.lib:380: Documentation/devicetree/bindings/i2c/i2c-virtio.example.dt.yaml] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1416: dt_binding_check] Error 2
\ndoc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1504542

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

author maintainer
#21 lore raw

PATCH 4/5 i2c: virtio: Update i2c-adapter's of_node

In reply to Viresh Kumar

Set of_node of the adapter from the virtio device to enable automatic parsing the of the I2C devices present in DT.

---
Depends on:

https://lore.kernel.org/linux-i2c/984ebecaf697058eb73389ed14ead9dd6d38fb53.1625796246.git.jie.deng@intel.com/

---
 drivers/i2c/busses/i2c-virtio.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i2c/busses/i2c-virtio.c +1 -0
index 0139cdc33cae..cb8cfae2748f 100644
@@ -223,6 +223,7 @@ static int virtio_i2c_probe(struct virtio_device *vdev)
 		 "i2c_virtio at virtio bus %d", vdev->index);
 	vi->adap.algo = &virtio_algorithm;
 	vi->adap.dev.parent = &vdev->dev;
+	vi->adap.dev.of_node = vdev->dev.of_node;
 	i2c_set_adapdata(&vi->adap, vi);
 
 	/*
Signature · 6 lines
2.31.1.272.g89b43f80a514

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
author maintainer
#22 lore raw

PATCH 5/5 dt-bindings: gpio: Add bindings for gpio-virtio

In reply to Viresh Kumar

gpio-virtio represents a virtio GPIO controller and this patch adds binding for the same. The gpio-virtio subnode can be part of a virtio,mmio node and is based on its binding.

---
Depends on:

https://lore.kernel.org/lkml/7c716c2eb7ace5b5a560d8502af93101dbb53d24.1626170146.git.viresh.kumar@linaro.org/

---
 .../devicetree/bindings/gpio/gpio-virtio.yaml | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-virtio.yaml
Documentation/devicetree/bindings/gpio/gpio-virtio.yaml new file +67 -0
new file mode 100644
index 000000000000..c813cdfd60fd
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/gpio-virtio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Virtio memory mapped GPIO controller
+
+maintainers:
+  - Viresh Kumar <[email protected]>
+
+description:
+  Virtio GPIO controller, see /schemas/virtio/mmio.yaml for more details.
+
+allOf:
+  - $ref: /schemas/gpio/gpio.yaml#
+
+properties:
+  $nodename:
+    pattern: '^gpio-virtio@[0-9]+$'
+
+  reg:
+    description:
+      The cell is the device ID of the GPIO device (VIRTIO_ID_GPIO) as per
+      dt-bindings/virtio/virtio_ids.h.
+    const: 41
+    $ref: /schemas/virtio/mmio.yaml#/properties/reg
+
+  gpio-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+
+required:
+  - reg
+  - gpio-controller
+  - "#gpio-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/virtio/virtio_ids.h>
+
+    virtio@3000 {
+        compatible = "virtio,mmio";
+        reg = <0x3000 0x100>;
+        interrupts = <41>;
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        gpio-virtio@0 {
+            reg = <VIRTIO_ID_GPIO>;
+            gpio-controller;
+            #gpio-cells = <2>;
+            interrupt-controller;
+            #interrupt-cells = <2>;
+        };
+    };
+
+...
Signature · 1 line
2.31.1.272.g89b43f80a514
maintainer
#23 lore raw

Re: [PATCH 5/5] dt-bindings: gpio: Add bindings for gpio-virtio

Quoted 5 lines · Viresh Kumar

gpio-virtio represents a virtio GPIO controller and this patch adds binding for the same. The gpio-virtio subnode can be part of a virtio,mmio node and is based on its binding.

Quoted 9 lines

---
Depends on:

https://lore.kernel.org/lkml/7c716c2eb7ace5b5a560d8502af93101dbb53d24.1626170146.git.viresh.kumar@linaro.org/

---
 .../devicetree/bindings/gpio/gpio-virtio.yaml | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-virtio.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Unknown file referenced: [Errno 2] No such file or directory: '/usr/local/lib/python3.8/dist-packages/dtschema/schemas/virtio/mmio.yaml'
xargs: dt-doc-validate: exited with status 255; aborting Documentation/devicetree/bindings/gpio/gpio-virtio.example.dts:19:18: fatal error: dt-bindings/virtio/virtio_ids.h: No such file or directory
19 | #include <dt-bindings/virtio/virtio_ids.h>

      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[1]: *** [scripts/Makefile.lib:380: Documentation/devicetree/bindings/gpio/gpio-virtio.example.dt.yaml] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1416: dt_binding_check] Error 2
\ndoc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1504545

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

#24 lore raw

Re: [PATCH 5/5] dt-bindings: gpio: Add bindings for gpio-virtio

In reply to Viresh Kumar
Quoted 74 lines · Viresh Kumar

gpio-virtio represents a virtio GPIO controller and this patch adds binding for the same. The gpio-virtio subnode can be part of a virtio,mmio node and is based on its binding.

---
Depends on:

https://lore.kernel.org/lkml/7c716c2eb7ace5b5a560d8502af93101dbb53d24.1626170146.git.viresh.kumar@linaro.org/

---
 .../devicetree/bindings/gpio/gpio-virtio.yaml | 67 +++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-virtio.yaml
Documentation/devicetree/bindings/gpio/gpio-virtio.yaml new file +53 -0
new file mode 100644
index 000000000000..c813cdfd60fd
@@ -0,0 +1,67 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/gpio-virtio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Virtio memory mapped GPIO controller
+
+maintainers:
+  - Viresh Kumar <[email protected]>
+
+description:
+  Virtio GPIO controller, see /schemas/virtio/mmio.yaml for more details.
+
+allOf:
+  - $ref: /schemas/gpio/gpio.yaml#
+
+properties:
+  $nodename:
+    pattern: '^gpio-virtio@[0-9]+$'
+
+  reg:
+    description:
+      The cell is the device ID of the GPIO device (VIRTIO_ID_GPIO) as per
+      dt-bindings/virtio/virtio_ids.h.
+    const: 41
+    $ref: /schemas/virtio/mmio.yaml#/properties/reg
+
+  gpio-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+
+required:
+  - reg
+  - gpio-controller
+  - "#gpio-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/virtio/virtio_ids.h>
+
+    virtio@3000 {
+        compatible = "virtio,mmio";
+        reg = <0x3000 0x100>;
+        interrupts = <41>;

Documentation/devicetree/bindings/gpio/gpio-virtio.yaml line 63

Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-virtio.yaml new file +10 -0
+
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        gpio-virtio@0 {
+            reg = <VIRTIO_ID_GPIO>;
+            gpio-controller;
+            #gpio-cells = <2>;
+            interrupt-controller;
+            #interrupt-cells = <2>;

Similar to I2C, all this can just be added to the parent node.

Rob