Merge tag 'dma-mapping-4.18' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig: - replace the force_dma flag with a dma_configure bus method. (Nipun Gupta, although one patch is іncorrectly attributed to me due to a git rebase bug) - use GFP_DMA32 more agressively in dma-direct. (Takashi Iwai) - remove PCI_DMA_BUS_IS_PHYS and rely on the dma-mapping API to do the right thing for bounce buffering. - move dma-debug initialization to common code, and apply a few cleanups to the dma-debug code. - cleanup the Kconfig mess around swiotlb selection - swiotlb comment fixup (Yisheng Xie) - a trivial swiotlb fix. (Dan Carpenter) - support swiotlb on RISC-V. (based on a patch from Palmer Dabbelt) - add a new generic dma-noncoherent dma_map_ops implementation and use it for arc, c6x and nds32. - improve scatterlist validity checking in dma-debug. (Robin Murphy) - add a struct device quirk to limit the dma-mask to 32-bit due to bridge/system issues, and switch x86 to use it instead of a local hack for VIA bridges. - handle devices without a dma_mask more gracefully in the dma-direct code. * tag 'dma-mapping-4.18' of git://git.infradead.org/users/hch/dma-mapping: (48 commits) dma-direct: don't crash on device without dma_mask nds32: use generic dma_noncoherent_ops nds32: implement the unmap_sg DMA operation nds32: consolidate DMA cache maintainance routines x86/pci-dma: switch the VIA 32-bit DMA quirk to use the struct device flag x86/pci-dma: remove the explicit nodac and allowdac option x86/pci-dma: remove the experimental forcesac boot option Documentation/x86: remove a stray reference to pci-nommu.c core, dma-direct: add a flag 32-bit dma limits dma-mapping: remove unused gfp_t parameter to arch_dma_alloc_attrs dma-debug: check scatterlist segments c6x: use generic dma_noncoherent_ops arc: use generic dma_noncoherent_ops arc: fix arc_dma_{map,unmap}_page arc: fix arc_dma_sync_sg_for_{cpu,device} arc: simplify arc_dma_sync_single_for_{cpu,device} dma-mapping: provide a generic dma-noncoherent implementation dma-mapping: simplify Kconfig dependencies riscv: add swiotlb support riscv: only enable ZONE_DMA32 for 64-bit ...
This commit is contained in:
@@ -3,17 +3,14 @@
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/dma-noncoherent.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/cache.h>
|
||||
#include <linux/highmem.h>
|
||||
#include <linux/slab.h>
|
||||
#include <asm/cacheflush.h>
|
||||
#include <asm/tlbflush.h>
|
||||
#include <asm/dma-mapping.h>
|
||||
#include <asm/proc-fns.h>
|
||||
|
||||
/*
|
||||
@@ -22,11 +19,6 @@
|
||||
static pte_t *consistent_pte;
|
||||
static DEFINE_RAW_SPINLOCK(consistent_lock);
|
||||
|
||||
enum master_type {
|
||||
FOR_CPU = 0,
|
||||
FOR_DEVICE = 1,
|
||||
};
|
||||
|
||||
/*
|
||||
* VM region handling support.
|
||||
*
|
||||
@@ -124,10 +116,8 @@ out:
|
||||
return c;
|
||||
}
|
||||
|
||||
/* FIXME: attrs is not used. */
|
||||
static void *nds32_dma_alloc_coherent(struct device *dev, size_t size,
|
||||
dma_addr_t * handle, gfp_t gfp,
|
||||
unsigned long attrs)
|
||||
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
|
||||
gfp_t gfp, unsigned long attrs)
|
||||
{
|
||||
struct page *page;
|
||||
struct arch_vm_region *c;
|
||||
@@ -232,8 +222,8 @@ no_page:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void nds32_dma_free(struct device *dev, size_t size, void *cpu_addr,
|
||||
dma_addr_t handle, unsigned long attrs)
|
||||
void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
|
||||
dma_addr_t handle, unsigned long attrs)
|
||||
{
|
||||
struct arch_vm_region *c;
|
||||
unsigned long flags, addr;
|
||||
@@ -333,145 +323,69 @@ static int __init consistent_init(void)
|
||||
}
|
||||
|
||||
core_initcall(consistent_init);
|
||||
static void consistent_sync(void *vaddr, size_t size, int direction, int master_type);
|
||||
static dma_addr_t nds32_dma_map_page(struct device *dev, struct page *page,
|
||||
unsigned long offset, size_t size,
|
||||
enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
|
||||
static inline void cache_op(phys_addr_t paddr, size_t size,
|
||||
void (*fn)(unsigned long start, unsigned long end))
|
||||
{
|
||||
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
||||
consistent_sync((void *)(page_address(page) + offset), size, dir, FOR_DEVICE);
|
||||
return page_to_phys(page) + offset;
|
||||
}
|
||||
struct page *page = pfn_to_page(paddr >> PAGE_SHIFT);
|
||||
unsigned offset = paddr & ~PAGE_MASK;
|
||||
size_t left = size;
|
||||
unsigned long start;
|
||||
|
||||
static void nds32_dma_unmap_page(struct device *dev, dma_addr_t handle,
|
||||
size_t size, enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
{
|
||||
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
||||
consistent_sync(phys_to_virt(handle), size, dir, FOR_CPU);
|
||||
}
|
||||
do {
|
||||
size_t len = left;
|
||||
|
||||
/*
|
||||
* Make an area consistent for devices.
|
||||
*/
|
||||
static void consistent_sync(void *vaddr, size_t size, int direction, int master_type)
|
||||
{
|
||||
unsigned long start = (unsigned long)vaddr;
|
||||
unsigned long end = start + size;
|
||||
|
||||
if (master_type == FOR_CPU) {
|
||||
switch (direction) {
|
||||
case DMA_TO_DEVICE:
|
||||
break;
|
||||
case DMA_FROM_DEVICE:
|
||||
case DMA_BIDIRECTIONAL:
|
||||
cpu_dma_inval_range(start, end);
|
||||
break;
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
} else {
|
||||
/* FOR_DEVICE */
|
||||
switch (direction) {
|
||||
case DMA_FROM_DEVICE:
|
||||
break;
|
||||
case DMA_TO_DEVICE:
|
||||
case DMA_BIDIRECTIONAL:
|
||||
cpu_dma_wb_range(start, end);
|
||||
break;
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int nds32_dma_map_sg(struct device *dev, struct scatterlist *sg,
|
||||
int nents, enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nents; i++, sg++) {
|
||||
void *virt;
|
||||
unsigned long pfn;
|
||||
struct page *page = sg_page(sg);
|
||||
|
||||
sg->dma_address = sg_phys(sg);
|
||||
pfn = page_to_pfn(page) + sg->offset / PAGE_SIZE;
|
||||
page = pfn_to_page(pfn);
|
||||
if (PageHighMem(page)) {
|
||||
virt = kmap_atomic(page);
|
||||
consistent_sync(virt, sg->length, dir, FOR_CPU);
|
||||
kunmap_atomic(virt);
|
||||
void *addr;
|
||||
|
||||
if (offset + len > PAGE_SIZE) {
|
||||
if (offset >= PAGE_SIZE) {
|
||||
page += offset >> PAGE_SHIFT;
|
||||
offset &= ~PAGE_MASK;
|
||||
}
|
||||
len = PAGE_SIZE - offset;
|
||||
}
|
||||
|
||||
addr = kmap_atomic(page);
|
||||
start = (unsigned long)(addr + offset);
|
||||
fn(start, start + len);
|
||||
kunmap_atomic(addr);
|
||||
} else {
|
||||
if (sg->offset > PAGE_SIZE)
|
||||
panic("sg->offset:%08x > PAGE_SIZE\n",
|
||||
sg->offset);
|
||||
virt = page_address(page) + sg->offset;
|
||||
consistent_sync(virt, sg->length, dir, FOR_CPU);
|
||||
start = (unsigned long)phys_to_virt(paddr);
|
||||
fn(start, start + size);
|
||||
}
|
||||
}
|
||||
return nents;
|
||||
offset = 0;
|
||||
page++;
|
||||
left -= len;
|
||||
} while (left);
|
||||
}
|
||||
|
||||
static void nds32_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
|
||||
int nhwentries, enum dma_data_direction dir,
|
||||
unsigned long attrs)
|
||||
void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
|
||||
size_t size, enum dma_data_direction dir)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
nds32_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle,
|
||||
size_t size, enum dma_data_direction dir)
|
||||
{
|
||||
consistent_sync((void *)phys_to_virt(handle), size, dir, FOR_CPU);
|
||||
}
|
||||
|
||||
static void
|
||||
nds32_dma_sync_single_for_device(struct device *dev, dma_addr_t handle,
|
||||
size_t size, enum dma_data_direction dir)
|
||||
{
|
||||
consistent_sync((void *)phys_to_virt(handle), size, dir, FOR_DEVICE);
|
||||
}
|
||||
|
||||
static void
|
||||
nds32_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,
|
||||
enum dma_data_direction dir)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nents; i++, sg++) {
|
||||
char *virt =
|
||||
page_address((struct page *)sg->page_link) + sg->offset;
|
||||
consistent_sync(virt, sg->length, dir, FOR_CPU);
|
||||
switch (dir) {
|
||||
case DMA_FROM_DEVICE:
|
||||
break;
|
||||
case DMA_TO_DEVICE:
|
||||
case DMA_BIDIRECTIONAL:
|
||||
cache_op(paddr, size, cpu_dma_wb_range);
|
||||
break;
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nds32_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
|
||||
int nents, enum dma_data_direction dir)
|
||||
void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
|
||||
size_t size, enum dma_data_direction dir)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nents; i++, sg++) {
|
||||
char *virt =
|
||||
page_address((struct page *)sg->page_link) + sg->offset;
|
||||
consistent_sync(virt, sg->length, dir, FOR_DEVICE);
|
||||
switch (dir) {
|
||||
case DMA_TO_DEVICE:
|
||||
break;
|
||||
case DMA_FROM_DEVICE:
|
||||
case DMA_BIDIRECTIONAL:
|
||||
cache_op(paddr, size, cpu_dma_inval_range);
|
||||
break;
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
struct dma_map_ops nds32_dma_ops = {
|
||||
.alloc = nds32_dma_alloc_coherent,
|
||||
.free = nds32_dma_free,
|
||||
.map_page = nds32_dma_map_page,
|
||||
.unmap_page = nds32_dma_unmap_page,
|
||||
.map_sg = nds32_dma_map_sg,
|
||||
.unmap_sg = nds32_dma_unmap_sg,
|
||||
.sync_single_for_device = nds32_dma_sync_single_for_device,
|
||||
.sync_single_for_cpu = nds32_dma_sync_single_for_cpu,
|
||||
.sync_sg_for_cpu = nds32_dma_sync_sg_for_cpu,
|
||||
.sync_sg_for_device = nds32_dma_sync_sg_for_device,
|
||||
};
|
||||
|
||||
EXPORT_SYMBOL(nds32_dma_ops);
|
||||
|
Fai riferimento in un nuovo problema
Block a user