From c83a76339f69f487108aefd720bc72f4dd09b6f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Tue, 1 Nov 2022 11:07:16 -0700 Subject: [PATCH] iris: Add vm bind and unbind to kmd backend MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit At this time this is a nop for i915 but in future we will have a Xe implementation. Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/gallium/drivers/iris/i915/iris_kmd_backend.c | 18 ++++++++++++ src/gallium/drivers/iris/iris_bufmgr.c | 35 ++++++++++++++++++++++-- src/gallium/drivers/iris/iris_kmd_backend.h | 2 ++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/iris/i915/iris_kmd_backend.c b/src/gallium/drivers/iris/i915/iris_kmd_backend.c index 3797129..d529700 100644 --- a/src/gallium/drivers/iris/i915/iris_kmd_backend.c +++ b/src/gallium/drivers/iris/i915/iris_kmd_backend.c @@ -358,6 +358,22 @@ i915_batch_submit(struct iris_batch *batch) return ret; } +static bool +i915_gem_vm_bind(struct iris_bo *bo) +{ + /* + * i915 does not support VM_BIND yet. The binding operation happens at + * submission when we supply BO handle & offset in the execbuffer list. + */ + return true; +} + +static bool +i915_gem_vm_unbind(struct iris_bo *bo) +{ + return true; +} + const struct iris_kmd_backend *i915_get_backend(void) { static const struct iris_kmd_backend i915_backend = { @@ -367,6 +383,8 @@ const struct iris_kmd_backend *i915_get_backend(void) .gem_mmap = i915_gem_mmap, .batch_check_for_reset = i915_batch_check_for_reset, .batch_submit = i915_batch_submit, + .gem_vm_bind = i915_gem_vm_bind, + .gem_vm_unbind = i915_gem_vm_unbind, }; return &i915_backend; } diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 5bcc99e..6422438 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -931,6 +931,12 @@ alloc_bo_from_cache(struct iris_bufmgr *bufmgr, */ if (memzone != iris_memzone_for_address(cur->address) || cur->address % alignment != 0) { + if (!bufmgr->kmd_backend->gem_vm_unbind(cur)) { + DBG("Unable to unbind vm of buf %u\n", cur->gem_handle); + bo_free(cur); + continue; + } + vma_free(bufmgr, cur->address, cur->size); cur->address = 0ull; } @@ -1101,6 +1107,9 @@ iris_bo_alloc(struct iris_bufmgr *bufmgr, if (bo->address == 0ull) goto err_free; + + if (!bufmgr->kmd_backend->gem_vm_bind(bo)) + goto err_vm_alloc; } bo->name = name; @@ -1136,6 +1145,8 @@ iris_bo_alloc(struct iris_bufmgr *bufmgr, return bo; +err_vm_alloc: + vma_free(bufmgr, bo->address, bo->size); err_free: simple_mtx_lock(&bufmgr->lock); bo_free(bo); @@ -1266,6 +1277,9 @@ iris_bo_gem_create_from_name(struct iris_bufmgr *bufmgr, if (bo->address == 0ull) goto err_free; + if (!bufmgr->kmd_backend->gem_vm_bind(bo)) + goto err_vm_alloc; + _mesa_hash_table_insert(bufmgr->handle_table, &bo->gem_handle, bo); _mesa_hash_table_insert(bufmgr->name_table, &bo->real.global_name, bo); @@ -1275,6 +1289,8 @@ out: simple_mtx_unlock(&bufmgr->lock); return bo; +err_vm_alloc: + vma_free(bufmgr, bo->address, bo->size); err_free: bo_free(bo); simple_mtx_unlock(&bufmgr->lock); @@ -1312,6 +1328,12 @@ bo_close(struct iris_bo *bo) assert(list_is_empty(&bo->real.exports)); } + /* Unbind and return the VMA for reuse */ + if (bufmgr->kmd_backend->gem_vm_unbind(bo)) + vma_free(bo->bufmgr, bo->address, bo->size); + else + DBG("Unable to unbind vm of buf %u\n", bo->gem_handle); + /* Close this object */ struct drm_gem_close close = { .handle = bo->gem_handle }; int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_GEM_CLOSE, &close); @@ -1325,9 +1347,6 @@ bo_close(struct iris_bo *bo) bo->size); } - /* Return the VMA for reuse */ - vma_free(bo->bufmgr, bo->address, bo->size); - for (int d = 0; d < bo->deps_size; d++) { for (int b = 0; b < IRIS_BATCH_COUNT; b++) { iris_syncobj_reference(bufmgr, &bo->deps[d].write_syncobjs[b], NULL); @@ -1824,12 +1843,17 @@ iris_bo_import_dmabuf(struct iris_bufmgr *bufmgr, int prime_fd) if (bo->address == 0ull) goto err_free; + if (!bufmgr->kmd_backend->gem_vm_bind(bo)) + goto err_vm_alloc; + _mesa_hash_table_insert(bufmgr->handle_table, &bo->gem_handle, bo); out: simple_mtx_unlock(&bufmgr->lock); return bo; +err_vm_alloc: + vma_free(bufmgr, bo->address, bo->size); err_free: bo_free(bo); simple_mtx_unlock(&bufmgr->lock); @@ -2065,6 +2089,9 @@ intel_aux_map_buffer_alloc(void *driver_ctx, uint32_t size) if (bo->address == 0ull) goto err_free; + if (!bufmgr->kmd_backend->gem_vm_bind(bo)) + goto err_vm_alloc; + simple_mtx_unlock(&bufmgr->lock); bo->name = "aux-map"; @@ -2081,6 +2108,8 @@ intel_aux_map_buffer_alloc(void *driver_ctx, uint32_t size) buf->map = iris_bo_map(NULL, bo, MAP_WRITE | MAP_RAW); return buf; +err_vm_alloc: + vma_free(bufmgr, bo->address, bo->size); err_free: free(buf); bo_free(bo); diff --git a/src/gallium/drivers/iris/iris_kmd_backend.h b/src/gallium/drivers/iris/iris_kmd_backend.h index f667564..f47837a 100644 --- a/src/gallium/drivers/iris/iris_kmd_backend.h +++ b/src/gallium/drivers/iris/iris_kmd_backend.h @@ -44,6 +44,8 @@ struct iris_kmd_backend { void *(*gem_mmap)(struct iris_bufmgr *bufmgr, struct iris_bo *bo); enum pipe_reset_status (*batch_check_for_reset)(struct iris_batch *batch); int (*batch_submit)(struct iris_batch *batch); + bool (*gem_vm_bind)(struct iris_bo *bo); + bool (*gem_vm_unbind)(struct iris_bo *bo); }; const struct iris_kmd_backend * -- 2.7.4