24 #include <linux/module.h>
27 #include <linux/pci.h>
28 #include <linux/slab.h>
31 #include <asm/uaccess.h>
57 #define SNDRV_DMA_DEVICE_UNUSED (unsigned int)-1
65 static long snd_allocated_pages;
67 static inline void inc_snd_pages(
int order)
69 snd_allocated_pages += 1 <<
order;
72 static inline void dec_snd_pages(
int order)
74 snd_allocated_pages -= 1 <<
order;
126 #ifdef CONFIG_HAS_DMA
149 static void snd_free_dev_pages(
struct device *dev,
size_t size,
void *
ptr,
191 dmab->
dev.dev = device;
199 #ifdef CONFIG_HAS_DMA
201 dmab->
area = snd_malloc_dev_pages(device, size, &dmab->
addr);
204 #ifdef CONFIG_SND_DMA_SGBUF
248 if (size != aligned_size)
267 switch (dmab->
dev.type) {
271 #ifdef CONFIG_HAS_DMA
276 #ifdef CONFIG_SND_DMA_SGBUF
352 static void free_all_reserved_pages(
void)
358 while (! list_empty(&mem_list_head)) {
359 p = mem_list_head.
next;
369 #ifdef CONFIG_PROC_FS
373 #define SND_MEM_PROC_FILE "driver/snd-page-alloc"
381 static char *types[] = {
"UNKNOWN",
"CONT",
"DEV",
"DEV-SG" };
384 seq_printf(seq,
"pages : %li bytes (%li pages per %likB)\n",
385 pages *
PAGE_SIZE, pages, PAGE_SIZE / 1024);
389 seq_printf(seq,
"buffer %d : ID %08x : type %s\n",
390 devno, mem->
id, types[mem->
buffer.dev.type]);
391 seq_printf(seq,
" addr = 0x%lx, size = %d bytes\n",
392 (
unsigned long)mem->
buffer.addr,
406 #define gettoken(bufp) strsep(bufp, " \t\n")
409 size_t count, loff_t * ppos)
414 if (count >
sizeof(buf) - 1)
421 token = gettoken(&p);
422 if (! token || *token ==
'#')
424 if (
strcmp(token,
"add") == 0) {
431 if ((token = gettoken(&p)) ==
NULL ||
433 (token = gettoken(&p)) ==
NULL ||
435 (token = gettoken(&p)) ==
NULL ||
437 (token = gettoken(&p)) ==
NULL ||
438 (size =
memparse(token, &endp)) < 64*1024 ||
439 size > 16*1024*1024 ||
440 (token = gettoken(&p)) ==
NULL ||
452 if (mask > 0 && mask < 0xffffffff) {
453 if (pci_set_dma_mask(pci, mask) < 0 ||
454 pci_set_consistent_dma_mask(pci, mask) < 0) {
455 printk(
KERN_ERR "snd-page-alloc: cannot set DMA mask %lx for pci %04x:%04x\n", mask, vendor, device);
460 for (i = 0; i < buffers; i++) {
462 memset(&dmab, 0,
sizeof(dmab));
465 printk(
KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size);
474 for (i = 0; i < buffers; i++) {
476 memset(&dmab, 0,
sizeof(dmab));
482 printk(
KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size);
488 }
else if (
strcmp(token,
"erase") == 0)
490 free_all_reserved_pages();
499 .open = snd_mem_proc_open,
502 .write = snd_mem_proc_write,
514 static int __init snd_mem_init(
void)
516 #ifdef CONFIG_PROC_FS
517 snd_mem_proc = proc_create(SND_MEM_PROC_FILE, 0644,
NULL,
523 static void __exit snd_mem_exit(
void)
526 free_all_reserved_pages();
527 if (snd_allocated_pages > 0)
528 printk(
KERN_ERR "snd-malloc: Memory leak? pages not freed = %li\n", snd_allocated_pages);