* [PATCH 1/2] PCI: Add pci_ops.add_bus() callback
@ 2015-11-23 12:40 Thierry Reding
2015-11-23 12:40 ` [PATCH 2/2] PCI: tegra: Implement ->add_bus() callback Thierry Reding
2015-12-04 19:50 ` [PATCH 1/2] PCI: Add pci_ops.add_bus() callback Bjorn Helgaas
0 siblings, 2 replies; 4+ messages in thread
From: Thierry Reding @ 2015-11-23 12:40 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: Stephen Warren, Alexandre Courbot, linux-pci, linux-tegra
From: Thierry Reding <treding@nvidia.com>
This callback will be called on every newly created bus. Drivers can
implement it to perform driver-specific initialization of the bus.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/pci/probe.c | 8 +++++++-
include/linux/pci.h | 1 +
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index e735c728e3b3..fbed432f8915 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -754,7 +754,13 @@ add_dev:
ret = device_register(&child->dev);
WARN_ON(ret < 0);
- pcibios_add_bus(child);
+ if (child->ops->add_bus) {
+ ret = child->ops->add_bus(child);
+ if (ret < 0)
+ dev_err(&child->dev, "failed to add bus: %d\n", ret);
+ } else {
+ pcibios_add_bus(child);
+ }
/* Create legacy_io and legacy_mem files for this bus */
pci_create_legacy_files(child);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index e828e7b4afec..70c1228d585f 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -569,6 +569,7 @@ static inline int pcibios_err_to_errno(int err)
/* Low-level architecture-dependent routines */
struct pci_ops {
+ int (*add_bus)(struct pci_bus *bus);
void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] PCI: tegra: Implement ->add_bus() callback
2015-11-23 12:40 [PATCH 1/2] PCI: Add pci_ops.add_bus() callback Thierry Reding
@ 2015-11-23 12:40 ` Thierry Reding
2015-12-04 20:01 ` Bjorn Helgaas
2015-12-04 19:50 ` [PATCH 1/2] PCI: Add pci_ops.add_bus() callback Bjorn Helgaas
1 sibling, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2015-11-23 12:40 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: Stephen Warren, Alexandre Courbot, linux-pci, linux-tegra
From: Thierry Reding <treding@nvidia.com>
The configuration space mapping on Tegra is somewhat special, and in
order to avoid wasting virtual address space the configuration space
for each bus needs to be stitched together from several blocks which
form a single continuous virtual address range for accessors.
Currently the configuration space is mapped upon the first access to
one of its registers. However, the mapping operation may sleep under
certain circumstances, so doing it from the configuration space
accessors (they are protected by a spin lock) will trigger a warning.
To avoid the warning, use the ->add_bus() callback to perform the
mapping at enumeration time when the operation is allowed to sleep.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
drivers/pci/host/pci-tegra.c | 40 +++++++++++++++++++---------------------
1 file changed, 19 insertions(+), 21 deletions(-)
diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
index 3018ae52e092..c3666f9d7ef1 100644
--- a/drivers/pci/host/pci-tegra.c
+++ b/drivers/pci/host/pci-tegra.c
@@ -426,31 +426,23 @@ free:
return ERR_PTR(err);
}
-/*
- * Look up a virtual address mapping for the specified bus number. If no such
- * mapping exists, try to create one.
- */
-static void __iomem *tegra_pcie_bus_map(struct tegra_pcie *pcie,
- unsigned int busnr)
+static int tegra_pcie_add_bus(struct pci_bus *bus)
{
- struct tegra_pcie_bus *bus;
+ struct tegra_pcie *pcie = sys_to_pcie(bus->sysdata);
+ struct tegra_pcie_bus *b;
- list_for_each_entry(bus, &pcie->buses, list)
- if (bus->nr == busnr)
- return (void __iomem *)bus->area->addr;
+ b = tegra_pcie_bus_alloc(pcie, bus->number);
+ if (IS_ERR(b))
+ return PTR_ERR(b);
- bus = tegra_pcie_bus_alloc(pcie, busnr);
- if (IS_ERR(bus))
- return NULL;
+ list_add_tail(&b->list, &pcie->buses);
- list_add_tail(&bus->list, &pcie->buses);
-
- return (void __iomem *)bus->area->addr;
+ return 0;
}
-static void __iomem *tegra_pcie_conf_address(struct pci_bus *bus,
- unsigned int devfn,
- int where)
+static void __iomem *tegra_pcie_map_bus(struct pci_bus *bus,
+ unsigned int devfn,
+ int where)
{
struct tegra_pcie *pcie = sys_to_pcie(bus->sysdata);
void __iomem *addr = NULL;
@@ -466,7 +458,12 @@ static void __iomem *tegra_pcie_conf_address(struct pci_bus *bus,
}
}
} else {
- addr = tegra_pcie_bus_map(pcie, bus->number);
+ struct tegra_pcie_bus *b;
+
+ list_for_each_entry(b, &pcie->buses, list)
+ if (b->nr == bus->number)
+ addr = (void __iomem *)b->area->addr;
+
if (!addr) {
dev_err(pcie->dev,
"failed to map cfg. space for bus %u\n",
@@ -481,7 +478,8 @@ static void __iomem *tegra_pcie_conf_address(struct pci_bus *bus,
}
static struct pci_ops tegra_pcie_ops = {
- .map_bus = tegra_pcie_conf_address,
+ .add_bus = tegra_pcie_add_bus,
+ .map_bus = tegra_pcie_map_bus,
.read = pci_generic_config_read32,
.write = pci_generic_config_write32,
};
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] PCI: Add pci_ops.add_bus() callback
2015-11-23 12:40 [PATCH 1/2] PCI: Add pci_ops.add_bus() callback Thierry Reding
2015-11-23 12:40 ` [PATCH 2/2] PCI: tegra: Implement ->add_bus() callback Thierry Reding
@ 2015-12-04 19:50 ` Bjorn Helgaas
1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2015-12-04 19:50 UTC (permalink / raw)
To: Thierry Reding
Cc: Bjorn Helgaas, Stephen Warren, Alexandre Courbot, linux-pci,
linux-tegra
Hi Thierry,
On Mon, Nov 23, 2015 at 01:40:25PM +0100, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> This callback will be called on every newly created bus. Drivers can
> implement it to perform driver-specific initialization of the bus.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> drivers/pci/probe.c | 8 +++++++-
> include/linux/pci.h | 1 +
> 2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index e735c728e3b3..fbed432f8915 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -754,7 +754,13 @@ add_dev:
> ret = device_register(&child->dev);
> WARN_ON(ret < 0);
>
> - pcibios_add_bus(child);
> + if (child->ops->add_bus) {
> + ret = child->ops->add_bus(child);
> + if (ret < 0)
> + dev_err(&child->dev, "failed to add bus: %d\n", ret);
> + } else {
> + pcibios_add_bus(child);
> + }
pcibios_add_bus() does arch-specific things. child->ops->add_bus()
does driver-specific things. I think these are orthogonal, so I think
we want to *always* call pcibios_add_bus(), don't we?
> /* Create legacy_io and legacy_mem files for this bus */
> pci_create_legacy_files(child);
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index e828e7b4afec..70c1228d585f 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -569,6 +569,7 @@ static inline int pcibios_err_to_errno(int err)
> /* Low-level architecture-dependent routines */
>
> struct pci_ops {
> + int (*add_bus)(struct pci_bus *bus);
> void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
> int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
> int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
> --
> 2.5.0
>
> --
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] PCI: tegra: Implement ->add_bus() callback
2015-11-23 12:40 ` [PATCH 2/2] PCI: tegra: Implement ->add_bus() callback Thierry Reding
@ 2015-12-04 20:01 ` Bjorn Helgaas
0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2015-12-04 20:01 UTC (permalink / raw)
To: Thierry Reding
Cc: Bjorn Helgaas, Stephen Warren, Alexandre Courbot, linux-pci,
linux-tegra
On Mon, Nov 23, 2015 at 01:40:26PM +0100, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> The configuration space mapping on Tegra is somewhat special, and in
It'd be nice to have a tiny hint about specifically what is special
about Tegra config space mapping.
> order to avoid wasting virtual address space the configuration space
> for each bus needs to be stitched together from several blocks which
> form a single continuous virtual address range for accessors.
>
> Currently the configuration space is mapped upon the first access to
> one of its registers. However, the mapping operation may sleep under
> certain circumstances, so doing it from the configuration space
> accessors (they are protected by a spin lock) will trigger a warning.
Can you include the exact warning? Does it happen always? Always on
the first config access to a bus?
> To avoid the warning, use the ->add_bus() callback to perform the
> mapping at enumeration time when the operation is allowed to sleep.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
> drivers/pci/host/pci-tegra.c | 40 +++++++++++++++++++---------------------
> 1 file changed, 19 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
> index 3018ae52e092..c3666f9d7ef1 100644
> --- a/drivers/pci/host/pci-tegra.c
> +++ b/drivers/pci/host/pci-tegra.c
> @@ -426,31 +426,23 @@ free:
> return ERR_PTR(err);
> }
>
> -/*
> - * Look up a virtual address mapping for the specified bus number. If no such
> - * mapping exists, try to create one.
> - */
> -static void __iomem *tegra_pcie_bus_map(struct tegra_pcie *pcie,
> - unsigned int busnr)
> +static int tegra_pcie_add_bus(struct pci_bus *bus)
> {
> - struct tegra_pcie_bus *bus;
> + struct tegra_pcie *pcie = sys_to_pcie(bus->sysdata);
> + struct tegra_pcie_bus *b;
>
> - list_for_each_entry(bus, &pcie->buses, list)
> - if (bus->nr == busnr)
> - return (void __iomem *)bus->area->addr;
> + b = tegra_pcie_bus_alloc(pcie, bus->number);
> + if (IS_ERR(b))
> + return PTR_ERR(b);
>
> - bus = tegra_pcie_bus_alloc(pcie, busnr);
> - if (IS_ERR(bus))
> - return NULL;
> + list_add_tail(&b->list, &pcie->buses);
>
> - list_add_tail(&bus->list, &pcie->buses);
> -
> - return (void __iomem *)bus->area->addr;
> + return 0;
> }
>
> -static void __iomem *tegra_pcie_conf_address(struct pci_bus *bus,
> - unsigned int devfn,
> - int where)
> +static void __iomem *tegra_pcie_map_bus(struct pci_bus *bus,
> + unsigned int devfn,
> + int where)
> {
> struct tegra_pcie *pcie = sys_to_pcie(bus->sysdata);
> void __iomem *addr = NULL;
> @@ -466,7 +458,12 @@ static void __iomem *tegra_pcie_conf_address(struct pci_bus *bus,
> }
> }
> } else {
> - addr = tegra_pcie_bus_map(pcie, bus->number);
> + struct tegra_pcie_bus *b;
> +
> + list_for_each_entry(b, &pcie->buses, list)
> + if (b->nr == bus->number)
> + addr = (void __iomem *)b->area->addr;
> +
> if (!addr) {
> dev_err(pcie->dev,
> "failed to map cfg. space for bus %u\n",
> @@ -481,7 +478,8 @@ static void __iomem *tegra_pcie_conf_address(struct pci_bus *bus,
> }
>
> static struct pci_ops tegra_pcie_ops = {
> - .map_bus = tegra_pcie_conf_address,
> + .add_bus = tegra_pcie_add_bus,
> + .map_bus = tegra_pcie_map_bus,
> .read = pci_generic_config_read32,
> .write = pci_generic_config_write32,
> };
> --
> 2.5.0
>
> --
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-12-04 20:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-23 12:40 [PATCH 1/2] PCI: Add pci_ops.add_bus() callback Thierry Reding
2015-11-23 12:40 ` [PATCH 2/2] PCI: tegra: Implement ->add_bus() callback Thierry Reding
2015-12-04 20:01 ` Bjorn Helgaas
2015-12-04 19:50 ` [PATCH 1/2] PCI: Add pci_ops.add_bus() callback Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).