Update of /cvsroot/alsa/alsa-driver/acore In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18820/alsa-driver/acore
Modified Files: memalloc.inc memalloc.patch sgbuf.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: memalloc.inc =================================================================== RCS file: /cvsroot/alsa/alsa-driver/acore/memalloc.inc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- memalloc.inc 10 Nov 2003 17:32:37 -0000 1.2 +++ memalloc.inc 2 Mar 2004 15:32:35 -0000 1.3 @@ -26,3 +26,50 @@ return res; } #endif + +static LIST_HEAD(snd_pci_devices); + +struct snd_pci_device { + struct list_head *list; + struct device dev; + struct pci_dev *pci; +}; + +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; + pdev->dev.dma_mask = &pci->dma_mask; + return &pdev->dev; +} +EXPORT_SYMBOL(snd_kdevice_pci); + +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_kdevice_busid(struct device *dev) +{ + if (dev->d.pci) + return dev->d.pci->slot_name; + return "???"; +} Index: memalloc.patch =================================================================== RCS file: /cvsroot/alsa/alsa-driver/acore/memalloc.patch,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- memalloc.patch 19 Jan 2004 18:38:28 -0000 1.3 +++ memalloc.patch 2 Mar 2004 15:32:35 -0000 1.4 @@ -1,81 +1,69 @@ ---- ../../alsa-kernel/core/memalloc.c 2004-01-19 12:52:21.856491159 +0100 -+++ memalloc.c 2004-01-19 13:00:09.973519397 +0100 +--- memalloc.c.old 2004-03-02 11:09:58.000000000 +0100 ++++ memalloc.c 2004-03-02 11:09:17.000000000 +0100 @@ -1,3 +1,4 @@ +#include "memalloc.inc" /* * Copyright (c) by Jaroslav Kysela <[EMAIL PROTECTED]> * Takashi Iwai <[EMAIL PROTECTED]> -@@ -73,6 +74,7 @@ - #define snd_assert(expr, args...) /**/ +@@ -461,7 +462,7 @@ #endif - -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) #ifdef CONFIG_PCI - #if defined(__i386__) || defined(__ppc__) || defined(__x86_64__) - #define HACK_PCI_ALLOC_CONSISTENT -@@ -94,19 +96,31 @@ - dma_addr_t *dma_handle) - { - void *ret; -- u64 dma_mask, cdma_mask; -+ u64 dma_mask; -+#ifdef CONFIG_HAVE_PCI_CONSISTENT_DMA_MASK -+ u64 cdma_mask; -+#endif - unsigned long mask; - - if (hwdev == NULL) - return pci_alloc_consistent(hwdev, size, dma_handle); - dma_mask = hwdev->dma_mask; -+#ifdef CONFIG_HAVE_PCI_CONSISTENT_DMA_MASK - cdma_mask = hwdev->consistent_dma_mask; -- mask = (unsigned long)dma_mask && (unsigned long)cdma_mask; -+#endif -+ mask = (unsigned long)dma_mask; -+#ifdef CONFIG_HAVE_PCI_CONSISTENT_DMA_MASK -+ mask &= (unsigned long)cdma_mask; -+#endif - hwdev->dma_mask = 0xffffffff; /* do without masking */ -+#ifdef CONFIG_HAVE_PCI_CONSISTENT_DMA_MASK - hwdev->consistent_dma_mask = 0xffffffff; /* do without masking */ -+#endif - ret = pci_alloc_consistent(hwdev, size, dma_handle); - hwdev->dma_mask = dma_mask; /* restore */ -+#ifdef CONFIG_HAVE_PCI_CONSISTENT_DMA_MASK - hwdev->consistent_dma_mask = cdma_mask; /* restore */ -+#endif - if (ret) { - /* obtained address is out of range? */ - if (((unsigned long)*dma_handle + size - 1) & ~mask) { -@@ -128,6 +142,7 @@ - - #endif /* arch */ - #endif /* CONFIG_PCI */ -+#endif /* LINUX >= 2.4.0 */ - - - /* -@@ -623,7 +638,7 @@ + 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: +@@ -522,7 +523,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: +@@ -569,7 +570,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: +@@ -724,6 +725,7 @@ + kfree(mem); + } + up(&list_mutex); ++ snd_kdevice_free_all(); } --#if defined(__i386__) -+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) && defined(__i386__) - /* - * on ix86, we allocate a page with GFP_KERNEL to assure the - * allocation. the code is almost same with kernel/i386/pci-dma.c but -@@ -648,7 +663,7 @@ - dma_addr_t addr; - unsigned long mask; +@@ -771,7 +773,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; + } -- mask = pci ? (unsigned long)pci->consistent_dma_mask : 0x00ffffffUL; -+ mask = pci ? (unsigned long)pci->dma_mask : 0x00ffffffUL; - ptr = (void *)__get_free_page(GFP_KERNEL); - if (ptr) { - addr = virt_to_phys(ptr); -@@ -1012,3 +1027,5 @@ - EXPORT_SYMBOL(snd_malloc_sbus_pages_fallback); - EXPORT_SYMBOL(snd_free_sbus_pages); - #endif +@@ -873,7 +875,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); ++#else ++ snd_kdevice_busid(mem->dev.dev.dev)); ++#endif + } + break; + default: +@@ -950,3 +956,5 @@ + EXPORT_SYMBOL(snd_malloc_pages); + EXPORT_SYMBOL(snd_malloc_pages_fallback); + EXPORT_SYMBOL(snd_free_pages); + +#include "memalloc.inc1" Index: sgbuf.c =================================================================== RCS file: /cvsroot/alsa/alsa-driver/acore/sgbuf.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- sgbuf.c 10 Nov 2003 17:32:37 -0000 1.5 +++ sgbuf.c 2 Mar 2004 15:32:35 -0000 1.6 @@ -57,8 +57,8 @@ unsigned int i; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) unsigned long rmask; - if (sgbuf->pci) - rmask = ~((unsigned long)sgbuf->pci->dma_mask); + if (sgbuf->dev->dev.dev->dma_mask) + rmask = ~((unsigned long)(*sgbuf->dev->dev.dev->dma_mask)); else rmask = ~0xffffffUL; #endif @@ -107,7 +107,28 @@ vfree(vmaddr); /* don't use wrapper */ } -void *snd_malloc_sgbuf_pages(struct pci_dev *pci, size_t size, struct snd_dma_buffer *dmab) +int snd_free_sgbuf_pages(const struct snd_dma_device *dev, + struct snd_dma_buffer *dmab) +{ + struct snd_sg_buf *sgbuf = dmab->private_data; + + if (dmab->area) + release_vm_buffer(sgbuf, dmab->area); + dmab->area = NULL; + if (sgbuf->table) + kfree(sgbuf->table); + sgbuf->table = NULL; + if (sgbuf->page_table) + kfree(sgbuf->page_table); + kfree(sgbuf); + dmab->private_data = NULL; + + return 0; +} + +void *snd_malloc_sgbuf_pages(const struct snd_dma_device *dev, + size_t size, struct snd_dma_buffer *dmab, + size_t *res_size) { struct snd_sg_buf *sgbuf; unsigned int pages; @@ -118,7 +139,7 @@ if (! sgbuf) return NULL; memset(sgbuf, 0, sizeof(*sgbuf)); - sgbuf->pci = pci; + sgbuf->dev = dev; pages = snd_sgbuf_aligned_pages(size); sgbuf->tblsize = sgbuf_align_table(pages); sgbuf->table = kmalloc(sizeof(*sgbuf->table) * sgbuf->tblsize, GFP_KERNEL); @@ -149,26 +170,8 @@ return dmab->area; _failed: - snd_free_sgbuf_pages(dmab); /* free the table */ + snd_free_sgbuf_pages(dev, dmab); /* free the table */ return NULL; } -int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab) -{ - struct snd_sg_buf *sgbuf = dmab->private_data; - - if (dmab->area) - release_vm_buffer(sgbuf, dmab->area); - dmab->area = NULL; - if (sgbuf->table) - kfree(sgbuf->table); - sgbuf->table = NULL; - if (sgbuf->page_table) - kfree(sgbuf->page_table); - kfree(sgbuf); - dmab->private_data = NULL; - - return 0; -} - #endif /* < 2.5.0 */ ------------------------------------------------------- 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