diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 01:02:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 01:02:30 +0000 |
commit | 76cb841cb886eef6b3bee341a2266c76578724ad (patch) | |
tree | f5892e5ba6cc11949952a6ce4ecbe6d516d6ce58 /drivers/gpu/drm/nouveau/nouveau_sgdma.c | |
parent | Initial commit. (diff) | |
download | linux-76cb841cb886eef6b3bee341a2266c76578724ad.tar.xz linux-76cb841cb886eef6b3bee341a2266c76578724ad.zip |
Adding upstream version 4.19.249.upstream/4.19.249
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'drivers/gpu/drm/nouveau/nouveau_sgdma.c')
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_sgdma.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_sgdma.c b/drivers/gpu/drm/nouveau/nouveau_sgdma.c new file mode 100644 index 000000000..326948b65 --- /dev/null +++ b/drivers/gpu/drm/nouveau/nouveau_sgdma.c @@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/pagemap.h> +#include <linux/slab.h> + +#include "nouveau_drv.h" +#include "nouveau_mem.h" +#include "nouveau_ttm.h" + +struct nouveau_sgdma_be { + /* this has to be the first field so populate/unpopulated in + * nouve_bo.c works properly, otherwise have to move them here + */ + struct ttm_dma_tt ttm; + struct nouveau_mem *mem; +}; + +static void +nouveau_sgdma_destroy(struct ttm_tt *ttm) +{ + struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; + + if (ttm) { + ttm_dma_tt_fini(&nvbe->ttm); + kfree(nvbe); + } +} + +static int +nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *reg) +{ + struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; + struct nouveau_mem *mem = nouveau_mem(reg); + int ret; + + ret = nouveau_mem_host(reg, &nvbe->ttm); + if (ret) + return ret; + + ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]); + if (ret) { + nouveau_mem_fini(mem); + return ret; + } + + nvbe->mem = mem; + return 0; +} + +static int +nv04_sgdma_unbind(struct ttm_tt *ttm) +{ + struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; + nouveau_mem_fini(nvbe->mem); + return 0; +} + +static struct ttm_backend_func nv04_sgdma_backend = { + .bind = nv04_sgdma_bind, + .unbind = nv04_sgdma_unbind, + .destroy = nouveau_sgdma_destroy +}; + +static int +nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *reg) +{ + struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm; + struct nouveau_mem *mem = nouveau_mem(reg); + int ret; + + ret = nouveau_mem_host(reg, &nvbe->ttm); + if (ret) + return ret; + + nvbe->mem = mem; + return 0; +} + +static struct ttm_backend_func nv50_sgdma_backend = { + .bind = nv50_sgdma_bind, + .unbind = nv04_sgdma_unbind, + .destroy = nouveau_sgdma_destroy +}; + +struct ttm_tt * +nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags) +{ + struct nouveau_drm *drm = nouveau_bdev(bo->bdev); + struct nouveau_sgdma_be *nvbe; + + nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL); + if (!nvbe) + return NULL; + + if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) + nvbe->ttm.ttm.func = &nv04_sgdma_backend; + else + nvbe->ttm.ttm.func = &nv50_sgdma_backend; + + if (ttm_dma_tt_init(&nvbe->ttm, bo, page_flags)) { + kfree(nvbe); + return NULL; + } + return &nvbe->ttm.ttm; +} |