Skip to content

Commit 47f25da

Browse files
PCI: cadence-host: Introduce cdns_pcie_host_disable() helper for cleanup
Introduce the helper function cdns_pcie_host_disable() which will undo the configuration performed by cdns_pcie_host_setup(). Also, export it for use by existing callers of cdns_pcie_host_setup(), thereby allowing them to cleanup on their exit path. Signed-off-by: Siddharth Vadapalli <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent f876904 commit 47f25da

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

drivers/pci/controller/cadence/pcie-cadence-host.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ static int cdns_pcie_retrain(struct cdns_pcie *pcie)
152152
return ret;
153153
}
154154

155+
static void cdns_pcie_host_disable_ptm_response(struct cdns_pcie *pcie)
156+
{
157+
u32 val;
158+
159+
val = cdns_pcie_readl(pcie, CDNS_PCIE_LM_PTM_CTRL);
160+
cdns_pcie_writel(pcie, CDNS_PCIE_LM_PTM_CTRL, val & ~CDNS_PCIE_LM_TPM_CTRL_PTMRSEN);
161+
}
162+
155163
static void cdns_pcie_host_enable_ptm_response(struct cdns_pcie *pcie)
156164
{
157165
u32 val;
@@ -177,6 +185,26 @@ static int cdns_pcie_host_start_link(struct cdns_pcie_rc *rc)
177185
return ret;
178186
}
179187

188+
static void cdns_pcie_host_deinit_root_port(struct cdns_pcie_rc *rc)
189+
{
190+
struct cdns_pcie *pcie = &rc->pcie;
191+
u32 value, ctrl;
192+
193+
cdns_pcie_rp_writew(pcie, PCI_CLASS_DEVICE, 0xffff);
194+
cdns_pcie_rp_writeb(pcie, PCI_CLASS_PROG, 0xff);
195+
cdns_pcie_rp_writeb(pcie, PCI_CLASS_REVISION, 0xff);
196+
cdns_pcie_writel(pcie, CDNS_PCIE_LM_ID, 0xffffffff);
197+
cdns_pcie_rp_writew(pcie, PCI_DEVICE_ID, 0xffff);
198+
ctrl = CDNS_PCIE_LM_BAR_CFG_CTRL_DISABLED;
199+
value = ~(CDNS_PCIE_LM_RC_BAR_CFG_BAR0_CTRL(ctrl) |
200+
CDNS_PCIE_LM_RC_BAR_CFG_BAR1_CTRL(ctrl) |
201+
CDNS_PCIE_LM_RC_BAR_CFG_PREFETCH_MEM_ENABLE |
202+
CDNS_PCIE_LM_RC_BAR_CFG_PREFETCH_MEM_64BITS |
203+
CDNS_PCIE_LM_RC_BAR_CFG_IO_ENABLE |
204+
CDNS_PCIE_LM_RC_BAR_CFG_IO_32BITS);
205+
cdns_pcie_writel(pcie, CDNS_PCIE_LM_RC_BAR_CFG, value);
206+
}
207+
180208
static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
181209
{
182210
struct cdns_pcie *pcie = &rc->pcie;
@@ -393,6 +421,32 @@ static int cdns_pcie_host_dma_ranges_cmp(void *priv, const struct list_head *a,
393421
return resource_size(entry2->res) - resource_size(entry1->res);
394422
}
395423

424+
static void cdns_pcie_host_unmap_dma_ranges(struct cdns_pcie_rc *rc)
425+
{
426+
struct cdns_pcie *pcie = &rc->pcie;
427+
enum cdns_pcie_rp_bar bar;
428+
u32 value;
429+
430+
/* Reset inbound configuration for all BARs which were being used */
431+
for (bar = RP_BAR0; bar <= RP_NO_BAR; bar++) {
432+
if (rc->avail_ib_bar[bar])
433+
continue;
434+
435+
cdns_pcie_writel(pcie, CDNS_PCIE_AT_IB_RP_BAR_ADDR0(bar), 0);
436+
cdns_pcie_writel(pcie, CDNS_PCIE_AT_IB_RP_BAR_ADDR1(bar), 0);
437+
438+
if (bar == RP_NO_BAR)
439+
continue;
440+
441+
value = ~(LM_RC_BAR_CFG_CTRL_MEM_64BITS(bar) |
442+
LM_RC_BAR_CFG_CTRL_PREF_MEM_64BITS(bar) |
443+
LM_RC_BAR_CFG_CTRL_MEM_32BITS(bar) |
444+
LM_RC_BAR_CFG_CTRL_PREF_MEM_32BITS(bar) |
445+
LM_RC_BAR_CFG_APERTURE(bar, bar_aperture_mask[bar] + 2));
446+
cdns_pcie_writel(pcie, CDNS_PCIE_LM_RC_BAR_CFG, value);
447+
}
448+
}
449+
396450
static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
397451
{
398452
struct cdns_pcie *pcie = &rc->pcie;
@@ -430,6 +484,29 @@ static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
430484
return 0;
431485
}
432486

487+
static void cdns_pcie_host_deinit_address_translation(struct cdns_pcie_rc *rc)
488+
{
489+
struct cdns_pcie *pcie = &rc->pcie;
490+
struct pci_host_bridge *bridge = pci_host_bridge_from_priv(rc);
491+
struct resource_entry *entry;
492+
int r;
493+
494+
cdns_pcie_host_unmap_dma_ranges(rc);
495+
496+
/*
497+
* Reset outbound region 0 which was reserved for configuration space
498+
* accesses.
499+
*/
500+
cdns_pcie_reset_outbound_region(pcie, 0);
501+
502+
/* Reset rest of the outbound regions */
503+
r = 1;
504+
resource_list_for_each_entry(entry, &bridge->windows) {
505+
cdns_pcie_reset_outbound_region(pcie, r);
506+
r++;
507+
}
508+
}
509+
433510
static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
434511
{
435512
struct cdns_pcie *pcie = &rc->pcie;
@@ -487,6 +564,12 @@ static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
487564
return cdns_pcie_host_map_dma_ranges(rc);
488565
}
489566

567+
static void cdns_pcie_host_deinit(struct cdns_pcie_rc *rc)
568+
{
569+
cdns_pcie_host_deinit_address_translation(rc);
570+
cdns_pcie_host_deinit_root_port(rc);
571+
}
572+
490573
int cdns_pcie_host_init(struct cdns_pcie_rc *rc)
491574
{
492575
int err;
@@ -499,6 +582,14 @@ int cdns_pcie_host_init(struct cdns_pcie_rc *rc)
499582
}
500583
EXPORT_SYMBOL_GPL(cdns_pcie_host_init);
501584

585+
static void cdns_pcie_host_link_disable(struct cdns_pcie_rc *rc)
586+
{
587+
struct cdns_pcie *pcie = &rc->pcie;
588+
589+
cdns_pcie_stop_link(pcie);
590+
cdns_pcie_host_disable_ptm_response(pcie);
591+
}
592+
502593
int cdns_pcie_host_link_setup(struct cdns_pcie_rc *rc)
503594
{
504595
struct cdns_pcie *pcie = &rc->pcie;
@@ -524,6 +615,19 @@ int cdns_pcie_host_link_setup(struct cdns_pcie_rc *rc)
524615
}
525616
EXPORT_SYMBOL_GPL(cdns_pcie_host_link_setup);
526617

618+
void cdns_pcie_host_disable(struct cdns_pcie_rc *rc)
619+
{
620+
struct pci_host_bridge *bridge;
621+
622+
bridge = pci_host_bridge_from_priv(rc);
623+
pci_stop_root_bus(bridge->bus);
624+
pci_remove_root_bus(bridge->bus);
625+
626+
cdns_pcie_host_deinit(rc);
627+
cdns_pcie_host_link_disable(rc);
628+
}
629+
EXPORT_SYMBOL_GPL(cdns_pcie_host_disable);
630+
527631
int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
528632
{
529633
struct device *dev = rc->pcie.dev;

drivers/pci/controller/cadence/pcie-cadence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ static inline bool cdns_pcie_link_up(struct cdns_pcie *pcie)
512512
int cdns_pcie_host_link_setup(struct cdns_pcie_rc *rc);
513513
int cdns_pcie_host_init(struct cdns_pcie_rc *rc);
514514
int cdns_pcie_host_setup(struct cdns_pcie_rc *rc);
515+
void cdns_pcie_host_disable(struct cdns_pcie_rc *rc);
515516
void __iomem *cdns_pci_map_bus(struct pci_bus *bus, unsigned int devfn,
516517
int where);
517518
#else
@@ -530,6 +531,10 @@ static inline int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
530531
return 0;
531532
}
532533

534+
static inline void cdns_pcie_host_disable(struct cdns_pcie_rc *rc)
535+
{
536+
}
537+
533538
static inline void __iomem *cdns_pci_map_bus(struct pci_bus *bus, unsigned int devfn,
534539
int where)
535540
{

0 commit comments

Comments
 (0)