23 #include <linux/time.h>
25 #include <linux/slab.h>
28 #include <linux/export.h>
34 static int preallocate_dma = 1;
36 MODULE_PARM_DESC(preallocate_dma,
"Preallocate DMA memory when the PCM devices are initialized.");
38 static int maximum_substreams = 4;
40 MODULE_PARM_DESC(maximum_substreams,
"Maximum substreams with preallocated DMA memory.");
42 static const size_t snd_minimum_buffer = 16384;
58 if (dmab->
bytes >= size)
73 }
while (size >= snd_minimum_buffer);
102 snd_pcm_lib_preallocate_dma_free(substream);
103 #ifdef CONFIG_SND_VERBOSE_PROCFS
104 snd_info_free_entry(substream->proc_prealloc_max_entry);
105 substream->proc_prealloc_max_entry =
NULL;
106 snd_info_free_entry(substream->proc_prealloc_entry);
107 substream->proc_prealloc_entry =
NULL;
125 for (stream = 0; stream < 2; stream++)
126 for (substream = pcm->
streams[stream].substream; substream; substream = substream->
next)
133 #ifdef CONFIG_SND_VERBOSE_PROCFS
143 snd_iprintf(buffer,
"%lu\n", (
unsigned long) substream->
dma_buffer.bytes / 1024);
151 static void snd_pcm_lib_preallocate_max_proc_read(
struct snd_info_entry *entry,
155 snd_iprintf(buffer,
"%lu\n", (
unsigned long) substream->
dma_max / 1024);
163 static void snd_pcm_lib_preallocate_proc_write(
struct snd_info_entry *entry,
175 if (!snd_info_get_line(buffer, line,
sizeof(line))) {
176 snd_info_get_str(str, line,
sizeof(str));
178 if ((size != 0 && size < 8192) || size > substream->
dma_max) {
184 memset(&new_dmab, 0,
sizeof(new_dmab));
189 size, &new_dmab) < 0) {
209 if ((entry = snd_info_create_card_entry(substream->
pcm->card,
"prealloc", substream->proc_root)) !=
NULL) {
210 entry->
c.
text.read = snd_pcm_lib_preallocate_proc_read;
211 entry->
c.
text.write = snd_pcm_lib_preallocate_proc_write;
214 if (snd_info_register(entry) < 0) {
215 snd_info_free_entry(entry);
219 substream->proc_prealloc_entry =
entry;
220 if ((entry = snd_info_create_card_entry(substream->
pcm->card,
"prealloc_max", substream->proc_root)) !=
NULL) {
221 entry->
c.
text.read = snd_pcm_lib_preallocate_max_proc_read;
223 if (snd_info_register(entry) < 0) {
224 snd_info_free_entry(entry);
228 substream->proc_prealloc_max_entry =
entry;
232 #define preallocate_info_init(s)
239 size_t size,
size_t max)
242 if (size > 0 && preallocate_dma && substream->
number < maximum_substreams)
243 preallocate_pcm_pages(substream, size);
272 size_t size,
size_t max)
276 return snd_pcm_lib_preallocate_pages1(substream, size, max);
296 size_t size,
size_t max)
301 for (stream = 0; stream < 2; stream++)
302 for (substream = pcm->
streams[stream].substream; substream; substream = substream->
next)
310 #ifdef CONFIG_SND_DMA_SGBUF
321 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
324 if (idx >= (
unsigned int)sgbuf->pages)
326 return sgbuf->page_table[
idx];
380 snd_pcm_set_runtime_buffer(substream, dmab);
409 snd_pcm_set_runtime_buffer(substream,
NULL);
416 size_t size,
gfp_t gfp_flags)
463 unsigned long offset)