memalloc.c 17 KB

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