Viresh Kumar
2021-Jul-14 02:26 UTC
[PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode
On 13-07-21, 22:34, Arnd Bergmann wrote:> On Tue, Jul 13, 2021 at 9:35 PM Rob Herring <robh+dt at kernel.org> wrote: > > 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.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.> > 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. -- viresh
Viresh Kumar
2021-Jul-14 11:40 UTC
[PATCH 1/5] dt-bindings: virtio: mmio: Add support for device subnode
On 14-07-21, 07:56, Viresh Kumar wrote:> 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 ? -- viresh -------------------------8<------------------------- diff --git a/Documentation/devicetree/bindings/virtio/mmio.yaml b/Documentation/devicetree/bindings/virtio/mmio.yaml index d46597028cf1..324b810e51a5 100644 --- a/Documentation/devicetree/bindings/virtio/mmio.yaml +++ b/Documentation/devicetree/bindings/virtio/mmio.yaml @@ -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: - | diff --git a/Documentation/devicetree/bindings/virtio/virtio-device.yaml b/Documentation/devicetree/bindings/virtio/virtio-device.yaml new file mode 100644 index 000000000000..9cfe090ea65f --- /dev/null +++ b/Documentation/devicetree/bindings/virtio/virtio-device.yaml @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/virtio/virtio-device.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Virtio device bindings + +maintainers: + - Viresh Kumar <viresh.kumar at linaro.org> + +description: + These bindings are applicable to virtio devices irrespective of the bus they + are bound to, like mmio or pci. + +allOf: + - $ref: /schemas/virtio/mmio.yaml# + +# We need a select here so we don't match all nodes with 'virtio,mmio' +select: + properties: + compatible: + contains: + pattern: '^virtio,[0-9]+$' + required: + - compatible + +properties: + compatible: + contains: + oneOf: + - items: + - const: virtio,mmio + - pattern: '^virtio,[0-9]+$' + +required: + - compatible + +additionalProperties: true + +examples: + - | + i2c: i2c-virtio at 3000 { + compatible = "virtio,mmio", "virtio,34"; + reg = <0x3000 0x100>; + interrupts = <41>; + }; + +... diff --git a/Documentation/devicetree/bindings/gpio/gpio-virtio.yaml b/Documentation/devicetree/bindings/gpio/gpio-virtio.yaml new file mode 100644 index 000000000000..8115ba794557 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-virtio.yaml @@ -0,0 +1,63 @@ +# 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 GPIO controller + +maintainers: + - Viresh Kumar <viresh.kumar at linaro.org> + +allOf: + - $ref: /schemas/gpio/gpio.yaml# + - $ref: /schemas/virtio/virtio-device.yaml# + +# We need a select here so we don't match all nodes with 'virtio,mmio' +select: + properties: + compatible: + contains: + enum: + - virtio,41 + required: + - compatible + +properties: + compatible: + oneOf: + - items: + - const: virtio,mmio + - const: virtio,41 + + gpio-controller: true + + "#gpio-cells": + const: 2 + + interrupt-controller: true + + "#interrupt-cells": + const: 2 + +required: + - compatible + - gpio-controller + - "#gpio-cells" + +unevaluatedProperties: false + +examples: + - | + gpio: gpio-virtio at 3000 { + compatible = "virtio,mmio", "virtio,41"; + reg = <0x3000 0x100>; + interrupts = <41>; + + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + +... diff --git a/Documentation/devicetree/bindings/i2c/i2c-virtio.yaml b/Documentation/devicetree/bindings/i2c/i2c-virtio.yaml new file mode 100644 index 000000000000..43e9910920d6 --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/i2c-virtio.yaml @@ -0,0 +1,54 @@ +# 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 I2C Adapter + +maintainers: + - Viresh Kumar <viresh.kumar at linaro.org> + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + - $ref: /schemas/virtio/virtio-device.yaml# + +# We need a select here so we don't match all nodes with 'virtio,mmio' +select: + properties: + compatible: + contains: + enum: + - virtio,34 + required: + - compatible + +properties: + compatible: + oneOf: + - items: + - const: virtio,mmio + - const: virtio,34 + +required: + - compatible + +unevaluatedProperties: false + +examples: + - | + i2c: i2c-virtio at 3000 { + compatible = "virtio,mmio", "virtio,34"; + reg = <0x3000 0x100>; + interrupts = <41>; + + #address-cells = <1>; + #size-cells = <0>; + + light-sensor at 1c { + compatible = "dynaimage,al3320a"; + reg = <0x20>; + }; + }; + +...