From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: Scatter-Gather buffer allocation before running on HDSP-MADI ? Date: Mon, 06 Oct 2003 15:50:50 +0200 Sender: alsa-devel-admin@lists.sourceforge.net Message-ID: References: <16254.61960.840856.972245@seneca.iemnet> Mime-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: Errors-To: alsa-devel-admin@lists.sourceforge.net List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: To: Jaroslav Kysela Cc: Winfried Ritsch , alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Sun, 5 Oct 2003 21:01:58 +0200 (CEST), Jaroslav wrote: > > On Sat, 4 Oct 2003, Winfried Ritsch wrote: > > > > > Hello ! > > > > (A question from an newbie-developer to make it perfect ;-) > > > > I am writing an ALSA-lowleveldriver for the RME HDSP-MADI card. > > (which have 64Audion in and out and an 128in64(= 8192Fader) Mixer > > see http://www.rme-audio.de/hdsp/hdspmadi.htm ) Coding is quite > > complete but I have trouble with the memory management. > > > > The Card uses ScatterGather Buffer, each channel 64kB and this > > has to be asigned (to be safe) before activation, so I want > > to allocate SGbuffer (64+64)*64*1024=8388608 in 4k-blocks. > > > > I do a > > > > snd_pcm_lib_preallocate_pci_pages_for_all(hdspm->pci, pcm,8388608l,8388608l) > > > > after making the pcm_device. > > > > Here the questions: > > > > 1) How can I get the sgbuf pointer ? > > > > ... since in the streams runtime is not set and therefore (besides the > > Documentation says is (snd_pcm_sgbuf_t*)substream->dma_private which I > > couldnt find) > > > > sgbuf = (snd_pcm_sgbuf_t*)substream->runtime->dma_private; > > > > is not assigned. > > > > but when I activate the card (for MIDI for example) there must be > > memory asigned und I think doing it in hw_params is to late. > > Note that ALSA has SG routines only for PCM streams and it's lifetime is > limited only for stream lifetime. well, this is no longer true. the sg-buffer allocation is handled generally in snd-page-alloc module (although only PCM handlers use it in practice :) and we have preallocation for sg PCM buffers now, too. > If hardware needs to allocate a big > buffer at the initialization phase, you have to do it yourself. the SG buffers should be pre-allocated via snd_pcm_lib_preallocate_sg_pages() and _for_all() functions instead of snd_pcm_lib_preallocate_pci_pages() and co. in addition, in hw_params() callback, you'll need to map the sg-pages like below: struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); ... for_all_pages { /* rewrite as you like */ /* get the physical address by snd_pcm_sgbuf_get_addr(). */ /* set this address on the hardware's address table */ do_my_mapping(snd_pcm_sgbuf_get_addr(sgbuf, offset)); } check via82xx.c as an example (or emu10k1 driver as a more complex case). you can find a brief information in my tutorial ("Non-Contiguous Buffers" section in "Buffer and Memory Management"). Takashi ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf