PCI: pci_host_bridge related cleanup
Subsystems (4)
cover PCI: pci_host_bridge related cleanup
will add struct device dev into host_bridge struct.
also will add release support to make sure allocated resource get freed during root bus removal including hostbridge and pci_sysdata.
The patches need to apply to linus v3.3 plus pci/linux-next
could get from
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-hostbridge-cleanup
-v2: dropped the patch that is with x86 pcibios_bus_to_resource that Bjorn objected.
reorder the patchesset to mold one appended patch into previous patch.
-v3: separate the patchset.
Thanks
Yinghai
Yinghai Lu (11):
PCI: Separate host_bridge code out from probe.c x86, PCI: Fix memleak with get_current_resources()
PCI: Rename pci_host_bridge() to find_pci_root_bridge()
PCI: Add generic device into pci_host_bridge struct
PCI: Add host bridge release support
x86, PCI: Break down get_current_resource()
x86, PCI: Add host bridge resource release for _CRS path x86, PCI: Embed name into pci_root_info struct x86, PCI: Embed pci_sysdata into pci_root_info on acpi path x86, PCI: Allocate pci_root_info for not using _CRS path x86, PCI: Merge root info printing for not using _CRS path
arch/x86/pci/acpi.c | 116 +++++++++++++++++++++------------- arch/x86/pci/amd_bus.c | 78 +++++++---------------- arch/x86/pci/broadcom_bus.c | 17 +---- arch/x86/pci/bus_numa.c | 86 +++++++++++++++++++------- arch/x86/pci/bus_numa.h | 19 +++--- drivers/pci/Makefile | 2 +- drivers/pci/host-bridge.c | 96 ++++++++++++++++++++++++++++ drivers/pci/probe.c | 146 +++++++++++-------------------------------- include/linux/pci.h | 9 +++- 9 files changed, 313 insertions(+), 256 deletions(-) create mode 100644 drivers/pci/host-bridge.c
Signature · 1 line
1.7.7
PATCH 1/11 PCI: Separate host_bridge code out from probe.c
We could put pci host bridge related code there, So could keep probe.c smaller.
-v2: Bjorn want add_to_pci_host_bridges to pass struct pci_host_bridge *
instead of list head pointer.
--- drivers/pci/Makefile | 2 +- drivers/pci/host-bridge.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 2 + drivers/pci/probe.c | 81 +-------------------------------------- 4 files changed, 97 insertions(+), 81 deletions(-) create mode 100644 drivers/pci/host-bridge.c
drivers/pci/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for the PCI bus specific drivers. # -obj-y += access.o bus.o probe.o remove.o pci.o \ +obj-y += access.o bus.o probe.o host-bridge.o remove.o pci.o \ pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \ irq.o vpd.o obj-$(CONFIG_PROC_FS) += proc.o
drivers/pci/host-bridge.c new file +93 -0
93 lines not on this page · raw message
drivers/pci/pci.h +2 -0
@@ -231,6 +231,8 @@ static inline int pci_ari_enabled(struct pci_bus *bus)void pci_reassigndev_resource_alignment (struct pci_dev *dev);extern void pci_disable_bridge_window (struct pci_dev *dev); +void add_to_pci_host_bridges (struct pci_host_bridge *bridge); +/* Single Root I/O Virtualization */ struct pci_sriov {int pos;/* capability position */
drivers/pci/probe.c +1 -80
103 lines not on this page · raw message
Signature · 1 line
1.7.7
PATCH 2/11 x86, PCI: Fix memleak with get_current_resources()
In reply to Yinghai LuIn pci_scan_acpi_root(), when pci_use_crs is set, get_current_resources() is used to get pci_root_info, and it will allocate name and resource array.
Later if pci_create_root_bus() can not create bus (could be already there...) it will only free bus res list, but the name and res array is not freed.
Let get_current_resource() take info pointer instead of using local info.
--- arch/x86/pci/acpi.c | 49 ++++++++++++++++++++++++++++++------------------- 1 files changed, 30 insertions(+), 19 deletions(-)
arch/x86/pci/acpi.c +30 -19
@@ -315,49 +315,55 @@ static void add_resources(struct pci_root_info *info) } } +static void free_pci_root_info (struct pci_root_info *info) +{ +kfree (info->name); +kfree (info->res); +memset (info,0 ,sizeof (struct pci_root_info )); +} +static void -get_current_resources (struct acpi_device *device,int busnum, +get_current_resources (struct pci_root_info *info, +struct acpi_device *device,int busnum,int domain,struct list_head *resources) { -struct pci_root_info info;size_t size; - info.bridge = device; - info.res_num =0 ; - info.resources = resources; + info->bridge = device; + info->res_num =0 ; + info->resources = resources;acpi_walk_resources (device->handle,METHOD_NAME__CRS , count_resource, - &info); -if (!info.res_num) + info); +if (!info->res_num)return ; - size =sizeof (*info.res) * info.res_num; - info.res =kmalloc (size,GFP_KERNEL ); -if (!info.res) + size =sizeof (*info->res) * info->res_num; + info->res =kmalloc (size,GFP_KERNEL ); +if (!info->res)return ; - info.name =kasprintf (GFP_KERNEL ,"PCI Bus %04x:%02x" , domain, busnum); -if (!info.name) + info->name =kasprintf (GFP_KERNEL ,"PCI Bus %04x:%02x" , domain, busnum); +if (!info->name) goto name_alloc_fail; - info.res_num =0 ; + info->res_num =0 ;acpi_walk_resources (device->handle,METHOD_NAME__CRS , setup_resource, - &info); + info);if (pci_use_crs) { -add_resources (&info); +add_resources (info);return ; } -kfree (info.name); - name_alloc_fail: -kfree (info.res); +free_pci_root_info (info); }struct pci_bus *__devinit pci_acpi_scan_root (struct acpi_pci_root *root) {struct acpi_device *device = root->device; +struct pci_root_info info;int domain = root->segment;int busnum = root->secondary.start;LIST_HEAD (resources);
@@ -402,6 +408,7 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root) sd->domain = domain; sd->node = node; +memset (&info,0 ,sizeof (struct pci_root_info ));/* * Maybe the desired pci bus has been already scanned. In such case * it is unnecessary to scan the pci bus with the given domain,busnum.
@@ -415,7 +422,8 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)memcpy (bus->sysdata, sd,sizeof (*sd));kfree (sd); }else { -get_current_resources (device, busnum, domain, &resources); +get_current_resources (&info, device, busnum, domain, + &resources);/* * _CRS with no apertures is normal, so only fall back to
@@ -429,6 +437,9 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root) bus->subordinate =pci_scan_child_bus (bus); else pci_free_resource_list(&resources); + +if (!bus && pci_use_crs) +free_pci_root_info (&info); }/* After the PCI-E bus has been walked and all devices discovered,
Signature · 1 line
1.7.7
PATCH 3/11 PCI: Rename pci_host_bridge() to find_pci_root_bridge()
In reply to Yinghai Lupci_host_bridge() looks like C++ constructor ?
Also separate find_pci_root_bus() out.
-v2: According to Bjorn, remove extra null checking.
--- drivers/pci/host-bridge.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-)
drivers/pci/host-bridge.c +13 -5
@@ -16,15 +16,22 @@ void add_to_pci_host_bridges(struct pci_host_bridge *bridge)list_add_tail (&bridge->list, &pci_host_bridges); } -static struct pci_host_bridge *pci_host_bridge (struct pci_dev *dev) +static struct pci_bus *find_pci_root_bus (struct pci_dev *dev) {struct pci_bus *bus; -struct pci_host_bridge *bridge; bus = dev->bus;while (bus->parent) bus = bus->parent; +return bus; +} + +static struct pci_host_bridge *find_pci_host_bridge (struct pci_dev *dev) +{ +struct pci_bus *bus =find_pci_root_bus (dev); +struct pci_host_bridge *bridge; +list_for_each_entry (bridge, &pci_host_bridges, list) {if (bridge->bus == bus)return bridge;
@@ -41,7 +48,7 @@ static bool resource_contains(struct resource *res1, struct resource *res2)void pcibios_resource_to_bus (struct pci_dev *dev,struct pci_bus_region *region,struct resource *res) { -struct pci_host_bridge *bridge =pci_host_bridge (dev); +struct pci_host_bridge *bridge =find_pci_host_bridge (dev);struct pci_host_bridge_window *window;resource_size_t offset =0 ;
@@ -69,12 +76,13 @@ static bool region_contains(struct pci_bus_region *region1,void pcibios_bus_to_resource (struct pci_dev *dev,struct resource *res,struct pci_bus_region *region) { -struct pci_host_bridge *bridge =pci_host_bridge (dev); +struct pci_host_bridge *bridge =find_pci_host_bridge (dev);struct pci_host_bridge_window *window; -struct pci_bus_region bus_region;resource_size_t offset =0 ;list_for_each_entry (window, &bridge->windows, list) { +struct pci_bus_region bus_region; +if (resource_type (res) !=resource_type (window->res))continue ;
Signature · 1 line
1.7.7
PATCH 4/11 PCI: Add generic device into pci_host_bridge struct
In reply to Yinghai LuUse that device for pci_root_bus bridge pointer.
With that make code more simple.
Also we can use pci_release_bus_bridge_dev() to release allocated pci_host_bridge during removing path.
At last, we can use root bus bridge pointer to get host bridge pointer instead of going over host bridge list, so could kill that host bridge list.
-v2: Add one missing put_device() in failing path.
--- drivers/pci/host-bridge.c | 15 +--------- drivers/pci/pci.h | 2 - drivers/pci/probe.c | 66 ++++++++++++++++++++++++--------------------- include/linux/pci.h | 4 ++- 4 files changed, 39 insertions(+), 48 deletions(-)
drivers/pci/host-bridge.c +1 -14
@@ -9,13 +9,6 @@#include "pci.h" -static LIST_HEAD (pci_host_bridges); - -void add_to_pci_host_bridges (struct pci_host_bridge *bridge) -{ -list_add_tail (&bridge->list, &pci_host_bridges); -} -static struct pci_bus *find_pci_root_bus (struct pci_dev *dev) {struct pci_bus *bus;
@@ -30,14 +23,8 @@ static struct pci_bus *find_pci_root_bus(struct pci_dev *dev)static struct pci_host_bridge *find_pci_host_bridge (struct pci_dev *dev) {struct pci_bus *bus =find_pci_root_bus (dev); -struct pci_host_bridge *bridge; - -list_for_each_entry (bridge, &pci_host_bridges, list) { -if (bridge->bus == bus) -return bridge; - } -return NULL ; +return to_pci_host_bridge (bus->bridge); }static bool resource_contains (struct resource *res1,struct resource *res2)
drivers/pci/pci.h +0 -2
@@ -231,8 +231,6 @@ static inline int pci_ari_enabled(struct pci_bus *bus)void pci_reassigndev_resource_alignment (struct pci_dev *dev);extern void pci_disable_bridge_window (struct pci_dev *dev); -void add_to_pci_host_bridges (struct pci_host_bridge *bridge); -/* Single Root I/O Virtualization */ struct pci_sriov {int pos;/* capability position */
drivers/pci/probe.c +35 -31
123 lines not on this page · raw message
include/linux/pci.h +3 -1
@@ -375,11 +375,13 @@ struct pci_host_bridge_window { };struct pci_host_bridge { -struct list_head list; +struct device dev;struct pci_bus *bus;/* root bus */ struct list_head windows;/* pci_host_bridge_windows */ }; +#define to_pci_host_bridge (n) container_of(n, struct pci_host_bridge, dev) +/* * The first PCI_BRIDGE_RESOURCE_NUM PCI bus resources (those that correspond * to P2P or CardBus bridge windows) go in a table. Additional ones (for
Signature · 1 line
1.7.7
PATCH 5/11 PCI: Add host bridge release support
In reply to Yinghai LuWe need one hook to release host bridge resource that are allocated for host bridge during creating root bus.
--- drivers/pci/host-bridge.c | 8 ++++++++ drivers/pci/probe.c | 3 ++- include/linux/pci.h | 5 +++++ 3 files changed, 15 insertions(+), 1 deletions(-)
drivers/pci/host-bridge.c +8 -0
@@ -27,6 +27,14 @@ static struct pci_host_bridge *find_pci_host_bridge(struct pci_dev *dev)return to_pci_host_bridge (bus->bridge); } +void pci_set_host_bridge_release (struct pci_host_bridge *bridge, +void (*release_fn)(struct pci_host_bridge *), +void *release_data) +{ + bridge->release_fn = release_fn; + bridge->release_data = release_data; +} +static bool resource_contains (struct resource *res1,struct resource *res2) {return res1->start <= res2->start && res1->end >= res2->end;
drivers/pci/probe.c +2 -1
@@ -1136,7 +1136,8 @@ static void pci_release_bus_bridge_dev(struct device *dev) {struct pci_host_bridge *bridge =to_pci_host_bridge (dev); -/* TODO: need to free window->res */ +if (bridge->release_fn) + bridge->release_fn (bridge);pci_free_resource_list (&bridge->windows);
include/linux/pci.h +5 -0
@@ -378,9 +378,14 @@ struct pci_host_bridge {struct device dev;struct pci_bus *bus;/* root bus */ struct list_head windows;/* pci_host_bridge_windows */ +void (*release_fn)(struct pci_host_bridge *); +void *release_data; };#define to_pci_host_bridge (n) container_of(n, struct pci_host_bridge, dev) +void pci_set_host_bridge_release (struct pci_host_bridge *bridge, +void (*release_fn)(struct pci_host_bridge *), +void *release_data);/* * The first PCI_BRIDGE_RESOURCE_NUM PCI bus resources (those that correspond
Signature · 1 line
1.7.7
PATCH 6/11 x86, PCI: Break down get_current_resource()
In reply to Yinghai LuChange it to probe_pci_root_info, aka only do one thing.
1. Remove resource list head from pci_root_info
2. Make get_current_resources() not to pass resources
3. Rename get_current_resourcs name to probe_pci_root_info
--- arch/x86/pci/acpi.c | 34 +++++++++++++--------------------- 1 files changed, 13 insertions(+), 21 deletions(-)
arch/x86/pci/acpi.c +13 -21
@@ -12,7 +12,6 @@ struct pci_root_info {char *name;unsigned int res_num;struct resource *res; -struct list_head *resources;int busnum; };
@@ -287,7 +286,8 @@ static void coalesce_windows(struct pci_root_info *info, unsigned long type) } } -static void add_resources (struct pci_root_info *info) +static void add_resources (struct pci_root_info *info, +struct list_head *resources) {int i;struct resource *res, *root, *conflict;
@@ -311,7 +311,7 @@ static void add_resources(struct pci_root_info *info)"ignoring host bridge window %pR (conflicts with %s %pR)\n" , res, conflict->name, conflict); else - pci_add_resource(info->resources, res); +pci_add_resource (resources ,res ); } }
@@ -323,41 +323,30 @@ static void free_pci_root_info(struct pci_root_info *info) }static void -get_current_resources (struct pci_root_info *info, -struct acpi_device *device,int busnum, -int domain,struct list_head *resources) +probe_pci_root_info (struct pci_root_info *info,struct acpi_device *device, +int busnum,int domain) {size_t size; info->bridge = device; info->res_num =0 ; - info->resources = resources;acpi_walk_resources (device->handle,METHOD_NAME__CRS , count_resource, info);if (!info->res_num)return ; size =sizeof (*info->res) * info->res_num; + info->res_num =0 ; info->res =kmalloc (size,GFP_KERNEL );if (!info->res)return ; info->name =kasprintf (GFP_KERNEL ,"PCI Bus %04x:%02x" , domain, busnum);if (!info->name) - goto name_alloc_fail; +return ; - info->res_num =0 ;acpi_walk_resources (device->handle,METHOD_NAME__CRS , setup_resource, info); - -if (pci_use_crs) { -add_resources (info); - -return ; - } - -name_alloc_fail: -free_pci_root_info (info); }struct pci_bus *__devinit pci_acpi_scan_root (struct acpi_pci_root *root)
@@ -422,15 +411,18 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)memcpy (bus->sysdata, sd,sizeof (*sd));kfree (sd); }else { -get_current_resources (&info, device, busnum, domain, - &resources); +probe_pci_root_info (&info, device, busnum, domain);/* * _CRS with no apertures is normal, so only fall back to * defaults or native bridge info if we're ignoring _CRS. */ -if (!pci_use_crs) +if (pci_use_crs) +add_resources (&info, &resources); +else { +free_pci_root_info (&info);x86_pci_root_bus_resources (busnum, &resources); + } bus =pci_create_root_bus (NULL , busnum, &pci_root_ops, sd, &resources);if (bus)
Signature · 1 line
1.7.7
PATCH 7/11 x86, PCI: Add host bridge resource release for _CRS path
In reply to Yinghai Lu1. Allocate pci_root_info instead of use local stack. we need to pass around info for release fn.
2. Add release_pci_root_info
3. Set x86 own host bridge release fn, so will make sure root bridge related resources get freed during root bus removal.
--- arch/x86/pci/acpi.c | 63 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 51 insertions(+), 12 deletions(-)
arch/x86/pci/acpi.c +51 -12
@@ -315,11 +315,40 @@ static void add_resources(struct pci_root_info *info, } } -static void free_pci_root_info (struct pci_root_info *info) +static void free_pci_root_info_res (struct pci_root_info *info) {kfree (info->name);kfree (info->res); -memset (info,0 ,sizeof (struct pci_root_info )); + info->res =NULL ; + info->res_num =0 ; +} + +static void __release_pci_root_info (struct pci_root_info *info) +{ +int i; +struct resource *res; + +for (i =0 ; i < info->res_num; i++) { + res = &info->res[i]; + +if (!res->parent) +continue ; + +if (!(res->flags & (IORESOURCE_MEM |IORESOURCE_IO ))) +continue ; + +release_resource (res); + } + +free_pci_root_info_res (info); + +kfree (info); +} +static void release_pci_root_info (struct pci_host_bridge *bridge) +{ +struct pci_root_info *info = bridge->release_data; + +__release_pci_root_info (info); } static void
@@ -352,7 +381,7 @@ probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device,struct pci_bus *__devinit pci_acpi_scan_root (struct acpi_pci_root *root) {struct acpi_device *device = root->device; -struct pci_root_info info; +struct pci_root_info *info =NULL ;int domain = root->segment;int busnum = root->secondary.start;LIST_HEAD (resources);
@@ -397,7 +426,13 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root) sd->domain = domain; sd->node = node; -memset (&info,0 ,sizeof (struct pci_root_info )); + info =kzalloc (sizeof (*info),GFP_KERNEL ); +if (!info) { +kfree (sd); +printk (KERN_WARNING "pci_bus %04x:%02x: " +"ignored (out of memory)\n" , domain, busnum); +return NULL ; + }/* * Maybe the desired pci bus has been already scanned. In such case * it is unnecessary to scan the pci bus with the given domain,busnum.
@@ -409,29 +444,33 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)* be replaced by sd. */ memcpy (bus->sysdata, sd,sizeof (*sd)); +kfree (info);kfree (sd); }else { -probe_pci_root_info (&info, device, busnum, domain); +probe_pci_root_info (info, device, busnum, domain);/* * _CRS with no apertures is normal, so only fall back to * defaults or native bridge info if we're ignoring _CRS. */ if (pci_use_crs) -add_resources (&info, &resources); +add_resources (info, &resources);else { -free_pci_root_info (&info); +free_pci_root_info_res (info);x86_pci_root_bus_resources (busnum, &resources); } + bus =pci_create_root_bus (NULL , busnum, &pci_root_ops, sd, &resources); -if (bus) +if (bus) { bus->subordinate =pci_scan_child_bus (bus); -else +pci_set_host_bridge_release ( +to_pci_host_bridge (bus->bridge), + release_pci_root_info, info); + }else {pci_free_resource_list (&resources); - -if (!bus && pci_use_crs) -free_pci_root_info (&info); +__release_pci_root_info (info); + } }/* After the PCI-E bus has been walked and all devices discovered,
Signature · 1 line
1.7.7
PATCH 8/11 x86, PCI: Embed name into pci_root_info struct
In reply to Yinghai LuNow we allocate info, and keep that in during whole life of host bridge.
So don't allocate info->name seperately, just put name into struct.
--- arch/x86/pci/acpi.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
arch/x86/pci/acpi.c +2 -5
@@ -9,7 +9,7 @@struct pci_root_info {struct acpi_device *bridge; -char *name; +char name[16 ];unsigned int res_num;struct resource *res;int busnum;
@@ -317,7 +317,6 @@ static void add_resources(struct pci_root_info *info,static void free_pci_root_info_res (struct pci_root_info *info) { -kfree (info->name);kfree (info->res); info->res =NULL ; info->res_num =0 ;
@@ -370,9 +369,7 @@ probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device,if (!info->res)return ; - info->name =kasprintf (GFP_KERNEL ,"PCI Bus %04x:%02x" , domain, busnum); -if (!info->name) -return ; +sprintf (info->name,"PCI Bus %04x:%02x" , domain, busnum);acpi_walk_resources (device->handle,METHOD_NAME__CRS , setup_resource, info);
Signature · 1 line
1.7.7
PATCH 9/11 x86, PCI: Embed pci_sysdata into pci_root_info on acpi path
In reply to Yinghai LuSo that part memory will be released on root bus removing path.
--- arch/x86/pci/acpi.c | 21 ++++----------------- 1 files changed, 4 insertions(+), 17 deletions(-)
arch/x86/pci/acpi.c +4 -17
@@ -13,6 +13,7 @@ struct pci_root_info {unsigned int res_num;struct resource *res;int busnum; +struct pci_sysdata sd; };static bool pci_use_crs = true;
@@ -410,26 +411,16 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)if (node !=-1 && !node_online (node)) node =-1 ; -/* Allocate per-root-bus (not per bus) arch-specific data. -* TODO: leak; this memory is never freed. -* It's arguable whether it's worth the trouble to care. -*/ - sd =kzalloc (sizeof (*sd),GFP_KERNEL ); -if (!sd) { + info =kzalloc (sizeof (*info),GFP_KERNEL ); +if (!info) {printk (KERN_WARNING "pci_bus %04x:%02x: " "ignored (out of memory)\n" , domain, busnum);return NULL ; } + sd = &info->sd; sd->domain = domain; sd->node = node; - info =kzalloc (sizeof (*info),GFP_KERNEL ); -if (!info) { -kfree (sd); -printk (KERN_WARNING "pci_bus %04x:%02x: " -"ignored (out of memory)\n" , domain, busnum); -return NULL ; - }/* * Maybe the desired pci bus has been already scanned. In such case * it is unnecessary to scan the pci bus with the given domain,busnum.
@@ -442,7 +433,6 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root)*/ memcpy (bus->sysdata, sd,sizeof (*sd));kfree (info); -kfree (sd); }else {probe_pci_root_info (info, device, busnum, domain);
@@ -484,9 +474,6 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root) } } -if (!bus) -kfree (sd); -if (bus && node !=-1 ) {#ifdef CONFIG_ACPI_NUMA if (pxm >=0 )
Signature · 1 line
1.7.7
PATCH 10/11 x86, PCI: Allocate pci_root_info for not using _CRS path
In reply to Yinghai LuSo we could get ride of static allocation and hard limits.
We could save some bytes, and can handle system with more than 4 peer root buses.
--- arch/x86/pci/amd_bus.c | 76 +++++++++++++++--------------------------- arch/x86/pci/broadcom_bus.c | 12 ++---- arch/x86/pci/bus_numa.c | 69 ++++++++++++++++++++++++++------------ arch/x86/pci/bus_numa.h | 18 ++++++---- 4 files changed, 88 insertions(+), 87 deletions(-)
arch/x86/pci/amd_bus.c +27 -49
@@ -32,6 +32,18 @@ static struct pci_hostbridge_probe pci_probes[] __initdata = {#define RANGE_NUM 16 +static struct pci_root_info __init *find_pci_root_info (int node,int link) +{ +struct pci_root_info *info; + +/* find the position */ +list_for_each_entry (info, &pci_root_infos, list) +if (info->node == node && info->link == link) +return info; + +return NULL ; +} +/** * early_fill_mp_bus_to_node() * called before pcibios_scan_root and pci_scan_bus
@@ -50,7 +62,6 @@ static int __init early_fill_mp_bus_info(void)int def_link;struct pci_root_info *info;u32 reg; -struct resource *res;u64 start;u64 end;struct range range[RANGE_NUM ];
@@ -86,7 +97,6 @@ static int __init early_fill_mp_bus_info(void)if (!found)return 0 ; - pci_root_num =0 ;for (i =0 ; i <4 ; i++) {int min_bus;int max_bus;
@@ -105,13 +115,8 @@ static int __init early_fill_mp_bus_info(void)#endif link = (reg >>8 ) &0x03 ; - info = &pci_root_info[pci_root_num]; - info->bus_min = min_bus; - info->bus_max = max_bus; - info->node = node; - info->link = link; + info =alloc_pci_root_info (min_bus, max_bus, node, link);sprintf (info->name,"PCI Bus #%02x" , min_bus); - pci_root_num++; }/* get the default node and link for left over res */
@@ -134,16 +139,10 @@ static int __init early_fill_mp_bus_info(void) link = (reg >>4 ) &0x03 ; end = (reg &0xfff000 ) |0xfff ; -/* find the position */ -for (j =0 ; j < pci_root_num; j++) { - info = &pci_root_info[j]; -if (info->node == node && info->link == link) -break ; - } -if (j == pci_root_num) + info =find_pci_root_info (node, link); +if (!info)continue ;/* not found */ - info = &pci_root_info[j];printk (KERN_DEBUG "node %d link %d: io port [%llx, %llx]\n" , node, link, start, end);
@@ -155,13 +154,8 @@ static int __init early_fill_mp_bus_info(void) }/* add left over io port range to def node/link, [0, 0xffff] */ /* find the position */ -for (j =0 ; j < pci_root_num; j++) { - info = &pci_root_info[j]; -if (info->node == def_node && info->link == def_link) -break ; - } -if (j < pci_root_num) { - info = &pci_root_info[j]; + info =find_pci_root_info (def_node, def_link); +if (info) {for (i =0 ; i <RANGE_NUM ; i++) {if (!range[i].end)continue ;
@@ -214,16 +208,10 @@ static int __init early_fill_mp_bus_info(void) end <<=8 ; end |=0xffff ; -/* find the position */ -for (j =0 ; j < pci_root_num; j++) { - info = &pci_root_info[j]; -if (info->node == node && info->link == link) -break ; - } -if (j == pci_root_num) -continue ;/* not found */ + info =find_pci_root_info (node, link); - info = &pci_root_info[j]; +if (!info) +continue ;printk (KERN_DEBUG "node %d link %d: mmio [%llx, %llx]" , node, link, start, end);
@@ -291,14 +279,8 @@ static int __init early_fill_mp_bus_info(void)* add left over mmio range to def node/link ? * that is tricky, just record range in from start_min to 4G */ -for (j =0 ; j < pci_root_num; j++) { - info = &pci_root_info[j]; -if (info->node == def_node && info->link == def_link) -break ; - } -if (j < pci_root_num) { - info = &pci_root_info[j]; - + info =find_pci_root_info (def_node, def_link); +if (info) {for (i =0 ; i <RANGE_NUM ; i++) {if (!range[i].end)continue ;
@@ -309,20 +291,16 @@ static int __init early_fill_mp_bus_info(void) } } -for (i =0 ; i < pci_root_num; i++) { -int res_num; +list_for_each_entry (info, &pci_root_infos, list) {int busnum; +struct pci_root_res *root_res; - info = &pci_root_info[i]; - res_num = info->res_num; busnum = info->bus_min;printk (KERN_DEBUG "bus: [%02x, %02x] on node %x link %x\n" , info->bus_min, info->bus_max, info->node, info->link); -for (j =0 ; j < res_num; j++) { - res = &info->res[j]; -printk (KERN_DEBUG "bus: %02x index %x %pR\n" , - busnum, j, res); - } +list_for_each_entry (root_res, &info->resources, list) +printk (KERN_DEBUG "bus: %02x %pR\n" , + busnum, &root_res->res); }return 0 ;
arch/x86/pci/broadcom_bus.c +4 -8
@@ -22,19 +22,15 @@static void __init cnb20le_res (u8 bus,u8 slot,u8 func) {struct pci_root_info *info; +struct pci_root_res *root_res;struct resource res;u16 word1, word2;u8 fbus, lbus; -int i; - - info = &pci_root_info[pci_root_num]; - pci_root_num++;/* read the PCI bus numbers */ fbus =read_pci_config_byte (bus, slot, func,0x44 ); lbus =read_pci_config_byte (bus, slot, func,0x45 ); - info->bus_min = fbus; - info->bus_max = lbus; + info =alloc_pci_root_info (fbus, lbus,0 ,0 );/* * Add the legacy IDE ports on bus 0
@@ -86,8 +82,8 @@ static void __init cnb20le_res(u8 bus, u8 slot, u8 func) res.flags =IORESOURCE_BUS ;printk (KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n" , &res); -for (i =0 ; i < info->res_num; i++) -printk (KERN_INFO "host bridge window %pR\n" , &info->res[i]); +list_for_each_entry (root_res, &info->resources, list) +printk (KERN_INFO "host bridge window %pR\n" , &root_res->res); }static int __init broadcom_postcore_init (void )
arch/x86/pci/bus_numa.c +47 -22
118 lines not on this page · raw message
arch/x86/pci/bus_numa.h +10 -8
@@ -4,22 +4,24 @@* sub bus (transparent) will use entres from 3 to store extra from * root, so need to make sure we have enough slot there. */ -#define RES_NUM 16 +struct pci_root_res { +struct list_head list; +struct resource res; +}; +struct pci_root_info { +struct list_head list;char name[12 ]; -unsigned int res_num; -struct resource res[RES_NUM ]; +struct list_head resources;int bus_min;int bus_max;int node;int link; }; -/* 4 at this time, it may become to 32 */ -#define PCI_ROOT_NR 4 -extern int pci_root_num; -extern struct pci_root_info pci_root_info[PCI_ROOT_NR ]; - +extern struct list_head pci_root_infos; +struct pci_root_info *alloc_pci_root_info (int bus_min,int bus_max, +int node,int link);extern void update_res (struct pci_root_info *info,resource_size_t start,resource_size_t end,unsigned long flags,int merge);#endif
Signature · 1 line
1.7.7
PATCH 11/11 x86, PCI: Merge root info printing for not using _CRS path
In reply to Yinghai Lu--- arch/x86/pci/amd_bus.c | 12 +----------- arch/x86/pci/broadcom_bus.c | 9 +-------- arch/x86/pci/bus_numa.c | 17 +++++++++++++++++ arch/x86/pci/bus_numa.h | 1 + 4 files changed, 20 insertions(+), 19 deletions(-)
arch/x86/pci/amd_bus.c +1 -11
@@ -291,17 +291,7 @@ static int __init early_fill_mp_bus_info(void) } } -list_for_each_entry (info, &pci_root_infos, list) { -int busnum; -struct pci_root_res *root_res; - - busnum = info->bus_min; -printk (KERN_DEBUG "bus: [%02x, %02x] on node %x link %x\n" , - info->bus_min, info->bus_max, info->node, info->link); -list_for_each_entry (root_res, &info->resources, list) -printk (KERN_DEBUG "bus: %02x %pR\n" , - busnum, &root_res->res); - } +print_pci_root_info (info,"bus:" , true);return 0 ; }
arch/x86/pci/broadcom_bus.c +1 -8
@@ -76,14 +76,7 @@ static void __init cnb20le_res(u8 bus, u8 slot, u8 func)update_res (info, res.start, res.end, res.flags,0 ); } -/* print information about this host bridge */ - res.start = fbus; - res.end = lbus; - res.flags =IORESOURCE_BUS ; -printk (KERN_INFO "CNB20LE PCI Host Bridge (domain 0000 %pR)\n" , &res); - -list_for_each_entry (root_res, &info->resources, list) -printk (KERN_INFO "host bridge window %pR\n" , &root_res->res); +print_pci_root_info (info,"host bridge windows: " , false); }static int __init broadcom_postcore_init (void )
arch/x86/pci/bus_numa.c +17 -0
@@ -77,6 +77,23 @@ struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max,return info; } +void print_pci_root_info (struct pci_root_info *info,char *name,bool nodelink) +{ +struct pci_root_res *root_res; +int busnum = info->bus_min; + +if (!nodelink) +printk (KERN_DEBUG "%s: [%02x, %02x]\n" , name, + info->bus_min, info->bus_max); +else +printk (KERN_DEBUG "%s: [%02x, %02x] on node %x link %x\n" , name, + info->bus_min, info->bus_max, info->node, info->link); + +list_for_each_entry (root_res, &info->resources, list) +printk (KERN_DEBUG "%s: %02x %pR\n" , name, busnum, + &root_res->res); +} +void __devinit update_res (struct pci_root_info *info,resource_size_t start,resource_size_t end,unsigned long flags,int merge) {
arch/x86/pci/bus_numa.h +1 -0
@@ -22,6 +22,7 @@ struct pci_root_info {extern struct list_head pci_root_infos;struct pci_root_info *alloc_pci_root_info (int bus_min,int bus_max,int node,int link); +void print_pci_root_info (struct pci_root_info *info,char *name,bool nodelink);extern void update_res (struct pci_root_info *info,resource_size_t start,resource_size_t end,unsigned long flags,int merge);#endif
Signature · 1 line
1.7.7
Bjorn Helgaas
maintainerQuoted 8 lines · Yinghai Lu
will add struct device dev into
host_bridgestruct.
also will add release support to make sure allocated resource get freed during root bus removal including hostbridge andpci_sysdata.The patches need to apply to linus v3.3 plus pci/linux-next
could get from
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-hostbridge-cleanup
I applied the patches from this branch to my "next" branch, with the exception of the following. Please take a look and make sure my "next" branch has what you expect.
Quoted 1 line
x86, PCI: Merge root info printing for not using
_CRSpath
This changes from printing info for all HT links to just one (probably unintentional). It should also use the "[bus %02x-%02x]" format as we do elsewhere.
Quoted 1 line
x86, PCI: Add print all root info for not using
_CRSpath
This fixes the unintentional "only print one HT link info" change from above.
Quoted 1 line
x86, PCI: Allocate temp range array in
amd_buspci_root_infoprobing
This had no changelog, so I don't know why we want this.
Bjorn
Quoted 5 lines · Bjorn Helgaas
Quoted 4 lines · Yinghai Lu
will add struct device dev into
host_bridgestruct.
also will add release support to make sure allocated resource get freed during root bus removal including hostbridge andpci_sysdata.
Quoted 8 lines
Quoted 4 lines
The patches need to apply to linus v3.3 plus pci/linux-next
could get from
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-hostbridge-cleanupI applied the patches from this branch to my "next" branch, with the exception of the following. Please take a look and make sure my "next" branch has what you expect.
Yes, these 11 patches are correct in your -next tree.
Thanks for updating subject and changelog.
Quoted 7 lines
Quoted 2 lines
x86, PCI: Merge root info printing for not using
_CRSpathThis changes from printing info for all HT links to just one (probably unintentional). It should also use the "[bus %02x-%02x]" format as we do elsewhere.
Quoted 7 lines
Quoted 1 line
x86, PCI: Add print all root info for not using
_CRSpathThis fixes the unintentional "only print one HT link info" change from above.
Quoted 1 line
x86, PCI: Allocate temp range array in
amd_buspci_root_infoprobingThis had no changelog, so I don't know why we want this.
let drop those three patches now. only for printing out etc.
Thanks
Yinghai