Commit | Line | Data |
---|---|---|
6ee73861 | 1 | #include <linux/pagemap.h> |
5a0e3ad6 | 2 | #include <linux/slab.h> |
6ee73861 | 3 | |
ebb945a9 BS |
4 | #include <subdev/fb.h> |
5 | ||
6 | #include "nouveau_drm.h" | |
7 | #include "nouveau_ttm.h" | |
6ee73861 BS |
8 | |
9 | struct nouveau_sgdma_be { | |
8e7e7052 JG |
10 | /* this has to be the first field so populate/unpopulated in |
11 | * nouve_bo.c works properly, otherwise have to move them here | |
12 | */ | |
13 | struct ttm_dma_tt ttm; | |
6ee73861 | 14 | struct drm_device *dev; |
3863c9bc | 15 | struct nouveau_mem *node; |
6ee73861 BS |
16 | }; |
17 | ||
efa58db3 | 18 | static void |
649bf3ca | 19 | nouveau_sgdma_destroy(struct ttm_tt *ttm) |
efa58db3 | 20 | { |
649bf3ca | 21 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
efa58db3 | 22 | |
649bf3ca | 23 | if (ttm) { |
8e7e7052 | 24 | ttm_dma_tt_fini(&nvbe->ttm); |
649bf3ca | 25 | kfree(nvbe); |
efa58db3 BS |
26 | } |
27 | } | |
28 | ||
6ee73861 | 29 | static int |
649bf3ca | 30 | nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem) |
6ee73861 | 31 | { |
649bf3ca | 32 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
3863c9bc BS |
33 | struct nouveau_mem *node = mem->mm_node; |
34 | u64 size = mem->num_pages << 12; | |
6ee73861 | 35 | |
3863c9bc BS |
36 | if (ttm->sg) { |
37 | node->sg = ttm->sg; | |
38 | nouveau_vm_map_sg_table(&node->vma[0], 0, size, node); | |
39 | } else { | |
40 | node->pages = nvbe->ttm.dma_address; | |
41 | nouveau_vm_map_sg(&node->vma[0], 0, size, node); | |
6ee73861 | 42 | } |
6ee73861 | 43 | |
3863c9bc | 44 | nvbe->node = node; |
6ee73861 BS |
45 | return 0; |
46 | } | |
47 | ||
48 | static int | |
649bf3ca | 49 | nv04_sgdma_unbind(struct ttm_tt *ttm) |
6ee73861 | 50 | { |
649bf3ca | 51 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
3863c9bc | 52 | nouveau_vm_unmap(&nvbe->node->vma[0]); |
6ee73861 BS |
53 | return 0; |
54 | } | |
55 | ||
efa58db3 | 56 | static struct ttm_backend_func nv04_sgdma_backend = { |
efa58db3 BS |
57 | .bind = nv04_sgdma_bind, |
58 | .unbind = nv04_sgdma_unbind, | |
59 | .destroy = nouveau_sgdma_destroy | |
60 | }; | |
6ee73861 | 61 | |
b571fe21 | 62 | static int |
649bf3ca | 63 | nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem) |
b571fe21 | 64 | { |
8e7e7052 | 65 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
26c0c9e3 | 66 | struct nouveau_mem *node = mem->mm_node; |
649bf3ca | 67 | |
26c0c9e3 | 68 | /* noop: bound in move_notify() */ |
22b33e8e DA |
69 | if (ttm->sg) { |
70 | node->sg = ttm->sg; | |
71 | } else | |
72 | node->pages = nvbe->ttm.dma_address; | |
b571fe21 BS |
73 | return 0; |
74 | } | |
75 | ||
76 | static int | |
649bf3ca | 77 | nv50_sgdma_unbind(struct ttm_tt *ttm) |
b571fe21 | 78 | { |
26c0c9e3 | 79 | /* noop: unbound in move_notify() */ |
b571fe21 BS |
80 | return 0; |
81 | } | |
82 | ||
b571fe21 | 83 | static struct ttm_backend_func nv50_sgdma_backend = { |
b571fe21 BS |
84 | .bind = nv50_sgdma_bind, |
85 | .unbind = nv50_sgdma_unbind, | |
86 | .destroy = nouveau_sgdma_destroy | |
87 | }; | |
88 | ||
649bf3ca JG |
89 | struct ttm_tt * |
90 | nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev, | |
91 | unsigned long size, uint32_t page_flags, | |
92 | struct page *dummy_read_page) | |
6ee73861 | 93 | { |
ebb945a9 | 94 | struct nouveau_drm *drm = nouveau_bdev(bdev); |
6ee73861 BS |
95 | struct nouveau_sgdma_be *nvbe; |
96 | ||
6ee73861 BS |
97 | nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL); |
98 | if (!nvbe) | |
99 | return NULL; | |
100 | ||
ebb945a9 BS |
101 | nvbe->dev = drm->dev; |
102 | if (nv_device(drm->device)->card_type < NV_50) | |
103 | nvbe->ttm.ttm.func = &nv04_sgdma_backend; | |
104 | else | |
105 | nvbe->ttm.ttm.func = &nv50_sgdma_backend; | |
6ee73861 | 106 | |
7a59cc34 | 107 | if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page)) |
649bf3ca | 108 | return NULL; |
8e7e7052 | 109 | return &nvbe->ttm.ttm; |
6ee73861 | 110 | } |