Add hostbridge resource release to support root bus hotplug in IA64
cover Add hostbridge resource release to support root bus hotplug in IA64
Hi Bjron,
This patchset mainly to add hostbridge resource release to support root bus hotplug
in IA64. Just based your suggestion, link:http://marc.info/?l=linux-pci&m=134506155529536&w=2 I'm very sorry to send the new version patchset late. Currently, hotplug root bus code has been in kernel, But in IA64, lack the hostbridge resource code. So we cannot hot add root bus because resource confict report.
This patchset based your pci-next branch code.
Jiang Liu (1):
PCI/IA64: fix memleak for create pci root bus fail
Yijing Wang (6):
PCI/X86: fix always use info->res[0] to store _CRS resource when
pci=nocrs set
PCI/IA64: SN: remove sn_pci_window_fixup()
PCI/IA64: make pci_root_info holds pci hostbridge resources PCI/IA64: Allocate pci_root_info instead of using stack PCI/IA64: add host bridge resource release for _CRS path PCI/IA64: introduce probe_pci_root_info() to manage _CRS resource
arch/ia64/include/asm/pci.h | 20 +++- arch/ia64/pci/pci.c | 221 +++++++++++++++++++++++++++-------------- arch/ia64/sn/kernel/io_init.c | 106 +++++++------------- arch/x86/pci/acpi.c | 7 +- 4 files changed, 199 insertions(+), 155 deletions(-)
PATCH 1/7 PCI/X86: fix always use info->res[0] to store _CRS resource when pci=nocrs set
We should increase info->res_num before checking pci_use_crs return, otherwise only the res[0] of pci_root_info will be used during setup_resource() when pci=nocrs set. And the old resource value will be overwritten by new resource item.
--- arch/x86/pci/acpi.c | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
arch/x86/pci/acpi.c +2 -5
@@ -324,14 +324,11 @@ setup_resource(struct acpi_resource *acpi_res, void *data) res->start = start; res->end = end; info->res_offset[info->res_num] = addr.translation_offset; + info->res_num++; -if (!pci_use_crs) { +if (!pci_use_crs)dev_printk (KERN_DEBUG , &info->bridge->dev,"host bridge window %pR (ignored)\n" , res); -return AE_OK ; - } - - info->res_num++;return AE_OK ; }
Signature · 1 line
1.7.1
PATCH 2/7 PCI/IA64: SN: remove sn_pci_window_fixup()
In reply to Yijing WangCurrently, pcibios_bus_to_resource() and pcibios_resource_to_bus() functions use pci_host_bridge_window in pci_host_bridge to translate bus side to/from cpu side addresses. Pci_window in pci_controller under IA64 is no used again, so remove this function.
--- arch/ia64/sn/kernel/io_init.c | 49 +---------------------------------------- 1 files changed, 1 insertions(+), 48 deletions(-)
arch/ia64/sn/kernel/io_init.c +1 -48
@@ -149,48 +149,6 @@ sn_legacy_pci_window_fixup(struct pci_controller *controller, }/* -* sn_pci_window_fixup() - Create a pci_window for each device resource. -* It will setup pci_windows for use by -* pcibios_bus_to_resource(), pcibios_resource_to_bus(), -* etc. -*/ -static void -sn_pci_window_fixup (struct pci_dev *dev,unsigned int count, -s64 * pci_addrs) -{ -struct pci_controller *controller =PCI_CONTROLLER (dev->bus); -unsigned int i; -unsigned int idx; -unsigned int new_count; -struct pci_window *new_window; - -if (count =0 ) -return ; - idx = controller->windows; - new_count = controller->windows + count; - new_window =kcalloc (new_count,sizeof (struct pci_window ),GFP_KERNEL ); -BUG_ON (new_window =NULL ); -if (controller->window) { -memcpy (new_window, controller->window, -sizeof (struct pci_window ) * controller->windows); -kfree (controller->window); - } - -/* Setup a pci_window for each device resource. */ -for (i =0 ; i <=PCI_ROM_RESOURCE ; i++) { -if (pci_addrs[i] =-1 ) -continue ; - - new_window[idx].offset = dev->resource[i].start - pci_addrs[i]; - new_window[idx].resource = dev->resource[i]; - idx++; - } - - controller->windows = new_count; - controller->window = new_window; -} - -/* * sn_io_slot_fixup() - We are not running with an ACPI capable PROM, * and need to convert the pci_dev->resource * 'start' and 'end' addresses to mapped addresses,
@@ -276,12 +234,7 @@ sn_io_slot_fixup(struct pci_dev *dev)IORESOURCE_ROM_BIOS_COPY ; } } -/* Create a pci_window in the pci_controller struct for -* each device resource. -*/ -if (count >0 ) -sn_pci_window_fixup (dev, count, pci_addrs); - +sn_pci_fixup_slot (dev, pcidev_info, sn_irq_info); }
Signature · 1 line
1.7.1
PATCH 3/7 PCI/IA64: make pci_root_info holds pci hostbridge resources
In reply to Yijing WangCurrently, pcibios_resource_to_bus() and pcibios_bus_to_resource() functions use pci_host_bridge to translate bus side address from/to cpu side address. The pci_window in pci_controller never be used again. So we remove pci_window in pci_controller and make pci_root_info hold the pci hostbridge resources like in x86.
--- arch/ia64/include/asm/pci.h | 18 ++++++----- arch/ia64/pci/pci.c | 68 ++++++++++++++++++++-------------------- arch/ia64/sn/kernel/io_init.c | 67 ++++++++++++++++++++++++--------------- 3 files changed, 85 insertions(+), 68 deletions(-)
arch/ia64/include/asm/pci.h +10 -8
@@ -89,23 +89,25 @@ extern int pci_mmap_legacy_page_range(struct pci_bus *bus,#define pci_legacy_read platform_pci_legacy_read#define pci_legacy_write platform_pci_legacy_write -struct pci_window { -struct resource resource; -u64 offset; -}; -struct pci_controller {void *acpi_handle;void *iommu;int segment;int node;/* nearest node with memory or -1 for global allocation */ -unsigned int windows; -struct pci_window *window; -void *platform_data; }; +struct pci_root_info { +struct acpi_device *bridge; +struct pci_controller *controller; +struct list_head resources; +struct resource *res; +resource_size_t *res_offset; +unsigned int res_num; +char *name; +}; +#define PCI_CONTROLLER (busdev) ((struct pci_controller *) busdev->sysdata)#define pci_domain_nr (busdev) (PCI_CONTROLLER(busdev)->segment)
arch/ia64/pci/pci.c +32 -33
125 lines not on this page · raw message
arch/ia64/sn/kernel/io_init.c +39 -24
98 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 4/7 PCI/IA64: Allocate pci_root_info instead of using stack
In reply to Yijing WangWe need to pass around info for release function.
--- arch/ia64/pci/pci.c | 59 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 35 insertions(+), 24 deletions(-)
arch/ia64/pci/pci.c +33 -23
@@ -322,7 +322,8 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)int domain = root->segment;int bus = root->secondary.start;struct pci_controller *controller; -struct pci_root_info info; +struct pci_root_info *info =NULL ; +int busnum = root->secondary.start;struct pci_bus *pbus;char *name;int pxm;
@@ -339,35 +340,42 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) controller->node =pxm_to_node (pxm);#endif -INIT_LIST_HEAD (&info.resources); + info =kzalloc (sizeof (*info),GFP_KERNEL ); +if (!info) { +printk (KERN_WARNING "pci_bus %04x:%02x: " +"ignored (out of memory)\n" , root->segment, busnum); + goto out2; + } + +INIT_LIST_HEAD (&info->resources);/* insert busn resource at first */ -pci_add_resource (&info.resources, &root->secondary); +pci_add_resource (&info->resources, &root->secondary);acpi_walk_resources (device->handle,METHOD_NAME__CRS , count_window, - &info.res_num); -if (info.res_num) { - info.res -kzalloc_node (sizeof (*info.res) * info.res_num, + &info->res_num); +if (info->res_num) { + info->res +kzalloc_node (sizeof (*info->res) * info->res_num,GFP_KERNEL , controller->node); -if (!info.res) - goto out2; - - info.res_offset = -kzalloc_node (sizeof (*info.res_offset) * info.res_num, -GFP_KERNEL , controller->node); -if (!info.res_offset) +if (!info->res) goto out3; + + info->res_offset +kzalloc_node (sizeof (*info->res_offset) * info->res_num, +GFP_KERNEL , controller->node); +if (!info->res_offset) + goto out4; name =kmalloc (16 ,GFP_KERNEL );if (!name) - goto out4; + goto out5;sprintf (name,"PCI Bus %04x:%02x" , domain, bus); - info.bridge = device; - info.controller = controller; - info.name = name; - info.res_num =0 ; + info->bridge = device; + info->controller = controller; + info->name = name; + info->res_num =0 ;acpi_walk_resources (device->handle,METHOD_NAME__CRS , - add_window, &info); + add_window, info); }/* * See arch/x86/pci/acpi.c.
@@ -376,18 +384,21 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)* such quirk. So we just ignore the case now. */ pbus =pci_create_root_bus (NULL , bus, &pci_root_ops, controller, - &info.resources); + &info->resources);if (!pbus) { -pci_free_resource_list (&info.resources); +pci_free_resource_list (&info->resources);return NULL ; }pci_scan_child_bus (pbus);return pbus; + +out5: +kfree (info->res_offset); out4: -kfree (info.res_offset); +kfree (info->res); out3: -kfree (info.res); +kfree (info); out2:kfree (controller); out1:
Signature · 1 line
1.7.1
PATCH 5/7 PCI/IA64: fix memleak for create pci root bus fail
In reply to Yijing WangFrom: Jiang Liu <[email protected]>
If pci_create_root_bus() return fail, we should release pci root info, pci controller etc.
--- arch/ia64/include/asm/pci.h | 6 +++ arch/ia64/pci/pci.c | 74 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 15 deletions(-)
arch/ia64/include/asm/pci.h +6 -0
@@ -89,6 +89,11 @@ extern int pci_mmap_legacy_page_range(struct pci_bus *bus,#define pci_legacy_read platform_pci_legacy_read#define pci_legacy_write platform_pci_legacy_write +struct iospace_resource { +struct list_head list; +struct resource res; +}; +struct pci_controller {void *acpi_handle;void *iommu;
@@ -105,6 +110,7 @@ struct pci_root_info {struct resource *res;resource_size_t *res_offset;unsigned int res_num; +struct list_head io_resources;char *name; };
arch/ia64/pci/pci.c +59 -15
128 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 6/7 PCI/IA64: add host bridge resource release for _CRS path
In reply to Yijing WangSet IA64 host bridge release function to make sure root bridge related resources get freed during root bus removal.
--- arch/ia64/pci/pci.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-)
arch/ia64/pci/pci.c +10 -1
@@ -358,6 +358,13 @@ static void __release_pci_root_info(struct pci_root_info *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); +} +struct pci_bus *pci_acpi_scan_root (struct acpi_pci_root *root) {struct acpi_device *device = root->device;
@@ -433,7 +440,9 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)__release_pci_root_info (info);return NULL ; } - + +pci_set_host_bridge_release (to_pci_host_bridge (pbus->bridge), + release_pci_root_info, info);pci_scan_child_bus (pbus);return pbus;
Signature · 1 line
1.7.1
PATCH 7/7 PCI/IA64: introduce probe_pci_root_info() to manage _CRS resource
In reply to Yijing WangCurrently, initialize _CRS resource code in IA64 make pci_acpi_scan_root() some lengthiness. Introduce probe_pci_root_info() to manage it like in X86,
--- arch/ia64/pci/pci.c | 91 +++++++++++++++++++++++++++----------------------- 1 files changed, 49 insertions(+), 42 deletions(-)
arch/ia64/pci/pci.c +49 -42
@@ -365,6 +365,48 @@ static void release_pci_root_info(struct pci_host_bridge *bridge)__release_pci_root_info (info); } +static void +probe_pci_root_info (struct pci_root_info *info,struct acpi_device *device, +int busnum,int domain) +{ +char *name; + + name =kmalloc (16 ,GFP_KERNEL ); +if (!name) +return ; + +sprintf (name,"PCI Bus %04x:%02x" , domain, busnum); + info->bridge = device; + info->name = name; + +acpi_walk_resources (device->handle,METHOD_NAME__CRS , count_window, + &info->res_num); +if (info->res_num) { + info->res = +kzalloc_node (sizeof (*info->res) * info->res_num, +GFP_KERNEL , info->controller->node); +if (!info->res) { +kfree (name); +return ; + } + + info->res_offset = +kzalloc_node (sizeof (*info->res_offset) * info->res_num, +GFP_KERNEL , info->controller->node); +if (!info->res_offset) { +kfree (name); +kfree (info->res); + info->res =NULL ; +return ; + } + + info->res_num =0 ; +acpi_walk_resources (device->handle,METHOD_NAME__CRS , + add_window, info); + }else +kfree (name); +} +struct pci_bus *pci_acpi_scan_root (struct acpi_pci_root *root) {struct acpi_device *device = root->device;
@@ -374,12 +416,11 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)struct pci_root_info *info =NULL ;int busnum = root->secondary.start;struct pci_bus *pbus; -char *name;int pxm; controller =alloc_pci_controller (domain);if (!controller) - goto out1; +return NULL ; controller->acpi_handle = device->handle;
@@ -392,41 +433,18 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) info =kzalloc (sizeof (*info),GFP_KERNEL );if (!info) {printk (KERN_WARNING "pci_bus %04x:%02x: " -"ignored (out of memory)\n" , root->segment, busnum); - goto out2; +"ignored (out of memory)\n" , domain, busnum); +kfree (controller); +return NULL ; } + info->controller = controller;INIT_LIST_HEAD (&info->io_resources);INIT_LIST_HEAD (&info->resources); +probe_pci_root_info (info, device, busnum, domain); +/* insert busn resource at first */ pci_add_resource (&info->resources, &root->secondary); -acpi_walk_resources (device->handle,METHOD_NAME__CRS , count_window, - &info->res_num); -if (info->res_num) { - info->res = -kzalloc_node (sizeof (*info->res) * info->res_num, -GFP_KERNEL , controller->node); -if (!info->res) - goto out3; - - info->res_offset = -kzalloc_node (sizeof (*info->res_offset) * info->res_num, -GFP_KERNEL , controller->node); -if (!info->res_offset) - goto out4; - - name =kmalloc (16 ,GFP_KERNEL ); -if (!name) - goto out5; - -sprintf (name,"PCI Bus %04x:%02x" , domain, bus); - info->bridge = device; - info->controller = controller; - info->name = name; - info->res_num =0 ; -acpi_walk_resources (device->handle,METHOD_NAME__CRS , - add_window, info); - }/* * See arch/x86/pci/acpi.c. * The desired pci bus might already be scanned in a quirk. We
@@ -445,17 +463,6 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) release_pci_root_info, info);pci_scan_child_bus (pbus);return pbus; - -out5: -kfree (info->res_offset); -out4: -kfree (info->res); -out3: -kfree (info); -out2: -kfree (controller); -out1: -return NULL ; }int pcibios_root_bridge_prepare (struct pci_host_bridge *bridge)
Signature · 1 line
1.7.1