qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: mst@redhat.com, marcel@redhat.com, qemu-devel@nongnu.org,
	alex.williamson@redhat.com
Subject: Re: [Qemu-devel] [RFC 4/5] pci: Simplify pci_bus_is_root()
Date: Wed, 4 Oct 2017 17:03:20 +1100	[thread overview]
Message-ID: <20171004060320.GV3260@umbus.fritz.box> (raw)
In-Reply-To: <20171003144259.GK17385@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 2823 bytes --]

On Tue, Oct 03, 2017 at 11:42:59AM -0300, Eduardo Habkost wrote:
> On Tue, Oct 03, 2017 at 08:14:22PM +1100, David Gibson wrote:
> > pci_bus_is_root() currently relies on a method in the PCIBusClass.
> > But it's always known if a PCI bus is a root bus when we create it, so
> > using a dynamic method is overkill.
> > 
> > This replaces it with an IS_ROOT bit in a new flags field, which is set on
> > root buses and otherwise clear.  As a bonus this removes the special
> > is_root logic from pci_expander_bridge, since it already creates its bus
> > as a root bus.
> > 
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > 
> > # Conflicts:
> > #	include/hw/pci/pci_bus.h
> 
> Should this be part of the commit message?

Oops.  I'll fix that for the next spin.

> > ---
> [...]
> > diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> > index 77d92a3dc4..cbb3386207 100644
> > --- a/include/hw/pci/pci.h
> > +++ b/include/hw/pci/pci.h
> > @@ -404,6 +404,11 @@ typedef AddressSpace *(*PCIIOMMUFunc)(PCIBus *, void *, int);
> >  #define PCI_BUS_GET_CLASS(obj) OBJECT_GET_CLASS(PCIBusClass, (obj), TYPE_PCI_BUS)
> >  #define TYPE_PCIE_BUS "PCIE"
> >  
> > +enum PCIBusFlags {
> > +    /* This bus is the root of a PCI domain */
> > +    PCI_BUS_IS_ROOT                                         = 0x0001,
> > +};
> > +
> >  typedef struct PCIBusClass {
> >      /*< private >*/
> >      BusClass parent_class;
> > @@ -416,6 +421,7 @@ typedef struct PCIBusClass {
> >  
> >  struct PCIBus {
> >      BusState qbus;
> > +    enum PCIBusFlags flags;
> 
> Why not a simple boolean field?  If we want to keep the struct
> size smaller when adding more flags, we can use bit-fields.

Well, mst suggested "flags", so this is what came to mind.  I guess
being a past kernel dev has given be a tendency to avoid bitfields,
though I don't think any of the problems they can cause would apply
here.

Note that I do add a second flags bit in patch 5/5.

> 
> >      PCIIOMMUFunc iommu_fn;
> >      void *iommu_opaque;
> >      uint8_t devfn_min;
> > @@ -440,8 +446,12 @@ struct PCIBus {
> >      Notifier machine_done;
> >  };
> >  
> > +static inline bool pci_bus_is_root(PCIBus *bus)
> > +{
> > +    return !!(bus->flags & PCI_BUS_IS_ROOT);
> > +}
> > +
> >  bool pci_bus_is_express(PCIBus *bus);
> > -bool pci_bus_is_root(PCIBus *bus);
> >  void pci_root_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
> >                                const char *name,
> >                                MemoryRegion *address_space_mem,
> 

-- 
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: 833 bytes --]

  reply	other threads:[~2017-10-04  6:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03  9:14 [Qemu-devel] [RFC 0/5] Assorted PCI/PCIe cleanups cleanups David Gibson
2017-10-03  9:14 ` [Qemu-devel] [RFC 1/5] pci: Rename root bus initialization functions for clarity David Gibson
2017-10-03  9:14 ` [Qemu-devel] [RFC 2/5] pci: Move bridge data structures from pci_bus.h to pci_bridge.h David Gibson
2017-10-03  9:14 ` [Qemu-devel] [RFC 3/5] pci: Fold pci_bus.h into pci.h David Gibson
2017-10-03  9:14 ` [Qemu-devel] [RFC 4/5] pci: Simplify pci_bus_is_root() David Gibson
2017-10-03 14:42   ` Eduardo Habkost
2017-10-04  6:03     ` David Gibson [this message]
2017-10-03  9:14 ` [Qemu-devel] [RFC 5/5] pcie: Don't allow extended config space access via conventional PCI bridges David Gibson

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=20171004060320.GV3260@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=alex.williamson@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@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).