Commit 30b7ba69 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: core: Add continuous and vmalloc mmap ops

The mmap of continuous pages and vmalloc'ed pages are relatively
easily done in a shot with the existing helper functions.
Implement the mmap ops for those types, so that the mmap works without
relying on the page fault handling.

Link: https://lore.kernel.org/r/20210609162551.7842-6-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent a202bd1a
...@@ -211,9 +211,19 @@ static void snd_dma_continuous_free(struct snd_dma_buffer *dmab) ...@@ -211,9 +211,19 @@ static void snd_dma_continuous_free(struct snd_dma_buffer *dmab)
free_pages_exact(dmab->area, dmab->bytes); free_pages_exact(dmab->area, dmab->bytes);
} }
static int snd_dma_continuous_mmap(struct snd_dma_buffer *dmab,
struct vm_area_struct *area)
{
return remap_pfn_range(area, area->vm_start,
dmab->addr >> PAGE_SHIFT,
area->vm_end - area->vm_start,
area->vm_page_prot);
}
static const struct snd_malloc_ops snd_dma_continuous_ops = { static const struct snd_malloc_ops snd_dma_continuous_ops = {
.alloc = snd_dma_continuous_alloc, .alloc = snd_dma_continuous_alloc,
.free = snd_dma_continuous_free, .free = snd_dma_continuous_free,
.mmap = snd_dma_continuous_mmap,
}; };
/* /*
...@@ -232,6 +242,12 @@ static void snd_dma_vmalloc_free(struct snd_dma_buffer *dmab) ...@@ -232,6 +242,12 @@ static void snd_dma_vmalloc_free(struct snd_dma_buffer *dmab)
vfree(dmab->area); vfree(dmab->area);
} }
static int snd_dma_vmalloc_mmap(struct snd_dma_buffer *dmab,
struct vm_area_struct *area)
{
return remap_vmalloc_range(area, dmab->area, 0);
}
static dma_addr_t snd_dma_vmalloc_get_addr(struct snd_dma_buffer *dmab, static dma_addr_t snd_dma_vmalloc_get_addr(struct snd_dma_buffer *dmab,
size_t offset) size_t offset)
{ {
...@@ -259,6 +275,7 @@ snd_dma_vmalloc_get_chunk_size(struct snd_dma_buffer *dmab, ...@@ -259,6 +275,7 @@ snd_dma_vmalloc_get_chunk_size(struct snd_dma_buffer *dmab,
static const struct snd_malloc_ops snd_dma_vmalloc_ops = { static const struct snd_malloc_ops snd_dma_vmalloc_ops = {
.alloc = snd_dma_vmalloc_alloc, .alloc = snd_dma_vmalloc_alloc,
.free = snd_dma_vmalloc_free, .free = snd_dma_vmalloc_free,
.mmap = snd_dma_vmalloc_mmap,
.get_addr = snd_dma_vmalloc_get_addr, .get_addr = snd_dma_vmalloc_get_addr,
.get_page = snd_dma_vmalloc_get_page, .get_page = snd_dma_vmalloc_get_page,
.get_chunk_size = snd_dma_vmalloc_get_chunk_size, .get_chunk_size = snd_dma_vmalloc_get_chunk_size,
......
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