anv: Replace handle by anv_bo in the gem_close()

struct anv_bo will be needed in the next patch to properly handle
closure of userptr bos.

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/23787>
This commit is contained in:
José Roberto de Souza
2023-07-18 09:03:13 -07:00
committed by Marge Bot
parent 7e7ab39424
commit 5c729cb1b8
5 changed files with 21 additions and 18 deletions
+11 -11
View File
@@ -1371,7 +1371,7 @@ anv_bo_unmap_close(struct anv_device *device, struct anv_bo *bo)
anv_device_unmap_bo(device, bo, bo->map, bo->size);
assert(bo->gem_handle != 0);
device->kmd_backend->gem_close(device, bo->gem_handle);
device->kmd_backend->gem_close(device, bo);
}
static void
@@ -1525,7 +1525,7 @@ anv_device_alloc_bo(struct anv_device *device,
VkResult result = anv_device_map_bo(device, &new_bo, 0, size,
0 /* propertyFlags */, &new_bo.map);
if (unlikely(result != VK_SUCCESS)) {
device->kmd_backend->gem_close(device, new_bo.gem_handle);
device->kmd_backend->gem_close(device, &new_bo);
return result;
}
}
@@ -1789,26 +1789,26 @@ anv_device_import_bo(struct anv_device *device,
__sync_fetch_and_add(&bo->refcount, 1);
} else {
off_t size = lseek(fd, 0, SEEK_END);
if (size == (off_t)-1) {
device->kmd_backend->gem_close(device, gem_handle);
pthread_mutex_unlock(&cache->mutex);
return vk_error(device, VK_ERROR_INVALID_EXTERNAL_HANDLE);
}
struct anv_bo new_bo = {
.name = "imported",
.gem_handle = gem_handle,
.refcount = 1,
.offset = -1,
.size = size,
.actual_size = size,
.flags = bo_flags,
.is_external = true,
.has_client_visible_address =
(alloc_flags & ANV_BO_ALLOC_CLIENT_VISIBLE_ADDRESS) != 0,
};
off_t size = lseek(fd, 0, SEEK_END);
if (size == (off_t)-1) {
device->kmd_backend->gem_close(device, &new_bo);
pthread_mutex_unlock(&cache->mutex);
return vk_error(device, VK_ERROR_INVALID_EXTERNAL_HANDLE);
}
new_bo.size = size;
new_bo.actual_size = size;
assert(new_bo._ccs_size == 0);
VkResult result = anv_bo_vma_alloc_or_close(device, &new_bo,
alloc_flags,
+2 -2
View File
@@ -28,9 +28,9 @@
#include "anv_private.h"
static void
stub_gem_close(struct anv_device *device, uint32_t gem_handle)
stub_gem_close(struct anv_device *device, struct anv_bo *bo)
{
close(gem_handle);
close(bo->gem_handle);
}
static uint32_t
+1 -1
View File
@@ -50,7 +50,7 @@ struct anv_kmd_backend {
enum anv_bo_alloc_flags alloc_flags,
uint64_t *actual_size);
uint32_t (*gem_create_userptr)(struct anv_device *device, void *mem, uint64_t size);
void (*gem_close)(struct anv_device *device, uint32_t handle);
void (*gem_close)(struct anv_device *device, struct anv_bo *bo);
/* Returns MAP_FAILED on error */
void *(*gem_mmap)(struct anv_device *device, struct anv_bo *bo,
uint64_t offset, uint64_t size,
+2 -2
View File
@@ -97,10 +97,10 @@ i915_gem_create(struct anv_device *device,
}
static void
i915_gem_close(struct anv_device *device, uint32_t handle)
i915_gem_close(struct anv_device *device, struct anv_bo *bo)
{
struct drm_gem_close close = {
.handle = handle,
.handle = bo->gem_handle,
};
intel_ioctl(device->fd, DRM_IOCTL_GEM_CLOSE, &close);
+5 -2
View File
@@ -60,10 +60,13 @@ xe_gem_create(struct anv_device *device,
}
static void
xe_gem_close(struct anv_device *device, uint32_t handle)
xe_gem_close(struct anv_device *device, struct anv_bo *bo)
{
if (bo->from_host_ptr)
return;
struct drm_gem_close close = {
.handle = handle,
.handle = bo->gem_handle,
};
intel_ioctl(device->fd, DRM_IOCTL_GEM_CLOSE, &close);
}