nouveau/ws: add a bo unmap helper function
authorKarol Herbst <kherbst@redhat.com>
Mon, 29 Aug 2022 13:48:44 +0000 (15:48 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:58 +0000 (21:31 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/vulkan/nvk_device_memory.c
src/nouveau/winsys/nouveau_bo.h
src/nouveau/winsys/nouveau_push.c

index 40869e5..0caf003 100644 (file)
@@ -118,7 +118,7 @@ nvk_allocate_memory(struct nvk_device *device,
             goto fail_bo;
          }
          memset(map, 0, mem->bo->size);
-         munmap(map, mem->bo->size);
+         nouveau_ws_bo_unmap(mem->bo, map);
       } else {
          VkResult result = zero_vram(device, mem->bo);
          if (result != VK_SUCCESS)
@@ -146,7 +146,7 @@ nvk_free_memory(struct nvk_device *device,
                 const VkAllocationCallbacks *pAllocator)
 {
    if (mem->map)
-      munmap(mem->map, mem->bo->size);
+      nouveau_ws_bo_unmap(mem->bo, mem->map);
 
    simple_mtx_lock(&device->memory_objects_lock);
    list_del(&mem->link);
@@ -255,7 +255,7 @@ nvk_UnmapMemory(
    if (mem == NULL)
       return;
 
-   munmap(mem->map, mem->bo->size);
+   nouveau_ws_bo_unmap(mem->bo, mem->map);
    mem->map = NULL;
 }
 
index 7342706..8787474 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "nouveau_device.h"
 
+#include <sys/mman.h>
+
 enum nouveau_ws_bo_flags {
    /* vram or gart depending on GPU */
    NOUVEAU_WS_BO_LOCAL = 0 << 0,
@@ -46,4 +48,10 @@ nouveau_ws_bo_ref(struct nouveau_ws_bo *bo)
    bo->refcnt++;
 }
 
+static inline void
+nouveau_ws_bo_unmap(struct nouveau_ws_bo *bo, void *ptr)
+{
+   munmap(ptr, bo->size);
+}
+
 #endif
index 275c15b..fcf1ea3 100644 (file)
@@ -55,7 +55,7 @@ nouveau_ws_push_new(struct nouveau_ws_device *dev, uint64_t size)
    return push;
 
 fail_alloc:
-   munmap(map, bo->size);
+   nouveau_ws_bo_unmap(bo, map);
 fail_map:
    nouveau_ws_bo_destroy(bo);
 fail_bo:
@@ -78,7 +78,7 @@ nouveau_ws_push_destroy(struct nouveau_ws_push *push)
 {
    util_dynarray_fini(&push->bos);
    if (push->bo) {
-      munmap(push->orig_map, push->bo->size);
+      nouveau_ws_bo_unmap(push->bo, push->orig_map);
       nouveau_ws_bo_destroy(push->bo);
    }
 }