Update of /cvsroot/alsa/alsa-driver/acore
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24264/acore

Modified Files:
        memalloc.inc memalloc.inc1 memalloc.patch memory_wrapper.c 
        pci_compat_22.c sgbuf.c 
Log Message:
- clean up the DMA code.  added the wrapper for 2.2/2.4 kernels.
- don't include unneeded header files for 2.6 kernels.
- always export pci_alloc_consistent() wrapper for 2.2 kernels.
  it's used for ISA buffer allocation now.
- added the missing header files.


Index: memalloc.inc
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/acore/memalloc.inc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- memalloc.inc        5 Mar 2004 11:54:05 -0000       1.5
+++ memalloc.inc        6 Mar 2004 16:55:12 -0000       1.6
@@ -28,100 +28,6 @@
 }
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)
-static LIST_HEAD(snd_pci_devices);
-
-struct snd_pci_device {
-       struct list_head *list;
-       struct device dev;
-       struct pci_dev *pci;
-       u64 dummy_mask;
-};
-
-static inline struct pci_dev *to_pci_dev(struct device *dev)
-{
-       return dev->d.pci;
-}
-
-static inline void *dma_alloc_coherent(struct device *dev, size_t size,
-                                      dma_addr_t *dma_handle, int flag)
-{
-       return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
-}
-
-static inline void dma_free_coherent(struct device *dev, size_t size,
-                                    void *vaddr, dma_addr_t dma_handle)
-{
-       pci_free_consistent(to_pci_dev(dev), size, vaddr, dma_handle);
-}
-
-struct device *snd_kdevice_pci(struct pci_dev *pci)
-{
-       struct snd_pci_device *pdev;
-       struct list_head *pos;
-
-       list_for_each(pos, &snd_pci_devices) {
-               pdev = list_entry(pos, struct snd_pci_device, list);
-               if (pdev->pci == pci)
-                       return &pdev->dev;
-       }
-       pdev = kmalloc(sizeof(struct snd_pci_device), GFP_KERNEL);
-       if (pdev == NULL) {
-               printk(KERN_ERR "unable to allocate snd_pci_device struct\n");
-               return NULL;
-       }
-       pdev->dev.d.pci = pci;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
-       pdev->dev.dma_mask = &pci->dma_mask;
-#else
-       pdev->dev.dma_mask = &pdev->dummy_mask;
-#endif
-       return &pdev->dev;
-}
-
-static void snd_kdevice_free_all(void)
-{
-       struct snd_pci_device *pdev;
-       struct list_head *pos, *n;
-
-       list_for_each_safe(pos, n, &snd_pci_devices) {
-               pdev = list_entry(pos, struct snd_pci_device, list);
-               kfree(pdev);
-       }
-}
-
-static const char *snd_pci_dev_name(struct pci_dev *pci)
-{
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
-       if (pci) {
-               static char tmp[32];
-               sprintf(tmp, "%02x:%02x:%02x",
-                       pci->bus->number,
-                       pci->bus->primary,
-                       pci->bus->secondary);
-               return tmp;
-       }
-#else
-       if (pci)
-               return pci->slot_name;
-#endif
-       return "???";
-}
-
-static const char *snd_kdevice_busid(struct device *dev)
-{
-       return snd_pci_dev_name(dev->d.pci);
-}
-
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
 #define __GFP_NOWARN   0
-
-#else /* >= 2.5.0 */
-
-static inline struct device *snd_kdevice_pci(struct pci_dev *pci)
-{
-       return &pci->dev;
-}
-
-#define snd_kdevice_free_all()
-
-#endif /* <2.5.0 */
+#endif

Index: memalloc.inc1
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/acore/memalloc.inc1,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- memalloc.inc1       20 Nov 2003 10:47:30 -0000      1.2
+++ memalloc.inc1       6 Mar 2004 16:55:12 -0000       1.3
@@ -1,5 +1,8 @@
 /* compatible functions */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) && defined(CONFIG_PCI)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
+EXPORT_SYMBOL(snd_pci_compat_alloc_consistent);
+EXPORT_SYMBOL(snd_pci_compat_free_consistent);
+#ifdef CONFIG_PCI
 EXPORT_SYMBOL(snd_pci_compat_match_device);
 EXPORT_SYMBOL(snd_pci_compat_register_driver);
 EXPORT_SYMBOL(snd_pci_compat_unregister_driver);
@@ -8,8 +11,6 @@
 EXPORT_SYMBOL(snd_pci_compat_set_power_state);
 EXPORT_SYMBOL(snd_pci_compat_enable_device);
 EXPORT_SYMBOL(snd_pci_compat_find_capability);
-EXPORT_SYMBOL(snd_pci_compat_alloc_consistent);
-EXPORT_SYMBOL(snd_pci_compat_free_consistent);
 EXPORT_SYMBOL(snd_pci_compat_dma_supported);
 EXPORT_SYMBOL(snd_pci_compat_get_dma_mask);
 EXPORT_SYMBOL(snd_pci_compat_set_dma_mask);
@@ -21,6 +22,7 @@
 EXPORT_SYMBOL(snd_pci_compat_request_regions);
 EXPORT_SYMBOL(snd_pci_compat_release_regions);
 #endif
+#endif
 
 #ifndef CONFIG_HAVE_VMALLOC_TO_PAGE
 EXPORT_SYMBOL(snd_compat_vmalloc_to_page);

Index: memalloc.patch
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/acore/memalloc.patch,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- memalloc.patch      5 Mar 2004 11:54:05 -0000       1.5
+++ memalloc.patch      6 Mar 2004 16:55:12 -0000       1.6
@@ -1,96 +1,100 @@
---- ../alsa-kernel/core/memalloc.c     2004-03-03 20:53:56.000000000 +0100
-+++ memalloc.c 2004-03-05 00:44:35.895900880 +0100
+--- memalloc.c 2004-03-06 17:00:36.556407787 +0100
++++ memalloc.c 2004-03-06 17:00:32.107418149 +0100
 @@ -1,3 +1,4 @@
 +#include "memalloc.inc"
  /*
   *  Copyright (c) by Jaroslav Kysela <[EMAIL PROTECTED]>
   *                   Takashi Iwai <[EMAIL PROTECTED]>
-@@ -85,6 +86,7 @@
+@@ -89,6 +90,7 @@
   *  Hacks
   */
  
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
+ static void *snd_dma_alloc_coherent1(struct device *dev, size_t size,
+                                    dma_addr_t *dma_handle, int flags)
+ {
+@@ -112,7 +114,15 @@
+ #undef dma_free_coherent
+ #define dma_free_coherent snd_dma_free_coherent1
+ 
++#else
++
++/* for 2.2/2.4 kernels */
++#define dma_alloc_coherent(dev,size,addr,flags) pci_alloc_consistent((struct pci_dev 
*)(dev),size,addr)
++#define dma_free_coherent(dev,size,ptr,addr) pci_free_consistent((struct pci_dev 
*)(dev),size,ptr,addr)
+ 
++#endif /* >= 2.6.0 */
++
 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
  #if defined(__i386__) || defined(__ppc__) || defined(__x86_64__)
  
  /*
-@@ -135,6 +137,7 @@
+@@ -136,13 +146,29 @@
+ {
+       void *ret;
+       u64 dma_mask;
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
++      struct pci_dev *pci = (struct pci_dev *)dev;
++#endif
+ 
+-      if (dev == NULL || !dev->dma_mask)
++      if (dev == NULL
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
++          || !dev->dma_mask
++#endif
++          )
+               return dma_alloc_coherent(dev, size, dma_handle, flags);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
+       dma_mask = *dev->dma_mask;
+       *dev->dma_mask = 0xffffffff;    /* do without masking */
++#else
++      dma_mask = pci->dma_mask;
++      pci->dma_mask = 0xffffffff;     /* do without masking */
++#endif
+       ret = dma_alloc_coherent(dev, size, dma_handle, flags);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
+       *dev->dma_mask = dma_mask;      /* restore */
++#else
++      pci->dma_mask = dma_mask;       /* restore */
++#endif
+       if (ret) {
+               /* obtained address is out of range? */
+               if (((unsigned long)*dma_handle + size - 1) & ~dma_mask) {
+@@ -163,6 +189,8 @@
  #define dma_alloc_coherent snd_dma_hack_alloc_coherent
  
  #endif /* arch */
 +#endif /* >= 2.4.0 */
++
  
  /*
   *
-@@ -462,7 +465,7 @@
- #endif
- #ifdef CONFIG_PCI
-       case SNDRV_DMA_TYPE_PCI:
--              dmab->area = snd_malloc_dev_pages(&dev->dev.pci->dev, size, 
&dmab->addr);
-+              dmab->area = snd_malloc_dev_pages(snd_kdevice_pci(dev->dev.pci), size, 
&dmab->addr);
-               break;
- #endif
-       case SNDRV_DMA_TYPE_DEV:
-@@ -523,7 +526,7 @@
- #endif
- #ifdef CONFIG_PCI
-       case SNDRV_DMA_TYPE_PCI:
--              dmab->area = snd_malloc_dev_pages_fallback(&dev->dev.pci->dev, size, 
&dmab->addr, &dmab->bytes);
-+              dmab->area = 
snd_malloc_dev_pages_fallback(snd_kdevice_pci(dev->dev.pci), size, &dmab->addr, 
&dmab->bytes);
-               break;
- #endif
-       case SNDRV_DMA_TYPE_DEV:
-@@ -570,7 +573,7 @@
- #endif
- #ifdef CONFIG_PCI
-       case SNDRV_DMA_TYPE_PCI:
--              snd_free_dev_pages(&dev->dev.pci->dev, dmab->bytes, dmab->area, 
dmab->addr);
-+              snd_free_dev_pages(snd_kdevice_pci(dev->dev.pci), dmab->bytes, 
dmab->area, dmab->addr);
-               break;
- #endif
-       case SNDRV_DMA_TYPE_DEV:
-@@ -725,6 +728,7 @@
-               kfree(mem);
-       }
-       up(&list_mutex);
-+      snd_kdevice_free_all();
- }
- 
- 
-@@ -772,7 +776,7 @@
- {
-       memset(dev, 0, sizeof(*dev));
-       dev->type = SNDRV_DMA_TYPE_DEV;
--      dev->dev.dev = &pci->dev;
-+      dev->dev.dev = snd_kdevice_pci(pci);
-       dev->id = id;
- }
- 
-@@ -875,7 +879,11 @@
-                       if (mem->dev.dev.dev) {
+@@ -797,9 +825,24 @@
+               case SNDRV_DMA_TYPE_DEV:
+               case SNDRV_DMA_TYPE_DEV_SG:
+                       if (mem->dev.dev) {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
                                len += sprintf(page + len, "%s [%s]",
-                                              mem->dev.type == SNDRV_DMA_TYPE_PCI_SG 
? "PCI" : "PCI-SG",
--                                             mem->dev.dev.pci->slot_name);
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
-+                                             mem->dev.dev.pci->dev.bus_id);
+                                              mem->dev.type == SNDRV_DMA_TYPE_DEV_SG 
? "DEV-SG" : "DEV",
+                                              mem->dev.dev->bus_id);
 +#else
-+                                             snd_pci_dev_name(mem->dev.dev.pci));
-+#endif
-                       }
-                       break;
- #endif
-@@ -884,7 +892,11 @@
-                       if (mem->dev.dev.dev) {
-                               len += sprintf(page + len, "%s [%s]",
-                                              mem->dev.type == SNDRV_DMA_TYPE_DEV_SG 
? "DEV" : "DEV-SG",
-+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
-                                              mem->dev.dev.dev->bus_id);
++                              struct pci_dev *pci = (struct pci_dev *)mem->dev.dev;
++                              len += sprintf(page + len, "%s ",
++                                             mem->dev.type == SNDRV_DMA_TYPE_DEV_SG 
? "PCI-SG" : "PCI");
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
++                              len += sprintf(page + len, "[%02x:%02x:%02x]",
++                                             pci->bus->number,
++                                             pci->bus->primary,
++                                             pci->bus->secondary);
 +#else
-+                                             snd_kdevice_busid(mem->dev.dev.dev));
++                              len += sprintf(page + len, "[%s]",
++                                             pci->slot_name);
++#endif /* < 2.4.0 */
 +#endif
-                       }
+                       } else
+                               len += sprintf(page + len, "ISA");
                        break;
-               default:
-@@ -959,3 +971,5 @@
+@@ -875,3 +918,5 @@
  EXPORT_SYMBOL(snd_malloc_pages);
  EXPORT_SYMBOL(snd_malloc_pages_fallback);
  EXPORT_SYMBOL(snd_free_pages);

Index: memory_wrapper.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/acore/memory_wrapper.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- memory_wrapper.c    10 Nov 2003 17:32:37 -0000      1.10
+++ memory_wrapper.c    6 Mar 2004 16:55:12 -0000       1.11
@@ -15,11 +15,9 @@
 #include <linux/mm.h>
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
-#ifdef CONFIG_PCI
 #include <sound/memalloc.h>
 #include "pci_compat_22.c"
 #endif
-#endif
 
 /* vmalloc_to_page wrapper */
 #ifndef CONFIG_HAVE_VMALLOC_TO_PAGE

Index: pci_compat_22.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/acore/pci_compat_22.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- pci_compat_22.c     21 Jan 2004 08:22:17 -0000      1.10
+++ pci_compat_22.c     6 Mar 2004 16:55:12 -0000       1.11
@@ -2,6 +2,8 @@
  * PCI-compatible layer for 2.2 kernels
  */
 
+#ifdef CONFIG_PCI
+
 static LIST_HEAD(pci_drivers);
 
 struct pci_driver_mapping {
@@ -296,46 +298,6 @@
        return 0;
 }
 
-static void *snd_pci_compat_alloc_consistent1(unsigned long dma_mask,
-                                             unsigned long size,
-                                             int hop)
-{
-       void *res;
-
-       if (++hop > 10)
-               return NULL;
-       res = snd_malloc_pages(size, GFP_KERNEL | (dma_mask <= 0x00ffffff ? GFP_DMA : 
0));
-       if (res == NULL)
-               return NULL;
-       if ((virt_to_bus(res) & ~dma_mask) ||
-           ((virt_to_bus(res) + size - 1) & ~dma_mask)) {
-               void *res1 = snd_pci_compat_alloc_consistent1(dma_mask, size, hop);
-               snd_free_pages(res, size);
-               return res1;
-       }
-       return res;
-}
-
-void *snd_pci_compat_alloc_consistent(struct pci_dev *dev,
-                                     long size,
-                                     dma_addr_t *dmaaddr)
-{
-       unsigned long dma_mask = snd_pci_compat_get_dma_mask(dev);
-       void *res = snd_pci_compat_alloc_consistent1(dma_mask, size, 0);
-       if (res != NULL)
-               *dmaaddr = (dma_addr_t)virt_to_bus(res);
-       return res;
-}
-
-void snd_pci_compat_free_consistent(struct pci_dev *dev, long size, void *ptr, 
dma_addr_t dmaaddr)
-{
-       if (bus_to_virt(dmaaddr) != ptr) {
-               printk(KERN_ERR "invalid address given %p != %lx to 
snd_pci_compat_free_consistent\n", ptr, (unsigned long)dmaaddr);
-               return;
-       }
-       snd_free_pages(ptr, size);
-}
-
 int snd_pci_compat_dma_supported(struct pci_dev *dev, dma_addr_t mask)
 {
        return 1;
@@ -396,3 +358,53 @@
        for (i = 0; i < 6; i++)
                snd_pci_compat_release_region(pdev, i);
 }
+
+#endif /* CONFIG_PCI */
+
+/* these functions are outside of CONFIG_PCI */
+
+static void *snd_pci_compat_alloc_consistent1(unsigned long dma_mask,
+                                             unsigned long size,
+                                             int hop)
+{
+       void *res;
+
+       if (++hop > 10)
+               return NULL;
+       res = snd_malloc_pages(size, GFP_KERNEL | (dma_mask <= 0x00ffffff ? GFP_DMA : 
0));
+       if (res == NULL)
+               return NULL;
+       if ((virt_to_bus(res) & ~dma_mask) ||
+           ((virt_to_bus(res) + size - 1) & ~dma_mask)) {
+               void *res1 = snd_pci_compat_alloc_consistent1(dma_mask, size, hop);
+               snd_free_pages(res, size);
+               return res1;
+       }
+       return res;
+}
+
+void *snd_pci_compat_alloc_consistent(struct pci_dev *dev,
+                                     long size,
+                                     dma_addr_t *dmaaddr)
+{
+       unsigned long dma_mask;
+#ifdef CONFIG_PCI
+       dma_mask = snd_pci_compat_get_dma_mask(dev);
+#else
+       dma_mask = 0xffffff; /* ISA - 16MB */
+#endif
+       void *res = snd_pci_compat_alloc_consistent1(dma_mask, size, 0);
+       if (res != NULL)
+               *dmaaddr = (dma_addr_t)virt_to_bus(res);
+       return res;
+}
+
+void snd_pci_compat_free_consistent(struct pci_dev *dev, long size, void *ptr, 
dma_addr_t dmaaddr)
+{
+       if (bus_to_virt(dmaaddr) != ptr) {
+               printk(KERN_ERR "invalid address given %p != %lx to 
snd_pci_compat_free_consistent\n", ptr, (unsigned long)dmaaddr);
+               return;
+       }
+       snd_free_pages(ptr, size);
+}
+

Index: sgbuf.c
===================================================================
RCS file: /cvsroot/alsa/alsa-driver/acore/sgbuf.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- sgbuf.c     3 Mar 2004 11:51:09 -0000       1.7
+++ sgbuf.c     6 Mar 2004 16:55:12 -0000       1.8
@@ -57,12 +57,8 @@
        unsigned int i;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0)
        unsigned long rmask;
-       if (sgbuf->dev.type == SNDRV_DMA_TYPE_PCI)
-               rmask = sgbuf->dev.dev.pci->dma_mask;
-       else if (sgbuf->dev.dev.dev->dma_mask)
-               rmask = *sgbuf->dev.dev.dev->dma_mask;
-       else
-               rmask = 0;
+       struct pci_dev *pci = (struct pci_dev *)sgbuf->dev.dev;
+       rmask = pci->dma_mask;
        if (rmask)
                rmask = ~rmask;
        else
@@ -146,10 +142,7 @@
                return NULL;
        memset(sgbuf, 0, sizeof(*sgbuf));
        sgbuf->dev = *dev;
-       if (dev->type == SNDRV_DMA_TYPE_PCI_SG)
-               sgbuf->dev.type = SNDRV_DMA_TYPE_PCI;
-       else
-               sgbuf->dev.type =SNDRV_DMA_TYPE_DEV;
+       sgbuf->dev.type = SNDRV_DMA_TYPE_DEV;
        pages = snd_sgbuf_aligned_pages(size);
        sgbuf->tblsize = sgbuf_align_table(pages);
        sgbuf->table = kmalloc(sizeof(*sgbuf->table) * sgbuf->tblsize, GFP_KERNEL);



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to