1 #include <linux/pagemap.h>
2 #include <linux/slab.h>
4 #include "nouveau_drm.h"
5 #include "nouveau_ttm.h"
7 struct nouveau_sgdma_be {
8 /* this has to be the first field so populate/unpopulated in
9 * nouve_bo.c works properly, otherwise have to move them here
11 struct ttm_dma_tt ttm;
12 struct drm_device *dev;
13 struct nouveau_mem *node;
17 nouveau_sgdma_destroy(struct ttm_tt *ttm)
19 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
22 ttm_dma_tt_fini(&nvbe->ttm);
28 nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
30 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
31 struct nouveau_mem *node = mem->mm_node;
38 node->pages = nvbe->ttm.dma_address;
40 node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
42 nouveau_vm_map(&node->vma[0], node);
48 nv04_sgdma_unbind(struct ttm_tt *ttm)
50 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
51 nouveau_vm_unmap(&nvbe->node->vma[0]);
55 static struct ttm_backend_func nv04_sgdma_backend = {
56 .bind = nv04_sgdma_bind,
57 .unbind = nv04_sgdma_unbind,
58 .destroy = nouveau_sgdma_destroy
62 nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
64 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
65 struct nouveau_mem *node = mem->mm_node;
67 /* noop: bound in move_notify() */
73 node->pages = nvbe->ttm.dma_address;
75 node->size = (mem->num_pages << PAGE_SHIFT) >> 12;
80 nv50_sgdma_unbind(struct ttm_tt *ttm)
82 /* noop: unbound in move_notify() */
86 static struct ttm_backend_func nv50_sgdma_backend = {
87 .bind = nv50_sgdma_bind,
88 .unbind = nv50_sgdma_unbind,
89 .destroy = nouveau_sgdma_destroy
93 nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,
94 unsigned long size, uint32_t page_flags,
95 struct page *dummy_read_page)
97 struct nouveau_drm *drm = nouveau_bdev(bdev);
98 struct nouveau_sgdma_be *nvbe;
100 nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
104 nvbe->dev = drm->dev;
105 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA)
106 nvbe->ttm.ttm.func = &nv04_sgdma_backend;
108 nvbe->ttm.ttm.func = &nv50_sgdma_backend;
110 if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page))
112 return &nvbe->ttm.ttm;