Skip to content

Commit

Permalink
Ported pcie-brcmstb bounce buffer implementation to ARM64. (#3144)
Browse files Browse the repository at this point in the history
Ported pcie-brcmstb bounce buffer implementation to ARM64.
This enables full 4G RAM usage on Raspberry Pi in 64-bit mode.

Signed-off-by: Yaroslav Rosomakho <[email protected]>

pcie-brcmstb: Correct SoC name

The Pi 4 SoC is called BCM2711, not BCM2838.

Fixes: "bcm2835-dma: Add proper 40-bit DMA support"
Fixes: "Ported pcie-brcmstb bounce buffer implementation to ARM64."

Signed-off-by: Phil Elwell <[email protected]>

pcie-brcmstb-bounce64.c: dev_err() -> dev_info() for info messages

"dmabounce: initialised" is not an error, so do not log it as such.
Prevents screen polution on OS with "quiet" as kernel parameter.

Closes #3266

pcie-brcmstb: Remove brcm_to_*, add pcie_to_dma40

The DMA framework performs the necessary address conversions for the
common cases based on the dma-ranges DT property. brcm_to_pci and
brcm_to_cpu were probably designed for non-DT use cases, something
which isn't an issue for 2711. This second level of mapping causes
breakage with a non-identity PCIe<->system address mapping, so remove
it completely.

The non-identity mapping also broke the DMA40 support, so add back a
simple translation from PCIe to sys addresses.

arm64 builds also require a wider coherent_dma_mask, otherwise the
bounce buffer allocation is rejected.

Signed-off-by: Phil Elwell <[email protected]>
  • Loading branch information
yaroslavros authored and pelwell committed Feb 25, 2020
1 parent 85dcbaa commit 2cfb1fa
Show file tree
Hide file tree
Showing 5 changed files with 645 additions and 85 deletions.
29 changes: 29 additions & 0 deletions arch/arm64/mm/dma-mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ void arch_dma_prep_coherent(struct page *page, size_t size)
}

#ifdef CONFIG_IOMMU_DMA
static int __swiotlb_get_sgtable_page(struct sg_table *sgt,
struct page *page, size_t size)
{
int ret = sg_alloc_table(sgt, 1, GFP_KERNEL);

if (!ret)
sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0);

return ret;
}

static int __swiotlb_mmap_pfn(struct vm_area_struct *vma,
unsigned long pfn, size_t size)
{
int ret = -ENXIO;
unsigned long nr_vma_pages = vma_pages(vma);
unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
unsigned long off = vma->vm_pgoff;

if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) {
ret = remap_pfn_range(vma, vma->vm_start,
pfn + off,
vma->vm_end - vma->vm_start,
vma->vm_page_prot);
}

return ret;
}

void arch_teardown_dma_ops(struct device *dev)
{
dev->dma_ops = NULL;
Expand Down
3 changes: 3 additions & 0 deletions drivers/pci/controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb.o
ifdef CONFIG_ARM
obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb-bounce.o
endif
ifdef CONFIG_ARM64
obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb-bounce64.o
endif

obj-$(CONFIG_VMD) += vmd.o
obj-$(CONFIG_PCIE_BRCMSTB) += pcie-brcmstb.o
Expand Down
6 changes: 3 additions & 3 deletions drivers/pci/controller/pcie-brcmstb-bounce.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
#ifndef _PCIE_BRCMSTB_BOUNCE_H
#define _PCIE_BRCMSTB_BOUNCE_H

#ifdef CONFIG_ARM
#if defined(CONFIG_ARM) || defined(CONFIG_ARM64)

int brcm_pcie_bounce_init(struct device *dev, unsigned long buffer_size,
dma_addr_t threshold);
phys_addr_t threshold);
int brcm_pcie_bounce_uninit(struct device *dev);
int brcm_pcie_bounce_register_dev(struct device *dev);

#else

static inline int brcm_pcie_bounce_init(struct device *dev,
unsigned long buffer_size,
dma_addr_t threshold)
phys_addr_t threshold)
{
return 0;
}
Expand Down
Loading

0 comments on commit 2cfb1fa

Please sign in to comment.