summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaith Ekstrand <faith.ekstrand@collabora.com>2023-08-04 11:59:21 -0500
committerMarge Bot <emma+marge@anholt.net>2023-08-04 21:32:07 +0000
commit0b6afbc407fb4a08ce5cdd234b729db662b944fe (patch)
tree67788f3f09ac8adc5e9590416b204ac03a026cb0
parent1a6a198ab54fcf0018bba1f5e3b3bb1ade578383 (diff)
nouveau/winsys: Allow nouveau_ws_device_new() without VM_BIND
Silently fall back to non-VM_BIND. The client can check for the has_vm_bind flag in the device to detect whether VM_BIND is actually available or not. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
-rw-r--r--src/nouveau/winsys/nouveau_bo.c22
-rw-r--r--src/nouveau/winsys/nouveau_device.c38
-rw-r--r--src/nouveau/winsys/nouveau_device.h1
3 files changed, 36 insertions, 25 deletions
diff --git a/src/nouveau/winsys/nouveau_bo.c b/src/nouveau/winsys/nouveau_bo.c
index ebfb80768b4..22267d4f5d4 100644
--- a/src/nouveau/winsys/nouveau_bo.c
+++ b/src/nouveau/winsys/nouveau_bo.c
@@ -61,6 +61,8 @@ nouveau_ws_alloc_vma(struct nouveau_ws_device *dev,
uint64_t size, uint64_t align,
bool sparse_resident)
{
+ assert(dev->has_vm_bind);
+
uint64_t offset;
simple_mtx_lock(&dev->vma_mutex);
offset = util_vma_heap_alloc(&dev->vma_heap, size, align);
@@ -81,6 +83,8 @@ nouveau_ws_free_vma(struct nouveau_ws_device *dev,
uint64_t offset, uint64_t size,
bool sparse_resident)
{
+ assert(dev->has_vm_bind);
+
if (dev->debug_flags & NVK_DEBUG_VM)
fprintf(stderr, "free vma %" PRIx64 " %" PRIx64 "\n",
offset, size);
@@ -97,6 +101,8 @@ void
nouveau_ws_bo_unbind_vma(struct nouveau_ws_device *dev,
uint64_t offset, uint64_t range)
{
+ assert(dev->has_vm_bind);
+
if (dev->debug_flags & NVK_DEBUG_VM)
fprintf(stderr, "unbind vma %" PRIx64 " %" PRIx64 "\n",
offset, range);
@@ -111,6 +117,8 @@ nouveau_ws_bo_bind_vma(struct nouveau_ws_device *dev,
uint64_t bo_offset,
uint32_t pte_kind)
{
+ assert(dev->has_vm_bind);
+
if (dev->debug_flags & NVK_DEBUG_VM)
fprintf(stderr, "bind vma %x %" PRIx64 " %" PRIx64 " %" PRIx64 " %d\n",
bo->handle, addr, range, bo_offset, pte_kind);
@@ -211,9 +219,11 @@ nouveau_ws_bo_new_tiled(struct nouveau_ws_device *dev,
bo->refcnt = 1;
#if NVK_NEW_UAPI == 1
- assert(pte_kind == 0);
- bo->offset = nouveau_ws_alloc_vma(dev, bo->size, align, false);
- nouveau_ws_bo_bind_vma(dev, bo, bo->offset, bo->size, 0, 0);
+ if (dev->has_vm_bind) {
+ assert(pte_kind == 0);
+ bo->offset = nouveau_ws_alloc_vma(dev, bo->size, align, false);
+ nouveau_ws_bo_bind_vma(dev, bo, bo->offset, bo->size, 0, 0);
+ }
#endif
_mesa_hash_table_insert(dev->bos, (void *)(uintptr_t)bo->handle, bo);
@@ -296,8 +306,10 @@ nouveau_ws_bo_destroy(struct nouveau_ws_bo *bo)
_mesa_hash_table_remove_key(dev->bos, (void *)(uintptr_t)bo->handle);
#if NVK_NEW_UAPI == 1
- nouveau_ws_bo_unbind_vma(bo->dev, bo->offset, bo->size);
- nouveau_ws_free_vma(bo->dev, bo->offset, bo->size, false);
+ if (dev->has_vm_bind) {
+ nouveau_ws_bo_unbind_vma(bo->dev, bo->offset, bo->size);
+ nouveau_ws_free_vma(bo->dev, bo->offset, bo->size, false);
+ }
#endif
drmCloseBufferHandle(bo->dev->fd, bo->handle);
diff --git a/src/nouveau/winsys/nouveau_device.c b/src/nouveau/winsys/nouveau_device.c
index da9f6301728..49b6a8e9717 100644
--- a/src/nouveau/winsys/nouveau_device.c
+++ b/src/nouveau/winsys/nouveau_device.c
@@ -259,14 +259,6 @@ nouveau_ws_device_new(drmDevicePtr drm_device)
goto out_err;
}
-#if NVK_NEW_UAPI == 1
- const uint64_t TOP = 1ull << 40;
- const uint64_t KERN = 1ull << 39;
- util_vma_heap_init(&device->vma_heap, 4096, (TOP - KERN) - 4096);
- simple_mtx_init(&device->vma_mutex, mtx_plain);
- device->vma_heap.alloc_high = false;
-#endif
-
uint32_t version =
ver->version_major << 24 |
ver->version_minor << 8 |
@@ -274,20 +266,19 @@ nouveau_ws_device_new(drmDevicePtr drm_device)
drmFreeVersion(ver);
ver = NULL;
-#if NVK_NEW_UAPI == 1
- /* don't work on older kernels */
- if (version < 0x01000400)
- goto out_err;
-#else
if (version < 0x01000301)
goto out_err;
-#endif
#if NVK_NEW_UAPI == 1
- /* start the new VM mode */
+ const uint64_t TOP = 1ull << 40;
+ const uint64_t KERN = 1ull << 39;
struct drm_nouveau_vm_init vminit = { TOP-KERN, KERN };
- ASSERTED int ret = drmCommandWrite(fd, DRM_NOUVEAU_VM_INIT, &vminit, sizeof(vminit));
- assert(!ret);
+ int ret = drmCommandWrite(fd, DRM_NOUVEAU_VM_INIT, &vminit, sizeof(vminit));
+ if (ret == 0) {
+ device->has_vm_bind = true;
+ util_vma_heap_init(&device->vma_heap, 4096, (TOP - KERN) - 4096);
+ simple_mtx_init(&device->vma_mutex, mtx_plain);
+ }
#endif
if (nouveau_ws_device_alloc(fd, device))
@@ -351,6 +342,12 @@ nouveau_ws_device_new(drmDevicePtr drm_device)
return device;
out_err:
+#if NVK_NEW_UAPI == 1
+ if (device->has_vm_bind) {
+ util_vma_heap_finish(&device->vma_heap);
+ simple_mtx_destroy(&device->vma_mutex);
+ }
+#endif
if (ver)
drmFreeVersion(ver);
out_open:
@@ -369,11 +366,12 @@ nouveau_ws_device_destroy(struct nouveau_ws_device *device)
simple_mtx_destroy(&device->bos_lock);
#if NVK_NEW_UAPI == 1
- util_vma_heap_finish(&device->vma_heap);
- simple_mtx_destroy(&device->vma_mutex);
+ if (device->has_vm_bind) {
+ util_vma_heap_finish(&device->vma_heap);
+ simple_mtx_destroy(&device->vma_mutex);
+ }
#endif
-
close(device->fd);
FREE(device);
}
diff --git a/src/nouveau/winsys/nouveau_device.h b/src/nouveau/winsys/nouveau_device.h
index 945c143c082..db30e8c6486 100644
--- a/src/nouveau/winsys/nouveau_device.h
+++ b/src/nouveau/winsys/nouveau_device.h
@@ -50,6 +50,7 @@ struct nouveau_ws_device {
struct hash_table *bos;
#if NVK_NEW_UAPI == 1
+ bool has_vm_bind;
struct util_vma_heap vma_heap;
simple_mtx_t vma_mutex;
#endif