Skip to content

Commit 531abff

Browse files
committed
Merge branch 'pci/controller/qcom'
- Select PCI Power Control Slot driver so slot voltage rails can be turned on/off if described in Root Port device tree node (Qiang Yu) - Parse only PCI bridge child nodes in device tree, skipping unrelated nodes such as OPP (Operating Performance Points), which caused probe failures (Krishna Chaitanya Chundru) - Add 8.0 GT/s and 32.0 GT/s equalization settings (Ziyue Zhang) - Fix typo in CURSOR macro names (Ziyue Zhang) - Consolidate Root Port 'phy' and 'reset' properties in struct qcom_pcie_port, regardless of whether we got them from the Root Port node or the host bridge node (Manivannan Sadhasivam) - Fetch and map the ELBI register space in the DWC core rather than in each driver individually (Krishna Chaitanya Chundru) - Enable ECAM mechanism in DWC core by setting up iATU with 'CFG Shift Feature' and use this in the qcom driver (Krishna Chaitanya Chundru) * pci/controller/qcom: PCI: dwc: Support ECAM mechanism by enabling iATU 'CFG Shift Feature' PCI: qcom: Prepare for the DWC ECAM enablement PCI: dwc: Prepare the driver for enabling ECAM mechanism using iATU 'CFG Shift Feature' PCI: dwc: Add support for ELBI resource mapping PCI: qcom: Move host bridge 'phy' and 'reset' pointers to struct qcom_pcie_port PCI: qcom: Fix macro typo for CURSOR PCI: qcom: Add equalization settings for 8.0 GT/s and 32.0 GT/s PCI: qcom: Restrict port parsing only to PCIe bridge child nodes PCI: qcom: Select PCI Power Control Slot driver
2 parents 93f32da + 0da48c5 commit 531abff

File tree

10 files changed

+343
-152
lines changed

10 files changed

+343
-152
lines changed

drivers/pci/controller/dwc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ config PCIE_DW_HOST
2020
bool
2121
select PCIE_DW
2222
select IRQ_MSI_LIB
23+
select PCI_HOST_COMMON
2324

2425
config PCIE_DW_EP
2526
bool
@@ -298,6 +299,7 @@ config PCIE_QCOM
298299
select CRC8
299300
select PCIE_QCOM_COMMON
300301
select PCI_HOST_COMMON
302+
select PCI_PWRCTRL_SLOT
301303
help
302304
Say Y here to enable PCIe controller support on Qualcomm SoCs. The
303305
PCIe controller uses the DesignWare core plus Qualcomm-specific

drivers/pci/controller/dwc/pci-exynos.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
struct exynos_pcie {
5555
struct dw_pcie pci;
56-
void __iomem *elbi_base;
5756
struct clk_bulk_data *clks;
5857
struct phy *phy;
5958
struct regulator_bulk_data supplies[2];
@@ -71,73 +70,78 @@ static u32 exynos_pcie_readl(void __iomem *base, u32 reg)
7170

7271
static void exynos_pcie_sideband_dbi_w_mode(struct exynos_pcie *ep, bool on)
7372
{
73+
struct dw_pcie *pci = &ep->pci;
7474
u32 val;
7575

76-
val = exynos_pcie_readl(ep->elbi_base, PCIE_ELBI_SLV_AWMISC);
76+
val = exynos_pcie_readl(pci->elbi_base, PCIE_ELBI_SLV_AWMISC);
7777
if (on)
7878
val |= PCIE_ELBI_SLV_DBI_ENABLE;
7979
else
8080
val &= ~PCIE_ELBI_SLV_DBI_ENABLE;
81-
exynos_pcie_writel(ep->elbi_base, val, PCIE_ELBI_SLV_AWMISC);
81+
exynos_pcie_writel(pci->elbi_base, val, PCIE_ELBI_SLV_AWMISC);
8282
}
8383

8484
static void exynos_pcie_sideband_dbi_r_mode(struct exynos_pcie *ep, bool on)
8585
{
86+
struct dw_pcie *pci = &ep->pci;
8687
u32 val;
8788

88-
val = exynos_pcie_readl(ep->elbi_base, PCIE_ELBI_SLV_ARMISC);
89+
val = exynos_pcie_readl(pci->elbi_base, PCIE_ELBI_SLV_ARMISC);
8990
if (on)
9091
val |= PCIE_ELBI_SLV_DBI_ENABLE;
9192
else
9293
val &= ~PCIE_ELBI_SLV_DBI_ENABLE;
93-
exynos_pcie_writel(ep->elbi_base, val, PCIE_ELBI_SLV_ARMISC);
94+
exynos_pcie_writel(pci->elbi_base, val, PCIE_ELBI_SLV_ARMISC);
9495
}
9596

9697
static void exynos_pcie_assert_core_reset(struct exynos_pcie *ep)
9798
{
99+
struct dw_pcie *pci = &ep->pci;
98100
u32 val;
99101

100-
val = exynos_pcie_readl(ep->elbi_base, PCIE_CORE_RESET);
102+
val = exynos_pcie_readl(pci->elbi_base, PCIE_CORE_RESET);
101103
val &= ~PCIE_CORE_RESET_ENABLE;
102-
exynos_pcie_writel(ep->elbi_base, val, PCIE_CORE_RESET);
103-
exynos_pcie_writel(ep->elbi_base, 0, PCIE_STICKY_RESET);
104-
exynos_pcie_writel(ep->elbi_base, 0, PCIE_NONSTICKY_RESET);
104+
exynos_pcie_writel(pci->elbi_base, val, PCIE_CORE_RESET);
105+
exynos_pcie_writel(pci->elbi_base, 0, PCIE_STICKY_RESET);
106+
exynos_pcie_writel(pci->elbi_base, 0, PCIE_NONSTICKY_RESET);
105107
}
106108

107109
static void exynos_pcie_deassert_core_reset(struct exynos_pcie *ep)
108110
{
111+
struct dw_pcie *pci = &ep->pci;
109112
u32 val;
110113

111-
val = exynos_pcie_readl(ep->elbi_base, PCIE_CORE_RESET);
114+
val = exynos_pcie_readl(pci->elbi_base, PCIE_CORE_RESET);
112115
val |= PCIE_CORE_RESET_ENABLE;
113116

114-
exynos_pcie_writel(ep->elbi_base, val, PCIE_CORE_RESET);
115-
exynos_pcie_writel(ep->elbi_base, 1, PCIE_STICKY_RESET);
116-
exynos_pcie_writel(ep->elbi_base, 1, PCIE_NONSTICKY_RESET);
117-
exynos_pcie_writel(ep->elbi_base, 1, PCIE_APP_INIT_RESET);
118-
exynos_pcie_writel(ep->elbi_base, 0, PCIE_APP_INIT_RESET);
117+
exynos_pcie_writel(pci->elbi_base, val, PCIE_CORE_RESET);
118+
exynos_pcie_writel(pci->elbi_base, 1, PCIE_STICKY_RESET);
119+
exynos_pcie_writel(pci->elbi_base, 1, PCIE_NONSTICKY_RESET);
120+
exynos_pcie_writel(pci->elbi_base, 1, PCIE_APP_INIT_RESET);
121+
exynos_pcie_writel(pci->elbi_base, 0, PCIE_APP_INIT_RESET);
119122
}
120123

121124
static int exynos_pcie_start_link(struct dw_pcie *pci)
122125
{
123-
struct exynos_pcie *ep = to_exynos_pcie(pci);
124126
u32 val;
125127

126-
val = exynos_pcie_readl(ep->elbi_base, PCIE_SW_WAKE);
128+
val = exynos_pcie_readl(pci->elbi_base, PCIE_SW_WAKE);
127129
val &= ~PCIE_BUS_EN;
128-
exynos_pcie_writel(ep->elbi_base, val, PCIE_SW_WAKE);
130+
exynos_pcie_writel(pci->elbi_base, val, PCIE_SW_WAKE);
129131

130132
/* assert LTSSM enable */
131-
exynos_pcie_writel(ep->elbi_base, PCIE_ELBI_LTSSM_ENABLE,
133+
exynos_pcie_writel(pci->elbi_base, PCIE_ELBI_LTSSM_ENABLE,
132134
PCIE_APP_LTSSM_ENABLE);
133135
return 0;
134136
}
135137

136138
static void exynos_pcie_clear_irq_pulse(struct exynos_pcie *ep)
137139
{
138-
u32 val = exynos_pcie_readl(ep->elbi_base, PCIE_IRQ_PULSE);
140+
struct dw_pcie *pci = &ep->pci;
139141

140-
exynos_pcie_writel(ep->elbi_base, val, PCIE_IRQ_PULSE);
142+
u32 val = exynos_pcie_readl(pci->elbi_base, PCIE_IRQ_PULSE);
143+
144+
exynos_pcie_writel(pci->elbi_base, val, PCIE_IRQ_PULSE);
141145
}
142146

143147
static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg)
@@ -150,12 +154,14 @@ static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg)
150154

151155
static void exynos_pcie_enable_irq_pulse(struct exynos_pcie *ep)
152156
{
157+
struct dw_pcie *pci = &ep->pci;
158+
153159
u32 val = IRQ_INTA_ASSERT | IRQ_INTB_ASSERT |
154160
IRQ_INTC_ASSERT | IRQ_INTD_ASSERT;
155161

156-
exynos_pcie_writel(ep->elbi_base, val, PCIE_IRQ_EN_PULSE);
157-
exynos_pcie_writel(ep->elbi_base, 0, PCIE_IRQ_EN_LEVEL);
158-
exynos_pcie_writel(ep->elbi_base, 0, PCIE_IRQ_EN_SPECIAL);
162+
exynos_pcie_writel(pci->elbi_base, val, PCIE_IRQ_EN_PULSE);
163+
exynos_pcie_writel(pci->elbi_base, 0, PCIE_IRQ_EN_LEVEL);
164+
exynos_pcie_writel(pci->elbi_base, 0, PCIE_IRQ_EN_SPECIAL);
159165
}
160166

161167
static u32 exynos_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base,
@@ -211,8 +217,7 @@ static struct pci_ops exynos_pci_ops = {
211217

212218
static bool exynos_pcie_link_up(struct dw_pcie *pci)
213219
{
214-
struct exynos_pcie *ep = to_exynos_pcie(pci);
215-
u32 val = exynos_pcie_readl(ep->elbi_base, PCIE_ELBI_RDLH_LINKUP);
220+
u32 val = exynos_pcie_readl(pci->elbi_base, PCIE_ELBI_RDLH_LINKUP);
216221

217222
return val & PCIE_ELBI_XMLH_LINKUP;
218223
}
@@ -295,11 +300,6 @@ static int exynos_pcie_probe(struct platform_device *pdev)
295300
if (IS_ERR(ep->phy))
296301
return PTR_ERR(ep->phy);
297302

298-
/* External Local Bus interface (ELBI) registers */
299-
ep->elbi_base = devm_platform_ioremap_resource_byname(pdev, "elbi");
300-
if (IS_ERR(ep->elbi_base))
301-
return PTR_ERR(ep->elbi_base);
302-
303303
ret = devm_clk_bulk_get_all_enabled(dev, &ep->clks);
304304
if (ret < 0)
305305
return ret;

drivers/pci/controller/dwc/pcie-al.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ static int al_pcie_probe(struct platform_device *pdev)
352352
return -ENOENT;
353353
}
354354
al_pcie->ecam_size = resource_size(ecam_res);
355+
pci->pp.native_ecam = true;
355356

356357
controller_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
357358
"controller");

drivers/pci/controller/dwc/pcie-designware-host.c

Lines changed: 134 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Author: Jingoo Han <[email protected]>
99
*/
1010

11+
#include <linux/align.h>
1112
#include <linux/iopoll.h>
1213
#include <linux/irqchip/chained_irq.h>
1314
#include <linux/irqchip/irq-msi-lib.h>
@@ -32,6 +33,8 @@ static struct pci_ops dw_child_pcie_ops;
3233
MSI_FLAG_PCI_MSIX | \
3334
MSI_GENERIC_FLAGS_MASK)
3435

36+
#define IS_256MB_ALIGNED(x) IS_ALIGNED(x, SZ_256M)
37+
3538
static const struct msi_parent_ops dw_pcie_msi_parent_ops = {
3639
.required_flags = DW_PCIE_MSI_FLAGS_REQUIRED,
3740
.supported_flags = DW_PCIE_MSI_FLAGS_SUPPORTED,
@@ -413,6 +416,95 @@ static void dw_pcie_host_request_msg_tlp_res(struct dw_pcie_rp *pp)
413416
}
414417
}
415418

419+
static int dw_pcie_config_ecam_iatu(struct dw_pcie_rp *pp)
420+
{
421+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
422+
struct dw_pcie_ob_atu_cfg atu = {0};
423+
resource_size_t bus_range_max;
424+
struct resource_entry *bus;
425+
int ret;
426+
427+
bus = resource_list_first_type(&pp->bridge->windows, IORESOURCE_BUS);
428+
429+
/*
430+
* Root bus under the host bridge doesn't require any iATU configuration
431+
* as DBI region will be used to access root bus config space.
432+
* Immediate bus under Root Bus, needs type 0 iATU configuration and
433+
* remaining buses need type 1 iATU configuration.
434+
*/
435+
atu.index = 0;
436+
atu.type = PCIE_ATU_TYPE_CFG0;
437+
atu.parent_bus_addr = pp->cfg0_base + SZ_1M;
438+
/* 1MiB is to cover 1 (bus) * 32 (devices) * 8 (functions) */
439+
atu.size = SZ_1M;
440+
atu.ctrl2 = PCIE_ATU_CFG_SHIFT_MODE_ENABLE;
441+
ret = dw_pcie_prog_outbound_atu(pci, &atu);
442+
if (ret)
443+
return ret;
444+
445+
bus_range_max = resource_size(bus->res);
446+
447+
if (bus_range_max < 2)
448+
return 0;
449+
450+
/* Configure remaining buses in type 1 iATU configuration */
451+
atu.index = 1;
452+
atu.type = PCIE_ATU_TYPE_CFG1;
453+
atu.parent_bus_addr = pp->cfg0_base + SZ_2M;
454+
atu.size = (SZ_1M * bus_range_max) - SZ_2M;
455+
atu.ctrl2 = PCIE_ATU_CFG_SHIFT_MODE_ENABLE;
456+
457+
return dw_pcie_prog_outbound_atu(pci, &atu);
458+
}
459+
460+
static int dw_pcie_create_ecam_window(struct dw_pcie_rp *pp, struct resource *res)
461+
{
462+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
463+
struct device *dev = pci->dev;
464+
struct resource_entry *bus;
465+
466+
bus = resource_list_first_type(&pp->bridge->windows, IORESOURCE_BUS);
467+
if (!bus)
468+
return -ENODEV;
469+
470+
pp->cfg = pci_ecam_create(dev, res, bus->res, &pci_generic_ecam_ops);
471+
if (IS_ERR(pp->cfg))
472+
return PTR_ERR(pp->cfg);
473+
474+
pci->dbi_base = pp->cfg->win;
475+
pci->dbi_phys_addr = res->start;
476+
477+
return 0;
478+
}
479+
480+
static bool dw_pcie_ecam_enabled(struct dw_pcie_rp *pp, struct resource *config_res)
481+
{
482+
struct resource *bus_range;
483+
u64 nr_buses;
484+
485+
/* Vendor glue drivers may implement their own ECAM mechanism */
486+
if (pp->native_ecam)
487+
return false;
488+
489+
/*
490+
* PCIe spec r6.0, sec 7.2.2 mandates the base address used for ECAM to
491+
* be aligned on a 2^(n+20) byte boundary, where n is the number of bits
492+
* used for representing 'bus' in BDF. Since the DWC cores always use 8
493+
* bits for representing 'bus', the base address has to be aligned to
494+
* 2^28 byte boundary, which is 256 MiB.
495+
*/
496+
if (!IS_256MB_ALIGNED(config_res->start))
497+
return false;
498+
499+
bus_range = resource_list_first_type(&pp->bridge->windows, IORESOURCE_BUS)->res;
500+
if (!bus_range)
501+
return false;
502+
503+
nr_buses = resource_size(config_res) >> PCIE_ECAM_BUS_SHIFT;
504+
505+
return nr_buses >= resource_size(bus_range);
506+
}
507+
416508
static int dw_pcie_host_get_resources(struct dw_pcie_rp *pp)
417509
{
418510
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
@@ -422,10 +514,6 @@ static int dw_pcie_host_get_resources(struct dw_pcie_rp *pp)
422514
struct resource *res;
423515
int ret;
424516

425-
ret = dw_pcie_get_resources(pci);
426-
if (ret)
427-
return ret;
428-
429517
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config");
430518
if (!res) {
431519
dev_err(dev, "Missing \"config\" reg space\n");
@@ -435,9 +523,32 @@ static int dw_pcie_host_get_resources(struct dw_pcie_rp *pp)
435523
pp->cfg0_size = resource_size(res);
436524
pp->cfg0_base = res->start;
437525

438-
pp->va_cfg0_base = devm_pci_remap_cfg_resource(dev, res);
439-
if (IS_ERR(pp->va_cfg0_base))
440-
return PTR_ERR(pp->va_cfg0_base);
526+
pp->ecam_enabled = dw_pcie_ecam_enabled(pp, res);
527+
if (pp->ecam_enabled) {
528+
ret = dw_pcie_create_ecam_window(pp, res);
529+
if (ret)
530+
return ret;
531+
532+
pp->bridge->ops = (struct pci_ops *)&pci_generic_ecam_ops.pci_ops;
533+
pp->bridge->sysdata = pp->cfg;
534+
pp->cfg->priv = pp;
535+
} else {
536+
pp->va_cfg0_base = devm_pci_remap_cfg_resource(dev, res);
537+
if (IS_ERR(pp->va_cfg0_base))
538+
return PTR_ERR(pp->va_cfg0_base);
539+
540+
/* Set default bus ops */
541+
pp->bridge->ops = &dw_pcie_ops;
542+
pp->bridge->child_ops = &dw_child_pcie_ops;
543+
pp->bridge->sysdata = pp;
544+
}
545+
546+
ret = dw_pcie_get_resources(pci);
547+
if (ret) {
548+
if (pp->cfg)
549+
pci_ecam_free(pp->cfg);
550+
return ret;
551+
}
441552

442553
/* Get the I/O range from DT */
443554
win = resource_list_first_type(&pp->bridge->windows, IORESOURCE_IO);
@@ -476,14 +587,10 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
476587
if (ret)
477588
return ret;
478589

479-
/* Set default bus ops */
480-
bridge->ops = &dw_pcie_ops;
481-
bridge->child_ops = &dw_child_pcie_ops;
482-
483590
if (pp->ops->init) {
484591
ret = pp->ops->init(pp);
485592
if (ret)
486-
return ret;
593+
goto err_free_ecam;
487594
}
488595

489596
if (pci_msi_enabled()) {
@@ -525,6 +632,14 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
525632
if (ret)
526633
goto err_free_msi;
527634

635+
if (pp->ecam_enabled) {
636+
ret = dw_pcie_config_ecam_iatu(pp);
637+
if (ret) {
638+
dev_err(dev, "Failed to configure iATU in ECAM mode\n");
639+
goto err_free_msi;
640+
}
641+
}
642+
528643
/*
529644
* Allocate the resource for MSG TLP before programming the iATU
530645
* outbound window in dw_pcie_setup_rc(). Since the allocation depends
@@ -560,8 +675,6 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
560675
/* Ignore errors, the link may come up later */
561676
dw_pcie_wait_for_link(pci);
562677

563-
bridge->sysdata = pp;
564-
565678
ret = pci_host_probe(bridge);
566679
if (ret)
567680
goto err_stop_link;
@@ -587,6 +700,10 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
587700
if (pp->ops->deinit)
588701
pp->ops->deinit(pp);
589702

703+
err_free_ecam:
704+
if (pp->cfg)
705+
pci_ecam_free(pp->cfg);
706+
590707
return ret;
591708
}
592709
EXPORT_SYMBOL_GPL(dw_pcie_host_init);
@@ -609,6 +726,9 @@ void dw_pcie_host_deinit(struct dw_pcie_rp *pp)
609726

610727
if (pp->ops->deinit)
611728
pp->ops->deinit(pp);
729+
730+
if (pp->cfg)
731+
pci_ecam_free(pp->cfg);
612732
}
613733
EXPORT_SYMBOL_GPL(dw_pcie_host_deinit);
614734

0 commit comments

Comments
 (0)