Lines Matching refs:ttm

72 	if (bo->ttm)  in ttm_tt_create()
99 bo->ttm = bdev->funcs->ttm_tt_create(bo, page_flags); in ttm_tt_create()
100 if (unlikely(bo->ttm == NULL)) in ttm_tt_create()
103 WARN_ON(bo->ttm->page_flags & TTM_TT_FLAG_EXTERNAL_MAPPABLE && in ttm_tt_create()
104 !(bo->ttm->page_flags & TTM_TT_FLAG_EXTERNAL)); in ttm_tt_create()
113 static int ttm_tt_alloc_page_directory(struct ttm_tt *ttm) in ttm_tt_alloc_page_directory() argument
115 ttm->pages = kvcalloc(ttm->num_pages, sizeof(void*), GFP_KERNEL); in ttm_tt_alloc_page_directory()
116 if (!ttm->pages) in ttm_tt_alloc_page_directory()
122 static int ttm_dma_tt_alloc_page_directory(struct ttm_tt *ttm) in ttm_dma_tt_alloc_page_directory() argument
124 ttm->pages = kvcalloc(ttm->num_pages, sizeof(*ttm->pages) + in ttm_dma_tt_alloc_page_directory()
125 sizeof(*ttm->dma_address), GFP_KERNEL); in ttm_dma_tt_alloc_page_directory()
126 if (!ttm->pages) in ttm_dma_tt_alloc_page_directory()
129 ttm->dma_address = (void *)(ttm->pages + ttm->num_pages); in ttm_dma_tt_alloc_page_directory()
133 static int ttm_sg_tt_alloc_page_directory(struct ttm_tt *ttm) in ttm_sg_tt_alloc_page_directory() argument
135 ttm->dma_address = kvcalloc(ttm->num_pages, sizeof(*ttm->dma_address), in ttm_sg_tt_alloc_page_directory()
137 if (!ttm->dma_address) in ttm_sg_tt_alloc_page_directory()
143 void ttm_tt_destroy(struct ttm_device *bdev, struct ttm_tt *ttm) in ttm_tt_destroy() argument
145 bdev->funcs->ttm_tt_destroy(bdev, ttm); in ttm_tt_destroy()
149 static void ttm_tt_init_fields(struct ttm_tt *ttm, in ttm_tt_init_fields() argument
155 ttm->num_pages = (PAGE_ALIGN(bo->base.size) >> PAGE_SHIFT) + extra_pages; in ttm_tt_init_fields()
156 ttm->page_flags = page_flags; in ttm_tt_init_fields()
157 ttm->dma_address = NULL; in ttm_tt_init_fields()
158 ttm->swap_storage = NULL; in ttm_tt_init_fields()
159 ttm->sg = bo->sg; in ttm_tt_init_fields()
160 ttm->caching = caching; in ttm_tt_init_fields()
163 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, in ttm_tt_init() argument
167 ttm_tt_init_fields(ttm, bo, page_flags, caching, extra_pages); in ttm_tt_init()
169 if (ttm_tt_alloc_page_directory(ttm)) { in ttm_tt_init()
177 void ttm_tt_fini(struct ttm_tt *ttm) in ttm_tt_fini() argument
179 WARN_ON(ttm->page_flags & TTM_TT_FLAG_PRIV_POPULATED); in ttm_tt_fini()
181 if (ttm->swap_storage) in ttm_tt_fini()
182 fput(ttm->swap_storage); in ttm_tt_fini()
183 ttm->swap_storage = NULL; in ttm_tt_fini()
185 if (ttm->pages) in ttm_tt_fini()
186 kvfree(ttm->pages); in ttm_tt_fini()
188 kvfree(ttm->dma_address); in ttm_tt_fini()
189 ttm->pages = NULL; in ttm_tt_fini()
190 ttm->dma_address = NULL; in ttm_tt_fini()
194 int ttm_sg_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, in ttm_sg_tt_init() argument
199 ttm_tt_init_fields(ttm, bo, page_flags, caching, 0); in ttm_sg_tt_init()
202 ret = ttm_sg_tt_alloc_page_directory(ttm); in ttm_sg_tt_init()
204 ret = ttm_dma_tt_alloc_page_directory(ttm); in ttm_sg_tt_init()
213 int ttm_tt_swapin(struct ttm_tt *ttm) in ttm_tt_swapin() argument
222 swap_storage = ttm->swap_storage; in ttm_tt_swapin()
228 for (i = 0; i < ttm->num_pages; ++i) { in ttm_tt_swapin()
235 to_page = ttm->pages[i]; in ttm_tt_swapin()
246 ttm->swap_storage = NULL; in ttm_tt_swapin()
247 ttm->page_flags &= ~TTM_TT_FLAG_SWAPPED; in ttm_tt_swapin()
266 int ttm_tt_swapout(struct ttm_device *bdev, struct ttm_tt *ttm, in ttm_tt_swapout() argument
269 loff_t size = (loff_t)ttm->num_pages << PAGE_SHIFT; in ttm_tt_swapout()
285 for (i = 0; i < ttm->num_pages; ++i) { in ttm_tt_swapout()
286 from_page = ttm->pages[i]; in ttm_tt_swapout()
301 ttm_tt_unpopulate(bdev, ttm); in ttm_tt_swapout()
302 ttm->swap_storage = swap_storage; in ttm_tt_swapout()
303 ttm->page_flags |= TTM_TT_FLAG_SWAPPED; in ttm_tt_swapout()
305 return ttm->num_pages; in ttm_tt_swapout()
315 struct ttm_tt *ttm, struct ttm_operation_ctx *ctx) in ttm_tt_populate() argument
319 if (!ttm) in ttm_tt_populate()
322 if (ttm_tt_is_populated(ttm)) in ttm_tt_populate()
325 if (!(ttm->page_flags & TTM_TT_FLAG_EXTERNAL)) { in ttm_tt_populate()
326 atomic_long_add(ttm->num_pages, &ttm_pages_allocated); in ttm_tt_populate()
328 atomic_long_add(ttm->num_pages, in ttm_tt_populate()
344 ret = bdev->funcs->ttm_tt_populate(bdev, ttm, ctx); in ttm_tt_populate()
346 ret = ttm_pool_alloc(&bdev->pool, ttm, ctx); in ttm_tt_populate()
350 ttm->page_flags |= TTM_TT_FLAG_PRIV_POPULATED; in ttm_tt_populate()
351 if (unlikely(ttm->page_flags & TTM_TT_FLAG_SWAPPED)) { in ttm_tt_populate()
352 ret = ttm_tt_swapin(ttm); in ttm_tt_populate()
354 ttm_tt_unpopulate(bdev, ttm); in ttm_tt_populate()
362 if (!(ttm->page_flags & TTM_TT_FLAG_EXTERNAL)) { in ttm_tt_populate()
363 atomic_long_sub(ttm->num_pages, &ttm_pages_allocated); in ttm_tt_populate()
365 atomic_long_sub(ttm->num_pages, in ttm_tt_populate()
372 void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) in ttm_tt_unpopulate() argument
374 if (!ttm_tt_is_populated(ttm)) in ttm_tt_unpopulate()
378 bdev->funcs->ttm_tt_unpopulate(bdev, ttm); in ttm_tt_unpopulate()
380 ttm_pool_free(&bdev->pool, ttm); in ttm_tt_unpopulate()
382 if (!(ttm->page_flags & TTM_TT_FLAG_EXTERNAL)) { in ttm_tt_unpopulate()
383 atomic_long_sub(ttm->num_pages, &ttm_pages_allocated); in ttm_tt_unpopulate()
385 atomic_long_sub(ttm->num_pages, in ttm_tt_unpopulate()
389 ttm->page_flags &= ~TTM_TT_FLAG_PRIV_POPULATED; in ttm_tt_unpopulate()