mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +00:00
a25684a956
This patch adds the support for allocation of non-contiguous DMA pages in the common memalloc helper. It's another SG-buffer type, but unlike the existing one, this is directional and requires the explicit sync / invalidation of dirty pages on non-coherent architectures. For this enhancement, the following points are changed: - snd_dma_device stores the DMA direction. - snd_dma_device stores need_sync flag indicating whether the explicit sync is required or not. - A new variant of helper functions, snd_dma_alloc_dir_pages() and *_all() are introduced; the old snd_dma_alloc_pages() and *_all() kept as just wrappers with DMA_BIDIRECTIONAL. - A new helper snd_dma_buffer_sync() is introduced; this gets called in the appropriate places. - A new allocation type, SNDRV_DMA_TYPE_NONCONTIG, is introduced. When the driver allocates pages with this new type, and it may require the SNDRV_PCM_INFO_EXPLICIT_SYNC flag set to the PCM hardware.info for taking the full control of PCM applptr and hwptr changes (that implies disabling the mmap of control/status data). When the buffer allocation is managed by snd_pcm_set_managed_buffer(), this flag is automatically set depending on the result of dma_need_sync() internally. Otherwise, if the buffer is managed manually, the driver has to set the flag explicitly, too. The explicit sync between CPU and device for non-coherent memory is performed at the points before and after read/write transfer as well as the applptr/hwptr syncptr ioctl. In the case of mmap mode, user-space is supposed to call the syncptr ioctl with the hwptr flag to update and fetch the status at first; this corresponds to CPU-sync. Then user-space advances the applptr via syncptr ioctl again with applptr flag, and this corresponds to the device sync with flushing. Other than the DMA direction and the explicit sync, the usage of this new buffer type is almost equivalent with the existing SNDRV_DMA_TYPE_DEV_SG; you can get the page and the address via snd_sgbuf_get_page() and snd_sgbuf_get_addr(), also calculate the continuous pages via snd_sgbuf_get_chunk_size(). For those SG-page handling, the non-contig type shares the same ops with the vmalloc handler. As we do always vmap the SG pages at first, the actual address can be deduced from the vmapped address easily without iterating the SG-list. Link: https://lore.kernel.org/r/20211017074859.24112-2-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
21 lines
741 B
C
21 lines
741 B
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#ifndef __MEMALLOC_LOCAL_H
|
|
#define __MEMALLOC_LOCAL_H
|
|
|
|
struct snd_malloc_ops {
|
|
void *(*alloc)(struct snd_dma_buffer *dmab, size_t size);
|
|
void (*free)(struct snd_dma_buffer *dmab);
|
|
dma_addr_t (*get_addr)(struct snd_dma_buffer *dmab, size_t offset);
|
|
struct page *(*get_page)(struct snd_dma_buffer *dmab, size_t offset);
|
|
unsigned int (*get_chunk_size)(struct snd_dma_buffer *dmab,
|
|
unsigned int ofs, unsigned int size);
|
|
int (*mmap)(struct snd_dma_buffer *dmab, struct vm_area_struct *area);
|
|
void (*sync)(struct snd_dma_buffer *dmab, enum snd_dma_sync_mode mode);
|
|
};
|
|
|
|
#ifdef CONFIG_SND_DMA_SGBUF
|
|
extern const struct snd_malloc_ops snd_dma_sg_ops;
|
|
#endif
|
|
|
|
#endif /* __MEMALLOC_LOCAL_H */
|