[alsa-devel] Allocating DMA buffer for non-PCM

Takashi Iwai tiwai at suse.de
Fri Feb 15 10:04:22 CET 2013


At Thu, 14 Feb 2013 19:46:39 +0100,
Adrian Knoth wrote:
> 
> On 02/14/2013 07:01 PM, Clemens Ladisch wrote:
> 
> >> On Thu, Feb 14, 2013 at 06:46:30PM +0100, Clemens Ladisch wrote:
> >>>> Would you say that the following is the proper way to allocate a DMA
> >>>> buffer used to hold level data?
> >>>>
> >>>> 	err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV_SG,
> >>>> 			snd_dma_pci_data(hdspm->pci),
> >>>> 			MADIFX_LEVEL_BUFFER_SIZE, &hdspm->dmaLevelBuffer);
> >>>>
> >>>>     hdspm->level_buffer = snd_sgbuf_get_ptr(&(hdspm->dmaLevelBuffer), 0);
> >>>
> >>> I don't see the code asking for the address of the second page, so I
> >>> guess there isn't one.
> >>
> >> Exactly.
> > 
> > So MADIFX_LEVEL_BUFFER_SIZE is guaranteed to not exceed the page size
> > on all architectures?
> 
> Absolutely not, it's known to be multiples of the page size, but the
> purpose of hdspm->level_buffer is to hold the continuous virtual
> address, so apparently, I was using the wrong getter function in the
> first place (I was actually looking for .area).

OK, then disregard my previous comment.  The SG-buffer is the right
thing.

FWIW, snd_sgbuf_get_ptr() return the pointer of the particular page.
If you access only the data in the page size, it'll work even with
that.


Takashi

> The code for accessing the other pages was omitted for the sake of
> simplicity, but since you've asked, here it is:
> 
>    	/* Fill level page table */
> 	for (i = 0; i < MADIFX_NUM_LEVEL_PAGES; i++) {
> 		levelPageTable[i] = snd_sgbuf_get_addr(&(hdspm->dmaLevelBuffer),
> 				i * MADIFX_HARDWARE_PAGE_SIZE);
> 
> 	}
> 
> 	/* Write level page table to device */
> 	lpti = (MADIFX == hdspm->io_type) ? MADIFX_LPTI_HMFX :
> 		MADIFX_LPTI_MFXT;
> 
> 	for (i = 0; i < MADIFX_NUM_LEVEL_PAGES; i++) {
> 		madifx_write(hdspm, MADIFX_PAGE_ADDRESS_LIST + (4 * (lpti + i)),
> 				levelPageTable[i]);
> 	}
> 
> 
> 
> Cheers
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel at alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 


More information about the Alsa-devel mailing list