Skip to content

Commit f4c55c5

Browse files
kishonbjorn-helgaas
authored andcommitted
PCI: designware: Program ATU with untranslated address
In DRA7, the CPU sees 32-bit addresses, but the PCIe controller can see only 28-bit addresses. So whenever the CPU issues a read/write request, the 4 most significant bits are used by L3 to determine the target controller. For example, the CPU reserves [mem 0x20000000-0x2fffffff] for the PCIe controller but the PCIe controller will see only [0x00000000-0x0fffffff]. For programming the outbound translation window the *base* should be programmed as 0x00000000. Whenever we try to write to, e.g., 0x20000000, it will be translated to whatever we have programmed in the translation window with base as 0x00000000. This is needed when the dt node is modelled something like this: axi { compatible = "simple-bus"; #size-cells = <1>; #address-cells = <1>; ranges = <0x0 0x20000000 0x10000000 // 28-bit bus 0x51000000 0x51000000 0x3000>; pcie@51000000 { reg = <0x1000 0x2000>, <0x51002000 0x14c>, <0x51000000 0x2000>; reg-names = "config", "ti_conf", "rc_dbics"; #address-cells = <3>; #size-cells = <2>; ranges = <0x81000000 0 0 0x03000 0 0x00010000 0x82000000 0 0x20013000 0x13000 0 0xffed000>; }; }; Here the CPU address for configuration space is 0x20013000 and the controller address for configuration space is 0x13000. The controller address should be used while programming the ATU (in order for translation to happen properly in DRA7xx). Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Mohit Kumar <mohit.kumar@st.com> Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Cc: Jingoo Han <jg1.han@samsung.com> Cc: Marek Vasut <marex@denx.de> Cc: Arnd Bergmann <arnd@arndb.de>
1 parent 4dd964d commit f4c55c5

2 files changed

Lines changed: 45 additions & 14 deletions

File tree

‎drivers/pci/host/pcie-designware.c‎

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,28 @@ int __init dw_pcie_host_init(struct pcie_port *pp)
401401
struct of_pci_range range;
402402
struct of_pci_range_parser parser;
403403
struct resource *cfg_res;
404-
u32 val;
405-
int i;
404+
u32 val, na, ns;
405+
const __be32 *addrp;
406+
int i, index;
407+
408+
/* Find the address cell size and the number of cells in order to get
409+
* the untranslated address.
410+
*/
411+
of_property_read_u32(np, "#address-cells", &na);
412+
ns = of_n_size_cells(np);
406413

407414
cfg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config");
408415
if (cfg_res) {
409416
pp->config.cfg0_size = resource_size(cfg_res)/2;
410417
pp->config.cfg1_size = resource_size(cfg_res)/2;
411418
pp->cfg0_base = cfg_res->start;
412419
pp->cfg1_base = cfg_res->start + pp->config.cfg0_size;
420+
421+
/* Find the untranslated configuration space address */
422+
index = of_property_match_string(np, "reg-names", "config");
423+
addrp = of_get_address(np, index, false, false);
424+
pp->cfg0_mod_base = of_read_number(addrp, ns);
425+
pp->cfg1_mod_base = pp->cfg0_mod_base + pp->config.cfg0_size;
413426
} else {
414427
dev_err(pp->dev, "missing *config* reg space\n");
415428
}
@@ -435,19 +448,33 @@ int __init dw_pcie_host_init(struct pcie_port *pp)
435448
pp->config.io_size = resource_size(&pp->io);
436449
pp->config.io_bus_addr = range.pci_addr;
437450
pp->io_base = range.cpu_addr;
451+
452+
/* Find the untranslated IO space address */
453+
pp->io_mod_base = of_read_number(parser.range -
454+
parser.np + na, ns);
438455
}
439456
if (restype == IORESOURCE_MEM) {
440457
of_pci_range_to_resource(&range, np, &pp->mem);
441458
pp->mem.name = "MEM";
442459
pp->config.mem_size = resource_size(&pp->mem);
443460
pp->config.mem_bus_addr = range.pci_addr;
461+
462+
/* Find the untranslated MEM space address */
463+
pp->mem_mod_base = of_read_number(parser.range -
464+
parser.np + na, ns);
444465
}
445466
if (restype == 0) {
446467
of_pci_range_to_resource(&range, np, &pp->cfg);
447468
pp->config.cfg0_size = resource_size(&pp->cfg)/2;
448469
pp->config.cfg1_size = resource_size(&pp->cfg)/2;
449470
pp->cfg0_base = pp->cfg.start;
450471
pp->cfg1_base = pp->cfg.start + pp->config.cfg0_size;
472+
473+
/* Find the untranslated configuration space address */
474+
pp->cfg0_mod_base = of_read_number(parser.range -
475+
parser.np + na, ns);
476+
pp->cfg1_mod_base = pp->cfg0_mod_base +
477+
pp->config.cfg0_size;
451478
}
452479
}
453480

@@ -522,9 +549,9 @@ static void dw_pcie_prog_viewport_cfg0(struct pcie_port *pp, u32 busdev)
522549
/* Program viewport 0 : OUTBOUND : CFG0 */
523550
dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0,
524551
PCIE_ATU_VIEWPORT);
525-
dw_pcie_writel_rc(pp, pp->cfg0_base, PCIE_ATU_LOWER_BASE);
526-
dw_pcie_writel_rc(pp, (pp->cfg0_base >> 32), PCIE_ATU_UPPER_BASE);
527-
dw_pcie_writel_rc(pp, pp->cfg0_base + pp->config.cfg0_size - 1,
552+
dw_pcie_writel_rc(pp, pp->cfg0_mod_base, PCIE_ATU_LOWER_BASE);
553+
dw_pcie_writel_rc(pp, (pp->cfg0_mod_base >> 32), PCIE_ATU_UPPER_BASE);
554+
dw_pcie_writel_rc(pp, pp->cfg0_mod_base + pp->config.cfg0_size - 1,
528555
PCIE_ATU_LIMIT);
529556
dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET);
530557
dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET);
@@ -538,9 +565,9 @@ static void dw_pcie_prog_viewport_cfg1(struct pcie_port *pp, u32 busdev)
538565
dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
539566
PCIE_ATU_VIEWPORT);
540567
dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG1, PCIE_ATU_CR1);
541-
dw_pcie_writel_rc(pp, pp->cfg1_base, PCIE_ATU_LOWER_BASE);
542-
dw_pcie_writel_rc(pp, (pp->cfg1_base >> 32), PCIE_ATU_UPPER_BASE);
543-
dw_pcie_writel_rc(pp, pp->cfg1_base + pp->config.cfg1_size - 1,
568+
dw_pcie_writel_rc(pp, pp->cfg1_mod_base, PCIE_ATU_LOWER_BASE);
569+
dw_pcie_writel_rc(pp, (pp->cfg1_mod_base >> 32), PCIE_ATU_UPPER_BASE);
570+
dw_pcie_writel_rc(pp, pp->cfg1_mod_base + pp->config.cfg1_size - 1,
544571
PCIE_ATU_LIMIT);
545572
dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET);
546573
dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET);
@@ -553,9 +580,9 @@ static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp)
553580
dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0,
554581
PCIE_ATU_VIEWPORT);
555582
dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1);
556-
dw_pcie_writel_rc(pp, pp->mem_base, PCIE_ATU_LOWER_BASE);
557-
dw_pcie_writel_rc(pp, (pp->mem_base >> 32), PCIE_ATU_UPPER_BASE);
558-
dw_pcie_writel_rc(pp, pp->mem_base + pp->config.mem_size - 1,
583+
dw_pcie_writel_rc(pp, pp->mem_mod_base, PCIE_ATU_LOWER_BASE);
584+
dw_pcie_writel_rc(pp, (pp->mem_mod_base >> 32), PCIE_ATU_UPPER_BASE);
585+
dw_pcie_writel_rc(pp, pp->mem_mod_base + pp->config.mem_size - 1,
559586
PCIE_ATU_LIMIT);
560587
dw_pcie_writel_rc(pp, pp->config.mem_bus_addr, PCIE_ATU_LOWER_TARGET);
561588
dw_pcie_writel_rc(pp, upper_32_bits(pp->config.mem_bus_addr),
@@ -569,9 +596,9 @@ static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp)
569596
dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
570597
PCIE_ATU_VIEWPORT);
571598
dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_IO, PCIE_ATU_CR1);
572-
dw_pcie_writel_rc(pp, pp->io_base, PCIE_ATU_LOWER_BASE);
573-
dw_pcie_writel_rc(pp, (pp->io_base >> 32), PCIE_ATU_UPPER_BASE);
574-
dw_pcie_writel_rc(pp, pp->io_base + pp->config.io_size - 1,
599+
dw_pcie_writel_rc(pp, pp->io_mod_base, PCIE_ATU_LOWER_BASE);
600+
dw_pcie_writel_rc(pp, (pp->io_mod_base >> 32), PCIE_ATU_UPPER_BASE);
601+
dw_pcie_writel_rc(pp, pp->io_mod_base + pp->config.io_size - 1,
575602
PCIE_ATU_LIMIT);
576603
dw_pcie_writel_rc(pp, pp->config.io_bus_addr, PCIE_ATU_LOWER_TARGET);
577604
dw_pcie_writel_rc(pp, upper_32_bits(pp->config.io_bus_addr),

‎drivers/pci/host/pcie-designware.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ struct pcie_port {
3636
u8 root_bus_nr;
3737
void __iomem *dbi_base;
3838
u64 cfg0_base;
39+
u64 cfg0_mod_base;
3940
void __iomem *va_cfg0_base;
4041
u64 cfg1_base;
42+
u64 cfg1_mod_base;
4143
void __iomem *va_cfg1_base;
4244
u64 io_base;
45+
u64 io_mod_base;
4346
u64 mem_base;
47+
u64 mem_mod_base;
4448
struct resource cfg;
4549
struct resource io;
4650
struct resource mem;

0 commit comments

Comments
 (0)