nouveau/ws: add a bo unmap helper function

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
Karol Herbst 2022-08-29 15:48:44 +02:00 committed by Marge Bot
parent 886db84e94
commit 05bc4500ad
3 changed files with 13 additions and 5 deletions

View 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;
}

View 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

View 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);
}
}