1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#ifndef __SOUND_MEMALLOC_H
25#define __SOUND_MEMALLOC_H
26
27struct device;
28
29
30
31
32struct snd_dma_device {
33 int type;
34 struct device *dev;
35};
36
37#ifndef snd_dma_pci_data
38#define snd_dma_pci_data(pci) (&(pci)->dev)
39#define snd_dma_isa_data() NULL
40#define snd_dma_continuous_data(x) ((struct device *)(unsigned long)(x))
41#endif
42
43
44
45
46
47#define SNDRV_DMA_TYPE_UNKNOWN 0
48#define SNDRV_DMA_TYPE_CONTINUOUS 1
49#define SNDRV_DMA_TYPE_DEV 2
50#ifdef CONFIG_SND_DMA_SGBUF
51#define SNDRV_DMA_TYPE_DEV_SG 3
52#else
53#define SNDRV_DMA_TYPE_DEV_SG SNDRV_DMA_TYPE_DEV
54#endif
55
56
57
58
59struct snd_dma_buffer {
60 struct snd_dma_device dev;
61 unsigned char *area;
62 dma_addr_t addr;
63 size_t bytes;
64 void *private_data;
65};
66
67#ifdef CONFIG_SND_DMA_SGBUF
68
69
70
71void *snd_malloc_sgbuf_pages(struct device *device,
72 size_t size, struct snd_dma_buffer *dmab,
73 size_t *res_size);
74int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab);
75
76struct snd_sg_page {
77 void *buf;
78 dma_addr_t addr;
79};
80
81struct snd_sg_buf {
82 int size;
83 int pages;
84 int tblsize;
85 struct snd_sg_page *table;
86 struct page **page_table;
87 struct device *dev;
88};
89
90
91
92
93static inline unsigned int snd_sgbuf_aligned_pages(size_t size)
94{
95 return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
96}
97
98
99
100
101static inline dma_addr_t snd_sgbuf_get_addr(struct snd_sg_buf *sgbuf, size_t offset)
102{
103 dma_addr_t addr = sgbuf->table[offset >> PAGE_SHIFT].addr;
104 addr &= PAGE_MASK;
105 return addr + offset % PAGE_SIZE;
106}
107
108
109
110
111static inline void *snd_sgbuf_get_ptr(struct snd_sg_buf *sgbuf, size_t offset)
112{
113 return sgbuf->table[offset >> PAGE_SHIFT].buf + offset % PAGE_SIZE;
114}
115#endif
116
117
118int snd_dma_alloc_pages(int type, struct device *dev, size_t size,
119 struct snd_dma_buffer *dmab);
120int snd_dma_alloc_pages_fallback(int type, struct device *dev, size_t size,
121 struct snd_dma_buffer *dmab);
122void snd_dma_free_pages(struct snd_dma_buffer *dmab);
123
124
125
126#define snd_dma_pci_buf_id(pci) (((unsigned int)(pci)->vendor << 16) | (pci)->device)
127
128size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id);
129int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id);
130
131
132void *snd_malloc_pages(size_t size, gfp_t gfp_flags);
133void snd_free_pages(void *ptr, size_t size);
134
135#endif
136
137