linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] PCI: dwc: Support remove
@ 2019-03-18  9:53 Jisheng Zhang
  2019-03-18  9:53 ` [PATCH v3 1/5] PCI: dwc: Fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18  9:53 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

Currently, the PCI dwc host users don't support the remove, but nothing
prevent us from supporting it. To achieve this goal, we need to ensure
we can do necessary clean up work.

Changes since v2:
  - address all Gustavo's comments
  - add Gustavo's ACK to patch1, patch3, patch4

Changes since v1:
  - address Bjorn's comments, I.E Capitalize, s/irq/IRQ/, s/msi/MSI/

Jisheng Zhang (5):
  PCI: dwc: Fix dw_pcie_free_msi() if msi_irq is invalid
  PCI: dwc: Free the page for MSI IRQ in dw_pcie_free_msi()
  PCI: dwc: Free MSI in the error code path of dw_pcie_host_init()
  PCI: dwc: Use devm_pci_alloc_host_bridge() to simplify the code
  PCI: dwc: Save root bus for driver remove

 .../pci/controller/dwc/pcie-designware-host.c | 59 ++++++++++---------
 drivers/pci/controller/dwc/pcie-designware.h  |  2 +
 2 files changed, 34 insertions(+), 27 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3 1/5] PCI: dwc: Fix dw_pcie_free_msi() if msi_irq is invalid
  2019-03-18  9:53 [PATCH v3 0/5] PCI: dwc: Support remove Jisheng Zhang
@ 2019-03-18  9:53 ` Jisheng Zhang
  2019-03-18  9:54 ` [PATCH v3 2/5] PCI: dwc: Free the page for MSI IRQ in dw_pcie_free_msi() Jisheng Zhang
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18  9:53 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

We should check msi_irq before calling irq_set_chained_handler() and
irq_set_handler_data().

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 25087d3c9a82..1040939f45b4 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -298,8 +298,10 @@ int dw_pcie_allocate_domains(struct pcie_port *pp)
 
 void dw_pcie_free_msi(struct pcie_port *pp)
 {
-	irq_set_chained_handler(pp->msi_irq, NULL);
-	irq_set_handler_data(pp->msi_irq, NULL);
+	if (pp->msi_irq) {
+		irq_set_chained_handler(pp->msi_irq, NULL);
+		irq_set_handler_data(pp->msi_irq, NULL);
+	}
 
 	irq_domain_remove(pp->msi_domain);
 	irq_domain_remove(pp->irq_domain);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 2/5] PCI: dwc: Free the page for MSI IRQ in dw_pcie_free_msi()
  2019-03-18  9:53 [PATCH v3 0/5] PCI: dwc: Support remove Jisheng Zhang
  2019-03-18  9:53 ` [PATCH v3 1/5] PCI: dwc: Fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
@ 2019-03-18  9:54 ` Jisheng Zhang
  2019-03-18 10:03   ` Gustavo Pimentel
  2019-03-18  9:55 ` PCI: dwc: Free MSI in the error code path of dw_pcie_host_init() Jisheng Zhang
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18  9:54 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

To avoid memory leak, we need to free the page for MSI in
dw_pcie_free_msi().

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++++----
 drivers/pci/controller/dwc/pcie-designware.h      |  1 +
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 1040939f45b4..a71b874ae3c0 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -305,20 +305,24 @@ void dw_pcie_free_msi(struct pcie_port *pp)
 
 	irq_domain_remove(pp->msi_domain);
 	irq_domain_remove(pp->irq_domain);
+
+	if (pp->msi_page)
+		__free_page(pp->msi_page);
 }
 
 void dw_pcie_msi_init(struct pcie_port *pp)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 	struct device *dev = pci->dev;
-	struct page *page;
 	u64 msi_target;
 
-	page = alloc_page(GFP_KERNEL);
-	pp->msi_data = dma_map_page(dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
+	pp->msi_page = alloc_page(GFP_KERNEL);
+	pp->msi_data = dma_map_page(dev, pp->msi_page, 0, PAGE_SIZE,
+				    DMA_FROM_DEVICE);
 	if (dma_mapping_error(dev, pp->msi_data)) {
 		dev_err(dev, "Failed to map MSI data\n");
-		__free_page(page);
+		__free_page(pp->msi_page);
+		pp->msi_page = NULL;
 		return;
 	}
 	msi_target = (u64)pp->msi_data;
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 377f4c0b52da..6fb0a1879932 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -179,6 +179,7 @@ struct pcie_port {
 	struct irq_domain	*irq_domain;
 	struct irq_domain	*msi_domain;
 	dma_addr_t		msi_data;
+	struct page		*msi_page;
 	u32			num_vectors;
 	u32			irq_mask[MAX_MSI_CTRLS];
 	raw_spinlock_t		lock;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* PCI: dwc: Free MSI in the error code path of dw_pcie_host_init()
  2019-03-18  9:53 [PATCH v3 0/5] PCI: dwc: Support remove Jisheng Zhang
  2019-03-18  9:53 ` [PATCH v3 1/5] PCI: dwc: Fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
  2019-03-18  9:54 ` [PATCH v3 2/5] PCI: dwc: Free the page for MSI IRQ in dw_pcie_free_msi() Jisheng Zhang
@ 2019-03-18  9:55 ` Jisheng Zhang
  2019-03-18 10:00   ` Jisheng Zhang
  2019-03-18  9:56 ` [PATCH v3 3/5] " Jisheng Zhang
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18  9:55 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

If we ever did some msi related initializations, we need to call
dw_pcie_free_msi() in the error code path.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index a71b874ae3c0..585080699675 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -483,7 +483,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	if (pp->ops->host_init) {
 		ret = pp->ops->host_init(pp);
 		if (ret)
-			goto error;
+			goto err_free_msi;
 	}
 
 	pp->root_bus_nr = pp->busn->start;
@@ -497,7 +497,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 
 	ret = pci_scan_root_bus_bridge(bridge);
 	if (ret)
-		goto error;
+		goto err_free_msi;
 
 	bus = bridge->bus;
 
@@ -513,6 +513,10 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	pci_bus_add_devices(bus);
 	return 0;
 
+err_free_msi:
+	if (IS_ENABLED(CONFIG_PCI_MSI) && pci_msi_enabled() &&
+			!pp->ops->msi_host_init)
+		dw_pcie_free_msi(pp);
 error:
 	pci_free_host_bridge(bridge);
 	return ret;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 3/5] PCI: dwc: Free MSI in the error code path of dw_pcie_host_init()
  2019-03-18  9:53 [PATCH v3 0/5] PCI: dwc: Support remove Jisheng Zhang
                   ` (2 preceding siblings ...)
  2019-03-18  9:55 ` PCI: dwc: Free MSI in the error code path of dw_pcie_host_init() Jisheng Zhang
@ 2019-03-18  9:56 ` Jisheng Zhang
  2019-03-28 17:08   ` Robin Murphy
  2019-03-18  9:57 ` [PATCH v3 4/5] PCI: dwc: Use devm_pci_alloc_host_bridge() to simplify the code Jisheng Zhang
  2019-03-18  9:58 ` [PATCH v3 5/5] PCI: dwc: Save root bus for driver remove Jisheng Zhang
  5 siblings, 1 reply; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18  9:56 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

If we ever did some msi related initializations, we need to call
dw_pcie_free_msi() in the error code path.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index a71b874ae3c0..585080699675 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -483,7 +483,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	if (pp->ops->host_init) {
 		ret = pp->ops->host_init(pp);
 		if (ret)
-			goto error;
+			goto err_free_msi;
 	}
 
 	pp->root_bus_nr = pp->busn->start;
@@ -497,7 +497,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 
 	ret = pci_scan_root_bus_bridge(bridge);
 	if (ret)
-		goto error;
+		goto err_free_msi;
 
 	bus = bridge->bus;
 
@@ -513,6 +513,10 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	pci_bus_add_devices(bus);
 	return 0;
 
+err_free_msi:
+	if (IS_ENABLED(CONFIG_PCI_MSI) && pci_msi_enabled() &&
+			!pp->ops->msi_host_init)
+		dw_pcie_free_msi(pp);
 error:
 	pci_free_host_bridge(bridge);
 	return ret;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 4/5] PCI: dwc: Use devm_pci_alloc_host_bridge() to simplify the code
  2019-03-18  9:53 [PATCH v3 0/5] PCI: dwc: Support remove Jisheng Zhang
                   ` (3 preceding siblings ...)
  2019-03-18  9:56 ` [PATCH v3 3/5] " Jisheng Zhang
@ 2019-03-18  9:57 ` Jisheng Zhang
  2019-03-18  9:58 ` [PATCH v3 5/5] PCI: dwc: Save root bus for driver remove Jisheng Zhang
  5 siblings, 0 replies; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18  9:57 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

Use devm_pci_alloc_host_bridge() to simplify the error code path.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
---
 .../pci/controller/dwc/pcie-designware-host.c | 21 +++++++------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 585080699675..68a9dac23b1b 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -358,7 +358,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		dev_err(dev, "Missing *config* reg space\n");
 	}
 
-	bridge = pci_alloc_host_bridge(0);
+	bridge = devm_pci_alloc_host_bridge(dev, 0);
 	if (!bridge)
 		return -ENOMEM;
 
@@ -369,7 +369,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 
 	ret = devm_request_pci_bus_resources(dev, &bridge->windows);
 	if (ret)
-		goto error;
+		return ret;
 
 	/* Get the I/O and memory ranges from DT */
 	resource_list_for_each_entry_safe(win, tmp, &bridge->windows) {
@@ -413,8 +413,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 						resource_size(pp->cfg));
 		if (!pci->dbi_base) {
 			dev_err(dev, "Error with ioremap\n");
-			ret = -ENOMEM;
-			goto error;
+			return -ENOMEM;
 		}
 	}
 
@@ -425,8 +424,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 					pp->cfg0_base, pp->cfg0_size);
 		if (!pp->va_cfg0_base) {
 			dev_err(dev, "Error with ioremap in function\n");
-			ret = -ENOMEM;
-			goto error;
+			return -ENOMEM;
 		}
 	}
 
@@ -436,8 +434,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 						pp->cfg1_size);
 		if (!pp->va_cfg1_base) {
 			dev_err(dev, "Error with ioremap\n");
-			ret = -ENOMEM;
-			goto error;
+			return -ENOMEM;
 		}
 	}
 
@@ -460,14 +457,14 @@ int dw_pcie_host_init(struct pcie_port *pp)
 			    pp->num_vectors == 0) {
 				dev_err(dev,
 					"Invalid number of vectors\n");
-				goto error;
+				return -EINVAL;
 			}
 		}
 
 		if (!pp->ops->msi_host_init) {
 			ret = dw_pcie_allocate_domains(pp);
 			if (ret)
-				goto error;
+				return ret;
 
 			if (pp->msi_irq)
 				irq_set_chained_handler_and_data(pp->msi_irq,
@@ -476,7 +473,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 		} else {
 			ret = pp->ops->msi_host_init(pp);
 			if (ret < 0)
-				goto error;
+				return ret;
 		}
 	}
 
@@ -517,8 +514,6 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	if (IS_ENABLED(CONFIG_PCI_MSI) && pci_msi_enabled() &&
 			!pp->ops->msi_host_init)
 		dw_pcie_free_msi(pp);
-error:
-	pci_free_host_bridge(bridge);
 	return ret;
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3 5/5] PCI: dwc: Save root bus for driver remove
  2019-03-18  9:53 [PATCH v3 0/5] PCI: dwc: Support remove Jisheng Zhang
                   ` (4 preceding siblings ...)
  2019-03-18  9:57 ` [PATCH v3 4/5] PCI: dwc: Use devm_pci_alloc_host_bridge() to simplify the code Jisheng Zhang
@ 2019-03-18  9:58 ` Jisheng Zhang
  2019-03-18 10:09   ` Gustavo Pimentel
  5 siblings, 1 reply; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18  9:58 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

Currently dwc host doesn't support the remove, but nothing prevent us
from supporting it. Save the root bus for clean up work in driver
remove code path.

After this patch, the dwc host users could implement its remove as:

static int foo_pcie_remove(struct platform_device *pdev)
{
	...
	pci_stop_root_bus(pp->root_bus);
	pci_remove_root_bus(pp->root_bus);
	dw_pcie_free_msi(pp);
	...
}

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++------
 drivers/pci/controller/dwc/pcie-designware.h      |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index 68a9dac23b1b..7e9dad7ba056 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -341,7 +341,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	struct device_node *np = dev->of_node;
 	struct platform_device *pdev = to_platform_device(dev);
 	struct resource_entry *win, *tmp;
-	struct pci_bus *bus, *child;
+	struct pci_bus *child;
 	struct pci_host_bridge *bridge;
 	struct resource *cfg_res;
 	int ret;
@@ -496,18 +496,18 @@ int dw_pcie_host_init(struct pcie_port *pp)
 	if (ret)
 		goto err_free_msi;
 
-	bus = bridge->bus;
+	pp->root_bus = bridge->bus;
 
 	if (pp->ops->scan_bus)
 		pp->ops->scan_bus(pp);
 
-	pci_bus_size_bridges(bus);
-	pci_bus_assign_resources(bus);
+	pci_bus_size_bridges(pp->root_bus);
+	pci_bus_assign_resources(pp->root_bus);
 
-	list_for_each_entry(child, &bus->children, node)
+	list_for_each_entry(child, &pp->root_bus->children, node)
 		pcie_bus_configure_settings(child);
 
-	pci_bus_add_devices(bus);
+	pci_bus_add_devices(pp->root_bus);
 	return 0;
 
 err_free_msi:
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 6fb0a1879932..adff0c713665 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -182,6 +182,7 @@ struct pcie_port {
 	struct page		*msi_page;
 	u32			num_vectors;
 	u32			irq_mask[MAX_MSI_CTRLS];
+	struct pci_bus		*root_bus;
 	raw_spinlock_t		lock;
 	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
 };
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: PCI: dwc: Free MSI in the error code path of dw_pcie_host_init()
  2019-03-18  9:55 ` PCI: dwc: Free MSI in the error code path of dw_pcie_host_init() Jisheng Zhang
@ 2019-03-18 10:00   ` Jisheng Zhang
  0 siblings, 0 replies; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-18 10:00 UTC (permalink / raw)
  To: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

On Mon, 18 Mar 2019 17:47:49 +0800 Jisheng Zhang wrote:

> If we ever did some msi related initializations, we need to call
> dw_pcie_free_msi() in the error code path.

Sorry, "PATCH" is missing in the email title, please ignore this one


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/5] PCI: dwc: Free the page for MSI IRQ in dw_pcie_free_msi()
  2019-03-18  9:54 ` [PATCH v3 2/5] PCI: dwc: Free the page for MSI IRQ in dw_pcie_free_msi() Jisheng Zhang
@ 2019-03-18 10:03   ` Gustavo Pimentel
  0 siblings, 0 replies; 12+ messages in thread
From: Gustavo Pimentel @ 2019-03-18 10:03 UTC (permalink / raw)
  To: Jisheng Zhang, Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi,
	Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

Hi,

On 18/03/2019 09:54, Jisheng Zhang wrote:
> To avoid memory leak, we need to free the page for MSI in
> dw_pcie_free_msi().
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++++----
>  drivers/pci/controller/dwc/pcie-designware.h      |  1 +
>  2 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index 1040939f45b4..a71b874ae3c0 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -305,20 +305,24 @@ void dw_pcie_free_msi(struct pcie_port *pp)
>  
>  	irq_domain_remove(pp->msi_domain);
>  	irq_domain_remove(pp->irq_domain);
> +
> +	if (pp->msi_page)
> +		__free_page(pp->msi_page);
>  }
>  
>  void dw_pcie_msi_init(struct pcie_port *pp)
>  {
>  	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
>  	struct device *dev = pci->dev;
> -	struct page *page;
>  	u64 msi_target;
>  
> -	page = alloc_page(GFP_KERNEL);
> -	pp->msi_data = dma_map_page(dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
> +	pp->msi_page = alloc_page(GFP_KERNEL);
> +	pp->msi_data = dma_map_page(dev, pp->msi_page, 0, PAGE_SIZE,
> +				    DMA_FROM_DEVICE);
>  	if (dma_mapping_error(dev, pp->msi_data)) {
>  		dev_err(dev, "Failed to map MSI data\n");
> -		__free_page(page);
> +		__free_page(pp->msi_page);
> +		pp->msi_page = NULL;
>  		return;
>  	}
>  	msi_target = (u64)pp->msi_data;
> diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
> index 377f4c0b52da..6fb0a1879932 100644
> --- a/drivers/pci/controller/dwc/pcie-designware.h
> +++ b/drivers/pci/controller/dwc/pcie-designware.h
> @@ -179,6 +179,7 @@ struct pcie_port {
>  	struct irq_domain	*irq_domain;
>  	struct irq_domain	*msi_domain;
>  	dma_addr_t		msi_data;
> +	struct page		*msi_page;
>  	u32			num_vectors;
>  	u32			irq_mask[MAX_MSI_CTRLS];
>  	raw_spinlock_t		lock;
> 

Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 5/5] PCI: dwc: Save root bus for driver remove
  2019-03-18  9:58 ` [PATCH v3 5/5] PCI: dwc: Save root bus for driver remove Jisheng Zhang
@ 2019-03-18 10:09   ` Gustavo Pimentel
  0 siblings, 0 replies; 12+ messages in thread
From: Gustavo Pimentel @ 2019-03-18 10:09 UTC (permalink / raw)
  To: Jisheng Zhang, Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi,
	Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

Hi,

On 18/03/2019 09:58, Jisheng Zhang wrote:
> Currently dwc host doesn't support the remove, but nothing prevent us
> from supporting it. Save the root bus for clean up work in driver
> remove code path.
> 
> After this patch, the dwc host users could implement its remove as:
> 
> static int foo_pcie_remove(struct platform_device *pdev)
> {
> 	...
> 	pci_stop_root_bus(pp->root_bus);
> 	pci_remove_root_bus(pp->root_bus);
> 	dw_pcie_free_msi(pp);
> 	...
> }
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
>  drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++------
>  drivers/pci/controller/dwc/pcie-designware.h      |  1 +
>  2 files changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index 68a9dac23b1b..7e9dad7ba056 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -341,7 +341,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
>  	struct device_node *np = dev->of_node;
>  	struct platform_device *pdev = to_platform_device(dev);
>  	struct resource_entry *win, *tmp;
> -	struct pci_bus *bus, *child;
> +	struct pci_bus *child;
>  	struct pci_host_bridge *bridge;
>  	struct resource *cfg_res;
>  	int ret;
> @@ -496,18 +496,18 @@ int dw_pcie_host_init(struct pcie_port *pp)
>  	if (ret)
>  		goto err_free_msi;
>  
> -	bus = bridge->bus;
> +	pp->root_bus = bridge->bus;
>  
>  	if (pp->ops->scan_bus)
>  		pp->ops->scan_bus(pp);
>  
> -	pci_bus_size_bridges(bus);
> -	pci_bus_assign_resources(bus);
> +	pci_bus_size_bridges(pp->root_bus);
> +	pci_bus_assign_resources(pp->root_bus);
>  
> -	list_for_each_entry(child, &bus->children, node)
> +	list_for_each_entry(child, &pp->root_bus->children, node)
>  		pcie_bus_configure_settings(child);
>  
> -	pci_bus_add_devices(bus);
> +	pci_bus_add_devices(pp->root_bus);
>  	return 0;
>  
>  err_free_msi:
> diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
> index 6fb0a1879932..adff0c713665 100644
> --- a/drivers/pci/controller/dwc/pcie-designware.h
> +++ b/drivers/pci/controller/dwc/pcie-designware.h
> @@ -182,6 +182,7 @@ struct pcie_port {
>  	struct page		*msi_page;
>  	u32			num_vectors;
>  	u32			irq_mask[MAX_MSI_CTRLS];
> +	struct pci_bus		*root_bus;
>  	raw_spinlock_t		lock;
>  	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
>  };
> 

Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/5] PCI: dwc: Free MSI in the error code path of dw_pcie_host_init()
  2019-03-18  9:56 ` [PATCH v3 3/5] " Jisheng Zhang
@ 2019-03-28 17:08   ` Robin Murphy
  2019-03-29 12:00     ` Jisheng Zhang
  0 siblings, 1 reply; 12+ messages in thread
From: Robin Murphy @ 2019-03-28 17:08 UTC (permalink / raw)
  To: Jisheng Zhang, Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi,
	Bjorn Helgaas
  Cc: linux-pci, linux-kernel, linux-arm-kernel

On 18/03/2019 09:56, Jisheng Zhang wrote:
> If we ever did some msi related initializations, we need to call
> dw_pcie_free_msi() in the error code path.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> ---
>   drivers/pci/controller/dwc/pcie-designware-host.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> index a71b874ae3c0..585080699675 100644
> --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> @@ -483,7 +483,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
>   	if (pp->ops->host_init) {
>   		ret = pp->ops->host_init(pp);
>   		if (ret)
> -			goto error;
> +			goto err_free_msi;
>   	}
>   
>   	pp->root_bus_nr = pp->busn->start;
> @@ -497,7 +497,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
>   
>   	ret = pci_scan_root_bus_bridge(bridge);
>   	if (ret)
> -		goto error;
> +		goto err_free_msi;
>   
>   	bus = bridge->bus;
>   
> @@ -513,6 +513,10 @@ int dw_pcie_host_init(struct pcie_port *pp)
>   	pci_bus_add_devices(bus);
>   	return 0;
>   
> +err_free_msi:
> +	if (IS_ENABLED(CONFIG_PCI_MSI) && pci_msi_enabled() &&

pci_msi_enabled() already has a stub for !CONFIG_PCI_MSI, so you 
shouldn't need an explicit IS_ENABLED() here.

Robin.

> +			!pp->ops->msi_host_init)
> +		dw_pcie_free_msi(pp);
>   error:
>   	pci_free_host_bridge(bridge);
>   	return ret;
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 3/5] PCI: dwc: Free MSI in the error code path of dw_pcie_host_init()
  2019-03-28 17:08   ` Robin Murphy
@ 2019-03-29 12:00     ` Jisheng Zhang
  0 siblings, 0 replies; 12+ messages in thread
From: Jisheng Zhang @ 2019-03-29 12:00 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Jingoo Han, Gustavo Pimentel, Lorenzo Pieralisi, Bjorn Helgaas,
	linux-pci, linux-kernel, linux-arm-kernel

On Thu, 28 Mar 2019 17:08:43 +0000 Robin Murphy wrote:

> 
> 
> On 18/03/2019 09:56, Jisheng Zhang wrote:
> > If we ever did some msi related initializations, we need to call
> > dw_pcie_free_msi() in the error code path.
> >
> > Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> > Acked-by: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
> > ---
> >   drivers/pci/controller/dwc/pcie-designware-host.c | 8 ++++++--
> >   1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
> > index a71b874ae3c0..585080699675 100644
> > --- a/drivers/pci/controller/dwc/pcie-designware-host.c
> > +++ b/drivers/pci/controller/dwc/pcie-designware-host.c
> > @@ -483,7 +483,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
> >       if (pp->ops->host_init) {
> >               ret = pp->ops->host_init(pp);
> >               if (ret)
> > -                     goto error;
> > +                     goto err_free_msi;
> >       }
> >
> >       pp->root_bus_nr = pp->busn->start;
> > @@ -497,7 +497,7 @@ int dw_pcie_host_init(struct pcie_port *pp)
> >
> >       ret = pci_scan_root_bus_bridge(bridge);
> >       if (ret)
> > -             goto error;
> > +             goto err_free_msi;
> >
> >       bus = bridge->bus;
> >
> > @@ -513,6 +513,10 @@ int dw_pcie_host_init(struct pcie_port *pp)
> >       pci_bus_add_devices(bus);
> >       return 0;
> >
> > +err_free_msi:
> > +     if (IS_ENABLED(CONFIG_PCI_MSI) && pci_msi_enabled() &&  
> 
> pci_msi_enabled() already has a stub for !CONFIG_PCI_MSI, so you
> shouldn't need an explicit IS_ENABLED() here.

Indeed, thanks very much. updated in V4

Thanks

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-03-29 12:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18  9:53 [PATCH v3 0/5] PCI: dwc: Support remove Jisheng Zhang
2019-03-18  9:53 ` [PATCH v3 1/5] PCI: dwc: Fix dw_pcie_free_msi() if msi_irq is invalid Jisheng Zhang
2019-03-18  9:54 ` [PATCH v3 2/5] PCI: dwc: Free the page for MSI IRQ in dw_pcie_free_msi() Jisheng Zhang
2019-03-18 10:03   ` Gustavo Pimentel
2019-03-18  9:55 ` PCI: dwc: Free MSI in the error code path of dw_pcie_host_init() Jisheng Zhang
2019-03-18 10:00   ` Jisheng Zhang
2019-03-18  9:56 ` [PATCH v3 3/5] " Jisheng Zhang
2019-03-28 17:08   ` Robin Murphy
2019-03-29 12:00     ` Jisheng Zhang
2019-03-18  9:57 ` [PATCH v3 4/5] PCI: dwc: Use devm_pci_alloc_host_bridge() to simplify the code Jisheng Zhang
2019-03-18  9:58 ` [PATCH v3 5/5] PCI: dwc: Save root bus for driver remove Jisheng Zhang
2019-03-18 10:09   ` Gustavo Pimentel

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).