From fa73130d9b1c12a22bc591aa958779e9f83e762f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Tue, 18 Jul 2023 11:56:25 -0700 Subject: [PATCH] iris: Add support for userptr in Xe KMD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Xe KMD only requires userptr to be bound to VM, so here returning UINT32_MAX as gem_handle in Xe version of gem_create_userptr() for all userptr bos. As no bo is created it was also necessary to add additional handling to xe_gem_close(). The vm bind side of userptr was already implemented, so it was only necessary add the special handling and the kmd vm bind call. This fixes piglit@amd_pinned_memory subtests that makes uses of userptr. Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/gallium/drivers/iris/iris_bufmgr.c | 7 ++++++- src/gallium/drivers/iris/xe/iris_kmd_backend.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index d713c8d198b..fd4f01e6cc9 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -1290,6 +1290,7 @@ iris_bo_create_userptr(struct iris_bufmgr *bufmgr, const char *name, bo->name = name; bo->size = size; bo->real.map = ptr; + bo->real.userptr = true; bo->bufmgr = bufmgr; bo->real.kflags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS | EXEC_OBJECT_PINNED; @@ -1305,15 +1306,19 @@ iris_bo_create_userptr(struct iris_bufmgr *bufmgr, const char *name, goto err_close; p_atomic_set(&bo->refcount, 1); - bo->real.userptr = true; bo->index = -1; bo->idle = true; bo->real.heap = IRIS_HEAP_SYSTEM_MEMORY; bo->real.mmap_mode = iris_bo_create_userptr_get_mmap_mode(bufmgr); bo->real.prime_fd = -1; + if (!bufmgr->kmd_backend->gem_vm_bind(bo)) + goto err_vma_free; + return bo; +err_vma_free: + vma_free(bufmgr, bo->address, bo->size); err_close: bufmgr->kmd_backend->gem_close(bufmgr, bo); err_free: diff --git a/src/gallium/drivers/iris/xe/iris_kmd_backend.c b/src/gallium/drivers/iris/xe/iris_kmd_backend.c index 031f6966892..a9a2019323c 100644 --- a/src/gallium/drivers/iris/xe/iris_kmd_backend.c +++ b/src/gallium/drivers/iris/xe/iris_kmd_backend.c @@ -430,6 +430,9 @@ error_implicit_sync_import: static int xe_gem_close(struct iris_bufmgr *bufmgr, struct iris_bo *bo) { + if (bo->real.userptr) + return 0; + struct drm_gem_close close = { .handle = bo->gem_handle, }; @@ -439,8 +442,13 @@ xe_gem_close(struct iris_bufmgr *bufmgr, struct iris_bo *bo) static uint32_t xe_gem_create_userptr(struct iris_bufmgr *bufmgr, void *ptr, uint64_t size) { - /* We return 0, because Xe doesn't create handles for userptrs. */ - return 0; + /* We return UINT32_MAX, because Xe doesn't create handles for userptrs but + * it needs a gem_handle different than 0 so iris_bo_is_real() returns true + * for userptr bos. + * UINT32_MAX handle here will not conflict with an actual gem handle with + * same id as userptr bos are not put to slab or bo cache. + */ + return UINT32_MAX; } const struct iris_kmd_backend *xe_get_backend(void)