]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI: dwc: Use parent_bus_offset to remove need for .cpu_addr_fixup()
authorFrank Li <Frank.Li@nxp.com>
Sat, 15 Mar 2025 20:15:47 +0000 (15:15 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 24 Mar 2025 19:58:34 +0000 (14:58 -0500)
We know the parent_bus_offset, either computed from a DT reg property (the
offset is the CPU physical addr - the 'config'/'addr_space' address on the
parent bus) or from a .cpu_addr_fixup() (which may have used a host bridge
window offset).

Apply that parent_bus_offset instead of calling .cpu_addr_fixup() when
programming the ATU.

This assumes all intermediate addresses are at the same offset from the CPU
physical addresses.

[bhelgaas: commit log]
Link: https://lore.kernel.org/r/20250315201548.858189-13-helgaas@kernel.org
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/controller/dwc/pcie-designware-ep.c
drivers/pci/controller/dwc/pcie-designware-host.c
drivers/pci/controller/dwc/pcie-designware.c

index 2ef9964fa0808b559aee60a0eb7a0c4885905851..c1feaadb046a9d29c1bb7ac7d33122f2e69bf103 100644 (file)
@@ -314,7 +314,8 @@ static void dw_pcie_ep_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
        struct dw_pcie_ep *ep = epc_get_drvdata(epc);
        struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
 
-       ret = dw_pcie_find_index(ep, addr, &atu_index);
+       ret = dw_pcie_find_index(ep, addr - pci->parent_bus_offset,
+                                &atu_index);
        if (ret < 0)
                return;
 
@@ -333,7 +334,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
 
        atu.func_no = func_no;
        atu.type = PCIE_ATU_TYPE_MEM;
-       atu.parent_bus_addr = addr;
+       atu.parent_bus_addr = addr - pci->parent_bus_offset;
        atu.pci_addr = pci_addr;
        atu.size = size;
        ret = dw_pcie_ep_outbound_atu(ep, &atu);
index 9e38ac7d1bcb707ddd465630afc7addb98b97a4e..d760abcbb785ea777f3d9bd62b199854622f4cc5 100644 (file)
@@ -635,7 +635,7 @@ static void __iomem *dw_pcie_other_conf_map_bus(struct pci_bus *bus,
                type = PCIE_ATU_TYPE_CFG1;
 
        atu.type = type;
-       atu.parent_bus_addr = pp->cfg0_base;
+       atu.parent_bus_addr = pp->cfg0_base - pci->parent_bus_offset;
        atu.pci_addr = busdev;
        atu.size = pp->cfg0_size;
 
@@ -660,7 +660,7 @@ static int dw_pcie_rd_other_conf(struct pci_bus *bus, unsigned int devfn,
 
        if (pp->cfg0_io_shared) {
                atu.type = PCIE_ATU_TYPE_IO;
-               atu.parent_bus_addr = pp->io_base;
+               atu.parent_bus_addr = pp->io_base - pci->parent_bus_offset;
                atu.pci_addr = pp->io_bus_addr;
                atu.size = pp->io_size;
 
@@ -686,7 +686,7 @@ static int dw_pcie_wr_other_conf(struct pci_bus *bus, unsigned int devfn,
 
        if (pp->cfg0_io_shared) {
                atu.type = PCIE_ATU_TYPE_IO;
-               atu.parent_bus_addr = pp->io_base;
+               atu.parent_bus_addr = pp->io_base - pci->parent_bus_offset;
                atu.pci_addr = pp->io_bus_addr;
                atu.size = pp->io_size;
 
@@ -755,7 +755,7 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)
 
                atu.index = i;
                atu.type = PCIE_ATU_TYPE_MEM;
-               atu.parent_bus_addr = entry->res->start;
+               atu.parent_bus_addr = entry->res->start - pci->parent_bus_offset;
                atu.pci_addr = entry->res->start - entry->offset;
 
                /* Adjust iATU size if MSG TLP region was allocated before */
@@ -777,7 +777,7 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)
                if (pci->num_ob_windows > ++i) {
                        atu.index = i;
                        atu.type = PCIE_ATU_TYPE_IO;
-                       atu.parent_bus_addr = pp->io_base;
+                       atu.parent_bus_addr = pp->io_base - pci->parent_bus_offset;
                        atu.pci_addr = pp->io_bus_addr;
                        atu.size = pp->io_size;
 
@@ -921,7 +921,7 @@ static int dw_pcie_pme_turn_off(struct dw_pcie *pci)
        atu.size = resource_size(pci->pp.msg_res);
        atu.index = pci->pp.msg_atu_index;
 
-       atu.parent_bus_addr = pci->pp.msg_res->start;
+       atu.parent_bus_addr = pci->pp.msg_res->start - pci->parent_bus_offset;
 
        ret = dw_pcie_prog_outbound_atu(pci, &atu);
        if (ret)
index 4b442d1aa55b50ca527ab6776fd866849cab2b0e..151085343adea33cdf89fe4fa7f3581924e00ac8 100644 (file)
@@ -475,9 +475,6 @@ int dw_pcie_prog_outbound_atu(struct dw_pcie *pci,
        u32 retries, val;
        u64 limit_addr;
 
-       if (pci->ops && pci->ops->cpu_addr_fixup)
-               parent_bus_addr = pci->ops->cpu_addr_fixup(pci, parent_bus_addr);
-
        limit_addr = parent_bus_addr + atu->size - 1;
 
        if ((limit_addr & ~pci->region_limit) != (parent_bus_addr & ~pci->region_limit) ||