| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* Copyright (C) 2009-2010 PetaLogix |
| 4 |
* Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corporation |
| 5 |
* |
| 6 |
* Provide default implementations of the DMA mapping callbacks for |
| 7 |
* directly mapped busses. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <linux/device.h> |
| 11 |
#include <linux/dma-map-ops.h> |
| 12 |
#include <linux/gfp.h> |
| 13 |
#include <linux/export.h> |
| 14 |
#include <linux/bug.h> |
| 15 |
#include <asm/cacheflush.h> |
| 16 |
|
| 17 |
static void __dma_sync(phys_addr_t paddr, size_t size, |
| 18 |
enum dma_data_direction direction) |
| 19 |
{ |
| 20 |
switch (direction) { |
| 21 |
case DMA_TO_DEVICE: |
| 22 |
case DMA_BIDIRECTIONAL: |
| 23 |
flush_dcache_range(paddr, paddr + size); |
| 24 |
break; |
| 25 |
case DMA_FROM_DEVICE: |
| 26 |
invalidate_dcache_range(paddr, paddr + size); |
| 27 |
break; |
| 28 |
default: |
| 29 |
BUG(); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, |
| 34 |
enum dma_data_direction dir) |
| 35 |
{ |
| 36 |
__dma_sync(paddr, size, dir); |
| 37 |
} |
| 38 |
|
| 39 |
void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, |
| 40 |
enum dma_data_direction dir) |
| 41 |
{ |
| 42 |
__dma_sync(paddr, size, dir); |
| 43 |
} |