Lines Matching +full:pre +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
35 card->total_pcm_alloc_bytes += bytes; in __update_allocated_size()
40 guard(mutex)(&card->memory_mutex); in update_allocated_size()
46 guard(mutex)(&card->memory_mutex); in decrease_allocated_size()
47 WARN_ON(card->total_pcm_alloc_bytes < bytes); in decrease_allocated_size()
48 __update_allocated_size(card, -(ssize_t)bytes); in decrease_allocated_size()
58 scoped_guard(mutex, &card->memory_mutex) { in do_alloc_pages()
60 card->total_pcm_alloc_bytes + size > max_alloc_per_card) in do_alloc_pages()
61 return -ENOMEM; in do_alloc_pages()
74 if (dmab->bytes != size) in do_alloc_pages()
75 update_allocated_size(card, dmab->bytes - size); in do_alloc_pages()
85 if (!dmab->area) in do_free_pages()
87 decrease_allocated_size(card, dmab->bytes); in do_free_pages()
89 dmab->area = NULL; in do_free_pages()
101 struct snd_dma_buffer *dmab = &substream->dma_buffer; in preallocate_pcm_pages()
102 struct snd_card *card = substream->pcm->card; in preallocate_pcm_pages()
107 err = do_alloc_pages(card, dmab->dev.type, dmab->dev.dev, in preallocate_pcm_pages()
108 substream->stream, size, dmab); in preallocate_pcm_pages()
109 if (err != -ENOMEM) in preallocate_pcm_pages()
115 dmab->bytes = 0; /* tell error */ in preallocate_pcm_pages()
117 substream->pcm->card->number, substream->pcm->device, in preallocate_pcm_pages()
118 substream->stream ? 'c' : 'p', substream->number, in preallocate_pcm_pages()
119 substream->pcm->name, orig_size); in preallocate_pcm_pages()
120 return -ENOMEM; in preallocate_pcm_pages()
124 * snd_pcm_lib_preallocate_free - release the preallocated buffer of the specified substream.
127 * Releases the pre-allocated buffer of the given substream.
131 do_free_pages(substream->pcm->card, &substream->dma_buffer); in snd_pcm_lib_preallocate_free()
135 * snd_pcm_lib_preallocate_free_for_all - release all pre-allocated buffers on the pcm
138 * Releases all the pre-allocated buffers on the given pcm.
159 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_proc_read()
160 snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_buffer.bytes / 1024); in snd_pcm_lib_preallocate_proc_read()
171 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_max_proc_read()
172 snd_iprintf(buffer, "%lu\n", (unsigned long) substream->dma_max / 1024); in snd_pcm_lib_preallocate_max_proc_read()
183 struct snd_pcm_substream *substream = entry->private_data; in snd_pcm_lib_preallocate_proc_write()
184 struct snd_card *card = substream->pcm->card; in snd_pcm_lib_preallocate_proc_write()
189 guard(mutex)(&substream->pcm->open_mutex); in snd_pcm_lib_preallocate_proc_write()
190 if (substream->runtime) { in snd_pcm_lib_preallocate_proc_write()
191 buffer->error = -EBUSY; in snd_pcm_lib_preallocate_proc_write()
196 buffer->error = kstrtoul(str, 10, &size); in snd_pcm_lib_preallocate_proc_write()
197 if (buffer->error != 0) in snd_pcm_lib_preallocate_proc_write()
200 if ((size != 0 && size < 8192) || size > substream->dma_max) { in snd_pcm_lib_preallocate_proc_write()
201 buffer->error = -EINVAL; in snd_pcm_lib_preallocate_proc_write()
204 if (substream->dma_buffer.bytes == size) in snd_pcm_lib_preallocate_proc_write()
207 new_dmab.dev = substream->dma_buffer.dev; in snd_pcm_lib_preallocate_proc_write()
210 substream->dma_buffer.dev.type, in snd_pcm_lib_preallocate_proc_write()
211 substream->dma_buffer.dev.dev, in snd_pcm_lib_preallocate_proc_write()
212 substream->stream, in snd_pcm_lib_preallocate_proc_write()
214 buffer->error = -ENOMEM; in snd_pcm_lib_preallocate_proc_write()
216 substream->pcm->card->number, substream->pcm->device, in snd_pcm_lib_preallocate_proc_write()
217 substream->stream ? 'c' : 'p', substream->number, in snd_pcm_lib_preallocate_proc_write()
218 substream->pcm->name, size); in snd_pcm_lib_preallocate_proc_write()
221 substream->buffer_bytes_max = size; in snd_pcm_lib_preallocate_proc_write()
223 substream->buffer_bytes_max = UINT_MAX; in snd_pcm_lib_preallocate_proc_write()
225 if (substream->dma_buffer.area) in snd_pcm_lib_preallocate_proc_write()
226 do_free_pages(card, &substream->dma_buffer); in snd_pcm_lib_preallocate_proc_write()
227 substream->dma_buffer = new_dmab; in snd_pcm_lib_preallocate_proc_write()
229 buffer->error = -EINVAL; in snd_pcm_lib_preallocate_proc_write()
237 entry = snd_info_create_card_entry(substream->pcm->card, "prealloc", in preallocate_info_init()
238 substream->proc_root); in preallocate_info_init()
242 entry->c.text.write = snd_pcm_lib_preallocate_proc_write; in preallocate_info_init()
243 entry->mode |= 0200; in preallocate_info_init()
245 entry = snd_info_create_card_entry(substream->pcm->card, "prealloc_max", in preallocate_info_init()
246 substream->proc_root); in preallocate_info_init()
259 * pre-allocate the buffer and create a proc file for the substream
267 if (snd_BUG_ON(substream->dma_buffer.dev.type)) in preallocate_pages()
268 return -EINVAL; in preallocate_pages()
270 substream->dma_buffer.dev.type = type; in preallocate_pages()
271 substream->dma_buffer.dev.dev = data; in preallocate_pages()
275 /* no fallback, only also inform -ENOMEM */ in preallocate_pages()
280 substream->number < maximum_substreams) { in preallocate_pages()
282 if (err < 0 && err != -ENOMEM) in preallocate_pages()
287 if (substream->dma_buffer.bytes > 0) in preallocate_pages()
288 substream->buffer_bytes_max = substream->dma_buffer.bytes; in preallocate_pages()
289 substream->dma_max = max; in preallocate_pages()
293 substream->managed_buffer_alloc = 1; in preallocate_pages()
313 * snd_pcm_lib_preallocate_pages - pre-allocation for the given DMA type
317 * @size: the requested pre-allocation size in bytes
318 * @max: the max. allowed pre-allocation size
320 * Do pre-allocation for the given DMA buffer type.
331 …* snd_pcm_lib_preallocate_pages_for_all - pre-allocation for continuous memory type (all substream…
335 * @size: the requested pre-allocation size in bytes
336 * @max: the max. allowed pre-allocation size
338 * Do pre-allocation to all substreams of the given pcm for the
350 * snd_pcm_set_managed_buffer - set up buffer management for a substream
354 * @size: the requested pre-allocation size in bytes
355 * @max: the max. allowed pre-allocation size
357 * Do pre-allocation for the given DMA buffer type, and set the managed
367 * When @size is non-zero and @max is zero, this tries to allocate for only
368 * the exact buffer size without fallback, and may return -ENOMEM.
388 * snd_pcm_set_managed_buffer_all - set up buffer management for all substreams
393 * @size: the requested pre-allocation size in bytes
394 * @max: the max. allowed pre-allocation size
396 * Do pre-allocation to all substreams of the given pcm for the specified DMA
410 * snd_pcm_lib_malloc_pages - allocate the DMA buffer
427 return -EINVAL; in snd_pcm_lib_malloc_pages()
428 if (snd_BUG_ON(substream->dma_buffer.dev.type == in snd_pcm_lib_malloc_pages()
430 return -EINVAL; in snd_pcm_lib_malloc_pages()
431 runtime = substream->runtime; in snd_pcm_lib_malloc_pages()
432 card = substream->pcm->card; in snd_pcm_lib_malloc_pages()
434 if (runtime->dma_buffer_p) { in snd_pcm_lib_malloc_pages()
438 if (runtime->dma_buffer_p->bytes >= size) { in snd_pcm_lib_malloc_pages()
439 runtime->dma_bytes = size; in snd_pcm_lib_malloc_pages()
444 if (substream->dma_buffer.area != NULL && in snd_pcm_lib_malloc_pages()
445 substream->dma_buffer.bytes >= size) { in snd_pcm_lib_malloc_pages()
446 dmab = &substream->dma_buffer; /* use the pre-allocated buffer */ in snd_pcm_lib_malloc_pages()
449 if (substream->dma_buffer.area && !substream->dma_max) in snd_pcm_lib_malloc_pages()
450 return -ENOMEM; in snd_pcm_lib_malloc_pages()
453 return -ENOMEM; in snd_pcm_lib_malloc_pages()
454 dmab->dev = substream->dma_buffer.dev; in snd_pcm_lib_malloc_pages()
456 substream->dma_buffer.dev.type, in snd_pcm_lib_malloc_pages()
457 substream->dma_buffer.dev.dev, in snd_pcm_lib_malloc_pages()
458 substream->stream, in snd_pcm_lib_malloc_pages()
462 substream->pcm->card->number, substream->pcm->device, in snd_pcm_lib_malloc_pages()
463 substream->stream ? 'c' : 'p', substream->number, in snd_pcm_lib_malloc_pages()
464 substream->pcm->name, size); in snd_pcm_lib_malloc_pages()
465 return -ENOMEM; in snd_pcm_lib_malloc_pages()
469 runtime->dma_bytes = size; in snd_pcm_lib_malloc_pages()
475 * snd_pcm_lib_free_pages - release the allocated DMA buffer.
487 return -EINVAL; in snd_pcm_lib_free_pages()
488 runtime = substream->runtime; in snd_pcm_lib_free_pages()
489 if (runtime->dma_area == NULL) in snd_pcm_lib_free_pages()
491 if (runtime->dma_buffer_p != &substream->dma_buffer) { in snd_pcm_lib_free_pages()
492 struct snd_card *card = substream->pcm->card; in snd_pcm_lib_free_pages()
495 do_free_pages(card, runtime->dma_buffer_p); in snd_pcm_lib_free_pages()
496 kfree(runtime->dma_buffer_p); in snd_pcm_lib_free_pages()