4 * Linux architectural port borrowing liberally from similar works of
5 * others. All original copyrights apply as per the original source
8 * OpenRISC implementation:
9 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
17 #ifndef __ASM_OPENRISC_DMA_MAPPING_H
18 #define __ASM_OPENRISC_DMA_MAPPING_H
21 * See Documentation/PCI/PCI-DMA-mapping.txt and
22 * Documentation/DMA-API.txt for documentation.
24 * This file is written with the intention of eventually moving over
25 * to largely using asm-generic/dma-mapping-common.h in its place.
28 #include <linux/dma-debug.h>
29 #include <asm-generic/dma-coherent.h>
30 #include <linux/kmemcheck.h>
32 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
34 int dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
36 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
37 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
39 void *or1k_dma_alloc_coherent(struct device *dev, size_t size,
40 dma_addr_t *dma_handle, gfp_t flag);
41 void or1k_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
42 dma_addr_t dma_handle);
43 dma_addr_t or1k_map_page(struct device *dev, struct page *page,
44 unsigned long offset, size_t size,
45 enum dma_data_direction dir,
46 struct dma_attrs *attrs);
47 void or1k_unmap_page(struct device *dev, dma_addr_t dma_handle,
48 size_t size, enum dma_data_direction dir,
49 struct dma_attrs *attrs);
50 void or1k_sync_single_for_cpu(struct device *dev,
51 dma_addr_t dma_handle, size_t size,
52 enum dma_data_direction dir);
53 void or1k_sync_single_for_device(struct device *dev,
54 dma_addr_t dma_handle, size_t size,
55 enum dma_data_direction dir);
57 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
58 dma_addr_t *dma_handle, gfp_t flag)
62 memory = or1k_dma_alloc_coherent(dev, size, dma_handle, flag);
64 debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
68 static inline void dma_free_coherent(struct device *dev, size_t size,
69 void *cpu_addr, dma_addr_t dma_handle)
71 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
72 or1k_dma_free_coherent(dev, size, cpu_addr, dma_handle);
75 static inline dma_addr_t dma_map_single(struct device *dev, void *ptr,
77 enum dma_data_direction dir)
81 kmemcheck_mark_initialized(ptr, size);
82 BUG_ON(!valid_dma_direction(dir));
83 addr = or1k_map_page(dev, virt_to_page(ptr),
84 (unsigned long)ptr & ~PAGE_MASK, size,
86 debug_dma_map_page(dev, virt_to_page(ptr),
87 (unsigned long)ptr & ~PAGE_MASK, size,
92 static inline void dma_unmap_single(struct device *dev, dma_addr_t addr,
94 enum dma_data_direction dir)
96 BUG_ON(!valid_dma_direction(dir));
97 or1k_unmap_page(dev, addr, size, dir, NULL);
98 debug_dma_unmap_page(dev, addr, size, dir, true);
101 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
103 enum dma_data_direction dir)
105 BUG_ON(!valid_dma_direction(dir));
106 or1k_sync_single_for_cpu(dev, addr, size, dir);
107 debug_dma_sync_single_for_cpu(dev, addr, size, dir);
110 static inline void dma_sync_single_for_device(struct device *dev,
111 dma_addr_t addr, size_t size,
112 enum dma_data_direction dir)
114 BUG_ON(!valid_dma_direction(dir));
115 or1k_sync_single_for_device(dev, addr, size, dir);
116 debug_dma_sync_single_for_device(dev, addr, size, dir);
119 static inline int dma_supported(struct device *dev, u64 dma_mask)
121 /* Support 32 bit DMA mask exclusively */
122 return dma_mask == 0xffffffffULL;
125 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
127 if (!dev->dma_mask || !dma_supported(dev, dma_mask))
130 *dev->dma_mask = dma_mask;
134 #endif /* __ASM_OPENRISC_DMA_MAPPING_H */