* [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks
@ 2016-02-09 14:30 Thierry Reding
2016-02-09 14:30 ` [PATCH v2 2/2] PCI: tegra: Implement ->{add,remove}_bus() callbacks Thierry Reding
2016-03-08 21:43 ` [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks Bjorn Helgaas
0 siblings, 2 replies; 4+ messages in thread
From: Thierry Reding @ 2016-02-09 14:30 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: Stephen Warren, Alexandre Courbot, linux-pci, linux-tegra
From: Thierry Reding <treding@nvidia.com>
These callbacks will be called on every newly created bus and when a bus
is being removed, respectively. This can be used by drivers to implement
driver-specific initialization and teardown of the bus, in addition to
the architecture-specifics implemented by the pcibios_add_bus() and the
pcibios_remove_bus() functions.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
Changes in v2:
- add pci_ops.remove_bus() callback
- always call pcibios_add_bus()
drivers/pci/probe.c | 6 ++++++
drivers/pci/remove.c | 4 ++++
include/linux/pci.h | 2 ++
3 files changed, 12 insertions(+)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 6d7ab9bb0d5a..3ea4de1c6926 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -758,6 +758,12 @@ add_dev:
pcibios_add_bus(child);
+ if (child->ops->add_bus) {
+ ret = child->ops->add_bus(child);
+ if (WARN_ON(ret < 0))
+ dev_err(&child->dev, "failed to add bus: %d\n", ret);
+ }
+
/* Create legacy_io and legacy_mem files for this bus */
pci_create_legacy_files(child);
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 8a280e9c2ad1..d35c7fcde3af 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -54,6 +54,10 @@ void pci_remove_bus(struct pci_bus *bus)
pci_bus_release_busn_res(bus);
up_write(&pci_bus_sem);
pci_remove_legacy_files(bus);
+
+ if (bus->ops->remove_bus)
+ bus->ops->remove_bus(bus);
+
pcibios_remove_bus(bus);
device_unregister(&bus->dev);
}
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 27df4a6585da..0f7ef14c4d10 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -578,6 +578,8 @@ 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 (*remove_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.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] PCI: tegra: Implement ->{add,remove}_bus() callbacks
2016-02-09 14:30 [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks Thierry Reding
@ 2016-02-09 14:30 ` Thierry Reding
2016-03-08 21:44 ` Bjorn Helgaas
2016-03-08 21:43 ` [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks Bjorn Helgaas
1 sibling, 1 reply; 4+ messages in thread
From: Thierry Reding @ 2016-02-09 14:30 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.
Also add an implementation of ->remove_bus() that undoes the mapping
established by the ->add_bus() callback. While it isn't currently
possible to unload the module, there is work underway to remedy this,
and this code will come in handy when that happens.
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
Changes in v2:
- add ->remove_bus() callback implementation
drivers/pci/host/pci-tegra.c | 54 ++++++++++++++++++++++++++++----------------
1 file changed, 34 insertions(+), 20 deletions(-)
diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
index 30323114c53c..75c55265ca73 100644
--- a/drivers/pci/host/pci-tegra.c
+++ b/drivers/pci/host/pci-tegra.c
@@ -426,31 +426,38 @@ 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 0;
+}
- return (void __iomem *)bus->area->addr;
+static void tegra_pcie_remove_bus(struct pci_bus *child)
+{
+ struct tegra_pcie *pcie = sys_to_pcie(child->sysdata);
+ struct tegra_pcie_bus *bus, *tmp;
+
+ list_for_each_entry_safe(bus, tmp, &pcie->buses, list) {
+ if (bus->nr == child->number) {
+ vunmap(bus->area->addr);
+ list_del(&bus->list);
+ kfree(bus);
+ break;
+ }
+ }
}
-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 +473,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 +493,9 @@ 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,
+ .remove_bus = tegra_pcie_remove_bus,
+ .map_bus = tegra_pcie_map_bus,
.read = pci_generic_config_read32,
.write = pci_generic_config_write32,
};
--
2.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks
2016-02-09 14:30 [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks Thierry Reding
2016-02-09 14:30 ` [PATCH v2 2/2] PCI: tegra: Implement ->{add,remove}_bus() callbacks Thierry Reding
@ 2016-03-08 21:43 ` Bjorn Helgaas
1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2016-03-08 21:43 UTC (permalink / raw)
To: Thierry Reding
Cc: Bjorn Helgaas, Stephen Warren, Alexandre Courbot, linux-pci,
linux-tegra
On Tue, Feb 09, 2016 at 03:30:47PM +0100, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> These callbacks will be called on every newly created bus and when a bus
> is being removed, respectively. This can be used by drivers to implement
> driver-specific initialization and teardown of the bus, in addition to
> the architecture-specifics implemented by the pcibios_add_bus() and the
> pcibios_remove_bus() functions.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
Applied to pci/host-tegra for v4.6, thanks!
> ---
> Changes in v2:
> - add pci_ops.remove_bus() callback
> - always call pcibios_add_bus()
>
> drivers/pci/probe.c | 6 ++++++
> drivers/pci/remove.c | 4 ++++
> include/linux/pci.h | 2 ++
> 3 files changed, 12 insertions(+)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 6d7ab9bb0d5a..3ea4de1c6926 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -758,6 +758,12 @@ add_dev:
>
> pcibios_add_bus(child);
>
> + if (child->ops->add_bus) {
> + ret = child->ops->add_bus(child);
> + if (WARN_ON(ret < 0))
> + dev_err(&child->dev, "failed to add bus: %d\n", ret);
> + }
> +
> /* Create legacy_io and legacy_mem files for this bus */
> pci_create_legacy_files(child);
>
> diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
> index 8a280e9c2ad1..d35c7fcde3af 100644
> --- a/drivers/pci/remove.c
> +++ b/drivers/pci/remove.c
> @@ -54,6 +54,10 @@ void pci_remove_bus(struct pci_bus *bus)
> pci_bus_release_busn_res(bus);
> up_write(&pci_bus_sem);
> pci_remove_legacy_files(bus);
> +
> + if (bus->ops->remove_bus)
> + bus->ops->remove_bus(bus);
> +
> pcibios_remove_bus(bus);
> device_unregister(&bus->dev);
> }
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 27df4a6585da..0f7ef14c4d10 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -578,6 +578,8 @@ 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 (*remove_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.7.1
>
> --
> 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 v2 2/2] PCI: tegra: Implement ->{add,remove}_bus() callbacks
2016-02-09 14:30 ` [PATCH v2 2/2] PCI: tegra: Implement ->{add,remove}_bus() callbacks Thierry Reding
@ 2016-03-08 21:44 ` Bjorn Helgaas
0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2016-03-08 21:44 UTC (permalink / raw)
To: Thierry Reding
Cc: Bjorn Helgaas, Stephen Warren, Alexandre Courbot, linux-pci,
linux-tegra
On Tue, Feb 09, 2016 at 03:30:48PM +0100, Thierry Reding wrote:
> 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.
> Also add an implementation of ->remove_bus() that undoes the mapping
> established by the ->add_bus() callback. While it isn't currently
> possible to unload the module, there is work underway to remedy this,
> and this code will come in handy when that happens.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
Applied to pci/host-tegra for v4.6, thanks!
> ---
> Changes in v2:
> - add ->remove_bus() callback implementation
>
> drivers/pci/host/pci-tegra.c | 54 ++++++++++++++++++++++++++++----------------
> 1 file changed, 34 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
> index 30323114c53c..75c55265ca73 100644
> --- a/drivers/pci/host/pci-tegra.c
> +++ b/drivers/pci/host/pci-tegra.c
> @@ -426,31 +426,38 @@ 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 0;
> +}
>
> - return (void __iomem *)bus->area->addr;
> +static void tegra_pcie_remove_bus(struct pci_bus *child)
> +{
> + struct tegra_pcie *pcie = sys_to_pcie(child->sysdata);
> + struct tegra_pcie_bus *bus, *tmp;
> +
> + list_for_each_entry_safe(bus, tmp, &pcie->buses, list) {
> + if (bus->nr == child->number) {
> + vunmap(bus->area->addr);
> + list_del(&bus->list);
> + kfree(bus);
> + break;
> + }
> + }
> }
>
> -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 +473,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 +493,9 @@ 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,
> + .remove_bus = tegra_pcie_remove_bus,
> + .map_bus = tegra_pcie_map_bus,
> .read = pci_generic_config_read32,
> .write = pci_generic_config_write32,
> };
> --
> 2.7.1
>
> --
> 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:[~2016-03-08 21:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-09 14:30 [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks Thierry Reding
2016-02-09 14:30 ` [PATCH v2 2/2] PCI: tegra: Implement ->{add,remove}_bus() callbacks Thierry Reding
2016-03-08 21:44 ` Bjorn Helgaas
2016-03-08 21:43 ` [PATCH v2 1/2] PCI: Add pci_ops.{add,remove}_bus() callbacks 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).