1 #include <linux/pagemap.h>
2 #include <linux/slab.h>
4 #include "nouveau_drv.h"
5 #include "nouveau_mem.h"
6 #include "nouveau_ttm.h"
8 struct nouveau_sgdma_be {
9 /* this has to be the first field so populate/unpopulated in
10 * nouve_bo.c works properly, otherwise have to move them here
12 struct ttm_dma_tt ttm;
13 struct nouveau_mem *mem;
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 *reg)
30 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
31 struct nouveau_mem *mem = nouveau_mem(reg);
34 ret = nouveau_mem_host(reg, &nvbe->ttm);
38 ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
40 nouveau_mem_fini(mem);
49 nv04_sgdma_unbind(struct ttm_tt *ttm)
51 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
52 nouveau_mem_fini(nvbe->mem);
56 static struct ttm_backend_func nv04_sgdma_backend = {
57 .bind = nv04_sgdma_bind,
58 .unbind = nv04_sgdma_unbind,
59 .destroy = nouveau_sgdma_destroy
63 nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *reg)
65 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
66 struct nouveau_mem *mem = nouveau_mem(reg);
69 ret = nouveau_mem_host(reg, &nvbe->ttm);
77 static struct ttm_backend_func nv50_sgdma_backend = {
78 .bind = nv50_sgdma_bind,
79 .unbind = nv04_sgdma_unbind,
80 .destroy = nouveau_sgdma_destroy
84 nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,
85 unsigned long size, uint32_t page_flags,
86 struct page *dummy_read_page)
88 struct nouveau_drm *drm = nouveau_bdev(bdev);
89 struct nouveau_sgdma_be *nvbe;
91 nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
95 if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA)
96 nvbe->ttm.ttm.func = &nv04_sgdma_backend;
98 nvbe->ttm.ttm.func = &nv50_sgdma_backend;
100 if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page))
102 * A failing ttm_dma_tt_init() will call ttm_tt_destroy()
103 * and thus our nouveau_sgdma_destroy() hook, so we don't need
107 return &nvbe->ttm.ttm;