diff options
author | Jérôme Glisse <jglisse@redhat.com> | 2017-08-09 14:55:23 -0400 |
---|---|---|
committer | Jérôme Glisse <jglisse@redhat.com> | 2017-08-29 10:35:02 -0400 |
commit | 68ab8cfe40ac357acc200fa927b8d92708deb447 (patch) | |
tree | c6b4c7578737b4168749c9368bd4dbd36e4a643b | |
parent | f89339200932c3c06aec8787746e691ef6320094 (diff) |
drm/nouveau/compote: add buffer vma on mmap through device file
Add nvkm_vma when buffer is mmap through device file so that same
CPU virtual address can be use on GPU too.
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
-rw-r--r-- | drivers/gpu/drm/nouveau/compote/compote-memory.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/gpu/drm/nouveau/compote/compote-memory.c b/drivers/gpu/drm/nouveau/compote/compote-memory.c index 8435ec0a8d03..5c7944d8672a 100644 --- a/drivers/gpu/drm/nouveau/compote/compote-memory.c +++ b/drivers/gpu/drm/nouveau/compote/compote-memory.c @@ -206,6 +206,7 @@ int compote_mo_mmap(struct compote_file *cfile, { struct ttm_bo_device *bdev = &cfile->cdevice->nvdrm->ttm.bdev; struct compote_mo_va *mo_va; + struct nvkm_vma *nvvma; struct compote_mo *mo; int ret; @@ -217,6 +218,29 @@ int compote_mo_mmap(struct compote_file *cfile, if (mo_va == NULL) return -ENOMEM; + nvvma = kzalloc(sizeof(*nvvma), GFP_KERNEL); + if (nvvma == NULL) { + kfree(mo_va); + return -ENOMEM; + } + nvvma->skip = (vma->vm_pgoff << PAGE_SHIFT) - mo->foffset; + + ret = ttm_bo_reserve(&mo->nvbo->bo, false, false, NULL); + if (ret) { + kfree(nvvma); + kfree(mo_va); + return ret; + } + ret = nouveau_bo_vma_add_fix(mo->nvbo, cfile->nvclient.vm, nvvma, + vma->vm_start, vma->vm_end - + vma->vm_start); + ttm_bo_unreserve(&mo->nvbo->bo); + if (ret) { + kfree(nvvma); + kfree(mo_va); + return ret; + } + mo_va->mo = mo; mo_va->start = vma->vm_start; mo_va->end = vma->vm_end; @@ -224,7 +248,12 @@ int compote_mo_mmap(struct compote_file *cfile, ret = ttm_bo_mmap(file, vma, bdev); if (unlikely(ret != 0)) { + if (!ttm_bo_reserve(&mo->nvbo->bo, false, false, NULL)) { + nouveau_bo_vma_del(mo->nvbo, nvvma); + ttm_bo_unreserve(&mo->nvbo->bo); + } compote_mo_unref(mo); + kfree(nvvma); kfree(mo_va); return ret; } |