PCI: allocate pci bus num range for unassigned bridge busn
cover PCI: allocate pci bus num range for unassigned bridge busn
676b367: pcmcia: remove workaround for fixing pci parent bus subordinate
ddbc547: PCI: Seperate child bus scanning to two passes overall
c82fe6d: PCI: kill pci_fixup_parent_subordinate_busnr() 7bf1ff4: PCI: Allocate bus range instead of use max blindly 1e511be: PCI: Strict checking of valid range for bridge
a433d03: PCI: Probe safe range that we can use for unassigned bridge. 7f45e65: PCI: Add pci_bus_extend/shrink_top()
6e8d9f1: PCI, parisc: Register busn_res for root buses
aadaf33: PCI, powerpc: Register busn_res for root buses 10ba93b: PCI, ia64: Register busn_res for root buses 6663d7a: PCI, x86: Register busn_res for root buses
f283aa2: PCI: Add busn_res tracking in core
d20c7d9: PCI: Add busn_res operation functions
196dcc6: PCI: Add iobusn_resource
634a14b: Make %pR could handle bus resource with domain
Set up iobusn_resource tree, and register bus number range to it. Later when need to find bus range, will try to allocate from the tree
Need to test on arches other than x86. esp for ia64 and powerpc that support
more than on peer root buses.
could be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-busn-alloc
-v2: according to Jesse, split to more small patches.
-v3: address some request from Bjorn. like make use %pR for busn_res debug print
out, and move the comment change with code change.
-v4: fixes the problem about rescan that Bjorn found.
Thanks
Yinghai
arch/ia64/pci/pci.c | 2 + arch/powerpc/kernel/pci-common.c | 7 +- arch/x86/include/asm/topology.h | 3 +- arch/x86/pci/acpi.c | 8 +- arch/x86/pci/bus_numa.c | 8 +- arch/x86/pci/common.c | 11 +- drivers/parisc/dino.c | 2 + drivers/parisc/lba_pci.c | 3 + drivers/pci/probe.c | 417 ++++++++++++++++++++++++++++++-------- drivers/pci/remove.c | 1 + drivers/pcmcia/yenta_socket.c | 75 ------- include/linux/ioport.h | 1 + include/linux/pci.h | 8 + kernel/resource.c | 8 + lib/vsprintf.c | 28 +++- 15 files changed, 410 insertions(+), 172 deletions(-)
PATCH 1/15 Make %pR could handle bus resource with domain
So could use %pR for busn_res with domain nr in start/end
--- lib/vsprintf.c | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-)
lib/vsprintf.c +24 -4
@@ -451,6 +451,12 @@ char *resource_string(char *buf, char *end, struct resource *res, .precision = -1, .flags = SPECIAL | SMALL | ZEROPAD, }; +static const struct printf_spec domain_spec = { + .base =16 , + .field_width =4 , + .precision =-1 , + .flags =SMALL |ZEROPAD , + };static const struct printf_spec bus_spec = { .base =16 , .field_width =2 ,
@@ -507,11 +513,25 @@ char *resource_string(char *buf, char *end, struct resource *res, specp = &mem_spec; decode =0 ; } - p =number (p, pend, res->start, *specp); -if (res->start != res->end) { - *p++ ='-' ; - p =number (p, pend, res->end, *specp); + +if (res->flags &IORESOURCE_BUS && res->end >>8 ) { + p =number (p, pend, res->start >>8 , domain_spec); + *p++ =':' ; + p =number (p, pend, res->start &0xff , *specp); +if (res->start != res->end) { + *p++ ='-' ; + p =number (p, pend, res->end >>8 , domain_spec); + *p++ =':' ; + p =number (p, pend, res->end &0xff , *specp); + } + }else { + p =number (p, pend, res->start, *specp); +if (res->start != res->end) { + *p++ ='-' ; + p =number (p, pend, res->end, *specp); + } } +if (decode) {if (res->flags &IORESOURCE_MEM_64 ) p =string (p, pend," 64bit" , str_spec);
Signature · 1 line
1.7.7
Bjorn Helgaas
maintainerRe: [PATCH 01/15] Make %pR could handle bus resource with domain
Quoted 33 lines · Yinghai Lu
So could use %pR for
busn_reswith domain nr in start/endSigned-off-by Yinghai Lu <[email protected]>Cc Andrew Morton <[email protected]>---
lib/vsprintf.c | 28 ++++++++++++++++++++++++----1 files changed, 24 insertions(+), 4 deletions(-)lib/vsprintf.c +6
-4@@ -451,6 +451,12 @@ char *resource_string(char *buf, char *end, struct resource *res, .precision = -1, .flags = SPECIAL | SMALL | ZEROPAD, }; + static const struct printf_spec domain_spec = { + .base = 16, + .field_width = 4, + .precision = -1, + .flags = SMALL | ZEROPAD, + }; static const struct printf_spec bus_spec = { .base = 16, .field_width = 2,@@ -507,11 +513,25 @@ char *resource_string(char *buf, char *end, struct resource *res, specp = &mem_spec; decode = 0; } - p = number(p, pend, res->start, *specp); - if (res->start != res->end) { - *p++ = '-'; - p = number(p, pend, res->end, *specp);
lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 525
Quoted 10 lines
lib/vsprintf.c +10
-0+ + if (res->flags & IORESOURCE_BUS && res->end >> 8) { + p = number(p, pend, res->start >> 8, domain_spec); + *p++ = ':'; + p = number(p, pend, res->start & 0xff, *specp); + if (res->start != res->end) { + *p++ = '-'; + p = number(p, pend, res->end >> 8, domain_spec); + *p++ = ':'; + p = number(p, pend, res->end & 0xff, *specp);
The "<< 8", ">>8", and "& 0xff" patterns are used frequently in these patches. I think it's worth adding macros or inline functions to make it clear that all these places are connected.
Quoted 15 lines
lib/vsprintf.c +8
-1+ } + } else { + p = number(p, pend, res->start, *specp); + if (res->start != res->end) { + *p++ = '-'; + p = number(p, pend, res->end, *specp); + } } + if (decode) { if (res->flags & IORESOURCE_MEM_64) p = string(p, pend, " 64bit", str_spec); --1.7.7
Re: [PATCH 01/15] Make %pR could handle bus resource with domain
Quoted 40 lines · Bjorn Helgaas
Quoted 39 lines · Yinghai Lu
So could use %pR for
busn_reswith domain nr in start/endSigned-off-by Yinghai Lu <[email protected]>Cc Andrew Morton <[email protected]>---
lib/vsprintf.c | 28 ++++++++++++++++++++++++----1 files changed, 24 insertions(+), 4 deletions(-)lib/vsprintf.c +12
-4@@ -451,6 +451,12 @@ char *resource_string(char *buf, char *end, struct resource *res, .precision = -1, .flags = SPECIAL | SMALL | ZEROPAD, }; + static const struct printf_spec domain_spec = { + .base = 16, + .field_width = 4, + .precision = -1, + .flags = SMALL | ZEROPAD, + }; static const struct printf_spec bus_spec = { .base = 16, .field_width = 2,@@ -507,11 +513,25 @@ char *resource_string(char *buf, char *end, struct resource *res, specp = &mem_spec; decode = 0; } - p = number(p, pend, res->start, *specp); - if (res->start != res->end) { - *p++ = '-'; - p = number(p, pend, res->end, *specp); + + if (res->flags & IORESOURCE_BUS && res->end >> 8) { + p = number(p, pend, res->start >> 8, domain_spec); + *p++ = ':'; + p = number(p, pend, res->start & 0xff, *specp); + if (res->start != res->end) {
Quoted 8 lines
lib/vsprintf.c char *resource_string(char *buf, char *end, struct resource *res, · line 525
Quoted 4 lines
lib/vsprintf.c +4
-0+ *p++ = '-'; + p = number(p, pend, res->end >> 8, domain_spec); + *p++ = ':'; + p = number(p, pend, res->end & 0xff, *specp);The "<< 8", ">>8", and "&
0xff" patterns are used frequently in these patches. I think it's worth adding macros or inline functions to make it clear that all these places are connected.
ok will check if can use
busn_domain_nr(res): res->end >> 8busn_bus_nr(res): res->end & 0xff;busn_val(domain_nr, bus_nr)
instead.
Thanks
Yinghai
PATCH 2/15 PCI: Add iobusn_resource
In reply to Yinghai Lualso add busn_res into struct pci_bus.
will use them to have bus number resource tree.
--- include/linux/ioport.h | 1 + include/linux/pci.h | 1 + kernel/resource.c | 8 ++++++++ 3 files changed, 10 insertions(+), 0 deletions(-)
include/linux/ioport.h +1 -0
@@ -136,6 +136,7 @@ struct resource {/* PC/ISA/whatever - the normal PC address spaces: IO and memory */ extern struct resource ioport_resource;extern struct resource iomem_resource; +extern struct resource iobusn_resource;extern struct resource *request_resource_conflict (struct resource *root,struct resource *new);extern int request_resource (struct resource *root,struct resource *new);
include/linux/pci.h +1 -0
@@ -419,6 +419,7 @@ struct pci_bus {struct list_head slots;/* list of slots on this bus */ struct resource *resource[PCI_BRIDGE_RESOURCE_NUM ];struct list_head resources;/* address space routed to this bus */ +struct resource busn_res;/* track registered bus num range */ struct pci_ops *ops;/* configuration access functions */ void *sysdata;/* hook for sys-specific extension */
kernel/resource.c +8 -0
@@ -38,6 +38,14 @@ struct resource iomem_resource = { };EXPORT_SYMBOL (iomem_resource); +struct resource iobusn_resource = { + .name ="PCI busn" , + .start =0 , + .end =0xffffff , + .flags =IORESOURCE_BUS , +}; +EXPORT_SYMBOL (iobusn_resource); +/* constraints to be met while allocating resources */ struct resource_constraint {resource_size_t min, max, align;
Signature · 1 line
1.7.7
Bjorn Helgaas
maintainerRe: [PATCH 02/15] PCI: Add iobusn_resource
Quoted 3 lines · Yinghai Lu
also add
busn_resinto structpci_bus.will use them to have bus number resource tree.
Will you make this tree visible in /proc? Seems like that would be useful for debugging and for symmetry with /proc/iomem and /proc/ioports.
Quoted 24 lines
Signed-off-by Yinghai Lu <[email protected]>---
include/linux/ioport.h | 1 +
include/linux/pci.h | 1 +
kernel/resource.c | 8 ++++++++3 files changed, 10 insertions(+), 0 deletions(-)include/linux/ioport.h +1
-0@@ -136,6 +136,7 @@ struct resource { /* PC/ISA/whatever - the normal PC address spaces: IO and memory */ extern struct resource ioport_resource; extern struct resource iomem_resource; +extern struct resource iobusn_resource; extern struct resource *request_resource_conflict(struct resource *root, struct resource *new); extern int request_resource(struct resource *root, struct resource *new);include/linux/pci.h +0
-0@@ -419,6 +419,7 @@ struct pci_bus {
Quoted 4 lines
struct
list_headslots; /* list of slots on this bus */ struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
structlist_headresources; /* address space routed to this bus */
+ struct resourcebusn_res; /* track registered bus num range */
Is this different from bus.secondary and bus.subordinate? Do we need both busn_res and secondary/subordinate? If we need both, in what circumstance with they contain different information?
Quoted 24 lines
struct
pci_ops*ops; /* configuration access functions */ void *sysdata; /* hook for sys-specific extension */kernel/resource.c +8
-1@@ -38,6 +38,14 @@ struct resource iomem_resource = { }; EXPORT_SYMBOL(iomem_resource); +struct resource iobusn_resource = { + .name = "PCI busn", + .start = 0, + .end = 0xffffff, + .flags = IORESOURCE_BUS, +}; +EXPORT_SYMBOL (iobusn_resource); + /* constraints to be met while allocating resources */ struct resource_constraint { resource_size_t min, max, align; --1.7.7
Re: [PATCH 02/15] PCI: Add iobusn_resource
Quoted 8 lines · Bjorn Helgaas
Quoted 3 lines · Yinghai Lu
also add
busn_resinto structpci_bus.will use them to have bus number resource tree.
Will you make this tree visible in /proc? Seems like that would be useful for debugging and for symmetry with
/proc/iomemand/proc/ioports.
will give it try.
Quoted 1 line
...
Quoted 9 lines
Quoted 5 lines
(quoted diff) +0
-0@@ -419,6 +419,7 @@ struct pci_bus {struct
list_headslots; /* list of slots on this bus */ struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
structlist_headresources; /* address space routed to this bus */
+ struct resourcebusn_res; /* track registered bus num range */Is this different from bus.secondary and bus.subordinate? Do we need both
busn_resand secondary/subordinate? If we need both, in what circumstance with they contain different information?
yes, sometime it
for non-peer root bus just after scan. and at that time will set busn_res.end correctly according to subordinate.
for peer root bus, busn_res.end could be bigger than bus subordinate
Yinghai
Re: [PATCH 02/15] PCI: Add iobusn_resource
In reply to Bjorn HelgaasQuoted 8 lines · Bjorn Helgaas
Quoted 3 lines · Yinghai Lu
also add
busn_resinto structpci_bus.will use them to have bus number resource tree.
Will you make this tree visible in /proc? Seems like that would be useful for debugging and for symmetry with
/proc/iomemand/proc/ioports.
To be honest that whole business with bus numbers in struct resource seems like gratuituous bloat & over engineering to me ...
Does it actually solve a specific problem or serve a purpose ?
Cheers,
Ben.
Quoted 63 lines
Quoted 25 lines
Signed-off-by Yinghai Lu <[email protected]>--- include/linux/ioport.h | 1 + include/linux/pci.h | 1 + kernel/resource.c | 8 ++++++++ 3 files changed, 10 insertions(+), 0 deletions(-)include/linux/ioport.h +1
-0@@ -136,6 +136,7 @@ struct resource {/* PC/ISA/whatever - the normal PC address spaces: IO and memory */ extern struct resource ioport_resource;extern struct resource iomem_resource; +extern struct resource iobusn_resource;extern struct resource *request_resource_conflict (struct resource *root,struct resource *new);extern int request_resource (struct resource *root,struct resource *new);include/linux/pci.h +0
-0include/linux/pci.h struct pci_bus { · line 422
Quoted 4 lines
include/linux/pci.h +1
-0@@ -419,6 +419,7 @@ struct pci_bus {struct list_head slots;/* list of slots on this bus */ struct resource *resource[PCI_BRIDGE_RESOURCE_NUM ];struct list_head resources;/* address space routed to this bus */ +struct resource busn_res;/* track registered bus num range */ Is this different from bus.secondary and bus.subordinate? Do we need both
busn_resand secondary/subordinate? If we need both, in what circumstance with they contain different information?Quoted 22 lines
include/linux/pci.h +0
-0struct pci_ops *ops;/* configuration access functions */ void *sysdata;/* hook for sys-specific extension */ kernel/resource.c +8
-1@@ -38,6 +38,14 @@ struct resource iomem_resource = { };EXPORT_SYMBOL (iomem_resource); +struct resource iobusn_resource = { + .name ="PCI busn" , + .start =0 , + .end =0xffffff , + .flags =IORESOURCE_BUS , +}; +EXPORT_SYMBOL (iobusn_resource); +/* constraints to be met while allocating resources */ struct resource_constraint {resource_size_t min, max, align; --Quoted 2 lines
1.7.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 02/15] PCI: Add iobusn_resource
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Bjorn Helgaas
Quoted 2 lines · Yinghai Lu
also add
busn_resinto structpci_bus.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
will use them to have bus number resource tree.
Will you make this tree visible in /proc? Seems like that would be useful for debugging and for symmetry with
/proc/iomemand/proc/ioports.To be honest that whole business with bus numbers in struct resource seems like gratuituous bloat & over engineering to me ...
ah, i thought it is simple enough, and should be done before already.
Quoted 1 line
Does it actually solve a specific problem or serve a purpose ?
very beginning is for one IBM x3950...
https://bugzilla.novell.com/show_bug.cgi?id=735909
++max searching valid bus number range is out of boundary of peer root bus range.
later, found the code could help: pcie hotplug, pci bus rescan and even remove some hacks for/from cardbus field.
now with this patchset (+ one patch that is not sent out yet), I could even use setpci/pci rescan to move pci bus around.
Thanks
Yinghai
Bjorn Helgaas
maintainerRe: [PATCH 02/15] PCI: Add iobusn_resource
Quoted 19 lines · Yinghai Lu
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 4 lines · Bjorn Helgaas
Quoted 3 lines · Yinghai Lu
also add
busn_resinto structpci_bus.will use them to have bus number resource tree.
To be honest that whole business with bus numbers in struct resource seems like gratuituous bloat & over engineering to me ...
ah, i thought it is simple enough, and should be done before already.
Quoted 1 line
Does it actually solve a specific problem or serve a purpose ?
very beginning is for one IBM x3950...
Quoted 8 lines
++max searching valid bus number range is out of boundary of peer root bus range.
later, found the code could help: pcie hotplug, pci bus rescan and even remove some hacks for/from cardbus field.
now with this patchset (+ one patch that is not sent out yet), I could even use setpci/pci rescan to move pci bus around.
The current bus number allocation in pci_scan_bridge() is very simple -- we just add one to the highest-numbered bridge we've seen. That works in many cases, but it means any holes in the range of used bus numbers are just wasted.
Here's a case I tripped over where the current scheme fails. The machine boots with bridge 00:03.0 to [bus 05-19]. Now we hot-add a hierarchy that is currently configured like this:
05:00.0 bridge to [bus 06-1e]
06:05.0 bridge to [bus 1c]
06:06.0 bridge to [bus 1d]
1c:00.0 NIC0
1d:00.0 NIC1[bus 1a-1e] is inaccessible because the 00:03.0 aperture only includes [bus 05-19]. There's plenty of space to reconfigure the hierarchy, e.g., to make 05:00.0 lead to [bus 06-19], 06:05.0 lead to [bus 18], and 06:06.0 lead to [bus 19]. But we aren't smart enough to do that.
So I think it's important to improve bus number allocation to make hot plug more robust, but I don't think the current series is understandable or maintainable yet.
Bjorn
Re: [PATCH 02/15] PCI: Add iobusn_resource
Quoted 15 lines · Bjorn Helgaas
The current bus number allocation in
pci_scan_bridge()is very simple -- we just add one to the highest-numbered bridge we've seen. That works in many cases, but it means any holes in the range of used bus numbers are just wasted.Here's a case I tripped over where the current scheme fails. The machine boots with bridge 00:03.0 to [bus 05-19]. Now we hot-add a hierarchy that is currently configured like this:
05:00.0 bridge to [bus 06-1e]
06:05.0 bridge to [bus 1c]
06:06.0 bridge to [bus 1d]
1c:00.0 NIC0
1d:00.0 NIC1
Quoted 4 lines
[bus 1a-1e] is inaccessible because the 00:03.0 aperture only includes [bus 05-19]. There's plenty of space to reconfigure the hierarchy, e.g., to make 05:00.0 lead to [bus 06-19], 06:05.0 lead to [bus 18], and 06:06.0 lead to [bus 19]. But we aren't smart enough to do that.
Yes, this patchset will reject 05:00.0 bus setting from bios, and assign it with 06-19.
Yinghai
PATCH 3/15 PCI: Add busn_res operation functions
In reply to Yinghai Luwill use them insert/update busn res in pci_bus
--- drivers/pci/probe.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 3 +++ 2 files changed, 39 insertions(+), 0 deletions(-)
drivers/pci/probe.c +36 -0
@@ -1622,6 +1622,42 @@ err_out:return NULL ; } +void pci_bus_insert_busn_res (struct pci_bus *b,int bus,int bus_max) +{ +struct resource *res = &b->busn_res; +struct resource *parent_res = &iobusn_resource; +int ret; + + res->start = (pci_domain_nr (b) <<8 ) | bus; + res->end = (pci_domain_nr (b) <<8 ) | bus_max; + res->flags =IORESOURCE_BUS ; + +if (!pci_is_root_bus (b)) + parent_res = &b->parent->busn_res; + + ret =insert_resource (parent_res, res); + +dev_printk (KERN_DEBUG , &b->dev, +"busn_res: %pR %s inserted under %pR\n" , + res, ret ?"can not be" :"is" , parent_res); +} + +void pci_bus_update_busn_res_end (struct pci_bus *b,int bus_max) +{ +struct resource *res = &b->busn_res; +struct resource old_res = *res; + + res->end &= ~0xff ; + res->end |= bus_max; +dev_printk (KERN_DEBUG , &b->dev,"busn_res: %pR end updated to %pR\n" , + &old_res, res); +} + +void pci_bus_release_busn_res (struct pci_bus *b) +{ +release_resource (&b->busn_res); +} +struct pci_bus *__devinit pci_scan_root_bus (struct device *parent,int bus,struct pci_ops *ops,void *sysdata,struct list_head *resources) {
include/linux/pci.h +3 -0
@@ -665,6 +665,9 @@ struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);struct pci_bus *pci_create_root_bus (struct device *parent,int bus,struct pci_ops *ops,void *sysdata,struct list_head *resources); +void pci_bus_insert_busn_res (struct pci_bus *b,int bus,int busmax); +void pci_bus_update_busn_res_end (struct pci_bus *b,int busmax); +void pci_bus_release_busn_res (struct pci_bus *b);struct pci_bus *__devinit pci_scan_root_bus (struct device *parent,int bus,struct pci_ops *ops,void *sysdata,struct list_head *resources);
Signature · 1 line
1.7.7
PATCH 4/15 PCI: Add busn_res tracking in core
In reply to Yinghai Luupdate pci_scan_root_bus, and pci_scan_bus to insert root bus busn into iobusn_resource tree.
--- drivers/pci/probe.c | 30 ++++++++++++++++++++++++++---- drivers/pci/remove.c | 1 + include/linux/pci.h | 4 ++++ 3 files changed, 31 insertions(+), 4 deletions(-)
drivers/pci/probe.c +26 -4
@@ -1658,8 +1658,9 @@ void pci_bus_release_busn_res(struct pci_bus *b)release_resource (&b->busn_res); } -struct pci_bus *__devinit pci_scan_root_bus (struct device *parent,int bus, -struct pci_ops *ops,void *sysdata,struct list_head *resources) +struct pci_bus *__devinit pci_scan_root_bus_max (struct device *parent,int bus, +int bus_max,struct pci_ops *ops,void *sysdata, +struct list_head *resources) {struct pci_bus *b;
@@ -1667,10 +1668,26 @@ struct pci_bus * __devinit pci_scan_root_bus(struct device *parent, int bus,if (!b)return NULL ; +pci_bus_insert_busn_res (b, bus, bus_max); b->subordinate =pci_scan_child_bus (b);pci_bus_add_devices (b);return b; } +EXPORT_SYMBOL (pci_scan_root_bus_max); + +struct pci_bus *__devinit pci_scan_root_bus (struct device *parent,int bus, +struct pci_ops *ops,void *sysdata, +struct list_head *resources) +{ +struct pci_bus *b; + + b =pci_scan_root_bus_max (parent, bus,255 , ops, sysdata, resources); + +if (b) +pci_bus_update_busn_res_end (b, b->subordinate); + +return b; +}EXPORT_SYMBOL (pci_scan_root_bus);/* Deprecated; use pci_scan_root_bus() instead */
@@ -1683,9 +1700,11 @@ struct pci_bus * __devinit pci_scan_bus_parented(struct device *parent,pci_add_resource (&resources, &ioport_resource);pci_add_resource (&resources, &iomem_resource); b =pci_create_root_bus (parent, bus, ops, sysdata, &resources); -if (b) +if (b) { +pci_bus_insert_busn_res (b, bus,255 ); b->subordinate =pci_scan_child_bus (b); -else +pci_bus_update_busn_res_end (b, b->subordinate); + }else pci_free_resource_list (&resources);return b; }
@@ -1701,7 +1720,10 @@ struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops,pci_add_resource (&resources, &iomem_resource); b =pci_create_root_bus (NULL , bus, ops, sysdata, &resources);if (b) { +pci_bus_insert_busn_res (b, bus,255 ); b->subordinate =pci_scan_child_bus (b); +pci_bus_update_busn_res_end (b, b->subordinate); +pci_bus_add_devices (b); }else {pci_free_resource_list (&resources);
drivers/pci/remove.c +1 -0
@@ -68,6 +68,7 @@ void pci_remove_bus(struct pci_bus *pci_bus)down_write (&pci_bus_sem);list_del (&pci_bus->node); +pci_bus_release_busn_res (pci_bus);up_write (&pci_bus_sem);if (!pci_bus->is_added)return ;
include/linux/pci.h +4 -0
@@ -668,6 +668,10 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,void pci_bus_insert_busn_res (struct pci_bus *b,int bus,int busmax);void pci_bus_update_busn_res_end (struct pci_bus *b,int busmax);void pci_bus_release_busn_res (struct pci_bus *b); +struct pci_bus *__devinit pci_scan_root_bus_max (struct device *parent,int bus, +int busmax,struct pci_ops *ops, +void *sysdata, +struct list_head *resources);struct pci_bus *__devinit pci_scan_root_bus (struct device *parent,int bus,struct pci_ops *ops,void *sysdata,struct list_head *resources);
Signature · 1 line
1.7.7
PATCH 5/15 PCI, x86: Register busn_res for root buses
In reply to Yinghai Luupdate x86_pci_root_bus_resources() to get bus_max for non-acpi case.
--- arch/x86/include/asm/topology.h | 3 ++- arch/x86/pci/acpi.c | 8 +++++--- arch/x86/pci/bus_numa.c | 8 +++++++- arch/x86/pci/common.c | 11 +++++++---- 4 files changed, 21 insertions(+), 9 deletions(-)
arch/x86/include/asm/topology.h +2 -1
@@ -172,7 +172,8 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) }struct pci_bus ; -void x86_pci_root_bus_resources (int bus,struct list_head *resources); +void x86_pci_root_bus_resources (int bus,int *bus_max, +struct list_head *resources);#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \
arch/x86/pci/acpi.c +5 -3
@@ -348,6 +348,7 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)struct acpi_device *device = root->device;int domain = root->segment;int busnum = root->secondary.start; +int busmax = root->secondary.end;LIST_HEAD (resources);struct pci_bus *bus;struct pci_sysdata *sd;
@@ -410,12 +411,13 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)* defaults or native bridge info if we're ignoring _CRS. */ if (!pci_use_crs) -x86_pci_root_bus_resources (busnum, &resources); +x86_pci_root_bus_resources (busnum, &busmax, &resources); bus =pci_create_root_bus (NULL , busnum, &pci_root_ops, sd, &resources); -if (bus) +if (bus) { +pci_bus_insert_busn_res (bus, busnum, busmax); bus->subordinate =pci_scan_child_bus (bus); -else + }else pci_free_resource_list (&resources); }
arch/x86/pci/bus_numa.c +7 -1
@@ -7,7 +7,8 @@int pci_root_num;struct pci_root_info pci_root_info[PCI_ROOT_NR ]; -void x86_pci_root_bus_resources (int bus,struct list_head *resources) +void x86_pci_root_bus_resources (int bus,int *bus_max, +struct list_head *resources) {int i;int j;
@@ -28,6 +29,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources) bus); info = &pci_root_info[i]; + *bus_max = info->bus_max;for (j =0 ; j < info->res_num; j++) {struct resource *res;struct resource *root;
@@ -51,6 +53,10 @@ default_resources:printk (KERN_DEBUG "PCI: root bus %02x: using default resources\n" , bus);pci_add_resource (resources, &ioport_resource);pci_add_resource (resources, &iomem_resource); +if (!bus) + *bus_max =0xff ; +else if (!*bus_max) + *bus_max = bus; } void __devinit update_res(struct pci_root_info *info, resource_size_t start,
arch/x86/pci/common.c +7 -4
@@ -433,6 +433,7 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum)LIST_HEAD (resources);struct pci_bus *bus =NULL ;struct pci_sysdata *sd; +int bus_max;while ((bus =pci_find_next_bus (bus)) !=NULL ) {if (bus->number == busnum) {
@@ -454,8 +455,9 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum) sd->node =get_mp_bus_to_node (busnum);printk (KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n" , busnum); -x86_pci_root_bus_resources (busnum, &resources); - bus =pci_scan_root_bus (NULL , busnum, &pci_root_ops, sd, &resources); +x86_pci_root_bus_resources (busnum, &bus_max, &resources); + bus =pci_scan_root_bus_max (NULL , busnum, bus_max, &pci_root_ops, sd, + &resources);if (!bus) {pci_free_resource_list (&resources);kfree (sd);
@@ -643,6 +645,7 @@ struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops,LIST_HEAD (resources);struct pci_bus *bus =NULL ;struct pci_sysdata *sd; +int bus_max;/* * Allocate per-root-bus (not per bus) arch-specific data.
@@ -655,8 +658,8 @@ struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops,return NULL ; } sd->node = node; -x86_pci_root_bus_resources (busno, &resources); - bus =pci_scan_root_bus (NULL , busno, ops, sd, &resources); +x86_pci_root_bus_resources (busno, &bus_max, &resources); + bus =pci_scan_root_bus_max (NULL , busno, bus_max, ops, sd, &resources);if (!bus) {pci_free_resource_list (&resources);kfree (sd);
Signature · 1 line
1.7.7
PATCH 6/15 PCI, ia64: Register busn_res for root buses
In reply to Yinghai Lu--- arch/ia64/pci/pci.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/ia64/pci/pci.c +2 -0
@@ -331,6 +331,7 @@ pci_acpi_scan_root(struct acpi_pci_root *root)struct acpi_device *device = root->device;int domain = root->segment;int bus = root->secondary.start; +int busmax = root->secondary.end;struct pci_controller *controller;unsigned int windows =0 ;struct pci_root_info info;
@@ -384,6 +385,7 @@ pci_acpi_scan_root(struct acpi_pci_root *root)return NULL ; } +pci_bus_insert_busn_res (pbus, busnum, busmax); pbus->subordinate =pci_scan_child_bus (pbus);return pbus;
Signature · 1 line
1.7.7
PATCH 7/15 PCI, powerpc: Register busn_res for root buses
In reply to Yinghai Lu--- arch/powerpc/kernel/pci-common.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/powerpc/kernel/pci-common.c +6 -1
@@ -1732,6 +1732,8 @@ void __devinit pcibios_scan_phb(struct pci_controller *hose) bus->secondary = hose->first_busno; hose->bus = bus; +pci_bus_insert_busn_res (bus, hose->first_busno, hose->last_busno); +/* Get probe mode and perform scan */ mode =PCI_PROBE_NORMAL ;if (node && ppc_md.pci_probe_mode)
@@ -1742,8 +1744,11 @@ void __devinit pcibios_scan_phb(struct pci_controller *hose)of_scan_bus (node, bus); } -if (mode ==PCI_PROBE_NORMAL ) +if (mode ==PCI_PROBE_NORMAL ) { +pci_bus_update_busn_res_end (bus,255 ); hose->last_busno = bus->subordinate =pci_scan_child_bus (bus); +pci_bus_update_busn_res_end (bus, bus->subordinate); + }/* Platform gets a chance to do some global fixups before * we proceed to resource allocation
Signature · 1 line
1.7.7
PATCH 8/15 PCI, parisc: Register busn_res for root buses
In reply to Yinghai Lu--- drivers/parisc/dino.c | 2 ++ drivers/parisc/lba_pci.c | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-)
drivers/parisc/dino.c +2 -0
@@ -1014,7 +1014,9 @@ static int __init dino_probe(struct parisc_device *dev)return 0 ; } +pci_bus_insert_busn_res (bus, dino_current_bus,255 ); bus->subordinate =pci_scan_child_bus (bus); +pci_bus_update_busn_res_end (bus, bus->subordinate);/* This code *depends* on scanning being single threaded * if it isn't, this global bus number count will fail
drivers/parisc/lba_pci.c +3 -0
@@ -1531,6 +1531,9 @@ lba_driver_probe(struct parisc_device *dev)return 0 ; } +pci_bus_insert_busn_res (lba_bus, lba_dev->hba.bus_num.start, + lba_dev->hba.bus_num.end); + lba_bus->subordinate =pci_scan_child_bus (lba_bus);/* This is in lieu of calling pci_assign_unassigned_resources() */
Signature · 1 line
1.7.7
PATCH 9/15 PCI: Add pci_bus_extend/shrink_top()
In reply to Yinghai Luextend or shrink bus and parent buses top (subordinate)
extended range is verified safe range, and stop at recorded parent_res.
--- drivers/pci/probe.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-)
drivers/pci/probe.c +46 -0
@@ -624,6 +624,52 @@ static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max) } } +static void __devinit pci_bus_extend_top (struct pci_bus *parent, +resource_size_t size,struct resource *parent_res) +{ +struct resource *res; + +if (!size) +return ; + +while (parent) { + res = &parent->busn_res; +if (res == parent_res) +break ; + res->end += size; + parent->subordinate += size; +pci_write_config_byte (parent->self,PCI_SUBORDINATE_BUS , + parent->subordinate); +dev_printk (KERN_DEBUG , &parent->dev, +"busn_res: extended %02llx to %pR\n" , + (unsigned long long )size, res); + parent = parent->parent; + } +} + +static void __devinit pci_bus_shrink_top (struct pci_bus *parent, +resource_size_t size,struct resource *parent_res) +{ +struct resource *res; + +if (!size) +return ; + +while (parent) { + res = &parent->busn_res; +if (res == parent_res) +break ; + res->end -= size; + parent->subordinate -= size; +pci_write_config_byte (parent->self,PCI_SUBORDINATE_BUS , + parent->subordinate); +dev_printk (KERN_DEBUG , &parent->dev, +"busn_res: shrunk %02llx to %pR\n" , + (unsigned long long )size, res); + parent = parent->parent; + } +} +/* * If it's a bridge, configure it and scan the bus behind it. * For CardBus bridges, we don't scan behind as the devices will
Signature · 1 line
1.7.7
PATCH 10/15 PCI: Probe safe range that we can use for unassigned bridge.
In reply to Yinghai LuTry to allocate from parent bus busn_res. if can not find any big enough, will try to extend parent bus top. even the extending is through allocating, after allocating will pad the range to parent buses top.
When extending happens, We will record the parent_res, so could use it as stopper for really extend/shrink top later.
--- drivers/pci/probe.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 114 insertions(+), 0 deletions(-)
drivers/pci/probe.c +114 -0
@@ -670,6 +670,120 @@ static void __devinit pci_bus_shrink_top(struct pci_bus *parent, } } +static resource_size_t __devinit find_res_top_free_size (struct resource *res) +{ +int ret = -ENOMEM ; +resource_size_t n_size; +struct resource tmp_res; + +/* +* find out number below res->end, that we can use at first +* res->start can not be used. +*/ + n_size =resource_size (res) -1 ; +memset (&tmp_res,0 ,sizeof (struct resource )); +while (n_size >0 ) { + ret =allocate_resource (res, &tmp_res, n_size, + res->end - n_size +1 , res->end, +1 ,NULL ,NULL ); +if (ret ==0 ) { +/* release busn_res */ +release_resource (&tmp_res); +break ; + } + n_size--; + } + +return n_size; +} + +static int __devinit pci_bridge_probe_busn_res (struct pci_bus *bus, +struct pci_dev *dev,struct resource *busn_res, +resource_size_t needed_size,struct resource **p) +{ +int ret = -ENOMEM ; +resource_size_t n_size; +struct pci_bus *parent; +struct resource *parent_res; +resource_size_t tmp = bus->busn_res.end +1 ; +int free_sz =-1 ; + + parent_res =NULL ; + +again: +/* +* find bigest range in bus->busn_res that we can use in the middle +* and we can not use bus->busn_res.start. +*/ + n_size =resource_size (&bus->busn_res) -1 ; +memset (busn_res,0 ,sizeof (struct resource )); +dev_printk (KERN_DEBUG , &dev->dev, +"find free busn in busn_res: %pR\n" , &bus->busn_res); +while (n_size >= needed_size) { + ret =allocate_resource (&bus->busn_res, busn_res, n_size, + bus->busn_res.start +1 , bus->busn_res.end, +1 ,NULL ,NULL ); +if (ret ==0 ) { +/* found one, prepare to return */ +release_resource (busn_res); + +return ret; + } + n_size--; + } + +/* try extend the top of parent buss */ +if (free_sz <0 ) { + free_sz =find_res_top_free_size (&bus->busn_res); +dev_printk (KERN_DEBUG , &dev->dev, +"found free busn %d in busn_res: %pR top\n" , + free_sz, &bus->busn_res); + } + n_size = free_sz; + +/* check if extend could cross domain boundary */ +if ((bus->busn_res.end &0xff ) ==0xff ) + goto reduce_needed_size; +if ((0x100 - (tmp &0xff )) < (needed_size - n_size)) + goto reduce_needed_size; + +/* find exteded range */ +memset (busn_res,0 ,sizeof (struct resource )); + parent = bus->parent; +while (parent) { + ret =allocate_resource (&parent->busn_res, busn_res, + needed_size - n_size, + tmp, tmp + needed_size - n_size -1 , +1 ,NULL ,NULL ); +if (ret ==0 ) +break ; + parent = parent->parent; + } + +reduce_needed_size: +if (ret !=0 ) { + needed_size--; +if (!needed_size) +return ret; + + goto again; + } + +/* save parent_res, we need it as stopper later */ + parent_res = busn_res->parent; + +/* prepare busn_res for return */ +release_resource (busn_res); + busn_res->start -= n_size; + +/* extend parent bus top*/ +pci_bus_extend_top (bus, needed_size - n_size, parent_res); + + *p = parent_res; + +return ret; +} +/* * If it's a bridge, configure it and scan the bus behind it. * For CardBus bridges, we don't scan behind as the devices will
Signature · 1 line
1.7.7
PATCH 11/15 PCI: Strict checking of valid range for bridge
In reply to Yinghai Luchildren bridges busn range should be able to be allocated from parent bus range.
to avoid overlapping between sibling bridges on same bus.
--- drivers/pci/probe.c | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-)
drivers/pci/probe.c +25 -0
@@ -784,6 +784,31 @@ reduce_needed_size:return ret; } +static int __devinit pci_bridge_check_busn_broken (struct pci_bus *bus, +struct pci_dev *dev, +int secondary,int subordinate) +{ +int broken =0 ; + +struct resource busn_res; +int ret; + +memset (&busn_res,0 ,sizeof (struct resource )); +dev_printk (KERN_DEBUG , &dev->dev, +"check if busn %02x-%02x is in busn_res: %pR\n" , + secondary, subordinate, &bus->busn_res); + ret =allocate_resource (&bus->busn_res, &busn_res, + (subordinate - secondary +1 ), + (pci_domain_nr (bus)<<8 ) | secondary, + (pci_domain_nr (bus)<<8 ) | subordinate, +1 ,NULL ,NULL ); +if (ret) + broken =1 ; +else +release_resource (&busn_res); + +return broken; +}/* * If it's a bridge, configure it and scan the bus behind it. * For CardBus bridges, we don't scan behind as the devices will
Signature · 1 line
1.7.7
PATCH 12/15 PCI: Allocate bus range instead of use max blindly
In reply to Yinghai Luevery bus have extra busn_res, and linked them toghter to iobusn_resource.
when need to find usable bus number range, try probe from iobusn_resource tree.
To avoid falling to small hole in the middle, we try from 8 spare bus.
if can not find 8 or more in the middle, will try to append 8 on top later. then if can not append, will try to find 7 from the middle, then will try to append 7 on top. then if can not append, will try to find 6 from the middle...
for cardbus will only find 4 spare.
if extend from top, at last will shrink back to really needed range...
-v4: fix checking with pci rescan. Found by Bjorn.
--- drivers/pci/probe.c | 101 ++++++++++++++++++++++++++++++--------------------- 1 files changed, 60 insertions(+), 41 deletions(-)
drivers/pci/probe.c +60 -41
@@ -823,10 +823,11 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, {struct pci_bus *child;int is_cardbus = (dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ); -u32 buses, i, j =0 ; +u32 buses;u16 bctl;u8 primary, secondary, subordinate;int broken =0 ; +struct resource *parent_res =NULL ;pci_read_config_dword (dev,PCI_PRIMARY_BUS , &buses); primary = buses &0xFF ;
@@ -838,10 +839,16 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,/* Check if setup is sensible at all */ if (!pass && - (primary != bus->number || secondary <= bus->number)) { -dev_dbg (&dev->dev,"bus configuration invalid, reconfiguring\n" ); + (primary != bus->number || secondary <= bus->number)) broken =1 ; - } + +/* more strict checking */ +if (!pass && !broken && !dev->subordinate) + broken =pci_bridge_check_busn_broken (bus, dev, + secondary, subordinate); + +if (broken) +dev_dbg (&dev->dev,"bus configuration invalid, reconfiguring\n" );/* Disable MasterAbortMode during probing to avoid reporting of bus errors (in some architectures) */
@@ -874,6 +881,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, child->primary = primary; child->subordinate = subordinate; child->bridge_ctl = bctl; + +pci_bus_insert_busn_res (child, secondary, subordinate); } cmax =pci_scan_child_bus (child);
@@ -886,6 +895,11 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,* We need to assign a number to this bus which we always * do in the second pass. */ +resource_size_t shrink_size; +struct resource busn_res; +int ret = -ENOMEM ; +int old_max = max; +if (!pass) {if (pcibios_assign_all_busses () || broken)/* Temporarily disable forwarding of the
@@ -902,20 +916,44 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,/* Clear errors */ pci_write_config_word (dev,PCI_STATUS ,0xffff ); -/* Prevent assigning a bus number that already exists. -* This can happen when a bridge is hot-plugged, so in -* this case we only re-scan this bus. */ - child =pci_find_bus (pci_domain_nr (bus), max+1 ); -if (!child) { - child =pci_add_new_bus (bus, dev, ++max); -if (!child) - goto out; +if (dev->subordinate) { +/* We get here only for cardbus */ + child = dev->subordinate; +if (!is_cardbus) +dev_warn (&dev->dev, +"rescan scaned bridge as broken one again ?" ); + + goto out; } +/* +* For CardBus bridges, we leave 4 bus numbers +* as cards with a PCI-to-PCI bridge can be +* inserted later. +* other just allocate 8 bus to avoid we fall into +* small hole in the middle. +*/ + ret =pci_bridge_probe_busn_res (bus, dev, &busn_res, + is_cardbus ? (CARDBUS_RESERVE_BUSNR +1 ) :8 , + &parent_res); + +if (ret !=0 ) + goto out; + + child =pci_add_new_bus (bus, dev, busn_res.start &0xff ); +if (!child) + goto out; + + child->subordinate = busn_res.end &0xff ; +pci_bus_insert_busn_res (child, busn_res.start &0xff , + busn_res.end &0xff ); + buses = (buses &0xff000000 ) | ((unsigned int )(child->primary) <<0 ) | ((unsigned int )(child->secondary) <<8 ) | ((unsigned int )(child->subordinate) <<16 ); + max = child->subordinate; +/* * yenta.c forces a secondary latency timer of 176. * Copy that behaviour here.
@@ -946,43 +984,24 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,* the real value of max. */ pci_fixup_parent_subordinate_busnr (child, max); + }else { -/* -* For CardBus bridges, we leave 4 bus numbers -* as cards with a PCI-to-PCI bridge can be -* inserted later. -*/ -for (i=0 ; i<CARDBUS_RESERVE_BUSNR ; i++) { -struct pci_bus *parent = bus; -if (pci_find_bus (pci_domain_nr (bus), - max+i+1 )) -break ; -while (parent->parent) { -if ((!pcibios_assign_all_busses ()) && - (parent->subordinate > max) && - (parent->subordinate <= max+i)) { - j =1 ; - } - parent = parent->parent; - } -if (j) { -/* -* Often, there are two cardbus bridges -* -- try to leave one valid bus number -* for each one. -*/ - i /=2 ; -break ; - } - } - max += i;pci_fixup_parent_subordinate_busnr (child, max); }/* * Set the subordinate bus number to its real value. */ + shrink_size = child->subordinate - max; child->subordinate = max;pci_write_config_byte (dev,PCI_SUBORDINATE_BUS , max); +pci_bus_update_busn_res_end (child, max); + +/* shrink some back, if we extend top before */ +if (!is_cardbus && (shrink_size >0 ) && parent_res) +pci_bus_shrink_top (bus, shrink_size, parent_res); + +if (old_max > max) + max = old_max; } sprintf(child->name,
Signature · 1 line
1.7.7
PATCH 13/15 PCI: kill pci_fixup_parent_subordinate_busnr()
In reply to Yinghai LuNow we can safely extend parent top and shrink them according iobusn_resource tree.
Don't need that any more.
--- drivers/pci/probe.c | 33 ++------------------------------- 1 files changed, 2 insertions(+), 31 deletions(-)
drivers/pci/probe.c +2 -31
@@ -608,22 +608,6 @@ struct pci_bus *__ref pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dereturn child; } -static void pci_fixup_parent_subordinate_busnr (struct pci_bus *child,int max) -{ -struct pci_bus *parent = child->parent; - -/* Attempts to fix that up are really dangerous unless -we're going to re-assign all bus numbers. */ -if (!pcibios_assign_all_busses ()) -return ; - -while (parent->parent && parent->subordinate < max) { - parent->subordinate = max; -pci_write_config_byte (parent->self,PCI_SUBORDINATE_BUS , max); - parent = parent->parent; - } -} -static void __devinit pci_bus_extend_top (struct pci_bus *parent,resource_size_t size,struct resource *parent_res) {
@@ -970,24 +954,11 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,if (!is_cardbus) { child->bridge_ctl = bctl; -/* -* Adjust subordinate busnr in parent buses. -* We do this before scanning for children because -* some devices may not be detected if the bios -* was lazy. -*/ -pci_fixup_parent_subordinate_busnr (child, max); +/* Now we can scan all subordinate buses... */ max =pci_scan_child_bus (child); -/* -* now fix it up again since we have found -* the real value of max. -*/ -pci_fixup_parent_subordinate_busnr (child, max); - - }else { -pci_fixup_parent_subordinate_busnr (child, max); } +/* * Set the subordinate bus number to its real value. */
Signature · 1 line
1.7.7
PATCH 14/15 PCI: Seperate child bus scanning to two passes overall
In reply to Yinghai LuIn extreme case: Two bridges are properly setup.
bridge A
bridge AA
bridge AB
bridge B
bridge BA
bridge BB
but AA, AB are not setup properly.
bridge A has small range, and bridge AB could need more, when do the
first pass0 for bridge A, it will do pass0 and pass1 for AA and AB,
during that process, it will extend range of A for AB blindly. because bridge B is not registered yet.
that could overlap range that is used by bridge B.
Right way should be:
do pass0 for all good bridges at first.
So we could do pass0 for bridge B before pass1 for bridge AB.
--- drivers/pci/probe.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 files changed, 34 insertions(+), 16 deletions(-)
drivers/pci/probe.c +34 -16
@@ -793,6 +793,9 @@ static int __devinit pci_bridge_check_busn_broken(struct pci_bus *bus,return broken; } + +static unsigned int __devinit __pci_scan_child_bus (struct pci_bus *bus, +int pass);/* * If it's a bridge, configure it and scan the bus behind it. * For CardBus bridges, we don't scan behind as the devices will
@@ -844,11 +847,10 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, !is_cardbus && !broken) {unsigned int cmax;/* -* Bus already configured by firmware, process it in the first -* pass and just note the configuration. +* Bus already configured by firmware, still process it in two +* passes in extreme case like two adjaced bridges have children +* bridges that are not setup properly. */ -if (pass) - goto out;/* * If we already got to this bus through a different bridge,
@@ -869,7 +871,7 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,pci_bus_insert_busn_res (child, secondary, subordinate); } - cmax =pci_scan_child_bus (child); + cmax =__pci_scan_child_bus (child, pass);if (cmax > max) max = cmax;if (child->subordinate > max)
@@ -1668,12 +1670,13 @@ void pcie_bus_configure_settings(struct pci_bus *bus, u8 mpss) }EXPORT_SYMBOL_GPL (pcie_bus_configure_settings); -unsigned int __devinit pci_scan_child_bus (struct pci_bus *bus) +static unsigned int __devinit __pci_scan_child_bus (struct pci_bus *bus, +int pass) { -unsigned int devfn, pass, max = bus->secondary; +unsigned int devfn, max = bus->secondary;struct pci_dev *dev; -dev_dbg (&bus->dev,"scanning bus\n" ); +dev_dbg (&bus->dev,"scanning bus pass %d\n" , pass);/* Go find them, Rover! */ for (devfn =0 ; devfn <0x100 ; devfn +=8 )
@@ -1687,18 +1690,16 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)* all PCI-to-PCI bridges on this bus. */ if (!bus->is_added) { -dev_dbg (&bus->dev,"fixups for bus\n" ); +dev_dbg (&bus->dev,"fixups for bus pass %d\n" , pass);pcibios_fixup_bus (bus);if (pci_is_root_bus (bus)) bus->is_added =1 ; } -for (pass=0 ; pass <2 ; pass++) -list_for_each_entry (dev, &bus->devices, bus_list) { -if (dev->hdr_type ==PCI_HEADER_TYPE_BRIDGE || - dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ) - max =pci_scan_bridge (bus, dev, max, pass); - } +list_for_each_entry (dev, &bus->devices, bus_list) +if (dev->hdr_type ==PCI_HEADER_TYPE_BRIDGE || + dev->hdr_type ==PCI_HEADER_TYPE_CARDBUS ) + max =pci_scan_bridge (bus, dev, max, pass);/* * We've scanned the bus and so we know all about what's on
@@ -1707,7 +1708,24 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)* * Return how far we've got finding sub-buses. */ -dev_dbg (&bus->dev,"bus scan returning with max=%02x\n" , max); +dev_dbg (&bus->dev,"bus scan returning with max=%02x pass %d\n" , + max, pass); + +return max; +} + +unsigned int __devinit pci_scan_child_bus (struct pci_bus *bus) +{ +int pass; +unsigned int max =0 , tmp; + +for (pass =0 ; pass <2 ; pass++) { + tmp =__pci_scan_child_bus (bus, pass); + +if (tmp > max) + max = tmp; + } +return max; }
Signature · 1 line
1.7.7
PATCH 15/15 pcmcia: remove workaround for fixing pci parent bus subordinate
In reply to Yinghai LuNow pci busn allocation code is there, and it will preallocate bus number and it will make sure parent buses subordinate is right.
So remove workaround here.
--- drivers/pcmcia/yenta_socket.c | 75 ----------------------------------------- 1 files changed, 0 insertions(+), 75 deletions(-)
drivers/pcmcia/yenta_socket.c +0 -75
@@ -1064,79 +1064,6 @@ static void yenta_config_init(struct yenta_socket *socket)config_writew (socket,CB_BRIDGE_CONTROL , bridge); } -/** -* yenta_fixup_parent_bridge - Fix subordinate bus# of the parent bridge -* @cardbus_bridge: The PCI bus which the CardBus bridge bridges to -* -* Checks if devices on the bus which the CardBus bridge bridges to would be -* invisible during PCI scans because of a misconfigured subordinate number -* of the parent brige - some BIOSes seem to be too lazy to set it right. -* Does the fixup carefully by checking how far it can go without conflicts. -* See http://bugzilla.kernel.org/show_bug.cgi?id=2944 for more information. -*/ -static void yenta_fixup_parent_bridge (struct pci_bus *cardbus_bridge) -{ -struct list_head *tmp; -unsigned char upper_limit; -/* -* We only check and fix the parent bridge: All systems which need -* this fixup that have been reviewed are laptops and the only bridge -* which needed fixing was the parent bridge of the CardBus bridge: -*/ -struct pci_bus *bridge_to_fix = cardbus_bridge->parent; - -/* Check bus numbers are already set up correctly: */ -if (bridge_to_fix->subordinate >= cardbus_bridge->subordinate) -return ;/* The subordinate number is ok, nothing to do */ - -if (!bridge_to_fix->parent) -return ;/* Root bridges are ok */ - -/* stay within the limits of the bus range of the parent: */ - upper_limit = bridge_to_fix->parent->subordinate; - -/* check the bus ranges of all silbling bridges to prevent overlap */ -list_for_each (tmp, &bridge_to_fix->parent->children) { -struct pci_bus *silbling =pci_bus_b (tmp); -/* -* If the silbling has a higher secondary bus number -* and it's secondary is equal or smaller than our -* current upper limit, set the new upper limit to -* the bus number below the silbling's range: -*/ -if (silbling->secondary > bridge_to_fix->subordinate - && silbling->secondary <= upper_limit) - upper_limit = silbling->secondary -1 ; - } - -/* Show that the wanted subordinate number is not possible: */ -if (cardbus_bridge->subordinate > upper_limit) -dev_printk (KERN_WARNING , &cardbus_bridge->dev, -"Upper limit for fixing this " -"bridge's parent bridge: #%02x\n" , upper_limit); - -/* If we have room to increase the bridge's subordinate number, */ -if (bridge_to_fix->subordinate < upper_limit) { - -/* use the highest number of the hidden bus, within limits */ -unsigned char subordinate_to_assign = -min (cardbus_bridge->subordinate, upper_limit); - -dev_printk (KERN_INFO , &bridge_to_fix->dev, -"Raising subordinate bus# of parent " -"bus (#%02x) from #%02x to #%02x\n" , - bridge_to_fix->number, - bridge_to_fix->subordinate, subordinate_to_assign); - -/* Save the new subordinate in the bus struct of the bridge */ - bridge_to_fix->subordinate = subordinate_to_assign; - -/* and update the PCI config space with the new subordinate */ -pci_write_config_byte (bridge_to_fix->self, -PCI_SUBORDINATE_BUS , bridge_to_fix->subordinate); - } -} -/* * Initialize a cardbus controller. Make sure we have a usable * interrupt, and that we can map the cardbus area. Fill in the
@@ -1257,8 +1184,6 @@ static int __devinit yenta_probe(struct pci_dev *dev, const struct pci_device_iddev_printk (KERN_INFO , &dev->dev,"Socket status: %08x\n" ,cb_readl (socket,CB_SOCKET_STATE )); -yenta_fixup_parent_bridge (dev->subordinate); -/* Register it with the pcmcia layer.. */ ret =pcmcia_register_socket (&socket->socket);if (ret ==0 ) {
Signature · 1 line
1.7.7