ttm_page_alloc_dma.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. /*
  2. * Copyright 2011 (c) Oracle Corp.
  3. * Permission is hereby granted, free of charge, to any person obtaining a
  4. * copy of this software and associated documentation files (the "Software"),
  5. * to deal in the Software without restriction, including without limitation
  6. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  7. * and/or sell copies of the Software, and to permit persons to whom the
  8. * Software is furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice (including the
  11. * next paragraph) shall be included in all copies or substantial portions
  12. * of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  17. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. *
  22. * Author: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
  23. */
  24. /*
  25. * A simple DMA pool losely based on dmapool.c. It has certain advantages
  26. * over the DMA pools:
  27. * - Pool collects resently freed pages for reuse (and hooks up to
  28. * the shrinker).
  29. * - Tracks currently in use pages
  30. * - Tracks whether the page is UC, WB or cached (and reverts to WB
  31. * when freed).
  32. */
  33. #if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU)
  34. #define pr_fmt(fmt) "[TTM] " fmt
  35. #include <linux/dma-mapping.h>
  36. #include <linux/list.h>
  37. #include <linux/seq_file.h> /* for seq_printf */
  38. #include <linux/slab.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/highmem.h>
  41. #include <linux/mm_types.h>
  42. #include <linux/module.h>
  43. #include <linux/mm.h>
  44. #include <linux/atomic.h>
  45. #include <linux/device.h>
  46. #include <linux/kthread.h>
  47. #include <drm/ttm/ttm_bo_driver.h>
  48. #include <drm/ttm/ttm_page_alloc.h>
  49. #include <drm/ttm/ttm_set_memory.h>
  50. #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
  51. #define SMALL_ALLOCATION 4
  52. #define FREE_ALL_PAGES (~0U)
  53. #define VADDR_FLAG_HUGE_POOL 1UL
  54. #define VADDR_FLAG_UPDATED_COUNT 2UL
  55. enum pool_type {
  56. IS_UNDEFINED = 0,
  57. IS_WC = 1 << 1,
  58. IS_UC = 1 << 2,
  59. IS_CACHED = 1 << 3,
  60. IS_DMA32 = 1 << 4,
  61. IS_HUGE = 1 << 5
  62. };
  63. /*
  64. * The pool structure. There are up to nine pools:
  65. * - generic (not restricted to DMA32):
  66. * - write combined, uncached, cached.
  67. * - dma32 (up to 2^32 - so up 4GB):
  68. * - write combined, uncached, cached.
  69. * - huge (not restricted to DMA32):
  70. * - write combined, uncached, cached.
  71. * for each 'struct device'. The 'cached' is for pages that are actively used.
  72. * The other ones can be shrunk by the shrinker API if neccessary.
  73. * @pools: The 'struct device->dma_pools' link.
  74. * @type: Type of the pool
  75. * @lock: Protects the free_list from concurrnet access. Must be
  76. * used with irqsave/irqrestore variants because pool allocator maybe called
  77. * from delayed work.
  78. * @free_list: Pool of pages that are free to be used. No order requirements.
  79. * @dev: The device that is associated with these pools.
  80. * @size: Size used during DMA allocation.
  81. * @npages_free: Count of available pages for re-use.
  82. * @npages_in_use: Count of pages that are in use.
  83. * @nfrees: Stats when pool is shrinking.
  84. * @nrefills: Stats when the pool is grown.
  85. * @gfp_flags: Flags to pass for alloc_page.
  86. * @name: Name of the pool.
  87. * @dev_name: Name derieved from dev - similar to how dev_info works.
  88. * Used during shutdown as the dev_info during release is unavailable.
  89. */
  90. struct dma_pool {
  91. struct list_head pools; /* The 'struct device->dma_pools link */
  92. enum pool_type type;
  93. spinlock_t lock;
  94. struct list_head free_list;
  95. struct device *dev;
  96. unsigned size;
  97. unsigned npages_free;
  98. unsigned npages_in_use;
  99. unsigned long nfrees; /* Stats when shrunk. */
  100. unsigned long nrefills; /* Stats when grown. */
  101. gfp_t gfp_flags;
  102. char name[13]; /* "cached dma32" */
  103. char dev_name[64]; /* Constructed from dev */
  104. };
  105. /*
  106. * The accounting page keeping track of the allocated page along with
  107. * the DMA address.
  108. * @page_list: The link to the 'page_list' in 'struct dma_pool'.
  109. * @vaddr: The virtual address of the page and a flag if the page belongs to a
  110. * huge pool
  111. * @dma: The bus address of the page. If the page is not allocated
  112. * via the DMA API, it will be -1.
  113. */
  114. struct dma_page {
  115. struct list_head page_list;
  116. unsigned long vaddr;
  117. struct page *p;
  118. dma_addr_t dma;
  119. };
  120. /*
  121. * Limits for the pool. They are handled without locks because only place where
  122. * they may change is in sysfs store. They won't have immediate effect anyway
  123. * so forcing serialization to access them is pointless.
  124. */
  125. struct ttm_pool_opts {
  126. unsigned alloc_size;
  127. unsigned max_size;
  128. unsigned small;
  129. };
  130. /*
  131. * Contains the list of all of the 'struct device' and their corresponding
  132. * DMA pools. Guarded by _mutex->lock.
  133. * @pools: The link to 'struct ttm_pool_manager->pools'
  134. * @dev: The 'struct device' associated with the 'pool'
  135. * @pool: The 'struct dma_pool' associated with the 'dev'
  136. */
  137. struct device_pools {
  138. struct list_head pools;
  139. struct device *dev;
  140. struct dma_pool *pool;
  141. };
  142. /*
  143. * struct ttm_pool_manager - Holds memory pools for fast allocation
  144. *
  145. * @lock: Lock used when adding/removing from pools
  146. * @pools: List of 'struct device' and 'struct dma_pool' tuples.
  147. * @options: Limits for the pool.
  148. * @npools: Total amount of pools in existence.
  149. * @shrinker: The structure used by [un|]register_shrinker
  150. */
  151. struct ttm_pool_manager {
  152. struct mutex lock;
  153. struct list_head pools;
  154. struct ttm_pool_opts options;
  155. unsigned npools;
  156. struct shrinker mm_shrink;
  157. struct kobject kobj;
  158. };
  159. static struct ttm_pool_manager *_manager;
  160. static struct attribute ttm_page_pool_max = {
  161. .name = "pool_max_size",
  162. .mode = S_IRUGO | S_IWUSR
  163. };
  164. static struct attribute ttm_page_pool_small = {
  165. .name = "pool_small_allocation",
  166. .mode = S_IRUGO | S_IWUSR
  167. };
  168. static struct attribute ttm_page_pool_alloc_size = {
  169. .name = "pool_allocation_size",
  170. .mode = S_IRUGO | S_IWUSR
  171. };
  172. static struct attribute *ttm_pool_attrs[] = {
  173. &ttm_page_pool_max,
  174. &ttm_page_pool_small,
  175. &ttm_page_pool_alloc_size,
  176. NULL
  177. };
  178. static void ttm_pool_kobj_release(struct kobject *kobj)
  179. {
  180. struct ttm_pool_manager *m =
  181. container_of(kobj, struct ttm_pool_manager, kobj);
  182. kfree(m);
  183. }
  184. static ssize_t ttm_pool_store(struct kobject *kobj, struct attribute *attr,
  185. const char *buffer, size_t size)
  186. {
  187. struct ttm_pool_manager *m =
  188. container_of(kobj, struct ttm_pool_manager, kobj);
  189. int chars;
  190. unsigned val;
  191. chars = sscanf(buffer, "%u", &val);
  192. if (chars == 0)
  193. return size;
  194. /* Convert kb to number of pages */
  195. val = val / (PAGE_SIZE >> 10);
  196. if (attr == &ttm_page_pool_max) {
  197. m->options.max_size = val;
  198. } else if (attr == &ttm_page_pool_small) {
  199. m->options.small = val;
  200. } else if (attr == &ttm_page_pool_alloc_size) {
  201. if (val > NUM_PAGES_TO_ALLOC*8) {
  202. pr_err("Setting allocation size to %lu is not allowed. Recommended size is %lu\n",
  203. NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 7),
  204. NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10));
  205. return size;
  206. } else if (val > NUM_PAGES_TO_ALLOC) {
  207. pr_warn("Setting allocation size to larger than %lu is not recommended\n",
  208. NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10));
  209. }
  210. m->options.alloc_size = val;
  211. }
  212. return size;
  213. }
  214. static ssize_t ttm_pool_show(struct kobject *kobj, struct attribute *attr,
  215. char *buffer)
  216. {
  217. struct ttm_pool_manager *m =
  218. container_of(kobj, struct ttm_pool_manager, kobj);
  219. unsigned val = 0;
  220. if (attr == &ttm_page_pool_max)
  221. val = m->options.max_size;
  222. else if (attr == &ttm_page_pool_small)
  223. val = m->options.small;
  224. else if (attr == &ttm_page_pool_alloc_size)
  225. val = m->options.alloc_size;
  226. val = val * (PAGE_SIZE >> 10);
  227. return snprintf(buffer, PAGE_SIZE, "%u\n", val);
  228. }
  229. static const struct sysfs_ops ttm_pool_sysfs_ops = {
  230. .show = &ttm_pool_show,
  231. .store = &ttm_pool_store,
  232. };
  233. static struct kobj_type ttm_pool_kobj_type = {
  234. .release = &ttm_pool_kobj_release,
  235. .sysfs_ops = &ttm_pool_sysfs_ops,
  236. .default_attrs = ttm_pool_attrs,
  237. };
  238. static int ttm_set_pages_caching(struct dma_pool *pool,
  239. struct page **pages, unsigned cpages)
  240. {
  241. int r = 0;
  242. /* Set page caching */
  243. if (pool->type & IS_UC) {
  244. r = ttm_set_pages_array_uc(pages, cpages);
  245. if (r)
  246. pr_err("%s: Failed to set %d pages to uc!\n",
  247. pool->dev_name, cpages);
  248. }
  249. if (pool->type & IS_WC) {
  250. r = ttm_set_pages_array_wc(pages, cpages);
  251. if (r)
  252. pr_err("%s: Failed to set %d pages to wc!\n",
  253. pool->dev_name, cpages);
  254. }
  255. return r;
  256. }
  257. static void __ttm_dma_free_page(struct dma_pool *pool, struct dma_page *d_page)
  258. {
  259. dma_addr_t dma = d_page->dma;
  260. d_page->vaddr &= ~VADDR_FLAG_HUGE_POOL;
  261. dma_free_coherent(pool->dev, pool->size, (void *)d_page->vaddr, dma);
  262. kfree(d_page);
  263. d_page = NULL;
  264. }
  265. static struct dma_page *__ttm_dma_alloc_page(struct dma_pool *pool)
  266. {
  267. struct dma_page *d_page;
  268. unsigned long attrs = 0;
  269. void *vaddr;
  270. d_page = kmalloc(sizeof(struct dma_page), GFP_KERNEL);
  271. if (!d_page)
  272. return NULL;
  273. if (pool->type & IS_HUGE)
  274. attrs = DMA_ATTR_NO_WARN;
  275. vaddr = dma_alloc_attrs(pool->dev, pool->size, &d_page->dma,
  276. pool->gfp_flags, attrs);
  277. if (vaddr) {
  278. if (is_vmalloc_addr(vaddr))
  279. d_page->p = vmalloc_to_page(vaddr);
  280. else
  281. d_page->p = virt_to_page(vaddr);
  282. d_page->vaddr = (unsigned long)vaddr;
  283. if (pool->type & IS_HUGE)
  284. d_page->vaddr |= VADDR_FLAG_HUGE_POOL;
  285. } else {
  286. kfree(d_page);
  287. d_page = NULL;
  288. }
  289. return d_page;
  290. }
  291. static enum pool_type ttm_to_type(int flags, enum ttm_caching_state cstate)
  292. {
  293. enum pool_type type = IS_UNDEFINED;
  294. if (flags & TTM_PAGE_FLAG_DMA32)
  295. type |= IS_DMA32;
  296. if (cstate == tt_cached)
  297. type |= IS_CACHED;
  298. else if (cstate == tt_uncached)
  299. type |= IS_UC;
  300. else
  301. type |= IS_WC;
  302. return type;
  303. }
  304. static void ttm_pool_update_free_locked(struct dma_pool *pool,
  305. unsigned freed_pages)
  306. {
  307. pool->npages_free -= freed_pages;
  308. pool->nfrees += freed_pages;
  309. }
  310. /* set memory back to wb and free the pages. */
  311. static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
  312. {
  313. struct page *page = d_page->p;
  314. unsigned num_pages;
  315. /* Don't set WB on WB page pool. */
  316. if (!(pool->type & IS_CACHED)) {
  317. num_pages = pool->size / PAGE_SIZE;
  318. if (ttm_set_pages_wb(page, num_pages))
  319. pr_err("%s: Failed to set %d pages to wb!\n",
  320. pool->dev_name, num_pages);
  321. }
  322. list_del(&d_page->page_list);
  323. __ttm_dma_free_page(pool, d_page);
  324. }
  325. static void ttm_dma_pages_put(struct dma_pool *pool, struct list_head *d_pages,
  326. struct page *pages[], unsigned npages)
  327. {
  328. struct dma_page *d_page, *tmp;
  329. if (pool->type & IS_HUGE) {
  330. list_for_each_entry_safe(d_page, tmp, d_pages, page_list)
  331. ttm_dma_page_put(pool, d_page);
  332. return;
  333. }
  334. /* Don't set WB on WB page pool. */
  335. if (npages && !(pool->type & IS_CACHED) &&
  336. ttm_set_pages_array_wb(pages, npages))
  337. pr_err("%s: Failed to set %d pages to wb!\n",
  338. pool->dev_name, npages);
  339. list_for_each_entry_safe(d_page, tmp, d_pages, page_list) {
  340. list_del(&d_page->page_list);
  341. __ttm_dma_free_page(pool, d_page);
  342. }
  343. }
  344. /*
  345. * Free pages from pool.
  346. *
  347. * To prevent hogging the ttm_swap process we only free NUM_PAGES_TO_ALLOC
  348. * number of pages in one go.
  349. *
  350. * @pool: to free the pages from
  351. * @nr_free: If set to true will free all pages in pool
  352. * @use_static: Safe to use static buffer
  353. **/
  354. static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
  355. bool use_static)
  356. {
  357. static struct page *static_buf[NUM_PAGES_TO_ALLOC];
  358. unsigned long irq_flags;
  359. struct dma_page *dma_p, *tmp;
  360. struct page **pages_to_free;
  361. struct list_head d_pages;
  362. unsigned freed_pages = 0,
  363. npages_to_free = nr_free;
  364. if (NUM_PAGES_TO_ALLOC < nr_free)
  365. npages_to_free = NUM_PAGES_TO_ALLOC;
  366. #if 0
  367. if (nr_free > 1) {
  368. pr_debug("%s: (%s:%d) Attempting to free %d (%d) pages\n",
  369. pool->dev_name, pool->name, current->pid,
  370. npages_to_free, nr_free);
  371. }
  372. #endif
  373. if (use_static)
  374. pages_to_free = static_buf;
  375. else
  376. pages_to_free = kmalloc_array(npages_to_free,
  377. sizeof(struct page *),
  378. GFP_KERNEL);
  379. if (!pages_to_free) {
  380. pr_debug("%s: Failed to allocate memory for pool free operation\n",
  381. pool->dev_name);
  382. return 0;
  383. }
  384. INIT_LIST_HEAD(&d_pages);
  385. restart:
  386. spin_lock_irqsave(&pool->lock, irq_flags);
  387. /* We picking the oldest ones off the list */
  388. list_for_each_entry_safe_reverse(dma_p, tmp, &pool->free_list,
  389. page_list) {
  390. if (freed_pages >= npages_to_free)
  391. break;
  392. /* Move the dma_page from one list to another. */
  393. list_move(&dma_p->page_list, &d_pages);
  394. pages_to_free[freed_pages++] = dma_p->p;
  395. /* We can only remove NUM_PAGES_TO_ALLOC at a time. */
  396. if (freed_pages >= NUM_PAGES_TO_ALLOC) {
  397. ttm_pool_update_free_locked(pool, freed_pages);
  398. /**
  399. * Because changing page caching is costly
  400. * we unlock the pool to prevent stalling.
  401. */
  402. spin_unlock_irqrestore(&pool->lock, irq_flags);
  403. ttm_dma_pages_put(pool, &d_pages, pages_to_free,
  404. freed_pages);
  405. INIT_LIST_HEAD(&d_pages);
  406. if (likely(nr_free != FREE_ALL_PAGES))
  407. nr_free -= freed_pages;
  408. if (NUM_PAGES_TO_ALLOC >= nr_free)
  409. npages_to_free = nr_free;
  410. else
  411. npages_to_free = NUM_PAGES_TO_ALLOC;
  412. freed_pages = 0;
  413. /* free all so restart the processing */
  414. if (nr_free)
  415. goto restart;
  416. /* Not allowed to fall through or break because
  417. * following context is inside spinlock while we are
  418. * outside here.
  419. */
  420. goto out;
  421. }
  422. }
  423. /* remove range of pages from the pool */
  424. if (freed_pages) {
  425. ttm_pool_update_free_locked(pool, freed_pages);
  426. nr_free -= freed_pages;
  427. }
  428. spin_unlock_irqrestore(&pool->lock, irq_flags);
  429. if (freed_pages)
  430. ttm_dma_pages_put(pool, &d_pages, pages_to_free, freed_pages);
  431. out:
  432. if (pages_to_free != static_buf)
  433. kfree(pages_to_free);
  434. return nr_free;
  435. }
  436. static void ttm_dma_free_pool(struct device *dev, enum pool_type type)
  437. {
  438. struct device_pools *p;
  439. struct dma_pool *pool;
  440. if (!dev)
  441. return;
  442. mutex_lock(&_manager->lock);
  443. list_for_each_entry_reverse(p, &_manager->pools, pools) {
  444. if (p->dev != dev)
  445. continue;
  446. pool = p->pool;
  447. if (pool->type != type)
  448. continue;
  449. list_del(&p->pools);
  450. kfree(p);
  451. _manager->npools--;
  452. break;
  453. }
  454. list_for_each_entry_reverse(pool, &dev->dma_pools, pools) {
  455. if (pool->type != type)
  456. continue;
  457. /* Takes a spinlock.. */
  458. /* OK to use static buffer since global mutex is held. */
  459. ttm_dma_page_pool_free(pool, FREE_ALL_PAGES, true);
  460. WARN_ON(((pool->npages_in_use + pool->npages_free) != 0));
  461. /* This code path is called after _all_ references to the
  462. * struct device has been dropped - so nobody should be
  463. * touching it. In case somebody is trying to _add_ we are
  464. * guarded by the mutex. */
  465. list_del(&pool->pools);
  466. kfree(pool);
  467. break;
  468. }
  469. mutex_unlock(&_manager->lock);
  470. }
  471. /*
  472. * On free-ing of the 'struct device' this deconstructor is run.
  473. * Albeit the pool might have already been freed earlier.
  474. */
  475. static void ttm_dma_pool_release(struct device *dev, void *res)
  476. {
  477. struct dma_pool *pool = *(struct dma_pool **)res;
  478. if (pool)
  479. ttm_dma_free_pool(dev, pool->type);
  480. }
  481. static int ttm_dma_pool_match(struct device *dev, void *res, void *match_data)
  482. {
  483. return *(struct dma_pool **)res == match_data;
  484. }
  485. static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,
  486. enum pool_type type)
  487. {
  488. const char *n[] = {"wc", "uc", "cached", " dma32", "huge"};
  489. enum pool_type t[] = {IS_WC, IS_UC, IS_CACHED, IS_DMA32, IS_HUGE};
  490. struct device_pools *sec_pool = NULL;
  491. struct dma_pool *pool = NULL, **ptr;
  492. unsigned i;
  493. int ret = -ENODEV;
  494. char *p;
  495. if (!dev)
  496. return NULL;
  497. ptr = devres_alloc(ttm_dma_pool_release, sizeof(*ptr), GFP_KERNEL);
  498. if (!ptr)
  499. return NULL;
  500. ret = -ENOMEM;
  501. pool = kmalloc_node(sizeof(struct dma_pool), GFP_KERNEL,
  502. dev_to_node(dev));
  503. if (!pool)
  504. goto err_mem;
  505. sec_pool = kmalloc_node(sizeof(struct device_pools), GFP_KERNEL,
  506. dev_to_node(dev));
  507. if (!sec_pool)
  508. goto err_mem;
  509. INIT_LIST_HEAD(&sec_pool->pools);
  510. sec_pool->dev = dev;
  511. sec_pool->pool = pool;
  512. INIT_LIST_HEAD(&pool->free_list);
  513. INIT_LIST_HEAD(&pool->pools);
  514. spin_lock_init(&pool->lock);
  515. pool->dev = dev;
  516. pool->npages_free = pool->npages_in_use = 0;
  517. pool->nfrees = 0;
  518. pool->gfp_flags = flags;
  519. if (type & IS_HUGE)
  520. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  521. pool->size = HPAGE_PMD_SIZE;
  522. #else
  523. BUG();
  524. #endif
  525. else
  526. pool->size = PAGE_SIZE;
  527. pool->type = type;
  528. pool->nrefills = 0;
  529. p = pool->name;
  530. for (i = 0; i < ARRAY_SIZE(t); i++) {
  531. if (type & t[i]) {
  532. p += snprintf(p, sizeof(pool->name) - (p - pool->name),
  533. "%s", n[i]);
  534. }
  535. }
  536. *p = 0;
  537. /* We copy the name for pr_ calls b/c when dma_pool_destroy is called
  538. * - the kobj->name has already been deallocated.*/
  539. snprintf(pool->dev_name, sizeof(pool->dev_name), "%s %s",
  540. dev_driver_string(dev), dev_name(dev));
  541. mutex_lock(&_manager->lock);
  542. /* You can get the dma_pool from either the global: */
  543. list_add(&sec_pool->pools, &_manager->pools);
  544. _manager->npools++;
  545. /* or from 'struct device': */
  546. list_add(&pool->pools, &dev->dma_pools);
  547. mutex_unlock(&_manager->lock);
  548. *ptr = pool;
  549. devres_add(dev, ptr);
  550. return pool;
  551. err_mem:
  552. devres_free(ptr);
  553. kfree(sec_pool);
  554. kfree(pool);
  555. return ERR_PTR(ret);
  556. }
  557. static struct dma_pool *ttm_dma_find_pool(struct device *dev,
  558. enum pool_type type)
  559. {
  560. struct dma_pool *pool, *tmp;
  561. if (type == IS_UNDEFINED)
  562. return NULL;
  563. /* NB: We iterate on the 'struct dev' which has no spinlock, but
  564. * it does have a kref which we have taken. The kref is taken during
  565. * graphic driver loading - in the drm_pci_init it calls either
  566. * pci_dev_get or pci_register_driver which both end up taking a kref
  567. * on 'struct device'.
  568. *
  569. * On teardown, the graphic drivers end up quiescing the TTM (put_pages)
  570. * and calls the dev_res deconstructors: ttm_dma_pool_release. The nice
  571. * thing is at that point of time there are no pages associated with the
  572. * driver so this function will not be called.
  573. */
  574. list_for_each_entry_safe(pool, tmp, &dev->dma_pools, pools)
  575. if (pool->type == type)
  576. return pool;
  577. return NULL;
  578. }
  579. /*
  580. * Free pages the pages that failed to change the caching state. If there
  581. * are pages that have changed their caching state already put them to the
  582. * pool.
  583. */
  584. static void ttm_dma_handle_caching_state_failure(struct dma_pool *pool,
  585. struct list_head *d_pages,
  586. struct page **failed_pages,
  587. unsigned cpages)
  588. {
  589. struct dma_page *d_page, *tmp;
  590. struct page *p;
  591. unsigned i = 0;
  592. p = failed_pages[0];
  593. if (!p)
  594. return;
  595. /* Find the failed page. */
  596. list_for_each_entry_safe(d_page, tmp, d_pages, page_list) {
  597. if (d_page->p != p)
  598. continue;
  599. /* .. and then progress over the full list. */
  600. list_del(&d_page->page_list);
  601. __ttm_dma_free_page(pool, d_page);
  602. if (++i < cpages)
  603. p = failed_pages[i];
  604. else
  605. break;
  606. }
  607. }
  608. /*
  609. * Allocate 'count' pages, and put 'need' number of them on the
  610. * 'pages' and as well on the 'dma_address' starting at 'dma_offset' offset.
  611. * The full list of pages should also be on 'd_pages'.
  612. * We return zero for success, and negative numbers as errors.
  613. */
  614. static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool,
  615. struct list_head *d_pages,
  616. unsigned count)
  617. {
  618. struct page **caching_array;
  619. struct dma_page *dma_p;
  620. struct page *p;
  621. int r = 0;
  622. unsigned i, j, npages, cpages;
  623. unsigned max_cpages = min(count,
  624. (unsigned)(PAGE_SIZE/sizeof(struct page *)));
  625. /* allocate array for page caching change */
  626. caching_array = kmalloc_array(max_cpages, sizeof(struct page *),
  627. GFP_KERNEL);
  628. if (!caching_array) {
  629. pr_debug("%s: Unable to allocate table for new pages\n",
  630. pool->dev_name);
  631. return -ENOMEM;
  632. }
  633. if (count > 1)
  634. pr_debug("%s: (%s:%d) Getting %d pages\n",
  635. pool->dev_name, pool->name, current->pid, count);
  636. for (i = 0, cpages = 0; i < count; ++i) {
  637. dma_p = __ttm_dma_alloc_page(pool);
  638. if (!dma_p) {
  639. pr_debug("%s: Unable to get page %u\n",
  640. pool->dev_name, i);
  641. /* store already allocated pages in the pool after
  642. * setting the caching state */
  643. if (cpages) {
  644. r = ttm_set_pages_caching(pool, caching_array,
  645. cpages);
  646. if (r)
  647. ttm_dma_handle_caching_state_failure(
  648. pool, d_pages, caching_array,
  649. cpages);
  650. }
  651. r = -ENOMEM;
  652. goto out;
  653. }
  654. p = dma_p->p;
  655. list_add(&dma_p->page_list, d_pages);
  656. #ifdef CONFIG_HIGHMEM
  657. /* gfp flags of highmem page should never be dma32 so we
  658. * we should be fine in such case
  659. */
  660. if (PageHighMem(p))
  661. continue;
  662. #endif
  663. npages = pool->size / PAGE_SIZE;
  664. for (j = 0; j < npages; ++j) {
  665. caching_array[cpages++] = p + j;
  666. if (cpages == max_cpages) {
  667. /* Note: Cannot hold the spinlock */
  668. r = ttm_set_pages_caching(pool, caching_array,
  669. cpages);
  670. if (r) {
  671. ttm_dma_handle_caching_state_failure(
  672. pool, d_pages, caching_array,
  673. cpages);
  674. goto out;
  675. }
  676. cpages = 0;
  677. }
  678. }
  679. }
  680. if (cpages) {
  681. r = ttm_set_pages_caching(pool, caching_array, cpages);
  682. if (r)
  683. ttm_dma_handle_caching_state_failure(pool, d_pages,
  684. caching_array, cpages);
  685. }
  686. out:
  687. kfree(caching_array);
  688. return r;
  689. }
  690. /*
  691. * @return count of pages still required to fulfill the request.
  692. */
  693. static int ttm_dma_page_pool_fill_locked(struct dma_pool *pool,
  694. unsigned long *irq_flags)
  695. {
  696. unsigned count = _manager->options.small;
  697. int r = pool->npages_free;
  698. if (count > pool->npages_free) {
  699. struct list_head d_pages;
  700. INIT_LIST_HEAD(&d_pages);
  701. spin_unlock_irqrestore(&pool->lock, *irq_flags);
  702. /* Returns how many more are neccessary to fulfill the
  703. * request. */
  704. r = ttm_dma_pool_alloc_new_pages(pool, &d_pages, count);
  705. spin_lock_irqsave(&pool->lock, *irq_flags);
  706. if (!r) {
  707. /* Add the fresh to the end.. */
  708. list_splice(&d_pages, &pool->free_list);
  709. ++pool->nrefills;
  710. pool->npages_free += count;
  711. r = count;
  712. } else {
  713. struct dma_page *d_page;
  714. unsigned cpages = 0;
  715. pr_debug("%s: Failed to fill %s pool (r:%d)!\n",
  716. pool->dev_name, pool->name, r);
  717. list_for_each_entry(d_page, &d_pages, page_list) {
  718. cpages++;
  719. }
  720. list_splice_tail(&d_pages, &pool->free_list);
  721. pool->npages_free += cpages;
  722. r = cpages;
  723. }
  724. }
  725. return r;
  726. }
  727. /*
  728. * The populate list is actually a stack (not that is matters as TTM
  729. * allocates one page at a time.
  730. * return dma_page pointer if success, otherwise NULL.
  731. */
  732. static struct dma_page *ttm_dma_pool_get_pages(struct dma_pool *pool,
  733. struct ttm_dma_tt *ttm_dma,
  734. unsigned index)
  735. {
  736. struct dma_page *d_page = NULL;
  737. struct ttm_tt *ttm = &ttm_dma->ttm;
  738. unsigned long irq_flags;
  739. int count;
  740. spin_lock_irqsave(&pool->lock, irq_flags);
  741. count = ttm_dma_page_pool_fill_locked(pool, &irq_flags);
  742. if (count) {
  743. d_page = list_first_entry(&pool->free_list, struct dma_page, page_list);
  744. ttm->pages[index] = d_page->p;
  745. ttm_dma->dma_address[index] = d_page->dma;
  746. list_move_tail(&d_page->page_list, &ttm_dma->pages_list);
  747. pool->npages_in_use += 1;
  748. pool->npages_free -= 1;
  749. }
  750. spin_unlock_irqrestore(&pool->lock, irq_flags);
  751. return d_page;
  752. }
  753. static gfp_t ttm_dma_pool_gfp_flags(struct ttm_dma_tt *ttm_dma, bool huge)
  754. {
  755. struct ttm_tt *ttm = &ttm_dma->ttm;
  756. gfp_t gfp_flags;
  757. if (ttm->page_flags & TTM_PAGE_FLAG_DMA32)
  758. gfp_flags = GFP_USER | GFP_DMA32;
  759. else
  760. gfp_flags = GFP_HIGHUSER;
  761. if (ttm->page_flags & TTM_PAGE_FLAG_ZERO_ALLOC)
  762. gfp_flags |= __GFP_ZERO;
  763. if (huge) {
  764. gfp_flags |= GFP_TRANSHUGE_LIGHT | __GFP_NORETRY |
  765. __GFP_KSWAPD_RECLAIM;
  766. gfp_flags &= ~__GFP_MOVABLE;
  767. gfp_flags &= ~__GFP_COMP;
  768. }
  769. if (ttm->page_flags & TTM_PAGE_FLAG_NO_RETRY)
  770. gfp_flags |= __GFP_RETRY_MAYFAIL;
  771. return gfp_flags;
  772. }
  773. /*
  774. * On success pages list will hold count number of correctly
  775. * cached pages. On failure will hold the negative return value (-ENOMEM, etc).
  776. */
  777. int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
  778. struct ttm_operation_ctx *ctx)
  779. {
  780. struct ttm_tt *ttm = &ttm_dma->ttm;
  781. struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
  782. unsigned long num_pages = ttm->num_pages;
  783. struct dma_pool *pool;
  784. struct dma_page *d_page;
  785. enum pool_type type;
  786. unsigned i;
  787. int ret;
  788. if (ttm->state != tt_unpopulated)
  789. return 0;
  790. if (ttm_check_under_lowerlimit(mem_glob, num_pages, ctx))
  791. return -ENOMEM;
  792. INIT_LIST_HEAD(&ttm_dma->pages_list);
  793. i = 0;
  794. type = ttm_to_type(ttm->page_flags, ttm->caching_state);
  795. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  796. if (ttm->page_flags & TTM_PAGE_FLAG_DMA32)
  797. goto skip_huge;
  798. pool = ttm_dma_find_pool(dev, type | IS_HUGE);
  799. if (!pool) {
  800. gfp_t gfp_flags = ttm_dma_pool_gfp_flags(ttm_dma, true);
  801. pool = ttm_dma_pool_init(dev, gfp_flags, type | IS_HUGE);
  802. if (IS_ERR_OR_NULL(pool))
  803. goto skip_huge;
  804. }
  805. while (num_pages >= HPAGE_PMD_NR) {
  806. unsigned j;
  807. d_page = ttm_dma_pool_get_pages(pool, ttm_dma, i);
  808. if (!d_page)
  809. break;
  810. ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
  811. pool->size, ctx);
  812. if (unlikely(ret != 0)) {
  813. ttm_dma_unpopulate(ttm_dma, dev);
  814. return -ENOMEM;
  815. }
  816. d_page->vaddr |= VADDR_FLAG_UPDATED_COUNT;
  817. for (j = i + 1; j < (i + HPAGE_PMD_NR); ++j) {
  818. ttm->pages[j] = ttm->pages[j - 1] + 1;
  819. ttm_dma->dma_address[j] = ttm_dma->dma_address[j - 1] +
  820. PAGE_SIZE;
  821. }
  822. i += HPAGE_PMD_NR;
  823. num_pages -= HPAGE_PMD_NR;
  824. }
  825. skip_huge:
  826. #endif
  827. pool = ttm_dma_find_pool(dev, type);
  828. if (!pool) {
  829. gfp_t gfp_flags = ttm_dma_pool_gfp_flags(ttm_dma, false);
  830. pool = ttm_dma_pool_init(dev, gfp_flags, type);
  831. if (IS_ERR_OR_NULL(pool))
  832. return -ENOMEM;
  833. }
  834. while (num_pages) {
  835. d_page = ttm_dma_pool_get_pages(pool, ttm_dma, i);
  836. if (!d_page) {
  837. ttm_dma_unpopulate(ttm_dma, dev);
  838. return -ENOMEM;
  839. }
  840. ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
  841. pool->size, ctx);
  842. if (unlikely(ret != 0)) {
  843. ttm_dma_unpopulate(ttm_dma, dev);
  844. return -ENOMEM;
  845. }
  846. d_page->vaddr |= VADDR_FLAG_UPDATED_COUNT;
  847. ++i;
  848. --num_pages;
  849. }
  850. if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
  851. ret = ttm_tt_swapin(ttm);
  852. if (unlikely(ret != 0)) {
  853. ttm_dma_unpopulate(ttm_dma, dev);
  854. return ret;
  855. }
  856. }
  857. ttm->state = tt_unbound;
  858. return 0;
  859. }
  860. EXPORT_SYMBOL_GPL(ttm_dma_populate);
  861. /* Put all pages in pages list to correct pool to wait for reuse */
  862. void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
  863. {
  864. struct ttm_tt *ttm = &ttm_dma->ttm;
  865. struct ttm_mem_global *mem_glob = ttm->bdev->glob->mem_glob;
  866. struct dma_pool *pool;
  867. struct dma_page *d_page, *next;
  868. enum pool_type type;
  869. bool is_cached = false;
  870. unsigned count, i, npages = 0;
  871. unsigned long irq_flags;
  872. type = ttm_to_type(ttm->page_flags, ttm->caching_state);
  873. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  874. pool = ttm_dma_find_pool(dev, type | IS_HUGE);
  875. if (pool) {
  876. count = 0;
  877. list_for_each_entry_safe(d_page, next, &ttm_dma->pages_list,
  878. page_list) {
  879. if (!(d_page->vaddr & VADDR_FLAG_HUGE_POOL))
  880. continue;
  881. count++;
  882. if (d_page->vaddr & VADDR_FLAG_UPDATED_COUNT) {
  883. ttm_mem_global_free_page(mem_glob, d_page->p,
  884. pool->size);
  885. d_page->vaddr &= ~VADDR_FLAG_UPDATED_COUNT;
  886. }
  887. ttm_dma_page_put(pool, d_page);
  888. }
  889. spin_lock_irqsave(&pool->lock, irq_flags);
  890. pool->npages_in_use -= count;
  891. pool->nfrees += count;
  892. spin_unlock_irqrestore(&pool->lock, irq_flags);
  893. }
  894. #endif
  895. pool = ttm_dma_find_pool(dev, type);
  896. if (!pool)
  897. return;
  898. is_cached = (ttm_dma_find_pool(pool->dev,
  899. ttm_to_type(ttm->page_flags, tt_cached)) == pool);
  900. /* make sure pages array match list and count number of pages */
  901. count = 0;
  902. list_for_each_entry_safe(d_page, next, &ttm_dma->pages_list,
  903. page_list) {
  904. ttm->pages[count] = d_page->p;
  905. count++;
  906. if (d_page->vaddr & VADDR_FLAG_UPDATED_COUNT) {
  907. ttm_mem_global_free_page(mem_glob, d_page->p,
  908. pool->size);
  909. d_page->vaddr &= ~VADDR_FLAG_UPDATED_COUNT;
  910. }
  911. if (is_cached)
  912. ttm_dma_page_put(pool, d_page);
  913. }
  914. spin_lock_irqsave(&pool->lock, irq_flags);
  915. pool->npages_in_use -= count;
  916. if (is_cached) {
  917. pool->nfrees += count;
  918. } else {
  919. pool->npages_free += count;
  920. list_splice(&ttm_dma->pages_list, &pool->free_list);
  921. /*
  922. * Wait to have at at least NUM_PAGES_TO_ALLOC number of pages
  923. * to free in order to minimize calls to set_memory_wb().
  924. */
  925. if (pool->npages_free >= (_manager->options.max_size +
  926. NUM_PAGES_TO_ALLOC))
  927. npages = pool->npages_free - _manager->options.max_size;
  928. }
  929. spin_unlock_irqrestore(&pool->lock, irq_flags);
  930. INIT_LIST_HEAD(&ttm_dma->pages_list);
  931. for (i = 0; i < ttm->num_pages; i++) {
  932. ttm->pages[i] = NULL;
  933. ttm_dma->dma_address[i] = 0;
  934. }
  935. /* shrink pool if necessary (only on !is_cached pools)*/
  936. if (npages)
  937. ttm_dma_page_pool_free(pool, npages, false);
  938. ttm->state = tt_unpopulated;
  939. }
  940. EXPORT_SYMBOL_GPL(ttm_dma_unpopulate);
  941. /**
  942. * Callback for mm to request pool to reduce number of page held.
  943. *
  944. * XXX: (dchinner) Deadlock warning!
  945. *
  946. * I'm getting sadder as I hear more pathetical whimpers about needing per-pool
  947. * shrinkers
  948. */
  949. static unsigned long
  950. ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
  951. {
  952. static unsigned start_pool;
  953. unsigned idx = 0;
  954. unsigned pool_offset;
  955. unsigned shrink_pages = sc->nr_to_scan;
  956. struct device_pools *p;
  957. unsigned long freed = 0;
  958. if (list_empty(&_manager->pools))
  959. return SHRINK_STOP;
  960. if (!mutex_trylock(&_manager->lock))
  961. return SHRINK_STOP;
  962. if (!_manager->npools)
  963. goto out;
  964. pool_offset = ++start_pool % _manager->npools;
  965. list_for_each_entry(p, &_manager->pools, pools) {
  966. unsigned nr_free;
  967. if (!p->dev)
  968. continue;
  969. if (shrink_pages == 0)
  970. break;
  971. /* Do it in round-robin fashion. */
  972. if (++idx < pool_offset)
  973. continue;
  974. nr_free = shrink_pages;
  975. /* OK to use static buffer since global mutex is held. */
  976. shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
  977. freed += nr_free - shrink_pages;
  978. pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
  979. p->pool->dev_name, p->pool->name, current->pid,
  980. nr_free, shrink_pages);
  981. }
  982. out:
  983. mutex_unlock(&_manager->lock);
  984. return freed;
  985. }
  986. static unsigned long
  987. ttm_dma_pool_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
  988. {
  989. struct device_pools *p;
  990. unsigned long count = 0;
  991. if (!mutex_trylock(&_manager->lock))
  992. return 0;
  993. list_for_each_entry(p, &_manager->pools, pools)
  994. count += p->pool->npages_free;
  995. mutex_unlock(&_manager->lock);
  996. return count;
  997. }
  998. static int ttm_dma_pool_mm_shrink_init(struct ttm_pool_manager *manager)
  999. {
  1000. manager->mm_shrink.count_objects = ttm_dma_pool_shrink_count;
  1001. manager->mm_shrink.scan_objects = &ttm_dma_pool_shrink_scan;
  1002. manager->mm_shrink.seeks = 1;
  1003. return register_shrinker(&manager->mm_shrink);
  1004. }
  1005. static void ttm_dma_pool_mm_shrink_fini(struct ttm_pool_manager *manager)
  1006. {
  1007. unregister_shrinker(&manager->mm_shrink);
  1008. }
  1009. int ttm_dma_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
  1010. {
  1011. int ret;
  1012. WARN_ON(_manager);
  1013. pr_info("Initializing DMA pool allocator\n");
  1014. _manager = kzalloc(sizeof(*_manager), GFP_KERNEL);
  1015. if (!_manager)
  1016. return -ENOMEM;
  1017. mutex_init(&_manager->lock);
  1018. INIT_LIST_HEAD(&_manager->pools);
  1019. _manager->options.max_size = max_pages;
  1020. _manager->options.small = SMALL_ALLOCATION;
  1021. _manager->options.alloc_size = NUM_PAGES_TO_ALLOC;
  1022. /* This takes care of auto-freeing the _manager */
  1023. ret = kobject_init_and_add(&_manager->kobj, &ttm_pool_kobj_type,
  1024. &glob->kobj, "dma_pool");
  1025. if (unlikely(ret != 0))
  1026. goto error;
  1027. ret = ttm_dma_pool_mm_shrink_init(_manager);
  1028. if (unlikely(ret != 0))
  1029. goto error;
  1030. return 0;
  1031. error:
  1032. kobject_put(&_manager->kobj);
  1033. _manager = NULL;
  1034. return ret;
  1035. }
  1036. void ttm_dma_page_alloc_fini(void)
  1037. {
  1038. struct device_pools *p, *t;
  1039. pr_info("Finalizing DMA pool allocator\n");
  1040. ttm_dma_pool_mm_shrink_fini(_manager);
  1041. list_for_each_entry_safe_reverse(p, t, &_manager->pools, pools) {
  1042. dev_dbg(p->dev, "(%s:%d) Freeing.\n", p->pool->name,
  1043. current->pid);
  1044. WARN_ON(devres_destroy(p->dev, ttm_dma_pool_release,
  1045. ttm_dma_pool_match, p->pool));
  1046. ttm_dma_free_pool(p->dev, p->pool->type);
  1047. }
  1048. kobject_put(&_manager->kobj);
  1049. _manager = NULL;
  1050. }
  1051. int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
  1052. {
  1053. struct device_pools *p;
  1054. struct dma_pool *pool = NULL;
  1055. if (!_manager) {
  1056. seq_printf(m, "No pool allocator running.\n");
  1057. return 0;
  1058. }
  1059. seq_printf(m, " pool refills pages freed inuse available name\n");
  1060. mutex_lock(&_manager->lock);
  1061. list_for_each_entry(p, &_manager->pools, pools) {
  1062. struct device *dev = p->dev;
  1063. if (!dev)
  1064. continue;
  1065. pool = p->pool;
  1066. seq_printf(m, "%13s %12ld %13ld %8d %8d %8s\n",
  1067. pool->name, pool->nrefills,
  1068. pool->nfrees, pool->npages_in_use,
  1069. pool->npages_free,
  1070. pool->dev_name);
  1071. }
  1072. mutex_unlock(&_manager->lock);
  1073. return 0;
  1074. }
  1075. EXPORT_SYMBOL_GPL(ttm_dma_page_alloc_debugfs);
  1076. #endif