Update of /cvsroot/alsa/alsa-kernel/pci/trident
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18820/alsa-kernel/pci/trident

Modified Files:
        trident_main.c trident_memory.c trident_synth.c 
Log Message:
Big DMA cleanup originated by Russell King <[EMAIL PROTECTED]>
* Russel
  - introduced 'struct device' support for 2.6 dma_alloc_coherent()
* Jaroslav
  - removed all bus-specific allocation functions
  - extended snd_dma_alloc_pages/snd_dma_free_pages to handle all bus types
  - recoded all (or almost all) device drivers
  - sgbuf functions are bus independent now


Index: trident_main.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/pci/trident/trident_main.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- trident_main.c      22 Feb 2004 18:35:01 -0000      1.53
+++ trident_main.c      2 Mar 2004 15:32:38 -0000       1.54
@@ -2189,10 +2189,10 @@
        if (trident->tlb.entries) {
                snd_pcm_substream_t *substream;
                for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; 
substream; substream = substream->next)
-                       snd_pcm_lib_preallocate_sg_pages(trident->pci, substream, 
64*1024, 128*1024);
-               snd_pcm_lib_preallocate_pci_pages(trident->pci, 
pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, 64*1024, 128*1024);
+                       snd_pcm_lib_preallocate_pages(substream, 
SNDRV_DMA_TYPE_PCI_SG, trident->pci, 64*1024, 128*1024);
+               
snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, 
SNDRV_DMA_TYPE_PCI, trident->pci, 64*1024, 128*1024);
        } else {
-               snd_pcm_lib_preallocate_pci_pages_for_all(trident->pci, pcm, 64*1024, 
128*1024);
+               snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_PCI, 
trident->pci, 64*1024, 128*1024);
        }
 
        if (rpcm)
@@ -2246,9 +2246,9 @@
        trident->foldback = foldback;
 
        if (trident->tlb.entries)
-               snd_pcm_lib_preallocate_sg_pages_for_all(trident->pci, foldback, 0, 
128*1024);
+               snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_PCI_SG, 
trident->pci, 0, 128*1024);
        else
-               snd_pcm_lib_preallocate_pci_pages_for_all(trident->pci, foldback, 
64*1024, 128*1024);
+               snd_pcm_lib_preallocate_pages_for_all(foldback, SNDRV_DMA_TYPE_PCI, 
trident->pci, 64*1024, 128*1024);
 
        if (rpcm)
                *rpcm = foldback;
@@ -2287,7 +2287,7 @@
        strcpy(spdif->name, "Trident 4DWave IEC958");
        trident->spdif = spdif;
 
-       snd_pcm_lib_preallocate_pci_pages_for_all(trident->pci, spdif, 64*1024, 
128*1024);
+       snd_pcm_lib_preallocate_pages_for_all(spdif, SNDRV_DMA_TYPE_PCI, trident->pci, 
64*1024, 128*1024);
 
        if (rpcm)
                *rpcm = spdif;
@@ -3348,13 +3348,12 @@
        /* TLB array must be aligned to 16kB !!! so we allocate
           32kB region and correct offset when necessary */
 
-       trident->tlb.buffer = snd_malloc_pci_pages(trident->pci, 2 * 
SNDRV_TRIDENT_MAX_PAGES * 4, &trident->tlb.buffer_dmaaddr);
-       if (trident->tlb.buffer == NULL) {
+       if (snd_dma_alloc_pages(&trident->dma_dev, 2 * SNDRV_TRIDENT_MAX_PAGES * 4, 
&trident->tlb.buffer) < 0) {
                snd_printk(KERN_ERR "trident: unable to allocate TLB buffer\n");
                return -ENOMEM;
        }
-       trident->tlb.entries = (unsigned int*)(((unsigned long)trident->tlb.buffer + 
SNDRV_TRIDENT_MAX_PAGES * 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES * 4 - 1));
-       trident->tlb.entries_dmaaddr = (trident->tlb.buffer_dmaaddr + 
SNDRV_TRIDENT_MAX_PAGES * 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES * 4 - 1);
+       trident->tlb.entries = (unsigned int*)(((unsigned 
long)trident->tlb.buffer.area + SNDRV_TRIDENT_MAX_PAGES * 4 - 1) & 
~(SNDRV_TRIDENT_MAX_PAGES * 4 - 1));
+       trident->tlb.entries_dmaaddr = (trident->tlb.buffer.addr + 
SNDRV_TRIDENT_MAX_PAGES * 4 - 1) & ~(SNDRV_TRIDENT_MAX_PAGES * 4 - 1);
        /* allocate shadow TLB page table (virtual addresses) */
        trident->tlb.shadow_entries = (unsigned long 
*)vmalloc(SNDRV_TRIDENT_MAX_PAGES*sizeof(unsigned long));
        if (trident->tlb.shadow_entries == NULL) {
@@ -3362,15 +3361,14 @@
                return -ENOMEM;
        }
        /* allocate and setup silent page and initialise TLB entries */
-       trident->tlb.silent_page = snd_malloc_pci_pages(trident->pci, 
SNDRV_TRIDENT_PAGE_SIZE, &trident->tlb.silent_page_dmaaddr);
-       if (trident->tlb.silent_page == 0UL) {
+       if (snd_dma_alloc_pages(&trident->dma_dev, SNDRV_TRIDENT_PAGE_SIZE, 
&trident->tlb.silent_page) < 0) {
                snd_printk(KERN_ERR "trident: unable to allocate silent page\n");
                return -ENOMEM;
        }
-       memset(trident->tlb.silent_page, 0, SNDRV_TRIDENT_PAGE_SIZE);
+       memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE);
        for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++) {
-               trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page_dmaaddr 
& ~(SNDRV_TRIDENT_PAGE_SIZE-1));
-               trident->tlb.shadow_entries[i] = (unsigned 
long)trident->tlb.silent_page;
+               trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page.addr & 
~(SNDRV_TRIDENT_PAGE_SIZE-1));
+               trident->tlb.shadow_entries[i] = (unsigned 
long)trident->tlb.silent_page.area;
        }
 
        /* use emu memory block manager code to manage tlb page allocation */
@@ -3585,9 +3583,13 @@
        }
        trident->irq = pci->irq;
 
+       memset(&trident->dma_dev, 0, sizeof(trident->dma_dev));
+       trident->dma_dev.type = SNDRV_DMA_TYPE_PCI;
+       trident->dma_dev.dev.pci = pci;
+
        /* allocate 16k-aligned TLB for NX cards */
        trident->tlb.entries = NULL;
-       trident->tlb.buffer = NULL;
+       trident->tlb.buffer.area = NULL;
        if (trident->device == TRIDENT_DEVICE_ID_NX) {
                if ((err = snd_trident_tlb_alloc(trident)) < 0) {
                        snd_trident_free(trident);
@@ -3681,15 +3683,15 @@
        else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
                outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
        }
-       if (trident->tlb.buffer) {
+       if (trident->tlb.buffer.area) {
                outl(0, TRID_REG(trident, NX_TLBC));
                if (trident->tlb.memhdr)
                        snd_util_memhdr_free(trident->tlb.memhdr);
-               if (trident->tlb.silent_page)
-                       snd_free_pci_pages(trident->pci, SNDRV_TRIDENT_PAGE_SIZE, 
trident->tlb.silent_page, trident->tlb.silent_page_dmaaddr);
+               if (trident->tlb.silent_page.area)
+                       snd_dma_free_pages(&trident->dma_dev, 
&trident->tlb.silent_page);
                if (trident->tlb.shadow_entries)
                        vfree(trident->tlb.shadow_entries);
-               snd_free_pci_pages(trident->pci, 2 * SNDRV_TRIDENT_MAX_PAGES * 4, 
trident->tlb.buffer, trident->tlb.buffer_dmaaddr);
+               snd_dma_free_pages(&trident->dma_dev, &trident->tlb.buffer);
        }
        if (trident->irq >= 0)
                free_irq(trident->irq, (void *)trident);

Index: trident_memory.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/pci/trident/trident_memory.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- trident_memory.c    9 Mar 2003 23:16:12 -0000       1.11
+++ trident_memory.c    2 Mar 2004 15:32:38 -0000       1.12
@@ -47,7 +47,7 @@
 /* fill TLB entrie(s) corresponding to page with ptr */
 #define set_tlb_bus(trident,page,ptr,addr) __set_tlb_bus(trident,page,ptr,addr)
 /* fill TLB entrie(s) corresponding to page with silence pointer */
-#define set_silent_tlb(trident,page)   __set_tlb_bus(trident, page, (unsigned 
long)trident->tlb.silent_page, trident->tlb.silent_page_dmaaddr)
+#define set_silent_tlb(trident,page)   __set_tlb_bus(trident, page, (unsigned 
long)trident->tlb.silent_page.area, trident->tlb.silent_page.addr)
 /* get aligned page from offset address */
 #define get_aligned_page(offset)       ((offset) >> 12)
 /* get offset address from aligned page */
@@ -367,8 +367,13 @@
        void *ptr = page_to_ptr(trident, page);
        dma_addr_t addr = page_to_addr(trident, page);
        set_silent_tlb(trident, page);
-       if (ptr)
-               snd_free_pci_pages(trident->pci, ALIGN_PAGE_SIZE, ptr, addr);
+       if (ptr) {
+               struct snd_dma_buffer dmab;
+               dmab.area = ptr;
+               dmab.addr = addr;
+               dmab.bytes = ALIGN_PAGE_SIZE;
+               snd_dma_free_pages(&trident->dma_dev, &dmab);
+       }
 }
 
 /* check new allocation range */
@@ -399,8 +404,7 @@
 static int synth_alloc_pages(trident_t *hw, snd_util_memblk_t *blk)
 {
        int page, first_page, last_page;
-       void *ptr;
-       dma_addr_t addr;
+       struct snd_dma_buffer dmab;
 
        firstpg(blk) = get_aligned_page(blk->offset);
        lastpg(blk) = get_aligned_page(blk->offset + blk->size - 1);
@@ -410,14 +414,13 @@
         * fortunately Trident page size and kernel PAGE_SIZE is identical!
         */
        for (page = first_page; page <= last_page; page++) {
-               ptr = snd_malloc_pci_pages(hw->pci, ALIGN_PAGE_SIZE, &addr);
-               if (ptr == NULL)
+               if (snd_dma_alloc_pages(&hw->dma_dev, ALIGN_PAGE_SIZE, &dmab) < 0)
                        goto __fail;
-               if (! is_valid_page(addr)) {
-                       snd_free_pci_pages(hw->pci, ALIGN_PAGE_SIZE, ptr, addr);
+               if (! is_valid_page(dmab.addr)) {
+                       snd_dma_free_pages(&hw->dma_dev, &dmab);
                        goto __fail;
                }
-               set_tlb_bus(hw, page, (unsigned long)ptr, addr);
+               set_tlb_bus(hw, page, (unsigned long)dmab.area, dmab.addr);
        }
        return 0;
 

Index: trident_synth.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/pci/trident/trident_synth.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- trident_synth.c     16 May 2003 08:37:42 -0000      1.11
+++ trident_synth.c     2 Mar 2004 15:32:38 -0000       1.12
@@ -507,7 +507,6 @@
                                         char *data, long len, int atomic)
 {
        trident_t *trident = snd_magic_cast(trident_t, private_data, return -ENXIO);
-       unsigned char *block = NULL;
        int size = instr->size;
        int shift = 0;
 
@@ -530,7 +529,7 @@
 
        if (trident->tlb.entries) {
                snd_util_memblk_t *memblk;
-               memblk = snd_trident_synth_alloc(trident,size); 
+               memblk = snd_trident_synth_alloc(trident, size); 
                if (memblk == NULL)
                        return -ENOMEM;
                if (snd_trident_synth_copy_from_user(trident, memblk, 0, data, size) ) 
{
@@ -540,17 +539,17 @@
                instr->address.ptr = (unsigned char*)memblk;
                instr->address.memory = memblk->offset;
        } else {
-               dma_addr_t addr;
-               block = (unsigned char *) snd_malloc_pci_pages(trident->pci, size, 
&addr);
-               if (block == NULL)
+               struct snd_dma_buffer dmab;
+
+               if (snd_dma_alloc_pages(&trident->dma_dev, size, &dmab) < 0)
                        return -ENOMEM;
 
-               if (copy_from_user(block, data, size)) {
-                       snd_free_pci_pages(trident->pci, size, block, addr);
+               if (copy_from_user(dmab.area, data, size)) {
+                       snd_dma_free_pages(&trident->dma_dev, &dmab);
                        return -EFAULT;
                }
-               instr->address.ptr = block;
-               instr->address.memory = addr;
+               instr->address.ptr = dmab.area;
+               instr->address.memory = dmab.addr;
        }
 
        trident->synth.current_size += size;



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to