Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Implements the generic device dma API for microblaze and the pci |
| 3 | * |
| 4 | * Copyright (C) 2009-2010 Michal Simek <monstr@monstr.eu> |
| 5 | * Copyright (C) 2009-2010 PetaLogix |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General |
| 8 | * Public License. See the file COPYING in the main directory of this |
| 9 | * archive for more details. |
| 10 | * |
| 11 | * This file is base on powerpc and x86 dma-mapping.h versions |
| 12 | * Copyright (C) 2004 IBM |
| 13 | */ |
| 14 | |
| 15 | #ifndef _ASM_MICROBLAZE_DMA_MAPPING_H |
| 16 | #define _ASM_MICROBLAZE_DMA_MAPPING_H |
| 17 | |
| 18 | /* |
Paul Bolle | 395cf96 | 2011-08-15 02:02:26 +0200 | [diff] [blame] | 19 | * See Documentation/DMA-API-HOWTO.txt and |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 20 | * Documentation/DMA-API.txt for documentation. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/cache.h> |
| 25 | #include <linux/mm.h> |
| 26 | #include <linux/scatterlist.h> |
| 27 | #include <linux/dma-debug.h> |
| 28 | #include <linux/dma-attrs.h> |
| 29 | #include <asm/io.h> |
Eli Billauer | cf560c1 | 2011-09-11 22:43:06 +0300 | [diff] [blame] | 30 | #include <asm/cacheflush.h> |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 31 | |
| 32 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) |
| 33 | |
| 34 | #define __dma_alloc_coherent(dev, gfp, size, handle) NULL |
| 35 | #define __dma_free_coherent(size, addr) ((void)0) |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 36 | |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 37 | /* |
| 38 | * Available generic sets of operations |
| 39 | */ |
| 40 | extern struct dma_map_ops dma_direct_ops; |
| 41 | |
| 42 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) |
| 43 | { |
Michal Simek | 3b3b685 | 2014-05-16 12:56:53 +0200 | [diff] [blame] | 44 | return &dma_direct_ops; |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 47 | static inline int dma_supported(struct device *dev, u64 mask) |
| 48 | { |
| 49 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 50 | |
| 51 | if (unlikely(!ops)) |
| 52 | return 0; |
| 53 | if (!ops->dma_supported) |
| 54 | return 1; |
| 55 | return ops->dma_supported(dev, mask); |
| 56 | } |
| 57 | |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 58 | static inline int dma_set_mask(struct device *dev, u64 dma_mask) |
| 59 | { |
| 60 | struct dma_map_ops *ops = get_dma_ops(dev); |
| 61 | |
| 62 | if (unlikely(ops == NULL)) |
| 63 | return -EIO; |
| 64 | if (ops->set_dma_mask) |
| 65 | return ops->set_dma_mask(dev, dma_mask); |
| 66 | if (!dev->dma_mask || !dma_supported(dev, dma_mask)) |
| 67 | return -EIO; |
| 68 | *dev->dma_mask = dma_mask; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | #include <asm-generic/dma-mapping-common.h> |
| 73 | |
Eli Billauer | cf560c1 | 2011-09-11 22:43:06 +0300 | [diff] [blame] | 74 | static inline void __dma_sync(unsigned long paddr, |
| 75 | size_t size, enum dma_data_direction direction) |
| 76 | { |
| 77 | switch (direction) { |
| 78 | case DMA_TO_DEVICE: |
| 79 | case DMA_BIDIRECTIONAL: |
| 80 | flush_dcache_range(paddr, paddr + size); |
| 81 | break; |
| 82 | case DMA_FROM_DEVICE: |
| 83 | invalidate_dcache_range(paddr, paddr + size); |
| 84 | break; |
| 85 | default: |
| 86 | BUG(); |
| 87 | } |
| 88 | } |
| 89 | |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 90 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
| 91 | { |
| 92 | struct dma_map_ops *ops = get_dma_ops(dev); |
Shuah Khan | e728fa1 | 2012-11-23 14:33:42 -0700 | [diff] [blame] | 93 | |
| 94 | debug_dma_mapping_error(dev, dma_addr); |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 95 | if (ops->mapping_error) |
| 96 | return ops->mapping_error(dev, dma_addr); |
| 97 | |
| 98 | return (dma_addr == DMA_ERROR_CODE); |
| 99 | } |
| 100 | |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 101 | static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
| 102 | enum dma_data_direction direction) |
| 103 | { |
| 104 | BUG_ON(direction == DMA_NONE); |
Eli Billauer | cf560c1 | 2011-09-11 22:43:06 +0300 | [diff] [blame] | 105 | __dma_sync(virt_to_phys(vaddr), size, (int)direction); |
Michal Simek | ccfe27d | 2010-01-14 11:21:02 +0100 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | #endif /* _ASM_MICROBLAZE_DMA_MAPPING_H */ |