Lines Matching +full:pre +full:- +full:its

1 // SPDX-License-Identifier: GPL-2.0-or-later
40 card->total_pcm_alloc_bytes + size > max_alloc_per_card) in do_alloc_pages()
41 return -ENOMEM; in do_alloc_pages()
45 mutex_lock(&card->memory_mutex); in do_alloc_pages()
46 card->total_pcm_alloc_bytes += dmab->bytes; in do_alloc_pages()
47 mutex_unlock(&card->memory_mutex); in do_alloc_pages()
54 if (!dmab->area) in do_free_pages()
56 mutex_lock(&card->memory_mutex); in do_free_pages()
57 WARN_ON(card->total_pcm_alloc_bytes < dmab->bytes); in do_free_pages()
58 card->total_pcm_alloc_bytes -= dmab->bytes; in do_free_pages()
59 mutex_unlock(&card->memory_mutex); in do_free_pages()
61 dmab->area = NULL; in do_free_pages()
72 struct snd_dma_buffer *dmab = &substream->dma_buffer; in preallocate_pcm_pages()
73 struct snd_card *card = substream->pcm->card; in preallocate_pcm_pages()
78 err = do_alloc_pages(card, dmab->dev.type, dmab->dev.dev, in preallocate_pcm_pages()
80 if (err != -ENOMEM) in preallocate_pcm_pages()
84 dmab->bytes = 0; /* tell error */ in preallocate_pcm_pages()
86 substream->pcm->card->number, substream->pcm->device, in preallocate_pcm_pages()
87 substream->stream ? 'c' : 'p', substream->number, in preallocate_pcm_pages()
88 substream->pcm->name, orig_size); in preallocate_pcm_pages()
97 do_free_pages(substream->pcm->card, &substream->dma_buffer); in snd_pcm_lib_preallocate_dma_free()
101 * snd_pcm_lib_preallocate_free - release the preallocated buffer of the specified substream.
104 * Releases the pre-allocated buffer of the given substream.
112 * snd_pcm_lib_preallocate_free_for_all - release all pre-allocated buffers on the pcm
115 * Releases all the pre-allocated buffers on the given pcm.
123 for (substream = pcm->streams[stream].substream; substream; substream = substream->next) in snd_pcm_lib_preallocate_free_for_all()
137 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_proc_read()
138 snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_buffer.bytes / 1024); in snd_pcm_lib_preallocate_proc_read()
149 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_max_proc_read()
150 snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_max / 1024); in snd_pcm_lib_preallocate_max_proc_read()
161 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_proc_write()
162 struct snd_card *card = substream->pcm->card; in snd_pcm_lib_preallocate_proc_write()
167 if (substream->runtime) { in snd_pcm_lib_preallocate_proc_write()
168 buffer->error = -EBUSY; in snd_pcm_lib_preallocate_proc_write()
174 if ((size != 0 && size < 8192) || size > substream->dma_max) { in snd_pcm_lib_preallocate_proc_write()
175 buffer->error = -EINVAL; in snd_pcm_lib_preallocate_proc_write()
178 if (substream->dma_buffer.bytes == size) in snd_pcm_lib_preallocate_proc_write()
181 new_dmab.dev = substream->dma_buffer.dev; in snd_pcm_lib_preallocate_proc_write()
184 substream->dma_buffer.dev.type, in snd_pcm_lib_preallocate_proc_write()
185 substream->dma_buffer.dev.dev, in snd_pcm_lib_preallocate_proc_write()
187 buffer->error = -ENOMEM; in snd_pcm_lib_preallocate_proc_write()
190 substream->buffer_bytes_max = size; in snd_pcm_lib_preallocate_proc_write()
192 substream->buffer_bytes_max = UINT_MAX; in snd_pcm_lib_preallocate_proc_write()
194 if (substream->dma_buffer.area) in snd_pcm_lib_preallocate_proc_write()
195 do_free_pages(card, &substream->dma_buffer); in snd_pcm_lib_preallocate_proc_write()
196 substream->dma_buffer = new_dmab; in snd_pcm_lib_preallocate_proc_write()
198 buffer->error = -EINVAL; in snd_pcm_lib_preallocate_proc_write()
206 entry = snd_info_create_card_entry(substream->pcm->card, "prealloc", in preallocate_info_init()
207 substream->proc_root); in preallocate_info_init()
211 entry->c.text.write = snd_pcm_lib_preallocate_proc_write; in preallocate_info_init()
212 entry->mode |= 0200; in preallocate_info_init()
214 entry = snd_info_create_card_entry(substream->pcm->card, "prealloc_max", in preallocate_info_init()
215 substream->proc_root); in preallocate_info_init()
226 * pre-allocate the buffer and create a proc file for the substream
232 if (snd_BUG_ON(substream->dma_buffer.dev.type)) in preallocate_pages()
235 substream->dma_buffer.dev.type = type; in preallocate_pages()
236 substream->dma_buffer.dev.dev = data; in preallocate_pages()
238 if (size > 0 && preallocate_dma && substream->number < maximum_substreams) in preallocate_pages()
241 if (substream->dma_buffer.bytes > 0) in preallocate_pages()
242 substream->buffer_bytes_max = substream->dma_buffer.bytes; in preallocate_pages()
243 substream->dma_max = max; in preallocate_pages()
247 substream->managed_buffer_alloc = 1; in preallocate_pages()
258 for (substream = pcm->streams[stream].substream; substream; in preallocate_pages_for_all()
259 substream = substream->next) in preallocate_pages_for_all()
265 * snd_pcm_lib_preallocate_pages - pre-allocation for the given DMA type
269 * @size: the requested pre-allocation size in bytes
270 * @max: the max. allowed pre-allocation size
272 * Do pre-allocation for the given DMA buffer type.
283 …* snd_pcm_lib_preallocate_pages_for_all - pre-allocation for continuous memory type (all substream…
287 * @size: the requested pre-allocation size in bytes
288 * @max: the max. allowed pre-allocation size
290 * Do pre-allocation to all substreams of the given pcm for the
302 * snd_pcm_set_managed_buffer - set up buffer management for a substream
306 * @size: the requested pre-allocation size in bytes
307 * @max: the max. allowed pre-allocation size
309 * Do pre-allocation for the given DMA buffer type, and set the managed
314 * the release explicitly in its callback.
327 * snd_pcm_set_managed_buffer_all - set up buffer management for all substreams
332 * @size: the requested pre-allocation size in bytes
333 * @max: the max. allowed pre-allocation size
335 * Do pre-allocation to all substreams of the given pcm for the specified DMA
348 * snd_pcm_sgbuf_ops_page - get the page struct at the given offset
361 if (idx >= (unsigned int)sgbuf->pages) in snd_pcm_sgbuf_ops_page()
363 return sgbuf->page_table[idx]; in snd_pcm_sgbuf_ops_page()
368 * snd_pcm_lib_malloc_pages - allocate the DMA buffer
385 return -EINVAL; in snd_pcm_lib_malloc_pages()
386 if (snd_BUG_ON(substream->dma_buffer.dev.type == in snd_pcm_lib_malloc_pages()
388 return -EINVAL; in snd_pcm_lib_malloc_pages()
389 runtime = substream->runtime; in snd_pcm_lib_malloc_pages()
390 card = substream->pcm->card; in snd_pcm_lib_malloc_pages()
392 if (runtime->dma_buffer_p) { in snd_pcm_lib_malloc_pages()
396 if (runtime->dma_buffer_p->bytes >= size) { in snd_pcm_lib_malloc_pages()
397 runtime->dma_bytes = size; in snd_pcm_lib_malloc_pages()
402 if (substream->dma_buffer.area != NULL && in snd_pcm_lib_malloc_pages()
403 substream->dma_buffer.bytes >= size) { in snd_pcm_lib_malloc_pages()
404 dmab = &substream->dma_buffer; /* use the pre-allocated buffer */ in snd_pcm_lib_malloc_pages()
408 return -ENOMEM; in snd_pcm_lib_malloc_pages()
409 dmab->dev = substream->dma_buffer.dev; in snd_pcm_lib_malloc_pages()
411 substream->dma_buffer.dev.type, in snd_pcm_lib_malloc_pages()
412 substream->dma_buffer.dev.dev, in snd_pcm_lib_malloc_pages()
415 return -ENOMEM; in snd_pcm_lib_malloc_pages()
419 runtime->dma_bytes = size; in snd_pcm_lib_malloc_pages()
425 * snd_pcm_lib_free_pages - release the allocated DMA buffer.
434 struct snd_card *card = substream->pcm->card; in snd_pcm_lib_free_pages()
438 return -EINVAL; in snd_pcm_lib_free_pages()
439 runtime = substream->runtime; in snd_pcm_lib_free_pages()
440 if (runtime->dma_area == NULL) in snd_pcm_lib_free_pages()
442 if (runtime->dma_buffer_p != &substream->dma_buffer) { in snd_pcm_lib_free_pages()
444 do_free_pages(card, runtime->dma_buffer_p); in snd_pcm_lib_free_pages()
445 kfree(runtime->dma_buffer_p); in snd_pcm_lib_free_pages()
458 return -EINVAL; in _snd_pcm_lib_alloc_vmalloc_buffer()
459 runtime = substream->runtime; in _snd_pcm_lib_alloc_vmalloc_buffer()
460 if (runtime->dma_area) { in _snd_pcm_lib_alloc_vmalloc_buffer()
461 if (runtime->dma_bytes >= size) in _snd_pcm_lib_alloc_vmalloc_buffer()
463 vfree(runtime->dma_area); in _snd_pcm_lib_alloc_vmalloc_buffer()
465 runtime->dma_area = __vmalloc(size, gfp_flags); in _snd_pcm_lib_alloc_vmalloc_buffer()
466 if (!runtime->dma_area) in _snd_pcm_lib_alloc_vmalloc_buffer()
467 return -ENOMEM; in _snd_pcm_lib_alloc_vmalloc_buffer()
468 runtime->dma_bytes = size; in _snd_pcm_lib_alloc_vmalloc_buffer()
474 * snd_pcm_lib_free_vmalloc_buffer - free vmalloc buffer
485 return -EINVAL; in snd_pcm_lib_free_vmalloc_buffer()
486 runtime = substream->runtime; in snd_pcm_lib_free_vmalloc_buffer()
487 vfree(runtime->dma_area); in snd_pcm_lib_free_vmalloc_buffer()
488 runtime->dma_area = NULL; in snd_pcm_lib_free_vmalloc_buffer()
494 * snd_pcm_lib_get_vmalloc_page - map vmalloc buffer offset to page struct
506 return vmalloc_to_page(substream->runtime->dma_area + offset); in snd_pcm_lib_get_vmalloc_page()