]> git.itanic.dy.fi Git - linux-stable/commitdiff
dmaengine: dw-edma: Convert ll/dt phys address to PCI bus/DMA address
authorSerge Semin <Sergey.Semin@baikalelectronics.ru>
Fri, 13 Jan 2023 17:13:45 +0000 (20:13 +0300)
committerLorenzo Pieralisi <lpieralisi@kernel.org>
Fri, 27 Jan 2023 16:15:33 +0000 (17:15 +0100)
The dw_edma_region.paddr field should be a memory base address visible by
the DW eDMA controller. If the DMA engine is embedded in the DW PCIe
Host/Endpoint controller, the address should belong to the Local CPU/
Application memory.  If eDMA is remotely accessible across the PCI bus via
PCI memory IOs, the address should be part of the PCI bus memory space.
The latter case hasn't been well covered in the corresponding glue-driver.

Since pci_dev.resource[] contains resources defined in the CPU memory
space, they need to be converted to the PCI bus address space.  Convert the
LL, DT and CSRs PCI memory ranges with pci_bus_address().

In addition, extend the dw_edma_region.paddr field size. The field normally
contains a memory range base address to be set in the DW eDMA Linked-List
pointer register or as a base address of the Linked-List data buffer. In
accordance with [1] the LL range is supposed to be created in the Local
CPU/Application memory, but depending on the DW eDMA utilization the memory
can be created as a part of the PCI bus address space (as in the case of
the DW PCIe Endpoint prototype kit).

In the former case dw_edma_region.paddr should be a dma_addr_t, while in
the latter one it should be a pci_bus_addr_t. Since the corresponding CSRs
are always 64 bits wide, convert dw_edma_region.paddr to be u64, and let
the client make sure it has a valid address visible by the DW eDMA
controller. For instance, the DW eDMA PCIe glue-driver initializes the
field with addresses from the PCI bus memory space.

[1] DesignWare Cores PCI Express Controller Databook - DWC PCIe Root Port,
    v.5.40a, March 2019, p.1103

Link: https://lore.kernel.org/r/20230113171409.30470-4-Sergey.Semin@baikalelectronics.ru
Fixes: 41aaff2a2ac0 ("dmaengine: Add Synopsys eDMA IP PCIe glue-logic")
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
Signed-off-by: Lorenzo Pieralisi <lpieralisi@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Acked-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/dw-edma/dw-edma-pcie.c
include/linux/dma/edma.h

index d6b5e246388471bc34b06b7a7888b36900116689..04c95cba1244bd7a66d8efebe68f56bf49fe8cbb 100644 (file)
@@ -231,7 +231,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
                        return -ENOMEM;
 
                ll_region->vaddr += ll_block->off;
-               ll_region->paddr = pdev->resource[ll_block->bar].start;
+               ll_region->paddr = pci_bus_address(pdev, ll_block->bar);
                ll_region->paddr += ll_block->off;
                ll_region->sz = ll_block->sz;
 
@@ -240,7 +240,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
                        return -ENOMEM;
 
                dt_region->vaddr += dt_block->off;
-               dt_region->paddr = pdev->resource[dt_block->bar].start;
+               dt_region->paddr = pci_bus_address(pdev, dt_block->bar);
                dt_region->paddr += dt_block->off;
                dt_region->sz = dt_block->sz;
        }
@@ -256,7 +256,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
                        return -ENOMEM;
 
                ll_region->vaddr += ll_block->off;
-               ll_region->paddr = pdev->resource[ll_block->bar].start;
+               ll_region->paddr = pci_bus_address(pdev, ll_block->bar);
                ll_region->paddr += ll_block->off;
                ll_region->sz = ll_block->sz;
 
@@ -265,7 +265,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
                        return -ENOMEM;
 
                dt_region->vaddr += dt_block->off;
-               dt_region->paddr = pdev->resource[dt_block->bar].start;
+               dt_region->paddr = pci_bus_address(pdev, dt_block->bar);
                dt_region->paddr += dt_block->off;
                dt_region->sz = dt_block->sz;
        }
index 7d8062e9c544c170b5653d04dc27486b0582c911..a864978ddd27dc40e230ed7b04e2d03ece113edc 100644 (file)
@@ -18,7 +18,7 @@
 struct dw_edma;
 
 struct dw_edma_region {
-       phys_addr_t     paddr;
+       u64             paddr;
        void __iomem    *vaddr;
        size_t          sz;
 };