Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1210924 > unrolled thread
| Started by | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| First post | 2015-08-21 08:40 +0200 |
| Last post | 2015-08-21 09:30 +0200 |
| Articles | 19 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v4 00/52] PCI: Resource allocation cleanup for v4.3 Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 23/52] PCI: Add support for more than two alt_size under same bridge Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 09/52] PCI: Rename pdev_sort_resources() to pdev_assign_resources_prepare() Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 18/52] PCI: Move comment to pci_need_to_release() Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 04/52] PCI: Optimize bus min_align/size calculation during sizing Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 27/52] PCI: Move ISA io port align out of calculate_iosize() Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 08/52] PCI: Remove duplicated code for resource sorting Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 05/52] PCI: Optimize bus align/size calculation for optional during sizing Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 36/52] PCI: Only treat non-pref mmio64 as pref if all bridges have MEM_64 Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 43/52] OF/PCI: Add IORESOURCE_MEM_64 for 64-bit resource Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
Re: [PATCH v4 43/52] OF/PCI: Add IORESOURCE_MEM_64 for 64-bit resource Rob Herring <robherring2@gmail.com> - 2015-08-21 20:20 +0200
Re: [PATCH v4 43/52] OF/PCI: Add IORESOURCE_MEM_64 for 64-bit resource Yinghai Lu <yinghai@kernel.org> - 2015-08-21 20:30 +0200
[PATCH v4 15/52] PCI: Cache window alignment value during bus sizing Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 01/52] PCI: Cleanup res_to_dev_res() printout Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 32/52] PCI: Kill macro checking for bus io port sizing Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 21/52] PCI: Move saved required resource list out of required+optional assigning Yinghai Lu <yinghai@kernel.org> - 2015-08-21 08:40 +0200
[PATCH v4 22/52] PCI: Add alt_size ressource allocation support Yinghai Lu <yinghai@kernel.org> - 2015-08-21 09:30 +0200
[PATCH v4 44/52] PCI: Treat optional as required in first try for bridge rescan Yinghai Lu <yinghai@kernel.org> - 2015-08-21 09:30 +0200
[PATCH v4 29/52] PCI: Unify calculate_size() for io port and MMIO Yinghai Lu <yinghai@kernel.org> - 2015-08-21 09:30 +0200
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 00/52] PCI: Resource allocation cleanup for v4.3 |
| Message-ID | <pZNZT-3SZ-3@gated-at.bofh.it> |
Hi,
After 5b28541552ef (PCI: Restrict 64-bit prefetchable bridge windows
to 64-bit resources), we have several reports on resource allocation
failure, and we try to fix the problem with resource clip, and get
more problems.
One is realloc fail with two graphics cards above 4G.
One is from sparc that have problem with clip as we don't parse
mem64 for it.
Other report is about pci remove/rescan does not work on some setup
when BIOS tend to allocate small bus size.
This patchset enhance resource allocation to address those problems.
1. optimize bus mmio alignment calculation.
2. optimize bus mmio optional alignment calculation.
3. add support for alt size to prefer small bus size to small bus alignment.
when we have small resource window on parent bridges.
4. treat ROM bar as optional resource.
5. during allocation, will pick up just fit resource.
6. parse MEM64 for sparc and other system with OF.
7. treat non-pref mmio64 if parent bridges are all pcie.
8. restore old pref allocation logic if hostbridge does not support mmio64 really.
9. don't realloc resource if device firmware does not support bar change.
10. add pci=assign_pref_bars to clear and assign pref bars.
11. don't clear resource when allocation fails.
I put latest copy at:
git://git.kernel.org/pub/scm/linux/kernel/git/yinghai/linux-yinghai.git for-pci-v4.3-next
That is based on kind of v4.2-rc7.
Yijing and Wei Yang both test the branch, and the patchset fixs rescan problem,
and is working well on powerpc setup.
Thanks
Yinghai
v2:
- fix resource_disabled allocation from powerpc
- other warnings that were found by Fengguang's build robot.
- io port alignment clean up.
- rebased to v4.2-rc2
- better for two alt_size support.
v3:
- fix reset bridge resource on last try: only with bridge resources
- remove/rescan path checking with old_size.
v4:
- Update changelog according to Bjorn.
- split calculate_size patch to two.
- use required instead of must.
Yinghai Lu (52):
PCI: Cleanup res_to_dev_res() printout
PCI: Reuse res_to_dev_res() in reassign_resources_sorted()
PCI: Use correct align for optional only resources during sorting
PCI: Optimize bus min_align/size calculation during sizing
PCI: Optimize bus align/size calculation for optional during sizing
PCI: Don't add too much optional size for hotplug bridge MMIO
PCI: Reorder resources list for required/optional resources
PCI: Remove duplicated code for resource sorting
PCI: Rename pdev_sort_resources() to pdev_assign_resources_prepare()
PCI: Treat ROM resource as optional during realloc
PCI: Add debug printout during releasing partial assigned resources
PCI: Simplify res reference using in __assign_resources_sorted()
PCI, acpiphp: Add missing realloc list checking after resource allocation
PCI: Add __add_to_list()
PCI: Cache window alignment value during bus sizing
PCI: Check if resource is allocated before trying to assign one
PCI: Separate out save_resources()/restore_resources()
PCI: Move comment to pci_need_to_release()
PCI: Separate required+optional assigning to another function
PCI: Skip required+optional if there is no optional
PCI: Move saved required resource list out of required+optional assigning
PCI: Add alt_size ressource allocation support
PCI: Add support for more than two alt_size under same bridge
PCI: Better support for two alt_size
PCI: Fix size calculation with old_size on rescan path
PCI: Don't add too much optional size for hotplug bridge io
PCI: Move ISA io port align out of calculate_iosize()
PCI: Don't add too much io port for hotplug bridge with old size
PCI: Unify calculate_size() for io port and MMIO
PCI: Allow bridge optional only io port resource required size to be 0
PCI: Unify skip_ioresource_align()
PCI: Kill macro checking for bus io port sizing
resources: Split out __allocate_resource()
resources: Make allocate_resource() return best fit resource
PCI: Check pref compatible bit for mem64 resource of PCIe device
PCI: Only treat non-pref mmio64 as pref if all bridges have MEM_64
PCI: Add has_mem64 for struct host_bridge
PCI: Only treat non-pref mmio64 as pref if host bridge has mmio64
PCI: Restore pref MMIO allocation logic for host bridge without mmio64
sparc/PCI: Add mem64 resource parsing for root bus
sparc/PCI: Add IORESOURCE_MEM_64 for 64-bit resource in OF parsing
powerpc/PCI: Add IORESOURCE_MEM_64 for 64-bit resource in OF parsing
OF/PCI: Add IORESOURCE_MEM_64 for 64-bit resource
PCI: Treat optional as required in first try for bridge rescan
PCI: Get new realloc size for bridge for last try
PCI: Don't release sibling bridge resources during hotplug
PCI: Don't release fixed resource for realloc
PCI: Claim fixed resource during remove/rescan path
PCI: Set resource to FIXED for LSI devices
PCI, x86: Add pci=assign_pref_bars to reallocate pref BARs
PCI: Introduce resource_disabled()
PCI: Don't set flags to 0 when assign resource fail
arch/alpha/kernel/pci.c | 2 +-
arch/ia64/pci/pci.c | 4 +-
arch/microblaze/pci/pci-common.c | 23 +-
arch/mn10300/unit-asb2305/pci-asb2305.c | 4 +-
arch/mn10300/unit-asb2305/pci.c | 4 +-
arch/powerpc/kernel/pci-common.c | 27 +-
arch/powerpc/kernel/pci_of_scan.c | 4 +-
arch/powerpc/platforms/powernv/pci-ioda.c | 12 +-
arch/s390/pci/pci.c | 2 +-
arch/sparc/kernel/of_device_32.c | 5 +-
arch/sparc/kernel/of_device_64.c | 5 +-
arch/sparc/kernel/pci.c | 9 +-
arch/sparc/kernel/pci_common.c | 15 +-
arch/sparc/kernel/pci_impl.h | 1 +
arch/x86/include/asm/pci_x86.h | 2 +-
arch/x86/pci/common.c | 7 +-
arch/x86/pci/i386.c | 72 +-
arch/xtensa/kernel/pci.c | 4 +-
drivers/iommu/intel-iommu.c | 3 +-
drivers/of/address.c | 4 +-
drivers/pci/bus.c | 6 +-
drivers/pci/host/pcie-rcar.c | 2 +-
drivers/pci/hotplug/acpiphp_glue.c | 1 +
drivers/pci/iov.c | 2 +-
drivers/pci/pci.c | 3 +-
drivers/pci/pci.h | 3 +
drivers/pci/probe.c | 44 +-
drivers/pci/quirks.c | 37 +
drivers/pci/rom.c | 2 +-
drivers/pci/setup-bus.c | 1311 +++++++++++++++++++++--------
drivers/pci/setup-res.c | 18 +-
include/asm-generic/pci-bridge.h | 2 +
include/linux/ioport.h | 6 +-
include/linux/pci.h | 2 +
kernel/resource.c | 175 +++-
35 files changed, 1352 insertions(+), 471 deletions(-)
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 23/52] PCI: Add support for more than two alt_size under same bridge |
| Message-ID | <pZO9A-44i-9@gated-at.bofh.it> |
| In reply to | #1210924 |
When we have two bridges under same parent bridge, and each child
bridge has alt_size, we need to increase parent alt_size to make
sure it could fit all alt entries.
In the patch, we first select one big size, and then keep reducing
the size and retrying to get the minimum value for alt_size.
Example:
two bridges: one have 8M/8M, and 1M/1M children res.
one have 4M/4M, and 1M/1M children res.
Then we have child pridges alt_align/alt_size: 8M/9M, 4M/5M.
Before this patch, parent bridge alt_align/alt_size is 8M/14M
that is wrong.
With this patch parent bridge alt_align/alt_size: 8M/17M.
At same time, child bridges required align/size: 4M/12M, 2M/6M.
and prarent bridge required align/size: 4M/20M.
So at last, we use 8M/17M as parent bridge alt_align/alt_size.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=100451
Reported-by: Yijing Wang <wangyijing@huawei.com>
Tested-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 8be5544..baf9900 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1329,6 +1329,47 @@ out:
return good_align;
}
+static resource_size_t calculate_mem_alt_size(struct list_head *head,
+ resource_size_t max_align, resource_size_t size,
+ resource_size_t align_low)
+{
+ struct align_test_res *p;
+ resource_size_t tmp;
+ resource_size_t good_size, bad_size;
+ int count = 0, order;
+
+ good_size = ALIGN(size, align_low);
+
+ list_for_each_entry(p, head, list)
+ count++;
+
+ if (count <= 1)
+ goto out;
+
+ sort_align_test(head);
+
+ tmp = max(size, max_align);
+ order = __fls(count);
+ if ((1ULL << order) < count)
+ order++;
+ good_size = ALIGN((tmp << order), align_low);
+ bad_size = ALIGN(size, align_low) - align_low;
+ size = good_size;
+ while (size > bad_size) {
+ /* check if align/size fit all entries */
+ if (is_align_size_good(head, max_align, size, 0))
+ good_size = size;
+ else
+ bad_size = size;
+
+ size = bad_size + ((good_size - bad_size) >> 1);
+ size = round_down(size, align_low);
+ }
+
+out:
+ return good_size;
+}
+
static inline bool is_optional(int i)
{
@@ -1375,6 +1416,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
mask | IORESOURCE_PREFETCH, type);
LIST_HEAD(align_test_list);
LIST_HEAD(align_test_add_list);
+ LIST_HEAD(align_test_alt_list);
resource_size_t alt_size = 0, alt_align = 0;
resource_size_t window_align;
@@ -1448,10 +1490,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
dev_res = res_to_dev_res(realloc_head, r);
if (dev_res && dev_res->alt_size) {
+ add_to_align_test_list(
+ &align_test_alt_list,
+ dev_res->alt_align,
+ dev_res->alt_size);
alt_size += dev_res->alt_size;
if (alt_align < dev_res->alt_align)
alt_align = dev_res->alt_align;
} else if (r_size > 1) {
+ add_to_align_test_list(
+ &align_test_alt_list,
+ align, r_size);
alt_size += r_size;
if (alt_align < align)
alt_align = align;
@@ -1471,14 +1520,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
if (size0 && realloc_head) {
alt_align = max(alt_align, window_align);
- alt_size = calculate_memsize(alt_size, min_size,
- 0, window_align);
+ /* need to increase size to fit more alt */
+ alt_size = calculate_mem_alt_size(&align_test_alt_list,
+ alt_align, alt_size,
+ window_align);
/* required is better ? */
if (alt_size >= size0) {
alt_align = 0;
alt_size = 0;
}
}
+ free_align_test_list(&align_test_alt_list);
if (sum_add_size < min_sum_size)
sum_add_size = min_sum_size;
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 09/52] PCI: Rename pdev_sort_resources() to pdev_assign_resources_prepare() |
| Message-ID | <pZO9A-44i-11@gated-at.bofh.it> |
| In reply to | #1210924 |
pdev_sort_resources() etc was used to check devices resources and put
resources that need to assign to one list in sorted order.
We don't do sorting in those functions anymore, so change to
__assign_resources_prepare() instead.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 44d63c0..1fd0b8d 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -205,8 +205,8 @@ static resource_size_t __pci_resource_alignment(
return r_align;
}
-/* Sort resources by alignment */
-static void pdev_sort_resources(struct pci_dev *dev,
+/* check resources and save to the list */
+static void pdev_assign_resources_prepare(struct pci_dev *dev,
struct list_head *realloc_head,
struct list_head *head)
{
@@ -242,7 +242,7 @@ static void pdev_sort_resources(struct pci_dev *dev,
}
}
-static void __dev_sort_resources(struct pci_dev *dev,
+static void __dev_assign_resources_prepare(struct pci_dev *dev,
struct list_head *realloc_head,
struct list_head *head)
{
@@ -260,7 +260,7 @@ static void __dev_sort_resources(struct pci_dev *dev,
return;
}
- pdev_sort_resources(dev, realloc_head, head);
+ pdev_assign_resources_prepare(dev, realloc_head, head);
}
static inline void reset_resource(struct resource *res)
@@ -560,7 +560,7 @@ static void pdev_assign_resources_sorted(struct pci_dev *dev,
{
LIST_HEAD(head);
- __dev_sort_resources(dev, add_head, &head);
+ __dev_assign_resources_prepare(dev, add_head, &head);
__assign_resources_sorted(&head, add_head, fail_head);
}
@@ -573,7 +573,7 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus,
LIST_HEAD(head);
list_for_each_entry(dev, &bus->devices, bus_list)
- __dev_sort_resources(dev, realloc_head, &head);
+ __dev_assign_resources_prepare(dev, realloc_head, &head);
__assign_resources_sorted(&head, realloc_head, fail_head);
}
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 18/52] PCI: Move comment to pci_need_to_release() |
| Message-ID | <pZO9A-44i-21@gated-at.bofh.it> |
| In reply to | #1210924 |
Move comment from caller to pci_need_to_release(), as we will have one new
caller for alt_size support.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 4a1fb4f..e4b4b55 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -409,6 +409,20 @@ static unsigned long pci_fail_res_type_mask(struct list_head *fail_head)
static bool pci_need_to_release(unsigned long mask, struct resource *res)
{
+ /*
+ * Separate three resource type checking if we need to release
+ * assigned resource.
+ * 1. if there is io port assign fail, will release assigned
+ * io port.
+ * 2. if there is pref mmio assign fail, release assigned
+ * pref mmio.
+ * if assigned pref mmio's parent is non-pref mmio and there
+ * is non-pref mmio assign fail, will release that assigned
+ * pref mmio.
+ * 3. if there is non-pref mmio assign fail or pref mmio
+ * assigned fail, will release assigned non-pref mmio.
+ */
+
if (res->flags & IORESOURCE_IO)
return !!(mask & IORESOURCE_IO);
@@ -465,19 +479,8 @@ static void __assign_resources_sorted(struct list_head *head,
* 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.
- *
- * Separate three resource type checking if we need to release
- * assigned resource after requested + add_size try.
- * 1. if there is io port assign fail, will release assigned
- * io port.
- * 2. if there is pref mmio assign fail, release assigned
- * pref mmio.
- * if assigned pref mmio's parent is non-pref mmio and there
- * is non-pref mmio assign fail, will release that assigned
- * pref mmio.
- * 3. if there is non-pref mmio assign fail or pref mmio
- * assigned fail, will release assigned non-pref mmio.
*/
+
LIST_HEAD(save_head);
LIST_HEAD(local_fail_head);
struct pci_dev_resource *save_res;
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 04/52] PCI: Optimize bus min_align/size calculation during sizing |
| Message-ID | <pZO9A-44i-15@gated-at.bofh.it> |
| In reply to | #1210924 |
Current code try to get align as small as possible and use that to
align final size. But it does not handle resource that size is bigger
than align in optimal way, kernel only use max align for them.
For example:
when we have resources with align/size: 1M/2M, 512M/512M,
bus resource min_align/size0 will be 512M/1024M,
but optimal value should be 256M/768M.
For following cases that we have resource size that is bigger
than resource alignment:
1. SRIOV bar.
2. PCI bridges with children that need several MMIOs that are more than 1M.
We can keep on trying to allocate children devices resources under range
[offset, offset + aligned_size) and offset is aligned with half_align.
If sucesses, we can use that half_align as new min_align.
After this patch, we get:
align/size: 1M/2M, 2M/4M, 4M/8M, 8M/16M
new min_align/min_size: 4M/32M, and old is 8M/32M
align/size: 1M/2M, 2M/4M, 4M/8M
new min_align/min_size: 2M/14M, and old is 4M/16M
align/size: 1M/2M, 512M/512M
new min_align/min_size: 256M/768M, and old is 512M/1024M
The real result from one system with one pcie card that has
four functions that support sriov:
children resources with align/size:
00800000/00800000
00800000/00800000
00800000/00800000
00800000/00800000
00010000/00200000
00010000/00200000
00010000/00200000
00010000/00200000
00008000/00008000
00008000/00008000
00008000/00008000
00008000/00008000
00004000/00080000
00004000/00080000
00004000/00080000
00004000/00080000
the for the bridge
with orig code we have min_align/min_size: 00400000/02c00000
and with this patch we have min_align/min_size: 00100000/02b00000
So align will be 1M instead of 4M and even have smaller size.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=81431
Reported-by: TJ <linux@iam.tj>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 195 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 157 insertions(+), 38 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index aea35b6..861fe68 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -30,6 +30,34 @@
unsigned int pci_flags;
+static inline bool is_before(resource_size_t align1, resource_size_t size1,
+ resource_size_t align2, resource_size_t size2)
+{
+ resource_size_t size1_left, size2_left;
+
+ /* big align is before small align */
+ if (align1 > align2)
+ return true;
+
+ /*
+ * for same align:
+ * aligned is before not aligned
+ * for not aligned, big remainder is before small remainder
+ */
+ if (align1 == align2) {
+ size1_left = size1 & (align1 - 1);
+ if (!size1_left)
+ size1_left = align1;
+ size2_left = size2 & (align2 - 1);
+ if (!size2_left)
+ size2_left = align2;
+ if (size1_left > size2_left)
+ return true;
+ }
+
+ return false;
+}
+
struct pci_dev_resource {
struct list_head list;
struct resource *res;
@@ -998,26 +1026,125 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
}
}
-static inline resource_size_t calculate_mem_align(resource_size_t *aligns,
- int max_order)
+struct align_test_res {
+ struct list_head list;
+ struct resource res;
+ resource_size_t size;
+ resource_size_t align;
+};
+
+static void free_align_test_list(struct list_head *head)
{
- resource_size_t align = 0;
- resource_size_t min_align = 0;
- int order;
+ struct align_test_res *p, *tmp;
- for (order = 0; order <= max_order; order++) {
- resource_size_t align1 = 1;
+ list_for_each_entry_safe(p, tmp, head, list) {
+ list_del(&p->list);
+ kfree(p);
+ }
+}
- align1 <<= (order + 20);
+static int add_to_align_test_list(struct list_head *head,
+ resource_size_t align, resource_size_t size)
+{
+ struct align_test_res *tmp;
+
+ tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
+ if (!tmp)
+ return -ENOMEM;
+
+ tmp->align = align;
+ tmp->size = size;
+
+ list_add_tail(&tmp->list, head);
+
+ return 0;
+}
+
+static void sort_align_test(struct list_head *head)
+{
+ struct align_test_res *res1, *tmp_res, *res2;
- if (!align)
- min_align = align1;
- else if (ALIGN(align + min_align, min_align) < align1)
- min_align = align1 >> 1;
- align += aligns[order];
+ list_for_each_entry_safe(res1, tmp_res, head, list) {
+ /* reorder it */
+ list_for_each_entry(res2, head, list) {
+ if (res2 == res1)
+ break;
+
+ if (is_before(res1->align, res1->size,
+ res2->align, res2->size)) {
+ list_move_tail(&res1->list, &res2->list);
+ break;
+ }
+ }
+ }
+}
+
+static bool is_align_size_good(struct list_head *head,
+ resource_size_t min_align, resource_size_t size,
+ resource_size_t start)
+{
+ struct align_test_res *p;
+ struct resource root;
+
+ memset(&root, 0, sizeof(root));
+ root.start = start;
+ root.end = start + size - 1;
+
+ list_for_each_entry(p, head, list)
+ memset(&p->res, 0, sizeof(p->res));
+
+ list_for_each_entry(p, head, list)
+ if (allocate_resource(&root, &p->res, p->size,
+ 0, (resource_size_t)-1ULL,
+ p->align, NULL, NULL))
+ return false;
+
+ return true;
+}
+
+static resource_size_t calculate_mem_align(struct list_head *head,
+ resource_size_t max_align, resource_size_t size,
+ resource_size_t align_low)
+{
+ struct align_test_res *p;
+ resource_size_t min_align, good_align, aligned_size, start;
+ int count = 0;
+
+ if (max_align <= align_low) {
+ good_align = align_low;
+ goto out;
}
- return min_align;
+ good_align = max_align;
+
+ list_for_each_entry(p, head, list)
+ count++;
+
+ if (count <= 1)
+ goto out;
+
+ sort_align_test(head);
+
+ do {
+ /* check if we can use smaller align */
+ min_align = good_align >> 1;
+ aligned_size = ALIGN(size, min_align);
+
+ /* need to make sure every offset work */
+ for (start = min_align; start < max_align; start += min_align) {
+ /* checked already with last align ? */
+ if (!(start & (good_align - 1)))
+ continue;
+
+ if (!is_align_size_good(head, min_align, aligned_size,
+ start))
+ goto out;
+ }
+ good_align = min_align;
+ } while (min_align > align_low);
+
+out:
+ return good_align;
}
/**
@@ -1047,19 +1174,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
{
struct pci_dev *dev;
resource_size_t min_align, align, size, size0, size1;
- resource_size_t aligns[18]; /* Alignments from 1Mb to 128Gb */
- int order, max_order;
+ resource_size_t max_align = 0;
struct resource *b_res = find_free_bus_resource(bus,
mask | IORESOURCE_PREFETCH, type);
resource_size_t children_add_size = 0;
resource_size_t children_add_align = 0;
resource_size_t add_align = 0;
+ LIST_HEAD(align_test_list);
if (!b_res)
return -ENOSPC;
- memset(aligns, 0, sizeof(aligns));
- max_order = 0;
size = 0;
list_for_each_entry(dev, &bus->devices, bus_list) {
@@ -1085,29 +1210,20 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
continue;
}
#endif
- /*
- * aligns[0] is for 1MB (since bridge memory
- * windows are always at least 1MB aligned), so
- * keep "order" from being negative for smaller
- * resources.
- */
align = pci_resource_alignment(dev, r);
- order = __ffs(align) - 20;
- if (order < 0)
- order = 0;
- if (order >= ARRAY_SIZE(aligns)) {
+ if (align > (1ULL<<37)) { /*128 Gb*/
dev_warn(&dev->dev, "disabling BAR %d: %pR (bad alignment %#llx)\n",
- i, r, (unsigned long long) align);
+ i, r, (unsigned long long) align);
r->flags = 0;
continue;
}
+
+ if (r_size > 1)
+ add_to_align_test_list(&align_test_list,
+ align, r_size);
size += r_size;
- /* Exclude ranges with size > align from
- calculation of the alignment. */
- if (r_size == align)
- aligns[order] += align;
- if (order > max_order)
- max_order = order;
+ if (align > max_align)
+ max_align = align;
if (realloc_head) {
children_add_size += get_res_add_size(realloc_head, r);
@@ -1117,9 +1233,12 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
}
}
- min_align = calculate_mem_align(aligns, max_order);
- min_align = max(min_align, window_alignment(bus, b_res->flags));
- size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align);
+ max_align = max(max_align, window_alignment(bus, b_res->flags));
+ min_align = calculate_mem_align(&align_test_list, max_align, size,
+ window_alignment(bus, b_res->flags));
+ size0 = calculate_memsize(size, min_size, 0,
+ resource_size(b_res), min_align);
+ free_align_test_list(&align_test_list);
add_align = max(min_align, add_align);
if (children_add_size > add_size)
add_size = children_add_size;
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 27/52] PCI: Move ISA io port align out of calculate_iosize() |
| Message-ID | <pZO9B-44i-31@gated-at.bofh.it> |
| In reply to | #1210924 |
We can move ISA io port align out of calculate_iosize(),
so we could unify calculate_iosize and calculate_memsize later.
That extra aligning or offset is to work around ISA devices:
When one bridge have several children devices, and every device
has several io port resources and resource size < 0x400.
We need to check size, and add extra size to make sure bit8/9
to be zero.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 39 +++++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 372a182..8f11cd1 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1120,11 +1120,6 @@ static resource_size_t calculate_iosize(resource_size_t size,
size = min_size;
if (old_size == 1)
old_size = 0;
- /* To be fixed in 2.5: we should have sort of HAVE_ISA
- flag in the struct pci_bus. */
-#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
- size = (size & 0xff) + ((size & ~0xffUL) << 2);
-#endif
size = ALIGN(size + size1, align);
if (size < old_size)
size = old_size;
@@ -1178,6 +1173,18 @@ static resource_size_t window_alignment(struct pci_bus *bus,
return max(align, arch_align);
}
+static resource_size_t size_aligned_for_isa(resource_size_t size)
+{
+ /*
+ * To be fixed in 2.5: we should have sort of HAVE_ISA
+ * flag in the struct pci_bus.
+ */
+#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
+ size = (size & 0xff) + ((size & ~0xffUL) << 2);
+#endif
+ return size;
+}
+
/**
* pbus_size_io() - size the io window of a given bus
*
@@ -1195,11 +1202,10 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
{
struct pci_dev *dev;
resource_size_t min_sum_size = 0;
- resource_size_t sum_add_size;
struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO,
IORESOURCE_IO);
resource_size_t size = 0, size0 = 0, size1 = 0;
- resource_size_t children_add_size = 0;
+ resource_size_t sum_add_size = 0, sum_add_size1 = 0;
resource_size_t min_align, align;
if (!b_res)
@@ -1216,7 +1222,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
for (i = 0; i < PCI_NUM_RESOURCES; i++) {
struct resource *r = &dev->resource[i];
- unsigned long r_size;
+ unsigned long r_size, r_add_size;
if (r->parent || !(r->flags & IORESOURCE_IO))
continue;
@@ -1232,18 +1238,27 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
if (align > min_align)
min_align = align;
- if (realloc_head)
- children_add_size += get_res_add_size(realloc_head, r);
+ if (realloc_head) {
+ r_add_size = get_res_add_size(realloc_head, r);
+ r_add_size += r_size;
+ if (r_add_size < 0x400)
+ /* Might be re-aligned for ISA */
+ sum_add_size += r_add_size;
+ else
+ sum_add_size1 += r_add_size;
+ }
}
}
+ size = size_aligned_for_isa(size);
size0 = calculate_iosize(size, min_size, size1,
resource_size(b_res), min_align);
- sum_add_size = children_add_size + size + size1;
+ sum_add_size = size_aligned_for_isa(sum_add_size);
+ sum_add_size += sum_add_size1;
if (sum_add_size < min_sum_size)
sum_add_size = min_sum_size;
size1 = !realloc_head ? size0 :
- calculate_iosize(size, min_size, sum_add_size - size,
+ calculate_iosize(sum_add_size, min_size, 0,
resource_size(b_res), min_align);
if (!size0 && !size1) {
if (b_res->start || b_res->end)
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 08/52] PCI: Remove duplicated code for resource sorting |
| Message-ID | <pZO9B-44i-37@gated-at.bofh.it> |
| In reply to | #1210924 |
Now sort_resources() and pdev_sort_resources() all have sorting
code.
As we are going to call sort_resources() several places later, so
choose to keep sort_resources(), and remove related code in
pdev_sort_resources().
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 555a7a3..44d63c0 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -214,9 +214,8 @@ static void pdev_sort_resources(struct pci_dev *dev,
for (i = 0; i < PCI_NUM_RESOURCES; i++) {
struct resource *r;
- struct pci_dev_resource *dev_res, *tmp;
+ struct pci_dev_resource *tmp;
resource_size_t r_align;
- struct list_head *n;
r = &dev->resource[i];
@@ -239,22 +238,7 @@ static void pdev_sort_resources(struct pci_dev *dev,
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,
- realloc_head);
-
- if (r_align > align) {
- n = &dev_res->list;
- break;
- }
- }
- /* Insert it just before n*/
- list_add_tail(&tmp->list, n);
+ list_add_tail(&tmp->list, head);
}
}
@@ -557,9 +541,9 @@ static void __assign_resources_sorted(struct list_head *head,
}
free_list(&save_head);
+requested_and_reassign:
sort_resources(head);
-requested_and_reassign:
/* Satisfy the must-have resource requests */
assign_requested_resources_sorted(head, fail_head);
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 05/52] PCI: Optimize bus align/size calculation for optional during sizing |
| Message-ID | <pZO9A-44i-17@gated-at.bofh.it> |
| In reply to | #1210924 |
Current add_align always use max align, that make required+optional
to get allocated more than needed in some cases.
Now we have new calculate_mem_align, we could use it for add_align
calculation.
Need to create separated list for required+optional align/size info.
After that we can get smaller add_align/size, we have more chance
to make required+optional to get allocated.
The result for bridge that have Intel 4x10g card installed.
pci 0000:20:03.2: bridge window [mem 0x00000000-0x000fffff 64bit pref]
to [bus 2a-31] calculate_mem for required
===========BEGIN========================
align/size:
00800000/00800000
00800000/00800000
00800000/00800000
00800000/00800000
00008000/00008000
00008000/00008000
00008000/00008000
00008000/00008000
old min_align/min_size: 00400000/02400000
min_align/min_size: 00400000/02400000
===========END========================
pci 0000:20:03.2: bridge window [mem 0x00000000-0x000fffff 64bit pref]
to [bus 2a-31] calculate_mem for required+optional
===========BEGIN========================
align/size:
00800000/00800000
00800000/00800000
00800000/00800000
00800000/00800000
00010000/00200000
00010000/00200000
00010000/00200000
00010000/00200000
00008000/00008000
00008000/00008000
00008000/00008000
00008000/00008000
00004000/00080000
00004000/00080000
00004000/00080000
00004000/00080000
for parent bridge:
original code min_align/min_size: 00800000/03000000
after this patch min_align/min_size: 00100000/02b00000
===========END========================
so required align/size: 0x400000/0x2400000, and
new required+optional align/size: 0x100000/0x2b00000, and it is much better
than original required+optional align/size: 0x800000/0x3000000
-v2: remove not used size1 in calculate_memsize
Link: https://bugzilla.kernel.org/show_bug.cgi?id=81431
Reported-by: TJ <linux@iam.tj>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
drivers/pci/setup-bus.c | 82 +++++++++++++++++++++++++++++-------------------
1 file changed, 51 insertions(+), 31 deletions(-)
---
drivers/pci/setup-bus.c | 82 ++++++++++++++++++++++++++++++-------------------
1 file changed, 51 insertions(+), 31 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 861fe68..6cccbe4 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -900,7 +900,6 @@ static resource_size_t calculate_iosize(resource_size_t size,
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)
{
@@ -910,7 +909,7 @@ static resource_size_t calculate_memsize(resource_size_t size,
old_size = 0;
if (size < old_size)
size = old_size;
- size = ALIGN(size + size1, align);
+ size = ALIGN(size, align);
return size;
}
@@ -1173,44 +1172,45 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
struct list_head *realloc_head)
{
struct pci_dev *dev;
- resource_size_t min_align, align, size, size0, size1;
- resource_size_t max_align = 0;
+ resource_size_t min_align = 0, min_add_align = 0;
+ resource_size_t max_align = 0, max_add_align = 0;
+ resource_size_t size = 0, size0 = 0, size1 = 0, sum_add_size = 0;
struct resource *b_res = find_free_bus_resource(bus,
mask | IORESOURCE_PREFETCH, type);
- resource_size_t children_add_size = 0;
- resource_size_t children_add_align = 0;
- resource_size_t add_align = 0;
LIST_HEAD(align_test_list);
+ LIST_HEAD(align_test_add_list);
if (!b_res)
return -ENOSPC;
- size = 0;
-
list_for_each_entry(dev, &bus->devices, bus_list) {
int i;
for (i = 0; i < PCI_NUM_RESOURCES; i++) {
struct resource *r = &dev->resource[i];
- resource_size_t r_size;
+ resource_size_t r_size, align;
if (r->parent || ((r->flags & mask) != type &&
(r->flags & mask) != type2 &&
(r->flags & mask) != type3))
continue;
+
r_size = resource_size(r);
+ align = pci_resource_alignment(dev, r);
#ifdef CONFIG_PCI_IOV
/* put SRIOV requested res to the optional list */
if (realloc_head && i >= PCI_IOV_RESOURCES &&
i <= PCI_IOV_RESOURCE_END) {
- add_align = max(pci_resource_alignment(dev, r), add_align);
+ add_to_align_test_list(&align_test_add_list,
+ align, r_size);
r->end = r->start - 1;
add_to_list(realloc_head, dev, r, r_size, 0/* don't care */);
- children_add_size += r_size;
+ sum_add_size += r_size;
+ if (align > max_add_align)
+ max_add_align = align;
continue;
}
#endif
- align = pci_resource_alignment(dev, r);
if (align > (1ULL<<37)) { /*128 Gb*/
dev_warn(&dev->dev, "disabling BAR %d: %pR (bad alignment %#llx)\n",
i, r, (unsigned long long) align);
@@ -1218,33 +1218,52 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
continue;
}
- if (r_size > 1)
+ if (r_size > 1) {
add_to_align_test_list(&align_test_list,
align, r_size);
- size += r_size;
- if (align > max_align)
- max_align = align;
+ size += r_size;
+ if (align > max_align)
+ max_align = align;
+ }
if (realloc_head) {
- children_add_size += get_res_add_size(realloc_head, r);
- children_add_align = get_res_add_align(realloc_head, r);
- add_align = max(add_align, children_add_align);
+ resource_size_t add_r_size, add_align;
+
+ add_r_size = get_res_add_size(realloc_head, r);
+ add_align = get_res_add_align(realloc_head, r);
+ /* no add on ? */
+ if (add_align < align)
+ add_align = align;
+ add_to_align_test_list(&align_test_add_list,
+ add_align,
+ r_size + add_r_size);
+ sum_add_size += r_size + add_r_size;
+ if (add_align > max_add_align)
+ max_add_align = add_align;
}
}
}
max_align = max(max_align, window_alignment(bus, b_res->flags));
- min_align = calculate_mem_align(&align_test_list, max_align, size,
- window_alignment(bus, b_res->flags));
- size0 = calculate_memsize(size, min_size, 0,
+ if (size || min_size) {
+ min_align = calculate_mem_align(&align_test_list, max_align,
+ size, window_alignment(bus, b_res->flags));
+ size0 = calculate_memsize(size, min_size,
resource_size(b_res), min_align);
+ }
free_align_test_list(&align_test_list);
- add_align = max(min_align, add_align);
- 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,
- resource_size(b_res), add_align);
+
+ if ((sum_add_size - size) < add_size)
+ sum_add_size = size + add_size;
+ if (sum_add_size > size && realloc_head) {
+ min_add_align = calculate_mem_align(&align_test_add_list,
+ max_add_align, sum_add_size,
+ window_alignment(bus, b_res->flags));
+ size1 = calculate_memsize(sum_add_size, min_size,
+ resource_size(b_res), min_add_align);
+ }
+ free_align_test_list(&align_test_add_list);
+
if (!size0 && !size1) {
if (b_res->start || b_res->end)
dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n",
@@ -1256,11 +1275,12 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
b_res->end = size0 + min_align - 1;
b_res->flags |= IORESOURCE_STARTALIGN;
if (size1 > size0 && realloc_head) {
- add_to_list(realloc_head, bus->self, b_res, size1-size0, add_align);
+ add_to_list(realloc_head, bus->self, b_res, size1 - size0,
+ min_add_align);
dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window %pR to %pR add_size %llx add_align %llx\n",
b_res, &bus->busn_res,
(unsigned long long) (size1 - size0),
- (unsigned long long) add_align);
+ (unsigned long long) min_add_align);
}
return 0;
}
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 36/52] PCI: Only treat non-pref mmio64 as pref if all bridges have MEM_64 |
| Message-ID | <pZO9B-44i-41@gated-at.bofh.it> |
| In reply to | #1210924 |
If any bridge up to root only have 32bit pref mmio, We don't need to
treat device non-pref mmio64 as as pref mmio64.
We need to move pci_bridge_check_ranges calling early.
for parent bridges pref mmio BAR may not allocated by BIOS, res flags
is still 0, we need to have it correct set before we check them for
child device resources.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 4772a09..9667cbf5 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1032,6 +1032,18 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
return -EINVAL;
}
+static bool pci_up_path_over_pref_mem64(struct pci_bus *bus)
+{
+ if (pci_is_root_bus(bus))
+ return true;
+
+ if (bus->self && !(bus->self->resource[PCI_BRIDGE_RESOURCES + 2].flags &
+ IORESOURCE_MEM_64))
+ return false;
+
+ return pci_up_path_over_pref_mem64(bus->parent);
+}
+
int pci_resource_pref_compatible(const struct pci_dev *dev,
struct resource *res)
{
@@ -1040,7 +1052,8 @@ int pci_resource_pref_compatible(const struct pci_dev *dev,
if ((res->flags & IORESOURCE_MEM) &&
(res->flags & IORESOURCE_MEM_64) &&
- dev->on_all_pcie_path)
+ dev->on_all_pcie_path &&
+ pci_up_path_over_pref_mem64(dev->bus))
return res->flags | IORESOURCE_PREFETCH;
return res->flags;
@@ -1821,6 +1834,10 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
struct resource *b_res;
int ret;
+ if (!pci_is_root_bus(bus) &&
+ (bus->self->class >> 8) == PCI_CLASS_BRIDGE_PCI)
+ pci_bridge_check_ranges(bus);
+
list_for_each_entry(dev, &bus->devices, bus_list) {
struct pci_bus *b = dev->subordinate;
if (!b)
@@ -1848,7 +1865,6 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
break;
case PCI_CLASS_BRIDGE_PCI:
- pci_bridge_check_ranges(bus);
if (bus->self->is_hotplug_bridge) {
min_io_size = pci_hotplug_io_size;
min_mem_size = pci_hotplug_mem_size;
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 43/52] OF/PCI: Add IORESOURCE_MEM_64 for 64-bit resource |
| Message-ID | <pZO9B-44i-47@gated-at.bofh.it> |
| In reply to | #1210924 |
For device resource PREF bit setting under bridge 64-bit pref resource, we need to make sure only set PREF for 64bit resource, so set IORESOUCE_MEM_64 for 64bit resource during OF device resource flags parsing. Link: https://bugzilla.kernel.org/show_bug.cgi?id=96261 Link: https://bugzilla.kernel.org/show_bug.cgi?id=96241 Signed-off-by: Yinghai Lu <yinghai@kernel.org> Cc: Grant Likely <grant.likely@linaro.org> Cc: Rob Herring <robh+dt@kernel.org> Cc: devicetree@vger.kernel.org --- drivers/of/address.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 8bfda6a..073125f 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -128,9 +128,11 @@ static unsigned int of_bus_pci_get_flags(const __be32 *addr) flags |= IORESOURCE_IO; break; case 0x02: /* 32 bits */ - case 0x03: /* 64 bits */ flags |= IORESOURCE_MEM; break; + case 0x03: /* 64 bits */ + flags |= IORESOURCE_MEM | IORESOURCE_MEM_64; + break; } if (w & 0x40000000) flags |= IORESOURCE_PREFETCH; -- 1.8.4.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Rob Herring <robherring2@gmail.com> |
|---|---|
| Date | 2015-08-21 20:20 +0200 |
| Subject | Re: [PATCH v4 43/52] OF/PCI: Add IORESOURCE_MEM_64 for 64-bit resource |
| Message-ID | <pZZ50-31h-19@gated-at.bofh.it> |
| In reply to | #1210934 |
On Fri, Aug 21, 2015 at 1:20 AM, Yinghai Lu <yinghai@kernel.org> wrote: > For device resource PREF bit setting under bridge 64-bit pref resource, > we need to make sure only set PREF for 64bit resource, so set > IORESOUCE_MEM_64 for 64bit resource during OF device resource flags > parsing. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=96261 > Link: https://bugzilla.kernel.org/show_bug.cgi?id=96241 > Signed-off-by: Yinghai Lu <yinghai@kernel.org> > Cc: Grant Likely <grant.likely@linaro.org> > Cc: Rob Herring <robh+dt@kernel.org> > Cc: devicetree@vger.kernel.org My comment from v1[1] is not addressed still. Rob [1] https://lkml.org/lkml/2015/7/10/736 > --- > drivers/of/address.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 8bfda6a..073125f 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -128,9 +128,11 @@ static unsigned int of_bus_pci_get_flags(const __be32 *addr) > flags |= IORESOURCE_IO; > break; > case 0x02: /* 32 bits */ > - case 0x03: /* 64 bits */ > flags |= IORESOURCE_MEM; > break; > + case 0x03: /* 64 bits */ > + flags |= IORESOURCE_MEM | IORESOURCE_MEM_64; > + break; > } > if (w & 0x40000000) > flags |= IORESOURCE_PREFETCH; > -- > 1.8.4.5 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 20:30 +0200 |
| Subject | Re: [PATCH v4 43/52] OF/PCI: Add IORESOURCE_MEM_64 for 64-bit resource |
| Message-ID | <pZZeG-3cy-41@gated-at.bofh.it> |
| In reply to | #1211287 |
On Fri, Aug 21, 2015 at 11:18 AM, Rob Herring <robherring2@gmail.com> wrote: > On Fri, Aug 21, 2015 at 1:20 AM, Yinghai Lu <yinghai@kernel.org> wrote: >> For device resource PREF bit setting under bridge 64-bit pref resource, >> we need to make sure only set PREF for 64bit resource, so set >> IORESOUCE_MEM_64 for 64bit resource during OF device resource flags >> parsing. >> >> Link: https://bugzilla.kernel.org/show_bug.cgi?id=96261 >> Link: https://bugzilla.kernel.org/show_bug.cgi?id=96241 >> Signed-off-by: Yinghai Lu <yinghai@kernel.org> >> Cc: Grant Likely <grant.likely@linaro.org> >> Cc: Rob Herring <robh+dt@kernel.org> >> Cc: devicetree@vger.kernel.org > > My comment from v1[1] is not addressed still. > > > [1] https://lkml.org/lkml/2015/7/10/736 | As the BZ says, we have several identical functions. Can we fix the | drivers/of/address.c version and remove the Sparc versions. The only | diff is the generic version converts from be32. I think that should be | a nop for Sparc. That would be better to let guys with Sparc or other OF arch to do the unification. Yinghai -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 15/52] PCI: Cache window alignment value during bus sizing |
| Message-ID | <pZO9B-44i-51@gated-at.bofh.it> |
| In reply to | #1210924 |
There are several calling to window_alignment(), and we will have more
for alt_size support, cache the value instead of keeping on getting it.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c2c0806..b17ee2d 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1197,6 +1197,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
mask | IORESOURCE_PREFETCH, type);
LIST_HEAD(align_test_list);
LIST_HEAD(align_test_add_list);
+ resource_size_t window_align;
if (!b_res)
return -ENOSPC;
@@ -1206,6 +1207,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
min_size = 0;
}
+ window_align = window_alignment(bus, b_res->flags);
+
list_for_each_entry(dev, &bus->devices, bus_list) {
int i;
@@ -1266,10 +1269,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
}
}
- max_align = max(max_align, window_alignment(bus, b_res->flags));
+ max_align = max(max_align, window_align);
if (size || min_size) {
min_align = calculate_mem_align(&align_test_list, max_align,
- size, window_alignment(bus, b_res->flags));
+ size, window_align);
size0 = calculate_memsize(size, min_size,
resource_size(b_res), min_align);
}
@@ -1280,7 +1283,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
if (sum_add_size > size && realloc_head) {
min_add_align = calculate_mem_align(&align_test_add_list,
max_add_align, sum_add_size,
- window_alignment(bus, b_res->flags));
+ window_align);
size1 = calculate_memsize(sum_add_size, min_size,
resource_size(b_res), min_add_align);
}
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 01/52] PCI: Cleanup res_to_dev_res() printout |
| Message-ID | <pZO9C-44i-53@gated-at.bofh.it> |
| In reply to | #1210924 |
Now get_res_add_size and get_res_add_align all have same printout
from res_to_dev_res(), and it is confusing.
Move out debug messages printout from res_to_dev_res(),
and later we will reuse res_to_dev_res() in other functions.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 508cc56..6d0815e 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -104,19 +104,9 @@ static struct pci_dev_resource *res_to_dev_res(struct list_head *head,
{
struct pci_dev_resource *dev_res;
- 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,
- "res[%d]=%pR res_to_dev_res add_size %llx min_align %llx\n",
- idx, dev_res->res,
- (unsigned long long)dev_res->add_size,
- (unsigned long long)dev_res->min_align);
-
+ list_for_each_entry(dev_res, head, list)
+ if (dev_res->res == res)
return dev_res;
- }
- }
return NULL;
}
@@ -127,7 +117,15 @@ static resource_size_t get_res_add_size(struct list_head *head,
struct pci_dev_resource *dev_res;
dev_res = res_to_dev_res(head, res);
- return dev_res ? dev_res->add_size : 0;
+ if (!dev_res || !dev_res->add_size)
+ return 0;
+
+ dev_printk(KERN_DEBUG, &dev_res->dev->dev,
+ "BAR %d: %pR get_res_add_size add_size %#llx\n",
+ (int)(res - &dev_res->dev->resource[0]),
+ res, (unsigned long long)dev_res->add_size);
+
+ return dev_res->add_size;
}
static resource_size_t get_res_add_align(struct list_head *head,
@@ -136,7 +134,15 @@ static resource_size_t get_res_add_align(struct list_head *head,
struct pci_dev_resource *dev_res;
dev_res = res_to_dev_res(head, res);
- return dev_res ? dev_res->min_align : 0;
+ if (!dev_res || !dev_res->min_align)
+ return 0;
+
+ dev_printk(KERN_DEBUG, &dev_res->dev->dev,
+ "BAR %d: %pR get_res_add_align min_align %#llx\n",
+ (int)(res - &dev_res->dev->resource[0]),
+ res, (unsigned long long)dev_res->min_align);
+
+ return dev_res->min_align;
}
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 32/52] PCI: Kill macro checking for bus io port sizing |
| Message-ID | <pZO9A-44i-27@gated-at.bofh.it> |
| In reply to | #1210924 |
We can use new generic version skip_isa_ioresource_align() instead
the old marcro, so kill the marco.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 1f08bed..1048483 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1166,15 +1166,12 @@ int skip_isa_ioresource_align(struct pci_bus *bus)
return 0;
}
-static resource_size_t size_aligned_for_isa(resource_size_t size)
+static resource_size_t size_aligned_for_isa(resource_size_t size,
+ struct pci_bus *bus)
{
- /*
- * To be fixed in 2.5: we should have sort of HAVE_ISA
- * flag in the struct pci_bus.
- */
-#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
- size = (size & 0xff) + ((size & ~0xffUL) << 2);
-#endif
+ if (!skip_isa_ioresource_align(bus))
+ size = (size & 0xff) + ((size & ~0xffUL) << 2);
+
return size;
}
@@ -1243,12 +1240,12 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
}
}
- size = size_aligned_for_isa(size);
+ size = size_aligned_for_isa(size, bus);
size += size1;
if (size || min_size)
size0 = calculate_size(size, min_size,
resource_size(b_res), min_align);
- sum_add_size = size_aligned_for_isa(sum_add_size);
+ sum_add_size = size_aligned_for_isa(sum_add_size, bus);
sum_add_size += sum_add_size1;
if (sum_add_size < min_sum_size)
sum_add_size = min_sum_size;
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 08:40 +0200 |
| Subject | [PATCH v4 21/52] PCI: Move saved required resource list out of required+optional assigning |
| Message-ID | <pZO9B-44i-49@gated-at.bofh.it> |
| In reply to | #1210924 |
We will need to share saved required list for alt_size support, so move
it out of required+optional assigning.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 7d2420d..6429309 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -450,6 +450,9 @@ static bool has_addon(struct list_head *head,
int add_count = 0;
struct pci_dev_resource *dev_res, *tmp_res;
+ if (!realloc_head)
+ return false;
+
/* check if we have add really */
list_for_each_entry(dev_res, head, list) {
tmp_res = res_to_dev_res(realloc_head, dev_res->res);
@@ -486,9 +489,9 @@ static void restore_resource(struct pci_dev_resource *save_res,
}
static bool __assign_resources_required_optional_sorted(struct list_head *head,
+ struct list_head *save_head,
struct list_head *realloc_head)
{
- LIST_HEAD(save_head);
LIST_HEAD(local_fail_head);
struct pci_dev_resource *save_res;
struct pci_dev_resource *dev_res, *tmp_res;
@@ -496,12 +499,6 @@ static bool __assign_resources_required_optional_sorted(struct list_head *head,
resource_size_t add_align, add_size;
struct resource *res;
- if (!has_addon(head, realloc_head))
- return false;
-
- if (!save_resources(head, &save_head))
- return false;
-
/* Update res in head list with add_size in realloc_head list */
list_for_each_entry(dev_res, head, list) {
res = dev_res->res;
@@ -542,7 +539,6 @@ static bool __assign_resources_required_optional_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(&save_head);
free_list(head);
return true;
@@ -556,7 +552,7 @@ static bool __assign_resources_required_optional_sorted(struct list_head *head,
if (res->parent && !pci_need_to_release(fail_type, res)) {
/* remove it from realloc_head list */
remove_from_list(realloc_head, res);
- remove_from_list(&save_head, res);
+ remove_from_list(save_head, res);
list_del(&dev_res->list);
kfree(dev_res);
}
@@ -575,11 +571,9 @@ static bool __assign_resources_required_optional_sorted(struct list_head *head,
}
}
/* Restore start/end/flags from saved list */
- list_for_each_entry(save_res, &save_head, list)
+ list_for_each_entry(save_res, save_head, list)
restore_resource(save_res, save_res->res);
- free_list(&save_head);
-
return false;
}
@@ -597,16 +591,24 @@ static void __assign_resources_sorted(struct list_head *head,
* then try to reassign add_size for some resources.
*/
+ LIST_HEAD(save_head);
+
/* Check required+optional add */
- if (realloc_head &&
- __assign_resources_required_optional_sorted(head, realloc_head))
+ if (has_addon(head, realloc_head) &&
+ save_resources(head, &save_head) &&
+ __assign_resources_required_optional_sorted(head, &save_head,
+ realloc_head)) {
+ free_list(&save_head);
return;
+ }
sort_resources(head);
/* Satisfy the must-have resource requests */
assign_requested_resources_sorted(head, fail_head);
+ free_list(&save_head);
+
/* Try to satisfy any additional optional resource
requests */
if (realloc_head)
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 09:30 +0200 |
| Subject | [PATCH v4 22/52] PCI: Add alt_size ressource allocation support |
| Message-ID | <pZOVY-5dT-9@gated-at.bofh.it> |
| In reply to | #1210924 |
On system with several pcie switches, BIOS allocate very tight resources
to the bridge bar, and it is not aligned to min_align as kernel allocation
code.
For example:
02:03.0---0c:00.0---0d:04.0---18:00.0
18:00.0 need 0x10000000, and 0x00010000.
BIOS only allocate 0x10100000 to 0d:04.0 and above bridges.
Later after using /sys/bus/pci/devices/0000:0c:00.0/remove to remove 0c:00.0,
rescan with /sys/bus/pci/rescan can not allocate 0x18000000 to 0c:00.0.
another example:
00:1c.0-[02-21]----00.0-[03-21]--+-01.0-[04-12]----00.0-[05-12]----19.0-[06-12]----00.0
+-05.0-[13]--
+-07.0-[14-20]----00.0-[15-20]--+-08.0-[16]--+-00.0
| | \-00.1
| +-14.0-[17]----00.0
| \-19.0-[18-20]----00.0
\-09.0-[21]--
06:00.0 need 0x4000000 and 0x800000.
BIOS only allocate 0x4800000 to 05:19.0 and 04:00.0.
when 05:19.0 get removed via /sys/bus/pci/devices/0000:05:19.0/remove,
rescan with /sys/bus/pci/rescan will fail.
pci 0000:05:19.0: BAR 14: no space for [mem size 0x06000000]
pci 0000:05:19.0: BAR 14: failed to assign [mem size 0x06000000]
pci 0000:06:00.0: BAR 2: no space for [mem size 0x04000000 64bit]
pci 0000:06:00.0: BAR 2: failed to assign [mem size 0x04000000 64bit]
pci 0000:06:00.0: BAR 0: no space for [mem size 0x00800000]
pci 0000:06:00.0: BAR 0: failed to assign [mem size 0x00800000]
current code try to use align 0x2000000 and size 0x6000000, but parent
bridge only have 0x4800000.
Introduce alt_align/alt_size and store them in realloc list in addition
to addon info, and will try it after min_align/min_size allocation fails.
The alt_align is max_align, and alt_size is aligned size with bridge
minimum window alignment.
on my test setup:
00:1c.7---61:00.0---62:00.0
62:00.0 needs 0x800000 and 0x20000.
and 00:1c.7 only have 9M allocated for mmio, with this patch we have
pci 0000:61:00.0: bridge window [mem 0x00400000-0x00ffffff] to [bus 62] add_size 0 add_align 0 alt_size 900000 alt_align 800000 req_size c00000 req_align 400000
pci 0000:61:00.0: BAR 14: no space for [mem size 0x00c00000]
pci 0000:61:00.0: BAR 14: failed to assign [mem size 0x00c00000]
pci 0000:61:00.0: BAR 14: assigned [mem 0xdf000000-0xdf8fffff]
pci 0000:62:00.0: BAR 0: assigned [mem 0xdf000000-0xdf7fffff pref]
pci 0000:62:00.0: BAR 1: assigned [mem 0xdf800000-0xdf81ffff]
pci 0000:61:00.0: PCI bridge to [bus 62]
pci 0000:61:00.0: bridge window [io 0x6000-0x6fff]
pci 0000:61:00.0: bridge window [mem 0xdf000000-0xdf8fffff]
pci 0000:00:1c.7: PCI bridge to [bus 61-68]
pci 0000:00:1c.7: bridge window [io 0x6000-0x6fff]
pci 0000:00:1c.7: bridge window [mem 0xdf000000-0xdf8fffff]
so for 61:00.0 first try with 12M fails, and second try with 9M the
alt_size works. Later 62:00.0 get correct resource allocated too.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=100451
Reported-by: Yijing Wang <wangyijing@huawei.com>
Tested-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 203 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 191 insertions(+), 12 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 6429309..8be5544 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -323,7 +323,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
{
struct resource *res;
struct pci_dev_resource *add_res, *tmp;
- resource_size_t add_size, align;
+ resource_size_t add_size, align, r_size;
int idx;
list_for_each_entry_safe(add_res, tmp, realloc_head, list) {
@@ -339,12 +339,23 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
idx = res - &add_res->dev->resource[0];
add_size = add_res->add_size;
align = add_res->min_align;
- if (!resource_size(res)) {
+ if (!add_size || !align) /* alt_size only */
+ goto out;
+
+ r_size = resource_size(res);
+ if (!r_size) {
res->start = align;
res->end = res->start + add_size - 1;
if (pci_assign_resource(add_res->dev, idx))
reset_resource(res);
} else {
+ /* could just assigned with alt, add difference ? */
+ resource_size_t size;
+
+ size = add_res->end - add_res->start + 1;
+ if (r_size < size)
+ add_size += size - r_size;
+
res->flags |= add_res->flags &
(IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
if (pci_reassign_resource(add_res->dev, idx,
@@ -577,6 +588,104 @@ static bool __assign_resources_required_optional_sorted(struct list_head *head,
return false;
}
+static bool __has_alt(struct list_head *head,
+ struct list_head *realloc_head)
+{
+ int alt_count = 0;
+ struct pci_dev_resource *dev_res, *alt_res;
+
+ if (!realloc_head)
+ return false;
+
+ /* check if we have alt really */
+ list_for_each_entry(dev_res, head, list) {
+ alt_res = res_to_dev_res(realloc_head, dev_res->res);
+ if (!alt_res || !alt_res->alt_size)
+ continue;
+
+ alt_count++;
+ }
+
+ if (!alt_count)
+ return false;
+
+ return true;
+}
+
+static void __assign_resources_alt_sorted(struct list_head *head,
+ struct list_head *save_head,
+ struct list_head *realloc_head,
+ struct list_head *local_fail_head)
+{
+ LIST_HEAD(local_alt_fail_head);
+ struct pci_dev_resource *dev_res;
+ struct pci_dev_resource *alt_res, *fail_res, *save_res;
+ unsigned long fail_type;
+ struct resource *res;
+
+ /* check failed type */
+ fail_type = pci_fail_res_type_mask(local_fail_head);
+ /* release resource with same type that failes */
+ list_for_each_entry(dev_res, head, list) {
+ res = dev_res->res;
+ if (res->parent) {
+ if (!pci_need_to_release(fail_type, res))
+ continue;
+
+ /*
+ * have to use saved info, as resource that does not
+ * have addon/alt is not in realloc list.
+ */
+ save_res = res_to_dev_res(save_head, res);
+ if (!save_res)
+ continue;
+
+ dev_printk(KERN_DEBUG, &dev_res->dev->dev,
+ "BAR %d: released %pR\n",
+ (int)(res - &dev_res->dev->resource[0]),
+ res);
+ release_resource(dev_res->res);
+ restore_resource(save_res, res);
+ } else {
+ /* restore fail one */
+ fail_res = res_to_dev_res(local_fail_head, res);
+ if (fail_res) {
+ restore_resource(fail_res, res);
+ remove_from_list(local_fail_head, res);
+ }
+ }
+
+ alt_res = res_to_dev_res(realloc_head, res);
+ if (!alt_res || !alt_res->alt_size)
+ continue;
+
+ /* change res to alt */
+ if (res->flags & IORESOURCE_STARTALIGN)
+ res->start = alt_res->alt_align;
+ else
+ res->start = 0;
+ res->end = res->start + alt_res->alt_size - 1;
+ }
+
+ sort_resources(head);
+ /* Satisfy the alt resource requests */
+ assign_requested_resources_sorted(head, &local_alt_fail_head);
+
+ /* update local fail list */
+ list_for_each_entry(fail_res, &local_alt_fail_head, list) {
+ res = fail_res->res;
+ dev_res = res_to_dev_res(realloc_head, res);
+ /* change res back to required */
+ if (dev_res && dev_res->alt_size)
+ restore_resource(dev_res, res);
+
+ if (!res_to_dev_res(local_fail_head, res))
+ add_to_list(local_fail_head, fail_res->dev, res);
+ reset_resource(res);
+ }
+ free_list(&local_alt_fail_head);
+}
+
static void __assign_resources_sorted(struct list_head *head,
struct list_head *realloc_head,
struct list_head *fail_head)
@@ -592,6 +701,8 @@ static void __assign_resources_sorted(struct list_head *head,
*/
LIST_HEAD(save_head);
+ LIST_HEAD(local_fail_head);
+ bool has_alt;
/* Check required+optional add */
if (has_addon(head, realloc_head) &&
@@ -604,15 +715,29 @@ static void __assign_resources_sorted(struct list_head *head,
sort_resources(head);
+ has_alt = __has_alt(head, realloc_head);
+ if (has_alt && list_empty(&save_head))
+ save_resources(head, &save_head);
+
/* Satisfy the must-have resource requests */
- assign_requested_resources_sorted(head, fail_head);
+ assign_requested_resources_sorted(head, &local_fail_head);
+
+ if (has_alt && !list_empty(&local_fail_head) && !list_empty(&save_head))
+ __assign_resources_alt_sorted(head, &save_head,
+ realloc_head,
+ &local_fail_head);
free_list(&save_head);
- /* Try to satisfy any additional optional resource
- requests */
+ /* Try to satisfy any additional optional resource requests */
if (realloc_head)
reassign_resources_sorted(realloc_head, head);
+
+ if (fail_head)
+ list_splice_tail(&local_fail_head, fail_head);
+ else
+ free_list(&local_fail_head);
+
free_list(head);
}
@@ -1250,6 +1375,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
mask | IORESOURCE_PREFETCH, type);
LIST_HEAD(align_test_list);
LIST_HEAD(align_test_add_list);
+ resource_size_t alt_size = 0, alt_align = 0;
resource_size_t window_align;
if (!b_res)
@@ -1306,6 +1432,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
if (realloc_head) {
resource_size_t add_r_size, add_align;
+ struct pci_dev_resource *dev_res;
add_r_size = get_res_add_size(realloc_head, r);
add_align = get_res_add_align(realloc_head, r);
@@ -1318,6 +1445,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
sum_add_size += r_size + add_r_size;
if (add_align > max_add_align)
max_add_align = add_align;
+
+ dev_res = res_to_dev_res(realloc_head, r);
+ if (dev_res && dev_res->alt_size) {
+ alt_size += dev_res->alt_size;
+ if (alt_align < dev_res->alt_align)
+ alt_align = dev_res->alt_align;
+ } else if (r_size > 1) {
+ alt_size += r_size;
+ if (alt_align < align)
+ alt_align = align;
+ }
}
}
}
@@ -1331,6 +1469,17 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
}
free_align_test_list(&align_test_list);
+ if (size0 && realloc_head) {
+ alt_align = max(alt_align, window_align);
+ alt_size = calculate_memsize(alt_size, min_size,
+ 0, window_align);
+ /* required is better ? */
+ if (alt_size >= size0) {
+ alt_align = 0;
+ alt_size = 0;
+ }
+ }
+
if (sum_add_size < min_sum_size)
sum_add_size = min_sum_size;
if (sum_add_size > size && realloc_head) {
@@ -1352,13 +1501,43 @@ 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;
- if (size1 > size0 && realloc_head) {
- __add_to_list(realloc_head, bus->self, b_res, size1 - size0,
- min_add_align, 0, 0);
- dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window %pR to %pR add_size %llx add_align %llx\n",
- b_res, &bus->busn_res,
- (unsigned long long) (size1 - size0),
- (unsigned long long) min_add_align);
+ if (realloc_head) {
+ resource_size_t final_add_size = 0;
+
+ if (size1 > size0)
+ final_add_size = size1 - size0;
+ else
+ min_add_align = 0;
+
+ /*
+ * realloc list include three type entries
+ * 1. optional only:
+ * add_size != 0, alt_size == 0, req_size == 0
+ * 2. required only with smaller alt_size.
+ * add_size == 0, alt_size != 0, req_size > alt_size
+ * 3. required + optional:
+ * add_size != 0, alt_size < req_size, req_size != 0
+ *
+ * So there is no req_size != 0, and alt_size == req_size.
+ * in that case, we already set alt_size = 0.
+ *
+ * req_align/req_size is not stored directly, and we
+ * have dev_res start/end/flags instead.
+ */
+ if (final_add_size || alt_size) {
+ __add_to_list(realloc_head, bus->self, b_res,
+ final_add_size, min_add_align,
+ alt_size, alt_align);
+ dev_printk(KERN_DEBUG, &bus->self->dev,
+ "bridge window %pR to %pR add_size %llx add_align %llx alt_size %llx alt_align %llx req_size %llx req_align %llx\n",
+ b_res, &bus->busn_res,
+ (unsigned long long)final_add_size,
+ (unsigned long long)min_add_align,
+ (unsigned long long)alt_size,
+ (unsigned long long)alt_align,
+ (unsigned long long)size0,
+ (unsigned long long)min_align);
+ }
}
return 0;
}
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 09:30 +0200 |
| Subject | [PATCH v4 44/52] PCI: Treat optional as required in first try for bridge rescan |
| Message-ID | <pZOVY-5dT-11@gated-at.bofh.it> |
| In reply to | #1210924 |
For rescan bridge/bus that children are removed before, we should treat
optional as required just like root bus the boot time in 19aa7ee432ce
(PCI: make re-allocation try harder by reassigning ranges higher in
the heirarchy).
The reason: allocate required and expand to optional path do not
put failed resource to fail list, so will lose required info before
next try.
So we are using following way:
1. First and following try before last try:
We don't keep realloc list so treat every optional as required.
allocate for required+optional and put failed in the fail list.
then size info (include must and optonal separatedly) will be kept
for next try.
2. last try:
a: try to allocate required+optional to see if all get allocated.
b: try to allocate required then expand to optional.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index cacdd75..898f9d7 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2355,25 +2355,34 @@ void __init pci_assign_unassigned_resources(void)
void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
{
struct pci_bus *parent = bridge->subordinate;
- LIST_HEAD(add_list); /* list of resources that
+ LIST_HEAD(realloc_head); /* list of resources that
want additional resources */
+ struct list_head *add_list = NULL;
int tried_times = 0;
LIST_HEAD(fail_head);
struct pci_dev_resource *fail_res;
int retval;
unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
IORESOURCE_PREFETCH | IORESOURCE_MEM_64;
+ int pci_try_num = 2;
again:
- __pci_bus_size_bridges(parent, &add_list);
- __pci_bridge_assign_resources(bridge, &add_list, &fail_head);
- BUG_ON(!list_empty(&add_list));
+ /*
+ * 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_head;
+ __pci_bus_size_bridges(parent, add_list);
+ __pci_bridge_assign_resources(bridge, add_list, &fail_head);
+ if (add_list)
+ BUG_ON(!list_empty(add_list));
tried_times++;
if (list_empty(&fail_head))
goto enable_all;
- if (tried_times >= 2) {
+ if (tried_times >= pci_try_num) {
/* still fail, don't need to try more */
free_list(&fail_head);
goto enable_all;
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Yinghai Lu <yinghai@kernel.org> |
|---|---|
| Date | 2015-08-21 09:30 +0200 |
| Subject | [PATCH v4 29/52] PCI: Unify calculate_size() for io port and MMIO |
| Message-ID | <pZOVZ-5dT-23@gated-at.bofh.it> |
| In reply to | #1210924 |
Now calculate_memsize() and calculate_iosize() is the same.
Change them to calculate_size().
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/pci/setup-bus.c | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index f3d89d1..2d26745 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1110,22 +1110,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus,
return NULL;
}
-static resource_size_t calculate_iosize(resource_size_t size,
- resource_size_t min_size,
- resource_size_t old_size,
- resource_size_t align)
-{
- if (size < min_size)
- size = min_size;
- if (old_size == 1)
- old_size = 0;
- size = ALIGN(size, align);
- if (size < old_size)
- size = old_size;
- return size;
-}
-
-static resource_size_t calculate_memsize(resource_size_t size,
+static resource_size_t calculate_size(resource_size_t size,
resource_size_t min_size,
resource_size_t old_size,
resource_size_t align)
@@ -1251,14 +1236,14 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,
size = size_aligned_for_isa(size);
size += size1;
- size0 = calculate_iosize(size, min_size,
+ size0 = calculate_size(size, min_size,
resource_size(b_res), min_align);
sum_add_size = size_aligned_for_isa(sum_add_size);
sum_add_size += sum_add_size1;
if (sum_add_size < min_sum_size)
sum_add_size = min_sum_size;
size1 = !realloc_head ? size0 :
- calculate_iosize(sum_add_size, min_size,
+ calculate_size(sum_add_size, min_size,
resource_size(b_res), min_align);
if (!size0 && !size1) {
if (b_res->start || b_res->end)
@@ -1611,7 +1596,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
if (size || min_size) {
min_align = calculate_mem_align(&align_test_list, max_align,
size, window_align);
- size0 = calculate_memsize(size, min_size,
+ size0 = calculate_size(size, min_size,
resource_size(b_res), min_align);
}
free_align_test_list(&align_test_list);
@@ -1636,7 +1621,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
min_add_align = calculate_mem_align(&align_test_add_list,
max_add_align, sum_add_size,
window_align);
- size1 = calculate_memsize(sum_add_size, min_size,
+ size1 = calculate_size(sum_add_size, min_size,
resource_size(b_res), min_add_align);
}
free_align_test_list(&align_test_add_list);
--
1.8.4.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web