Lines Matching +full:pre +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
36 card->total_pcm_alloc_bytes += bytes; in __update_allocated_size()
41 mutex_lock(&card->memory_mutex); in update_allocated_size()
43 mutex_unlock(&card->memory_mutex); in update_allocated_size()
48 mutex_lock(&card->memory_mutex); in decrease_allocated_size()
49 WARN_ON(card->total_pcm_alloc_bytes < bytes); in decrease_allocated_size()
50 __update_allocated_size(card, -(ssize_t)bytes); in decrease_allocated_size()
51 mutex_unlock(&card->memory_mutex); in decrease_allocated_size()
61 mutex_lock(&card->memory_mutex); in do_alloc_pages()
63 card->total_pcm_alloc_bytes + size > max_alloc_per_card) { in do_alloc_pages()
64 mutex_unlock(&card->memory_mutex); in do_alloc_pages()
65 return -ENOMEM; in do_alloc_pages()
68 mutex_unlock(&card->memory_mutex); in do_alloc_pages()
79 if (dmab->bytes != size) in do_alloc_pages()
80 update_allocated_size(card, dmab->bytes - size); in do_alloc_pages()
90 if (!dmab->area) in do_free_pages()
92 decrease_allocated_size(card, dmab->bytes); in do_free_pages()
94 dmab->area = NULL; in do_free_pages()
106 struct snd_dma_buffer *dmab = &substream->dma_buffer; in preallocate_pcm_pages()
107 struct snd_card *card = substream->pcm->card; in preallocate_pcm_pages()
112 err = do_alloc_pages(card, dmab->dev.type, dmab->dev.dev, in preallocate_pcm_pages()
113 substream->stream, size, dmab); in preallocate_pcm_pages()
114 if (err != -ENOMEM) in preallocate_pcm_pages()
120 dmab->bytes = 0; /* tell error */ in preallocate_pcm_pages()
122 substream->pcm->card->number, substream->pcm->device, in preallocate_pcm_pages()
123 substream->stream ? 'c' : 'p', substream->number, in preallocate_pcm_pages()
124 substream->pcm->name, orig_size); in preallocate_pcm_pages()
125 return -ENOMEM; in preallocate_pcm_pages()
129 * snd_pcm_lib_preallocate_free - release the preallocated buffer of the specified substream.
132 * Releases the pre-allocated buffer of the given substream.
136 do_free_pages(substream->pcm->card, &substream->dma_buffer); in snd_pcm_lib_preallocate_free()
140 * snd_pcm_lib_preallocate_free_for_all - release all pre-allocated buffers on the pcm
143 * Releases all the pre-allocated buffers on the given pcm.
164 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_proc_read()
165 snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_buffer.bytes / 1024); in snd_pcm_lib_preallocate_proc_read()
176 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_max_proc_read()
177 snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_max / 1024); in snd_pcm_lib_preallocate_max_proc_read()
188 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_proc_write()
189 struct snd_card *card = substream->pcm->card; in snd_pcm_lib_preallocate_proc_write()
194 mutex_lock(&substream->pcm->open_mutex); in snd_pcm_lib_preallocate_proc_write()
195 if (substream->runtime) { in snd_pcm_lib_preallocate_proc_write()
196 buffer->error = -EBUSY; in snd_pcm_lib_preallocate_proc_write()
202 if ((size != 0 && size < 8192) || size > substream->dma_max) { in snd_pcm_lib_preallocate_proc_write()
203 buffer->error = -EINVAL; in snd_pcm_lib_preallocate_proc_write()
206 if (substream->dma_buffer.bytes == size) in snd_pcm_lib_preallocate_proc_write()
209 new_dmab.dev = substream->dma_buffer.dev; in snd_pcm_lib_preallocate_proc_write()
212 substream->dma_buffer.dev.type, in snd_pcm_lib_preallocate_proc_write()
213 substream->dma_buffer.dev.dev, in snd_pcm_lib_preallocate_proc_write()
214 substream->stream, in snd_pcm_lib_preallocate_proc_write()
216 buffer->error = -ENOMEM; in snd_pcm_lib_preallocate_proc_write()
218 substream->pcm->card->number, substream->pcm->device, in snd_pcm_lib_preallocate_proc_write()
219 substream->stream ? 'c' : 'p', substream->number, in snd_pcm_lib_preallocate_proc_write()
220 substream->pcm->name, size); in snd_pcm_lib_preallocate_proc_write()
223 substream->buffer_bytes_max = size; in snd_pcm_lib_preallocate_proc_write()
225 substream->buffer_bytes_max = UINT_MAX; in snd_pcm_lib_preallocate_proc_write()
227 if (substream->dma_buffer.area) in snd_pcm_lib_preallocate_proc_write()
228 do_free_pages(card, &substream->dma_buffer); in snd_pcm_lib_preallocate_proc_write()
229 substream->dma_buffer = new_dmab; in snd_pcm_lib_preallocate_proc_write()
231 buffer->error = -EINVAL; in snd_pcm_lib_preallocate_proc_write()
234 mutex_unlock(&substream->pcm->open_mutex); in snd_pcm_lib_preallocate_proc_write()
241 entry = snd_info_create_card_entry(substream->pcm->card, "prealloc", in preallocate_info_init()
242 substream->proc_root); in preallocate_info_init()
246 entry->c.text.write = snd_pcm_lib_preallocate_proc_write; in preallocate_info_init()
247 entry->mode |= 0200; in preallocate_info_init()
249 entry = snd_info_create_card_entry(substream->pcm->card, "prealloc_max", in preallocate_info_init()
250 substream->proc_root); in preallocate_info_init()
263 * pre-allocate the buffer and create a proc file for the substream
271 if (snd_BUG_ON(substream->dma_buffer.dev.type)) in preallocate_pages()
272 return -EINVAL; in preallocate_pages()
274 substream->dma_buffer.dev.type = type; in preallocate_pages()
275 substream->dma_buffer.dev.dev = data; in preallocate_pages()
279 /* no fallback, only also inform -ENOMEM */ in preallocate_pages()
284 substream->number < maximum_substreams) { in preallocate_pages()
286 if (err < 0 && err != -ENOMEM) in preallocate_pages()
291 if (substream->dma_buffer.bytes > 0) in preallocate_pages()
292 substream->buffer_bytes_max = substream->dma_buffer.bytes; in preallocate_pages()
293 substream->dma_max = max; in preallocate_pages()
297 substream->managed_buffer_alloc = 1; in preallocate_pages()
317 * snd_pcm_lib_preallocate_pages - pre-allocation for the given DMA type
321 * @size: the requested pre-allocation size in bytes
322 * @max: the max. allowed pre-allocation size
324 * Do pre-allocation for the given DMA buffer type.
335 …* snd_pcm_lib_preallocate_pages_for_all - pre-allocation for continuous memory type (all substream…
339 * @size: the requested pre-allocation size in bytes
340 * @max: the max. allowed pre-allocation size
342 * Do pre-allocation to all substreams of the given pcm for the
354 * snd_pcm_set_managed_buffer - set up buffer management for a substream
358 * @size: the requested pre-allocation size in bytes
359 * @max: the max. allowed pre-allocation size
361 * Do pre-allocation for the given DMA buffer type, and set the managed
371 * When @size is non-zero and @max is zero, this tries to allocate for only
372 * the exact buffer size without fallback, and may return -ENOMEM.
392 * snd_pcm_set_managed_buffer_all - set up buffer management for all substreams
397 * @size: the requested pre-allocation size in bytes
398 * @max: the max. allowed pre-allocation size
400 * Do pre-allocation to all substreams of the given pcm for the specified DMA
414 * snd_pcm_lib_malloc_pages - allocate the DMA buffer
431 return -EINVAL; in snd_pcm_lib_malloc_pages()
432 if (snd_BUG_ON(substream->dma_buffer.dev.type == in snd_pcm_lib_malloc_pages()
434 return -EINVAL; in snd_pcm_lib_malloc_pages()
435 runtime = substream->runtime; in snd_pcm_lib_malloc_pages()
436 card = substream->pcm->card; in snd_pcm_lib_malloc_pages()
438 if (runtime->dma_buffer_p) { in snd_pcm_lib_malloc_pages()
442 if (runtime->dma_buffer_p->bytes >= size) { in snd_pcm_lib_malloc_pages()
443 runtime->dma_bytes = size; in snd_pcm_lib_malloc_pages()
448 if (substream->dma_buffer.area != NULL && in snd_pcm_lib_malloc_pages()
449 substream->dma_buffer.bytes >= size) { in snd_pcm_lib_malloc_pages()
450 dmab = &substream->dma_buffer; /* use the pre-allocated buffer */ in snd_pcm_lib_malloc_pages()
453 if (substream->dma_buffer.area && !substream->dma_max) in snd_pcm_lib_malloc_pages()
454 return -ENOMEM; in snd_pcm_lib_malloc_pages()
457 return -ENOMEM; in snd_pcm_lib_malloc_pages()
458 dmab->dev = substream->dma_buffer.dev; in snd_pcm_lib_malloc_pages()
460 substream->dma_buffer.dev.type, in snd_pcm_lib_malloc_pages()
461 substream->dma_buffer.dev.dev, in snd_pcm_lib_malloc_pages()
462 substream->stream, in snd_pcm_lib_malloc_pages()
466 substream->pcm->card->number, substream->pcm->device, in snd_pcm_lib_malloc_pages()
467 substream->stream ? 'c' : 'p', substream->number, in snd_pcm_lib_malloc_pages()
468 substream->pcm->name, size); in snd_pcm_lib_malloc_pages()
469 return -ENOMEM; in snd_pcm_lib_malloc_pages()
473 runtime->dma_bytes = size; in snd_pcm_lib_malloc_pages()
479 * snd_pcm_lib_free_pages - release the allocated DMA buffer.
491 return -EINVAL; in snd_pcm_lib_free_pages()
492 runtime = substream->runtime; in snd_pcm_lib_free_pages()
493 if (runtime->dma_area == NULL) in snd_pcm_lib_free_pages()
495 if (runtime->dma_buffer_p != &substream->dma_buffer) { in snd_pcm_lib_free_pages()
496 struct snd_card *card = substream->pcm->card; in snd_pcm_lib_free_pages()
499 do_free_pages(card, runtime->dma_buffer_p); in snd_pcm_lib_free_pages()
500 kfree(runtime->dma_buffer_p); in snd_pcm_lib_free_pages()
513 return -EINVAL; in _snd_pcm_lib_alloc_vmalloc_buffer()
514 runtime = substream->runtime; in _snd_pcm_lib_alloc_vmalloc_buffer()
515 if (runtime->dma_area) { in _snd_pcm_lib_alloc_vmalloc_buffer()
516 if (runtime->dma_bytes >= size) in _snd_pcm_lib_alloc_vmalloc_buffer()
518 vfree(runtime->dma_area); in _snd_pcm_lib_alloc_vmalloc_buffer()
520 runtime->dma_area = __vmalloc(size, gfp_flags); in _snd_pcm_lib_alloc_vmalloc_buffer()
521 if (!runtime->dma_area) in _snd_pcm_lib_alloc_vmalloc_buffer()
522 return -ENOMEM; in _snd_pcm_lib_alloc_vmalloc_buffer()
523 runtime->dma_bytes = size; in _snd_pcm_lib_alloc_vmalloc_buffer()
529 * snd_pcm_lib_free_vmalloc_buffer - free vmalloc buffer
540 return -EINVAL; in snd_pcm_lib_free_vmalloc_buffer()
541 runtime = substream->runtime; in snd_pcm_lib_free_vmalloc_buffer()
542 vfree(runtime->dma_area); in snd_pcm_lib_free_vmalloc_buffer()
543 runtime->dma_area = NULL; in snd_pcm_lib_free_vmalloc_buffer()
549 * snd_pcm_lib_get_vmalloc_page - map vmalloc buffer offset to page struct
561 return vmalloc_to_page(substream->runtime->dma_area + offset); in snd_pcm_lib_get_vmalloc_page()