diff mbox

[v7,03/60] sparc/PCI: Unify pci_register_region()

Message ID CAE9FiQXXP8-5hNvKXuh5mu6Xu_9yFufmpZaXv0V95TwBBnxCpA@mail.gmail.com
State Superseded
Headers show

Commit Message

Yinghai Lu Oct. 21, 2015, 6:16 p.m. UTC
On Tue, Oct 20, 2015 at 7:35 PM, Bjorn Helgaas <helgaas@kernel.org> wrote:
> On Tue, Oct 20, 2015 at 03:30:44PM -0700, Yinghai Lu wrote:
> I doubt I would agree with a change like this, but maybe, if you can
> explain what's unique about the sparc architecture that would require
> a change like this.

Then how about this one ?

otherwise we need to compare res with pbm->mem_space or pbm->mem64_space
to get direct parent for request_resource_conflict() calling in
pci_register_legacy_regions().

also check if if return is NULL to decide if it is valid region.
---
 drivers/pci/host-bridge.c |   10 +++++++++-
 include/linux/pci.h       |    5 +++--
 2 files changed, 12 insertions(+), 3 deletions(-)

 void pci_bus_add_devices(const struct pci_bus *bus);
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Bjorn Helgaas Oct. 21, 2015, 6:50 p.m. UTC | #1
On Wed, Oct 21, 2015 at 11:16:53AM -0700, Yinghai Lu wrote:
> On Tue, Oct 20, 2015 at 7:35 PM, Bjorn Helgaas <helgaas@kernel.org> wrote:
> > On Tue, Oct 20, 2015 at 03:30:44PM -0700, Yinghai Lu wrote:
> > I doubt I would agree with a change like this, but maybe, if you can
> > explain what's unique about the sparc architecture that would require
> > a change like this.
> 
> Then how about this one ?
> 
> otherwise we need to compare res with pbm->mem_space or pbm->mem64_space
> to get direct parent for request_resource_conflict() calling in
> pci_register_legacy_regions().

Lots of other architectures have both mem32 and mem64 apertures.  You
haven't explained what's unique about sparc yet.  Does
pci_find_parent_resource() not work on sparc?  If not, is that because the
resource tree looks different on sparc than on other architectures?  If so,
is that difference something intentional that we want to keep, or should we
converge on a single resource tree format across all architectures?

> also check if if return is NULL to decide if it is valid region.
> ---
>  drivers/pci/host-bridge.c |   10 +++++++++-
>  include/linux/pci.h       |    5 +++--
>  2 files changed, 12 insertions(+), 3 deletions(-)
> 
> Index: linux-2.6/drivers/pci/host-bridge.c
> ===================================================================
> --- linux-2.6.orig/drivers/pci/host-bridge.c
> +++ linux-2.6/drivers/pci/host-bridge.c
> @@ -70,12 +70,17 @@ static bool region_contains(struct pci_b
>      return region1->start <= region2->start && region1->end >= region2->end;
>  }
> 
> -void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
> +/*
> + * return host bridge window resource
> + */
> +struct resource *pcibios_bus_to_resource(struct pci_bus *bus,
> +                 struct resource *res,
>                   struct pci_bus_region *region)
>  {
>      struct pci_host_bridge *bridge = pci_find_host_bridge(bus);
>      struct resource_entry *window;
>      resource_size_t offset = 0;
> +    struct resource *res_ret = NULL;
> 
>      resource_list_for_each_entry(window, &bridge->windows) {
>          struct pci_bus_region bus_region;
> @@ -88,11 +93,14 @@ void pcibios_bus_to_resource(struct pci_
> 
>          if (region_contains(&bus_region, region)) {
>              offset = window->offset;
> +            res_ret = window->res;
>              break;
>          }
>      }
> 
>      res->start = region->start + offset;
>      res->end = region->end + offset;
> +
> +    return res_ret;
>  }
>  EXPORT_SYMBOL(pcibios_bus_to_resource);
> Index: linux-2.6/include/linux/pci.h
> ===================================================================
> --- linux-2.6.orig/include/linux/pci.h
> +++ linux-2.6/include/linux/pci.h
> @@ -781,8 +781,9 @@ void pci_fixup_cardbus(struct pci_bus *)
> 
>  void pcibios_resource_to_bus(struct pci_bus *bus, struct
> pci_bus_region *region,
>                   struct resource *res);
> -void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
> -                 struct pci_bus_region *region);
> +struct resource *pcibios_bus_to_resource(struct pci_bus *bus,
> +                     struct resource *res,
> +                     struct pci_bus_region *region);
>  void pcibios_scan_specific_bus(int busn);
>  struct pci_bus *pci_find_bus(int domain, int busnr);
>  void pci_bus_add_devices(const struct pci_bus *bus);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Oct. 22, 2015, 1:27 a.m. UTC | #2
From: Yinghai Lu <yinghai@kernel.org>
Date: Wed, 21 Oct 2015 11:16:53 -0700

> otherwise we need to compare res with pbm->mem_space or pbm->mem64_space
> to get direct parent for request_resource_conflict() calling in
> pci_register_legacy_regions().

Right, this is the issue.

On sparc64, the cpu physical base address used for accessing 64-bit
and non-64-bit memory spaces is different.

And that's why the resource values will be different.

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Benjamin Herrenschmidt Oct. 22, 2015, 3:47 a.m. UTC | #3
On Wed, 2015-10-21 at 18:27 -0700, David Miller wrote:
> From: Yinghai Lu <yinghai@kernel.org>
> Date: Wed, 21 Oct 2015 11:16:53 -0700
> 
> > otherwise we need to compare res with pbm->mem_space or pbm
> ->mem64_space
> > to get direct parent for request_resource_conflict() calling in
> > pci_register_legacy_regions().
> 
> Right, this is the issue.
> 
> On sparc64, the cpu physical base address used for accessing 64-bit
> and non-64-bit memory spaces is different.
> 
> And that's why the resource values will be different.

This is the same on power btw, we have separate PowerBus windows to the
PHB that get mapped respectively to 32-bit PCI MMIO and 64-bit PCI
MMIO. The former gets "remapped" to generates 0-based PCI cycles, while
the latter is 1:1. So the offset between CPU and PCI changes depending
on which window you hit.

Cheers,
Ben.

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas Oct. 23, 2015, 5:38 a.m. UTC | #4
On Thu, Oct 22, 2015 at 02:47:42PM +1100, Benjamin Herrenschmidt wrote:
> On Wed, 2015-10-21 at 18:27 -0700, David Miller wrote:
> > From: Yinghai Lu <yinghai@kernel.org>
> > Date: Wed, 21 Oct 2015 11:16:53 -0700
> > 
> > > otherwise we need to compare res with pbm->mem_space or pbm
> > ->mem64_space
> > > to get direct parent for request_resource_conflict() calling in
> > > pci_register_legacy_regions().
> > 
> > Right, this is the issue.
> > 
> > On sparc64, the cpu physical base address used for accessing 64-bit
> > and non-64-bit memory spaces is different.
> > 
> > And that's why the resource values will be different.
> 
> This is the same on power btw, we have separate PowerBus windows to the
> PHB that get mapped respectively to 32-bit PCI MMIO and 64-bit PCI
> MMIO. The former gets "remapped" to generates 0-based PCI cycles, while
> the latter is 1:1. So the offset between CPU and PCI changes depending
> on which window you hit.

Lots of architectures do this, and the PCI core supports it by keeping
a list of all the host bridge windows.  Each entry has a struct
resource that contains the CPU address, as well as the offset from the
CPU address to the PCI address.  The arch or host bridge driver uses
pci_add_resource_offset() to tell the core about the window and the
offset.

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

Index: linux-2.6/drivers/pci/host-bridge.c
===================================================================
--- linux-2.6.orig/drivers/pci/host-bridge.c
+++ linux-2.6/drivers/pci/host-bridge.c
@@ -70,12 +70,17 @@  static bool region_contains(struct pci_b
     return region1->start <= region2->start && region1->end >= region2->end;
 }

-void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
+/*
+ * return host bridge window resource
+ */
+struct resource *pcibios_bus_to_resource(struct pci_bus *bus,
+                 struct resource *res,
                  struct pci_bus_region *region)
 {
     struct pci_host_bridge *bridge = pci_find_host_bridge(bus);
     struct resource_entry *window;
     resource_size_t offset = 0;
+    struct resource *res_ret = NULL;

     resource_list_for_each_entry(window, &bridge->windows) {
         struct pci_bus_region bus_region;
@@ -88,11 +93,14 @@  void pcibios_bus_to_resource(struct pci_

         if (region_contains(&bus_region, region)) {
             offset = window->offset;
+            res_ret = window->res;
             break;
         }
     }

     res->start = region->start + offset;
     res->end = region->end + offset;
+
+    return res_ret;
 }
 EXPORT_SYMBOL(pcibios_bus_to_resource);
Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -781,8 +781,9 @@  void pci_fixup_cardbus(struct pci_bus *)

 void pcibios_resource_to_bus(struct pci_bus *bus, struct
pci_bus_region *region,
                  struct resource *res);
-void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
-                 struct pci_bus_region *region);
+struct resource *pcibios_bus_to_resource(struct pci_bus *bus,
+                     struct resource *res,
+                     struct pci_bus_region *region);
 void pcibios_scan_specific_bus(int busn);
 struct pci_bus *pci_find_bus(int domain, int busnr);