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"
8 #include "nouveau_bo.h"
10 struct nouveau_sgdma_be {
11 /* this has to be the first field so populate/unpopulated in
12 * nouve_bo.c works properly, otherwise have to move them here
15 struct nouveau_mem *mem;
19 nouveau_sgdma_destroy(struct ttm_device *bdev, struct ttm_tt *ttm)
21 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
24 nouveau_sgdma_unbind(bdev, ttm);
25 ttm_tt_destroy_common(bdev, ttm);
26 ttm_tt_fini(&nvbe->ttm);
32 nouveau_sgdma_bind(struct ttm_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
34 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
35 struct nouveau_drm *drm = nouveau_bdev(bdev);
36 struct nouveau_mem *mem = nouveau_mem(reg);
42 ret = nouveau_mem_host(reg, &nvbe->ttm);
46 if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
47 ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
49 nouveau_mem_fini(mem);
59 nouveau_sgdma_unbind(struct ttm_device *bdev, struct ttm_tt *ttm)
61 struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
63 nouveau_mem_fini(nvbe->mem);
69 nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
71 struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
72 struct nouveau_bo *nvbo = nouveau_bo(bo);
73 struct nouveau_sgdma_be *nvbe;
74 enum ttm_caching caching;
76 if (nvbo->force_coherent)
77 caching = ttm_uncached;
78 else if (drm->agp.bridge)
79 caching = ttm_write_combined;
83 nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
87 if (ttm_sg_tt_init(&nvbe->ttm, bo, page_flags, caching)) {