[alsa-devel] [PATCH] alsa: provide a more useful get_unmapped_area handler for pcm
Takashi Iwai
tiwai at suse.de
Wed Mar 10 10:43:13 CET 2010
At Tue, 9 Mar 2010 12:57:52 -0500,
Mike Frysinger wrote:
>
> From: Daniel Glöckner <dg at emlix.com>
>
> Shared memory mappings on nommu machines require a get_unmapped_area
> file operation that suggests an address for the mapping. The current
> implementation returns 0 and thus forces the driver to implement an
> mmap handler that fixes up the start and end address of the vma.
>
> This patch returns the address of the dma buffer, so it should work
> out of the box for all drivers that use the snd_pcm_runtime->dma_area
> pointer.
>
> Addresses for mapping the status and control pages are returned as
> well, but to make those work the conditional compilation of
> snd_pcm_mmap_{status,control} would need to be revised.
>
> URL: http://thread.gmane.org/gmane.linux.alsa.devel/61230
> Signed-off-by: Daniel Glöckner <dg at emlix.com>
> Signed-off-by: Cliff Cai <cliff.cai at analog.com>
> Signed-off-by: Mike Frysinger <vapier at gentoo.org>
> ---
> this has been posted before but didnt seem to get any feedback ...
Looks so.
Now I applied the patch. I'll add it for 2.6.34 merge, too.
This doesn't work for every case, though. But the irregular cases
without dma_area setup don't provide mmap usually, so mostly OK :)
thanks,
Takashi
>
> sound/core/pcm_native.c | 30 ++++++++++++++++++++++--------
> 1 files changed, 22 insertions(+), 8 deletions(-)
>
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 8728876..9681518 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -3434,14 +3434,28 @@ out:
> #endif /* CONFIG_SND_SUPPORT_OLD_API */
>
> #ifndef CONFIG_MMU
> -unsigned long dummy_get_unmapped_area(struct file *file, unsigned long addr,
> - unsigned long len, unsigned long pgoff,
> - unsigned long flags)
> -{
> - return 0;
> +static unsigned long snd_pcm_get_unmapped_area(struct file *file,
> + unsigned long addr,
> + unsigned long len,
> + unsigned long pgoff,
> + unsigned long flags)
> +{
> + struct snd_pcm_file *pcm_file = file->private_data;
> + struct snd_pcm_substream *substream = pcm_file->substream;
> + struct snd_pcm_runtime *runtime = substream->runtime;
> + unsigned long offset = pgoff << PAGE_SHIFT;
> +
> + switch (offset) {
> + case SNDRV_PCM_MMAP_OFFSET_STATUS:
> + return (unsigned long)runtime->status;
> + case SNDRV_PCM_MMAP_OFFSET_CONTROL:
> + return (unsigned long)runtime->control;
> + default:
> + return (unsigned long)runtime->dma_area + offset;
> + }
> }
> #else
> -# define dummy_get_unmapped_area NULL
> +# define snd_pcm_get_unmapped_area NULL
> #endif
>
> /*
> @@ -3460,7 +3474,7 @@ const struct file_operations snd_pcm_f_ops[2] = {
> .compat_ioctl = snd_pcm_ioctl_compat,
> .mmap = snd_pcm_mmap,
> .fasync = snd_pcm_fasync,
> - .get_unmapped_area = dummy_get_unmapped_area,
> + .get_unmapped_area = snd_pcm_get_unmapped_area,
> },
> {
> .owner = THIS_MODULE,
> @@ -3473,6 +3487,6 @@ const struct file_operations snd_pcm_f_ops[2] = {
> .compat_ioctl = snd_pcm_ioctl_compat,
> .mmap = snd_pcm_mmap,
> .fasync = snd_pcm_fasync,
> - .get_unmapped_area = dummy_get_unmapped_area,
> + .get_unmapped_area = snd_pcm_get_unmapped_area,
> }
> };
> --
> 1.7.0.2
>
More information about the Alsa-devel
mailing list