ALSA: Add DSP firmware loader
cover ALSA: Add DSP firmware loader
From: Ian Minett <[email protected]>
Hi Takashi,
Thanks for the recent code samples, they were very useful. We've built on them
to produce this latest patchset, incorporating the updates you provided to add the loader functions, and doing a minimal update to the CA0132 codec to use the new ops to perform the firmware transfer.
Please let us know if any tweaks are needed to the update.
Thanks,
- Ian
---
1:
- memalloc.h
- pcm.h
- pcm_memory.c
- sgbuf.c
Include Takashi's updates:
Make snd_sgbuf_get_{ptr|addr}() available for non-SG cases. Passing struct snd_dma_buffer pointer instead, so that they work no matter whether real SG buffer is used or not.
2:
- hda_intel.c
- hda_codec.h
Include Takashi's updates:
Pass DMA buffer pointers in calls to setup_bdle(). Add new callback routines to controller to handle loading firmware binaries.
Add new switch to Kconfig to enable DSP firmware loader.
3:
- patch_ca0132.c
- ca0132_regs.h
Add support for DSP firmware transfer to CA0132 codec:
Add transfer handler functions.
Call the new snd_hda_codec_load_dsp_xxx loader ops to control download. Add chip access routines.
PATCH 1/3 ALSA: Make snd_sgbuf_get_{ptr|addr}() available for non-SG cases.
From: Ian Minett <[email protected]>
include/sound/memalloc.h +25 -2
@@ -98,8 +98,10 @@ static inline unsigned int snd_sgbuf_aligned_pages(size_t size)/* * return the physical address at the corresponding offset */ -static inline dma_addr_t snd_sgbuf_get_addr (struct snd_sg_buf *sgbuf,size_t offset) +static inline dma_addr_t snd_sgbuf_get_addr (struct snd_dma_buffer *dmab, +size_t offset) { +struct snd_sg_buf *sgbuf = dmab->private_data;dma_addr_t addr = sgbuf->table[offset >>PAGE_SHIFT ].addr; addr &=PAGE_MASK ;return addr + offset %PAGE_SIZE ;
@@ -108,10 +110,31 @@ static inline dma_addr_t snd_sgbuf_get_addr(struct snd_sg_buf *sgbuf, size_t off/* * return the virtual address at the corresponding offset */ -static inline void *snd_sgbuf_get_ptr (struct snd_sg_buf *sgbuf,size_t offset) +static inline void *snd_sgbuf_get_ptr (struct snd_dma_buffer *dmab, +size_t offset) { +struct snd_sg_buf *sgbuf = dmab->private_data;return sgbuf->table[offset >>PAGE_SHIFT ].buf + offset %PAGE_SIZE ; } + +unsigned int snd_sgbuf_get_chunk_size (struct snd_dma_buffer *dmab, +unsigned int ofs,unsigned int size); +#else +/* non-SG versions */ +static inline dma_addr_t snd_sgbuf_get_addr (struct snd_dma_buffer *dmab, +size_t offset) +{ +return dmab->addr + offset; +} + +static inline void *snd_sgbuf_get_ptr (struct snd_dma_buffer *dmab, +size_t offset) +{ +return dmab->area + offset; +} + +#define snd_sgbuf_get_chunk_size (dmab, ofs, size) (size) +#endif /* CONFIG_SND_DMA_SGBUF */ /* allocate/release a buffer */
include/sound/pcm.h +14 -25
@@ -982,53 +982,42 @@ static int snd_pcm_lib_alloc_vmalloc_32_buffer_snd_pcm_lib_alloc_vmalloc_buffer \ (subs, size, GFP_KERNEL | GFP_DMA32 | __GFP_ZERO) +#define snd_pcm_get_dma_buf (substream) ((substream)->runtime->dma_buffer_p) +#ifdef CONFIG_SND_DMA_SGBUF /* * SG-buffer handling */ #define snd_pcm_substream_sgbuf (substream) \ - ((substream)->runtime->dma_buffer_p->private_data) - -static inline dma_addr_t -snd_pcm_sgbuf_get_addr (struct snd_pcm_substream *substream,unsigned int ofs) -{ -struct snd_sg_buf *sg =snd_pcm_substream_sgbuf (substream); -return snd_sgbuf_get_addr (sg, ofs); -} - -static inline void * -snd_pcm_sgbuf_get_ptr (struct snd_pcm_substream *substream,unsigned int ofs) -{ -struct snd_sg_buf *sg =snd_pcm_substream_sgbuf (substream); -return snd_sgbuf_get_ptr (sg, ofs); -} + snd_pcm_get_dma_buf(substream)->private_datastruct page *snd_pcm_sgbuf_ops_page (struct snd_pcm_substream *substream,unsigned long offset); -unsigned int snd_pcm_sgbuf_get_chunk_size (struct snd_pcm_substream *substream, -unsigned int ofs,unsigned int size); -#else /* !SND_DMA_SGBUF */ /* * fake using a continuous buffer */ +#define snd_pcm_sgbuf_ops_page NULL +#endif /* SND_DMA_SGBUF */ +static inline dma_addr_t snd_pcm_sgbuf_get_addr (struct snd_pcm_substream *substream,unsigned int ofs) { -return substream->runtime->dma_addr + ofs; +return snd_sgbuf_get_addr (snd_pcm_get_dma_buf (substream), ofs); }static inline void *snd_pcm_sgbuf_get_ptr (struct snd_pcm_substream *substream,unsigned int ofs) { -return substream->runtime->dma_area + ofs; +return snd_sgbuf_get_ptr (snd_pcm_get_dma_buf (substream), ofs); } -#define snd_pcm_sgbuf_ops_page NULL - -#define snd_pcm_sgbuf_get_chunk_size (subs, ofs, size) (size) - -#endif /* SND_DMA_SGBUF */ +static inline unsigned int +snd_pcm_sgbuf_get_chunk_size (struct snd_pcm_substream *substream, +unsigned int ofs,unsigned int size) +{ +return snd_sgbuf_get_chunk_size (snd_pcm_get_dma_buf (substream), ofs, size); +}/* handle mmap counter - PCM mmap callback should handle this counter properly */ static inline void snd_pcm_mmap_data_open (struct vm_area_struct *area)
sound/core/pcm_memory.c +0 -26
@@ -327,32 +327,6 @@ struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigne }EXPORT_SYMBOL (snd_pcm_sgbuf_ops_page); - -/* -* compute the max chunk size with continuous pages on sg-buffer -*/ -unsigned int snd_pcm_sgbuf_get_chunk_size (struct snd_pcm_substream *substream, -unsigned int ofs,unsigned int size) -{ -struct snd_sg_buf *sg =snd_pcm_substream_sgbuf (substream); -unsigned int start, end, pg; - - start = ofs >>PAGE_SHIFT ; - end = (ofs + size -1 ) >>PAGE_SHIFT ; -/* check page continuity */ - pg = sg->table[start].addr >>PAGE_SHIFT ; -for (;;) { - start++; -if (start > end) -break ; - pg++; -if ((sg->table[start].addr >>PAGE_SHIFT ) != pg) -return (start <<PAGE_SHIFT ) - ofs; - } -/* ok, all on continuous pages */ -return size; -} -EXPORT_SYMBOL (snd_pcm_sgbuf_get_chunk_size);#endif /* CONFIG_SND_DMA_SGBUF */ /**
sound/core/sgbuf.c +28 -0
@@ -22,6 +22,7 @@#include <linux/slab.h> #include <linux/mm.h> #include <linux/vmalloc.h> +#include <linux/export.h> #include <sound/memalloc.h>
@@ -136,3 +137,30 @@ void *snd_malloc_sgbuf_pages(struct device *device,snd_free_sgbuf_pages (dmab);/* free the table */ return NULL ; } + + +/* +* compute the max chunk size with continuous pages on sg-buffer +*/ +unsigned int snd_sgbuf_get_chunk_size (struct snd_dma_buffer *dmab, +unsigned int ofs,unsigned int size) +{ +struct snd_sg_buf *sg = dmab->private_data; +unsigned int start, end, pg; + + start = ofs >>PAGE_SHIFT ; + end = (ofs + size -1 ) >>PAGE_SHIFT ; +/* check page continuity */ + pg = sg->table[start].addr >>PAGE_SHIFT ; +for (;;) { + start++; +if (start > end) +break ; + pg++; +if ((sg->table[start].addr >>PAGE_SHIFT ) != pg) +return (start <<PAGE_SHIFT ) - ofs; + } +/* ok, all on continuous pages */ +return size; +} +EXPORT_SYMBOL (snd_sgbuf_get_chunk_size);
Signature · 1 line
1.7.4.1
PATCH 2/3 ALSA: Add new DSP loader callback routines
In reply to Ian MinettFrom: Ian Minett <[email protected]>
sound/pci/hda/Kconfig +8 -0
@@ -244,4 +244,12 @@ config SND_HDA_POWER_SAVE_DEFAULT The default time-out value in seconds for HD-audio automatic power-save mode. 0 means to disable the power-save mode. +config SND_HDA_DSP_LOADER + bool "Enable DSP firmware loader" + depends on FW_LOADER + default y + help + Say Y here to enable the DSP firmware loader, used by certain + codecs (e.g. CA0132) to transfer their DSP binaries to the hardware. + endif
sound/pci/hda/hda_codec.c +1 -1
@@ -2390,7 +2390,7 @@ typedef int (*map_slave_func_t)(void *, struct snd_kcontrol *);/* apply the function to all matching slave ctls in the mixer list */ static int map_slaves (struct hda_codec *codec,const char *const *slaves, -const char *suffix,map_slave_func_t func,void *data) +const char *suffix,map_slave_func_t func,void *data) {struct hda_nid_item *items;const char *const *s;
sound/pci/hda/hda_codec.h +49 -4
83 lines not on this page · raw message
sound/pci/hda/hda_intel.c +117 -14
209 lines not on this page · raw message
Signature · 1 line
1.7.4.1
At Thu, 30 Aug 2012 13:21:03 -0700,
Quoted 8 lines · Ian Minett
From: Ian Minett <[email protected]>
Hi Takashi,
Thanks for the recent code samples, they were very useful. We've built on them
to produce this latest patchset, incorporating the updates you provided to add the loader functions, and doing a minimal update to the CA0132 codec to use the new ops to perform the firmware transfer.
Please let us know if any tweaks are needed to the update.
Thanks for the patches, and sorry for the late response, as I was traveling for KS and Plumbers.
Looking at the new codes now... well, the first two patches are almost what I wrote. In such a case, you must not change the authorship. Keep the git commit author as me.
The third one, the most essential part in the whole patch series, is still fairly difficult to read. Basically a few things are missing:
- No comment to functions. Most of functions look obvious, but still better to describe the fundamental mechanism of the DSP loading on CA0132. And give descriptions to arguments that aren't pretty intuitive (e.g. how router_chans, reloc or ovly influence on behavior.)
- No comment is given to registers. Hard to guess what's XRAM, YRAM, UC or whatever. Brief and concise descriptions are appreciated.
- Home-baked debug macros like SUCCEEDED(), CTASSERT(), CA0132_LOG() or FAIL_MSG() should be avoided. You might think a hack like FAIL_MSG() is great, but it isn't -- even though it saves lines, it hinders the code reading unless readers learn this new code flow condition.
- Because of the big code shuffling (likely too many lines have been inserted in the middle), the patch generation wasn't optimal. For example, you can see chipio_send() is completely added and then deleted in the patch although the function itself isn't changed at all. You can avoided this by carefully putting the new codes in the file. Or some git option might give a better result...
- Why hda_stream_format is defined?
- You need proper ifdefs in patch_ca0132.c for the case without CONFIG_SND_HDA_DSP_LOADER.
- The firmware data must be cached and reloaded upon PM resume.
Also, you fixed some space issues in the patch. If a clean-up is really needed, do it in a separate patch, and don't mix it in this patch.
thanks,
Takashi