iris: Move iris_bufmgr_bo_close() to kmd backend

The next patch will need a special handling when closing userptr bos
in Xe KMD, so here moving iris_bufmgr_bo_close() to kmd backend
and changing the gem_handle parameter to iris_bo.

There still one DRM_IOCTL_GEM_CLOSE call left in iris_bufmgr, that
is used to close exported gem handles.
iris_bufmgr_get_for_fd() could be used to get the iris_bufmgr but
we would still have problems with bo_export != iris_bo, so leaving
as is until a better solution is found.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Marcin Ślusarz <marcin.slusarz@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:53:46 -07:00 committed by Marge Bot
parent 36bc3da586
commit 0698bc9e5a
4 changed files with 27 additions and 9 deletions

View file

@ -412,10 +412,20 @@ i915_gem_vm_unbind(struct iris_bo *bo)
return true;
}
static int
i915_gem_close(struct iris_bufmgr *bufmgr, struct iris_bo *bo)
{
struct drm_gem_close close = {
.handle = bo->gem_handle,
};
return intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_GEM_CLOSE, &close);
}
const struct iris_kmd_backend *i915_get_backend(void)
{
static const struct iris_kmd_backend i915_backend = {
.gem_create = i915_gem_create,
.gem_close = i915_gem_close,
.bo_madvise = i915_bo_madvise,
.bo_set_caching = i915_bo_set_caching,
.gem_mmap = i915_gem_mmap,

View file

@ -1272,12 +1272,6 @@ iris_bo_close(int fd, uint32_t gem_handle)
return intel_ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
}
static int
iris_bufmgr_bo_close(struct iris_bufmgr *bufmgr, uint32_t gem_handle)
{
return iris_bo_close(bufmgr->fd, gem_handle);
}
static enum iris_mmap_mode
iris_bo_create_userptr_get_mmap_mode(struct iris_bufmgr *bufmgr)
{
@ -1345,7 +1339,7 @@ iris_bo_create_userptr(struct iris_bufmgr *bufmgr, const char *name,
return bo;
err_close:
iris_bufmgr_bo_close(bufmgr, bo->gem_handle);
bufmgr->kmd_backend->gem_close(bufmgr, bo);
err_free:
free(bo);
return NULL;
@ -1415,7 +1409,10 @@ iris_bo_gem_create_from_name(struct iris_bufmgr *bufmgr,
bo = bo_calloc();
if (!bo) {
iris_bufmgr_bo_close(bufmgr, open_arg.handle);
struct iris_bo close_bo = {
.gem_handle = open_arg.handle,
};
bufmgr->kmd_backend->gem_close(bufmgr, &close_bo);
goto out;
}
@ -1500,7 +1497,7 @@ bo_close(struct iris_bo *bo)
close(bo->real.prime_fd);
/* Close this object */
if (iris_bufmgr_bo_close(bufmgr, bo->gem_handle) != 0) {
if (bufmgr->kmd_backend->gem_close(bufmgr, bo) != 0) {
DBG("DRM_IOCTL_GEM_CLOSE %d failed (%s): %s\n",
bo->gem_handle, bo->name, strerror(errno));
}

View file

@ -39,6 +39,7 @@ struct iris_kmd_backend {
const struct intel_memory_class_instance **regions,
uint16_t regions_count, uint64_t size,
enum iris_heap heap_flags, unsigned alloc_flags);
int (*gem_close)(struct iris_bufmgr *bufmgr, struct iris_bo *bo);
bool (*bo_madvise)(struct iris_bo *bo, enum iris_madvice state);
int (*bo_set_caching)(struct iris_bo *bo, bool cached);
void *(*gem_mmap)(struct iris_bufmgr *bufmgr, struct iris_bo *bo);

View file

@ -427,10 +427,20 @@ error_implicit_sync_import:
return ret;
}
static int
xe_gem_close(struct iris_bufmgr *bufmgr, struct iris_bo *bo)
{
struct drm_gem_close close = {
.handle = bo->gem_handle,
};
return intel_ioctl(iris_bufmgr_get_fd(bufmgr), DRM_IOCTL_GEM_CLOSE, &close);
}
const struct iris_kmd_backend *xe_get_backend(void)
{
static const struct iris_kmd_backend xe_backend = {
.gem_create = xe_gem_create,
.gem_close = xe_gem_close,
.gem_mmap = xe_gem_mmap,
.gem_vm_bind = xe_gem_vm_bind,
.gem_vm_unbind = xe_gem_vm_unbind,