1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/pagemap.h>
3 #include <linux/slab.h>
5 #include "nouveau_drv.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 nvkm_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 *reg)
30 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
31 struct nvkm_mem *node = reg->mm_node;
38 node->pages = nvbe->ttm.dma_address;
40 node->size = (reg->num_pages << PAGE_SHIFT) >> 12;
42 nvkm_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 nvkm_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 *reg)
64 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
65 struct nvkm_mem *node = reg->mm_node;
67 /* noop: bound in move_notify() */
73 node->pages = nvbe->ttm.dma_address;
75 node->size = (reg->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 if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA)
105 nvbe->ttm.ttm.func = &nv04_sgdma_backend;
107 nvbe->ttm.ttm.func = &nv50_sgdma_backend;
109 if (ttm_dma_tt_init(&nvbe->ttm, bdev, size, page_flags, dummy_read_page))
111 * A failing ttm_dma_tt_init() will call ttm_tt_destroy()
112 * and thus our nouveau_sgdma_destroy() hook, so we don't need
116 return &nvbe->ttm.ttm;