hw/virtio: Add PCIe capability to virtio devices
RFC PATCH 1/1 hw/virtio: Add PCIe capability to virtio devices
The virtio devices are converted to PCI-Express
if they are plugged into a PCI-Express bus and
the 'modern' protocol is enabled.
---
This is an RFC because all it does it adds the PCIe capability and nothing more. I post it early so I can get feedbacks on what is the best way to continue it.
Any comments would be appreciated,
Thanks,
Marcel
hw/virtio/virtio-pci.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
hw/virtio/virtio-pci.c +11 -0
@@ -1591,6 +1591,17 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)address_space_init (&proxy->modern_as, &proxy->modern_cfg,"virtio-pci-cfg-as" ); +if (!(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN ) + &&pci_bus_is_express (pci_dev->bus)) { +int pos =pci_add_capability (pci_dev,PCI_CAP_ID_EXP ,0 , +PCI_EXP_VER2_SIZEOF ); + +if (pos >0 ) { + pci_dev->exp.exp_cap = pos; + pci_dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; + } + } +virtio_pci_bus_new (&proxy->bus,sizeof (proxy->bus), proxy);if (k->realize) { k->realize (proxy, errp);
Signature · 1 line
2.1.0
Quoted 8 lines · Marcel Apfelbaum
The virtio devices are converted to PCI-Express
if they are plugged into a PCI-Express bus and
the 'modern' protocol is enabled.Signed-off-by Marcel Apfelbaum <[email protected]>---
This is an RFC because all it does it adds the PCIe capability and nothing more.
Express capability is easy.
But if you go over express space you will see that a bunch of other capabilities are required, such as PM capability etc. These might need more work.
Quoted 14 lines
I post it early so I can get feedbacks on what is the best way to continue it.
Any comments would be appreciated,
Thanks,
Marcelhw/virtio/virtio-pci.c | 11 +++++++++++ 1 file changed, 11 insertions(+)hw/virtio/virtio-pci.c +0
-0
hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1595
Quoted 5 lines
hw/virtio/virtio-pci.c +2
-0@@ -1591,6 +1591,17 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)address_space_init (&proxy->modern_as, &proxy->modern_cfg,"virtio-pci-cfg-as" ); +if (!(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN ) + &&pci_bus_is_express (pci_dev->bus)) {
One point: we probably want to avoid doing this for integrated devices on root bus. Does pci_bus_is_express return true there?
hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1599
Quoted 4 lines
hw/virtio/virtio-pci.c +4
-0+int pos =pci_add_capability (pci_dev,PCI_CAP_ID_EXP ,0 , +PCI_EXP_VER2_SIZEOF ); + +if (pos >0 ) {
We probably want to assert on pos < 0 instead.
That implies a code bug.
Quoted 10 lines
hw/virtio/virtio-pci.c +5
-0+ pci_dev->exp.exp_cap = pos; + pci_dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; + } + } +virtio_pci_bus_new (&proxy->bus,sizeof (proxy->bus), proxy);if (k->realize) { k->realize (proxy, errp);Signature · 1 line
2.1.0
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Marcel Apfelbaum
The virtio devices are converted to PCI-Express
if they are plugged into a PCI-Express bus and
the 'modern' protocol is enabled.Signed-off-by Marcel Apfelbaum <[email protected]>---
Quoted 6 lines
Quoted 1 line
This is an RFC because all it does it adds the PCIe capability and nothing more.
Express capability is easy.
But if you go over express space you will see that a bunch of other capabilities are required, such as PM capability etc. These might need more work.
Also what about the legacy io bar? I guess we'd better avoid that for express devices.
Maybe it makes sense to add virtio-*-pcie devices (virtio-1.0 only, with pcie caps)?
cheers,
Gerd
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Marcel Apfelbaum
The virtio devices are converted to PCI-Express
if they are plugged into a PCI-Express bus and
the 'modern' protocol is enabled.Signed-off-by Marcel Apfelbaum <[email protected]>---
This is an RFC because all it does it adds the PCIe capability and nothing more.
Quoted 7 lines
Quoted 4 lines
Express capability is easy.
But if you go over express space you will see that a bunch of other capabilities are required, such as PM capability etc. These might need more work.Also what about the legacy io bar? I guess we'd better avoid that for express devices.
This needs some thought. We definitely still want a way to enable it I think, e.g. for old guests.
Quoted 5 lines
Maybe it makes sense to add virtio-*-pcie devices (virtio-1.0 only, with pcie caps)?
cheers,
Gerd
Personally I think it's ugly enough to remember the need to specify -pci. OTOH the need to specify upstream and downstream ports is even uglier. Any idea how to address both issues at the same time?
Signature · 1 line
MST
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Marcel Apfelbaum
The virtio devices are converted to PCI-Express
if they are plugged into a PCI-Express bus and
the 'modern' protocol is enabled.Signed-off-by Marcel Apfelbaum <[email protected] <javascript:;>>---
Quoted 7 lines
Quoted 1 line
This is an RFC because all it does it adds the PCIe capability and
nothing more.
Express capability is easy.
But if you go over express space you will see that a bunch of other capabilities are required, such as PM capability etc. These might need more work.
Sure, I'll look on the PCIe spec for the minimum requirements.
Quoted 18 lines
Quoted 2 lines
I post it early so I can get feedbacks on what is the best way to
continue it.
hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice
Quoted 13 lines
Any comments would be appreciated,
Thanks,
Marcelhw/virtio/virtio-pci.c | 11 +++++++++++ 1 file changed, 11 insertions(+)hw/virtio/virtio-pci.c +0
-0@@ -1591,6 +1591,17 @@ static void virtio_pci_realize(PCIDevice
*pci_dev, Error **errp)Quoted 1 line
Quoted 8 lines
Quoted 1 line
address_space_init(&proxy->modern_as, &proxy->modern_cfg,"virtio-pci-cfg-as");
hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1595
Quoted 3 lines
hw/virtio/virtio-pci.c +2
-0+if (!(proxy->flags &VIRTIO_PCI_FLAG_DISABLE_MODERN ) + &&pci_bus_is_express (pci_dev->bus)) {One point: we probably want to avoid doing this for integrated devices on root bus. Does
pci_bus_is_expressreturn true there?
Hmm, I'll check, but I think it does. Is this a must?
Quoted 10 lines
hw/virtio/virtio-pci.c static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) · line 1599
Quoted 5 lines
hw/virtio/virtio-pci.c +4
-0+int pos =pci_add_capability (pci_dev,PCI_CAP_ID_EXP ,0 , +PCI_EXP_VER2_SIZEOF ); + +if (pos >0 ) {We probably want to assert on pos < 0 instead.
That implies a code bug.
I was wondering what to do here, thanks for the idea!
Thanks,
Marcel
Quoted 13 lines
Quoted 11 lines
hw/virtio/virtio-pci.c +5
-1+ pci_dev->exp.exp_cap = pos; + pci_dev->cap_present |=QEMU_PCI_CAP_EXPRESS ; + } + } +virtio_pci_bus_new (&proxy->bus,sizeof (proxy->bus), proxy);if (k->realize) { k->realize (proxy, errp); --2.1.0
Quoted 52 lines · Marcel Apfelbaum
On Monday, October 12, 2015, Michael S. Tsirkin <[email protected]> wrote:
On Mon, Oct 12, 2015 at 06:17:54PM +0300, Marcel Apfelbaum wrote:
> The virtio devices are converted to PCI-Express
> if they are plugged into a PCI-Express bus and
> the 'modern' protocol is enabled.
>
> Signed-off-by: Marcel Apfelbaum <[email protected]>
> ---
>
> This is an RFC because all it does it adds the PCIe capability and nothing more.Express capability is easy.
But if you go over express space you will see that a bunch of other capabilities are required, such as PM capability etc. These might need more work.Sure, I'll look on the PCIe spec for the minimum requirements.
Quoted 1 line
I post it early so I can get feedbacks on what is the best way to
continue it. > > Any comments would be appreciated, > Thanks, > Marcel > > hw/virtio/virtio-pci.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > index 6703806..f7c93d9 100644 > --- a/hw/virtio/virtio-pci.c > +++ b/hw/virtio/virtio-pci.c > @@ -1591,6 +1591,17 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) > > address_space_init(&proxy->modern_as, &proxy->modern_cfg, "virtio-pci-cfg-as"); > > + if (!(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN) > + && pci_bus_is_express(pci_dev->bus)) { One point: we probably want to avoid doing this for integrated devices on root bus. Does pci_bus_is_express return true there?
Quoted 1 line
Hmm, I'll check, but I think it does. Is this a must?
It's probably a smart thing to do because you can't e.g. hot-unplug them. So supporting PCI E capability for integrated devices is probably more work than just making the PCI devices (which is not spec compliant but very popular so guests support this).
Quoted 32 lines
Quoted 6 lines
+ int pos = pci_add_capability(pci_dev,
PCI_CAP_ID_EXP, 0, + PCI_EXP_VER2_SIZEOF); +
+ if (pos > 0) {We probably want to assert on pos < 0 instead. That implies a code bug.
I was wondering what to do here, thanks for the idea!
Thanks,
MarcelQuoted 10 lines
+
pci_dev->exp.exp_cap= pos;
+pci_dev->cap_present|=QEMU_PCI_CAP_EXPRESS; + }
+ }
+
virtio_pci_bus_new(&proxy->bus, sizeof(proxy->bus), proxy); if (k->realize) {
k->realize(proxy, errp);
--
2.1.0