2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Takashi Iwai <tiwai@suse.de>
5 * Generic memory allocators
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/config.h>
25 #include <linux/version.h>
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
31 #include <asm/semaphore.h>
32 #include <sound/memalloc.h>
35 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@suse.cz>");
36 MODULE_DESCRIPTION("Memory allocator for ALSA system.");
37 MODULE_LICENSE("GPL");
43 static int enable[8] = {[0 ... (SNDRV_CARDS-1)] = 1};
44 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
45 MODULE_PARM_DESC(enable, "Enable cards to allocate buffers.");
51 static DECLARE_MUTEX(list_mutex);
52 static LIST_HEAD(mem_list_head);
54 /* buffer preservation list */
56 struct snd_dma_device dev;
57 struct snd_dma_buffer buffer;
59 struct list_head list;
62 /* id for pre-allocated buffers */
63 #define SNDRV_DMA_DEVICE_UNUSED (unsigned int)-1
65 #ifdef CONFIG_SND_DEBUG
66 #define __ASTRING__(x) #x
67 #define snd_assert(expr, args...) do {\
69 printk(KERN_ERR "snd-malloc: BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
74 #define snd_assert(expr, args...) /**/
78 #if defined(__i386__) || defined(__ppc__) || defined(__x86_64__)
79 #define HACK_PCI_ALLOC_CONSISTENT
82 * A hack to allocate large buffers via pci_alloc_consistent()
84 * since pci_alloc_consistent always tries GFP_DMA when the requested
85 * pci memory region is below 32bit, it happens quite often that even
86 * 2 order of pages cannot be allocated.
88 * so in the following, we allocate at first without dma_mask, so that
89 * allocation will be done without GFP_DMA. if the area doesn't match
90 * with the requested region, then realloate with the original dma_mask
94 static void *snd_pci_hack_alloc_consistent(struct pci_dev *hwdev, size_t size,
95 dma_addr_t *dma_handle)
102 return pci_alloc_consistent(hwdev, size, dma_handle);
103 dma_mask = hwdev->dma_mask;
104 rmask = ~((unsigned long)dma_mask);
105 hwdev->dma_mask = 0xffffffff; /* do without masking */
106 ret = pci_alloc_consistent(hwdev, size, dma_handle);
107 hwdev->dma_mask = dma_mask; /* restore */
109 /* obtained address is out of range? */
110 if (((unsigned long)*dma_handle + size - 1) & rmask) {
111 /* reallocate with the proper mask */
112 pci_free_consistent(hwdev, size, ret, *dma_handle);
113 ret = pci_alloc_consistent(hwdev, size, dma_handle);
116 /* wish to success now with the proper mask... */
117 if (dma_mask != 0xffffffff)
118 ret = pci_alloc_consistent(hwdev, size, dma_handle);
123 /* redefine pci_alloc_consistent for some architectures */
124 #undef pci_alloc_consistent
125 #define pci_alloc_consistent snd_pci_hack_alloc_consistent
128 #endif /* CONFIG_PCI */
132 * compare the two devices
133 * returns non-zero if matched.
135 static int compare_device(const struct snd_dma_device *a, const struct snd_dma_device *b, int allow_unused)
137 if (a->type != b->type)
139 if (a->id != b->id) {
140 if (! allow_unused || (a->id != SNDRV_DMA_DEVICE_UNUSED && b->id != SNDRV_DMA_DEVICE_UNUSED))
144 case SNDRV_DMA_TYPE_CONTINUOUS:
146 case SNDRV_DMA_TYPE_ISA:
148 return a->dev.flags == b->dev.flags;
150 case SNDRV_DMA_TYPE_PCI:
151 case SNDRV_DMA_TYPE_PCI_SG:
152 return a->dev.pci == b->dev.pci;
155 case SNDRV_DMA_TYPE_SBUS:
156 return a->dev.sbus == b->dev.sbus;
163 * snd_dma_alloc_pages - allocate the buffer area according to the given type
164 * @dev: the buffer device info
165 * @size: the buffer size to allocate
166 * @dmab: buffer allocation record to store the allocated data
168 * Calls the memory-allocator function for the corresponding
171 * Returns zero if the buffer with the given size is allocated successfuly,
172 * other a negative value at error.
174 int snd_dma_alloc_pages(const struct snd_dma_device *dev, size_t size,
175 struct snd_dma_buffer *dmab)
177 snd_assert(dev != NULL, return -ENXIO);
178 snd_assert(size > 0, return -ENXIO);
179 snd_assert(dmab != NULL, return -ENXIO);
183 case SNDRV_DMA_TYPE_CONTINUOUS:
184 dmab->area = snd_malloc_pages(size, dev->dev.flags);
188 case SNDRV_DMA_TYPE_ISA:
189 dmab->area = snd_malloc_isa_pages(size, &dmab->addr);
193 case SNDRV_DMA_TYPE_PCI:
194 dmab->area = snd_malloc_pci_pages(dev->dev.pci, size, &dmab->addr);
196 case SNDRV_DMA_TYPE_PCI_SG:
197 snd_malloc_sgbuf_pages(dev->dev.pci, size, dmab);
201 case SNDRV_DMA_TYPE_SBUS:
202 dmab->area = snd_malloc_sbus_pages(dev->dev.sbus, size, &dmab->addr);
206 printk(KERN_ERR "snd-malloc: invalid device type %d\n", dev->type);
218 * snd_dma_free_pages - release the allocated buffer
219 * @dev: the buffer device info
220 * @dmbab: the buffer allocation record to release
222 * Releases the allocated buffer via snd_dma_alloc_pages().
224 void snd_dma_free_pages(const struct snd_dma_device *dev, struct snd_dma_buffer *dmab)
227 case SNDRV_DMA_TYPE_CONTINUOUS:
228 snd_free_pages(dmab->area, dmab->bytes);
231 case SNDRV_DMA_TYPE_ISA:
232 snd_free_isa_pages(dmab->bytes, dmab->area, dmab->addr);
236 case SNDRV_DMA_TYPE_PCI:
237 snd_free_pci_pages(dev->dev.pci, dmab->bytes, dmab->area, dmab->addr);
239 case SNDRV_DMA_TYPE_PCI_SG:
240 snd_free_sgbuf_pages(dmab);
244 case SNDRV_DMA_TYPE_SBUS:
245 snd_free_sbus_pages(dev->dev.sbus, dmab->bytes, dmab->area, dmab->addr);
249 printk(KERN_ERR "snd-malloc: invalid device type %d\n", dev->type);
255 * search for the device
257 static struct snd_mem_list *mem_list_find(const struct snd_dma_device *dev, int search_empty)
260 struct snd_mem_list *mem;
262 list_for_each(p, &mem_list_head) {
263 mem = list_entry(p, struct snd_mem_list, list);
264 if (mem->used && search_empty)
266 if (compare_device(&mem->dev, dev, search_empty))
273 * snd_dma_get_reserved - get the reserved buffer for the given device
274 * @dev: the buffer device info
275 * @dmab: the buffer allocation record to store
277 * Looks for the reserved-buffer list and re-uses if the same buffer
278 * is found in the list. When the buffer is found, it's marked as used.
279 * For unmarking the buffer, call snd_dma_free_reserved().
281 * Returns the size of buffer if the buffer is found, or zero if not found.
283 size_t snd_dma_get_reserved(const struct snd_dma_device *dev, struct snd_dma_buffer *dmab)
285 struct snd_mem_list *mem;
287 snd_assert(dev && dmab, return 0);
290 mem = mem_list_find(dev, 1);
303 * snd_dma_free_reserved - unmark the reserved buffer
304 * @dev: the buffer device info
306 * Looks for the matching reserved buffer and erases the mark on it
311 int snd_dma_free_reserved(const struct snd_dma_device *dev)
313 struct snd_mem_list *mem;
315 snd_assert(dev, return -EINVAL);
317 mem = mem_list_find(dev, 0);
325 * snd_dma_set_reserved - reserve the buffer
326 * @dev: the buffer device info
327 * @dmab: the buffer to reserve
329 * Reserves the given buffer as a reserved buffer.
330 * When an old reserved buffer already exists, the old one is released
331 * and replaced with the new one.
333 * When NULL buffer pointer or zero buffer size is given, the existing
334 * buffer is released and the entry is removed.
336 * Returns zero if successful, or a negative code at error.
338 int snd_dma_set_reserved(const struct snd_dma_device *dev, struct snd_dma_buffer *dmab)
340 struct snd_mem_list *mem;
342 snd_assert(dev, return -EINVAL);
344 mem = mem_list_find(dev, 0);
346 snd_dma_free_pages(dev, &mem->buffer);
347 if (! dmab || ! dmab->bytes) {
348 /* remove the entry */
349 list_del(&mem->list);
355 if (! dmab || ! dmab->bytes) {
359 mem = kmalloc(sizeof(*mem), GFP_KERNEL);
365 list_add(&mem->list, &mem_list_head);
367 /* store the entry */
375 * purge all reserved buffers
377 static void free_all_reserved_pages(void)
380 struct snd_mem_list *mem;
383 while (! list_empty(&mem_list_head)) {
384 p = mem_list_head.next;
385 mem = list_entry(p, struct snd_mem_list, list);
387 snd_dma_free_pages(&mem->dev, &mem->buffer);
396 * Generic memory allocators
400 static long snd_allocated_pages; /* holding the number of allocated pages */
402 static void mark_pages(void *res, int order)
404 struct page *page = virt_to_page(res);
405 struct page *last_page = page + (1 << order);
406 while (page < last_page)
407 SetPageReserved(page++);
408 snd_allocated_pages += 1 << order;
411 static void unmark_pages(void *res, int order)
413 struct page *page = virt_to_page(res);
414 struct page *last_page = page + (1 << order);
415 while (page < last_page)
416 ClearPageReserved(page++);
417 snd_allocated_pages -= 1 << order;
421 * snd_malloc_pages - allocate pages with the given size
422 * @size: the size to allocate in bytes
423 * @gfp_flags: the allocation conditions, GFP_XXX
425 * Allocates the physically contiguous pages with the given size.
427 * Returns the pointer of the buffer, or NULL if no enoguh memory.
429 void *snd_malloc_pages(size_t size, unsigned int gfp_flags)
434 snd_assert(size > 0, return NULL);
435 snd_assert(gfp_flags != 0, return NULL);
436 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
437 if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL) {
444 * snd_malloc_pages_fallback - allocate pages with the given size with fallback
445 * @size: the requested size to allocate in bytes
446 * @gfp_flags: the allocation conditions, GFP_XXX
447 * @res_size: the pointer to store the size of buffer actually allocated
449 * Allocates the physically contiguous pages with the given request
450 * size. When no space is left, this function reduces the size and
451 * tries to allocate again. The size actually allocated is stored in
454 * Returns the pointer of the buffer, or NULL if no enoguh memory.
456 void *snd_malloc_pages_fallback(size_t size, unsigned int gfp_flags, size_t *res_size)
460 snd_assert(size > 0, return NULL);
461 snd_assert(res_size != NULL, return NULL);
463 if ((res = snd_malloc_pages(size, gfp_flags)) != NULL) {
468 } while (size >= PAGE_SIZE);
473 * snd_free_pages - release the pages
474 * @ptr: the buffer pointer to release
475 * @size: the allocated buffer size
477 * Releases the buffer allocated via snd_malloc_pages().
479 void snd_free_pages(void *ptr, size_t size)
485 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
486 unmark_pages(ptr, pg);
487 free_pages((unsigned long) ptr, pg);
490 #if defined(CONFIG_ISA) && ! defined(CONFIG_PCI)
493 * snd_malloc_isa_pages - allocate pages for ISA bus with the given size
494 * @size: the size to allocate in bytes
495 * @dma_addr: the pointer to store the physical address of the buffer
497 * Allocates the physically contiguous pages with the given size for
500 * Returns the pointer of the buffer, or NULL if no enoguh memory.
502 void *snd_malloc_isa_pages(size_t size, dma_addr_t *dma_addr)
505 dma_area = snd_malloc_pages(size, GFP_ATOMIC|GFP_DMA);
506 *dma_addr = dma_area ? isa_virt_to_bus(dma_area) : 0UL;
511 * snd_malloc_isa_pages_fallback - allocate pages with the given size with fallback for ISA bus
512 * @size: the requested size to allocate in bytes
513 * @dma_addr: the pointer to store the physical address of the buffer
514 * @res_size: the pointer to store the size of buffer actually allocated
516 * Allocates the physically contiguous pages with the given request
517 * size for PCI bus. When no space is left, this function reduces the size and
518 * tries to allocate again. The size actually allocated is stored in
521 * Returns the pointer of the buffer, or NULL if no enoguh memory.
523 void *snd_malloc_isa_pages_fallback(size_t size,
524 dma_addr_t *dma_addr,
528 dma_area = snd_malloc_pages_fallback(size, GFP_ATOMIC|GFP_DMA, res_size);
529 *dma_addr = dma_area ? isa_virt_to_bus(dma_area) : 0UL;
533 #endif /* CONFIG_ISA && !CONFIG_PCI */
538 * snd_malloc_pci_pages - allocate pages for PCI bus with the given size
539 * @pci: the pci device pointer
540 * @size: the size to allocate in bytes
541 * @dma_addr: the pointer to store the physical address of the buffer
543 * Allocates the physically contiguous pages with the given size for
546 * Returns the pointer of the buffer, or NULL if no enoguh memory.
548 void *snd_malloc_pci_pages(struct pci_dev *pci,
550 dma_addr_t *dma_addr)
555 snd_assert(size > 0, return NULL);
556 snd_assert(dma_addr != NULL, return NULL);
557 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
558 res = pci_alloc_consistent(pci, PAGE_SIZE * (1 << pg), dma_addr);
566 * snd_malloc_pci_pages_fallback - allocate pages with the given size with fallback for PCI bus
567 * @pci: pci device pointer
568 * @size: the requested size to allocate in bytes
569 * @dma_addr: the pointer to store the physical address of the buffer
570 * @res_size: the pointer to store the size of buffer actually allocated
572 * Allocates the physically contiguous pages with the given request
573 * size for PCI bus. When no space is left, this function reduces the size and
574 * tries to allocate again. The size actually allocated is stored in
577 * Returns the pointer of the buffer, or NULL if no enoguh memory.
579 void *snd_malloc_pci_pages_fallback(struct pci_dev *pci,
581 dma_addr_t *dma_addr,
586 snd_assert(res_size != NULL, return NULL);
588 if ((res = snd_malloc_pci_pages(pci, size, dma_addr)) != NULL) {
593 } while (size >= PAGE_SIZE);
598 * snd_free_pci_pages - release the pages
599 * @pci: pci device pointer
600 * @size: the allocated buffer size
601 * @ptr: the buffer pointer to release
602 * @dma_addr: the physical address of the buffer
604 * Releases the buffer allocated via snd_malloc_pci_pages().
606 void snd_free_pci_pages(struct pci_dev *pci,
615 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
616 unmark_pages(ptr, pg);
617 pci_free_consistent(pci, PAGE_SIZE * (1 << pg), ptr, dma_addr);
621 #if defined(__i386__)
623 * on ix86, we allocate a page with GFP_KERNEL to assure the
624 * allocation. the code is almost same with kernel/i386/pci-dma.c but
625 * it allocates only a single page and checks the validity of the
626 * page address with the given pci dma mask.
630 * snd_malloc_pci_page - allocate a page in the valid pci dma mask
631 * @pci: pci device pointer
632 * @addrp: the pointer to store the physical address of the buffer
634 * Allocates a single page for the given PCI device and returns
635 * the virtual address and stores the physical address on addrp.
637 * This function cannot be called from interrupt handlers or
640 void *snd_malloc_pci_page(struct pci_dev *pci, dma_addr_t *addrp)
646 rmask = ~(unsigned long)(pci ? pci->dma_mask : 0x00ffffff);
647 ptr = (void *)__get_free_page(GFP_KERNEL);
649 addr = virt_to_phys(ptr);
650 if (((unsigned long)addr + PAGE_SIZE - 1) & rmask) {
651 /* try to reallocate with the GFP_DMA */
652 free_page((unsigned long)ptr);
653 /* use GFP_ATOMIC for the DMA zone to avoid stall */
654 ptr = (void *)__get_free_page(GFP_ATOMIC | GFP_DMA);
655 if (ptr) /* ok, the address must be within lower 16MB... */
656 addr = virt_to_phys(ptr);
663 memset(ptr, 0, PAGE_SIZE);
671 /* on other architectures, call snd_malloc_pci_pages() helper function
672 * which uses pci_alloc_consistent().
674 void *snd_malloc_pci_page(struct pci_dev *pci, dma_addr_t *addrp)
676 return snd_malloc_pci_pages(pci, PAGE_SIZE, addrp);
681 #if 0 /* for kernel-doc */
683 * snd_free_pci_page - release a page
684 * @pci: pci device pointer
685 * @ptr: the buffer pointer to release
686 * @dma_addr: the physical address of the buffer
688 * Releases the buffer allocated via snd_malloc_pci_page().
690 void snd_free_pci_page(struct pci_dev *pci, void *ptr, dma_addr_t dma_addr);
691 #endif /* for kernel-doc */
693 #endif /* CONFIG_PCI */
698 * snd_malloc_sbus_pages - allocate pages for SBUS with the given size
699 * @sdev: sbus device pointer
700 * @size: the size to allocate in bytes
701 * @dma_addr: the pointer to store the physical address of the buffer
703 * Allocates the physically contiguous pages with the given size for
706 * Returns the pointer of the buffer, or NULL if no enoguh memory.
708 void *snd_malloc_sbus_pages(struct sbus_dev *sdev,
710 dma_addr_t *dma_addr)
715 snd_assert(size > 0, return NULL);
716 snd_assert(dma_addr != NULL, return NULL);
717 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
718 res = sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr);
726 * snd_malloc_pci_pages_fallback - allocate pages with the given size with fallback for SBUS
727 * @sdev: sbus device pointer
728 * @size: the requested size to allocate in bytes
729 * @dma_addr: the pointer to store the physical address of the buffer
730 * @res_size: the pointer to store the size of buffer actually allocated
732 * Allocates the physically contiguous pages with the given request
733 * size for SBUS. When no space is left, this function reduces the size and
734 * tries to allocate again. The size actually allocated is stored in
737 * Returns the pointer of the buffer, or NULL if no enoguh memory.
739 void *snd_malloc_sbus_pages_fallback(struct sbus_dev *sdev,
741 dma_addr_t *dma_addr,
746 snd_assert(res_size != NULL, return NULL);
748 if ((res = snd_malloc_sbus_pages(sdev, size, dma_addr)) != NULL) {
753 } while (size >= PAGE_SIZE);
758 * snd_free_sbus_pages - release the pages
759 * @sdev: sbus device pointer
760 * @size: the allocated buffer size
761 * @ptr: the buffer pointer to release
762 * @dma_addr: the physical address of the buffer
764 * Releases the buffer allocated via snd_malloc_pci_pages().
766 void snd_free_sbus_pages(struct sbus_dev *sdev,
775 for (pg = 0; PAGE_SIZE * (1 << pg) < size; pg++);
776 unmark_pages(ptr, pg);
777 sbus_free_consistent(sdev, PAGE_SIZE * (1 << pg), ptr, dma_addr);
780 #endif /* CONFIG_SBUS */
784 * allocation of buffers for pre-defined devices
787 /* FIXME: for pci only - other bus? */
788 struct prealloc_dev {
789 unsigned short vendor;
790 unsigned short device;
791 unsigned long dma_mask;
793 unsigned int buffers;
796 #define HAMMERFALL_BUFFER_SIZE (16*1024*4*(26+1))
798 static struct prealloc_dev prealloc_devices[] __initdata = {
803 .dma_mask = 0xffffffff,
804 .size = HAMMERFALL_BUFFER_SIZE,
811 .dma_mask = 0xffffffff,
812 .size = HAMMERFALL_BUFFER_SIZE,
815 { }, /* terminator */
818 static void __init preallocate_cards(void)
820 struct pci_dev *pci = NULL;
825 while ((pci = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci)) != NULL) {
826 struct prealloc_dev *dev;
827 if (card >= SNDRV_CARDS)
829 for (dev = prealloc_devices; dev->vendor; dev++) {
831 if (dev->vendor != pci->vendor || dev->device != pci->device)
833 if (! enable[card++])
836 if (pci_set_dma_mask(pci, dev->dma_mask) < 0) {
837 printk(KERN_ERR "snd-page-alloc: cannot set DMA mask %lx for pci %04x:%04x\n", dev->dma_mask, dev->vendor, dev->device);
841 for (i = 0; i < dev->buffers; i++) {
842 struct snd_dma_device dma;
843 struct snd_dma_buffer buf;
844 snd_dma_device_pci(&dma, pci, SNDRV_DMA_DEVICE_UNUSED);
845 memset(&buf, 0, sizeof(buf));
846 snd_dma_alloc_pages(&dma, dev->size, &buf);
848 if (snd_dma_set_reserved(&dma, &buf) < 0) {
849 printk(KERN_WARNING "snd-page-alloc: cannot reserve buffer\n");
850 snd_dma_free_pages(&dma, &buf);
853 printk(KERN_WARNING "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", dev->size);
860 #ifdef CONFIG_PROC_FS
862 * proc file interface
864 static int snd_mem_proc_read(char *page, char **start, off_t off,
865 int count, int *eof, void *data)
868 long pages = snd_allocated_pages >> (PAGE_SHIFT-12);
870 struct snd_mem_list *mem;
874 len += sprintf(page + len, "pages : %li bytes (%li pages per %likB)\n",
875 pages * PAGE_SIZE, pages, PAGE_SIZE / 1024);
877 list_for_each(p, &mem_list_head) {
878 mem = list_entry(p, struct snd_mem_list, list);
880 len += sprintf(page + len, "buffer %d : ", devno);
881 if (mem->dev.id == SNDRV_DMA_DEVICE_UNUSED)
882 len += sprintf(page + len, "UNUSED");
884 len += sprintf(page + len, "ID %08x", mem->dev.id);
885 len += sprintf(page + len, " : type ");
886 switch (mem->dev.type) {
887 case SNDRV_DMA_TYPE_CONTINUOUS:
888 len += sprintf(page + len, "CONT [%x]", mem->dev.dev.flags);
891 case SNDRV_DMA_TYPE_PCI:
892 case SNDRV_DMA_TYPE_PCI_SG:
893 if (mem->dev.dev.pci) {
894 len += sprintf(page + len, "PCI [%04x:%04x]",
895 mem->dev.dev.pci->vendor,
896 mem->dev.dev.pci->device);
901 case SNDRV_DMA_TYPE_ISA:
902 len += sprintf(page + len, "ISA [%x]", mem->dev.dev.flags);
906 case SNDRV_DMA_TYPE_SBUS:
907 len += sprintf(page + len, "SBUS [%x]", mem->dev.dev.sbus->slot);
911 len += sprintf(page + len, "UNKNOWN");
914 len += sprintf(page + len, "\n addr = 0x%lx, size = %d bytes, used = %s\n",
915 (unsigned long)mem->buffer.addr, (int)mem->buffer.bytes,
916 mem->used ? "yes" : "no");
921 #endif /* CONFIG_PROC_FS */
927 static int __init snd_mem_init(void)
929 #ifdef CONFIG_PROC_FS
930 create_proc_read_entry("driver/snd-page-alloc", 0, 0, snd_mem_proc_read, NULL);
936 static void __exit snd_mem_exit(void)
938 remove_proc_entry("driver/snd-page-alloc", NULL);
939 free_all_reserved_pages();
940 if (snd_allocated_pages > 0)
941 printk(KERN_ERR "snd-malloc: Memory leak? pages not freed = %li\n", snd_allocated_pages);
945 module_init(snd_mem_init)
946 module_exit(snd_mem_exit)
951 /* format is: snd-page-alloc=enable */
953 static int __init snd_mem_setup(char *str)
955 static unsigned __initdata nr_dev = 0;
957 if (nr_dev >= SNDRV_CARDS)
959 (void)(get_option(&str,&enable[nr_dev]) == 2);
964 __setup("snd-page-alloc=", snd_mem_setup);
971 EXPORT_SYMBOL(snd_dma_alloc_pages);
972 EXPORT_SYMBOL(snd_dma_free_pages);
973 EXPORT_SYMBOL(snd_dma_get_reserved);
974 EXPORT_SYMBOL(snd_dma_free_reserved);
975 EXPORT_SYMBOL(snd_dma_set_reserved);
977 EXPORT_SYMBOL(snd_malloc_pages);
978 EXPORT_SYMBOL(snd_malloc_pages_fallback);
979 EXPORT_SYMBOL(snd_free_pages);
980 #if defined(CONFIG_ISA) && ! defined(CONFIG_PCI)
981 EXPORT_SYMBOL(snd_malloc_isa_pages);
982 EXPORT_SYMBOL(snd_malloc_isa_pages_fallback);
985 EXPORT_SYMBOL(snd_malloc_pci_pages);
986 EXPORT_SYMBOL(snd_malloc_pci_pages_fallback);
987 EXPORT_SYMBOL(snd_malloc_pci_page);
988 EXPORT_SYMBOL(snd_free_pci_pages);
989 EXPORT_SYMBOL(snd_malloc_sgbuf_pages);
990 EXPORT_SYMBOL(snd_free_sgbuf_pages);
993 EXPORT_SYMBOL(snd_malloc_sbus_pages);
994 EXPORT_SYMBOL(snd_malloc_sbus_pages_fallback);
995 EXPORT_SYMBOL(snd_free_sbus_pages);