Re: [PATCH v4 3/5] PCI: Handle IORESOURCE_PCI_FIXED when sizing and assigning resources.

2015-10-06 Thread David Daney

On 10/05/2015 03:23 PM, Sean O. Stalley wrote:

On Fri, Oct 02, 2015 at 03:37:54PM -0700, David Daney wrote:

...


+/*
+ * Try to assign any resources marked as IORESOURCE_PCI_FIXED, as they
+ * are skipped by pbus_assign_resources_sorted().
+ */
+static void pdev_assign_fixed_resources(struct pci_dev *dev)
+{
+   int i;
+
+   for (i = 0; i <  PCI_NUM_RESOURCES; i++) {
+   struct pci_bus *b;
+   struct resource *r = &dev->resource[i];
+
+   if (r->parent || !(r->flags & IORESOURCE_PCI_FIXED) ||
+   !(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
+   continue;
+
+   b = dev->bus;
+   while (b && !r->parent) {
+   assign_fixed_resource_on_bus(b, r);
+   b = b->parent;
+   }
+   if (!r->parent) {
+   /*
+* If that didn't work, try to fallback to the
+* ultimate parent.
+*/
+   if (r->flags &  IORESOURCE_IO)
+   request_resource(&ioport_resource, r);
+   else
+   request_resource(&iomem_resource, r);
+   }


I don't think this check is necessary.
assign_fixed_resource_on_bus() should find these resources when it reaches the 
top bus.
(since since the root bus contains these resources).


You are correct.  It does work fine without that last fallback bit.  I 
will remove that, and re-send the patches.


Thanks,
David Daney






+   }
+}


-Sean



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 3/5] PCI: Handle IORESOURCE_PCI_FIXED when sizing and assigning resources.

2015-10-05 Thread Sean O. Stalley
On Fri, Oct 02, 2015 at 08:00:20PM -0700, Yinghai Lu wrote:
> On Fri, Oct 2, 2015 at 4:38 PM, David Daney  wrote:
> > On 10/02/2015 04:14 PM, Yinghai Lu wrote:
> >>
> >> https://patchwork.kernel.org/patch/7304371/
> >> [v6,06/53] PCI: Claim fixed resource during remove/rescan path
> >
> >
> > This one is interesting, but I don't think it will work.
> >
> > pci_claim_resource() calls pci_find_parent_resource(), which will fail in
> > important use cases.
> >
> > It is perfectly legal for a bridge provisioned by EA to not specify any
> > resources.  In this case we must walk up the bus tree until we find
> > something that contains the device resource, and can thus be a parent.
> >
> > That is a big part of what my patch is doing.
> 
> looks we need another resource flags for EA in addition to
> FIXED as it could out side of bridge MMIO range.

I think I get what you are saying, but let me check.

If a bridge gets reconfigured, it needs to be able to tell if this resource is 
EA or not.
If it is a fixed EA resource, it doesn't need to include it in its MMIO range.
If it is fixed for some other reason,
we should make sure the bridges MMIO range includes the fixed region.

You are suggesting that we should add a flag for EA, so if a bridge tries to 
move,
the bridge knows weather or not the resource is EA,
and therefore if it needs to worry about the resource when setting it's range?

Is that what you are trying to say?

-Sean
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 3/5] PCI: Handle IORESOURCE_PCI_FIXED when sizing and assigning resources.

2015-10-05 Thread Sean O. Stalley
On Fri, Oct 02, 2015 at 03:37:54PM -0700, David Daney wrote:

...

> +/*
> + * Try to assign any resources marked as IORESOURCE_PCI_FIXED, as they
> + * are skipped by pbus_assign_resources_sorted().
> + */
> +static void pdev_assign_fixed_resources(struct pci_dev *dev)
> +{
> + int i;
> +
> + for (i = 0; i <  PCI_NUM_RESOURCES; i++) {
> + struct pci_bus *b;
> + struct resource *r = &dev->resource[i];
> +
> + if (r->parent || !(r->flags & IORESOURCE_PCI_FIXED) ||
> + !(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
> + continue;
> +
> + b = dev->bus;
> + while (b && !r->parent) {
> + assign_fixed_resource_on_bus(b, r);
> + b = b->parent;
> + }
> + if (!r->parent) {
> + /*
> +  * If that didn't work, try to fallback to the
> +  * ultimate parent.
> +  */
> + if (r->flags &  IORESOURCE_IO)
> + request_resource(&ioport_resource, r);
> + else
> + request_resource(&iomem_resource, r);
> + }

I don't think this check is necessary.
assign_fixed_resource_on_bus() should find these resources when it reaches the 
top bus.
(since since the root bus contains these resources).

> + }
> +}

-Sean
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 3/5] PCI: Handle IORESOURCE_PCI_FIXED when sizing and assigning resources.

2015-10-02 Thread Yinghai Lu
On Fri, Oct 2, 2015 at 4:38 PM, David Daney  wrote:
> On 10/02/2015 04:14 PM, Yinghai Lu wrote:
>>
>> https://patchwork.kernel.org/patch/7304371/
>> [v6,06/53] PCI: Claim fixed resource during remove/rescan path
>
>
> This one is interesting, but I don't think it will work.
>
> pci_claim_resource() calls pci_find_parent_resource(), which will fail in
> important use cases.
>
> It is perfectly legal for a bridge provisioned by EA to not specify any
> resources.  In this case we must walk up the bus tree until we find
> something that contains the device resource, and can thus be a parent.
>
> That is a big part of what my patch is doing.

looks we need another resource flags for EA in addition to
FIXED as it could out side of bridge MMIO range.

>
> As for the merits of assigning fixed resources from the FINAL fixup, rather
> than in __pci_bus_assign_resources(), I am unsure.

usually __pci_bus_assign_resources() is used for unassigned one. so
I don't want it mixed with request resource there.

Thanks

Yinghai
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 3/5] PCI: Handle IORESOURCE_PCI_FIXED when sizing and assigning resources.

2015-10-02 Thread David Daney

On 10/02/2015 04:14 PM, Yinghai Lu wrote:

On Fri, Oct 2, 2015 at 3:37 PM, David Daney  wrote:

From: David Daney 

The new Enhanced Allocation (EA) capability support creates resources
with the IORESOURCE_PCI_FIXED set.  This creates a couple of problems:

1) Since these resources cannot be relocated or resized, their
alignment is not really defined, and it is therefore not specified.
This causes a problem in pbus_size_mem() where resources with
unspecified alignment are disabled.

2) During resource assignment in pci_bus_assign_resources(),
IORESOURCE_PCI_FIXED resources are not given a parent.  This, in
turn, causes pci_enable_resources() to fail with a "not claimed"
error.

So, in pbus_size_mem() skip IORESOURCE_PCI_FIXED resources, instead of
disabling them.

In __pci_bus_assign_resources(), for IORESOURCE_PCI_FIXED resources,
try to request the resource from a parent bus.


Can you check if

https://patchwork.kernel.org/patch/7304971/
[v6,05/53] PCI: Don't release fixed resource for realloc



This one isn't relevant as the problem is seen when we are acquiring 
resources, not releasing them.




https://patchwork.kernel.org/patch/7304371/
[v6,06/53] PCI: Claim fixed resource during remove/rescan path


This one is interesting, but I don't think it will work.

pci_claim_resource() calls pci_find_parent_resource(), which will fail 
in important use cases.


It is perfectly legal for a bridge provisioned by EA to not specify any 
resources.  In this case we must walk up the bus tree until we find 
something that contains the device resource, and can thus be a parent.


That is a big part of what my patch is doing.

As for the merits of assigning fixed resources from the FINAL fixup, 
rather than in __pci_bus_assign_resources(), I am unsure.


Thanks,
David Daney




address the the problem that you met?

 Yinghai



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 3/5] PCI: Handle IORESOURCE_PCI_FIXED when sizing and assigning resources.

2015-10-02 Thread Yinghai Lu
On Fri, Oct 2, 2015 at 3:37 PM, David Daney  wrote:
> From: David Daney 
>
> The new Enhanced Allocation (EA) capability support creates resources
> with the IORESOURCE_PCI_FIXED set.  This creates a couple of problems:
>
> 1) Since these resources cannot be relocated or resized, their
>alignment is not really defined, and it is therefore not specified.
>This causes a problem in pbus_size_mem() where resources with
>unspecified alignment are disabled.
>
> 2) During resource assignment in pci_bus_assign_resources(),
>IORESOURCE_PCI_FIXED resources are not given a parent.  This, in
>turn, causes pci_enable_resources() to fail with a "not claimed"
>error.
>
> So, in pbus_size_mem() skip IORESOURCE_PCI_FIXED resources, instead of
> disabling them.
>
> In __pci_bus_assign_resources(), for IORESOURCE_PCI_FIXED resources,
> try to request the resource from a parent bus.

Can you check if

https://patchwork.kernel.org/patch/7304971/
[v6,05/53] PCI: Don't release fixed resource for realloc

https://patchwork.kernel.org/patch/7304371/
[v6,06/53] PCI: Claim fixed resource during remove/rescan path

address the the problem that you met?

Yinghai
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 3/5] PCI: Handle IORESOURCE_PCI_FIXED when sizing and assigning resources.

2015-10-02 Thread David Daney
From: David Daney 

The new Enhanced Allocation (EA) capability support creates resources
with the IORESOURCE_PCI_FIXED set.  This creates a couple of problems:

1) Since these resources cannot be relocated or resized, their
   alignment is not really defined, and it is therefore not specified.
   This causes a problem in pbus_size_mem() where resources with
   unspecified alignment are disabled.

2) During resource assignment in pci_bus_assign_resources(),
   IORESOURCE_PCI_FIXED resources are not given a parent.  This, in
   turn, causes pci_enable_resources() to fail with a "not claimed"
   error.

So, in pbus_size_mem() skip IORESOURCE_PCI_FIXED resources, instead of
disabling them.

In __pci_bus_assign_resources(), for IORESOURCE_PCI_FIXED resources,
try to request the resource from a parent bus.

Signed-off-by: David Daney 
---
 drivers/pci/setup-bus.c | 60 ++---
 1 file changed, 57 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 508cc56..8f9ed9b 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1037,9 +1037,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned 
long mask,
struct resource *r = &dev->resource[i];
resource_size_t r_size;
 
-   if (r->parent || ((r->flags & mask) != type &&
- (r->flags & mask) != type2 &&
- (r->flags & mask) != type3))
+   if (r->parent || (r->flags | IORESOURCE_PCI_FIXED) ||
+   ((r->flags & mask) != type &&
+(r->flags & mask) != type2 &&
+(r->flags & mask) != type3))
continue;
r_size = resource_size(r);
 #ifdef CONFIG_PCI_IOV
@@ -1340,6 +1341,57 @@ void pci_bus_size_bridges(struct pci_bus *bus)
 }
 EXPORT_SYMBOL(pci_bus_size_bridges);
 
+static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r)
+{
+   int i;
+   struct resource *parent_r;
+   unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM |
+   IORESOURCE_PREFETCH;
+
+   pci_bus_for_each_resource(b, parent_r, i) {
+   if (!parent_r)
+   continue;
+
+   if ((r->flags & mask) == (parent_r->flags & mask) &&
+   resource_contains(parent_r, r))
+   request_resource(parent_r, r);
+   }
+}
+
+/*
+ * Try to assign any resources marked as IORESOURCE_PCI_FIXED, as they
+ * are skipped by pbus_assign_resources_sorted().
+ */
+static void pdev_assign_fixed_resources(struct pci_dev *dev)
+{
+   int i;
+
+   for (i = 0; i <  PCI_NUM_RESOURCES; i++) {
+   struct pci_bus *b;
+   struct resource *r = &dev->resource[i];
+
+   if (r->parent || !(r->flags & IORESOURCE_PCI_FIXED) ||
+   !(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
+   continue;
+
+   b = dev->bus;
+   while (b && !r->parent) {
+   assign_fixed_resource_on_bus(b, r);
+   b = b->parent;
+   }
+   if (!r->parent) {
+   /*
+* If that didn't work, try to fallback to the
+* ultimate parent.
+*/
+   if (r->flags &  IORESOURCE_IO)
+   request_resource(&ioport_resource, r);
+   else
+   request_resource(&iomem_resource, r);
+   }
+   }
+}
+
 void __pci_bus_assign_resources(const struct pci_bus *bus,
struct list_head *realloc_head,
struct list_head *fail_head)
@@ -1350,6 +1402,8 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,
pbus_assign_resources_sorted(bus, realloc_head, fail_head);
 
list_for_each_entry(dev, &bus->devices, bus_list) {
+   pdev_assign_fixed_resources(dev);
+
b = dev->subordinate;
if (!b)
continue;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/