memalloc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * 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. #include <linux/module.h>
  24. #include <linux/proc_fs.h>
  25. #include <linux/init.h>
  26. #include <linux/pci.h>
  27. #include <linux/slab.h>
  28. #include <linux/mm.h>
  29. #include <linux/seq_file.h>
  30. #include <asm/uaccess.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/mutex.h>
  34. #include <sound/memalloc.h>
  35. #ifdef CONFIG_SBUS
  36. #include <asm/sbus.h>
  37. #endif
  38. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@perex.cz>");
  39. MODULE_DESCRIPTION("Memory allocator for ALSA system.");
  40. MODULE_LICENSE("GPL");
  41. /*
  42. */
  43. void *snd_malloc_sgbuf_pages(struct device *device,
  44. size_t size, struct snd_dma_buffer *dmab,
  45. size_t *res_size);
  46. int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab);
  47. /*
  48. */
  49. static DEFINE_MUTEX(list_mutex);
  50. static LIST_HEAD(mem_list_head);
  51. /* buffer preservation list */
  52. struct snd_mem_list {
  53. struct snd_dma_buffer buffer;
  54. unsigned int id;
  55. struct list_head list;
  56. };
  57. /* id for pre-allocated buffers */
  58. #define SNDRV_DMA_DEVICE_UNUSED (unsigned int)-1
  59. #ifdef CONFIG_SND_DEBUG
  60. #define __ASTRING__(x) #x
  61. #define snd_assert(expr, args...) do {\
  62. if (!(expr)) {\
  63. printk(KERN_ERR "snd-malloc: BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
  64. args;\
  65. }\
  66. } while (0)
  67. #else
  68. #define snd_assert(expr, args...) /**/
  69. #endif
  70. /*
  71. * Hacks
  72. */
  73. #if defined(__i386__)
  74. /*
  75. * A hack to allocate large buffers via dma_alloc_coherent()
  76. *
  77. * since dma_alloc_coherent always tries GFP_DMA when the requested
  78. * pci memory region is below 32bit, it happens quite often that even
  79. * 2 order of pages cannot be allocated.
  80. *
  81. * so in the following, we allocate at first without dma_mask, so that
  82. * allocation will be done without GFP_DMA. if the area doesn't match
  83. * with the requested region, then realloate with the original dma_mask
  84. * again.
  85. *
  86. * Really, we want to move this type of thing into dma_alloc_coherent()
  87. * so dma_mask doesn't have to be messed with.
  88. */
  89. static void *snd_dma_hack_alloc_coherent(struct device *dev, size_t size,
  90. dma_addr_t *dma_handle,
  91. gfp_t flags)
  92. {
  93. void *ret;
  94. u64 dma_mask, coherent_dma_mask;
  95. if (dev == NULL || !dev->dma_mask)
  96. return dma_alloc_coherent(dev, size, dma_handle, flags);
  97. dma_mask = *dev->dma_mask;
  98. coherent_dma_mask = dev->coherent_dma_mask;
  99. *dev->dma_mask = 0xffffffff; /* do without masking */
  100. dev->coherent_dma_mask = 0xffffffff; /* do without masking */
  101. ret = dma_alloc_coherent(dev, size, dma_handle, flags);
  102. *dev->dma_mask = dma_mask; /* restore */
  103. dev->coherent_dma_mask = coherent_dma_mask; /* restore */
  104. if (ret) {
  105. /* obtained address is out of range? */
  106. if (((unsigned long)*dma_handle + size - 1) & ~dma_mask) {
  107. /* reallocate with the proper mask */
  108. dma_free_coherent(dev, size, ret, *dma_handle);
  109. ret = dma_alloc_coherent(dev, size, dma_handle, flags);
  110. }
  111. } else {
  112. /* wish to success now with the proper mask... */
  113. if (dma_mask != 0xffffffffUL) {
  114. /* allocation with GFP_ATOMIC to avoid the long stall */
  115. flags &= ~GFP_KERNEL;
  116. flags |= GFP_ATOMIC;
  117. ret = dma_alloc_coherent(dev, size, dma_handle, flags);
  118. }
  119. }
  120. return ret;
  121. }
  122. /* redefine dma_alloc_coherent for some architectures */
  123. #undef dma_alloc_coherent
  124. #define dma_alloc_coherent snd_dma_hack_alloc_coherent
  125. #endif /* arch */
  126. /*
  127. *
  128. * Generic memory allocators
  129. *
  130. */
  131. static long snd_allocated_pages; /* holding the number of allocated pages */
  132. static inline void inc_snd_pages(int order)
  133. {
  134. snd_allocated_pages += 1 << order;
  135. }
  136. static inline void dec_snd_pages(int order)
  137. {
  138. snd_allocated_pages -= 1 << order;
  139. }
  140. /**
  141. * snd_malloc_pages - allocate pages with the given size
  142. * @size: the size to allocate in bytes
  143. * @gfp_flags: the allocation conditions, GFP_XXX
  144. *
  145. * Allocates the physically contiguous pages with the given size.
  146. *
  147. * Returns the pointer of the buffer, or NULL if no enoguh memory.
  148. */
  149. void *snd_malloc_pages(size_t size, gfp_t gfp_flags)
  150. {
  151. int pg;
  152. void *res;
  153. snd_assert(size > 0, return NULL);
  154. snd_assert(gfp_flags != 0, return NULL);
  155. gfp_flags |= __GFP_COMP; /* compound page lets parts be mapped */
  156. pg = get_order(size);
  157. if ((res = (void *) __get_free_pages(gfp_flags, pg)) != NULL)
  158. inc_snd_pages(pg);
  159. return res;
  160. }
  161. /**
  162. * snd_free_pages - release the pages
  163. * @ptr: the buffer pointer to release
  164. * @size: the allocated buffer size
  165. *
  166. * Releases the buffer allocated via snd_malloc_pages().
  167. */
  168. void snd_free_pages(void *ptr, size_t size)
  169. {
  170. int pg;
  171. if (ptr == NULL)
  172. return;
  173. pg = get_order(size);
  174. dec_snd_pages(pg);
  175. free_pages((unsigned long) ptr, pg);
  176. }
  177. /*
  178. *
  179. * Bus-specific memory allocators
  180. *
  181. */
  182. #ifdef CONFIG_HAS_DMA
  183. /* allocate the coherent DMA pages */
  184. static void *snd_malloc_dev_pages(struct device *dev, size_t size, dma_addr_t *dma)
  185. {
  186. int pg;
  187. void *res;
  188. gfp_t gfp_flags;
  189. snd_assert(size > 0, return NULL);
  190. snd_assert(dma != NULL, return NULL);
  191. pg = get_order(size);
  192. gfp_flags = GFP_KERNEL
  193. | __GFP_COMP /* compound page lets parts be mapped */
  194. | __GFP_NORETRY /* don't trigger OOM-killer */
  195. | __GFP_NOWARN; /* no stack trace print - this call is non-critical */
  196. res = dma_alloc_coherent(dev, PAGE_SIZE << pg, dma, gfp_flags);
  197. if (res != NULL)
  198. inc_snd_pages(pg);
  199. return res;
  200. }
  201. /* free the coherent DMA pages */
  202. static void snd_free_dev_pages(struct device *dev, size_t size, void *ptr,
  203. dma_addr_t dma)
  204. {
  205. int pg;
  206. if (ptr == NULL)
  207. return;
  208. pg = get_order(size);
  209. dec_snd_pages(pg);
  210. dma_free_coherent(dev, PAGE_SIZE << pg, ptr, dma);
  211. }
  212. #endif /* CONFIG_HAS_DMA */
  213. #ifdef CONFIG_SBUS
  214. static void *snd_malloc_sbus_pages(struct device *dev, size_t size,
  215. dma_addr_t *dma_addr)
  216. {
  217. struct sbus_dev *sdev = (struct sbus_dev *)dev;
  218. int pg;
  219. void *res;
  220. snd_assert(size > 0, return NULL);
  221. snd_assert(dma_addr != NULL, return NULL);
  222. pg = get_order(size);
  223. res = sbus_alloc_consistent(sdev, PAGE_SIZE * (1 << pg), dma_addr);
  224. if (res != NULL)
  225. inc_snd_pages(pg);
  226. return res;
  227. }
  228. static void snd_free_sbus_pages(struct device *dev, size_t size,
  229. void *ptr, dma_addr_t dma_addr)
  230. {
  231. struct sbus_dev *sdev = (struct sbus_dev *)dev;
  232. int pg;
  233. if (ptr == NULL)
  234. return;
  235. pg = get_order(size);
  236. dec_snd_pages(pg);
  237. sbus_free_consistent(sdev, PAGE_SIZE * (1 << pg), ptr, dma_addr);
  238. }
  239. #endif /* CONFIG_SBUS */
  240. /*
  241. *
  242. * ALSA generic memory management
  243. *
  244. */
  245. /**
  246. * snd_dma_alloc_pages - allocate the buffer area according to the given type
  247. * @type: the DMA buffer type
  248. * @device: the device pointer
  249. * @size: the buffer size to allocate
  250. * @dmab: buffer allocation record to store the allocated data
  251. *
  252. * Calls the memory-allocator function for the corresponding
  253. * buffer type.
  254. *
  255. * Returns zero if the buffer with the given size is allocated successfuly,
  256. * other a negative value at error.
  257. */
  258. int snd_dma_alloc_pages(int type, struct device *device, size_t size,
  259. struct snd_dma_buffer *dmab)
  260. {
  261. snd_assert(size > 0, return -ENXIO);
  262. snd_assert(dmab != NULL, return -ENXIO);
  263. dmab->dev.type = type;
  264. dmab->dev.dev = device;
  265. dmab->bytes = 0;
  266. switch (type) {
  267. case SNDRV_DMA_TYPE_CONTINUOUS:
  268. dmab->area = snd_malloc_pages(size, (unsigned long)device);
  269. dmab->addr = 0;
  270. break;
  271. #ifdef CONFIG_SBUS
  272. case SNDRV_DMA_TYPE_SBUS:
  273. dmab->area = snd_malloc_sbus_pages(device, size, &dmab->addr);
  274. break;
  275. #endif
  276. #ifdef CONFIG_HAS_DMA
  277. case SNDRV_DMA_TYPE_DEV:
  278. dmab->area = snd_malloc_dev_pages(device, size, &dmab->addr);
  279. break;
  280. case SNDRV_DMA_TYPE_DEV_SG:
  281. snd_malloc_sgbuf_pages(device, size, dmab, NULL);
  282. break;
  283. #endif
  284. default:
  285. printk(KERN_ERR "snd-malloc: invalid device type %d\n", type);
  286. dmab->area = NULL;
  287. dmab->addr = 0;
  288. return -ENXIO;
  289. }
  290. if (! dmab->area)
  291. return -ENOMEM;
  292. dmab->bytes = size;
  293. return 0;
  294. }
  295. /**
  296. * snd_dma_alloc_pages_fallback - allocate the buffer area according to the given type with fallback
  297. * @type: the DMA buffer type
  298. * @device: the device pointer
  299. * @size: the buffer size to allocate
  300. * @dmab: buffer allocation record to store the allocated data
  301. *
  302. * Calls the memory-allocator function for the corresponding
  303. * buffer type. When no space is left, this function reduces the size and
  304. * tries to allocate again. The size actually allocated is stored in
  305. * res_size argument.
  306. *
  307. * Returns zero if the buffer with the given size is allocated successfuly,
  308. * other a negative value at error.
  309. */
  310. int snd_dma_alloc_pages_fallback(int type, struct device *device, size_t size,
  311. struct snd_dma_buffer *dmab)
  312. {
  313. int err;
  314. snd_assert(size > 0, return -ENXIO);
  315. snd_assert(dmab != NULL, return -ENXIO);
  316. while ((err = snd_dma_alloc_pages(type, device, size, dmab)) < 0) {
  317. if (err != -ENOMEM)
  318. return err;
  319. size >>= 1;
  320. if (size <= PAGE_SIZE)
  321. return -ENOMEM;
  322. }
  323. if (! dmab->area)
  324. return -ENOMEM;
  325. return 0;
  326. }
  327. /**
  328. * snd_dma_free_pages - release the allocated buffer
  329. * @dmab: the buffer allocation record to release
  330. *
  331. * Releases the allocated buffer via snd_dma_alloc_pages().
  332. */
  333. void snd_dma_free_pages(struct snd_dma_buffer *dmab)
  334. {
  335. switch (dmab->dev.type) {
  336. case SNDRV_DMA_TYPE_CONTINUOUS:
  337. snd_free_pages(dmab->area, dmab->bytes);
  338. break;
  339. #ifdef CONFIG_SBUS
  340. case SNDRV_DMA_TYPE_SBUS:
  341. snd_free_sbus_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
  342. break;
  343. #endif
  344. #ifdef CONFIG_HAS_DMA
  345. case SNDRV_DMA_TYPE_DEV:
  346. snd_free_dev_pages(dmab->dev.dev, dmab->bytes, dmab->area, dmab->addr);
  347. break;
  348. case SNDRV_DMA_TYPE_DEV_SG:
  349. snd_free_sgbuf_pages(dmab);
  350. break;
  351. #endif
  352. default:
  353. printk(KERN_ERR "snd-malloc: invalid device type %d\n", dmab->dev.type);
  354. }
  355. }
  356. /**
  357. * snd_dma_get_reserved - get the reserved buffer for the given device
  358. * @dmab: the buffer allocation record to store
  359. * @id: the buffer id
  360. *
  361. * Looks for the reserved-buffer list and re-uses if the same buffer
  362. * is found in the list. When the buffer is found, it's removed from the free list.
  363. *
  364. * Returns the size of buffer if the buffer is found, or zero if not found.
  365. */
  366. size_t snd_dma_get_reserved_buf(struct snd_dma_buffer *dmab, unsigned int id)
  367. {
  368. struct snd_mem_list *mem;
  369. snd_assert(dmab, return 0);
  370. mutex_lock(&list_mutex);
  371. list_for_each_entry(mem, &mem_list_head, list) {
  372. if (mem->id == id &&
  373. (mem->buffer.dev.dev == NULL || dmab->dev.dev == NULL ||
  374. ! memcmp(&mem->buffer.dev, &dmab->dev, sizeof(dmab->dev)))) {
  375. struct device *dev = dmab->dev.dev;
  376. list_del(&mem->list);
  377. *dmab = mem->buffer;
  378. if (dmab->dev.dev == NULL)
  379. dmab->dev.dev = dev;
  380. kfree(mem);
  381. mutex_unlock(&list_mutex);
  382. return dmab->bytes;
  383. }
  384. }
  385. mutex_unlock(&list_mutex);
  386. return 0;
  387. }
  388. /**
  389. * snd_dma_reserve_buf - reserve the buffer
  390. * @dmab: the buffer to reserve
  391. * @id: the buffer id
  392. *
  393. * Reserves the given buffer as a reserved buffer.
  394. *
  395. * Returns zero if successful, or a negative code at error.
  396. */
  397. int snd_dma_reserve_buf(struct snd_dma_buffer *dmab, unsigned int id)
  398. {
  399. struct snd_mem_list *mem;
  400. snd_assert(dmab, return -EINVAL);
  401. mem = kmalloc(sizeof(*mem), GFP_KERNEL);
  402. if (! mem)
  403. return -ENOMEM;
  404. mutex_lock(&list_mutex);
  405. mem->buffer = *dmab;
  406. mem->id = id;
  407. list_add_tail(&mem->list, &mem_list_head);
  408. mutex_unlock(&list_mutex);
  409. return 0;
  410. }
  411. /*
  412. * purge all reserved buffers
  413. */
  414. static void free_all_reserved_pages(void)
  415. {
  416. struct list_head *p;
  417. struct snd_mem_list *mem;
  418. mutex_lock(&list_mutex);
  419. while (! list_empty(&mem_list_head)) {
  420. p = mem_list_head.next;
  421. mem = list_entry(p, struct snd_mem_list, list);
  422. list_del(p);
  423. snd_dma_free_pages(&mem->buffer);
  424. kfree(mem);
  425. }
  426. mutex_unlock(&list_mutex);
  427. }
  428. #ifdef CONFIG_PROC_FS
  429. /*
  430. * proc file interface
  431. */
  432. #define SND_MEM_PROC_FILE "driver/snd-page-alloc"
  433. static struct proc_dir_entry *snd_mem_proc;
  434. static int snd_mem_proc_read(struct seq_file *seq, void *offset)
  435. {
  436. long pages = snd_allocated_pages >> (PAGE_SHIFT-12);
  437. struct snd_mem_list *mem;
  438. int devno;
  439. static char *types[] = { "UNKNOWN", "CONT", "DEV", "DEV-SG", "SBUS" };
  440. mutex_lock(&list_mutex);
  441. seq_printf(seq, "pages : %li bytes (%li pages per %likB)\n",
  442. pages * PAGE_SIZE, pages, PAGE_SIZE / 1024);
  443. devno = 0;
  444. list_for_each_entry(mem, &mem_list_head, list) {
  445. devno++;
  446. seq_printf(seq, "buffer %d : ID %08x : type %s\n",
  447. devno, mem->id, types[mem->buffer.dev.type]);
  448. seq_printf(seq, " addr = 0x%lx, size = %d bytes\n",
  449. (unsigned long)mem->buffer.addr,
  450. (int)mem->buffer.bytes);
  451. }
  452. mutex_unlock(&list_mutex);
  453. return 0;
  454. }
  455. static int snd_mem_proc_open(struct inode *inode, struct file *file)
  456. {
  457. return single_open(file, snd_mem_proc_read, NULL);
  458. }
  459. /* FIXME: for pci only - other bus? */
  460. #ifdef CONFIG_PCI
  461. #define gettoken(bufp) strsep(bufp, " \t\n")
  462. static ssize_t snd_mem_proc_write(struct file *file, const char __user * buffer,
  463. size_t count, loff_t * ppos)
  464. {
  465. char buf[128];
  466. char *token, *p;
  467. if (count > sizeof(buf) - 1)
  468. return -EINVAL;
  469. if (copy_from_user(buf, buffer, count))
  470. return -EFAULT;
  471. buf[count] = '\0';
  472. p = buf;
  473. token = gettoken(&p);
  474. if (! token || *token == '#')
  475. return count;
  476. if (strcmp(token, "add") == 0) {
  477. char *endp;
  478. int vendor, device, size, buffers;
  479. long mask;
  480. int i, alloced;
  481. struct pci_dev *pci;
  482. if ((token = gettoken(&p)) == NULL ||
  483. (vendor = simple_strtol(token, NULL, 0)) <= 0 ||
  484. (token = gettoken(&p)) == NULL ||
  485. (device = simple_strtol(token, NULL, 0)) <= 0 ||
  486. (token = gettoken(&p)) == NULL ||
  487. (mask = simple_strtol(token, NULL, 0)) < 0 ||
  488. (token = gettoken(&p)) == NULL ||
  489. (size = memparse(token, &endp)) < 64*1024 ||
  490. size > 16*1024*1024 /* too big */ ||
  491. (token = gettoken(&p)) == NULL ||
  492. (buffers = simple_strtol(token, NULL, 0)) <= 0 ||
  493. buffers > 4) {
  494. printk(KERN_ERR "snd-page-alloc: invalid proc write format\n");
  495. return count;
  496. }
  497. vendor &= 0xffff;
  498. device &= 0xffff;
  499. alloced = 0;
  500. pci = NULL;
  501. while ((pci = pci_get_device(vendor, device, pci)) != NULL) {
  502. if (mask > 0 && mask < 0xffffffff) {
  503. if (pci_set_dma_mask(pci, mask) < 0 ||
  504. pci_set_consistent_dma_mask(pci, mask) < 0) {
  505. printk(KERN_ERR "snd-page-alloc: cannot set DMA mask %lx for pci %04x:%04x\n", mask, vendor, device);
  506. return count;
  507. }
  508. }
  509. for (i = 0; i < buffers; i++) {
  510. struct snd_dma_buffer dmab;
  511. memset(&dmab, 0, sizeof(dmab));
  512. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  513. size, &dmab) < 0) {
  514. printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size);
  515. pci_dev_put(pci);
  516. return count;
  517. }
  518. snd_dma_reserve_buf(&dmab, snd_dma_pci_buf_id(pci));
  519. }
  520. alloced++;
  521. }
  522. if (! alloced) {
  523. for (i = 0; i < buffers; i++) {
  524. struct snd_dma_buffer dmab;
  525. memset(&dmab, 0, sizeof(dmab));
  526. /* FIXME: We can allocate only in ZONE_DMA
  527. * without a device pointer!
  528. */
  529. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, NULL,
  530. size, &dmab) < 0) {
  531. printk(KERN_ERR "snd-page-alloc: cannot allocate buffer pages (size = %d)\n", size);
  532. break;
  533. }
  534. snd_dma_reserve_buf(&dmab, (unsigned int)((vendor << 16) | device));
  535. }
  536. }
  537. } else if (strcmp(token, "erase") == 0)
  538. /* FIXME: need for releasing each buffer chunk? */
  539. free_all_reserved_pages();
  540. else
  541. printk(KERN_ERR "snd-page-alloc: invalid proc cmd\n");
  542. return count;
  543. }
  544. #endif /* CONFIG_PCI */
  545. static const struct file_operations snd_mem_proc_fops = {
  546. .owner = THIS_MODULE,
  547. .open = snd_mem_proc_open,
  548. .read = seq_read,
  549. #ifdef CONFIG_PCI
  550. .write = snd_mem_proc_write,
  551. #endif
  552. .llseek = seq_lseek,
  553. .release = single_release,
  554. };
  555. #endif /* CONFIG_PROC_FS */
  556. /*
  557. * module entry
  558. */
  559. static int __init snd_mem_init(void)
  560. {
  561. #ifdef CONFIG_PROC_FS
  562. snd_mem_proc = create_proc_entry(SND_MEM_PROC_FILE, 0644, NULL);
  563. if (snd_mem_proc)
  564. snd_mem_proc->proc_fops = &snd_mem_proc_fops;
  565. #endif
  566. return 0;
  567. }
  568. static void __exit snd_mem_exit(void)
  569. {
  570. remove_proc_entry(SND_MEM_PROC_FILE, NULL);
  571. free_all_reserved_pages();
  572. if (snd_allocated_pages > 0)
  573. printk(KERN_ERR "snd-malloc: Memory leak? pages not freed = %li\n", snd_allocated_pages);
  574. }
  575. module_init(snd_mem_init)
  576. module_exit(snd_mem_exit)
  577. /*
  578. * exports
  579. */
  580. EXPORT_SYMBOL(snd_dma_alloc_pages);
  581. EXPORT_SYMBOL(snd_dma_alloc_pages_fallback);
  582. EXPORT_SYMBOL(snd_dma_free_pages);
  583. EXPORT_SYMBOL(snd_dma_get_reserved_buf);
  584. EXPORT_SYMBOL(snd_dma_reserve_buf);
  585. EXPORT_SYMBOL(snd_malloc_pages);
  586. EXPORT_SYMBOL(snd_free_pages);