source: GPL/trunk/include/linux/dma-mapping.h@ 703

Last change on this file since 703 was 703, checked in by David Azarewicz, 4 years ago

Merge changes from next branch.

File size: 4.6 KB
Line 
1#ifndef _ASM_LINUX_DMA_MAPPING_H
2#define _ASM_LINUX_DMA_MAPPING_H
3#include <linux/pci.h>
4#include <linux/errno.h>
5#include <linux/string.h>
6#include <linux/err.h>
7
8/* These definitions mirror those in pci.h, so they can be used
9 * interchangeably with their PCI_ counterparts */
10enum dma_data_direction {
11 DMA_BIDIRECTIONAL = 0,
12 DMA_TO_DEVICE = 1,
13 DMA_FROM_DEVICE = 2,
14 DMA_NONE = 3,
15};
16
17/*
18 * A dma_addr_t can hold any valid DMA or bus address for the platform.
19 * It can be given to a device to use as a DMA source or target. A CPU cannot
20 * reference a dma_addr_t directly because there may be translation between
21 * its physical address space and the bus address space.
22 */
23struct dma_map_ops {
24#if 0
25 void* (*alloc)(struct device *dev, size_t size,
26 dma_addr_t *dma_handle, gfp_t gfp,
27 struct dma_attrs *attrs);
28 void (*free)(struct device *dev, size_t size,
29 void *vaddr, dma_addr_t dma_handle,
30 struct dma_attrs *attrs);
31 int (*mmap)(struct device *, struct vm_area_struct *,
32 void *, dma_addr_t, size_t, struct dma_attrs *attrs);
33
34 int (*get_sgtable)(struct device *dev, struct sg_table *sgt, void *,
35 dma_addr_t, size_t, struct dma_attrs *attrs);
36
37 dma_addr_t (*map_page)(struct device *dev, struct page *page,
38 unsigned long offset, size_t size,
39 enum dma_data_direction dir,
40 struct dma_attrs *attrs);
41 void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
42 size_t size, enum dma_data_direction dir,
43 struct dma_attrs *attrs);
44 /*
45 * map_sg returns 0 on error and a value > 0 on success.
46 * It should never return a value < 0.
47 */
48 int (*map_sg)(struct device *dev, struct scatterlist *sg,
49 int nents, enum dma_data_direction dir,
50 struct dma_attrs *attrs);
51 void (*unmap_sg)(struct device *dev,
52 struct scatterlist *sg, int nents,
53 enum dma_data_direction dir,
54 struct dma_attrs *attrs);
55 void (*sync_single_for_cpu)(struct device *dev,
56 dma_addr_t dma_handle, size_t size,
57 enum dma_data_direction dir);
58 void (*sync_single_for_device)(struct device *dev,
59 dma_addr_t dma_handle, size_t size,
60 enum dma_data_direction dir);
61 void (*sync_sg_for_cpu)(struct device *dev,
62 struct scatterlist *sg, int nents,
63 enum dma_data_direction dir);
64 void (*sync_sg_for_device)(struct device *dev,
65 struct scatterlist *sg, int nents,
66 enum dma_data_direction dir);
67 int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
68#endif
69 int (*dma_supported)(struct device *dev, u64 mask);
70 int (*set_dma_mask)(struct device *dev, u64 mask);
71#ifdef ARCH_HAS_DMA_GET_REQUIRED_MASK
72 u64 (*get_required_mask)(struct device *dev);
73#endif
74 int is_phys;
75};
76
77
78#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
79
80#define DMA_MASK_NONE 0x0ULL
81
82#define DMA_64BIT_MASK 0xffffffffffffffffULL
83//#define DMA_32BIT_MASK 0x00000000ffffffffULL
84
85#ifndef DMA_32BIT_MASK
86#define DMA_32BIT_MASK 0xffffffff
87#endif
88#ifndef DMA_31BIT_MASK
89#define DMA_31BIT_MASK 0x000000007fffffffULL
90#endif
91#ifndef DMA_30BIT_MASK
92#define DMA_30BIT_MASK 0x000000003fffffffULL
93#endif
94#ifndef DMA_28BIT_MASK
95#define DMA_28BIT_MASK 0x000000000fffffffULL
96#endif
97#ifndef DMA_24BIT_MASK
98#define DMA_24BIT_MASK 0x0000000000ffffffULL
99#endif
100#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
101
102//extern struct dma_map_ops *dma_ops;
103
104static inline struct dma_map_ops *get_dma_ops(struct device *dev)
105{
106 if (dev->dma_ops)
107 return dev->dma_ops;
108 return NULL;
109}
110
111static inline void set_dma_ops(struct device *dev,
112 struct dma_map_ops *dma_ops)
113{
114 dev->dma_ops = dma_ops;
115}
116
117int dma_supported(struct device *dev, u64 mask);
118int dma_set_mask(struct device *dev, u64 mask);
119int dma_set_coherent_mask(struct device *dev, u64 mask);
120
121/*
122 * Set both the DMA mask and the coherent DMA mask to the same thing.
123 * Note that we don't check the return value from dma_set_coherent_mask()
124 * as the DMA API guarantees that the coherent DMA mask can be set to
125 * the same or smaller than the streaming DMA mask.
126 */
127static inline int dma_set_mask_and_coherent(struct device *dev, u64 mask)
128{
129 int rc = dma_set_mask(dev, mask);
130 if (rc == 0)
131 dma_set_coherent_mask(dev, mask);
132 return rc;
133}
134
135#if 1
136#define dma_alloc_coherent(dev,size,addr,flags) pci_alloc_consistent((struct pci_dev *)(dev),size,addr)
137#else
138extern void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp);
139#endif
140#define dma_free_coherent(dev,size,ptr,addr) pci_free_consistent((struct pci_dev *)(dev),size,ptr,addr)
141static inline bool dma_can_mmap(struct device *dev)
142{
143 return false;
144}
145#define pci_set_consistent_dma_mask(p,x) pci_set_dma_mask(p,x)
146#endif
Note: See TracBrowser for help on using the repository browser.