mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-27 01:05:18 +07:00
58b0440663
The only functional differences (modulo a few missing fixes in the arch code) is that architectures without coherent caches need a hook to convert a virtual or dma address into a pfn, given that we don't have the kernel linear mapping available for the otherwise easy virt_to_page call. As a side effect we can support mmap of the per-device coherent area even on architectures not providing the callback, and we make previous dangerous default methods dma_common_mmap actually save for non-coherent architectures by rejecting it without the right helper. In addition to that we need a hook so that some architectures can override the protection bits when mmaping a dma coherent allocations. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Paul Burton <paul.burton@mips.com> # MIPS parts
45 lines
1.0 KiB
C
45 lines
1.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2009-2010 PetaLogix
|
|
* Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corporation
|
|
*
|
|
* Provide default implementations of the DMA mapping callbacks for
|
|
* directly mapped busses.
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/dma-noncoherent.h>
|
|
#include <linux/gfp.h>
|
|
#include <linux/dma-debug.h>
|
|
#include <linux/export.h>
|
|
#include <linux/bug.h>
|
|
#include <asm/cacheflush.h>
|
|
|
|
static void __dma_sync(struct device *dev, phys_addr_t paddr, size_t size,
|
|
enum dma_data_direction direction)
|
|
{
|
|
switch (direction) {
|
|
case DMA_TO_DEVICE:
|
|
case DMA_BIDIRECTIONAL:
|
|
flush_dcache_range(paddr, paddr + size);
|
|
break;
|
|
case DMA_FROM_DEVICE:
|
|
invalidate_dcache_range(paddr, paddr + size);
|
|
break;
|
|
default:
|
|
BUG();
|
|
}
|
|
}
|
|
|
|
void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
|
|
size_t size, enum dma_data_direction dir)
|
|
{
|
|
__dma_sync(dev, paddr, size, dir);
|
|
}
|
|
|
|
void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
|
|
size_t size, enum dma_data_direction dir)
|
|
{
|
|
__dma_sync(dev, paddr, size, dir);
|
|
}
|