[SCSI] bnx2i: Fixed the endian on TTT for NOP out transmission
[linux-2.6.git] / arch / openrisc / include / asm / dma-mapping.h
1 /*
2  * OpenRISC Linux
3  *
4  * Linux architectural port borrowing liberally from similar works of
5  * others.  All original copyrights apply as per the original source
6  * declaration.
7  *
8  * OpenRISC implementation:
9  * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
10  *
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.
15  */
16
17 #ifndef __ASM_OPENRISC_DMA_MAPPING_H
18 #define __ASM_OPENRISC_DMA_MAPPING_H
19
20 /*
21  * See Documentation/PCI/PCI-DMA-mapping.txt and
22  * Documentation/DMA-API.txt for documentation.
23  *
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.
26  */
27
28 #include <linux/dma-debug.h>
29 #include <asm-generic/dma-coherent.h>
30 #include <linux/kmemcheck.h>
31
32 #define DMA_ERROR_CODE          (~(dma_addr_t)0x0)
33
34 int dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
35
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)
38
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);
56
57 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
58                                         dma_addr_t *dma_handle, gfp_t flag)
59 {
60         void *memory;
61
62         memory = or1k_dma_alloc_coherent(dev, size, dma_handle, flag);
63
64         debug_dma_alloc_coherent(dev, size, *dma_handle, memory);
65         return memory;
66 }
67
68 static inline void dma_free_coherent(struct device *dev, size_t size,
69                                      void *cpu_addr, dma_addr_t dma_handle)
70 {
71         debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
72         or1k_dma_free_coherent(dev, size, cpu_addr, dma_handle);
73 }
74
75 static inline dma_addr_t dma_map_single(struct device *dev, void *ptr,
76                                         size_t size,
77                                         enum dma_data_direction dir)
78 {
79         dma_addr_t addr;
80
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,
85                              dir, NULL);
86         debug_dma_map_page(dev, virt_to_page(ptr),
87                            (unsigned long)ptr & ~PAGE_MASK, size,
88                            dir, addr, true);
89         return addr;
90 }
91
92 static inline void dma_unmap_single(struct device *dev, dma_addr_t addr,
93                                           size_t size,
94                                           enum dma_data_direction dir)
95 {
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);
99 }
100
101 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
102                                            size_t size,
103                                            enum dma_data_direction dir)
104 {
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);
108 }
109
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)
113 {
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);
117 }
118
119 static inline int dma_supported(struct device *dev, u64 dma_mask)
120 {
121         /* Support 32 bit DMA mask exclusively */
122         return dma_mask == 0xffffffffULL;
123 }
124
125 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
126 {
127         if (!dev->dma_mask || !dma_supported(dev, dma_mask))
128                 return -EIO;
129
130         *dev->dma_mask = dma_mask;
131
132         return 0;
133 }
134 #endif  /* __ASM_OPENRISC_DMA_MAPPING_H */