31 #define pr_fmt(fmt) "[TTM] " fmt
33 #include <linux/sched.h>
39 #include <linux/slab.h>
40 #include <linux/export.h>
51 static void ttm_tt_alloc_page_directory(
struct ttm_tt *ttm)
56 static void ttm_dma_tt_alloc_page_directory(
struct ttm_dma_tt *ttm)
58 ttm->
ttm.pages = drm_calloc_large(ttm->
ttm.num_pages,
sizeof(
void*));
64 static inline int ttm_tt_set_page_caching(
struct page *
p,
90 static inline int ttm_tt_set_page_caching(
struct page *p,
103 static int ttm_tt_set_caching(
struct ttm_tt *ttm,
107 struct page *cur_page;
113 if (ttm->
state == tt_unpopulated) {
125 ret = ttm_tt_set_page_caching(cur_page,
138 for (j = 0; j <
i; ++
j) {
141 (
void)ttm_tt_set_page_caching(cur_page, c_state,
160 return ttm_tt_set_caching(ttm, state);
169 if (ttm->
state == tt_bound) {
174 ttm->
bdev->driver->ttm_tt_unpopulate(ttm);
182 ttm->
func->destroy(ttm);
187 struct page *dummy_read_page)
195 ttm->
state = tt_unpopulated;
198 ttm_tt_alloc_page_directory(ttm);
201 pr_err(
"Failed allocating page table\n");
210 drm_free_large(ttm->
pages);
217 struct page *dummy_read_page)
231 ttm_dma_tt_alloc_page_directory(ttm_dma);
234 pr_err(
"Failed allocating page table\n");
245 drm_free_large(ttm->
pages);
257 ret = ttm->
func->unbind(ttm);
273 ret = ttm->
bdev->driver->ttm_tt_populate(ttm);
277 ret = ttm->
func->bind(ttm, bo_mem);
290 struct file *swap_storage;
291 struct page *from_page;
292 struct page *to_page;
299 swap_space = swap_storage->
f_path.dentry->d_inode->i_mapping;
302 from_page = shmem_read_mapping_page(swap_space, i);
303 if (IS_ERR(from_page)) {
304 ret = PTR_ERR(from_page);
311 copy_highpage(to_page, from_page);
328 struct file *swap_storage;
329 struct page *from_page;
330 struct page *to_page;
337 if (!persistent_swap_storage) {
341 if (
unlikely(IS_ERR(swap_storage))) {
342 pr_err(
"Failed allocating swap storage\n");
343 return PTR_ERR(swap_storage);
346 swap_storage = persistent_swap_storage;
348 swap_space = swap_storage->
f_path.dentry->d_inode->i_mapping;
351 from_page = ttm->
pages[
i];
354 to_page = shmem_read_mapping_page(swap_space, i);
356 ret = PTR_ERR(to_page);
359 copy_highpage(to_page, from_page);
365 ttm->
bdev->driver->ttm_tt_unpopulate(ttm);
368 if (persistent_swap_storage)
373 if (!persistent_swap_storage)