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