blob: 3733351a27f218f7678dde1e16c4b151b7a470b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Takashi Iwai <tiwai@suse.de>
4 *
5 * Generic memory allocators
6 *
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/module.h>
25#include <linux/proc_fs.h>
26#include <linux/init.h>
27#include <linux/pci.h>
28#include <linux/slab.h>
29#include <linux/mm.h>
Takashi Iwaiccec6e22007-09-17 21:55:10 +020030#include <linux/seq_file.h>
Takashi Iwaib6a96912005-05-30 18:27:03 +020031#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/dma-mapping.h>
33#include <linux/moduleparam.h>
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010034#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <sound/memalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020038MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070039MODULE_DESCRIPTION("Memory allocator for ALSA system.");
40MODULE_LICENSE("GPL");
41
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/*
44 */
45
46void *snd_malloc_sgbuf_pages(struct device *device,
47 size_t size, struct snd_dma_buffer *dmab,
48 size_t *res_size);
49int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab);
50
51/*
52 */
53
Ingo Molnar1a60d4c2006-01-16 16:29:08 +010054static DEFINE_MUTEX(list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static LIST_HEAD(mem_list_head);
56
57/* buffer preservation list */
58struct snd_mem_list {
59 struct snd_dma_buffer buffer;
60 unsigned int id;
61 struct list_head list;
62};
63
64/* id for pre-allocated buffers */
65#define SNDRV_DMA_DEVICE_UNUSED (unsigned int)-1
66
67#ifdef CONFIG_SND_DEBUG
68#define __ASTRING__(x) #x
69#define snd_assert(expr, args...) do {\
70 if (!(expr)) {\
71 printk(KERN_ERR "snd-malloc: BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
72 args;\
73 }\
74} while (0)
75#else
76#define snd_assert(expr, args...) /**/
77#endif
78
79/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 *
81 * Generic memory allocators
82 *
83 */
84
85static long snd_allocated_pages; /* holding the number of allocated pages */
86
87static inline void inc_snd_pages(int order)
88{
89 snd_allocated_pages += 1 << order;
90}
91
92static inline void dec_snd_pages(int order)
93{
94 snd_allocated_pages -= 1 << order;
95}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/**
98 * snd_malloc_pages - allocate pages with the given size
99 * @size: the size to allocate in bytes
100 * @gfp_flags: the allocation conditions, GFP_XXX
101 *
102 * Allocates the physically contiguous pages with the given size.
103 *
104 * Returns the pointer of the buffer, or NULL if no enoguh memory.
105 */
Al Viro1ef64e62005-10-21 03:22:18 -0400106void *snd_malloc_pages(size_t size, gfp_t gfp_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 int pg;
109 void *res;
110
111 snd_assert(size > 0, return NULL);
112 snd_assert(gfp_flags != 0, return NULL);
Hugh Dickinsf3d48f02005-11-21 21:32:22 -0800113 gfp_flags |= __GFP_COMP; /* compound page lets parts be mapped */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 pg = get_order(size);
Takashi Iwai2ba8c152006-01-31 14:44:28 +0100115 if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 inc_snd_pages(pg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return res;
118}
119
120/**
121 * snd_free_pages - release the pages
122 * @ptr: the buffer pointer to release
123 * @size: the allocated buffer size
124 *
125 * Releases the buffer allocated via snd_malloc_pages().
126 */
127void snd_free_pages(void *ptr, size_t size)
128{
129 int pg;
130
131 if (ptr == NULL)
132 return;
133 pg = get_order(size);
134 dec_snd_pages(pg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 free_pages((unsigned long) ptr, pg);
136}
137
138/*
139 *
140 * Bus-specific memory allocators
141 *
142 */
143
Takashi Iwai8f115512007-07-26 18:59:36 +0200144#ifdef CONFIG_HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* allocate the coherent DMA pages */
146static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *dma)
147{
148 int pg;
149 void *res;
Al Viro1ef64e62005-10-21 03:22:18 -0400150 gfp_t gfp_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 snd_assert(size > 0, return NULL);
153 snd_assert(dma != NULL, return NULL);
154 pg = get_order(size);
155 gfp_flags = GFP_KERNEL
Hugh Dickinsf3d48f02005-11-21 21:32:22 -0800156 | __GFP_COMP /* compound page lets parts be mapped */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 | __GFP_NORETRY /* don't trigger OOM-killer */
158 | __GFP_NOWARN; /* no stack trace print - this call is non-critical */
159 res = dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags);
Takashi Iwai2ba8c152006-01-31 14:44:28 +0100160 if (res != NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 inc_snd_pages(pg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 return res;
164}
165
166/* free the coherent DMA pages */
167static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
168 dma_addr_t dma)
169{
170 int pg;
171
172 if (ptr == NULL)
173 return;
174 pg = get_order(size);
175 dec_snd_pages(pg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
177}
Takashi Iwai8f115512007-07-26 18:59:36 +0200178#endif /* CONFIG_HAS_DMA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/*
181 *
182 * ALSA generic memory management
183 *
184 */
185
186
187/**
188 * snd_dma_alloc_pages - allocate the buffer area according to the given type
189 * @type: the DMA buffer type
190 * @device: the device pointer
191 * @size: the buffer size to allocate
192 * @dmab: buffer allocation record to store the allocated data
193 *
194 * Calls the memory-allocator function for the corresponding
195 * buffer type.
196 *
197 * Returns zero if the buffer with the given size is allocated successfuly,
198 * other a negative value at error.
199 */
200int snd_dma_alloc_pages(int type, struct device *device, size_t size,
201 struct snd_dma_buffer *dmab)
202{
203 snd_assert(size > 0, return -ENXIO);
204 snd_assert(dmab != NULL, return -ENXIO);
205
206 dmab->dev.type = type;
207 dmab->dev.dev = device;
208 dmab->bytes = 0;
209 switch (type) {
210 case SNDRV_DMA_TYPE_CONTINUOUS:
211 dmab->area = snd_malloc_pages(size, (unsigned long)device);
212 dmab->addr = 0;
213 break;
Takashi Iwai8f115512007-07-26 18:59:36 +0200214#ifdef CONFIG_HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 case SNDRV_DMA_TYPE_DEV:
216 dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
217 break;
218 case SNDRV_DMA_TYPE_DEV_SG:
219 snd_malloc_sgbuf_pages(device, size, dmab, NULL);
220 break;
Takashi Iwai8f115512007-07-26 18:59:36 +0200221#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 default:
223 printk(KERN_ERR "snd-malloc: invalid device type %d\n", type);
224 dmab->area = NULL;
225 dmab->addr = 0;
226 return -ENXIO;
227 }
228 if (! dmab->area)
229 return -ENOMEM;
230 dmab->bytes = size;
231 return 0;
232}
233
234/**
235 * snd_dma_alloc_pages_fallback - allocate the buffer area according to the given type with fallback
236 * @type: the DMA buffer type
237 * @device: the device pointer
238 * @size: the buffer size to allocate
239 * @dmab: buffer allocation record to store the allocated data
240 *
241 * Calls the memory-allocator function for the corresponding
242 * buffer type. When no space is left, this function reduces the size and
243 * tries to allocate again. The size actually allocated is stored in
244 * res_size argument.
245 *
246 * Returns zero if the buffer with the given size is allocated successfuly,
247 * other a negative value at error.
248 */
249int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size,
250 struct snd_dma_buffer *dmab)
251{
252 int err;
253
254 snd_assert(size > 0, return -ENXIO);
255 snd_assert(dmab != NULL, return -ENXIO);
256
257 while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
258 if (err != -ENOMEM)
259 return err;
260 size >>= 1;
261 if (size <= PAGE_SIZE)
262 return -ENOMEM;
263 }
264 if (! dmab->area)
265 return -ENOMEM;
266 return 0;
267}
268
269
270/**
271 * snd_dma_free_pages - release the allocated buffer
272 * @dmab: the buffer allocation record to release
273 *
274 * Releases the allocated buffer via snd_dma_alloc_pages().
275 */
276void snd_dma_free_pages(struct snd_dma_buffer *dmab)
277{
278 switch (dmab->dev.type) {
279 case SNDRV_DMA_TYPE_CONTINUOUS:
280 snd_free_pages(dmab->area, dmab->bytes);
281 break;
Takashi Iwai8f115512007-07-26 18:59:36 +0200282#ifdef CONFIG_HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 case SNDRV_DMA_TYPE_DEV:
284 snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
285 break;
286 case SNDRV_DMA_TYPE_DEV_SG:
287 snd_free_sgbuf_pages(dmab);
288 break;
Takashi Iwai8f115512007-07-26 18:59:36 +0200289#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 default:
291 printk(KERN_ERR "snd-malloc: invalid device type %d\n", dmab->dev.type);
292 }
293}
294
295
296/**
297 * snd_dma_get_reserved - get the reserved buffer for the given device
298 * @dmab: the buffer allocation record to store
299 * @id: the buffer id
300 *
301 * Looks for the reserved-buffer list and re-uses if the same buffer
302 * is found in the list. When the buffer is found, it's removed from the free list.
303 *
304 * Returns the size of buffer if the buffer is found, or zero if not found.
305 */
306size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id)
307{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 struct snd_mem_list *mem;
309
310 snd_assert(dmab, return 0);
311
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100312 mutex_lock(&list_mutex);
Johannes Berg9244b2c2006-10-05 16:02:22 +0200313 list_for_each_entry(mem, &mem_list_head, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 if (mem->id == id &&
Takashi Iwaib6a96912005-05-30 18:27:03 +0200315 (mem->buffer.dev.dev == NULL || dmab->dev.dev == NULL ||
316 ! memcmp(&mem->buffer.dev, &dmab->dev, sizeof(dmab->dev)))) {
317 struct device *dev = dmab->dev.dev;
Johannes Berg9244b2c2006-10-05 16:02:22 +0200318 list_del(&mem->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 *dmab = mem->buffer;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200320 if (dmab->dev.dev == NULL)
321 dmab->dev.dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 kfree(mem);
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100323 mutex_unlock(&list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return dmab->bytes;
325 }
326 }
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100327 mutex_unlock(&list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 return 0;
329}
330
331/**
332 * snd_dma_reserve_buf - reserve the buffer
333 * @dmab: the buffer to reserve
334 * @id: the buffer id
335 *
336 * Reserves the given buffer as a reserved buffer.
337 *
338 * Returns zero if successful, or a negative code at error.
339 */
340int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id)
341{
342 struct snd_mem_list *mem;
343
344 snd_assert(dmab, return -EINVAL);
345 mem = kmalloc(sizeof(*mem), GFP_KERNEL);
346 if (! mem)
347 return -ENOMEM;
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100348 mutex_lock(&list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 mem->buffer = *dmab;
350 mem->id = id;
351 list_add_tail(&mem->list, &mem_list_head);
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100352 mutex_unlock(&list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return 0;
354}
355
356/*
357 * purge all reserved buffers
358 */
359static void free_all_reserved_pages(void)
360{
361 struct list_head *p;
362 struct snd_mem_list *mem;
363
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100364 mutex_lock(&list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 while (! list_empty(&mem_list_head)) {
366 p = mem_list_head.next;
367 mem = list_entry(p, struct snd_mem_list, list);
368 list_del(p);
369 snd_dma_free_pages(&mem->buffer);
370 kfree(mem);
371 }
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100372 mutex_unlock(&list_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#ifdef CONFIG_PROC_FS
377/*
378 * proc file interface
379 */
Takashi Iwaib6a96912005-05-30 18:27:03 +0200380#define SND_MEM_PROC_FILE "driver/snd-page-alloc"
Clemens Ladischa53fc182005-08-11 15:59:17 +0200381static struct proc_dir_entry *snd_mem_proc;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200382
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200383static int snd_mem_proc_read(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 long pages = snd_allocated_pages >> (PAGE_SHIFT-12);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 struct snd_mem_list *mem;
387 int devno;
David S. Miller759ee812008-08-27 00:33:26 -0700388 static char *types[] = { "UNKNOWN", "CONT", "DEV", "DEV-SG" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100390 mutex_lock(&list_mutex);
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200391 seq_printf(seq, "pages : %li bytes (%li pages per %likB)\n",
392 pages * PAGE_SIZE, pages, PAGE_SIZE / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 devno = 0;
Johannes Berg9244b2c2006-10-05 16:02:22 +0200394 list_for_each_entry(mem, &mem_list_head, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 devno++;
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200396 seq_printf(seq, "buffer %d : ID %08x : type %s\n",
397 devno, mem->id, types[mem->buffer.dev.type]);
398 seq_printf(seq, " addr = 0x%lx, size = %d bytes\n",
399 (unsigned long)mem->buffer.addr,
400 (int)mem->buffer.bytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
Ingo Molnar1a60d4c2006-01-16 16:29:08 +0100402 mutex_unlock(&list_mutex);
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200403 return 0;
404}
405
406static int snd_mem_proc_open(struct inode *inode, struct file *file)
407{
408 return single_open(file, snd_mem_proc_read, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
Takashi Iwaib6a96912005-05-30 18:27:03 +0200410
411/* FIXME: for pci only - other bus? */
412#ifdef CONFIG_PCI
413#define gettoken(bufp) strsep(bufp, " \t\n")
414
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200415static ssize_t snd_mem_proc_write(struct file *file, const char __user * buffer,
416 size_t count, loff_t * ppos)
Takashi Iwaib6a96912005-05-30 18:27:03 +0200417{
418 char buf[128];
419 char *token, *p;
420
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200421 if (count > sizeof(buf) - 1)
422 return -EINVAL;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200423 if (copy_from_user(buf, buffer, count))
424 return -EFAULT;
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200425 buf[count] = '\0';
Takashi Iwaib6a96912005-05-30 18:27:03 +0200426
427 p = buf;
428 token = gettoken(&p);
429 if (! token || *token == '#')
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200430 return count;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200431 if (strcmp(token, "add") == 0) {
432 char *endp;
433 int vendor, device, size, buffers;
434 long mask;
435 int i, alloced;
436 struct pci_dev *pci;
437
438 if ((token = gettoken(&p)) == NULL ||
439 (vendor = simple_strtol(token, NULL, 0)) <= 0 ||
440 (token = gettoken(&p)) == NULL ||
441 (device = simple_strtol(token, NULL, 0)) <= 0 ||
442 (token = gettoken(&p)) == NULL ||
443 (mask = simple_strtol(token, NULL, 0)) < 0 ||
444 (token = gettoken(&p)) == NULL ||
445 (size = memparse(token, &endp)) < 64*1024 ||
446 size > 16*1024*1024 /* too big */ ||
447 (token = gettoken(&p)) == NULL ||
448 (buffers = simple_strtol(token, NULL, 0)) <= 0 ||
449 buffers > 4) {
450 printk(KERN_ERR "snd-page-alloc: invalid proc write format\n");
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200451 return count;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200452 }
453 vendor &= 0xffff;
454 device &= 0xffff;
455
456 alloced = 0;
457 pci = NULL;
Jiri Slaby0dd119f2005-09-07 14:28:33 +0200458 while ((pci = pci_get_device(vendor, device, pci)) != NULL) {
Takashi Iwaib6a96912005-05-30 18:27:03 +0200459 if (mask > 0 && mask < 0xffffffff) {
460 if (pci_set_dma_mask(pci, mask) < 0 ||
461 pci_set_consistent_dma_mask(pci, mask) < 0) {
462 printk(KERN_ERR "snd-page-alloc: cannot set DMA mask %lx for pci %04x:%04x\n", mask, vendor, device);
Julia Lawalldf1deb62007-11-28 11:58:56 +0100463 pci_dev_put(pci);
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200464 return count;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200465 }
466 }
467 for (i = 0; i < buffers; i++) {
468 struct snd_dma_buffer dmab;
469 memset(&dmab, 0, sizeof(dmab));
470 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
471 size, &dmab) < 0) {
472 printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size);
Jiri Slaby0dd119f2005-09-07 14:28:33 +0200473 pci_dev_put(pci);
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200474 return count;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200475 }
476 snd_dma_reserve_buf(&dmab, snd_dma_pci_buf_id(pci));
477 }
478 alloced++;
479 }
480 if (! alloced) {
481 for (i = 0; i < buffers; i++) {
482 struct snd_dma_buffer dmab;
483 memset(&dmab, 0, sizeof(dmab));
484 /* FIXME: We can allocate only in ZONE_DMA
485 * without a device pointer!
486 */
487 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, NULL,
488 size, &dmab) < 0) {
489 printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size);
490 break;
491 }
492 snd_dma_reserve_buf(&dmab, (unsigned int)((vendor << 16) | device));
493 }
494 }
495 } else if (strcmp(token, "erase") == 0)
496 /* FIXME: need for releasing each buffer chunk? */
497 free_all_reserved_pages();
498 else
499 printk(KERN_ERR "snd-page-alloc: invalid proc cmd\n");
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200500 return count;
Takashi Iwaib6a96912005-05-30 18:27:03 +0200501}
502#endif /* CONFIG_PCI */
Takashi Iwaiccec6e22007-09-17 21:55:10 +0200503
504static const struct file_operations snd_mem_proc_fops = {
505 .owner = THIS_MODULE,
506 .open = snd_mem_proc_open,
507 .read = seq_read,
508#ifdef CONFIG_PCI
509 .write = snd_mem_proc_write,
510#endif
511 .llseek = seq_lseek,
512 .release = single_release,
513};
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#endif /* CONFIG_PROC_FS */
516
517/*
518 * module entry
519 */
520
521static int __init snd_mem_init(void)
522{
523#ifdef CONFIG_PROC_FS
Denis V. Lunev7bf4e6d2008-04-29 01:02:13 -0700524 snd_mem_proc = proc_create(SND_MEM_PROC_FILE, 0644, NULL,
525 &snd_mem_proc_fops);
Takashi Iwaib6a96912005-05-30 18:27:03 +0200526#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return 0;
528}
529
530static void __exit snd_mem_exit(void)
531{
Takashi Iwaie0be4d32005-08-23 11:11:03 +0200532 remove_proc_entry(SND_MEM_PROC_FILE, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 free_all_reserved_pages();
534 if (snd_allocated_pages > 0)
535 printk(KERN_ERR "snd-malloc: Memory leak? pages not freed = %li\n", snd_allocated_pages);
536}
537
538
539module_init(snd_mem_init)
540module_exit(snd_mem_exit)
541
542
543/*
544 * exports
545 */
546EXPORT_SYMBOL(snd_dma_alloc_pages);
547EXPORT_SYMBOL(snd_dma_alloc_pages_fallback);
548EXPORT_SYMBOL(snd_dma_free_pages);
549
550EXPORT_SYMBOL(snd_dma_get_reserved_buf);
551EXPORT_SYMBOL(snd_dma_reserve_buf);
552
553EXPORT_SYMBOL(snd_malloc_pages);
554EXPORT_SYMBOL(snd_free_pages);