Skip to content

Commit

Permalink
PCI: dwc: Add dw_pcie_ops.host_deinit() callback
Browse files Browse the repository at this point in the history
dw_pcie_host_init() calls the dw_pcie_ops.host_init() callback to do
platform-specific host initialization.

Add a dw_pcie_ops.host_deinit() callback to perform the corresponding
cleanups in dw_pcie_host_deinit() and in dw_pcie_host_init() failure paths.

Link: https://lore.kernel.org/r/20220624143947.8991-9-Sergey.Semin@baikalelectronics.ru
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
  • Loading branch information
fancer authored and bjorn-helgaas committed Aug 1, 2022
1 parent 58c379e commit c6481d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
21 changes: 16 additions & 5 deletions drivers/pci/controller/dwc/pcie-designware-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,14 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
pp->num_vectors = MSI_DEF_NUM_VECTORS;
} else if (pp->num_vectors > MAX_MSI_IRQS) {
dev_err(dev, "Invalid number of vectors\n");
return -EINVAL;
ret = -EINVAL;
goto err_deinit_host;
}

if (pp->ops->msi_host_init) {
ret = pp->ops->msi_host_init(pp);
if (ret < 0)
return ret;
goto err_deinit_host;
} else if (pp->has_msi_ctrl) {
u32 ctrl, num_ctrls;

Expand All @@ -372,16 +373,18 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
pp->msi_irq = platform_get_irq_byname_optional(pdev, "msi");
if (pp->msi_irq < 0) {
pp->msi_irq = platform_get_irq(pdev, 0);
if (pp->msi_irq < 0)
return pp->msi_irq;
if (pp->msi_irq < 0) {
ret = pp->msi_irq;
goto err_deinit_host;
}
}
}

pp->msi_irq_chip = &dw_pci_msi_bottom_irq_chip;

ret = dw_pcie_allocate_domains(pp);
if (ret)
return ret;
goto err_deinit_host;

if (pp->msi_irq > 0)
irq_set_chained_handler_and_data(pp->msi_irq,
Expand Down Expand Up @@ -434,6 +437,11 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
err_free_msi:
if (pp->has_msi_ctrl)
dw_pcie_free_msi(pp);

err_deinit_host:
if (pp->ops->host_deinit)
pp->ops->host_deinit(pp);

return ret;
}
EXPORT_SYMBOL_GPL(dw_pcie_host_init);
Expand All @@ -449,6 +457,9 @@ void dw_pcie_host_deinit(struct dw_pcie_rp *pp)

if (pp->has_msi_ctrl)
dw_pcie_free_msi(pp);

if (pp->ops->host_deinit)
pp->ops->host_deinit(pp);
}
EXPORT_SYMBOL_GPL(dw_pcie_host_deinit);

Expand Down
1 change: 1 addition & 0 deletions drivers/pci/controller/dwc/pcie-designware.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ enum dw_pcie_device_mode {

struct dw_pcie_host_ops {
int (*host_init)(struct dw_pcie_rp *pp);
void (*host_deinit)(struct dw_pcie_rp *pp);
int (*msi_host_init)(struct dw_pcie_rp *pp);
};

Expand Down

0 comments on commit c6481d5

Please sign in to comment.