Pass resources to pci_create_bus() and fix MIPS PCI resources
v3 cover Pass resources to pci_create_bus() and fix MIPS PCI resources
Change the pci_create_bus() interface to pass in available resources to get them settled down early. This is to avoid possible resource conflicts while doing pci_scan_slot() in pci_scan_child_bus(). Note that pcibios_fixup_bus() can get rid of such conflicts, but it's done AFTER scanning slots.
In addition, MIPS PCI resources are now fixed using this new interface.
-- Changes --
v3 - v2:
o Do not do fixups for root buses in pcibios_fixup_bus().
o Skip bus creation when bus resources cannot be allocated.
o PCI domain/bus numbers added to the error info in controller_resources().
v2 - v1:
o Merge [PATCH 1/3] to [PATCH 3/3], so now 2 patches in total.
o Add more info to patch description.
o Fix arch breaks in default resource setup discovered by Bjorn Helgaas.
Deng-Cheng Zhu (2):
PCI: Pass available resources into pci_create_bus()
MIPS: PCI: Pass controller's resources to pci_create_bus() in
pcibios_scanbus()
arch/microblaze/pci/pci-common.c | 3 +- arch/mips/pci/pci.c | 61 +++++++++++++++++++++++++++++++++----- arch/powerpc/kernel/pci-common.c | 3 +- arch/sparc/kernel/pci.c | 3 +- arch/x86/pci/acpi.c | 2 +- drivers/pci/probe.c | 15 +++++++-- include/linux/pci.h | 3 +- 7 files changed, 73 insertions(+), 17 deletions(-)
PATCH v3 1/2 PCI: Pass available resources into pci_create_bus()
Currently, after pci_create_bus(), resources available on the bus could be handled by pci_scan_child_bus(). The problem is that, in pci_scan_child_bus(), before calling arch-dependent pcibios_fixup_bus(), PCI quirks will probably conflict (while doing pci_claim_resource()) with resources like system controller's I/O resource that have not yet been added to the bus. One can see that, by default, ioport_resource and iomem_resource are filled into the bus->resource[] array as the initial resources in pci_create_bus(). So, to avoid such conflicts, add those really available resources right before returning the newly created bus in pci_create_bus() whose interface should then be extended to receive them.
A related discussion thread can be found here:
http://www.spinics.net/lists/mips/msg41654.html
---
Changes (v3 - v2):
None
Changes (v2 - v1):
o Add more info to the patch description.
o Fix arch breaks in default resource setup discovered by Bjorn Helgaas.
arch/microblaze/pci/pci-common.c | 3 ++- arch/powerpc/kernel/pci-common.c | 3 ++- arch/sparc/kernel/pci.c | 3 ++- arch/x86/pci/acpi.c | 2 +- drivers/pci/probe.c | 15 +++++++++++---- include/linux/pci.h | 3 ++- 6 files changed, 20 insertions(+), 9 deletions(-)
arch/microblaze/pci/pci-common.c +2 -1
@@ -1581,7 +1581,8 @@ static void __devinit pcibios_scan_phb(struct pci_controller *hose) node ? node->full_name : "<NO NAME>");/* Create an empty bus for the toplevel */ - bus =pci_create_bus (hose->parent, hose->first_busno, hose->ops, hose); + bus =pci_create_bus (hose->parent, hose->first_busno, + hose->ops, hose,NULL );if (bus ==NULL ) {printk (KERN_ERR "Failed to create bus for PCI domain %04x\n" , hose->global_number);
arch/powerpc/kernel/pci-common.c +2 -1
@@ -1703,7 +1703,8 @@ void __devinit pcibios_scan_phb(struct pci_controller *hose) node ? node->full_name : "<NO NAME>");/* Create an empty bus for the toplevel */ - bus =pci_create_bus (hose->parent, hose->first_busno, hose->ops, hose); + bus =pci_create_bus (hose->parent, hose->first_busno, + hose->ops, hose,NULL );if (bus ==NULL ) {pr_err ("Failed to create bus for PCI domain %04x\n" , hose->global_number);
arch/sparc/kernel/pci.c +2 -1
@@ -689,7 +689,8 @@ struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm,printk ("PCI: Scanning PBM %s\n" , node->full_name); - bus =pci_create_bus (parent, pbm->pci_first_busno, pbm->pci_ops, pbm); + bus =pci_create_bus (parent, pbm->pci_first_busno, + pbm->pci_ops, pbm,NULL );if (!bus) {printk (KERN_ERR "Failed to create bus for %s\n" , node->full_name);
arch/x86/pci/acpi.c +1 -1
@@ -353,7 +353,7 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)memcpy (bus->sysdata, sd,sizeof (*sd));kfree (sd); }else { - bus =pci_create_bus (NULL , busnum, &pci_root_ops, sd); + bus =pci_create_bus (NULL , busnum, &pci_root_ops, sd,NULL );if (bus) {get_current_resources (device, busnum, domain, bus); bus->subordinate =pci_scan_child_bus (bus);
drivers/pci/probe.c +11 -4
@@ -1516,7 +1516,8 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus) }struct pci_bus *pci_create_bus (struct device *parent, -int bus,struct pci_ops *ops,void *sysdata) +int bus,struct pci_ops *ops,void *sysdata, +struct pci_bus_resource *bus_res) {int error;struct pci_bus *b, *b2;
@@ -1570,8 +1571,14 @@ struct pci_bus * pci_create_bus(struct device *parent,pci_create_legacy_files (b); b->number = b->secondary = bus; - b->resource[0 ] = &ioport_resource; - b->resource[1 ] = &iomem_resource; + +/* Add initial resources to the bus */ +if (bus_res !=NULL ) +list_add_tail (&b->resources, &bus_res->list); +else { + b->resource[0 ] = &ioport_resource; + b->resource[1 ] = &iomem_resource; + }return b;
@@ -1592,7 +1599,7 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent, {struct pci_bus *b; - b =pci_create_bus (parent, bus, ops, sysdata); + b =pci_create_bus (parent, bus, ops, sysdata,NULL );if (b) b->subordinate =pci_scan_child_bus (b);return b;
include/linux/pci.h +2 -1
@@ -666,7 +666,8 @@ static inline struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *oreturn root_bus; }struct pci_bus *pci_create_bus (struct device *parent,int bus, -struct pci_ops *ops,void *sysdata); +struct pci_ops *ops,void *sysdata, +struct pci_bus_resource *bus_res);struct pci_bus *pci_add_new_bus (struct pci_bus *parent,struct pci_dev *dev,int busnr);void pcie_update_link_speed (struct pci_bus *bus,u16 link_status);
Signature · 1 line
1.7.1
PATCH v3 2/2 MIPS: PCI: Pass controller's resources to pci_create_bus() in pcibios_scanbus()
In reply to Deng-Cheng ZhuUse the new interface of pci_create_bus() so that system controller's resources are added to the root bus upon bus creation, thereby avoiding conflicts with PCI quirks before pcibios_fixup_bus() gets the chance to do right things in pci_scan_child_bus().
---
Changes (v3 - v2):
o Do not do fixups for root buses in pcibios_fixup_bus().
o Skip bus creation when bus resources cannot be allocated.
o PCI domain/bus numbers added to the error info in controller_resources().
o Patch description modified according to the changes above.
Changes (v2 - v1):
o Merge [PATCH 1/3] to [PATCH 3/3] of v1.
o Add more info to patch description.
arch/mips/pci/pci.c | 61 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 53 insertions(+), 8 deletions(-)
arch/mips/pci/pci.c +53 -8
@@ -76,11 +76,42 @@ pcibios_align_resource(void *data, const struct resource *res,return start; } +static struct pci_bus_resource * +controller_resources (const struct pci_controller *ctrl,int domain,int busno) +{ +struct pci_bus_resource *mem_res, *io_res; + + mem_res =kzalloc (sizeof (struct pci_bus_resource ),GFP_KERNEL ); +if (!mem_res) + goto err_out; + + mem_res->res = ctrl->mem_resource; + mem_res->flags =0 ; +INIT_LIST_HEAD (&mem_res->list); + + io_res =kzalloc (sizeof (struct pci_bus_resource ),GFP_KERNEL ); +if (!io_res) { +kfree (mem_res); + goto err_out; + } + + io_res->res = ctrl->io_resource; + io_res->flags =0 ; +list_add (&io_res->list, &mem_res->list); + +return mem_res; +err_out: +printk (KERN_ERR "PCI bus %04x:%02x: Can't allocate bus resource.\n" , + domain, busno); +return NULL ; +} +static void __devinit pcibios_scanbus (struct pci_controller *hose) {static int next_busno;static int need_domain_info; -struct pci_bus *bus; +struct pci_bus *bus =NULL ; +struct pci_bus_resource *bus_res;if (!hose->iommu)PCI_DMA_BUS_IS_PHYS =1 ;
@@ -88,7 +119,22 @@ static void __devinit pcibios_scanbus(struct pci_controller *hose)if (hose->get_busno && pci_probe_only) next_busno = (*hose->get_busno)(); - bus =pci_scan_bus (next_busno, hose->pci_ops, hose); + bus_res =controller_resources (hose, hose->index, next_busno); +if (bus_res) { + bus =pci_create_bus (NULL , next_busno, hose->pci_ops, + hose, bus_res); +if (bus) { + bus->subordinate =pci_scan_child_bus (bus); +pci_bus_add_devices (bus); + }else { +/* io_resource */ +kfree (list_first_entry (&bus_res->list, + struct pci_bus_resource, list)); +/* mem_resource */ +kfree (bus_res); + } + } + hose->bus = bus; need_domain_info = need_domain_info || hose->index;
@@ -265,15 +311,14 @@ void __devinit pcibios_fixup_bus(struct pci_bus *bus) {/* Propagate hose info into the subordinate devices. */ -struct pci_controller *hose = bus->sysdata;struct list_head *ln;struct pci_dev *dev = bus->self; -if (!dev) { - bus->resource[0 ] = hose->io_resource; - bus->resource[1 ] = hose->mem_resource; - }else if (pci_probe_only && - (dev->class >>8 ) ==PCI_CLASS_BRIDGE_PCI ) { +/* +* Root bus resources should already be set up correctly in +* pci_create_bus(), so don't do fixups for it. +*/ +if (pci_probe_only && (dev->class >>8 ) ==PCI_CLASS_BRIDGE_PCI ) {pci_read_bridge_bases (bus);pcibios_fixup_device_resources (dev, bus); }
Signature · 1 line
1.7.1
Quoted 23 lines · Deng-Cheng Zhu
Change the
pci_create_bus()interface to pass in available resources to get them settled down early. This is to avoid possible resource conflicts while doingpci_scan_slot()inpci_scan_child_bus(). Note thatpcibios_fixup_bus()can get rid of such conflicts, but it's done AFTER scanning slots.In addition, MIPS PCI resources are now fixed using this new interface.
-- Changes --
v3 - v2:
o Do not do fixups for root buses inpcibios_fixup_bus().
o Skip bus creation when bus resources cannot be allocated.
o PCI domain/bus numbers added to the error info incontroller_resources().v2 - v1:
o Merge [PATCH 1/3] to [PATCH 3/3], so now 2 patches in total.
o Add more info to patch description.
o Fix arch breaks in default resource setup discovered by Bjorn Helgaas.Deng-Cheng Zhu (2):
PCI: Pass available resources intopci_create_bus()
MIPS: PCI: Pass controller's resources topci_create_bus()inpcibios_scanbus()
Quoted 8 lines
arch/microblaze/pci/pci-common.c | 3 +-
arch/mips/pci/pci.c | 61 +++++++++++++++++++++++++++++++++-----arch/powerpc/kernel/pci-common.c| 3 +-arch/sparc/kernel/pci.c| 3 +-arch/x86/pci/acpi.c | 2 +- drivers/pci/probe.c | 15 +++++++-- include/linux/pci.h | 3 +- 7 files changed, 73 insertions(+), 17 deletions(-)
This is beautiful. Thanks for doing this work! I hope other architectures will follow your lead and get rid of their root bus resource fixups.
Bjorn Helgaas
maintainerQuoted 33 lines · Bjorn Helgaas
Quoted 23 lines · Deng-Cheng Zhu
Change the
pci_create_bus()interface to pass in available resources to get them settled down early. This is to avoid possible resource conflicts while doingpci_scan_slot()inpci_scan_child_bus(). Note thatpcibios_fixup_bus()can get rid of such conflicts, but it's done AFTER scanning slots.In addition, MIPS PCI resources are now fixed using this new interface.
-- Changes --
v3 - v2:
o Do not do fixups for root buses inpcibios_fixup_bus().
o Skip bus creation when bus resources cannot be allocated.
o PCI domain/bus numbers added to the error info incontroller_resources().v2 - v1:
o Merge [PATCH 1/3] to [PATCH 3/3], so now 2 patches in total.
o Add more info to patch description.
o Fix arch breaks in default resource setup discovered by Bjorn Helgaas.Deng-Cheng Zhu (2):
PCI: Pass available resources intopci_create_bus()
MIPS: PCI: Pass controller's resources topci_create_bus()inpcibios_scanbus()Quoted 8 lines
arch/microblaze/pci/pci-common.c | 3 +-
arch/mips/pci/pci.c | 61 +++++++++++++++++++++++++++++++++-----arch/powerpc/kernel/pci-common.c| 3 +-arch/sparc/kernel/pci.c| 3 +-arch/x86/pci/acpi.c | 2 +- drivers/pci/probe.c | 15 +++++++-- include/linux/pci.h | 3 +- 7 files changed, 73 insertions(+), 17 deletions(-)
Quoted 6 lines
This is beautiful. Thanks for doing this work! I hope other architectures will follow your lead and get rid of their root bus resource fixups.
Reviewed-by Bjorn Helgaas <[email protected]>
One logistical issue here is that the first patch touches several architectures at once, which puts Jesse in a bit of a pinch. If he applies it, there's always the possibility that an arch patch will conflict with it, which makes merging harder.
It might be easier if, instead of changing the pci_create_bus() interface, you added a new one (it could call pci_create_bus() then replace the resources, so the implementation could still be mostly shared.) We already have a plethora of "create bus" methods (pci_create_bus(), pci_scan_bus_parented(), pci_scan_bus()), but if you added a pci_create_root_bus() or something similar, maybe we could try to converge on it and obsolete the others.
Then the first patch would touch only the PCI core, and the second would touch only MIPS, which would make merging more straightforward.
Bjorn
Hi, Bjorn
Thanks for your constructive review.
Quoted 4 lines
One logistical issue here is that the first patch touches several architectures at once, which puts Jesse in a bit of a pinch. If he applies it, there's always the possibility that an arch patch will conflict with it, which makes merging harder.
In case the conflicts happen, the effort to resolve them should be trivial (a matter of an extra NULL argument), I suppose. Also, the odds of other incoming arch patches making a reference to pci_create_bus() should not be great.
Quoted 11 lines
It might be easier if, instead of changing the
pci_create_bus()interface, you added a new one (it could callpci_create_bus()then replace the resources, so the implementation could still be mostly shared.) We already have a plethora of "create bus" methods (pci_create_bus(),pci_scan_bus_parented(),pci_scan_bus()), but if you added apci_create_root_bus()or something similar, maybe we could try to converge on it and obsolete the others.Then the first patch would touch only the PCI core, and the second would touch only MIPS, which would make merging more straightforward.
Hmm.. Adding a wrapper of pci_create_bus() does leave other architectures alone for this merging. But before all of them converge on it (a long way to go), the wrapper is adding naming confusion to the PCI core. Personally I think the current low-level transparent change to pci_create_bus() is appropriate enough. Does anybody have comments?
Deng-Cheng
Bjorn Helgaas
maintainerQuoted 27 lines · Deng-Cheng Zhu
Hi, Bjorn
Thanks for your constructive review.
Quoted 4 lines
One logistical issue here is that the first patch touches several architectures at once, which puts Jesse in a bit of a pinch. If he applies it, there's always the possibility that an arch patch will conflict with it, which makes merging harder.
In case the conflicts happen, the effort to resolve them should be trivial (a matter of an extra NULL argument), I suppose. Also, the odds of other incoming arch patches making a reference to
pci_create_bus()should not be great.Quoted 11 lines
It might be easier if, instead of changing the
pci_create_bus()interface, you added a new one (it could callpci_create_bus()then replace the resources, so the implementation could still be mostly shared.) We already have a plethora of "create bus" methods (pci_create_bus(),pci_scan_bus_parented(),pci_scan_bus()), but if you added apci_create_root_bus()or something similar, maybe we could try to converge on it and obsolete the others.Then the first patch would touch only the PCI core, and the second would touch only MIPS, which would make merging more straightforward.
Quoted 8 lines
Hmm.. Adding a wrapper of
pci_create_bus()does leave other architectures alone for this merging. But before all of them converge on it (a long way to go), the wrapper is adding naming confusion to the PCI core. Personally I think the current low-level transparent change topci_create_bus()is appropriate enough. Does anybody have comments?Deng-Cheng
Just to be clear, I'm fine with it either way, as long as Jesse and the arch maintainers are OK with it.
Quoted 35 lines · On Wed, 31 Aug 2011 07:48:16 -0600 Bjorn Helgaas <[email protected]> wrote:
Quoted 34 lines · Deng-Cheng Zhu
Hi, Bjorn
Thanks for your constructive review.
Quoted 4 lines
One logistical issue here is that the first patch touches several architectures at once, which puts Jesse in a bit of a pinch. If he applies it, there's always the possibility that an arch patch will conflict with it, which makes merging harder.
In case the conflicts happen, the effort to resolve them should be trivial (a matter of an extra NULL argument), I suppose. Also, the odds of other incoming arch patches making a reference to
pci_create_bus()should not be great.Quoted 11 lines
It might be easier if, instead of changing the
pci_create_bus()interface, you added a new one (it could callpci_create_bus()then replace the resources, so the implementation could still be mostly shared.) We already have a plethora of "create bus" methods (pci_create_bus(),pci_scan_bus_parented(),pci_scan_bus()), but if you added apci_create_root_bus()or something similar, maybe we could try to converge on it and obsolete the others.Then the first patch would touch only the PCI core, and the second would touch only MIPS, which would make merging more straightforward.
Hmm.. Adding a wrapper of
pci_create_bus()does leave other architectures alone for this merging. But before all of them converge on it (a long way to go), the wrapper is adding naming confusion to the PCI core. Personally I think the current low-level transparent change topci_create_bus()is appropriate enough. Does anybody have comments?
Quoted 4 lines
Quoted 1 line
Deng-Cheng
Just to be clear, I'm fine with it either way, as long as Jesse and the arch maintainers are OK with it.
I'm fine merging the arch bits too, as long as you can get some arch maintainer acks. If there are conflicts Linus will flag them (he likes to fix the occasional merge problem anyway).
Thanks,
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center