X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Ffreedreno%2Fvulkan%2Ftu_device.c;h=b4ae1268d7e24889a21649dfbe74aa150f6e68ff;hp=9f2881724cfc8b600a9a89bbeeb645a4f915217e;hb=59e5f95bdccf70219dd67adabd8b7f09b62710bf;hpb=270599cc1e7d800dc3192e472c07e6440150de97 diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index 9f2881724cf..b4ae1268d7e 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -68,100 +67,6 @@ tu_device_get_cache_uuid(uint16_t family, void *uuid) return 0; } -static VkResult -tu_bo_init(struct tu_device *dev, - struct tu_bo *bo, - uint32_t gem_handle, - uint64_t size) -{ - uint64_t iova = tu_gem_info_iova(dev, gem_handle); - if (!iova) - return VK_ERROR_OUT_OF_DEVICE_MEMORY; - - *bo = (struct tu_bo) { - .gem_handle = gem_handle, - .size = size, - .iova = iova, - }; - - return VK_SUCCESS; -} - -VkResult -tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size) -{ - /* TODO: Choose better flags. As of 2018-11-12, freedreno/drm/msm_bo.c - * always sets `flags = MSM_BO_WC`, and we copy that behavior here. - */ - uint32_t gem_handle = tu_gem_new(dev, size, MSM_BO_WC); - if (!gem_handle) - return vk_error(dev->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY); - - VkResult result = tu_bo_init(dev, bo, gem_handle, size); - if (result != VK_SUCCESS) { - tu_gem_close(dev, gem_handle); - return vk_error(dev->instance, result); - } - - return VK_SUCCESS; -} - -VkResult -tu_bo_init_dmabuf(struct tu_device *dev, - struct tu_bo *bo, - uint64_t size, - int fd) -{ - uint32_t gem_handle = tu_gem_import_dmabuf(dev, fd, size); - if (!gem_handle) - return vk_error(dev->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE); - - VkResult result = tu_bo_init(dev, bo, gem_handle, size); - if (result != VK_SUCCESS) { - tu_gem_close(dev, gem_handle); - return vk_error(dev->instance, result); - } - - return VK_SUCCESS; -} - -int -tu_bo_export_dmabuf(struct tu_device *dev, struct tu_bo *bo) -{ - return tu_gem_export_dmabuf(dev, bo->gem_handle); -} - -VkResult -tu_bo_map(struct tu_device *dev, struct tu_bo *bo) -{ - if (bo->map) - return VK_SUCCESS; - - uint64_t offset = tu_gem_info_offset(dev, bo->gem_handle); - if (!offset) - return vk_error(dev->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY); - - /* TODO: Should we use the wrapper os_mmap() like Freedreno does? */ - void *map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, - dev->physical_device->local_fd, offset); - if (map == MAP_FAILED) - return vk_error(dev->instance, VK_ERROR_MEMORY_MAP_FAILED); - - bo->map = map; - return VK_SUCCESS; -} - -void -tu_bo_finish(struct tu_device *dev, struct tu_bo *bo) -{ - assert(bo->gem_handle); - - if (bo->map) - munmap(bo->map, bo->size); - - tu_gem_close(dev, bo->gem_handle); -} - VkResult tu_physical_device_init(struct tu_physical_device *device, struct tu_instance *instance)