Skip to contentSkip to conversation

PCI: uniphier: Tear down legacy interrupts on host removal

PATCH In review Guangshuo Li 3 participants 3 messages Nov 29 – Dec 1

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: uniphier: Tear down legacy interrupts on host removal

The host driver leaves its chained handler and INTx domain installed when host initialization fails or the driver is removed. Detach the handler and release the interrupt mappings in the host deinit callback. On removal, stop the root bus before releasing the controller resources.

This issue was found by our static analysis tool under development.

Fixes 7e6d5cd88a6f ("PCI: uniphier: Add UniPhier PCIe host controller support")
---
 drivers/pci/controller/dwc/pcie-uniphier.c | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-uniphier.c +37 -1
index 1c8d7694543f..4c9e75fbd8e3 100644
@@ -282,6 +282,7 @@ static int uniphier_pcie_config_intx_irq(struct dw_pcie_rp *pp)
 	pcie->intx_irq_domain = irq_domain_create_linear(of_fwnode_handle(np_intc), PCI_NUM_INTX,
 						&uniphier_intx_domain_ops, pp);
 	if (!pcie->intx_irq_domain) {
+		irq_dispose_mapping(pp->irq);
 		dev_err(pci->dev, "Failed to get INTx domain\n");
 		ret = -ENODEV;
 		goto out_put_node;
@@ -310,8 +311,23 @@ static int uniphier_pcie_host_init(struct dw_pcie_rp *pp)
 	return 0;
 }
 
+static void uniphier_pcie_host_deinit(struct dw_pcie_rp *pp)
+{
+	struct uniphier_pcie *pcie = to_uniphier_pcie(to_dw_pcie_from_pp(pp));
+	unsigned int i;
+
+	writel(0, pcie->base + PCL_RCV_INT);
+	writel(0, pcie->base + PCL_RCV_INTX);
+	irq_set_chained_handler_and_data(pp->irq, NULL, NULL);
+	for (i = 0; i < PCI_NUM_INTX; i++)
+		irq_dispose_mapping(irq_find_mapping(pcie->intx_irq_domain, i));
+	irq_domain_remove(pcie->intx_irq_domain);
+	irq_dispose_mapping(pp->irq);
+}
+
 static const struct dw_pcie_host_ops uniphier_pcie_host_ops = {
 	.init = uniphier_pcie_host_init,
+	.deinit = uniphier_pcie_host_deinit,
 };
 
 static int uniphier_pcie_host_enable(struct uniphier_pcie *pcie)
@@ -348,6 +364,13 @@ static int uniphier_pcie_host_enable(struct uniphier_pcie *pcie)
 	return ret;
 }
 
+static void uniphier_pcie_host_disable(struct uniphier_pcie *pcie)
+{
+	phy_exit(pcie->phy);
+	reset_control_assert(pcie->rst);
+	clk_disable_unprepare(pcie->clk);
+}
+
 static const struct dw_pcie_ops dw_pcie_ops = {
 	.start_link = uniphier_pcie_start_link,
 	.stop_link = uniphier_pcie_stop_link,
@@ -391,7 +414,19 @@ static int uniphier_pcie_probe(struct platform_device *pdev)
 
 	pcie->pci.pp.ops = &uniphier_pcie_host_ops;
 
-	return dw_pcie_host_init(&pcie->pci.pp);
+	ret = dw_pcie_host_init(&pcie->pci.pp);
+	if (ret)
+		uniphier_pcie_host_disable(pcie);
+
+	return ret;
+}
+
+static void uniphier_pcie_remove(struct platform_device *pdev)
+{
+	struct uniphier_pcie *pcie = platform_get_drvdata(pdev);
+
+	dw_pcie_host_deinit(&pcie->pci.pp);
+	uniphier_pcie_host_disable(pcie);
 }
 
 static const struct of_device_id uniphier_pcie_match[] = {
@@ -401,6 +436,7 @@ static const struct of_device_id uniphier_pcie_match[] = {
 
 static struct platform_driver uniphier_pcie_driver = {
 	.probe  = uniphier_pcie_probe,
+	.remove = uniphier_pcie_remove,
 	.driver = {
 		.name = "uniphier-pcie",
 		.of_match_table = uniphier_pcie_match,

base-commit: 647e1e846730c6aad27e9b858df292f5d4377f63

Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

The host driver leaves its chained handler and INTx domain installed when host initialization fails or the driver is removed. Detach the handler and release the interrupt mappings in the host deinit callback. On removal, stop the root bus before releasing the controller resources.

This issue was found by our static analysis tool under development.

Fixes 7e6d5cd88a6f ("PCI: uniphier: Add UniPhier PCIe host controller support")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Guangshuo Li

Hi,

Quoted 5 lines · Guangshuo Li

The host driver leaves its chained handler and INTx domain installed when host initialization fails or the driver is removed. Detach the handler and release the interrupt mappings in the host deinit callback. On removal, stop the root bus before releasing the controller resources.

Quoted 7 lines

This issue was found by our static analysis tool under development.

Fixes 7e6d5cd88a6f ("PCI: uniphier: Add UniPhier PCIe host controller support")
---
  drivers/pci/controller/dwc/pcie-uniphier.c | 38 +++++++++++++++++++++-
  1 file changed, 37 insertions(+), 1 deletion(-)

Thank you for the patch.

I reviewed the changes and they look reasonable to me.

I also tested repeated unbind(and port removal)/bind cycles of the controller on the real board like that:

cd /sys/devices/platform/soc@0/66000000.pcie
echo 1 > pci0000\:00/0000\:00\:00.0/remove
cd driver
echo 66000000.pcie > unbind
echo 66000000.pcie > bind
cd -

And the controller was reprobed successfully and the root port was recreated without warning or errors.

I don't see any obvious issues with this change.

Thank you,

---
Best Regards
Kunihiko Hayashi