Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dma-mapping.h
Go to the documentation of this file.
1 #ifndef ___ASM_SPARC_DMA_MAPPING_H
2 #define ___ASM_SPARC_DMA_MAPPING_H
3 
4 #include <linux/scatterlist.h>
5 #include <linux/mm.h>
6 #include <linux/dma-debug.h>
7 
8 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
9 
10 extern int dma_supported(struct device *dev, u64 mask);
11 
12 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
13 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
14 
15 extern struct dma_map_ops *dma_ops;
16 extern struct dma_map_ops *leon_dma_ops;
17 extern struct dma_map_ops pci32_dma_ops;
18 
19 extern struct bus_type pci_bus_type;
20 
21 static inline struct dma_map_ops *get_dma_ops(struct device *dev)
22 {
23 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
25  return leon_dma_ops;
26  else if (dev->bus == &pci_bus_type)
27  return &pci32_dma_ops;
28 #endif
29  return dma_ops;
30 }
31 
33 
34 #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL)
35 
36 static inline void *dma_alloc_attrs(struct device *dev, size_t size,
38  struct dma_attrs *attrs)
39 {
40  struct dma_map_ops *ops = get_dma_ops(dev);
41  void *cpu_addr;
42 
43  cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
44  debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr);
45  return cpu_addr;
46 }
47 
48 #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL)
49 
50 static inline void dma_free_attrs(struct device *dev, size_t size,
52  struct dma_attrs *attrs)
53 {
54  struct dma_map_ops *ops = get_dma_ops(dev);
55 
56  debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
57  ops->free(dev, size, cpu_addr, dma_handle, attrs);
58 }
59 
60 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
61 {
62  return (dma_addr == DMA_ERROR_CODE);
63 }
64 
65 static inline int dma_set_mask(struct device *dev, u64 mask)
66 {
67 #ifdef CONFIG_PCI
68  if (dev->bus == &pci_bus_type) {
69  if (!dev->dma_mask || !dma_supported(dev, mask))
70  return -EINVAL;
71  *dev->dma_mask = mask;
72  return 0;
73  }
74 #endif
75  return -EINVAL;
76 }
77 
78 #endif