iris: Add support for userptr in Xe KMD

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 <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23817>
This commit is contained in:
José Roberto de Souza 2023-07-18 11:56:25 -07:00 committed by Marge Bot
parent b38f7834f5
commit fa73130d9b
2 changed files with 16 additions and 3 deletions

View file

@ -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:

View file

@ -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)