Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: Fix SG-buffer DMA with non-coherent architectures

Using SG-buffers with dma_alloc_coherent() is often very inefficient
on non-coherent architectures because a tracking record could be
allocated in addition for each dma_alloc_coherent() call.
Instead, simply disable SG-buffers but just allocate normal continuous
buffers on non-supported (currently all but x86) architectures.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

+40 -1
+6
include/sound/memalloc.h
··· 47 47 #define SNDRV_DMA_TYPE_UNKNOWN 0 /* not defined */ 48 48 #define SNDRV_DMA_TYPE_CONTINUOUS 1 /* continuous no-DMA memory */ 49 49 #define SNDRV_DMA_TYPE_DEV 2 /* generic device continuous */ 50 + #ifdef CONFIG_SND_DMA_SGBUF 50 51 #define SNDRV_DMA_TYPE_DEV_SG 3 /* generic device SG-buffer */ 52 + #else 53 + #define SNDRV_DMA_TYPE_DEV_SG SNDRV_DMA_TYPE_DEV /* no SG-buf support */ 54 + #endif 51 55 52 56 /* 53 57 * info for buffer allocation ··· 64 60 void *private_data; /* private for allocator; don't touch */ 65 61 }; 66 62 63 + #ifdef CONFIG_SND_DMA_SGBUF 67 64 /* 68 65 * Scatter-Gather generic device pages 69 66 */ ··· 112 107 { 113 108 return sgbuf->table[offset >> PAGE_SHIFT].buf + offset % PAGE_SIZE; 114 109 } 110 + #endif /* CONFIG_SND_DMA_SGBUF */ 115 111 116 112 /* allocate/release a buffer */ 117 113 int snd_dma_alloc_pages(int type, struct device *dev, size_t size,
+23
include/sound/pcm.h
··· 902 902 int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size); 903 903 int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream); 904 904 905 + #ifdef CONFIG_SND_DMA_SGBUF 905 906 /* 906 907 * SG-buffer handling 907 908 */ ··· 927 926 unsigned long offset); 928 927 unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream, 929 928 unsigned int ofs, unsigned int size); 929 + 930 + #else /* !SND_DMA_SGBUF */ 931 + /* 932 + * fake using a continuous buffer 933 + */ 934 + static inline dma_addr_t 935 + snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs) 936 + { 937 + return substream->runtime->dma_addr + ofs; 938 + } 939 + 940 + static inline void * 941 + snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs) 942 + { 943 + return substream->runtime->dma_area + ofs; 944 + } 945 + 946 + #define snd_pcm_sgbuf_ops_page NULL 947 + 948 + #define snd_pcm_sgbuf_get_chunk_size(subs, ofs, size) (size) 949 + 950 + #endif /* SND_DMA_SGBUF */ 930 951 931 952 /* handle mmap counter - PCM mmap callback should handle this counter properly */ 932 953 static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
+4
sound/core/Kconfig
··· 206 206 config SND_VMASTER 207 207 bool 208 208 209 + config SND_DMA_SGBUF 210 + def_bool y 211 + depends on X86 212 + 209 213 source "sound/core/seq/Kconfig"
+1 -1
sound/core/Makefile
··· 13 13 pcm_memory.o 14 14 15 15 snd-page-alloc-y := memalloc.o 16 - snd-page-alloc-$(CONFIG_HAS_DMA) += sgbuf.o 16 + snd-page-alloc-$(CONFIG_SND_DMA_SGBUF) += sgbuf.o 17 17 18 18 snd-rawmidi-objs := rawmidi.o 19 19 snd-timer-objs := timer.o
+4
sound/core/memalloc.c
··· 199 199 case SNDRV_DMA_TYPE_DEV: 200 200 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr); 201 201 break; 202 + #endif 203 + #ifdef CONFIG_SND_DMA_SGBUF 202 204 case SNDRV_DMA_TYPE_DEV_SG: 203 205 snd_malloc_sgbuf_pages(device, size, dmab, NULL); 204 206 break; ··· 271 269 case SNDRV_DMA_TYPE_DEV: 272 270 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr); 273 271 break; 272 + #endif 273 + #ifdef CONFIG_SND_DMA_SGBUF 274 274 case SNDRV_DMA_TYPE_DEV_SG: 275 275 snd_free_sgbuf_pages(dmab); 276 276 break;
+2
sound/core/pcm_memory.c
··· 304 304 305 305 EXPORT_SYMBOL(snd_pcm_lib_preallocate_pages_for_all); 306 306 307 + #ifdef CONFIG_SND_DMA_SGBUF 307 308 /** 308 309 * snd_pcm_sgbuf_ops_page - get the page struct at the given offset 309 310 * @substream: the pcm substream instance ··· 350 349 return size; 351 350 } 352 351 EXPORT_SYMBOL(snd_pcm_sgbuf_get_chunk_size); 352 + #endif /* CONFIG_SND_DMA_SGBUF */ 353 353 354 354 /** 355 355 * snd_pcm_lib_malloc_pages - allocate the DMA buffer