Lines Matching refs:dmab
20 static const struct snd_malloc_ops *snd_dma_get_ops(struct snd_dma_buffer *dmab);
23 static inline gfp_t snd_mem_get_gfp_flags(const struct snd_dma_buffer *dmab, in snd_mem_get_gfp_flags() argument
26 if (!dmab->dev.dev) in snd_mem_get_gfp_flags()
29 return (__force gfp_t)(unsigned long)dmab->dev.dev; in snd_mem_get_gfp_flags()
32 static void *__snd_dma_alloc_pages(struct snd_dma_buffer *dmab, size_t size) in __snd_dma_alloc_pages() argument
34 const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); in __snd_dma_alloc_pages()
38 return ops->alloc(dmab, size); in __snd_dma_alloc_pages()
55 struct snd_dma_buffer *dmab) in snd_dma_alloc_pages() argument
59 if (WARN_ON(!dmab)) in snd_dma_alloc_pages()
63 dmab->dev.type = type; in snd_dma_alloc_pages()
64 dmab->dev.dev = device; in snd_dma_alloc_pages()
65 dmab->bytes = 0; in snd_dma_alloc_pages()
66 dmab->addr = 0; in snd_dma_alloc_pages()
67 dmab->private_data = NULL; in snd_dma_alloc_pages()
68 dmab->area = __snd_dma_alloc_pages(dmab, size); in snd_dma_alloc_pages()
69 if (!dmab->area) in snd_dma_alloc_pages()
71 dmab->bytes = size; in snd_dma_alloc_pages()
92 struct snd_dma_buffer *dmab) in snd_dma_alloc_pages_fallback() argument
96 while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) { in snd_dma_alloc_pages_fallback()
104 if (! dmab->area) in snd_dma_alloc_pages_fallback()
116 void snd_dma_free_pages(struct snd_dma_buffer *dmab) in snd_dma_free_pages() argument
118 const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); in snd_dma_free_pages()
121 ops->free(dmab); in snd_dma_free_pages()
149 struct snd_dma_buffer *dmab; in snd_devm_alloc_pages() local
156 dmab = devres_alloc(__snd_release_pages, sizeof(*dmab), GFP_KERNEL); in snd_devm_alloc_pages()
157 if (!dmab) in snd_devm_alloc_pages()
160 err = snd_dma_alloc_pages(type, dev, size, dmab); in snd_devm_alloc_pages()
162 devres_free(dmab); in snd_devm_alloc_pages()
166 devres_add(dev, dmab); in snd_devm_alloc_pages()
167 return dmab; in snd_devm_alloc_pages()
176 int snd_dma_buffer_mmap(struct snd_dma_buffer *dmab, in snd_dma_buffer_mmap() argument
179 const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); in snd_dma_buffer_mmap()
182 return ops->mmap(dmab, area); in snd_dma_buffer_mmap()
193 dma_addr_t snd_sgbuf_get_addr(struct snd_dma_buffer *dmab, size_t offset) in snd_sgbuf_get_addr() argument
195 const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); in snd_sgbuf_get_addr()
198 return ops->get_addr(dmab, offset); in snd_sgbuf_get_addr()
200 return dmab->addr + offset; in snd_sgbuf_get_addr()
209 struct page *snd_sgbuf_get_page(struct snd_dma_buffer *dmab, size_t offset) in snd_sgbuf_get_page() argument
211 const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); in snd_sgbuf_get_page()
214 return ops->get_page(dmab, offset); in snd_sgbuf_get_page()
216 return virt_to_page(dmab->area + offset); in snd_sgbuf_get_page()
227 unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab, in snd_sgbuf_get_chunk_size() argument
230 const struct snd_malloc_ops *ops = snd_dma_get_ops(dmab); in snd_sgbuf_get_chunk_size()
233 return ops->get_chunk_size(dmab, ofs, size); in snd_sgbuf_get_chunk_size()
242 static void *snd_dma_continuous_alloc(struct snd_dma_buffer *dmab, size_t size) in snd_dma_continuous_alloc() argument
244 gfp_t gfp = snd_mem_get_gfp_flags(dmab, GFP_KERNEL); in snd_dma_continuous_alloc()
248 dmab->addr = page_to_phys(virt_to_page(p)); in snd_dma_continuous_alloc()
252 static void snd_dma_continuous_free(struct snd_dma_buffer *dmab) in snd_dma_continuous_free() argument
254 free_pages_exact(dmab->area, dmab->bytes); in snd_dma_continuous_free()
257 static int snd_dma_continuous_mmap(struct snd_dma_buffer *dmab, in snd_dma_continuous_mmap() argument
261 dmab->addr >> PAGE_SHIFT, in snd_dma_continuous_mmap()
275 static void *snd_dma_vmalloc_alloc(struct snd_dma_buffer *dmab, size_t size) in snd_dma_vmalloc_alloc() argument
277 gfp_t gfp = snd_mem_get_gfp_flags(dmab, GFP_KERNEL | __GFP_HIGHMEM); in snd_dma_vmalloc_alloc()
282 static void snd_dma_vmalloc_free(struct snd_dma_buffer *dmab) in snd_dma_vmalloc_free() argument
284 vfree(dmab->area); in snd_dma_vmalloc_free()
287 static int snd_dma_vmalloc_mmap(struct snd_dma_buffer *dmab, in snd_dma_vmalloc_mmap() argument
290 return remap_vmalloc_range(area, dmab->area, 0); in snd_dma_vmalloc_mmap()
293 #define get_vmalloc_page_addr(dmab, offset) \ argument
294 page_to_phys(vmalloc_to_page((dmab)->area + (offset)))
296 static dma_addr_t snd_dma_vmalloc_get_addr(struct snd_dma_buffer *dmab, in snd_dma_vmalloc_get_addr() argument
299 return get_vmalloc_page_addr(dmab, offset) + offset % PAGE_SIZE; in snd_dma_vmalloc_get_addr()
302 static struct page *snd_dma_vmalloc_get_page(struct snd_dma_buffer *dmab, in snd_dma_vmalloc_get_page() argument
305 return vmalloc_to_page(dmab->area + offset); in snd_dma_vmalloc_get_page()
309 snd_dma_vmalloc_get_chunk_size(struct snd_dma_buffer *dmab, in snd_dma_vmalloc_get_chunk_size() argument
318 addr = get_vmalloc_page_addr(dmab, start); in snd_dma_vmalloc_get_chunk_size()
324 if (get_vmalloc_page_addr(dmab, start) != addr) in snd_dma_vmalloc_get_chunk_size()
345 static void *snd_dma_iram_alloc(struct snd_dma_buffer *dmab, size_t size) in snd_dma_iram_alloc() argument
347 struct device *dev = dmab->dev.dev; in snd_dma_iram_alloc()
354 dmab->private_data = pool; in snd_dma_iram_alloc()
356 p = gen_pool_dma_alloc_align(pool, size, &dmab->addr, PAGE_SIZE); in snd_dma_iram_alloc()
364 dmab->dev.type = SNDRV_DMA_TYPE_DEV; in snd_dma_iram_alloc()
365 return __snd_dma_alloc_pages(dmab, size); in snd_dma_iram_alloc()
368 static void snd_dma_iram_free(struct snd_dma_buffer *dmab) in snd_dma_iram_free() argument
370 struct gen_pool *pool = dmab->private_data; in snd_dma_iram_free()
372 if (pool && dmab->area) in snd_dma_iram_free()
373 gen_pool_free(pool, (unsigned long)dmab->area, dmab->bytes); in snd_dma_iram_free()
376 static int snd_dma_iram_mmap(struct snd_dma_buffer *dmab, in snd_dma_iram_mmap() argument
381 dmab->addr >> PAGE_SHIFT, in snd_dma_iram_mmap()
402 static void *snd_dma_dev_alloc(struct snd_dma_buffer *dmab, size_t size) in snd_dma_dev_alloc() argument
406 p = dma_alloc_coherent(dmab->dev.dev, size, &dmab->addr, DEFAULT_GFP); in snd_dma_dev_alloc()
408 if (p && dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC) in snd_dma_dev_alloc()
414 static void snd_dma_dev_free(struct snd_dma_buffer *dmab) in snd_dma_dev_free() argument
417 if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC) in snd_dma_dev_free()
418 set_memory_wb((unsigned long)dmab->area, in snd_dma_dev_free()
419 PAGE_ALIGN(dmab->bytes) >> PAGE_SHIFT); in snd_dma_dev_free()
421 dma_free_coherent(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); in snd_dma_dev_free()
424 static int snd_dma_dev_mmap(struct snd_dma_buffer *dmab, in snd_dma_dev_mmap() argument
428 if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC) in snd_dma_dev_mmap()
431 return dma_mmap_coherent(dmab->dev.dev, area, in snd_dma_dev_mmap()
432 dmab->area, dmab->addr, dmab->bytes); in snd_dma_dev_mmap()
448 static void *snd_dma_wc_alloc(struct snd_dma_buffer *dmab, size_t size) in snd_dma_wc_alloc() argument
450 return dma_alloc_wc(dmab->dev.dev, size, &dmab->addr, DEFAULT_GFP); in snd_dma_wc_alloc()
453 static void snd_dma_wc_free(struct snd_dma_buffer *dmab) in snd_dma_wc_free() argument
455 dma_free_wc(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); in snd_dma_wc_free()
458 static int snd_dma_wc_mmap(struct snd_dma_buffer *dmab, in snd_dma_wc_mmap() argument
461 return dma_mmap_wc(dmab->dev.dev, area, in snd_dma_wc_mmap()
462 dmab->area, dmab->addr, dmab->bytes); in snd_dma_wc_mmap()
492 static const struct snd_malloc_ops *snd_dma_get_ops(struct snd_dma_buffer *dmab) in snd_dma_get_ops() argument
494 if (WARN_ON_ONCE(dmab->dev.type <= SNDRV_DMA_TYPE_UNKNOWN || in snd_dma_get_ops()
495 dmab->dev.type >= ARRAY_SIZE(dma_ops))) in snd_dma_get_ops()
497 return dma_ops[dmab->dev.type]; in snd_dma_get_ops()