Skip to content

Commit ba7e87c

Browse files
committed
Merge branch 'remotes/lorenzo/pci/cadence'
- Refactor Cadence PCIe host controller to use as a library for both host and endpoint (Tom Joseph) * remotes/lorenzo/pci/cadence: PCI: cadence: Move all files to per-device cadence directory PCI: cadence: Refactor driver to use as a core library
2 parents 318ed91 + de80f95 commit ba7e87c

File tree

9 files changed

+315
-210
lines changed

9 files changed

+315
-210
lines changed

drivers/pci/controller/Kconfig

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,6 @@ config PCI_AARDVARK
2222
controller is part of the South Bridge of the Marvel Armada
2323
3700 SoC.
2424

25-
menu "Cadence PCIe controllers support"
26-
27-
config PCIE_CADENCE
28-
bool
29-
30-
config PCIE_CADENCE_HOST
31-
bool "Cadence PCIe host controller"
32-
depends on OF
33-
depends on PCI
34-
select IRQ_DOMAIN
35-
select PCIE_CADENCE
36-
help
37-
Say Y here if you want to support the Cadence PCIe controller in host
38-
mode. This PCIe controller may be embedded into many different vendors
39-
SoCs.
40-
41-
config PCIE_CADENCE_EP
42-
bool "Cadence PCIe endpoint controller"
43-
depends on OF
44-
depends on PCI_ENDPOINT
45-
select PCIE_CADENCE
46-
help
47-
Say Y here if you want to support the Cadence PCIe controller in
48-
endpoint mode. This PCIe controller may be embedded into many
49-
different vendors SoCs.
50-
51-
endmenu
52-
5325
config PCIE_XILINX_NWL
5426
bool "NWL PCIe Core"
5527
depends on ARCH_ZYNQMP || COMPILE_TEST
@@ -289,4 +261,5 @@ config PCI_HYPERV_INTERFACE
289261
have a common interface with the Hyper-V PCI frontend driver.
290262

291263
source "drivers/pci/controller/dwc/Kconfig"
264+
source "drivers/pci/controller/cadence/Kconfig"
292265
endmenu

drivers/pci/controller/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
obj-$(CONFIG_PCIE_CADENCE) += pcie-cadence.o
3-
obj-$(CONFIG_PCIE_CADENCE_HOST) += pcie-cadence-host.o
4-
obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o
2+
obj-$(CONFIG_PCIE_CADENCE) += cadence/
53
obj-$(CONFIG_PCI_FTPCI100) += pci-ftpci100.o
64
obj-$(CONFIG_PCI_HYPERV) += pci-hyperv.o
75
obj-$(CONFIG_PCI_HYPERV_INTERFACE) += pci-hyperv-intf.o
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
menu "Cadence PCIe controllers support"
4+
depends on PCI
5+
6+
config PCIE_CADENCE
7+
bool
8+
9+
config PCIE_CADENCE_HOST
10+
bool
11+
depends on OF
12+
select IRQ_DOMAIN
13+
select PCIE_CADENCE
14+
15+
config PCIE_CADENCE_EP
16+
bool
17+
depends on OF
18+
depends on PCI_ENDPOINT
19+
select PCIE_CADENCE
20+
21+
config PCIE_CADENCE_PLAT
22+
bool
23+
24+
config PCIE_CADENCE_PLAT_HOST
25+
bool "Cadence PCIe platform host controller"
26+
depends on OF
27+
select PCIE_CADENCE_HOST
28+
select PCIE_CADENCE_PLAT
29+
help
30+
Say Y here if you want to support the Cadence PCIe platform controller in
31+
host mode. This PCIe controller may be embedded into many different
32+
vendors SoCs.
33+
34+
config PCIE_CADENCE_PLAT_EP
35+
bool "Cadence PCIe platform endpoint controller"
36+
depends on OF
37+
depends on PCI_ENDPOINT
38+
select PCIE_CADENCE_EP
39+
select PCIE_CADENCE_PLAT
40+
help
41+
Say Y here if you want to support the Cadence PCIe platform controller in
42+
endpoint mode. This PCIe controller may be embedded into many
43+
different vendors SoCs.
44+
45+
endmenu
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
obj-$(CONFIG_PCIE_CADENCE) += pcie-cadence.o
3+
obj-$(CONFIG_PCIE_CADENCE_HOST) += pcie-cadence-host.o
4+
obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep.o
5+
obj-$(CONFIG_PCIE_CADENCE_PLAT) += pcie-cadence-plat.o

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

Lines changed: 5 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,6 @@
1717
#define CDNS_PCIE_EP_IRQ_PCI_ADDR_NONE 0x1
1818
#define CDNS_PCIE_EP_IRQ_PCI_ADDR_LEGACY 0x3
1919

20-
/**
21-
* struct cdns_pcie_ep - private data for this PCIe endpoint controller driver
22-
* @pcie: Cadence PCIe controller
23-
* @max_regions: maximum number of regions supported by hardware
24-
* @ob_region_map: bitmask of mapped outbound regions
25-
* @ob_addr: base addresses in the AXI bus where the outbound regions start
26-
* @irq_phys_addr: base address on the AXI bus where the MSI/legacy IRQ
27-
* dedicated outbound regions is mapped.
28-
* @irq_cpu_addr: base address in the CPU space where a write access triggers
29-
* the sending of a memory write (MSI) / normal message (legacy
30-
* IRQ) TLP through the PCIe bus.
31-
* @irq_pci_addr: used to save the current mapping of the MSI/legacy IRQ
32-
* dedicated outbound region.
33-
* @irq_pci_fn: the latest PCI function that has updated the mapping of
34-
* the MSI/legacy IRQ dedicated outbound region.
35-
* @irq_pending: bitmask of asserted legacy IRQs.
36-
*/
37-
struct cdns_pcie_ep {
38-
struct cdns_pcie pcie;
39-
u32 max_regions;
40-
unsigned long ob_region_map;
41-
phys_addr_t *ob_addr;
42-
phys_addr_t irq_phys_addr;
43-
void __iomem *irq_cpu_addr;
44-
u64 irq_pci_addr;
45-
u8 irq_pci_fn;
46-
u8 irq_pending;
47-
};
48-
4920
static int cdns_pcie_ep_write_header(struct pci_epc *epc, u8 fn,
5021
struct pci_epf_header *hdr)
5122
{
@@ -424,28 +395,17 @@ static const struct pci_epc_ops cdns_pcie_epc_ops = {
424395
.get_features = cdns_pcie_ep_get_features,
425396
};
426397

427-
static const struct of_device_id cdns_pcie_ep_of_match[] = {
428-
{ .compatible = "cdns,cdns-pcie-ep" },
429-
430-
{ },
431-
};
432398

433-
static int cdns_pcie_ep_probe(struct platform_device *pdev)
399+
int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep)
434400
{
435-
struct device *dev = &pdev->dev;
401+
struct device *dev = ep->pcie.dev;
402+
struct platform_device *pdev = to_platform_device(dev);
436403
struct device_node *np = dev->of_node;
437-
struct cdns_pcie_ep *ep;
438-
struct cdns_pcie *pcie;
439-
struct pci_epc *epc;
404+
struct cdns_pcie *pcie = &ep->pcie;
440405
struct resource *res;
406+
struct pci_epc *epc;
441407
int ret;
442-
int phy_count;
443-
444-
ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL);
445-
if (!ep)
446-
return -ENOMEM;
447408

448-
pcie = &ep->pcie;
449409
pcie->is_rc = false;
450410

451411
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "reg");
@@ -474,19 +434,6 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev)
474434
if (!ep->ob_addr)
475435
return -ENOMEM;
476436

477-
ret = cdns_pcie_init_phy(dev, pcie);
478-
if (ret) {
479-
dev_err(dev, "failed to init phy\n");
480-
return ret;
481-
}
482-
platform_set_drvdata(pdev, pcie);
483-
pm_runtime_enable(dev);
484-
ret = pm_runtime_get_sync(dev);
485-
if (ret < 0) {
486-
dev_err(dev, "pm_runtime_get_sync() failed\n");
487-
goto err_get_sync;
488-
}
489-
490437
/* Disable all but function 0 (anyway BIT(0) is hardwired to 1). */
491438
cdns_pcie_writel(pcie, CDNS_PCIE_LM_EP_FUNC_CFG, BIT(0));
492439

@@ -528,38 +475,5 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev)
528475
err_init:
529476
pm_runtime_put_sync(dev);
530477

531-
err_get_sync:
532-
pm_runtime_disable(dev);
533-
cdns_pcie_disable_phy(pcie);
534-
phy_count = pcie->phy_count;
535-
while (phy_count--)
536-
device_link_del(pcie->link[phy_count]);
537-
538478
return ret;
539479
}
540-
541-
static void cdns_pcie_ep_shutdown(struct platform_device *pdev)
542-
{
543-
struct device *dev = &pdev->dev;
544-
struct cdns_pcie *pcie = dev_get_drvdata(dev);
545-
int ret;
546-
547-
ret = pm_runtime_put_sync(dev);
548-
if (ret < 0)
549-
dev_dbg(dev, "pm_runtime_put_sync failed\n");
550-
551-
pm_runtime_disable(dev);
552-
553-
cdns_pcie_disable_phy(pcie);
554-
}
555-
556-
static struct platform_driver cdns_pcie_ep_driver = {
557-
.driver = {
558-
.name = "cdns-pcie-ep",
559-
.of_match_table = cdns_pcie_ep_of_match,
560-
.pm = &cdns_pcie_pm_ops,
561-
},
562-
.probe = cdns_pcie_ep_probe,
563-
.shutdown = cdns_pcie_ep_shutdown,
564-
};
565-
builtin_platform_driver(cdns_pcie_ep_driver);

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

Lines changed: 7 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,6 @@
1111

1212
#include "pcie-cadence.h"
1313

14-
/**
15-
* struct cdns_pcie_rc - private data for this PCIe Root Complex driver
16-
* @pcie: Cadence PCIe controller
17-
* @dev: pointer to PCIe device
18-
* @cfg_res: start/end offsets in the physical system memory to map PCI
19-
* configuration space accesses
20-
* @bus_range: first/last buses behind the PCIe host controller
21-
* @cfg_base: IO mapped window to access the PCI configuration space of a
22-
* single function at a time
23-
* @max_regions: maximum number of regions supported by the hardware
24-
* @no_bar_nbits: Number of bits to keep for inbound (PCIe -> CPU) address
25-
* translation (nbits sets into the "no BAR match" register)
26-
* @vendor_id: PCI vendor ID
27-
* @device_id: PCI device ID
28-
*/
29-
struct cdns_pcie_rc {
30-
struct cdns_pcie pcie;
31-
struct device *dev;
32-
struct resource *cfg_res;
33-
struct resource *bus_range;
34-
void __iomem *cfg_base;
35-
u32 max_regions;
36-
u32 no_bar_nbits;
37-
u16 vendor_id;
38-
u16 device_id;
39-
};
40-
4114
static void __iomem *cdns_pci_map_bus(struct pci_bus *bus, unsigned int devfn,
4215
int where)
4316
{
@@ -92,11 +65,6 @@ static struct pci_ops cdns_pcie_host_ops = {
9265
.write = pci_generic_config_write,
9366
};
9467

95-
static const struct of_device_id cdns_pcie_host_of_match[] = {
96-
{ .compatible = "cdns,cdns-pcie-host" },
97-
98-
{ },
99-
};
10068

10169
static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
10270
{
@@ -136,10 +104,10 @@ static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc)
136104
static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
137105
{
138106
struct cdns_pcie *pcie = &rc->pcie;
139-
struct resource *cfg_res = rc->cfg_res;
140107
struct resource *mem_res = pcie->mem_res;
141108
struct resource *bus_range = rc->bus_range;
142-
struct device *dev = rc->dev;
109+
struct resource *cfg_res = rc->cfg_res;
110+
struct device *dev = pcie->dev;
143111
struct device_node *np = dev->of_node;
144112
struct of_pci_range_parser parser;
145113
struct of_pci_range range;
@@ -233,25 +201,21 @@ static int cdns_pcie_host_init(struct device *dev,
233201
return err;
234202
}
235203

236-
static int cdns_pcie_host_probe(struct platform_device *pdev)
204+
int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
237205
{
238-
struct device *dev = &pdev->dev;
206+
struct device *dev = rc->pcie.dev;
207+
struct platform_device *pdev = to_platform_device(dev);
239208
struct device_node *np = dev->of_node;
240209
struct pci_host_bridge *bridge;
241210
struct list_head resources;
242-
struct cdns_pcie_rc *rc;
243211
struct cdns_pcie *pcie;
244212
struct resource *res;
245213
int ret;
246-
int phy_count;
247214

248-
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc));
215+
bridge = pci_host_bridge_from_priv(rc);
249216
if (!bridge)
250217
return -ENOMEM;
251218

252-
rc = pci_host_bridge_priv(bridge);
253-
rc->dev = dev;
254-
255219
pcie = &rc->pcie;
256220
pcie->is_rc = true;
257221

@@ -287,21 +251,8 @@ static int cdns_pcie_host_probe(struct platform_device *pdev)
287251
dev_err(dev, "missing \"mem\"\n");
288252
return -EINVAL;
289253
}
290-
pcie->mem_res = res;
291254

292-
ret = cdns_pcie_init_phy(dev, pcie);
293-
if (ret) {
294-
dev_err(dev, "failed to init phy\n");
295-
return ret;
296-
}
297-
platform_set_drvdata(pdev, pcie);
298-
299-
pm_runtime_enable(dev);
300-
ret = pm_runtime_get_sync(dev);
301-
if (ret < 0) {
302-
dev_err(dev, "pm_runtime_get_sync() failed\n");
303-
goto err_get_sync;
304-
}
255+
pcie->mem_res = res;
305256

306257
ret = cdns_pcie_host_init(dev, &resources, rc);
307258
if (ret)
@@ -326,37 +277,5 @@ static int cdns_pcie_host_probe(struct platform_device *pdev)
326277
err_init:
327278
pm_runtime_put_sync(dev);
328279

329-
err_get_sync:
330-
pm_runtime_disable(dev);
331-
cdns_pcie_disable_phy(pcie);
332-
phy_count = pcie->phy_count;
333-
while (phy_count--)
334-
device_link_del(pcie->link[phy_count]);
335-
336280
return ret;
337281
}
338-
339-
static void cdns_pcie_shutdown(struct platform_device *pdev)
340-
{
341-
struct device *dev = &pdev->dev;
342-
struct cdns_pcie *pcie = dev_get_drvdata(dev);
343-
int ret;
344-
345-
ret = pm_runtime_put_sync(dev);
346-
if (ret < 0)
347-
dev_dbg(dev, "pm_runtime_put_sync failed\n");
348-
349-
pm_runtime_disable(dev);
350-
cdns_pcie_disable_phy(pcie);
351-
}
352-
353-
static struct platform_driver cdns_pcie_host_driver = {
354-
.driver = {
355-
.name = "cdns-pcie-host",
356-
.of_match_table = cdns_pcie_host_of_match,
357-
.pm = &cdns_pcie_pm_ops,
358-
},
359-
.probe = cdns_pcie_host_probe,
360-
.shutdown = cdns_pcie_shutdown,
361-
};
362-
builtin_platform_driver(cdns_pcie_host_driver);

0 commit comments

Comments
 (0)