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

ALSA: core: Add device-managed request_dma()

This patch adds a devres-supported helper for requesting an ISA DMA
channel that will be automatically freed at the device unbinding.
It'll be used by quite a few ISA sound drivers.

Link: https://lore.kernel.org/r/20210715075941.23332-4-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+39
+1
include/sound/core.h
··· 329 329 void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode); 330 330 void snd_dma_disable(unsigned long dma); 331 331 unsigned int snd_dma_pointer(unsigned long dma, unsigned int size); 332 + int snd_devm_request_dma(struct device *dev, int dma, const char *name); 332 333 #endif 333 334 334 335 /* misc.c */
+38
sound/core/isadma.c
··· 97 97 return size - result; 98 98 } 99 99 EXPORT_SYMBOL(snd_dma_pointer); 100 + 101 + struct snd_dma_data { 102 + int dma; 103 + }; 104 + 105 + static void __snd_release_dma(struct device *dev, void *data) 106 + { 107 + struct snd_dma_data *p = data; 108 + 109 + snd_dma_disable(p->dma); 110 + free_dma(p->dma); 111 + } 112 + 113 + /** 114 + * snd_devm_request_dma - the managed version of request_dma() 115 + * @dev: the device pointer 116 + * @dma: the dma number 117 + * @name: the name string of the requester 118 + * 119 + * Returns zero on success, or a negative error code. 120 + * The requested DMA will be automatically released at unbinding via devres. 121 + */ 122 + int snd_devm_request_dma(struct device *dev, int dma, const char *name) 123 + { 124 + struct snd_dma_data *p; 125 + 126 + if (request_dma(dma, name)) 127 + return -EBUSY; 128 + p = devres_alloc(__snd_release_dma, sizeof(*p), GFP_KERNEL); 129 + if (!p) { 130 + free_dma(dma); 131 + return -ENOMEM; 132 + } 133 + p->dma = dma; 134 + devres_add(dev, p); 135 + return 0; 136 + } 137 + EXPORT_SYMBOL_GPL(snd_devm_request_dma);