From: David Gibson <david@gibson.dropbear.id.au>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: aik@ozlabs.ru, marcel@redhat.com, lersek@redhat.com,
qemu-ppc@nongnu.org, qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour
Date: Tue, 18 Apr 2017 12:21:51 +1000 [thread overview]
Message-ID: <20170418022151.GD12235@umbus.fritz.box> (raw)
In-Reply-To: <20170417183045.GA7078@thinpad.lan.raisama.net>
[-- Attachment #1: Type: text/plain, Size: 3511 bytes --]
On Mon, Apr 17, 2017 at 03:30:46PM -0300, Eduardo Habkost wrote:
> On Tue, Mar 28, 2017 at 01:16:50PM +1100, David Gibson wrote:
> > Currently PCI/PCIe hybrid devices - that is, devices which can appear as
> > either plain PCI or PCIe depending on where they're attached - will only
> > appear in PCIe mode if they're attached to a PCIe bus via a root port or
> > downstream port.
> >
> > This is correct for "standard" PCIe setups, but there are some platforms
> > which need different behaviour (notably "pseries" whose paravirtualized
> > PCI host bridges have some idiosyncracies).
> >
> > This patch allows the host bridge to override the normal behaviour.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> > hw/pci/pci.c | 11 +++++++++--
> > include/hw/pci/pci_host.h | 1 +
> > 2 files changed, 10 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > index 779787b..ac68065 100644
> > --- a/hw/pci/pci.c
> > +++ b/hw/pci/pci.c
> > @@ -392,9 +392,16 @@ bool pci_bus_is_root(PCIBus *bus)
> >
> > bool pci_allow_hybrid_pcie(PCIDevice *pci_dev)
>
> Why are we asking the device about allowing hybrid pcie, and not
> the bus itself? Shouldn't we be able to query this before the
> device is plugged, and before pci_dev->bus is even set?
>
> In other words, why pci_allow_hyberid_pcie() and
> pci_device_get_bus() get a PCIDevice* argument instead of a
> PCIBus* argument?
Ah good point. I made it a PCIDevice simply for convenience, but
you're right we should be able to query before the device is plugged.
>
> > {
> > - PCIBus *bus = pci_dev->bus;
> > + PCIHostState *host_bridge = PCI_HOST_BRIDGE(pci_device_root_bus(pci_dev)->qbus.parent);
>
> There's something I don't understand completely: what exactly
> guarantees that pci_device_root_bus(...)->qbus.parent is always
> going to be a PCI_HOST_BRIDGE?
Well, by definition whatever is above the root bus isn't PCI, which
pretty much means it has to be a PCI host bridge. A machine could
break this assumption, but I think that would be a bug. We use this
same pattern to find a PCI device's (or bus's) host bridge in other
places - there doesn't appear to be another way.
> > + PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_GET_CLASS(host_bridge);
> > +
> > + if (hc->allow_hybrid_pcie) {
> > + return hc->allow_hybrid_pcie(host_bridge, pci_dev);
> > + } else {
> > + PCIBus *bus = pci_dev->bus;
> >
> > - return pci_bus_is_express(bus) && !pci_bus_is_root(bus);
> > + return pci_bus_is_express(bus) && !pci_bus_is_root(bus);
> > + }
> > }
> >
> > void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
> > diff --git a/include/hw/pci/pci_host.h b/include/hw/pci/pci_host.h
> > index ba31595..ad03cca 100644
> > --- a/include/hw/pci/pci_host.h
> > +++ b/include/hw/pci/pci_host.h
> > @@ -54,6 +54,7 @@ typedef struct PCIHostBridgeClass {
> > SysBusDeviceClass parent_class;
> >
> > const char *(*root_bus_path)(PCIHostState *, PCIBus *);
> > + bool (*allow_hybrid_pcie)(PCIHostState *, PCIDevice *);
> > } PCIHostBridgeClass;
> >
> > /* common internal helpers for PCI/PCIe hosts, cut off overflows */
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2017-04-18 3:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-28 2:16 [Qemu-devel] [RFC for-2.10 0/3] Rework handling of PCI/PCIe "hybrid" devices David Gibson
2017-03-28 2:16 ` [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching " David Gibson
2017-04-19 17:48 ` Marcel Apfelbaum
2017-04-26 15:23 ` Michael S. Tsirkin
2017-05-01 6:53 ` David Gibson
2017-08-29 11:42 ` David Gibson
2017-08-29 14:12 ` Eduardo Habkost
2017-08-30 5:54 ` David Gibson
2017-08-30 12:23 ` Eduardo Habkost
2017-09-26 5:04 ` David Gibson
2017-03-28 2:16 ` [Qemu-devel] [RFC for-2.10 2/3] pci: Allow host bridges to override PCI/PCIe hybrid device behaviour David Gibson
2017-04-17 18:30 ` Eduardo Habkost
2017-04-18 2:21 ` David Gibson [this message]
2017-04-18 14:33 ` Eduardo Habkost
2017-04-19 18:04 ` Marcel Apfelbaum
2017-04-26 15:29 ` Michael S. Tsirkin
2017-05-01 6:56 ` David Gibson
2017-09-28 7:53 ` David Gibson
2017-03-28 2:16 ` [Qemu-devel] [RFC for-2.10 3/3] pseries: Allow PCIe virtio and XHCI on pseries machine type David Gibson
2017-03-29 2:20 ` Alexey Kardashevskiy
2017-03-29 4:07 ` David Gibson
2017-08-29 13:01 ` [Qemu-devel] [RFC for-2.10 0/3] Rework handling of PCI/PCIe "hybrid" devices Eduardo Habkost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170418022151.GD12235@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=aik@ozlabs.ru \
--cc=ehabkost@redhat.com \
--cc=lersek@redhat.com \
--cc=marcel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).