1 // SPDX-License-Identifier: MIT
2 #include <linux/pagemap.h>
3 #include <linux/slab.h>
4 #include <drm/ttm/ttm_tt.h>
6 #include "nouveau_drv.h"
7 #include "nouveau_mem.h"
8 #include "nouveau_ttm.h"
9 #include "nouveau_bo.h"
11 struct nouveau_sgdma_be {
12 /* this has to be the first field so populate/unpopulated in
13 * nouve_bo.c works properly, otherwise have to move them here
16 struct nouveau_mem *mem;
20 nouveau_sgdma_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
22 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
25 ttm_tt_fini(&nvbe->ttm);
31 nouveau_sgdma_bind(struct ttm_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_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_drm *drm = nouveau_bdev(bo->bdev);
71 struct nouveau_bo *nvbo = nouveau_bo(bo);
72 struct nouveau_sgdma_be *nvbe;
73 enum ttm_caching caching;
75 if (nvbo->force_coherent)
76 caching = ttm_uncached;
77 else if (drm->agp.bridge)
78 caching = ttm_write_combined;
82 nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
86 if (ttm_sg_tt_init(&nvbe->ttm, bo, page_flags, caching)) {