turnip: Only get bo offset when we need to mmap
authorKristian H. Kristensen <hoegsberg@chromium.org>
Wed, 16 Jan 2019 19:02:38 +0000 (11:02 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:41 +0000 (10:01 -0700)
The offset we get from MSM_INFO_GET_OFFSET is an offset into the drm fd
for the purpose of mmaping the buffer.

src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_private.h

index 11d200e2f036afd152f71e8856de9859d3883d1e..7ff1e5a4f6271fb197ca3cf81b3b8c6e0de59f3d 100644 (file)
@@ -83,20 +83,6 @@ tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size)
    if (!gem_handle)
       goto fail_new;
 
    if (!gem_handle)
       goto fail_new;
 
-   /* Calling DRM_MSM_GEM_INFO forces the kernel to allocate backing pages. We
-    * want immediate backing pages because vkAllocateMemory and friends must
-    * not lazily fail.
-    *
-    * TODO(chadv): Must we really call DRM_MSM_GEM_INFO to acquire backing
-    * pages? I infer so from reading comments in msm_bo.c:bo_allocate(), but
-    * maybe I misunderstand.
-    */
-
-   /* TODO: Do we need 'offset' if we have 'iova'? */
-   uint64_t offset = tu_gem_info_offset(dev, gem_handle);
-   if (!offset)
-      goto fail_info;
-
    uint64_t iova = tu_gem_info_iova(dev, gem_handle);
    if (!iova)
       goto fail_info;
    uint64_t iova = tu_gem_info_iova(dev, gem_handle);
    if (!iova)
       goto fail_info;
@@ -104,7 +90,6 @@ tu_bo_init_new(struct tu_device *dev, struct tu_bo *bo, uint64_t size)
    *bo = (struct tu_bo) {
       .gem_handle = gem_handle,
       .size = size,
    *bo = (struct tu_bo) {
       .gem_handle = gem_handle,
       .size = size,
-      .offset = offset,
       .iova = iova,
    };
 
       .iova = iova,
    };
 
@@ -122,9 +107,13 @@ tu_bo_map(struct tu_device *dev, struct tu_bo *bo)
    if (bo->map)
       return VK_SUCCESS;
 
    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,
    /* 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, bo->offset);
+                    dev->physical_device->local_fd, offset);
    if (map == MAP_FAILED)
       return vk_error(dev->instance, VK_ERROR_MEMORY_MAP_FAILED);
 
    if (map == MAP_FAILED)
       return vk_error(dev->instance, VK_ERROR_MEMORY_MAP_FAILED);
 
index 53f493a61aac0125962ed5246f3b6fa803416f59..a112bbcb7817c2b7b87a46c44799c0bfc03a28fc 100644 (file)
@@ -432,7 +432,6 @@ struct tu_bo
 {
    uint32_t gem_handle;
    uint64_t size;
 {
    uint32_t gem_handle;
    uint64_t size;
-   uint64_t offset;
    uint64_t iova;
    void *map;
 };
    uint64_t iova;
    void *map;
 };