1
2
3
4
5
6
7
8
9#ifndef __SOUND_MEMALLOC_H
10#define __SOUND_MEMALLOC_H
11
12#include <linux/dma-direction.h>
13#include <asm/page.h>
14
15struct device;
16struct vm_area_struct;
17struct sg_table;
18
19
20
21
22struct snd_dma_device {
23 int type;
24 enum dma_data_direction dir;
25 bool need_sync;
26 struct device *dev;
27};
28
29#define snd_dma_continuous_data(x) ((struct device *)(__force unsigned long)(x))
30
31
32
33
34
35#define SNDRV_DMA_TYPE_UNKNOWN 0
36#define SNDRV_DMA_TYPE_CONTINUOUS 1
37#define SNDRV_DMA_TYPE_DEV 2
38#define SNDRV_DMA_TYPE_DEV_WC 5
39#ifdef CONFIG_GENERIC_ALLOCATOR
40#define SNDRV_DMA_TYPE_DEV_IRAM 4
41#else
42#define SNDRV_DMA_TYPE_DEV_IRAM SNDRV_DMA_TYPE_DEV
43#endif
44#define SNDRV_DMA_TYPE_VMALLOC 7
45#define SNDRV_DMA_TYPE_NONCONTIG 8
46#define SNDRV_DMA_TYPE_NONCOHERENT 9
47#ifdef CONFIG_SND_DMA_SGBUF
48#define SNDRV_DMA_TYPE_DEV_SG SNDRV_DMA_TYPE_NONCONTIG
49#define SNDRV_DMA_TYPE_DEV_WC_SG 6
50#else
51#define SNDRV_DMA_TYPE_DEV_SG SNDRV_DMA_TYPE_DEV
52#define SNDRV_DMA_TYPE_DEV_WC_SG SNDRV_DMA_TYPE_DEV_WC
53#endif
54
55
56
57
58struct snd_dma_buffer {
59 struct snd_dma_device dev;
60 unsigned char *area;
61 dma_addr_t addr;
62 size_t bytes;
63 void *private_data;
64};
65
66
67
68
69static inline unsigned int snd_sgbuf_aligned_pages(size_t size)
70{
71 return (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
72}
73
74
75int snd_dma_alloc_dir_pages(int type, struct device *dev,
76 enum dma_data_direction dir, size_t size,
77 struct snd_dma_buffer *dmab);
78
79static inline int snd_dma_alloc_pages(int type, struct device *dev,
80 size_t size, struct snd_dma_buffer *dmab)
81{
82 return snd_dma_alloc_dir_pages(type, dev, DMA_BIDIRECTIONAL, size, dmab);
83}
84
85int snd_dma_alloc_pages_fallback(int type, struct device *dev, size_t size,
86 struct snd_dma_buffer *dmab);
87void snd_dma_free_pages(struct snd_dma_buffer *dmab);
88int snd_dma_buffer_mmap(struct snd_dma_buffer *dmab,
89 struct vm_area_struct *area);
90
91enum snd_dma_sync_mode { SNDRV_DMA_SYNC_CPU, SNDRV_DMA_SYNC_DEVICE };
92#ifdef CONFIG_HAS_DMA
93void snd_dma_buffer_sync(struct snd_dma_buffer *dmab,
94 enum snd_dma_sync_mode mode);
95#else
96static inline void snd_dma_buffer_sync(struct snd_dma_buffer *dmab,
97 enum snd_dma_sync_mode mode) {}
98#endif
99
100dma_addr_t snd_sgbuf_get_addr(struct snd_dma_buffer *dmab, size_t offset);
101struct page *snd_sgbuf_get_page(struct snd_dma_buffer *dmab, size_t offset);
102unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab,
103 unsigned int ofs, unsigned int size);
104
105
106struct snd_dma_buffer *snd_devm_alloc_dir_pages(struct device *dev, int type,
107 enum dma_data_direction dir,
108 size_t size);
109
110static inline struct snd_dma_buffer *
111snd_devm_alloc_pages(struct device *dev, int type, size_t size)
112{
113 return snd_devm_alloc_dir_pages(dev, type, DMA_BIDIRECTIONAL, size);
114}
115
116static inline struct sg_table *
117snd_dma_noncontig_sg_table(struct snd_dma_buffer *dmab)
118{
119 return dmab->private_data;
120}
121
122#endif
123
124