freedreno/drm-shim: Better iova handling
authorRob Clark <robdclark@chromium.org>
Fri, 29 Apr 2022 16:20:07 +0000 (09:20 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 2 May 2022 19:50:33 +0000 (19:50 +0000)
We actually want to use util_vma to handle this.  But fortunately core
drm-shim alredy does this for mem offset, we can just delete a bunch of
code and re-use that.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16250>

src/freedreno/drm-shim/freedreno_noop.c

index c48ff76..1a5bac5 100644 (file)
 
 bool drm_shim_driver_prefers_first_render_node = true;
 
-struct msm_bo {
-   struct shim_bo base;
-   uint32_t offset;
-};
-
-static struct msm_bo *
-msm_bo(struct shim_bo *bo)
-{
-   return (struct msm_bo *)bo;
-}
-
-struct msm_device {
-   uint32_t next_offset;
-};
-
-static struct msm_device msm = {
-   .next_offset = 0x1000,
-};
-
 struct msm_device_info {
    uint32_t gpu_id;
    uint32_t chip_id;
@@ -70,19 +51,23 @@ msm_ioctl_gem_new(int fd, unsigned long request, void *arg)
 {
    struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
    struct drm_msm_gem_new *create = arg;
-   struct msm_bo *bo = calloc(1, sizeof(*bo));
    size_t size = ALIGN(create->size, 4096);
 
-   drm_shim_bo_init(&bo->base, size);
+   if (!size)
+      return -EINVAL;
 
-   assert(UINT_MAX - msm.next_offset > size);
+   struct shim_bo *bo = calloc(1, sizeof(*bo));
+   int ret;
 
-   bo->offset = msm.next_offset;
-   msm.next_offset += size;
+   ret = drm_shim_bo_init(bo, size);
+   if (ret) {
+      free(bo);
+      return ret;
+   }
 
-   create->handle = drm_shim_bo_get_handle(shim_fd, &bo->base);
+   create->handle = drm_shim_bo_get_handle(shim_fd, bo);
 
-   drm_shim_bo_put(&bo->base);
+   drm_shim_bo_put(bo);
 
    return 0;
 }
@@ -102,7 +87,7 @@ msm_ioctl_gem_info(int fd, unsigned long request, void *arg)
       args->value = drm_shim_bo_get_mmap_offset(shim_fd, bo);
       break;
    case MSM_INFO_GET_IOVA:
-      args->value = msm_bo(bo)->offset;
+      args->value = bo->mem_addr;
       break;
    case MSM_INFO_SET_IOVA:
    case MSM_INFO_SET_NAME: