qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	aik@ozlabs.ru, qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	marcel@redhat.com, lersek@redhat.com
Subject: Re: [Qemu-devel] [RFC for-2.10 1/3] pci/pcie: Make a consistent helper for switching PCI/PCIe "hybrid" devices
Date: Tue, 29 Aug 2017 11:12:36 -0300	[thread overview]
Message-ID: <20170829141236.GX15315@localhost.localdomain> (raw)
In-Reply-To: <20170829114239.GP2578@umbus.fritz.box>

On Tue, Aug 29, 2017 at 09:42:39PM +1000, David Gibson wrote:
> On Wed, Apr 26, 2017 at 06:23:58PM +0300, Michael S. Tsirkin wrote:
> > On Tue, Mar 28, 2017 at 01:16:49PM +1100, David Gibson wrote:
> > > virtio-pci and XHCI are "hybrid" devices in the sense that they can present
> > > themselves as either PCIe or plain PCI devices depending on the machine
> > > and bus they're connected to.
> > > 
> > > For virtio-pci to present as PCIe it requires that it's connected to a PCIe
> > > bus and that it's not a root bus - this is to ensure that the device is
> > > connected via a PCIe root port or downstream port rather than being a
> > > integrated endpoint.  Some guests (Windows in particular AIUI) don't really
> > > cope with PCIe integrated endpoints.
> > > 
> > > For XHCI it only checks that the bus is PCIe, but that probably means it
> > > would cause problems if attached as an integrated devices directly to a
> > > PCIe root bus.
> > > 
> > > This patch makes the test consistent between XHCI and virtio-pci, and
> > > clarifies things by having them both use a new 'pci_allow_hybrid_pcie()'
> > > helper which performs the same check as virtio-pci.
> > > 
> > > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > > ---
> > >  hw/pci/pci.c           | 7 +++++++
> > >  hw/usb/hcd-xhci.c      | 2 +-
> > >  hw/virtio/virtio-pci.c | 3 +--
> > >  include/hw/pci/pci.h   | 1 +
> > >  4 files changed, 10 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> > > index bd8043c..779787b 100644
> > > --- a/hw/pci/pci.c
> > > +++ b/hw/pci/pci.c
> > > @@ -390,6 +390,13 @@ bool pci_bus_is_root(PCIBus *bus)
> > >      return PCI_BUS_GET_CLASS(bus)->is_root(bus);
> > >  }
> > >  
> > > +bool pci_allow_hybrid_pcie(PCIDevice *pci_dev)
> > > +{
> > > +    PCIBus *bus = pci_dev->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,
> > >                           const char *name,
> > >                           MemoryRegion *address_space_mem,
> > 
> > I'd prefer pci_allow_hybrid_pci_pcie.
> 
> Ok, I've made that change for the next spin (aimed at 2.11, obviously).

I'm a bit confused by the naming: by looking at the function
name, I don't know if "allow hybrid" means "this bus+device can
(also) work as Conventional PCI" or "this bus+device can (also)
work as PCI Express".

What about just naming it pci_allow_pcie() or
pci_bus_allow_pcie()?  It looks like the function doesn't care if
the device is hybrid or PCIe-only: it's only checking if the
device can work as PCIe on that bus.  It's up to the device to
decide if it should switch to Conventional PCI or report an error
if the function returns false.

> 
> > 
> > > diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
> > > index f0af852..a7ff4fd 100644
> > > --- a/hw/usb/hcd-xhci.c
> > > +++ b/hw/usb/hcd-xhci.c
> > > @@ -3619,7 +3619,7 @@ static void usb_xhci_realize(struct PCIDevice *dev, Error **errp)
> > >                       PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64,
> > >                       &xhci->mem);
> > >  
> > > -    if (pci_bus_is_express(dev->bus) ||
> > > +    if (pci_allow_hybrid_pcie(dev) ||
> > >          xhci_get_flag(xhci, XHCI_FLAG_FORCE_PCIE_ENDCAP)) {
> > >          ret = pcie_endpoint_cap_init(dev, 0xa0);
> > >          assert(ret >= 0);
> > 
> > This seems to change the behaviour for xhci on a root bus - what
> > am I missing?
> 
> Nothing.  I didn't consider the backwards compat implications; I'll
> fix it for the next spin.
> 
> -- 
> 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



-- 
Eduardo

  reply	other threads:[~2017-08-29 14:12 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 [this message]
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
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=20170829141236.GX15315@localhost.localdomain \
    --to=ehabkost@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=david@gibson.dropbear.id.au \
    --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).