Update of /cvsroot/alsa/alsa-kernel/core
In directory sc8-pr-cvs1:/tmp/cvs-serv32183/core

Modified Files:
        memory.c pcm_sgbuf.c sound.c 
Log Message:
[PATCH: pci-alloc-page.dif]

- added snd_malloc_pci_page() and snd_free_pci_page() functions to
  allocate a single page on the pci.



Index: memory.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/memory.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- memory.c    7 Jan 2003 12:27:45 -0000       1.23
+++ memory.c    8 Jan 2003 11:24:48 -0000       1.24
@@ -695,3 +695,81 @@
        return 0;
 #endif
 }
+
+
+#ifdef CONFIG_PCI
+
+#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
+ * it allocates only a single page and checks the validity of the
+ * page address with the given pci dma mask.
+ */
+
+/**
+ * snd_malloc_pci_page - allocate a page in the valid pci dma mask
+ * @pci: pci device pointer
+ * @addrp: the pointer to store the physical address of the buffer
+ *
+ * Allocates a single page for the given PCI device and returns
+ * the virtual address and stores the physical address on addrp.
+ * 
+ * This function cannot be called from interrupt handlers or
+ * within spinlocks.
+ */
+void *snd_malloc_pci_page(struct pci_dev *pci, dma_addr_t *addrp)
+{
+       void *ptr;
+       dma_addr_t addr;
+       unsigned long rmask;
+
+       rmask = ~(unsigned long)(pci ? pci->dma_mask : 0x00ffffff);
+       ptr = (void *)__get_free_page(GFP_KERNEL);
+       if (ptr) {
+               addr = virt_to_phys(ptr);
+               if (((unsigned long)addr + PAGE_SIZE - 1) & rmask) {
+                       /* try to reallocate with the GFP_DMA */
+                       free_page((unsigned long)ptr);
+                       ptr = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
+                       if (ptr) /* ok, the address must be within lower 16MB... */
+                               addr = virt_to_phys(ptr);
+                       else
+                               addr = 0;
+               }
+       } else
+               addr = 0;
+       if (ptr) {
+               struct page *page = virt_to_page(ptr);
+               memset(ptr, 0, PAGE_SIZE);
+               SetPageReserved(page);
+#ifdef CONFIG_SND_DEBUG_MEMORY
+               snd_alloc_pages++;
+#endif
+       }
+       *addrp = addr;
+       return ptr;
+}
+#else
+/* on other architectures, call snd_malloc_pci_pages() helper function
+ * which uses pci_alloc_consistent().
+ */
+void *snd_malloc_pci_page(struct pci_dev *pci, dma_addr_t *addrp)
+{
+       return snd_malloc_pci_pages(pci, PAGE_SIZE, addrp);
+}
+#endif /* 2.4 && i386 */
+
+#if 0 /* for kernel-doc */
+/**
+ * snd_free_pci_page - release a page
+ * @pci: pci device pointer
+ * @ptr: the buffer pointer to release
+ * @dma_addr: the physical address of the buffer
+ *
+ * Releases the buffer allocated via snd_malloc_pci_page().
+ */
+void snd_free_pci_page(struct pci_dev *pci, void *ptr, dma_addr_t dma_addr);
+#endif /* for kernel-doc */
+
+#endif /* CONFIG_PCI */

Index: pcm_sgbuf.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/pcm_sgbuf.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- pcm_sgbuf.c 7 Jan 2003 12:27:46 -0000       1.8
+++ pcm_sgbuf.c 8 Jan 2003 11:24:48 -0000       1.9
@@ -41,8 +41,7 @@
                return;
        while (sgbuf->pages > pages) {
                sgbuf->pages--;
-               snd_free_pci_pages(sgbuf->pci, PAGE_SIZE,
-                                  sgbuf->table[sgbuf->pages].buf,
+               snd_free_pci_page(sgbuf->pci, sgbuf->table[sgbuf->pages].buf,
                                   sgbuf->table[sgbuf->pages].addr);
        }
 }
@@ -108,56 +107,6 @@
        return 0;
 }
 
-/*
- * snd_pci_alloc_page - allocate a page in the valid pci dma mask
- *
- * returns the virtual address and stores the physical address on
- * addrp.  this function cannot be called from interrupt handlers or
- * within spinlocks.
- */
-#ifdef __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
- * it allocates only a single page and checkes the validity of the
- * page address with the given pci dma mask.
- */
-inline static void *snd_pci_alloc_page(struct pci_dev *pci, dma_addr_t *addrp)
-{
-       void *ptr;
-       dma_addr_t addr;
-       unsigned long rmask;
-
-       if (pci)
-               rmask = ~(unsigned long)pci->dma_mask;
-       else
-               rmask = 0;
-       ptr = (void *)__get_free_page(GFP_KERNEL);
-       if (ptr) {
-               addr = virt_to_phys(ptr);
-               if (((unsigned long)addr + PAGE_SIZE - 1) & rmask) {
-                       /* try to reallocate with the GFP_DMA */
-                       free_page((unsigned long)ptr);
-                       ptr = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
-                       if (ptr) /* ok, the address must be within lower 16MB... */
-                               addr = virt_to_phys(ptr);
-                       else
-                               addr = 0;
-               }
-       } else
-               addr = 0;
-       if (ptr)
-               memset(ptr, 0, PAGE_SIZE);
-       *addrp = addr;
-       return ptr;
-}
-#else
-/* on other architectures, call snd_malloc_pci_pages() helper function
- * which uses pci_alloc_consistent().
- */
-#define snd_pci_alloc_page(pci, addrp) snd_malloc_pci_pages(pci, PAGE_SIZE, addrp)
-#endif
-
 /**
  * snd_pcm_sgbuf_alloc - allocate the pages for the SG buffer
  * @substream: the pcm substream instance
@@ -203,7 +152,7 @@
        while (sgbuf->pages < pages) {
                void *ptr;
                dma_addr_t addr;
-               ptr = snd_pci_alloc_page(sgbuf->pci, &addr);
+               ptr = snd_malloc_pci_page(sgbuf->pci, &addr);
                if (! ptr)
                        return -ENOMEM;
                sgbuf->table[sgbuf->pages].buf = ptr;

Index: sound.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/sound.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- sound.c     7 Jan 2003 12:27:46 -0000       1.32
+++ sound.c     8 Jan 2003 11:24:48 -0000       1.33
@@ -442,6 +442,7 @@
 #ifdef CONFIG_PCI
 EXPORT_SYMBOL(snd_malloc_pci_pages);
 EXPORT_SYMBOL(snd_malloc_pci_pages_fallback);
+EXPORT_SYMBOL(snd_malloc_pci_page);
 EXPORT_SYMBOL(snd_free_pci_pages);
 #endif
 #ifdef CONFIG_SBUS



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to