PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nouveau_sgdma.c
bloba4d22e5eb176ef342023fdf0e581c564139139ed
1 #include <linux/pagemap.h>
2 #include <linux/slab.h>
4 #include <subdev/fb.h>
6 #include "nouveau_drm.h"
7 #include "nouveau_ttm.h"
9 struct nouveau_sgdma_be {
10 /* this has to be the first field so populate/unpopulated in
11 * nouve_bo.c works properly, otherwise have to move them here
13 struct ttm_dma_tt ttm;
14 struct drm_device *dev;
15 struct nouveau_mem *node;
18 static void
19 nouveau_sgdma_destroy(struct ttm_tt *ttm)
21 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
23 if (ttm) {
24 ttm_dma_tt_fini(&nvbe->ttm);
25 kfree(nvbe);
29 static int
30 nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
32 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
33 struct nouveau_mem *node = mem->mm_node;
35 if (ttm->sg) {
36 node->sg = ttm->sg;
37 node->pages = NULL;
38 } else {
39 node->sg = NULL;
40 node->pages = nvbe->ttm.dma_address;
42 node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
44 nouveau_vm_map(&node->vma[0], node);
45 nvbe->node = node;
46 return 0;
49 static int
50 nv04_sgdma_unbind(struct ttm_tt *ttm)
52 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
53 nouveau_vm_unmap(&nvbe->node->vma[0]);
54 return 0;
57 static struct ttm_backend_func nv04_sgdma_backend = {
58 .bind = nv04_sgdma_bind,
59 .unbind = nv04_sgdma_unbind,
60 .destroy = nouveau_sgdma_destroy
63 static int
64 nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
66 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
67 struct nouveau_mem *node = mem->mm_node;
69 /* noop: bound in move_notify() */
70 if (ttm->sg) {
71 node->sg = ttm->sg;
72 node->pages = NULL;
73 } else {
74 node->sg = NULL;
75 node->pages = nvbe->ttm.dma_address;
77 node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
78 return 0;
81 static int
82 nv50_sgdma_unbind(struct ttm_tt *ttm)
84 /* noop: unbound in move_notify() */
85 return 0;
88 static struct ttm_backend_func nv50_sgdma_backend = {
89 .bind = nv50_sgdma_bind,
90 .unbind = nv50_sgdma_unbind,
91 .destroy = nouveau_sgdma_destroy
94 struct ttm_tt *
95 nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,
96 unsigned long size, uint32_t page_flags,
97 struct page *dummy_read_page)
99 struct nouveau_drm *drm = nouveau_bdev(bdev);
100 struct nouveau_sgdma_be *nvbe;
102 nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
103 if (!nvbe)
104 return NULL;
106 nvbe->dev = drm->dev;
107 if (nv_device(drm->device)->card_type < NV_50)
108 nvbe->ttm.ttm.func = &nv04_sgdma_backend;
109 else
110 nvbe->ttm.ttm.func = &nv50_sgdma_backend;
112 if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page))
113 return NULL;
114 return &nvbe->ttm.ttm;