Skip to content

Commit 3f0b362

Browse files
committed
Merge branch 'pci/controller/cadence'
- Drop a runtime PM 'put' to resolve a runtime atomic count underflow (Hans Zhang) - Use shared PCIE_MSG_CODE_* definitions and remove duplicate cdns_pcie_msg_code definitions (Hans Zhang) - Make the cadence core buildable as a module (Kishon Vijay Abraham I) - Add cdns_pcie_host_disable() and cdns_pcie_ep_disable() for use by loadable drivers when they are removed (Siddharth Vadapalli) - Make j721e buildable as a loadable and removable module (Siddharth Vadapalli) - Fix j721e host/endpoint dependencies that result in link failures in some configs (Arnd Bergmann) * pci/controller/cadence: PCI: j721e: Fix host/endpoint dependencies PCI: j721e: Add support to build as a loadable module PCI: cadence-ep: Introduce cdns_pcie_ep_disable() helper for cleanup PCI: cadence-host: Introduce cdns_pcie_host_disable() helper for cleanup PCI: cadence: Add support to build pcie-cadence library as a kernel module PCI: cadence: Remove duplicate message code definitions PCI: cadence: Fix runtime atomic count underflow
2 parents c3b2f9d + 3c05e88 commit 3f0b362

File tree

6 files changed

+197
-36
lines changed

6 files changed

+197
-36
lines changed

drivers/pci/controller/cadence/Kconfig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ menu "Cadence-based PCIe controllers"
44
depends on PCI
55

66
config PCIE_CADENCE
7-
bool
7+
tristate
88

99
config PCIE_CADENCE_HOST
10-
bool
10+
tristate
1111
depends on OF
1212
select IRQ_DOMAIN
1313
select PCIE_CADENCE
1414

1515
config PCIE_CADENCE_EP
16-
bool
16+
tristate
1717
depends on OF
1818
depends on PCI_ENDPOINT
1919
select PCIE_CADENCE
@@ -43,25 +43,25 @@ config PCIE_CADENCE_PLAT_EP
4343
different vendors SoCs.
4444

4545
config PCI_J721E
46-
bool
46+
tristate
47+
select PCIE_CADENCE_HOST if PCI_J721E_HOST != n
48+
select PCIE_CADENCE_EP if PCI_J721E_EP != n
4749

4850
config PCI_J721E_HOST
49-
bool "TI J721E PCIe controller (host mode)"
51+
tristate "TI J721E PCIe controller (host mode)"
5052
depends on ARCH_K3 || COMPILE_TEST
5153
depends on OF
52-
select PCIE_CADENCE_HOST
5354
select PCI_J721E
5455
help
5556
Say Y here if you want to support the TI J721E PCIe platform
5657
controller in host mode. TI J721E PCIe controller uses Cadence PCIe
5758
core.
5859

5960
config PCI_J721E_EP
60-
bool "TI J721E PCIe controller (endpoint mode)"
61+
tristate "TI J721E PCIe controller (endpoint mode)"
6162
depends on ARCH_K3 || COMPILE_TEST
6263
depends on OF
6364
depends on PCI_ENDPOINT
64-
select PCIE_CADENCE_EP
6565
select PCI_J721E
6666
help
6767
Say Y here if you want to support the TI J721E PCIe platform

drivers/pci/controller/cadence/pci-j721e.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/irqchip/chained_irq.h>
1616
#include <linux/irqdomain.h>
1717
#include <linux/mfd/syscon.h>
18+
#include <linux/module.h>
1819
#include <linux/of.h>
1920
#include <linux/pci.h>
2021
#include <linux/platform_device.h>
@@ -27,6 +28,7 @@
2728
#define cdns_pcie_to_rc(p) container_of(p, struct cdns_pcie_rc, pcie)
2829

2930
#define ENABLE_REG_SYS_2 0x108
31+
#define ENABLE_CLR_REG_SYS_2 0x308
3032
#define STATUS_REG_SYS_2 0x508
3133
#define STATUS_CLR_REG_SYS_2 0x708
3234
#define LINK_DOWN BIT(1)
@@ -116,6 +118,15 @@ static irqreturn_t j721e_pcie_link_irq_handler(int irq, void *priv)
116118
return IRQ_HANDLED;
117119
}
118120

121+
static void j721e_pcie_disable_link_irq(struct j721e_pcie *pcie)
122+
{
123+
u32 reg;
124+
125+
reg = j721e_pcie_intd_readl(pcie, ENABLE_CLR_REG_SYS_2);
126+
reg |= pcie->linkdown_irq_regfield;
127+
j721e_pcie_intd_writel(pcie, ENABLE_CLR_REG_SYS_2, reg);
128+
}
129+
119130
static void j721e_pcie_config_link_irq(struct j721e_pcie *pcie)
120131
{
121132
u32 reg;
@@ -464,7 +475,7 @@ static int j721e_pcie_probe(struct platform_device *pdev)
464475

465476
switch (mode) {
466477
case PCI_MODE_RC:
467-
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_HOST))
478+
if (!IS_ENABLED(CONFIG_PCI_J721E_HOST))
468479
return -ENODEV;
469480

470481
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc));
@@ -483,7 +494,7 @@ static int j721e_pcie_probe(struct platform_device *pdev)
483494
pcie->cdns_pcie = cdns_pcie;
484495
break;
485496
case PCI_MODE_EP:
486-
if (!IS_ENABLED(CONFIG_PCIE_CADENCE_EP))
497+
if (!IS_ENABLED(CONFIG_PCI_J721E_EP))
487498
return -ENODEV;
488499

489500
ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL);
@@ -633,9 +644,22 @@ static void j721e_pcie_remove(struct platform_device *pdev)
633644
struct j721e_pcie *pcie = platform_get_drvdata(pdev);
634645
struct cdns_pcie *cdns_pcie = pcie->cdns_pcie;
635646
struct device *dev = &pdev->dev;
647+
struct cdns_pcie_ep *ep;
648+
struct cdns_pcie_rc *rc;
649+
650+
if (pcie->mode == PCI_MODE_RC) {
651+
rc = container_of(cdns_pcie, struct cdns_pcie_rc, pcie);
652+
cdns_pcie_host_disable(rc);
653+
} else {
654+
ep = container_of(cdns_pcie, struct cdns_pcie_ep, pcie);
655+
cdns_pcie_ep_disable(ep);
656+
}
657+
658+
gpiod_set_value_cansleep(pcie->reset_gpio, 0);
636659

637660
clk_disable_unprepare(pcie->refclk);
638661
cdns_pcie_disable_phy(cdns_pcie);
662+
j721e_pcie_disable_link_irq(pcie);
639663
pm_runtime_put(dev);
640664
pm_runtime_disable(dev);
641665
}
@@ -730,4 +754,8 @@ static struct platform_driver j721e_pcie_driver = {
730754
.pm = pm_sleep_ptr(&j721e_pcie_pm_ops),
731755
},
732756
};
733-
builtin_platform_driver(j721e_pcie_driver);
757+
module_platform_driver(j721e_pcie_driver);
758+
759+
MODULE_LICENSE("GPL");
760+
MODULE_DESCRIPTION("PCIe controller driver for TI's J721E and related SoCs");
761+
MODULE_AUTHOR("Kishon Vijay Abraham I <[email protected]>");

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#include <linux/bitfield.h>
77
#include <linux/delay.h>
88
#include <linux/kernel.h>
9+
#include <linux/module.h>
910
#include <linux/of.h>
1011
#include <linux/pci-epc.h>
1112
#include <linux/platform_device.h>
1213
#include <linux/sizes.h>
1314

1415
#include "pcie-cadence.h"
16+
#include "../../pci.h"
1517

1618
#define CDNS_PCIE_EP_MIN_APERTURE 128 /* 128 bytes */
1719
#define CDNS_PCIE_EP_IRQ_PCI_ADDR_NONE 0x1
@@ -337,10 +339,10 @@ static void cdns_pcie_ep_assert_intx(struct cdns_pcie_ep *ep, u8 fn, u8 intx,
337339

338340
if (is_asserted) {
339341
ep->irq_pending |= BIT(intx);
340-
msg_code = MSG_CODE_ASSERT_INTA + intx;
342+
msg_code = PCIE_MSG_CODE_ASSERT_INTA + intx;
341343
} else {
342344
ep->irq_pending &= ~BIT(intx);
343-
msg_code = MSG_CODE_DEASSERT_INTA + intx;
345+
msg_code = PCIE_MSG_CODE_DEASSERT_INTA + intx;
344346
}
345347

346348
spin_lock_irqsave(&ep->lock, flags);
@@ -644,6 +646,17 @@ static const struct pci_epc_ops cdns_pcie_epc_ops = {
644646
.get_features = cdns_pcie_ep_get_features,
645647
};
646648

649+
void cdns_pcie_ep_disable(struct cdns_pcie_ep *ep)
650+
{
651+
struct device *dev = ep->pcie.dev;
652+
struct pci_epc *epc = to_pci_epc(dev);
653+
654+
pci_epc_deinit_notify(epc);
655+
pci_epc_mem_free_addr(epc, ep->irq_phys_addr, ep->irq_cpu_addr,
656+
SZ_128K);
657+
pci_epc_mem_exit(epc);
658+
}
659+
EXPORT_SYMBOL_GPL(cdns_pcie_ep_disable);
647660

648661
int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep)
649662
{
@@ -751,3 +764,8 @@ int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep)
751764

752765
return ret;
753766
}
767+
EXPORT_SYMBOL_GPL(cdns_pcie_ep_setup);
768+
769+
MODULE_LICENSE("GPL");
770+
MODULE_DESCRIPTION("Cadence PCIe endpoint controller driver");
771+
MODULE_AUTHOR("Cyrille Pitchen <[email protected]>");

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

Lines changed: 114 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/delay.h>
77
#include <linux/kernel.h>
8+
#include <linux/module.h>
89
#include <linux/list_sort.h>
910
#include <linux/of_address.h>
1011
#include <linux/of_pci.h>
@@ -72,6 +73,7 @@ void __iomem *cdns_pci_map_bus(struct pci_bus *bus, unsigned int devfn,
7273

7374
return rc->cfg_base + (where & 0xfff);
7475
}
76+
EXPORT_SYMBOL_GPL(cdns_pci_map_bus);
7577

7678
static struct pci_ops cdns_pcie_host_ops = {
7779
.map_bus = cdns_pci_map_bus,
@@ -150,6 +152,14 @@ static int cdns_pcie_retrain(struct cdns_pcie *pcie)
150152
return ret;
151153
}
152154

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+
153163
static void cdns_pcie_host_enable_ptm_response(struct cdns_pcie *pcie)
154164
{
155165
u32 val;
@@ -175,6 +185,26 @@ static int cdns_pcie_host_start_link(struct cdns_pcie_rc *rc)
175185
return ret;
176186
}
177187

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+
178208
static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
179209
{
180210
struct cdns_pcie *pcie = &rc->pcie;
@@ -391,6 +421,32 @@ static int cdns_pcie_host_dma_ranges_cmp(void *priv, const struct list_head *a,
391421
return resource_size(entry2->res) - resource_size(entry1->res);
392422
}
393423

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+
394450
static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
395451
{
396452
struct cdns_pcie *pcie = &rc->pcie;
@@ -428,6 +484,29 @@ static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
428484
return 0;
429485
}
430486

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+
431510
static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
432511
{
433512
struct cdns_pcie *pcie = &rc->pcie;
@@ -485,6 +564,12 @@ static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
485564
return cdns_pcie_host_map_dma_ranges(rc);
486565
}
487566

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+
488573
int cdns_pcie_host_init(struct cdns_pcie_rc *rc)
489574
{
490575
int err;
@@ -495,6 +580,15 @@ int cdns_pcie_host_init(struct cdns_pcie_rc *rc)
495580

496581
return cdns_pcie_host_init_address_translation(rc);
497582
}
583+
EXPORT_SYMBOL_GPL(cdns_pcie_host_init);
584+
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+
}
498592

499593
int cdns_pcie_host_link_setup(struct cdns_pcie_rc *rc)
500594
{
@@ -519,6 +613,20 @@ int cdns_pcie_host_link_setup(struct cdns_pcie_rc *rc)
519613

520614
return 0;
521615
}
616+
EXPORT_SYMBOL_GPL(cdns_pcie_host_link_setup);
617+
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);
522630

523631
int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
524632
{
@@ -570,14 +678,10 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
570678
if (!bridge->ops)
571679
bridge->ops = &cdns_pcie_host_ops;
572680

573-
ret = pci_host_probe(bridge);
574-
if (ret < 0)
575-
goto err_init;
576-
577-
return 0;
578-
579-
err_init:
580-
pm_runtime_put_sync(dev);
581-
582-
return ret;
681+
return pci_host_probe(bridge);
583682
}
683+
EXPORT_SYMBOL_GPL(cdns_pcie_host_setup);
684+
685+
MODULE_LICENSE("GPL");
686+
MODULE_DESCRIPTION("Cadence PCIe host controller driver");
687+
MODULE_AUTHOR("Cyrille Pitchen <[email protected]>");

0 commit comments

Comments
 (0)