Commit b9759ef2 authored by Cezary Rojewski's avatar Cezary Rojewski Committed by Mark Brown

ALSA: core: Implement compress page allocation and free routines

Add simple malloc and free methods for memory management for compress
streams. Based on snd_pcm_lib_malloc_pages and snd_pcm_lib_free_pages
implementation.
Signed-off-by: default avatarDivya Prakash <divya1.prakash@intel.com>
Signed-off-by: default avatarCezary Rojewski <cezary.rojewski@intel.com>
Reviewed-by: default avatarTakashi Iwai <tiwai@suse.de>
Acked-by: default avatarVinod Koul <vkoul@kernel.org>
Acked-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20200218143924.10565-3-cezary.rojewski@intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 386dd54b
...@@ -67,6 +67,7 @@ struct snd_compr_runtime { ...@@ -67,6 +67,7 @@ struct snd_compr_runtime {
* @metadata_set: metadata set flag, true when set * @metadata_set: metadata set flag, true when set
* @next_track: has userspace signal next track transition, true when set * @next_track: has userspace signal next track transition, true when set
* @private_data: pointer to DSP private data * @private_data: pointer to DSP private data
* @dma_buffer: allocated buffer if any
*/ */
struct snd_compr_stream { struct snd_compr_stream {
const char *name; const char *name;
...@@ -78,6 +79,7 @@ struct snd_compr_stream { ...@@ -78,6 +79,7 @@ struct snd_compr_stream {
bool metadata_set; bool metadata_set;
bool next_track; bool next_track;
void *private_data; void *private_data;
struct snd_dma_buffer dma_buffer;
}; };
/** /**
...@@ -212,6 +214,9 @@ snd_compr_set_runtime_buffer(struct snd_compr_stream *stream, ...@@ -212,6 +214,9 @@ snd_compr_set_runtime_buffer(struct snd_compr_stream *stream,
} }
} }
int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size);
int snd_compr_free_pages(struct snd_compr_stream *stream);
int snd_compr_stop_error(struct snd_compr_stream *stream, int snd_compr_stop_error(struct snd_compr_stream *stream,
snd_pcm_state_t state); snd_pcm_state_t state);
......
...@@ -488,6 +488,48 @@ snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) ...@@ -488,6 +488,48 @@ snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg)
} }
#endif /* !COMPR_CODEC_CAPS_OVERFLOW */ #endif /* !COMPR_CODEC_CAPS_OVERFLOW */
int snd_compr_malloc_pages(struct snd_compr_stream *stream, size_t size)
{
struct snd_dma_buffer *dmab;
int ret;
if (snd_BUG_ON(!(stream) || !(stream)->runtime))
return -EINVAL;
dmab = kzalloc(sizeof(*dmab), GFP_KERNEL);
if (!dmab)
return -ENOMEM;
dmab->dev = stream->dma_buffer.dev;
ret = snd_dma_alloc_pages(dmab->dev.type, dmab->dev.dev, size, dmab);
if (ret < 0) {
kfree(dmab);
return ret;
}
snd_compr_set_runtime_buffer(stream, dmab);
stream->runtime->dma_bytes = size;
return 1;
}
EXPORT_SYMBOL(snd_compr_malloc_pages);
int snd_compr_free_pages(struct snd_compr_stream *stream)
{
struct snd_compr_runtime *runtime = stream->runtime;
if (snd_BUG_ON(!(stream) || !(stream)->runtime))
return -EINVAL;
if (runtime->dma_area == NULL)
return 0;
if (runtime->dma_buffer_p != &stream->dma_buffer) {
/* It's a newly allocated buffer. Release it now. */
snd_dma_free_pages(runtime->dma_buffer_p);
kfree(runtime->dma_buffer_p);
}
snd_compr_set_runtime_buffer(stream, NULL);
return 0;
}
EXPORT_SYMBOL(snd_compr_free_pages);
/* revisit this with snd_pcm_preallocate_xxx */ /* revisit this with snd_pcm_preallocate_xxx */
static int snd_compr_allocate_buffer(struct snd_compr_stream *stream, static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
struct snd_compr_params *params) struct snd_compr_params *params)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment