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

Last change on this file was 772, checked in by David Azarewicz, 4 months ago

Merge in changes from 6.6-LTS branch.
Fixed additional 25+ problems.

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