linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/21] PCI : bridge resource reallocation patchset
@ 2012-01-21 10:08 Yinghai Lu
  2012-01-21 10:08 ` [PATCH 01/21] PCI : Calculate right add_size Yinghai Lu
                   ` (20 more replies)
  0 siblings, 21 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

a181193: PCI: only enable pci realloc when SRIOV bar is not assigned
6662c73: PCI: Make pci bridge reallocating enabled/disabled
1a60212: PCI: Retry on type IORESOURCE_IO allocation.
59e4fd4: PCI: Fix cardbus bridge resources as optional size handling
daa08ff: PCI: Disable cardbus bridge MEM1 pref CTL
e11dc0e: PCI: remove add_to_failed_list()
11af29c: PCI: add debug print out for add_size
6a30c7b: PCI: Change free_list() to function
e5aa050: PCI: Rename dev_res_x to add_res or fail_res
ff503cf: PCI: Merge pci_dev_resource_x and pci_dev_resource
2874630: PCI: Replace resource_list with generic list
8eedd1e: PCI: Move struct resource_list to setup-bus.c
23a6d3e: PCI: Move pdev_sort_resources() to setup-bus.c
93acbd6: PCI: Fixing multiple retrying with pci resource optional resources allocation under multi bridges
7f5dac3: PCI: Make pci_rescan_bus handle add_list
18dd9be: PCI: Make rescan bus could increase bridge resource size if needed
52e0afc: PCI: Using add_list in pcie hotplug path.
2b6542d: PCI: Try to assign required+option size at first
4beb962: PCI: Move get_res_add_size() early
8cb9020: PCI: Make add_to_list() return status
8535f21: PCI : Calculate right add_size

those patches will fix optional resource size pass over parent bus problem.

and try allocate request + optional resource at first, and then if failed will
fall back to get requested at first then try to expand to optional one.

at last will try auto detect if we need to realloc bridge resource.

Also replace local resource_list and resource_list_x with generic list.

or get from

	git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci2

Thanks

Yinghai

 Documentation/kernel-parameters.txt |    7 +-
 drivers/pci/pci-sysfs.c             |    5 +-
 drivers/pci/pci.c                   |    4 +-
 drivers/pci/pci.h                   |    2 +-
 drivers/pci/probe.c                 |   22 +-
 drivers/pci/setup-bus.c             |  629 ++++++++++++++++++++++++-----------
 drivers/pci/setup-res.c             |   52 +---
 include/linux/ioport.h              |    6 -
 include/linux/pci.h                 |    2 +-
 9 files changed, 451 insertions(+), 278 deletions(-)





^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 01/21] PCI : Calculate right add_size
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-27 17:55   ` Jesse Barnes
  2012-01-21 10:08 ` [PATCH 02/21] PCI: Make add_to_list() return status Yinghai Lu
                   ` (19 subsequent siblings)
  20 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

During debug one SRIOV enabled hotplug, found add_size is not passed properly.

the device have devices under two level bridges..

 +-[0000:80]-+-00.0-[81-8f]--
 |           +-01.0-[90-9f]--
 |           +-02.0-[a0-af]----00.0-[a1-a3]--+-02.0-[a2]--+-00.0  Oracle Corporation Device
 |           |                               \-03.0-[a3]--+-00.0  Oracle Corporation Device

so later parent bridge will not try to add big range.
[  557.455077] pci 0000:a0:00.0: BAR 14: assigned [mem 0xf9000000-0xf93fffff]
[  557.461974] pci 0000:a0:00.0: BAR 15: assigned [mem 0xf6000000-0xf61fffff pref]
[  557.469340] pci 0000:a1:02.0: BAR 14: assigned [mem 0xf9000000-0xf91fffff]
[  557.476231] pci 0000:a1:02.0: BAR 15: assigned [mem 0xf6000000-0xf60fffff pref]
[  557.483582] pci 0000:a1:03.0: BAR 14: assigned [mem 0xf9200000-0xf93fffff]
[  557.490468] pci 0000:a1:03.0: BAR 15: assigned [mem 0xf6100000-0xf61fffff pref]
[  557.497833] pci 0000:a1:03.0: BAR 14: can't assign mem (size 0x200000)
[  557.504378] pci 0000:a1:03.0: failed to add optional resources res=[mem 0xf9200000-0xf93fffff]
[  557.513026] pci 0000:a1:02.0: BAR 14: can't assign mem (size 0x200000)
[  557.519578] pci 0000:a1:02.0: failed to add optional resources res=[mem 0xf9000000-0xf91fffff]

it turns out We did not calculate size1 properly.

static resource_size_t calculate_memsize(resource_size_t size,
                resource_size_t min_size,
                resource_size_t size1,
                resource_size_t old_size,
                resource_size_t align)
{
        if (size < min_size)
                size = min_size;
        if (old_size == 1 )
                old_size = 0;
        if (size < old_size)
                size = old_size;
        size = ALIGN(size + size1, align);
        return size;
}

We should not pass add_size with min_size in calculate_memsize.
that will make add_size not contribute final add_size.

Just pass add_size with size1 to calculate_memsize()

With this change, We should have chance to remove extra addon in pci_reassign_resource...

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |    4 ++--
 drivers/pci/setup-res.c |    5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 86b69f85..9d932f4 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -612,7 +612,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
 	if (children_add_size > add_size)
 		add_size = children_add_size;
 	size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
-		calculate_iosize(size, min_size+add_size, size1,
+		calculate_iosize(size, min_size, add_size + size1,
 			resource_size(b_res), 4096);
 	if (!size0 && !size1) {
 		if (b_res->start || b_res->end)
@@ -726,7 +726,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
 	if (children_add_size > add_size)
 		add_size = children_add_size;
 	size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 :
-		calculate_memsize(size, min_size+add_size, 0,
+		calculate_memsize(size, min_size, add_size,
 				resource_size(b_res), min_align);
 	if (!size0 && !size1) {
 		if (b_res->start || b_res->end)
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 5717509b..8b25f9c 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -233,11 +233,12 @@ int pci_reassign_resource(struct pci_dev *dev, int resno, resource_size_t addsiz
 		return -EINVAL;
 	}
 
-	new_size = resource_size(res) + addsize + min_align;
+	/* already aligned with min_align */
+	new_size = resource_size(res) + addsize;
 	ret = _pci_assign_resource(dev, resno, new_size, min_align);
 	if (!ret) {
 		res->flags &= ~IORESOURCE_STARTALIGN;
-		dev_info(&dev->dev, "BAR %d: assigned %pR\n", resno, res);
+		dev_info(&dev->dev, "BAR %d: reassigned %pR\n", resno, res);
 		if (resno < PCI_BRIDGE_RESOURCES)
 			pci_update_resource(dev, resno);
 	}
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 02/21] PCI: Make add_to_list() return status
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
  2012-01-21 10:08 ` [PATCH 01/21] PCI : Calculate right add_size Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 03/21] PCI: Move get_res_add_size() early Yinghai Lu
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

will be used for resource_list_x duplication for try requested+optional at first.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 9d932f4..0282fde 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -64,7 +64,7 @@ void pci_realloc(void)
  * @add_size:	additional size to be optionally added
  *              to the resource
  */
-static void add_to_list(struct resource_list_x *head,
+static int add_to_list(struct resource_list_x *head,
 		 struct pci_dev *dev, struct resource *res,
 		 resource_size_t add_size, resource_size_t min_align)
 {
@@ -75,7 +75,7 @@ static void add_to_list(struct resource_list_x *head,
 	tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
 	if (!tmp) {
 		pr_warning("add_to_list: kmalloc() failed!\n");
-		return;
+		return -ENOMEM;
 	}
 
 	tmp->next = ln;
@@ -87,6 +87,8 @@ static void add_to_list(struct resource_list_x *head,
 	tmp->add_size = add_size;
 	tmp->min_align = min_align;
 	list->next = tmp;
+
+	return 0;
 }
 
 static void add_to_failed_list(struct resource_list_x *head,
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 03/21] PCI: Move get_res_add_size() early
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
  2012-01-21 10:08 ` [PATCH 01/21] PCI : Calculate right add_size Yinghai Lu
  2012-01-21 10:08 ` [PATCH 02/21] PCI: Make add_to_list() return status Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 04/21] PCI: Try to assign required+option size at first Yinghai Lu
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

Need to call it from __assign_resources_sorted() later.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 0282fde..75d43eb 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -99,6 +99,21 @@ static void add_to_failed_list(struct resource_list_x *head,
 			0 /* dont care */);
 }
 
+static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
+					struct resource *res)
+{
+	struct resource_list_x *list;
+
+	/* check if it is in realloc_head list */
+	for (list = realloc_head->next; list && list->res != res;
+			list = list->next)
+		;
+	if (list)
+		return list->add_size;
+
+	return 0;
+}
+
 static void __dev_sort_resources(struct pci_dev *dev,
 				 struct resource_list *head)
 {
@@ -550,20 +565,6 @@ static resource_size_t calculate_memsize(resource_size_t size,
 	return size;
 }
 
-static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
-					struct resource *res)
-{
-	struct resource_list_x *list;
-
-	/* check if it is in realloc_head list */
-	for (list = realloc_head->next; list && list->res != res;
-			list = list->next);
-	if (list)
-		return list->add_size;
-
-	return 0;
-}
-
 /**
  * pbus_size_io() - size the io window of a given bus
  *
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 04/21] PCI: Try to assign required+option size at first
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (2 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 03/21] PCI: Move get_res_add_size() early Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 05/21] PCI: Using add_list in pcie hotplug path Yinghai Lu
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

Found reassign can not find right range for one resource. even total range is enough.

bridge b1:02.0 will need 2M+3M
bridge b1:03.0 will need 2M+3M

so bridge b0:00.0 will get assigned: 4M : [f8000000-f83fffff]
   later is reassigned to 10M : [f8000000-f9ffffff]

b1:02.0 is assigned to 2M : [f8000000-f81fffff]
b1:03.0 is assigned to 2M : [f8200000-f83fffff]

after that b1:03.0 get chance to be reassigned to [f8200000-f86fffff]
but b1:02.0 will not have chance to expand, because b1:03.0 is using in middle one.

[  187.911401] pci 0000:b1:02.0: bridge window [mem 0x00100000-0x002fffff] to [bus b2-b2] add_size 300000
[  187.920764] pci 0000:b1:03.0: bridge window [mem 0x00100000-0x002fffff] to [bus b3-b3] add_size 300000
[  187.930129] pci 0000:b1:02.0: [mem 0x00100000-0x002fffff] get_res_add_size  add_size 300000
[  187.938500] pci 0000:b1:03.0: [mem 0x00100000-0x002fffff] get_res_add_size  add_size 300000
[  187.946857] pci 0000:b0:00.0: bridge window [mem 0x00100000-0x004fffff] to [bus b1-b3] add_size 600000
[  187.956206] pci 0000:b0:00.0: BAR 14: assigned [mem 0xf8000000-0xf83fffff]
[  187.963102] pci 0000:b0:00.0: BAR 15: assigned [mem 0xf5000000-0xf51fffff pref]
[  187.970434] pci 0000:b0:00.0: BAR 14: reassigned [mem 0xf8000000-0xf89fffff]
[  187.977497] pci 0000:b1:02.0: BAR 14: assigned [mem 0xf8000000-0xf81fffff]
[  187.984383] pci 0000:b1:02.0: BAR 15: assigned [mem 0xf5000000-0xf50fffff pref]
[  187.991695] pci 0000:b1:03.0: BAR 14: assigned [mem 0xf8200000-0xf83fffff]
[  187.998576] pci 0000:b1:03.0: BAR 15: assigned [mem 0xf5100000-0xf51fffff pref]
[  188.005888] pci 0000:b1:03.0: BAR 14: reassigned [mem 0xf8200000-0xf86fffff]
[  188.012939] pci 0000:b1:02.0: BAR 14: can't assign mem (size 0x200000)
[  188.019471] pci 0000:b1:02.0: failed to add 300000 to res=[mem 0xf8000000-0xf81fffff]
[  188.027326] pci 0000:b2:00.0: reg 184: [mem 0x00000000-0x00003fff 64bit]
[  188.034071] pci 0000:b2:00.0: reg 18c: [mem 0x00000000-0x000fffff 64bit]
[  188.040795] pci 0000:b2:00.0: BAR 2: assigned [mem 0xf8000000-0xf80fffff 64bit]
[  188.048119] pci 0000:b2:00.0: BAR 2: set to [mem 0xf8000000-0xf80fffff 64bit] (PCI address [0xf8000000-0xf80fffff])
[  188.058550] pci 0000:b2:00.0: BAR 6: assigned [mem 0xf5000000-0xf50fffff pref]
[  188.065802] pci 0000:b2:00.0: BAR 0: assigned [mem 0xf8100000-0xf8103fff 64bit]
[  188.073125] pci 0000:b2:00.0: BAR 0: set to [mem 0xf8100000-0xf8103fff 64bit] (PCI address [0xf8100000-0xf8103fff])
[  188.083596] pci 0000:b2:00.0: reg 18c: [mem 0x00000000-0x000fffff 64bit]
[  188.090310] pci 0000:b2:00.0: BAR 9: can't assign mem (size 0x300000)
[  188.096773] pci 0000:b2:00.0: reg 184: [mem 0x00000000-0x00003fff 64bit]
[  188.103479] pci 0000:b2:00.0: BAR 7: assigned [mem 0xf8104000-0xf810ffff 64bit]
[  188.110801] pci 0000:b2:00.0: BAR 7: set to [mem 0xf8104000-0xf810ffff 64bit] (PCI address [0xf8104000-0xf810ffff])
[  188.121256] pci 0000:b1:02.0: PCI bridge to [bus b2-b2]
[  188.126512] pci 0000:b1:02.0:   bridge window [mem 0xf8000000-0xf81fffff]
[  188.133328] pci 0000:b1:02.0:   bridge window [mem 0xf5000000-0xf50fffff pref]
[  188.140608] pci 0000:b3:00.0: reg 184: [mem 0x00000000-0x00003fff 64bit]
[  188.147341] pci 0000:b3:00.0: reg 18c: [mem 0x00000000-0x000fffff 64bit]
[  188.154076] pci 0000:b3:00.0: BAR 2: assigned [mem 0xf8200000-0xf82fffff 64bit]
[  188.161417] pci 0000:b3:00.0: BAR 2: set to [mem 0xf8200000-0xf82fffff 64bit] (PCI address [0xf8200000-0xf82fffff])
[  188.171865] pci 0000:b3:00.0: BAR 6: assigned [mem 0xf5100000-0xf51fffff pref]
[  188.179090] pci 0000:b3:00.0: BAR 0: assigned [mem 0xf8300000-0xf8303fff 64bit]
[  188.186431] pci 0000:b3:00.0: BAR 0: set to [mem 0xf8300000-0xf8303fff 64bit] (PCI address [0xf8300000-0xf8303fff])
[  188.196884] pci 0000:b3:00.0: reg 18c: [mem 0x00000000-0x000fffff 64bit]
[  188.203591] pci 0000:b3:00.0: BAR 9: assigned [mem 0xf8400000-0xf86fffff 64bit]
[  188.210909] pci 0000:b3:00.0: BAR 9: set to [mem 0xf8400000-0xf86fffff 64bit] (PCI address [0xf8400000-0xf86fffff])
[  188.221379] pci 0000:b3:00.0: reg 184: [mem 0x00000000-0x00003fff 64bit]
[  188.228089] pci 0000:b3:00.0: BAR 7: assigned [mem 0xf8304000-0xf830ffff 64bit]
[  188.235407] pci 0000:b3:00.0: BAR 7: set to [mem 0xf8304000-0xf830ffff 64bit] (PCI address [0xf8304000-0xf830ffff])
[  188.245843] pci 0000:b1:03.0: PCI bridge to [bus b3-b3]
[  188.251107] pci 0000:b1:03.0:   bridge window [mem 0xf8200000-0xf86fffff]
[  188.257922] pci 0000:b1:03.0:   bridge window [mem 0xf5100000-0xf51fffff pref]
[  188.265180] pci 0000:b0:00.0: PCI bridge to [bus b1-b3]
[  188.270443] pci 0000:b0:00.0:   bridge window [mem 0xf8000000-0xf89fffff]
[  188.277250] pci 0000:b0:00.0:   bridge window [mem 0xf5000000-0xf51fffff pref]
[  188.284512] pcieport 0000:80:02.2: PCI bridge to [bus b0-bf]
[  188.290184] pcieport 0000:80:02.2:   bridge window [io  0xa000-0xbfff]
[  188.296735] pcieport 0000:80:02.2:   bridge window [mem 0xf8000000-0xf8ffffff]
[  188.303963] pcieport 0000:80:02.2:   bridge window [mem 0xf5000000-0xf5ffffff 64bit pref]

b2:00.0 BAR 9 has not get assigned...

root cause:
b1:02.0 can not be added more range, because b1:03.0 is just after it.
not space between required ranges.

Solution:
Try to assign required + optional all together at first, and if it fails, go with required then reassign path.

-v2: seperate add_to_list change() to another patch according to Jesse.
     seperate get_res_add_size() moving to another patch according to Jesse.
     add !realloc_head->next check if the list is empty to bail early according to Jesse.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 82 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 75d43eb..7757c00 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -99,6 +99,24 @@ static void add_to_failed_list(struct resource_list_x *head,
 			0 /* dont care */);
 }
 
+static void remove_from_list(struct resource_list_x *realloc_head,
+				 struct resource *res)
+{
+	struct resource_list_x *prev, *tmp, *list;
+
+	prev = realloc_head;
+	for (list = realloc_head->next; list;) {
+		if (list->res != res) {
+			prev = list;
+			list = list->next;
+			continue;
+		}
+		tmp = list;
+		prev->next = list = list->next;
+		kfree(tmp);
+	}
+}
+
 static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
 					struct resource *res)
 {
@@ -108,8 +126,13 @@ static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
 	for (list = realloc_head->next; list && list->res != res;
 			list = list->next)
 		;
-	if (list)
+
+	if (list) {
+		dev_printk(KERN_DEBUG, &list->dev->dev,
+			 "%pR get_res_add_size  add_size %llx\n",
+			 list->res, (unsigned long long)list->add_size);
 		return list->add_size;
+	}
 
 	return 0;
 }
@@ -238,6 +261,64 @@ static void __assign_resources_sorted(struct resource_list *head,
 				 struct resource_list_x *realloc_head,
 				 struct resource_list_x *fail_head)
 {
+	/*
+	 * Should not assign requested resources at first.
+	 *   they could be adjacent, so later reassign can not reallocate
+	 *   them one by one in parent resource window.
+	 * Try to assign requested + add_size at begining
+	 *  if could do that, could get out early.
+	 *  if could not do that, we still try to assign requested at first,
+	 *    then try to reassign add_size for some resources.
+	 */
+	struct resource_list_x save_head, local_fail_head, *list;
+	struct resource_list *l;
+
+	/* Check if optional add_size is there */
+	if (!realloc_head || !realloc_head->next)
+		goto requested_and_reassign;
+
+	/* Save original start, end, flags etc at first */
+	save_head.next = NULL;
+	for (l = head->next; l; l = l->next)
+		if (add_to_list(&save_head, l->dev, l->res, 0, 0)) {
+			free_list(resource_list_x, &save_head);
+			goto requested_and_reassign;
+		}
+
+	/* Update res in head list with add_size in realloc_head list */
+	for (l = head->next; l; l = l->next)
+		l->res->end += get_res_add_size(realloc_head, l->res);
+
+	/* Try updated head list with add_size added */
+	local_fail_head.next = NULL;
+	assign_requested_resources_sorted(head, &local_fail_head);
+
+	/* all assigned with add_size ? */
+	if (!local_fail_head.next) {
+		/* Remove head list from realloc_head list */
+		for (l = head->next; l; l = l->next)
+			remove_from_list(realloc_head, l->res);
+		free_list(resource_list_x, &save_head);
+		free_list(resource_list, head);
+		return;
+	}
+
+	free_list(resource_list_x, &local_fail_head);
+	/* Release assigned resource */
+	for (l = head->next; l; l = l->next)
+		if (l->res->parent)
+			release_resource(l->res);
+	/* Restore start/end/flags from saved list */
+	for (list = save_head.next; list; list = list->next) {
+		struct resource *res = list->res;
+
+		res->start = list->start;
+		res->end = list->end;
+		res->flags = list->flags;
+	}
+	free_list(resource_list_x, &save_head);
+
+requested_and_reassign:
 	/* Satisfy the must-have resource requests */
 	assign_requested_resources_sorted(head, fail_head);
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 05/21] PCI: Using add_list in pcie hotplug path.
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (3 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 04/21] PCI: Try to assign required+option size at first Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 06/21] PCI: Make rescan bus could increase bridge resource size if needed Yinghai Lu
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

We need add size for hot plug path when pluging in hotplug chassis without cards.
-v2: change descriptions. make it can be applied after
	pci: Check bridge resources after resource allocation.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 7757c00..97c1eda 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -330,13 +330,14 @@ requested_and_reassign:
 }
 
 static void pdev_assign_resources_sorted(struct pci_dev *dev,
+				 struct resource_list_x *add_head,
 				 struct resource_list_x *fail_head)
 {
 	struct resource_list head;
 
 	head.next = NULL;
 	__dev_sort_resources(dev, &head);
-	__assign_resources_sorted(&head, NULL, fail_head);
+	__assign_resources_sorted(&head, add_head, fail_head);
 
 }
 
@@ -1006,17 +1007,19 @@ void __ref pci_bus_assign_resources(const struct pci_bus *bus)
 EXPORT_SYMBOL(pci_bus_assign_resources);
 
 static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge,
+					 struct resource_list_x *add_head,
 					 struct resource_list_x *fail_head)
 {
 	struct pci_bus *b;
 
-	pdev_assign_resources_sorted((struct pci_dev *)bridge, fail_head);
+	pdev_assign_resources_sorted((struct pci_dev *)bridge,
+					 add_head, fail_head);
 
 	b = bridge->subordinate;
 	if (!b)
 		return;
 
-	__pci_bus_assign_resources(b, NULL, fail_head);
+	__pci_bus_assign_resources(b, add_head, fail_head);
 
 	switch (bridge->class >> 8) {
 	case PCI_CLASS_BRIDGE_PCI:
@@ -1291,6 +1294,8 @@ enable_and_dump:
 void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 {
 	struct pci_bus *parent = bridge->subordinate;
+	struct resource_list_x add_list; /* list of resources that
+					want additional resources */
 	int tried_times = 0;
 	struct resource_list_x head, *list;
 	int retval;
@@ -1298,11 +1303,12 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 				  IORESOURCE_PREFETCH;
 
 	head.next = NULL;
+	add_list.next = NULL;
 
 again:
-	pci_bus_size_bridges(parent);
-	__pci_bridge_assign_resources(bridge, &head);
-
+	__pci_bus_size_bridges(parent, &add_list);
+	__pci_bridge_assign_resources(bridge, &add_list, &head);
+	BUG_ON(add_list.next);
 	tried_times++;
 
 	if (!head.next)
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 06/21] PCI: Make rescan bus could increase bridge resource size if needed
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (4 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 05/21] PCI: Using add_list in pcie hotplug path Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-27 18:00   ` Jesse Barnes
  2012-01-21 10:08 ` [PATCH 07/21] PCI: Make pci_rescan_bus handle add_list Yinghai Lu
                   ` (14 subsequent siblings)
  20 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

Current rescan will not touch bridge MMIO and IO.

Try to reuse pci_assign_unassigned_bridge_resources(bridge) to update bridge
resource, if child devices need more resource.

only do that for bridges that all children get removed before. So do not
release resources that could already be used by drivers of child devices.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/pci-sysfs.c |    5 ++++-
 drivers/pci/probe.c     |   24 ++++++++++++++++++++++++
 include/linux/pci.h     |    1 +
 3 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 106be0d..87ddbca 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -366,7 +366,10 @@ dev_bus_rescan_store(struct device *dev, struct device_attribute *attr,
 
 	if (val) {
 		mutex_lock(&pci_remove_rescan_mutex);
-		pci_rescan_bus(bus);
+		if (!pci_is_root_bus(bus) && list_empty(&bus->devices))
+			pci_rescan_bus_bridge_resize(bus->self);
+		else
+			pci_rescan_bus(bus);
 		mutex_unlock(&pci_remove_rescan_mutex);
 	}
 	return count;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 04e74f4..24c8710 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1608,6 +1608,30 @@ EXPORT_SYMBOL(pci_scan_bus_parented);
 
 #ifdef CONFIG_HOTPLUG
 /**
+ * pci_rescan_bus_bridge_resize - scan a PCI bus for devices.
+ * @bridge: PCI bridge for the bus to scan
+ *
+ * Scan a PCI bus and child buses for new devices, adds them,
+ * and enables them, it will resize bridge mmio/io resource if it is possible
+ * for safe, caller should make sure that children get removed already.
+ *
+ * Returns the max number of subordinate bus discovered.
+ */
+unsigned int __ref pci_rescan_bus_bridge_resize(struct pci_dev *bridge)
+{
+	unsigned int max;
+	struct pci_bus *bus = bridge->subordinate;
+
+	max = pci_scan_child_bus(bus);
+
+	pci_assign_unassigned_bridge_resources(bridge);
+
+	pci_bus_add_devices(bus);
+
+	return max;
+}
+
+/**
  * pci_rescan_bus - scan a PCI bus for devices.
  * @bus: PCI bus to scan
  *
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 7cda65b..841ba6f 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -879,6 +879,7 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev);
 /* Functions for PCI Hotplug drivers to use */
 int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
 #ifdef CONFIG_HOTPLUG
+unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge);
 unsigned int pci_rescan_bus(struct pci_bus *bus);
 #endif
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 07/21] PCI: Make pci_rescan_bus handle add_list
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (5 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 06/21] PCI: Make rescan bus could increase bridge resource size if needed Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 08/21] PCI: Fixing multiple retrying with pci resource optional resources allocation under multi bridges Yinghai Lu
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

So it will allocate resource to hotplug bridge during remove/rescan.

Need to move that function to setup-bus.c so it could use
  __pci_bus_size_bridges and __pci_bus_assign_resources
directly to take add_list.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/probe.c     |   32 --------------------------------
 drivers/pci/setup-bus.c |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 24c8710..7232fc8 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1631,38 +1631,6 @@ unsigned int __ref pci_rescan_bus_bridge_resize(struct pci_dev *bridge)
 	return max;
 }
 
-/**
- * pci_rescan_bus - scan a PCI bus for devices.
- * @bus: PCI bus to scan
- *
- * Scan a PCI bus and child buses for new devices, adds them,
- * and enables them.
- *
- * Returns the max number of subordinate bus discovered.
- */
-unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
-{
-	unsigned int max;
-	struct pci_dev *dev;
-
-	max = pci_scan_child_bus(bus);
-
-	down_read(&pci_bus_sem);
-	list_for_each_entry(dev, &bus->devices, bus_list)
-		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
-		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
-			if (dev->subordinate)
-				pci_bus_size_bridges(dev->subordinate);
-	up_read(&pci_bus_sem);
-
-	pci_bus_assign_resources(bus);
-	pci_enable_bridges(bus);
-	pci_bus_add_devices(bus);
-
-	return max;
-}
-EXPORT_SYMBOL_GPL(pci_rescan_bus);
-
 EXPORT_SYMBOL(pci_add_new_bus);
 EXPORT_SYMBOL(pci_scan_slot);
 EXPORT_SYMBOL(pci_scan_bridge);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 97c1eda..c09c67a 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1357,3 +1357,42 @@ enable_all:
 	pci_enable_bridges(parent);
 }
 EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
+
+#ifdef CONFIG_HOTPLUG
+/**
+ * pci_rescan_bus - scan a PCI bus for devices.
+ * @bus: PCI bus to scan
+ *
+ * Scan a PCI bus and child buses for new devices, adds them,
+ * and enables them.
+ *
+ * Returns the max number of subordinate bus discovered.
+ */
+unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
+{
+	unsigned int max;
+	struct pci_dev *dev;
+	struct resource_list_x add_list; /* list of resources that
+					want additional resources */
+
+	max = pci_scan_child_bus(bus);
+
+	add_list.next = NULL;
+	down_read(&pci_bus_sem);
+	list_for_each_entry(dev, &bus->devices, bus_list)
+		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
+		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
+			if (dev->subordinate)
+				__pci_bus_size_bridges(dev->subordinate,
+							 &add_list);
+	up_read(&pci_bus_sem);
+	__pci_bus_assign_resources(bus, &add_list, NULL);
+	BUG_ON(add_list.next);
+
+	pci_enable_bridges(bus);
+	pci_bus_add_devices(bus);
+
+	return max;
+}
+EXPORT_SYMBOL_GPL(pci_rescan_bus);
+#endif
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 08/21] PCI: Fixing multiple retrying with pci resource optional resources allocation under multi bridges
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (6 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 07/21] PCI: Make pci_rescan_bus handle add_list Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 09/21] PCI: Move pdev_sort_resources() to setup-bus.c Yinghai Lu
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

One system has devices that support sriov and those devices
are connected to pcie switch to pcie root port.

 +-[0000:80]-+-00.0-[81-8f]--
 |           +-01.0-[90-9f]--
 |           +-02.0-[a0-af]----00.0-[a1-a3]--+-02.0-[a2]--+-00.0 Oracle Corporation Device 207a
 |           |                               \-03.0-[a3]--+-00.0 Oracle Corporation Device 207a
 |           +-02.2-[b0-bf]----00.0-[b1-b3]--+-02.0-[b2]--+-00.0 Oracle Corporation Device 207a
 |           |                               \-03.0-[b3]--+-00.0 Oracle Corporation Device 207a

When BIOS does not assign resource for sriov bar, kernel pci reallocation
ony go up to one bridge and then failed to get resource to all sriov bar.
even We have big enough range in peer root bus for allocation.
Specifically, only bridge a1:02.0 level get cleared, and reallocated. kernel does not
go up to clear bridge 80:02.0 level.

To make it go upper levels, during retring, We need to treat good to have
as must have.

Only last try will treat good to have as optional, at that time, parent
bridges resource already released so it will have chance to get assigned
with must_have plus good_to_have for all children devices.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   46 ++++++++++++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c09c67a..c79ce4e 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -943,7 +943,8 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
 		 * Follow thru
 		 */
 	default:
-		pbus_size_io(bus, 0, additional_io_size, realloc_head);
+		pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
+			     additional_io_size, realloc_head);
 		/* If the bridge supports prefetchable range, size it
 		   separately. If it doesn't, or its prefetchable window
 		   has already been allocated by arch code, try
@@ -951,11 +952,15 @@ void __ref __pci_bus_size_bridges(struct pci_bus *bus,
 		   resources. */
 		mask = IORESOURCE_MEM;
 		prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
-		if (pbus_size_mem(bus, prefmask, prefmask, 0, additional_mem_size, realloc_head))
+		if (pbus_size_mem(bus, prefmask, prefmask,
+				  realloc_head ? 0 : additional_mem_size,
+				  additional_mem_size, realloc_head))
 			mask = prefmask; /* Success, size non-prefetch only. */
 		else
 			additional_mem_size += additional_mem_size;
-		pbus_size_mem(bus, mask, IORESOURCE_MEM, 0, additional_mem_size, realloc_head);
+		pbus_size_mem(bus, mask, IORESOURCE_MEM,
+				realloc_head ? 0 : additional_mem_size,
+				additional_mem_size, realloc_head);
 		break;
 	}
 }
@@ -1194,45 +1199,50 @@ pci_assign_unassigned_resources(void)
 	struct pci_bus *bus;
 	struct resource_list_x realloc_list; /* list of resources that
 					want additional resources */
+	struct resource_list_x *add_list = NULL;
 	int tried_times = 0;
 	enum release_type rel_type = leaf_only;
 	struct resource_list_x head, *list;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
 	unsigned long failed_type;
-	int max_depth = pci_get_max_depth();
-	int pci_try_num;
-
+	int pci_try_num = 1;
 
 	head.next = NULL;
 	realloc_list.next = NULL;
 
-	pci_try_num = max_depth + 1;
-	printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n",
-		 max_depth, pci_try_num);
+	/* don't realloc if asked to do so */
+	if (pci_realloc_enabled()) {
+		int max_depth = pci_get_max_depth();
+
+		pci_try_num = max_depth + 1;
+		printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n",
+			 max_depth, pci_try_num);
+	}
 
 again:
+	/*
+	 * last try will use add_list, otherwise will try good to have as
+	 * must have, so can realloc parent bridge resource
+	 */
+	if (tried_times + 1 == pci_try_num)
+		add_list = &realloc_list;
 	/* Depth first, calculate sizes and alignments of all
 	   subordinate buses. */
 	list_for_each_entry(bus, &pci_root_buses, node)
-		__pci_bus_size_bridges(bus, &realloc_list);
+		__pci_bus_size_bridges(bus, add_list);
 
 	/* Depth last, allocate resources and update the hardware. */
 	list_for_each_entry(bus, &pci_root_buses, node)
-		__pci_bus_assign_resources(bus, &realloc_list, &head);
-	BUG_ON(realloc_list.next);
+		__pci_bus_assign_resources(bus, add_list, &head);
+	if (add_list)
+		BUG_ON(add_list->next);
 	tried_times++;
 
 	/* any device complain? */
 	if (!head.next)
 		goto enable_and_dump;
 
-	/* don't realloc if asked to do so */
-	if (!pci_realloc_enabled()) {
-		free_list(resource_list_x, &head);
-		goto enable_and_dump;
-	}
-
 	failed_type = 0;
 	for (list = head.next; list;) {
 		failed_type |= list->flags;
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 09/21] PCI: Move pdev_sort_resources() to setup-bus.c
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (7 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 08/21] PCI: Fixing multiple retrying with pci resource optional resources allocation under multi bridges Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 10/21] PCI: Move struct resource_list " Yinghai Lu
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

So we could move definition of struct resource_list to setup_bus.c

later could convert resource_list to regular list.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/setup-res.c |   47 -----------------------------------------------
 include/linux/pci.h     |    1 -
 3 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c79ce4e..f233d12 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -137,6 +137,52 @@ static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
 	return 0;
 }
 
+/* Sort resources by alignment */
+static void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
+{
+	int i;
+
+	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+		struct resource *r;
+		struct resource_list *list, *tmp;
+		resource_size_t r_align;
+
+		r = &dev->resource[i];
+
+		if (r->flags & IORESOURCE_PCI_FIXED)
+			continue;
+
+		if (!(r->flags) || r->parent)
+			continue;
+
+		r_align = pci_resource_alignment(dev, r);
+		if (!r_align) {
+			dev_warn(&dev->dev, "BAR %d: %pR has bogus alignment\n",
+				 i, r);
+			continue;
+		}
+		for (list = head; ; list = list->next) {
+			resource_size_t align = 0;
+			struct resource_list *ln = list->next;
+
+			if (ln)
+				align = pci_resource_alignment(ln->dev, ln->res);
+
+			if (r_align > align) {
+				tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
+				if (!tmp)
+					panic("pdev_sort_resources(): "
+					      "kmalloc() failed!\n");
+				tmp->next = ln;
+				tmp->res = r;
+				tmp->dev = dev;
+				list->next = tmp;
+				break;
+			}
+		}
+	}
+}
+
 static void __dev_sort_resources(struct pci_dev *dev,
 				 struct resource_list *head)
 {
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 8b25f9c..4b1f376 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -280,53 +280,6 @@ int pci_assign_resource(struct pci_dev *dev, int resno)
 	return ret;
 }
 
-
-/* Sort resources by alignment */
-void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
-{
-	int i;
-
-	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-		struct resource *r;
-		struct resource_list *list, *tmp;
-		resource_size_t r_align;
-
-		r = &dev->resource[i];
-
-		if (r->flags & IORESOURCE_PCI_FIXED)
-			continue;
-
-		if (!(r->flags) || r->parent)
-			continue;
-
-		r_align = pci_resource_alignment(dev, r);
-		if (!r_align) {
-			dev_warn(&dev->dev, "BAR %d: %pR has bogus alignment\n",
-				 i, r);
-			continue;
-		}
-		for (list = head; ; list = list->next) {
-			resource_size_t align = 0;
-			struct resource_list *ln = list->next;
-
-			if (ln)
-				align = pci_resource_alignment(ln->dev, ln->res);
-
-			if (r_align > align) {
-				tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
-				if (!tmp)
-					panic("pdev_sort_resources(): "
-					      "kmalloc() failed!\n");
-				tmp->next = ln;
-				tmp->res = r;
-				tmp->dev = dev;
-				list->next = tmp;
-				break;
-			}
-		}
-	}
-}
-
 int pci_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 841ba6f..aa1d0d9 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -895,7 +895,6 @@ int pci_claim_resource(struct pci_dev *, int);
 void pci_assign_unassigned_resources(void);
 void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge);
 void pdev_enable_device(struct pci_dev *);
-void pdev_sort_resources(struct pci_dev *, struct resource_list *);
 int pci_enable_resources(struct pci_dev *, int mask);
 void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
 		    int (*)(const struct pci_dev *, u8, u8));
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 10/21] PCI: Move struct resource_list to setup-bus.c
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (8 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 09/21] PCI: Move pdev_sort_resources() to setup-bus.c Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 11/21] PCI: Replace resource_list with generic list Yinghai Lu
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

No user outside of setup-bus.c now.

later will convert resource_list to regular list.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |    6 ++++++
 include/linux/ioport.h  |    6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index f233d12..b067a4c 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -27,6 +27,12 @@
 #include <linux/slab.h>
 #include "pci.h"
 
+struct resource_list {
+	struct resource_list *next;
+	struct resource *res;
+	struct pci_dev *dev;
+};
+
 struct resource_list_x {
 	struct resource_list_x *next;
 	struct resource *res;
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 9d57a71..e885ba2 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -23,12 +23,6 @@ struct resource {
 	struct resource *parent, *sibling, *child;
 };
 
-struct resource_list {
-	struct resource_list *next;
-	struct resource *res;
-	struct pci_dev *dev;
-};
-
 /*
  * IO resources have these defined flags.
  */
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 11/21] PCI: Replace resource_list with generic list
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (9 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 10/21] PCI: Move struct resource_list " Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 12/21] PCI: Merge pci_dev_resource_x and pci_dev_resource Yinghai Lu
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

So we can use helper functions for generic list.

-v2: Use list_add_tail instead of adding list_insert_before,
	 Pointed out by Linus.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |  372 +++++++++++++++++++++++------------------------
 1 files changed, 181 insertions(+), 191 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index b067a4c..4c5509e 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -27,14 +27,14 @@
 #include <linux/slab.h>
 #include "pci.h"
 
-struct resource_list {
-	struct resource_list *next;
+struct pci_dev_resource {
+	struct list_head list;
 	struct resource *res;
 	struct pci_dev *dev;
 };
 
-struct resource_list_x {
-	struct resource_list_x *next;
+struct pci_dev_resource_x {
+	struct list_head list;
 	struct resource *res;
 	struct pci_dev *dev;
 	resource_size_t start;
@@ -44,14 +44,12 @@ struct resource_list_x {
 	unsigned long flags;
 };
 
-#define free_list(type, head) do {                      \
-	struct type *list, *tmp;			\
-	for (list = (head)->next; list;) {		\
-		tmp = list;				\
-		list = list->next;			\
-		kfree(tmp);				\
-	}						\
-	(head)->next = NULL;				\
+#define free_list(type, head) do {				\
+	struct type *dev_res, *tmp;				\
+	list_for_each_entry_safe(dev_res, tmp, head, list) {	\
+		list_del(&dev_res->list);			\
+		kfree(dev_res);					\
+	}							\
 } while (0)
 
 int pci_realloc_enable = 0;
@@ -70,21 +68,18 @@ void pci_realloc(void)
  * @add_size:	additional size to be optionally added
  *              to the resource
  */
-static int add_to_list(struct resource_list_x *head,
+static int add_to_list(struct list_head *head,
 		 struct pci_dev *dev, struct resource *res,
 		 resource_size_t add_size, resource_size_t min_align)
 {
-	struct resource_list_x *list = head;
-	struct resource_list_x *ln = list->next;
-	struct resource_list_x *tmp;
+	struct pci_dev_resource_x *tmp;
 
-	tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
+	tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
 	if (!tmp) {
 		pr_warning("add_to_list: kmalloc() failed!\n");
 		return -ENOMEM;
 	}
 
-	tmp->next = ln;
 	tmp->res = res;
 	tmp->dev = dev;
 	tmp->start = res->start;
@@ -92,12 +87,13 @@ static int add_to_list(struct resource_list_x *head,
 	tmp->flags = res->flags;
 	tmp->add_size = add_size;
 	tmp->min_align = min_align;
-	list->next = tmp;
+
+	list_add(&tmp->list, head);
 
 	return 0;
 }
 
-static void add_to_failed_list(struct resource_list_x *head,
+static void add_to_failed_list(struct list_head *head,
 				struct pci_dev *dev, struct resource *res)
 {
 	add_to_list(head, dev, res,
@@ -105,53 +101,48 @@ static void add_to_failed_list(struct resource_list_x *head,
 			0 /* dont care */);
 }
 
-static void remove_from_list(struct resource_list_x *realloc_head,
+static void remove_from_list(struct list_head *realloc_head,
 				 struct resource *res)
 {
-	struct resource_list_x *prev, *tmp, *list;
+	struct pci_dev_resource_x *dev_res_x, *tmp;
 
-	prev = realloc_head;
-	for (list = realloc_head->next; list;) {
-		if (list->res != res) {
-			prev = list;
-			list = list->next;
-			continue;
+	list_for_each_entry_safe(dev_res_x, tmp, realloc_head, list) {
+		if (dev_res_x->res == res) {
+			list_del(&dev_res_x->list);
+			kfree(dev_res_x);
+			break;
 		}
-		tmp = list;
-		prev->next = list = list->next;
-		kfree(tmp);
 	}
 }
 
-static resource_size_t get_res_add_size(struct resource_list_x *realloc_head,
+static resource_size_t get_res_add_size(struct list_head *realloc_head,
 					struct resource *res)
 {
-	struct resource_list_x *list;
+	struct pci_dev_resource_x *dev_res_x;
 
-	/* check if it is in realloc_head list */
-	for (list = realloc_head->next; list && list->res != res;
-			list = list->next)
-		;
-
-	if (list) {
-		dev_printk(KERN_DEBUG, &list->dev->dev,
-			 "%pR get_res_add_size  add_size %llx\n",
-			 list->res, (unsigned long long)list->add_size);
-		return list->add_size;
+	list_for_each_entry(dev_res_x, realloc_head, list) {
+		if (dev_res_x->res == res) {
+			dev_printk(KERN_DEBUG, &dev_res_x->dev->dev,
+				 "%pR get_res_add_size  add_size %llx\n",
+				 dev_res_x->res,
+				 (unsigned long long)dev_res_x->add_size);
+			return dev_res_x->add_size;
+		}
 	}
 
 	return 0;
 }
 
 /* Sort resources by alignment */
-static void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
+static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
 {
 	int i;
 
 	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
 		struct resource *r;
-		struct resource_list *list, *tmp;
+		struct pci_dev_resource *dev_res, *tmp;
 		resource_size_t r_align;
+		struct list_head *n;
 
 		r = &dev->resource[i];
 
@@ -167,30 +158,34 @@ static void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
 				 i, r);
 			continue;
 		}
-		for (list = head; ; list = list->next) {
-			resource_size_t align = 0;
-			struct resource_list *ln = list->next;
 
-			if (ln)
-				align = pci_resource_alignment(ln->dev, ln->res);
+		tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
+		if (!tmp)
+			panic("pdev_sort_resources(): "
+			      "kmalloc() failed!\n");
+		tmp->res = r;
+		tmp->dev = dev;
+
+		/* fallback is smallest one or list is empty*/
+		n = head;
+		list_for_each_entry(dev_res, head, list) {
+			resource_size_t align;
+
+			align = pci_resource_alignment(dev_res->dev,
+							 dev_res->res);
 
 			if (r_align > align) {
-				tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
-				if (!tmp)
-					panic("pdev_sort_resources(): "
-					      "kmalloc() failed!\n");
-				tmp->next = ln;
-				tmp->res = r;
-				tmp->dev = dev;
-				list->next = tmp;
+				n = &dev_res->list;
 				break;
 			}
 		}
+		/* Insert it just before n*/
+		list_add_tail(&tmp->list, n);
 	}
 }
 
 static void __dev_sort_resources(struct pci_dev *dev,
-				 struct resource_list *head)
+				 struct list_head *head)
 {
 	u16 class = dev->class >> 8;
 
@@ -228,49 +223,53 @@ static inline void reset_resource(struct resource *res)
  * additional resources for the element, provided the element
  * is in the head list.
  */
-static void reassign_resources_sorted(struct resource_list_x *realloc_head,
-		struct resource_list *head)
+static void reassign_resources_sorted(struct list_head *realloc_head,
+		struct list_head *head)
 {
 	struct resource *res;
-	struct resource_list_x *list, *tmp, *prev;
-	struct resource_list *hlist;
+	struct pci_dev_resource_x *dev_res_x, *tmp;
+	struct pci_dev_resource *dev_res;
 	resource_size_t add_size;
 	int idx;
 
-	prev = realloc_head;
-	for (list = realloc_head->next; list;) {
-		res = list->res;
+	list_for_each_entry_safe(dev_res_x, tmp, realloc_head, list) {
+		bool found_match = false;
+
+		res = dev_res_x->res;
 		/* skip resource that has been reset */
 		if (!res->flags)
 			goto out;
 
 		/* skip this resource if not found in head list */
-		for (hlist = head->next; hlist && hlist->res != res;
-				hlist = hlist->next);
-		if (!hlist) { /* just skip */
-			prev = list;
-			list = list->next;
-			continue;
+		list_for_each_entry(dev_res, head, list) {
+			if (dev_res->res == res) {
+				found_match = true;
+				break;
+			}
 		}
+		if (!found_match)/* just skip */
+			continue;
 
-		idx = res - &list->dev->resource[0];
-		add_size=list->add_size;
+		idx = res - &dev_res_x->dev->resource[0];
+		add_size = dev_res_x->add_size;
 		if (!resource_size(res)) {
-			res->start = list->start;
+			res->start = dev_res_x->start;
 			res->end = res->start + add_size - 1;
-			if(pci_assign_resource(list->dev, idx))
+			if (pci_assign_resource(dev_res_x->dev, idx))
 				reset_resource(res);
 		} else {
-			resource_size_t align = list->min_align;
-			res->flags |= list->flags & (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
-			if (pci_reassign_resource(list->dev, idx, add_size, align))
-				dev_printk(KERN_DEBUG, &list->dev->dev, "failed to add optional resources res=%pR\n",
+			resource_size_t align = dev_res_x->min_align;
+			res->flags |= dev_res_x->flags &
+				 (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
+			if (pci_reassign_resource(dev_res_x->dev, idx,
+						  add_size, align))
+				dev_printk(KERN_DEBUG, &dev_res_x->dev->dev,
+				   "failed to add optional resources res=%pR\n",
 							res);
 		}
 out:
-		tmp = list;
-		prev->next = list = list->next;
-		kfree(tmp);
+		list_del(&dev_res_x->list);
+		kfree(dev_res_x);
 	}
 }
 
@@ -284,34 +283,36 @@ out:
  * Satisfy resource requests of each element in the list. Add
  * requests that could not satisfied to the failed_list.
  */
-static void assign_requested_resources_sorted(struct resource_list *head,
-				 struct resource_list_x *fail_head)
+static void assign_requested_resources_sorted(struct list_head *head,
+				 struct list_head *fail_head)
 {
 	struct resource *res;
-	struct resource_list *list;
+	struct pci_dev_resource *dev_res;
 	int idx;
 
-	for (list = head->next; list; list = list->next) {
-		res = list->res;
-		idx = res - &list->dev->resource[0];
-		if (resource_size(res) && pci_assign_resource(list->dev, idx)) {
-			if (fail_head && !pci_is_root_bus(list->dev->bus)) {
+	list_for_each_entry(dev_res, head, list) {
+		res = dev_res->res;
+		idx = res - &dev_res->dev->resource[0];
+		if (resource_size(res) &&
+		    pci_assign_resource(dev_res->dev, idx)) {
+			if (fail_head && !pci_is_root_bus(dev_res->dev->bus)) {
 				/*
 				 * if the failed res is for ROM BAR, and it will
 				 * be enabled later, don't add it to the list
 				 */
 				if (!((idx == PCI_ROM_RESOURCE) &&
 				      (!(res->flags & IORESOURCE_ROM_ENABLE))))
-					add_to_failed_list(fail_head, list->dev, res);
+					add_to_failed_list(fail_head,
+							   dev_res->dev, res);
 			}
 			reset_resource(res);
 		}
 	}
 }
 
-static void __assign_resources_sorted(struct resource_list *head,
-				 struct resource_list_x *realloc_head,
-				 struct resource_list_x *fail_head)
+static void __assign_resources_sorted(struct list_head *head,
+				 struct list_head *realloc_head,
+				 struct list_head *fail_head)
 {
 	/*
 	 * Should not assign requested resources at first.
@@ -322,53 +323,55 @@ static void __assign_resources_sorted(struct resource_list *head,
 	 *  if could not do that, we still try to assign requested at first,
 	 *    then try to reassign add_size for some resources.
 	 */
-	struct resource_list_x save_head, local_fail_head, *list;
-	struct resource_list *l;
+	LIST_HEAD(save_head);
+	LIST_HEAD(local_fail_head);
+	struct pci_dev_resource_x *dev_res_x;
+	struct pci_dev_resource *dev_res;
 
 	/* Check if optional add_size is there */
-	if (!realloc_head || !realloc_head->next)
+	if (!realloc_head || list_empty(realloc_head))
 		goto requested_and_reassign;
 
 	/* Save original start, end, flags etc at first */
-	save_head.next = NULL;
-	for (l = head->next; l; l = l->next)
-		if (add_to_list(&save_head, l->dev, l->res, 0, 0)) {
-			free_list(resource_list_x, &save_head);
+	list_for_each_entry(dev_res, head, list) {
+		if (add_to_list(&save_head, dev_res->dev, dev_res->res, 0, 0)) {
+			free_list(pci_dev_resource_x, &save_head);
 			goto requested_and_reassign;
 		}
+	}
 
 	/* Update res in head list with add_size in realloc_head list */
-	for (l = head->next; l; l = l->next)
-		l->res->end += get_res_add_size(realloc_head, l->res);
+	list_for_each_entry(dev_res, head, list)
+		dev_res->res->end += get_res_add_size(realloc_head,
+							dev_res->res);
 
 	/* Try updated head list with add_size added */
-	local_fail_head.next = NULL;
 	assign_requested_resources_sorted(head, &local_fail_head);
 
 	/* all assigned with add_size ? */
-	if (!local_fail_head.next) {
+	if (list_empty(&local_fail_head)) {
 		/* Remove head list from realloc_head list */
-		for (l = head->next; l; l = l->next)
-			remove_from_list(realloc_head, l->res);
-		free_list(resource_list_x, &save_head);
-		free_list(resource_list, head);
+		list_for_each_entry(dev_res, head, list)
+			remove_from_list(realloc_head, dev_res->res);
+		free_list(pci_dev_resource_x, &save_head);
+		free_list(pci_dev_resource, head);
 		return;
 	}
 
-	free_list(resource_list_x, &local_fail_head);
+	free_list(pci_dev_resource_x, &local_fail_head);
 	/* Release assigned resource */
-	for (l = head->next; l; l = l->next)
-		if (l->res->parent)
-			release_resource(l->res);
+	list_for_each_entry(dev_res, head, list)
+		if (dev_res->res->parent)
+			release_resource(dev_res->res);
 	/* Restore start/end/flags from saved list */
-	for (list = save_head.next; list; list = list->next) {
-		struct resource *res = list->res;
+	list_for_each_entry(dev_res_x, &save_head, list) {
+		struct resource *res = dev_res_x->res;
 
-		res->start = list->start;
-		res->end = list->end;
-		res->flags = list->flags;
+		res->start = dev_res_x->start;
+		res->end = dev_res_x->end;
+		res->flags = dev_res_x->flags;
 	}
-	free_list(resource_list_x, &save_head);
+	free_list(pci_dev_resource_x, &save_head);
 
 requested_and_reassign:
 	/* Satisfy the must-have resource requests */
@@ -378,29 +381,27 @@ requested_and_reassign:
 		requests */
 	if (realloc_head)
 		reassign_resources_sorted(realloc_head, head);
-	free_list(resource_list, head);
+	free_list(pci_dev_resource, head);
 }
 
 static void pdev_assign_resources_sorted(struct pci_dev *dev,
-				 struct resource_list_x *add_head,
-				 struct resource_list_x *fail_head)
+				 struct list_head *add_head,
+				 struct list_head *fail_head)
 {
-	struct resource_list head;
+	LIST_HEAD(head);
 
-	head.next = NULL;
 	__dev_sort_resources(dev, &head);
 	__assign_resources_sorted(&head, add_head, fail_head);
 
 }
 
 static void pbus_assign_resources_sorted(const struct pci_bus *bus,
-					 struct resource_list_x *realloc_head,
-					 struct resource_list_x *fail_head)
+					 struct list_head *realloc_head,
+					 struct list_head *fail_head)
 {
 	struct pci_dev *dev;
-	struct resource_list head;
+	LIST_HEAD(head);
 
-	head.next = NULL;
 	list_for_each_entry(dev, &bus->devices, bus_list)
 		__dev_sort_resources(dev, &head);
 
@@ -713,7 +714,7 @@ static resource_size_t calculate_memsize(resource_size_t size,
  * We must be careful with the ISA aliasing though.
  */
 static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
-		resource_size_t add_size, struct resource_list_x *realloc_head)
+		resource_size_t add_size, struct list_head *realloc_head)
 {
 	struct pci_dev *dev;
 	struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO);
@@ -781,7 +782,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
 static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
 			 unsigned long type, resource_size_t min_size,
 			resource_size_t add_size,
-			struct resource_list_x *realloc_head)
+			struct list_head *realloc_head)
 {
 	struct pci_dev *dev;
 	resource_size_t min_align, align, size, size0, size1;
@@ -891,7 +892,7 @@ unsigned long pci_cardbus_resource_alignment(struct resource *res)
 }
 
 static void pci_bus_size_cardbus(struct pci_bus *bus,
-			struct resource_list_x *realloc_head)
+			struct list_head *realloc_head)
 {
 	struct pci_dev *bridge = bus->self;
 	struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
@@ -953,7 +954,7 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
 }
 
 void __ref __pci_bus_size_bridges(struct pci_bus *bus,
-			struct resource_list_x *realloc_head)
+			struct list_head *realloc_head)
 {
 	struct pci_dev *dev;
 	unsigned long mask, prefmask;
@@ -1024,8 +1025,8 @@ void __ref pci_bus_size_bridges(struct pci_bus *bus)
 EXPORT_SYMBOL(pci_bus_size_bridges);
 
 static void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
-					 struct resource_list_x *realloc_head,
-					 struct resource_list_x *fail_head)
+					 struct list_head *realloc_head,
+					 struct list_head *fail_head)
 {
 	struct pci_bus *b;
 	struct pci_dev *dev;
@@ -1064,8 +1065,8 @@ void __ref pci_bus_assign_resources(const struct pci_bus *bus)
 EXPORT_SYMBOL(pci_bus_assign_resources);
 
 static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge,
-					 struct resource_list_x *add_head,
-					 struct resource_list_x *fail_head)
+					 struct list_head *add_head,
+					 struct list_head *fail_head)
 {
 	struct pci_bus *b;
 
@@ -1249,20 +1250,18 @@ void __init
 pci_assign_unassigned_resources(void)
 {
 	struct pci_bus *bus;
-	struct resource_list_x realloc_list; /* list of resources that
+	LIST_HEAD(realloc_head); /* list of resources that
 					want additional resources */
-	struct resource_list_x *add_list = NULL;
+	struct list_head *add_list = NULL;
 	int tried_times = 0;
 	enum release_type rel_type = leaf_only;
-	struct resource_list_x head, *list;
+	LIST_HEAD(fail_head);
+	struct pci_dev_resource_x *dev_res_x;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
 	unsigned long failed_type;
 	int pci_try_num = 1;
 
-	head.next = NULL;
-	realloc_list.next = NULL;
-
 	/* don't realloc if asked to do so */
 	if (pci_realloc_enabled()) {
 		int max_depth = pci_get_max_depth();
@@ -1278,7 +1277,7 @@ again:
 	 * must have, so can realloc parent bridge resource
 	 */
 	if (tried_times + 1 == pci_try_num)
-		add_list = &realloc_list;
+		add_list = &realloc_head;
 	/* Depth first, calculate sizes and alignments of all
 	   subordinate buses. */
 	list_for_each_entry(bus, &pci_root_buses, node)
@@ -1286,27 +1285,26 @@ again:
 
 	/* Depth last, allocate resources and update the hardware. */
 	list_for_each_entry(bus, &pci_root_buses, node)
-		__pci_bus_assign_resources(bus, add_list, &head);
+		__pci_bus_assign_resources(bus, add_list, &fail_head);
 	if (add_list)
-		BUG_ON(add_list->next);
+		BUG_ON(!list_empty(add_list));
 	tried_times++;
 
 	/* any device complain? */
-	if (!head.next)
+	if (list_empty(&fail_head))
 		goto enable_and_dump;
 
 	failed_type = 0;
-	for (list = head.next; list;) {
-		failed_type |= list->flags;
-		list = list->next;
-	}
+	list_for_each_entry(dev_res_x, &fail_head, list)
+		failed_type |= dev_res_x->flags;
+
 	/*
 	 * io port are tight, don't try extra
 	 * or if reach the limit, don't want to try more
 	 */
 	failed_type &= type_mask;
 	if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) {
-		free_list(resource_list_x, &head);
+		free_list(pci_dev_resource_x, &fail_head);
 		goto enable_and_dump;
 	}
 
@@ -1321,25 +1319,23 @@ again:
 	 * Try to release leaf bridge's resources that doesn't fit resource of
 	 * child device under that bridge
 	 */
-	for (list = head.next; list;) {
-		bus = list->dev->bus;
-		pci_bus_release_bridge_resources(bus, list->flags & type_mask,
-						  rel_type);
-		list = list->next;
+	list_for_each_entry(dev_res_x, &fail_head, list) {
+		bus = dev_res_x->dev->bus;
+		pci_bus_release_bridge_resources(bus,
+						 dev_res_x->flags & type_mask,
+						 rel_type);
 	}
 	/* restore size and flags */
-	for (list = head.next; list;) {
-		struct resource *res = list->res;
+	list_for_each_entry(dev_res_x, &fail_head, list) {
+		struct resource *res = dev_res_x->res;
 
-		res->start = list->start;
-		res->end = list->end;
-		res->flags = list->flags;
-		if (list->dev->subordinate)
+		res->start = dev_res_x->start;
+		res->end = dev_res_x->end;
+		res->flags = dev_res_x->flags;
+		if (dev_res_x->dev->subordinate)
 			res->flags = 0;
-
-		list = list->next;
 	}
-	free_list(resource_list_x, &head);
+	free_list(pci_dev_resource_x, &fail_head);
 
 	goto again;
 
@@ -1356,29 +1352,27 @@ enable_and_dump:
 void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 {
 	struct pci_bus *parent = bridge->subordinate;
-	struct resource_list_x add_list; /* list of resources that
+	LIST_HEAD(add_list); /* list of resources that
 					want additional resources */
 	int tried_times = 0;
-	struct resource_list_x head, *list;
+	LIST_HEAD(fail_head);
+	struct pci_dev_resource_x *dev_res_x;
 	int retval;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
 
-	head.next = NULL;
-	add_list.next = NULL;
-
 again:
 	__pci_bus_size_bridges(parent, &add_list);
-	__pci_bridge_assign_resources(bridge, &add_list, &head);
-	BUG_ON(add_list.next);
+	__pci_bridge_assign_resources(bridge, &add_list, &fail_head);
+	BUG_ON(!list_empty(&add_list));
 	tried_times++;
 
-	if (!head.next)
+	if (list_empty(&fail_head))
 		goto enable_all;
 
 	if (tried_times >= 2) {
 		/* still fail, don't need to try more */
-		free_list(resource_list_x, &head);
+		free_list(pci_dev_resource_x, &fail_head);
 		goto enable_all;
 	}
 
@@ -1389,27 +1383,24 @@ again:
 	 * Try to release leaf bridge's resources that doesn't fit resource of
 	 * child device under that bridge
 	 */
-	for (list = head.next; list;) {
-		struct pci_bus *bus = list->dev->bus;
-		unsigned long flags = list->flags;
+	list_for_each_entry(dev_res_x, &fail_head, list) {
+		struct pci_bus *bus = dev_res_x->dev->bus;
+		unsigned long flags = dev_res_x->flags;
 
 		pci_bus_release_bridge_resources(bus, flags & type_mask,
 						 whole_subtree);
-		list = list->next;
 	}
 	/* restore size and flags */
-	for (list = head.next; list;) {
-		struct resource *res = list->res;
+	list_for_each_entry(dev_res_x, &fail_head, list) {
+		struct resource *res = dev_res_x->res;
 
-		res->start = list->start;
-		res->end = list->end;
-		res->flags = list->flags;
-		if (list->dev->subordinate)
+		res->start = dev_res_x->start;
+		res->end = dev_res_x->end;
+		res->flags = dev_res_x->flags;
+		if (dev_res_x->dev->subordinate)
 			res->flags = 0;
-
-		list = list->next;
 	}
-	free_list(resource_list_x, &head);
+	free_list(pci_dev_resource_x, &fail_head);
 
 	goto again;
 
@@ -1434,12 +1425,11 @@ unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
 {
 	unsigned int max;
 	struct pci_dev *dev;
-	struct resource_list_x add_list; /* list of resources that
+	LIST_HEAD(add_list); /* list of resources that
 					want additional resources */
 
 	max = pci_scan_child_bus(bus);
 
-	add_list.next = NULL;
 	down_read(&pci_bus_sem);
 	list_for_each_entry(dev, &bus->devices, bus_list)
 		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
@@ -1449,7 +1439,7 @@ unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
 							 &add_list);
 	up_read(&pci_bus_sem);
 	__pci_bus_assign_resources(bus, &add_list, NULL);
-	BUG_ON(add_list.next);
+	BUG_ON(!list_empty(&add_list));
 
 	pci_enable_bridges(bus);
 	pci_bus_add_devices(bus);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 12/21] PCI: Merge pci_dev_resource_x and pci_dev_resource
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (10 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 11/21] PCI: Replace resource_list with generic list Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 13/21] PCI: Rename dev_res_x to add_res or fail_res Yinghai Lu
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

pci_dev_resource_x is superset of pci_dev_resource

and those two are temp struct during resource reallocating.

pci_dev_resource usage is quite limted.

So just use pci_dev_resource_x, and rename it as new pci_dev_resource.

-v2: According to Linus, Separate free_list change to another patch

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 4c5509e..af2a98a 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -31,12 +31,6 @@ struct pci_dev_resource {
 	struct list_head list;
 	struct resource *res;
 	struct pci_dev *dev;
-};
-
-struct pci_dev_resource_x {
-	struct list_head list;
-	struct resource *res;
-	struct pci_dev *dev;
 	resource_size_t start;
 	resource_size_t end;
 	resource_size_t add_size;
@@ -72,7 +66,7 @@ static int add_to_list(struct list_head *head,
 		 struct pci_dev *dev, struct resource *res,
 		 resource_size_t add_size, resource_size_t min_align)
 {
-	struct pci_dev_resource_x *tmp;
+	struct pci_dev_resource *tmp;
 
 	tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
 	if (!tmp) {
@@ -104,7 +98,7 @@ static void add_to_failed_list(struct list_head *head,
 static void remove_from_list(struct list_head *realloc_head,
 				 struct resource *res)
 {
-	struct pci_dev_resource_x *dev_res_x, *tmp;
+	struct pci_dev_resource *dev_res_x, *tmp;
 
 	list_for_each_entry_safe(dev_res_x, tmp, realloc_head, list) {
 		if (dev_res_x->res == res) {
@@ -118,7 +112,7 @@ static void remove_from_list(struct list_head *realloc_head,
 static resource_size_t get_res_add_size(struct list_head *realloc_head,
 					struct resource *res)
 {
-	struct pci_dev_resource_x *dev_res_x;
+	struct pci_dev_resource *dev_res_x;
 
 	list_for_each_entry(dev_res_x, realloc_head, list) {
 		if (dev_res_x->res == res) {
@@ -227,7 +221,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
 		struct list_head *head)
 {
 	struct resource *res;
-	struct pci_dev_resource_x *dev_res_x, *tmp;
+	struct pci_dev_resource *dev_res_x, *tmp;
 	struct pci_dev_resource *dev_res;
 	resource_size_t add_size;
 	int idx;
@@ -325,7 +319,7 @@ static void __assign_resources_sorted(struct list_head *head,
 	 */
 	LIST_HEAD(save_head);
 	LIST_HEAD(local_fail_head);
-	struct pci_dev_resource_x *dev_res_x;
+	struct pci_dev_resource *dev_res_x;
 	struct pci_dev_resource *dev_res;
 
 	/* Check if optional add_size is there */
@@ -335,7 +329,7 @@ static void __assign_resources_sorted(struct list_head *head,
 	/* Save original start, end, flags etc at first */
 	list_for_each_entry(dev_res, head, list) {
 		if (add_to_list(&save_head, dev_res->dev, dev_res->res, 0, 0)) {
-			free_list(pci_dev_resource_x, &save_head);
+			free_list(pci_dev_resource, &save_head);
 			goto requested_and_reassign;
 		}
 	}
@@ -353,12 +347,12 @@ static void __assign_resources_sorted(struct list_head *head,
 		/* Remove head list from realloc_head list */
 		list_for_each_entry(dev_res, head, list)
 			remove_from_list(realloc_head, dev_res->res);
-		free_list(pci_dev_resource_x, &save_head);
+		free_list(pci_dev_resource, &save_head);
 		free_list(pci_dev_resource, head);
 		return;
 	}
 
-	free_list(pci_dev_resource_x, &local_fail_head);
+	free_list(pci_dev_resource, &local_fail_head);
 	/* Release assigned resource */
 	list_for_each_entry(dev_res, head, list)
 		if (dev_res->res->parent)
@@ -371,7 +365,7 @@ static void __assign_resources_sorted(struct list_head *head,
 		res->end = dev_res_x->end;
 		res->flags = dev_res_x->flags;
 	}
-	free_list(pci_dev_resource_x, &save_head);
+	free_list(pci_dev_resource, &save_head);
 
 requested_and_reassign:
 	/* Satisfy the must-have resource requests */
@@ -1256,7 +1250,7 @@ pci_assign_unassigned_resources(void)
 	int tried_times = 0;
 	enum release_type rel_type = leaf_only;
 	LIST_HEAD(fail_head);
-	struct pci_dev_resource_x *dev_res_x;
+	struct pci_dev_resource *dev_res_x;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
 	unsigned long failed_type;
@@ -1304,7 +1298,7 @@ again:
 	 */
 	failed_type &= type_mask;
 	if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) {
-		free_list(pci_dev_resource_x, &fail_head);
+		free_list(pci_dev_resource, &fail_head);
 		goto enable_and_dump;
 	}
 
@@ -1335,7 +1329,7 @@ again:
 		if (dev_res_x->dev->subordinate)
 			res->flags = 0;
 	}
-	free_list(pci_dev_resource_x, &fail_head);
+	free_list(pci_dev_resource, &fail_head);
 
 	goto again;
 
@@ -1356,7 +1350,7 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 					want additional resources */
 	int tried_times = 0;
 	LIST_HEAD(fail_head);
-	struct pci_dev_resource_x *dev_res_x;
+	struct pci_dev_resource *dev_res_x;
 	int retval;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
@@ -1372,7 +1366,7 @@ again:
 
 	if (tried_times >= 2) {
 		/* still fail, don't need to try more */
-		free_list(pci_dev_resource_x, &fail_head);
+		free_list(pci_dev_resource, &fail_head);
 		goto enable_all;
 	}
 
@@ -1400,7 +1394,7 @@ again:
 		if (dev_res_x->dev->subordinate)
 			res->flags = 0;
 	}
-	free_list(pci_dev_resource_x, &fail_head);
+	free_list(pci_dev_resource, &fail_head);
 
 	goto again;
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 13/21] PCI: Rename dev_res_x to add_res or fail_res
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (11 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 12/21] PCI: Merge pci_dev_resource_x and pci_dev_resource Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 14/21] PCI: Change free_list() to function Yinghai Lu
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

According to Linus, don't use dev_res_x.
Replace them with add_res, fail_res etc according to context.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |  110 +++++++++++++++++++++++-----------------------
 1 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index af2a98a..a6e427a 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -95,32 +95,32 @@ static void add_to_failed_list(struct list_head *head,
 			0 /* dont care */);
 }
 
-static void remove_from_list(struct list_head *realloc_head,
+static void remove_from_list(struct list_head *head,
 				 struct resource *res)
 {
-	struct pci_dev_resource *dev_res_x, *tmp;
+	struct pci_dev_resource *dev_res, *tmp;
 
-	list_for_each_entry_safe(dev_res_x, tmp, realloc_head, list) {
-		if (dev_res_x->res == res) {
-			list_del(&dev_res_x->list);
-			kfree(dev_res_x);
+	list_for_each_entry_safe(dev_res, tmp, head, list) {
+		if (dev_res->res == res) {
+			list_del(&dev_res->list);
+			kfree(dev_res);
 			break;
 		}
 	}
 }
 
-static resource_size_t get_res_add_size(struct list_head *realloc_head,
+static resource_size_t get_res_add_size(struct list_head *head,
 					struct resource *res)
 {
-	struct pci_dev_resource *dev_res_x;
+	struct pci_dev_resource *dev_res;
 
-	list_for_each_entry(dev_res_x, realloc_head, list) {
-		if (dev_res_x->res == res) {
-			dev_printk(KERN_DEBUG, &dev_res_x->dev->dev,
+	list_for_each_entry(dev_res, head, list) {
+		if (dev_res->res == res) {
+			dev_printk(KERN_DEBUG, &dev_res->dev->dev,
 				 "%pR get_res_add_size  add_size %llx\n",
-				 dev_res_x->res,
-				 (unsigned long long)dev_res_x->add_size);
-			return dev_res_x->add_size;
+				 dev_res->res,
+				 (unsigned long long)dev_res->add_size);
+			return dev_res->add_size;
 		}
 	}
 
@@ -221,15 +221,15 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
 		struct list_head *head)
 {
 	struct resource *res;
-	struct pci_dev_resource *dev_res_x, *tmp;
+	struct pci_dev_resource *add_res, *tmp;
 	struct pci_dev_resource *dev_res;
 	resource_size_t add_size;
 	int idx;
 
-	list_for_each_entry_safe(dev_res_x, tmp, realloc_head, list) {
+	list_for_each_entry_safe(add_res, tmp, realloc_head, list) {
 		bool found_match = false;
 
-		res = dev_res_x->res;
+		res = add_res->res;
 		/* skip resource that has been reset */
 		if (!res->flags)
 			goto out;
@@ -244,26 +244,26 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
 		if (!found_match)/* just skip */
 			continue;
 
-		idx = res - &dev_res_x->dev->resource[0];
-		add_size = dev_res_x->add_size;
+		idx = res - &add_res->dev->resource[0];
+		add_size = add_res->add_size;
 		if (!resource_size(res)) {
-			res->start = dev_res_x->start;
+			res->start = add_res->start;
 			res->end = res->start + add_size - 1;
-			if (pci_assign_resource(dev_res_x->dev, idx))
+			if (pci_assign_resource(add_res->dev, idx))
 				reset_resource(res);
 		} else {
-			resource_size_t align = dev_res_x->min_align;
-			res->flags |= dev_res_x->flags &
+			resource_size_t align = add_res->min_align;
+			res->flags |= add_res->flags &
 				 (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
-			if (pci_reassign_resource(dev_res_x->dev, idx,
+			if (pci_reassign_resource(add_res->dev, idx,
 						  add_size, align))
-				dev_printk(KERN_DEBUG, &dev_res_x->dev->dev,
+				dev_printk(KERN_DEBUG, &add_res->dev->dev,
 				   "failed to add optional resources res=%pR\n",
 							res);
 		}
 out:
-		list_del(&dev_res_x->list);
-		kfree(dev_res_x);
+		list_del(&add_res->list);
+		kfree(add_res);
 	}
 }
 
@@ -319,7 +319,7 @@ static void __assign_resources_sorted(struct list_head *head,
 	 */
 	LIST_HEAD(save_head);
 	LIST_HEAD(local_fail_head);
-	struct pci_dev_resource *dev_res_x;
+	struct pci_dev_resource *save_res;
 	struct pci_dev_resource *dev_res;
 
 	/* Check if optional add_size is there */
@@ -358,12 +358,12 @@ static void __assign_resources_sorted(struct list_head *head,
 		if (dev_res->res->parent)
 			release_resource(dev_res->res);
 	/* Restore start/end/flags from saved list */
-	list_for_each_entry(dev_res_x, &save_head, list) {
-		struct resource *res = dev_res_x->res;
+	list_for_each_entry(save_res, &save_head, list) {
+		struct resource *res = save_res->res;
 
-		res->start = dev_res_x->start;
-		res->end = dev_res_x->end;
-		res->flags = dev_res_x->flags;
+		res->start = save_res->start;
+		res->end = save_res->end;
+		res->flags = save_res->flags;
 	}
 	free_list(pci_dev_resource, &save_head);
 
@@ -1250,7 +1250,7 @@ pci_assign_unassigned_resources(void)
 	int tried_times = 0;
 	enum release_type rel_type = leaf_only;
 	LIST_HEAD(fail_head);
-	struct pci_dev_resource *dev_res_x;
+	struct pci_dev_resource *fail_res;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
 	unsigned long failed_type;
@@ -1289,8 +1289,8 @@ again:
 		goto enable_and_dump;
 
 	failed_type = 0;
-	list_for_each_entry(dev_res_x, &fail_head, list)
-		failed_type |= dev_res_x->flags;
+	list_for_each_entry(fail_res, &fail_head, list)
+		failed_type |= fail_res->flags;
 
 	/*
 	 * io port are tight, don't try extra
@@ -1313,20 +1313,20 @@ again:
 	 * Try to release leaf bridge's resources that doesn't fit resource of
 	 * child device under that bridge
 	 */
-	list_for_each_entry(dev_res_x, &fail_head, list) {
-		bus = dev_res_x->dev->bus;
+	list_for_each_entry(fail_res, &fail_head, list) {
+		bus = fail_res->dev->bus;
 		pci_bus_release_bridge_resources(bus,
-						 dev_res_x->flags & type_mask,
+						 fail_res->flags & type_mask,
 						 rel_type);
 	}
 	/* restore size and flags */
-	list_for_each_entry(dev_res_x, &fail_head, list) {
-		struct resource *res = dev_res_x->res;
+	list_for_each_entry(fail_res, &fail_head, list) {
+		struct resource *res = fail_res->res;
 
-		res->start = dev_res_x->start;
-		res->end = dev_res_x->end;
-		res->flags = dev_res_x->flags;
-		if (dev_res_x->dev->subordinate)
+		res->start = fail_res->start;
+		res->end = fail_res->end;
+		res->flags = fail_res->flags;
+		if (fail_res->dev->subordinate)
 			res->flags = 0;
 	}
 	free_list(pci_dev_resource, &fail_head);
@@ -1350,7 +1350,7 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 					want additional resources */
 	int tried_times = 0;
 	LIST_HEAD(fail_head);
-	struct pci_dev_resource *dev_res_x;
+	struct pci_dev_resource *fail_res;
 	int retval;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
@@ -1377,21 +1377,21 @@ again:
 	 * Try to release leaf bridge's resources that doesn't fit resource of
 	 * child device under that bridge
 	 */
-	list_for_each_entry(dev_res_x, &fail_head, list) {
-		struct pci_bus *bus = dev_res_x->dev->bus;
-		unsigned long flags = dev_res_x->flags;
+	list_for_each_entry(fail_res, &fail_head, list) {
+		struct pci_bus *bus = fail_res->dev->bus;
+		unsigned long flags = fail_res->flags;
 
 		pci_bus_release_bridge_resources(bus, flags & type_mask,
 						 whole_subtree);
 	}
 	/* restore size and flags */
-	list_for_each_entry(dev_res_x, &fail_head, list) {
-		struct resource *res = dev_res_x->res;
+	list_for_each_entry(fail_res, &fail_head, list) {
+		struct resource *res = fail_res->res;
 
-		res->start = dev_res_x->start;
-		res->end = dev_res_x->end;
-		res->flags = dev_res_x->flags;
-		if (dev_res_x->dev->subordinate)
+		res->start = fail_res->start;
+		res->end = fail_res->end;
+		res->flags = fail_res->flags;
+		if (fail_res->dev->subordinate)
 			res->flags = 0;
 	}
 	free_list(pci_dev_resource, &fail_head);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 14/21] PCI: Change free_list() to function
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (12 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 13/21] PCI: Rename dev_res_x to add_res or fail_res Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 15/21] PCI: add debug print out for add_size Yinghai Lu
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

After merging struct pci_dev_resource_x and pci_dev_resource,
We can use function instead of macro now.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   36 +++++++++++++++++++-----------------
 1 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index a6e427a..c845d18 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -38,13 +38,15 @@ struct pci_dev_resource {
 	unsigned long flags;
 };
 
-#define free_list(type, head) do {				\
-	struct type *dev_res, *tmp;				\
-	list_for_each_entry_safe(dev_res, tmp, head, list) {	\
-		list_del(&dev_res->list);			\
-		kfree(dev_res);					\
-	}							\
-} while (0)
+static void free_list(struct list_head *head)
+{
+	struct pci_dev_resource *dev_res, *tmp;
+
+	list_for_each_entry_safe(dev_res, tmp, head, list) {
+		list_del(&dev_res->list);
+		kfree(dev_res);
+	}
+}
 
 int pci_realloc_enable = 0;
 #define pci_realloc_enabled() pci_realloc_enable
@@ -329,7 +331,7 @@ static void __assign_resources_sorted(struct list_head *head,
 	/* Save original start, end, flags etc at first */
 	list_for_each_entry(dev_res, head, list) {
 		if (add_to_list(&save_head, dev_res->dev, dev_res->res, 0, 0)) {
-			free_list(pci_dev_resource, &save_head);
+			free_list(&save_head);
 			goto requested_and_reassign;
 		}
 	}
@@ -347,12 +349,12 @@ static void __assign_resources_sorted(struct list_head *head,
 		/* Remove head list from realloc_head list */
 		list_for_each_entry(dev_res, head, list)
 			remove_from_list(realloc_head, dev_res->res);
-		free_list(pci_dev_resource, &save_head);
-		free_list(pci_dev_resource, head);
+		free_list(&save_head);
+		free_list(head);
 		return;
 	}
 
-	free_list(pci_dev_resource, &local_fail_head);
+	free_list(&local_fail_head);
 	/* Release assigned resource */
 	list_for_each_entry(dev_res, head, list)
 		if (dev_res->res->parent)
@@ -365,7 +367,7 @@ static void __assign_resources_sorted(struct list_head *head,
 		res->end = save_res->end;
 		res->flags = save_res->flags;
 	}
-	free_list(pci_dev_resource, &save_head);
+	free_list(&save_head);
 
 requested_and_reassign:
 	/* Satisfy the must-have resource requests */
@@ -375,7 +377,7 @@ requested_and_reassign:
 		requests */
 	if (realloc_head)
 		reassign_resources_sorted(realloc_head, head);
-	free_list(pci_dev_resource, head);
+	free_list(head);
 }
 
 static void pdev_assign_resources_sorted(struct pci_dev *dev,
@@ -1298,7 +1300,7 @@ again:
 	 */
 	failed_type &= type_mask;
 	if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) {
-		free_list(pci_dev_resource, &fail_head);
+		free_list(&fail_head);
 		goto enable_and_dump;
 	}
 
@@ -1329,7 +1331,7 @@ again:
 		if (fail_res->dev->subordinate)
 			res->flags = 0;
 	}
-	free_list(pci_dev_resource, &fail_head);
+	free_list(&fail_head);
 
 	goto again;
 
@@ -1366,7 +1368,7 @@ again:
 
 	if (tried_times >= 2) {
 		/* still fail, don't need to try more */
-		free_list(pci_dev_resource, &fail_head);
+		free_list(&fail_head);
 		goto enable_all;
 	}
 
@@ -1394,7 +1396,7 @@ again:
 		if (fail_res->dev->subordinate)
 			res->flags = 0;
 	}
-	free_list(pci_dev_resource, &fail_head);
+	free_list(&fail_head);
 
 	goto again;
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 15/21] PCI: add debug print out for add_size
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (13 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 14/21] PCI: Change free_list() to function Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 16/21] PCI: remove add_to_failed_list() Yinghai Lu
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

for some corner cases later.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c845d18..ae0b1f2 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -118,10 +118,13 @@ static resource_size_t get_res_add_size(struct list_head *head,
 
 	list_for_each_entry(dev_res, head, list) {
 		if (dev_res->res == res) {
+			int idx = res - &dev_res->dev->resource[0];
+
 			dev_printk(KERN_DEBUG, &dev_res->dev->dev,
-				 "%pR get_res_add_size  add_size %llx\n",
-				 dev_res->res,
+				 "res[%d]=%pR get_res_add_size add_size %llx\n",
+				 idx, dev_res->res,
 				 (unsigned long long)dev_res->add_size);
+
 			return dev_res->add_size;
 		}
 	}
@@ -260,8 +263,9 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
 			if (pci_reassign_resource(add_res->dev, idx,
 						  add_size, align))
 				dev_printk(KERN_DEBUG, &add_res->dev->dev,
-				   "failed to add optional resources res=%pR\n",
-							res);
+					   "failed to add %llx res[%d]=%pR\n",
+					   (unsigned long long)add_size,
+					   idx, res);
 		}
 out:
 		list_del(&add_res->list);
@@ -760,8 +764,12 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
 	b_res->start = 4096;
 	b_res->end = b_res->start + size0 - 1;
 	b_res->flags |= IORESOURCE_STARTALIGN;
-	if (size1 > size0 && realloc_head)
+	if (size1 > size0 && realloc_head) {
 		add_to_list(realloc_head, bus->self, b_res, size1-size0, 4096);
+		dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window "
+				 "%pR to [bus %02x-%02x] add_size %lx\n", b_res,
+				 bus->secondary, bus->subordinate, size1-size0);
+	}
 }
 
 /**
@@ -873,8 +881,12 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
 	b_res->start = min_align;
 	b_res->end = size0 + min_align - 1;
 	b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask;
-	if (size1 > size0 && realloc_head)
+	if (size1 > size0 && realloc_head) {
 		add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align);
+		dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window "
+				 "%pR to [bus %02x-%02x] add_size %llx\n", b_res,
+				 bus->secondary, bus->subordinate, (unsigned long long)size1-size0);
+	}
 	return 1;
 }
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 16/21] PCI: remove add_to_failed_list()
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (14 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 15/21] PCI: add debug print out for add_size Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-27 18:21   ` Jesse Barnes
  2012-01-21 10:08 ` [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL Yinghai Lu
                   ` (4 subsequent siblings)
  20 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

only one user, just use add_to_list instead.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   14 ++++----------
 1 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index ae0b1f2..090217a 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -89,14 +89,6 @@ static int add_to_list(struct list_head *head,
 	return 0;
 }
 
-static void add_to_failed_list(struct list_head *head,
-				struct pci_dev *dev, struct resource *res)
-{
-	add_to_list(head, dev, res,
-			0 /* dont care */,
-			0 /* dont care */);
-}
-
 static void remove_from_list(struct list_head *head,
 				 struct resource *res)
 {
@@ -302,8 +294,10 @@ static void assign_requested_resources_sorted(struct list_head *head,
 				 */
 				if (!((idx == PCI_ROM_RESOURCE) &&
 				      (!(res->flags & IORESOURCE_ROM_ENABLE))))
-					add_to_failed_list(fail_head,
-							   dev_res->dev, res);
+					add_to_list(fail_head,
+						    dev_res->dev, res,
+						    0 /* dont care */,
+						    0 /* dont care */);
 			}
 			reset_resource(res);
 		}
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (15 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 16/21] PCI: remove add_to_failed_list() Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-27 18:22   ` Jesse Barnes
  2012-01-21 10:08 ` [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling Yinghai Lu
                   ` (3 subsequent siblings)
  20 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

Some BIOS enable both pref for MEM0 and MEM1.

but we assume MEM1 is non-pref...

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 090217a..d5897c3 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -914,6 +914,14 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
 	if (realloc_head)
 		add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
 
+	/* MEM1 must not be pref mmio */
+	pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
+	if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM1) {
+		ctrl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1;
+		pci_write_config_word(bridge, PCI_CB_BRIDGE_CONTROL, ctrl);
+		pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
+	}
+
 	/*
 	 * Check whether prefetchable memory is supported
 	 * by this bridge.
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (16 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-27 18:23   ` Jesse Barnes
  2012-01-21 10:08 ` [PATCH 19/21] PCI: Retry on type IORESOURCE_IO allocation Yinghai Lu
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

We should not set the requested size to -2.

that will confuse the resource list sorting with align when SIZEALIGN is used.

Change to STARTALIGN and pass align from start.

We are safe to do that just as we do that regular pci bridge.

In the long run, we should just treat cardbus like regular pci bridge.

Also fix when realloc is not passed, should keep the requested size.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   63 ++++++++++++++++++++++++++--------------------
 1 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index d5897c3..3b3932a 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -898,21 +898,30 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
 {
 	struct pci_dev *bridge = bus->self;
 	struct resource *b_res = &bridge->resource[PCI_BRIDGE_RESOURCES];
+	resource_size_t b_res_3_size = pci_cardbus_mem_size * 2;
 	u16 ctrl;
 
 	/*
 	 * Reserve some resources for CardBus.  We reserve
 	 * a fixed amount of bus space for CardBus bridges.
 	 */
-	b_res[0].start = 0;
-	b_res[0].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
-	if (realloc_head)
-		add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size, 0 /* dont care */);
+	b_res[0].start = pci_cardbus_io_size;
+	b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1;
+	b_res[0].flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
+	if (realloc_head) {
+		b_res[0].end -= pci_cardbus_io_size;
+		add_to_list(realloc_head, bridge, b_res, pci_cardbus_io_size,
+				pci_cardbus_io_size);
+	}
 
-	b_res[1].start = 0;
-	b_res[1].flags |= IORESOURCE_IO | IORESOURCE_SIZEALIGN;
-	if (realloc_head)
-		add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
+	b_res[1].start = pci_cardbus_io_size;
+	b_res[1].end = b_res[1].start + pci_cardbus_io_size - 1;
+	b_res[1].flags |= IORESOURCE_IO | IORESOURCE_STARTALIGN;
+	if (realloc_head) {
+		b_res[1].end -= pci_cardbus_io_size;
+		add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size,
+				 pci_cardbus_io_size);
+	}
 
 	/* MEM1 must not be pref mmio */
 	pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
@@ -939,28 +948,28 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
 	 * twice the size.
 	 */
 	if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) {
-		b_res[2].start = 0;
-		b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_SIZEALIGN;
-		if (realloc_head)
-			add_to_list(realloc_head, bridge, b_res+2, pci_cardbus_mem_size, 0 /* dont care */);
+		b_res[2].start = pci_cardbus_mem_size;
+		b_res[2].end = b_res[2].start + pci_cardbus_mem_size - 1;
+		b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH |
+				  IORESOURCE_STARTALIGN;
+		if (realloc_head) {
+			b_res[2].end -= pci_cardbus_mem_size;
+			add_to_list(realloc_head, bridge, b_res+2,
+				 pci_cardbus_mem_size, pci_cardbus_mem_size);
+		}
 
-		b_res[3].start = 0;
-		b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
-		if (realloc_head)
-			add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size, 0 /* dont care */);
-	} else {
-		b_res[3].start = 0;
-		b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_SIZEALIGN;
-		if (realloc_head)
-			add_to_list(realloc_head, bridge, b_res+3, pci_cardbus_mem_size * 2, 0 /* dont care */);
+		/* reduce that to half */
+		b_res_3_size = pci_cardbus_mem_size;
 	}
 
-	/* set the size of the resource to zero, so that the resource does not
-	 * get assigned during required-resource allocation cycle but gets assigned
-	 * during the optional-resource allocation cycle.
- 	 */
-	b_res[0].start = b_res[1].start = b_res[2].start = b_res[3].start = 1;
-	b_res[0].end = b_res[1].end = b_res[2].end = b_res[3].end = 0;
+	b_res[3].start = pci_cardbus_mem_size;
+	b_res[3].end = b_res[3].start + b_res_3_size - 1;
+	b_res[3].flags |= IORESOURCE_MEM | IORESOURCE_STARTALIGN;
+	if (realloc_head) {
+		b_res[3].end -= b_res_3_size;
+		add_to_list(realloc_head, bridge, b_res+3, b_res_3_size,
+				 pci_cardbus_mem_size);
+	}
 }
 
 void __ref __pci_bus_size_bridges(struct pci_bus *bus,
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 19/21] PCI: Retry on type IORESOURCE_IO allocation.
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (17 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 20/21] PCI: Make pci bridge reallocating enabled/disabled Yinghai Lu
  2012-01-21 10:08 ` [PATCH 21/21] PCI: only enable pci realloc when SRIOV bar is not assigned Yinghai Lu
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

During reenabling pci reallocating for pci bridge by clean the small size in
bridge and assign with requested + optional size for first several try,
Ram mention could have problem with one case
	https://bugzilla.kernel.org/show_bug.cgi?id=15960

After checking the booting log in
	https://lkml.org/lkml/2010/4/19/44
	[regression, bisected] Xonar DX invalid PCI I/O range since 977d17bb174

We should not stop too early for io ports.
	Apr 19 10:19:38 [kernel] pci 0000:04:00.0: BAR 7: can't assign io (size 0x4000)
	Apr 19 10:19:38 [kernel] pci 0000:05:01.0: BAR 8: assigned [mem 0x80400000-0x805fffff]
	Apr 19 10:19:38 [kernel] pci 0000:05:01.0: BAR 7: can't assign io (size 0x2000)
	Apr 19 10:19:38 [kernel] pci 0000:05:02.0: BAR 7: can't assign io (size 0x1000)
	Apr 19 10:19:38 [kernel] pci 0000:05:03.0: BAR 7: can't assign io (size 0x1000)
	Apr 19 10:19:38 [kernel] pci 0000:08:00.0: BAR 7: can't assign io (size 0x1000)
	Apr 19 10:19:38 [kernel] pci 0000:09:04.0: BAR 0: can't assign io (size 0x100)
and clear 00:1c.0 to retry again.

The patch remove the IORESOUCE_IO checking, and try one more time.
and we will have chance to get allocation for 00:1c.0 io port range because
from 0x4000 to 0x8000 could be used.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   12 +-----------
 1 files changed, 1 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 3b3932a..c22be02 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1278,7 +1278,6 @@ pci_assign_unassigned_resources(void)
 	struct pci_dev_resource *fail_res;
 	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
 				  IORESOURCE_PREFETCH;
-	unsigned long failed_type;
 	int pci_try_num = 1;
 
 	/* don't realloc if asked to do so */
@@ -1313,16 +1312,7 @@ again:
 	if (list_empty(&fail_head))
 		goto enable_and_dump;
 
-	failed_type = 0;
-	list_for_each_entry(fail_res, &fail_head, list)
-		failed_type |= fail_res->flags;
-
-	/*
-	 * io port are tight, don't try extra
-	 * or if reach the limit, don't want to try more
-	 */
-	failed_type &= type_mask;
-	if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) {
+	if (tried_times >= pci_try_num) {
 		free_list(&fail_head);
 		goto enable_and_dump;
 	}
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 20/21] PCI: Make pci bridge reallocating enabled/disabled
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (18 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 19/21] PCI: Retry on type IORESOURCE_IO allocation Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-21 10:08 ` [PATCH 21/21] PCI: only enable pci realloc when SRIOV bar is not assigned Yinghai Lu
  20 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

Let the user could enable and disable with pci=realloc=on or pci=realloc=off

Also
1. move variable and functions near the place they are used.
2. change macro to function
3. change related functions and variable to static and _init
4. update parameter description accordingly.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 Documentation/kernel-parameters.txt |    7 +++++--
 drivers/pci/pci.c                   |    4 ++--
 drivers/pci/pci.h                   |    2 +-
 drivers/pci/setup-bus.c             |   25 ++++++++++++++++++-------
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 81c287f..cd48b76 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2067,8 +2067,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 				the default.
 				off: Turn ECRC off
 				on: Turn ECRC on.
-		realloc		reallocate PCI resources if allocations done by BIOS
-				are erroneous.
+		realloc=	Enable/disable reallocating PCI bridge resources
+				if allocations done by BIOS are too small to fit
+				resources required by children devices.
+				off: Turn realloc off
+				on: Turn realloc on
 
 	pcie_aspm=	[PCIE] Forcibly enable or disable PCIe Active State Power
 			Management.
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6f45a73..2576940 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3564,8 +3564,8 @@ static int __init pci_setup(char *str)
 				pci_no_msi();
 			} else if (!strcmp(str, "noaer")) {
 				pci_no_aer();
-			} else if (!strncmp(str, "realloc", 7)) {
-				pci_realloc();
+			} else if (!strncmp(str, "realloc=", 8)) {
+				pci_realloc_get_opt(str + 8);
 			} else if (!strcmp(str, "nodomains")) {
 				pci_no_domains();
 			} else if (!strncmp(str, "cbiosize=", 9)) {
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index b74084e..2f87579 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -146,7 +146,7 @@ static inline void pci_no_msi(void) { }
 static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { }
 #endif
 
-extern void pci_realloc(void);
+void pci_realloc_get_opt(char *);
 
 static inline int pci_no_d1d2(struct pci_dev *dev)
 {
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c22be02..1c97e14 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -48,13 +48,6 @@ static void free_list(struct list_head *head)
 	}
 }
 
-int pci_realloc_enable = 0;
-#define pci_realloc_enabled() pci_realloc_enable
-void pci_realloc(void)
-{
-	pci_realloc_enable = 1;
-}
-
 /**
  * add_to_list() - add a new resource tracker to the list
  * @head:	Head of the list
@@ -1259,6 +1252,24 @@ static int __init pci_get_max_depth(void)
 	return depth;
 }
 
+/*
+ * -1: undefined, will auto detect later
+ *  0: disabled by user
+ *  1: enabled by user
+ *  2: enabled by auto detect
+ */
+static int pci_realloc_enable __initdata = -1;
+void __init pci_realloc_get_opt(char *str)
+{
+	if (!strncmp(str, "off", 3))
+		pci_realloc_enable = 0;
+	else if (!strncmp(str, "on", 2))
+		pci_realloc_enable = 1;
+}
+static bool __init pci_realloc_enabled(void)
+{
+	return pci_realloc_enable > 0;
+}
 
 /*
  * first try will not touch pci bridge res
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 21/21] PCI: only enable pci realloc when SRIOV bar is not assigned
  2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
                   ` (19 preceding siblings ...)
  2012-01-21 10:08 ` [PATCH 20/21] PCI: Make pci bridge reallocating enabled/disabled Yinghai Lu
@ 2012-01-21 10:08 ` Yinghai Lu
  2012-01-27 18:25   ` Jesse Barnes
  20 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-01-21 10:08 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Yinghai Lu

If bios does not assign those BAR or wrong address, then kernel will
try to do pci realloc.

in that case, user still can use pci=realloc=off to override it.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/setup-bus.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 1c97e14..3070e1b 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1271,6 +1271,31 @@ static bool __init pci_realloc_enabled(void)
 	return pci_realloc_enable > 0;
 }
 
+static void __init pci_realloc_detect(void)
+{
+	struct pci_dev *dev = NULL;
+
+	if (pci_realloc_enable != -1)
+		return;
+
+#ifdef CONFIG_PCI_IOV
+	for_each_pci_dev(dev) {
+		int i;
+
+		for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) {
+			struct resource *r = &dev->resource[i];
+
+			/* Not assigned, or rejected by kernel */
+			if (r->flags && !r->start) {
+				pci_realloc_enable = 2;
+
+				return;
+			}
+		}
+	}
+#endif
+}
+
 /*
  * first try will not touch pci bridge res
  * second  and later try will clear small leaf bridge res
@@ -1292,6 +1317,7 @@ pci_assign_unassigned_resources(void)
 	int pci_try_num = 1;
 
 	/* don't realloc if asked to do so */
+	pci_realloc_detect();
 	if (pci_realloc_enabled()) {
 		int max_depth = pci_get_max_depth();
 
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH 01/21] PCI : Calculate right add_size
  2012-01-21 10:08 ` [PATCH 01/21] PCI : Calculate right add_size Yinghai Lu
@ 2012-01-27 17:55   ` Jesse Barnes
  0 siblings, 0 replies; 34+ messages in thread
From: Jesse Barnes @ 2012-01-27 17:55 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 344 bytes --]

On Sat, 21 Jan 2012 02:08:17 -0800
Yinghai Lu <yinghai@kernel.org> wrote:

> During debug one SRIOV enabled hotplug, found add_size is not passed properly.
> 
> the device have devices under two level bridges..
> 

Ok applied 1-5 so far, looking through the rest now.

Thanks,
-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 06/21] PCI: Make rescan bus could increase bridge resource size if needed
  2012-01-21 10:08 ` [PATCH 06/21] PCI: Make rescan bus could increase bridge resource size if needed Yinghai Lu
@ 2012-01-27 18:00   ` Jesse Barnes
  0 siblings, 0 replies; 34+ messages in thread
From: Jesse Barnes @ 2012-01-27 18:00 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 608 bytes --]

On Sat, 21 Jan 2012 02:08:22 -0800
Yinghai Lu <yinghai@kernel.org> wrote:

> Current rescan will not touch bridge MMIO and IO.
> 
> Try to reuse pci_assign_unassigned_bridge_resources(bridge) to update bridge
> resource, if child devices need more resource.
> 
> only do that for bridges that all children get removed before. So do not
> release resources that could already be used by drivers of child devices.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---

Applied, but I fixed up the comment; please check for accuracy.

-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 16/21] PCI: remove add_to_failed_list()
  2012-01-21 10:08 ` [PATCH 16/21] PCI: remove add_to_failed_list() Yinghai Lu
@ 2012-01-27 18:21   ` Jesse Barnes
  0 siblings, 0 replies; 34+ messages in thread
From: Jesse Barnes @ 2012-01-27 18:21 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 281 bytes --]

On Sat, 21 Jan 2012 02:08:32 -0800
Yinghai Lu <yinghai@kernel.org> wrote:

> only one user, just use add_to_list instead.

Ok applied up to patch 16, thanks a lot for the cleanups.  See my
replies on the later ones.

-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL
  2012-01-21 10:08 ` [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL Yinghai Lu
@ 2012-01-27 18:22   ` Jesse Barnes
  2012-01-27 18:39     ` Yinghai Lu
  0 siblings, 1 reply; 34+ messages in thread
From: Jesse Barnes @ 2012-01-27 18:22 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1358 bytes --]

On Sat, 21 Jan 2012 02:08:33 -0800
Yinghai Lu <yinghai@kernel.org> wrote:

> Some BIOS enable both pref for MEM0 and MEM1.
> 
> but we assume MEM1 is non-pref...
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/setup-bus.c |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index 090217a..d5897c3 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -914,6 +914,14 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
>  	if (realloc_head)
>  		add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
>  
> +	/* MEM1 must not be pref mmio */
> +	pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
> +	if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM1) {
> +		ctrl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1;
> +		pci_write_config_word(bridge, PCI_CB_BRIDGE_CONTROL, ctrl);
> +		pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
> +	}
> +
>  	/*
>  	 * Check whether prefetchable memory is supported
>  	 * by this bridge.

Is there an actual bug report for this one where prefetchable regions
are causing trouble?  I can see that they would I just wonder if this
bug is hidden by some other...

-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling
  2012-01-21 10:08 ` [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling Yinghai Lu
@ 2012-01-27 18:23   ` Jesse Barnes
  2012-01-27 21:37     ` Yinghai Lu
  0 siblings, 1 reply; 34+ messages in thread
From: Jesse Barnes @ 2012-01-27 18:23 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel, Dominik Brodowski

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

On Sat, 21 Jan 2012 02:08:34 -0800
Yinghai Lu <yinghai@kernel.org> wrote:

> We should not set the requested size to -2.
> 
> that will confuse the resource list sorting with align when SIZEALIGN is used.
> 
> Change to STARTALIGN and pass align from start.
> 
> We are safe to do that just as we do that regular pci bridge.
> 
> In the long run, we should just treat cardbus like regular pci bridge.
> 
> Also fix when realloc is not passed, should keep the requested size.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>

I'd like to see some testing on this one... Dominik?

-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 21/21] PCI: only enable pci realloc when SRIOV bar is not assigned
  2012-01-21 10:08 ` [PATCH 21/21] PCI: only enable pci realloc when SRIOV bar is not assigned Yinghai Lu
@ 2012-01-27 18:25   ` Jesse Barnes
  0 siblings, 0 replies; 34+ messages in thread
From: Jesse Barnes @ 2012-01-27 18:25 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 844 bytes --]

On Sat, 21 Jan 2012 02:08:37 -0800
Yinghai Lu <yinghai@kernel.org> wrote:

> If bios does not assign those BAR or wrong address, then kernel will
> try to do pci realloc.
> 
> in that case, user still can use pci=realloc=off to override it.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/setup-bus.c |   26 ++++++++++++++++++++++++++
>  1 files changed, 26 insertions(+), 0 deletions(-)
> 

I worry about this one; distros may enable IOV to keep a unified kernel
binary and end up messing up all sorts of systems that happen to have
IOV devices that the user doesn't actually care about.

I'd prefer to leave it disabled by default, and let drivers spew a
message about IOV resources being unavailable and mentioning the
realloc= param...

-- 
Jesse Barnes, Intel Open Source Technology Center

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL
  2012-01-27 18:22   ` Jesse Barnes
@ 2012-01-27 18:39     ` Yinghai Lu
  0 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-01-27 18:39 UTC (permalink / raw)
  To: Jesse Barnes; +Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel

On Fri, Jan 27, 2012 at 10:22 AM, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> On Sat, 21 Jan 2012 02:08:33 -0800
> Yinghai Lu <yinghai@kernel.org> wrote:
>
>> Some BIOS enable both pref for MEM0 and MEM1.
>>
>> but we assume MEM1 is non-pref...
>>
>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>> ---
>>  drivers/pci/setup-bus.c |    8 ++++++++
>>  1 files changed, 8 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
>> index 090217a..d5897c3 100644
>> --- a/drivers/pci/setup-bus.c
>> +++ b/drivers/pci/setup-bus.c
>> @@ -914,6 +914,14 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
>>       if (realloc_head)
>>               add_to_list(realloc_head, bridge, b_res+1, pci_cardbus_io_size, 0 /* dont care */);
>>
>> +     /* MEM1 must not be pref mmio */
>> +     pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
>> +     if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM1) {
>> +             ctrl &= ~PCI_CB_BRIDGE_CTL_PREFETCH_MEM1;
>> +             pci_write_config_word(bridge, PCI_CB_BRIDGE_CONTROL, ctrl);
>> +             pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl);
>> +     }
>> +
>>       /*
>>        * Check whether prefetchable memory is supported
>>        * by this bridge.
>
> Is there an actual bug report for this one where prefetchable regions
> are causing trouble?  I can see that they would I just wonder if this
> bug is hidden by some other...

Yes, it should be hidden  by some others.

Yinghai

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling
  2012-01-27 18:23   ` Jesse Barnes
@ 2012-01-27 21:37     ` Yinghai Lu
  2012-02-05 21:58       ` Dominik Brodowski
  0 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-01-27 21:37 UTC (permalink / raw)
  To: Jesse Barnes, Dominik Brodowski
  Cc: Ram Pai, Linus Torvalds, linux-pci, linux-kernel

On Fri, Jan 27, 2012 at 10:23 AM, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> On Sat, 21 Jan 2012 02:08:34 -0800
> Yinghai Lu <yinghai@kernel.org> wrote:
>
>> We should not set the requested size to -2.
>>
>> that will confuse the resource list sorting with align when SIZEALIGN is used.
>>
>> Change to STARTALIGN and pass align from start.
>>
>> We are safe to do that just as we do that regular pci bridge.
>>
>> In the long run, we should just treat cardbus like regular pci bridge.
>>
>> Also fix when realloc is not passed, should keep the requested size.
>>
>> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>
> I'd like to see some testing on this one... Dominik?

Dominik,

Can you please test branch at

	git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
for-pci2

Thanks

Yinghai

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling
  2012-01-27 21:37     ` Yinghai Lu
@ 2012-02-05 21:58       ` Dominik Brodowski
  2012-02-05 23:30         ` Yinghai Lu
  0 siblings, 1 reply; 34+ messages in thread
From: Dominik Brodowski @ 2012-02-05 21:58 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Jesse Barnes, Ram Pai, Linus Torvalds, linux-pci, linux-kernel

On Fri, Jan 27, 2012 at 01:37:44PM -0800, Yinghai Lu wrote:
> On Fri, Jan 27, 2012 at 10:23 AM, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> > On Sat, 21 Jan 2012 02:08:34 -0800
> > Yinghai Lu <yinghai@kernel.org> wrote:
> >
> >> We should not set the requested size to -2.
> >>
> >> that will confuse the resource list sorting with align when SIZEALIGN is used.
> >>
> >> Change to STARTALIGN and pass align from start.
> >>
> >> We are safe to do that just as we do that regular pci bridge.
> >>
> >> In the long run, we should just treat cardbus like regular pci bridge.
> >>
> >> Also fix when realloc is not passed, should keep the requested size.
> >>
> >> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> >
> > I'd like to see some testing on this one... Dominik?
> 
> Dominik,
> 
> Can you please test branch at
> 
> 	git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
> for-pci2

Tested this on my limited test systems (COUNT=1), and seems to work fine.

Best,
	Dominik

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling
  2012-02-05 21:58       ` Dominik Brodowski
@ 2012-02-05 23:30         ` Yinghai Lu
  2012-02-10 15:35           ` Dominik Brodowski
  0 siblings, 1 reply; 34+ messages in thread
From: Yinghai Lu @ 2012-02-05 23:30 UTC (permalink / raw)
  To: Dominik Brodowski, Yinghai Lu, Jesse Barnes, Ram Pai,
	Linus Torvalds, linux-pci, linux-kernel

On Sun, Feb 5, 2012 at 1:58 PM, Dominik Brodowski
<linux@dominikbrodowski.net> wrote:
> On Fri, Jan 27, 2012 at 01:37:44PM -0800, Yinghai Lu wrote:
>> On Fri, Jan 27, 2012 at 10:23 AM, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
>> > On Sat, 21 Jan 2012 02:08:34 -0800
>> > Yinghai Lu <yinghai@kernel.org> wrote:
>> >
>> >> We should not set the requested size to -2.
>> >>
>> >> that will confuse the resource list sorting with align when SIZEALIGN is used.
>> >>
>> >> Change to STARTALIGN and pass align from start.
>> >>
>> >> We are safe to do that just as we do that regular pci bridge.
>> >>
>> >> In the long run, we should just treat cardbus like regular pci bridge.
>> >>
>> >> Also fix when realloc is not passed, should keep the requested size.
>> >>
>> >> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
>> >
>> > I'd like to see some testing on this one... Dominik?
>>
>> Dominik,
>>
>> Can you please test branch at
>>
>>       git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
>> for-pci2
>
> Tested this on my limited test systems (COUNT=1), and seems to work fine.
>

Thanks a lot.

Thought that you should have bunch of systems (laptop) with pci cardbus slots.

Found another regression by one commit already got into linus' tree.

and should be fixed by

[PATCH] pci: Fix pci cardbus removal

http://git.kernel.org/?p=linux/kernel/git/yinghai/linux-yinghai.git;a=patch;h=29834f2faeed3cb87dea984a3d411337752e6b7c

please double check

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci3

or

git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
for-pci-busn-alloc

Yinghai

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling
  2012-02-05 23:30         ` Yinghai Lu
@ 2012-02-10 15:35           ` Dominik Brodowski
  2012-02-10 17:07             ` Yinghai Lu
  0 siblings, 1 reply; 34+ messages in thread
From: Dominik Brodowski @ 2012-02-10 15:35 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Jesse Barnes, Ram Pai, Linus Torvalds, linux-pci, linux-kernel

On Sun, Feb 05, 2012 at 03:30:09PM -0800, Yinghai Lu wrote:
> On Sun, Feb 5, 2012 at 1:58 PM, Dominik Brodowski
> <linux@dominikbrodowski.net> wrote:
> > On Fri, Jan 27, 2012 at 01:37:44PM -0800, Yinghai Lu wrote:
> >> On Fri, Jan 27, 2012 at 10:23 AM, Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
> >> > On Sat, 21 Jan 2012 02:08:34 -0800
> >> > Yinghai Lu <yinghai@kernel.org> wrote:
> >> >
> >> >> We should not set the requested size to -2.
> >> >>
> >> >> that will confuse the resource list sorting with align when SIZEALIGN is used.
> >> >>
> >> >> Change to STARTALIGN and pass align from start.
> >> >>
> >> >> We are safe to do that just as we do that regular pci bridge.
> >> >>
> >> >> In the long run, we should just treat cardbus like regular pci bridge.
> >> >>
> >> >> Also fix when realloc is not passed, should keep the requested size.
> >> >>
> >> >> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> >> >
> >> > I'd like to see some testing on this one... Dominik?
> >>
> >> Dominik,
> >>
> >> Can you please test branch at
> >>
> >>       git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
> >> for-pci2
> >
> > Tested this on my limited test systems (COUNT=1), and seems to work fine.
> >
> 
> Thanks a lot.
> 
> Thought that you should have bunch of systems (laptop) with pci cardbus
> slots.
> 
> Found another regression by one commit already got into linus' tree.
> 
> and should be fixed by
> 
> [PATCH] pci: Fix pci cardbus removal
> 
> http://git.kernel.org/?p=linux/kernel/git/yinghai/linux-yinghai.git;a=patch;h=29834f2faeed3cb87dea984a3d411337752e6b7c
> 
> please double check
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci3
> 
> or
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
> for-pci-busn-alloc

I pulled both trees, and things still work fine on my test system.

Best,
	Dominik

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling
  2012-02-10 15:35           ` Dominik Brodowski
@ 2012-02-10 17:07             ` Yinghai Lu
  0 siblings, 0 replies; 34+ messages in thread
From: Yinghai Lu @ 2012-02-10 17:07 UTC (permalink / raw)
  To: Dominik Brodowski, Yinghai Lu, Jesse Barnes, Ram Pai,
	Linus Torvalds, linux-pci, linux-kernel

On Fri, Feb 10, 2012 at 7:35 AM, Dominik Brodowski
<linux@dominikbrodowski.net> wrote:

>> Found another regression by one commit already got into linus' tree.
>>
>> and should be fixed by
>>
>> [PATCH] pci: Fix pci cardbus removal
>>
>> http://git.kernel.org/?p=linux/kernel/git/yinghai/linux-yinghai.git;a=patch;h=29834f2faeed3cb87dea984a3d411337752e6b7c
>>
>> please double check
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci3
>>
>> or
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git
>> for-pci-busn-alloc
>
> I pulled both trees, and things still work fine on my test system.

thanks a lot

Yinghai

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2012-02-10 17:07 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-21 10:08 [PATCH 00/21] PCI : bridge resource reallocation patchset Yinghai Lu
2012-01-21 10:08 ` [PATCH 01/21] PCI : Calculate right add_size Yinghai Lu
2012-01-27 17:55   ` Jesse Barnes
2012-01-21 10:08 ` [PATCH 02/21] PCI: Make add_to_list() return status Yinghai Lu
2012-01-21 10:08 ` [PATCH 03/21] PCI: Move get_res_add_size() early Yinghai Lu
2012-01-21 10:08 ` [PATCH 04/21] PCI: Try to assign required+option size at first Yinghai Lu
2012-01-21 10:08 ` [PATCH 05/21] PCI: Using add_list in pcie hotplug path Yinghai Lu
2012-01-21 10:08 ` [PATCH 06/21] PCI: Make rescan bus could increase bridge resource size if needed Yinghai Lu
2012-01-27 18:00   ` Jesse Barnes
2012-01-21 10:08 ` [PATCH 07/21] PCI: Make pci_rescan_bus handle add_list Yinghai Lu
2012-01-21 10:08 ` [PATCH 08/21] PCI: Fixing multiple retrying with pci resource optional resources allocation under multi bridges Yinghai Lu
2012-01-21 10:08 ` [PATCH 09/21] PCI: Move pdev_sort_resources() to setup-bus.c Yinghai Lu
2012-01-21 10:08 ` [PATCH 10/21] PCI: Move struct resource_list " Yinghai Lu
2012-01-21 10:08 ` [PATCH 11/21] PCI: Replace resource_list with generic list Yinghai Lu
2012-01-21 10:08 ` [PATCH 12/21] PCI: Merge pci_dev_resource_x and pci_dev_resource Yinghai Lu
2012-01-21 10:08 ` [PATCH 13/21] PCI: Rename dev_res_x to add_res or fail_res Yinghai Lu
2012-01-21 10:08 ` [PATCH 14/21] PCI: Change free_list() to function Yinghai Lu
2012-01-21 10:08 ` [PATCH 15/21] PCI: add debug print out for add_size Yinghai Lu
2012-01-21 10:08 ` [PATCH 16/21] PCI: remove add_to_failed_list() Yinghai Lu
2012-01-27 18:21   ` Jesse Barnes
2012-01-21 10:08 ` [PATCH 17/21] PCI: Disable cardbus bridge MEM1 pref CTL Yinghai Lu
2012-01-27 18:22   ` Jesse Barnes
2012-01-27 18:39     ` Yinghai Lu
2012-01-21 10:08 ` [PATCH 18/21] PCI: Fix cardbus bridge resources as optional size handling Yinghai Lu
2012-01-27 18:23   ` Jesse Barnes
2012-01-27 21:37     ` Yinghai Lu
2012-02-05 21:58       ` Dominik Brodowski
2012-02-05 23:30         ` Yinghai Lu
2012-02-10 15:35           ` Dominik Brodowski
2012-02-10 17:07             ` Yinghai Lu
2012-01-21 10:08 ` [PATCH 19/21] PCI: Retry on type IORESOURCE_IO allocation Yinghai Lu
2012-01-21 10:08 ` [PATCH 20/21] PCI: Make pci bridge reallocating enabled/disabled Yinghai Lu
2012-01-21 10:08 ` [PATCH 21/21] PCI: only enable pci realloc when SRIOV bar is not assigned Yinghai Lu
2012-01-27 18:25   ` Jesse Barnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).