diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2009-12-18 03:29:00 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-12-18 06:54:01 -0500 |
commit | 681b84e17747e1c208e8e1acc54cc5e612da84d1 (patch) | |
tree | f82316d8038b17711bdfbfb4e9ea7f2d76b5a9fc /sound/core | |
parent | 14d44e2c2cb2ef3c88c5090a2d419772e15e7a16 (diff) |
sound: pcm: add vmalloc buffer helper functions
There are now five copies of the code to allocate a PCM buffer using
vmalloc(). Add a sixth in the core so that the others can be removed.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/pcm_memory.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c index caa7796bc2f5..d9727c74b2e1 100644 --- a/sound/core/pcm_memory.c +++ b/sound/core/pcm_memory.c | |||
@@ -434,3 +434,57 @@ int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream) | |||
434 | } | 434 | } |
435 | 435 | ||
436 | EXPORT_SYMBOL(snd_pcm_lib_free_pages); | 436 | EXPORT_SYMBOL(snd_pcm_lib_free_pages); |
437 | |||
438 | int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream, | ||
439 | size_t size, gfp_t gfp_flags) | ||
440 | { | ||
441 | struct snd_pcm_runtime *runtime; | ||
442 | |||
443 | if (PCM_RUNTIME_CHECK(substream)) | ||
444 | return -EINVAL; | ||
445 | runtime = substream->runtime; | ||
446 | if (runtime->dma_area) { | ||
447 | if (runtime->dma_bytes >= size) | ||
448 | return 0; /* already large enough */ | ||
449 | vfree(runtime->dma_area); | ||
450 | } | ||
451 | runtime->dma_area = __vmalloc(size, gfp_flags, PAGE_KERNEL); | ||
452 | if (!runtime->dma_area) | ||
453 | return -ENOMEM; | ||
454 | runtime->dma_bytes = size; | ||
455 | return 1; | ||
456 | } | ||
457 | EXPORT_SYMBOL(_snd_pcm_lib_alloc_vmalloc_buffer); | ||
458 | |||
459 | /** | ||
460 | * snd_pcm_lib_free_vmalloc_buffer - free vmalloc buffer | ||
461 | * @substream: the substream with a buffer allocated by | ||
462 | * snd_pcm_lib_alloc_vmalloc_buffer() | ||
463 | */ | ||
464 | int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream) | ||
465 | { | ||
466 | struct snd_pcm_runtime *runtime; | ||
467 | |||
468 | if (PCM_RUNTIME_CHECK(substream)) | ||
469 | return -EINVAL; | ||
470 | runtime = substream->runtime; | ||
471 | vfree(runtime->dma_area); | ||
472 | runtime->dma_area = NULL; | ||
473 | return 0; | ||
474 | } | ||
475 | EXPORT_SYMBOL(snd_pcm_lib_free_vmalloc_buffer); | ||
476 | |||
477 | /** | ||
478 | * snd_pcm_lib_get_vmalloc_page - map vmalloc buffer offset to page struct | ||
479 | * @substream: the substream with a buffer allocated by | ||
480 | * snd_pcm_lib_alloc_vmalloc_buffer() | ||
481 | * @offset: offset in the buffer | ||
482 | * | ||
483 | * This function is to be used as the page callback in the PCM ops. | ||
484 | */ | ||
485 | struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream, | ||
486 | unsigned long offset) | ||
487 | { | ||
488 | return vmalloc_to_page(substream->runtime->dma_area + offset); | ||
489 | } | ||
490 | EXPORT_SYMBOL(snd_pcm_lib_get_vmalloc_page); | ||