1 // SPDX-License-Identifier: MIT
2 #include <linux/pagemap.h>
3 #include <linux/slab.h>
5 #include "nouveau_drv.h"
6 #include "nouveau_mem.h"
7 #include "nouveau_ttm.h"
9 struct nouveau_sgdma_be {
10 /* this has to be the first field so populate/unpopulated in
11 * nouve_bo.c works properly, otherwise have to move them here
13 struct ttm_dma_tt ttm;
14 struct nouveau_mem *mem;
18 nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
20 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
23 nouveau_sgdma_unbind(bdev, ttm);
24 ttm_tt_destroy_common(bdev, ttm);
25 ttm_dma_tt_fini(&nvbe->ttm);
31 nouveau_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
33 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
34 struct nouveau_drm *drm = nouveau_bdev(bdev);
35 struct nouveau_mem *mem = nouveau_mem(reg);
41 ret = nouveau_mem_host(reg, &nvbe->ttm);
45 if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
46 ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
48 nouveau_mem_fini(mem);
58 nouveau_sgdma_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
60 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
62 nouveau_mem_fini(nvbe->mem);
68 nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
70 struct nouveau_sgdma_be *nvbe;
72 nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
76 if (ttm_dma_tt_init(&nvbe->ttm, bo, page_flags)) {
80 return &nvbe->ttm.ttm;