Skip to content

Commit d07701a

Browse files
kishonLorenzo Pieralisi
authored andcommitted
PCI: cadence: Add new *ops* for CPU addr fixup
Cadence driver uses "mem" memory resource to obtain the offset of configuration space address region, memory space address region and message space address region. The obtained offset is used to program the Address Translation Unit (ATU). However certain platforms like TI's J721E SoC require the absolute address to be programmed in the ATU and not just the offset. Add new *ops* for CPU addr fixup for the platform drivers to provide the correct address to be programmed in the ATU. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]>
1 parent f87b838 commit d07701a

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,14 @@ static int cdns_pcie_host_map_dma_ranges(struct cdns_pcie_rc *rc)
328328
static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
329329
{
330330
struct cdns_pcie *pcie = &rc->pcie;
331-
struct resource *mem_res = pcie->mem_res;
332331
struct resource *bus_range = rc->bus_range;
333332
struct resource *cfg_res = rc->cfg_res;
334333
struct device *dev = pcie->dev;
335334
struct device_node *np = dev->of_node;
336335
struct of_pci_range_parser parser;
336+
u64 cpu_addr = cfg_res->start;
337337
struct of_pci_range range;
338338
u32 addr0, addr1, desc1;
339-
u64 cpu_addr;
340339
int r, err;
341340

342341
/*
@@ -349,7 +348,9 @@ static int cdns_pcie_host_init_address_translation(struct cdns_pcie_rc *rc)
349348
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_PCI_ADDR1(0), addr1);
350349
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(0), desc1);
351350

352-
cpu_addr = cfg_res->start - mem_res->start;
351+
if (pcie->ops->cpu_addr_fixup)
352+
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
353+
353354
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(12) |
354355
(lower_32_bits(cpu_addr) & GENMASK(31, 8));
355356
addr1 = upper_32_bits(cpu_addr);
@@ -478,14 +479,6 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
478479
}
479480
rc->cfg_res = res;
480481

481-
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem");
482-
if (!res) {
483-
dev_err(dev, "missing \"mem\"\n");
484-
return -EINVAL;
485-
}
486-
487-
pcie->mem_res = res;
488-
489482
ret = cdns_pcie_start_link(pcie);
490483
if (ret) {
491484
dev_err(dev, "Failed to start link\n");

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/of_device.h>
1414
#include "pcie-cadence.h"
1515

16+
#define CDNS_PLAT_CPU_TO_BUS_ADDR 0x0FFFFFFF
17+
1618
/**
1719
* struct cdns_plat_pcie - private data for this PCIe platform driver
1820
* @pcie: Cadence PCIe controller
@@ -30,6 +32,15 @@ struct cdns_plat_pcie_of_data {
3032

3133
static const struct of_device_id cdns_plat_pcie_of_match[];
3234

35+
static u64 cdns_plat_cpu_addr_fixup(struct cdns_pcie *pcie, u64 cpu_addr)
36+
{
37+
return cpu_addr & CDNS_PLAT_CPU_TO_BUS_ADDR;
38+
}
39+
40+
static const struct cdns_pcie_ops cdns_plat_ops = {
41+
.cpu_addr_fixup = cdns_plat_cpu_addr_fixup,
42+
};
43+
3344
static int cdns_plat_pcie_probe(struct platform_device *pdev)
3445
{
3546
const struct cdns_plat_pcie_of_data *data;
@@ -66,6 +77,7 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
6677

6778
rc = pci_host_bridge_priv(bridge);
6879
rc->pcie.dev = dev;
80+
rc->pcie.ops = &cdns_plat_ops;
6981
cdns_plat_pcie->pcie = &rc->pcie;
7082
cdns_plat_pcie->is_rc = is_rc;
7183

@@ -93,6 +105,7 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)
93105
return -ENOMEM;
94106

95107
ep->pcie.dev = dev;
108+
ep->pcie.ops = &cdns_plat_ops;
96109
cdns_plat_pcie->pcie = &ep->pcie;
97110
cdns_plat_pcie->is_rc = is_rc;
98111

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 fn,
7373
cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_DESC1(r), desc1);
7474

7575
/* Set the CPU address */
76-
cpu_addr -= pcie->mem_res->start;
76+
if (pcie->ops->cpu_addr_fixup)
77+
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
78+
7779
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(nbits) |
7880
(lower_32_bits(cpu_addr) & GENMASK(31, 8));
7981
addr1 = upper_32_bits(cpu_addr);
@@ -100,7 +102,9 @@ void cdns_pcie_set_outbound_region_for_normal_msg(struct cdns_pcie *pcie, u8 fn,
100102
}
101103

102104
/* Set the CPU address */
103-
cpu_addr -= pcie->mem_res->start;
105+
if (pcie->ops->cpu_addr_fixup)
106+
cpu_addr = pcie->ops->cpu_addr_fixup(pcie, cpu_addr);
107+
104108
addr0 = CDNS_PCIE_AT_OB_REGION_CPU_ADDR0_NBITS(17) |
105109
(lower_32_bits(cpu_addr) & GENMASK(31, 8));
106110
addr1 = upper_32_bits(cpu_addr);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ struct cdns_pcie_ops {
254254
int (*start_link)(struct cdns_pcie *pcie);
255255
void (*stop_link)(struct cdns_pcie *pcie);
256256
bool (*link_up)(struct cdns_pcie *pcie);
257+
u64 (*cpu_addr_fixup)(struct cdns_pcie *pcie, u64 cpu_addr);
257258
};
258259

259260
/**

0 commit comments

Comments
 (0)