| .. | .. |
|---|
| 1 | | -// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | +// SPDX-License-Identifier: MIT |
|---|
| 2 | 2 | #include <linux/pagemap.h> |
|---|
| 3 | 3 | #include <linux/slab.h> |
|---|
| 4 | 4 | |
|---|
| .. | .. |
|---|
| 14 | 14 | struct nouveau_mem *mem; |
|---|
| 15 | 15 | }; |
|---|
| 16 | 16 | |
|---|
| 17 | | -static void |
|---|
| 18 | | -nouveau_sgdma_destroy(struct ttm_tt *ttm) |
|---|
| 17 | +void |
|---|
| 18 | +nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm) |
|---|
| 19 | 19 | { |
|---|
| 20 | 20 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
|---|
| 21 | 21 | |
|---|
| 22 | 22 | if (ttm) { |
|---|
| 23 | + nouveau_sgdma_unbind(bdev, ttm); |
|---|
| 24 | + ttm_tt_destroy_common(bdev, ttm); |
|---|
| 23 | 25 | ttm_dma_tt_fini(&nvbe->ttm); |
|---|
| 24 | 26 | kfree(nvbe); |
|---|
| 25 | 27 | } |
|---|
| 26 | 28 | } |
|---|
| 27 | 29 | |
|---|
| 28 | | -static int |
|---|
| 29 | | -nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *reg) |
|---|
| 30 | +int |
|---|
| 31 | +nouveau_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg) |
|---|
| 30 | 32 | { |
|---|
| 31 | 33 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
|---|
| 34 | + struct nouveau_drm *drm = nouveau_bdev(bdev); |
|---|
| 32 | 35 | struct nouveau_mem *mem = nouveau_mem(reg); |
|---|
| 33 | 36 | int ret; |
|---|
| 37 | + |
|---|
| 38 | + if (nvbe->mem) |
|---|
| 39 | + return 0; |
|---|
| 34 | 40 | |
|---|
| 35 | 41 | ret = nouveau_mem_host(reg, &nvbe->ttm); |
|---|
| 36 | 42 | if (ret) |
|---|
| 37 | 43 | return ret; |
|---|
| 38 | 44 | |
|---|
| 39 | | - ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]); |
|---|
| 40 | | - if (ret) { |
|---|
| 41 | | - nouveau_mem_fini(mem); |
|---|
| 42 | | - return ret; |
|---|
| 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]); |
|---|
| 47 | + if (ret) { |
|---|
| 48 | + nouveau_mem_fini(mem); |
|---|
| 49 | + return ret; |
|---|
| 50 | + } |
|---|
| 43 | 51 | } |
|---|
| 44 | 52 | |
|---|
| 45 | 53 | nvbe->mem = mem; |
|---|
| 46 | 54 | return 0; |
|---|
| 47 | 55 | } |
|---|
| 48 | 56 | |
|---|
| 49 | | -static int |
|---|
| 50 | | -nv04_sgdma_unbind(struct ttm_tt *ttm) |
|---|
| 57 | +void |
|---|
| 58 | +nouveau_sgdma_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm) |
|---|
| 51 | 59 | { |
|---|
| 52 | 60 | struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
|---|
| 53 | | - nouveau_mem_fini(nvbe->mem); |
|---|
| 54 | | - return 0; |
|---|
| 61 | + if (nvbe->mem) { |
|---|
| 62 | + nouveau_mem_fini(nvbe->mem); |
|---|
| 63 | + nvbe->mem = NULL; |
|---|
| 64 | + } |
|---|
| 55 | 65 | } |
|---|
| 56 | | - |
|---|
| 57 | | -static struct ttm_backend_func nv04_sgdma_backend = { |
|---|
| 58 | | - .bind = nv04_sgdma_bind, |
|---|
| 59 | | - .unbind = nv04_sgdma_unbind, |
|---|
| 60 | | - .destroy = nouveau_sgdma_destroy |
|---|
| 61 | | -}; |
|---|
| 62 | | - |
|---|
| 63 | | -static int |
|---|
| 64 | | -nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *reg) |
|---|
| 65 | | -{ |
|---|
| 66 | | - struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; |
|---|
| 67 | | - struct nouveau_mem *mem = nouveau_mem(reg); |
|---|
| 68 | | - int ret; |
|---|
| 69 | | - |
|---|
| 70 | | - ret = nouveau_mem_host(reg, &nvbe->ttm); |
|---|
| 71 | | - if (ret) |
|---|
| 72 | | - return ret; |
|---|
| 73 | | - |
|---|
| 74 | | - nvbe->mem = mem; |
|---|
| 75 | | - return 0; |
|---|
| 76 | | -} |
|---|
| 77 | | - |
|---|
| 78 | | -static struct ttm_backend_func nv50_sgdma_backend = { |
|---|
| 79 | | - .bind = nv50_sgdma_bind, |
|---|
| 80 | | - .unbind = nv04_sgdma_unbind, |
|---|
| 81 | | - .destroy = nouveau_sgdma_destroy |
|---|
| 82 | | -}; |
|---|
| 83 | 66 | |
|---|
| 84 | 67 | struct ttm_tt * |
|---|
| 85 | 68 | nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags) |
|---|
| 86 | 69 | { |
|---|
| 87 | | - struct nouveau_drm *drm = nouveau_bdev(bo->bdev); |
|---|
| 88 | 70 | struct nouveau_sgdma_be *nvbe; |
|---|
| 89 | 71 | |
|---|
| 90 | 72 | nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL); |
|---|
| 91 | 73 | if (!nvbe) |
|---|
| 92 | 74 | return NULL; |
|---|
| 93 | | - |
|---|
| 94 | | - if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) |
|---|
| 95 | | - nvbe->ttm.ttm.func = &nv04_sgdma_backend; |
|---|
| 96 | | - else |
|---|
| 97 | | - nvbe->ttm.ttm.func = &nv50_sgdma_backend; |
|---|
| 98 | 75 | |
|---|
| 99 | 76 | if (ttm_dma_tt_init(&nvbe->ttm, bo, page_flags)) { |
|---|
| 100 | 77 | kfree(nvbe); |
|---|