Re: [RFC/RFT PATCH] PCI: move pci_read_bridge_bases to the generic PCI layer

From: Lorenzo Pieralisi
Date: Tue May 26 2015 - 10:22:07 EST


On Tue, May 26, 2015 at 01:57:59PM +0100, Will Deacon wrote:
> Hi Lorenzo,
>
> On Thu, May 21, 2015 at 02:14:25PM +0100, Lorenzo Pieralisi wrote:
> > When a PCI bus is scanned, upon PCI bridge detection the kernel
> > has to read the bridge registers to set-up its resources so that
> > the PCI resource hierarchy can be validated properly.
> >
> > Most if not all architectures read PCI bridge registers in the
> > pcibios_fixup_bus hook, that is called by the PCI generic layer
> > whenever a PCI bus is scanned.
> >
> > Since pci_read_bridge_bases is an arch agnostic operation (and it
> > is carried out on all architectures) it can be moved to the generic
> > PCI layer in order to consolidate code and remove the respective
> > calls from the architectures back-ends.
> >
> > The PCI_PROBE_ONLY flag is not checked before calling
> > pci_read_bridge_buses in the generic layer since reading the bridge
> > bases is not related to resources assignment; this implies that it
> > can be carried out safely on PCI_PROBE_ONLY systems too and should
> > not affect architectures (alpha, mips) that check the PCI_PROBE_ONLY
> > flag before reading the bridge bases.
>
> [...]
>
> > diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c
> > index 82f738e..cded02c 100644
> > --- a/arch/alpha/kernel/pci.c
> > +++ b/arch/alpha/kernel/pci.c
> > @@ -242,12 +242,7 @@ pci_restore_srm_config(void)
> >
> > void pcibios_fixup_bus(struct pci_bus *bus)
> > {
> > - struct pci_dev *dev = bus->self;
> > -
> > - if (pci_has_flag(PCI_PROBE_ONLY) && dev &&
> > - (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
> > - pci_read_bridge_bases(bus);
> > - }
>
> I appreciate you're basically moving this code ...
>
> > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> > index 062fee6..335d9f2 100644
> > --- a/drivers/pci/probe.c
> > +++ b/drivers/pci/probe.c
> > @@ -453,7 +453,11 @@ void pci_read_bridge_bases(struct pci_bus *child)
> > struct resource *res;
> > int i;
> >
> > - if (pci_is_root_bus(child)) /* It's a host bus, nothing to read */
> > + /*
> > + * If it is not a PCI bridge there is nothing to read
> > + */
> > + if (pci_is_root_bus(child) || !dev ||
> > + !((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI))
> > return;
>
> ... to here, but shouldn't we dispense with the class check and use
> pci_is_bridge instead? pci_read_bridge_bases is making an assumption
> that the header type is BRIDGE, so that seems like the more sensible
> check to me.

Yes I thought about that before posting. I added the class check to make
sure it covers the current checks carried out on all architectures
I am patching (ie pci_is_bridge() would allow reading bridge bases
for a cardbus header and I do not think that's correct as the code
stands).

I am happy to refactor the check once we have some coverage for all
archs.

> Also, with these changes, can we now make pci_read_bridge_bases static
> (as it has an implicit rdering requirement on the device having been
> scanned)?

As far as I understand the code, SPARC still needs it in arch specific
code that scans the PCI bus, so I could not make it static with this
set, I removed the call from all pcibios_fixup_bus implementations
that were calling it but that's where I had to stop.

Thanks for having a look,
Lorenzo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/