Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vc4: Use DMA Resv to implement VC4 wait BO IOCTL

Since the BOs used by VC4 have DMA Reservation Objects attached to
them, waiting for seqnos to check BO availability is unnecessary.
Instead, `drm_gem_dma_resv_wait()` can be used.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Melissa Wen <mwen@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241220134204.634577-3-mcanal@igalia.com

+14 -11
+14 -11
drivers/gpu/drm/vc4/vc4_gem.c
··· 1020 1020 struct vc4_dev *vc4 = to_vc4_dev(dev); 1021 1021 int ret; 1022 1022 struct drm_vc4_wait_bo *args = data; 1023 - struct drm_gem_object *gem_obj; 1024 - struct vc4_bo *bo; 1023 + unsigned long timeout_jiffies = 1024 + usecs_to_jiffies(div_u64(args->timeout_ns, 1000)); 1025 + ktime_t start = ktime_get(); 1026 + u64 delta_ns; 1025 1027 1026 1028 if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4)) 1027 1029 return -ENODEV; ··· 1031 1029 if (args->pad != 0) 1032 1030 return -EINVAL; 1033 1031 1034 - gem_obj = drm_gem_object_lookup(file_priv, args->handle); 1035 - if (!gem_obj) { 1036 - DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle); 1037 - return -EINVAL; 1038 - } 1039 - bo = to_vc4_bo(gem_obj); 1032 + ret = drm_gem_dma_resv_wait(file_priv, args->handle, 1033 + true, timeout_jiffies); 1040 1034 1041 - ret = vc4_wait_for_seqno_ioctl_helper(dev, bo->seqno, 1042 - &args->timeout_ns); 1035 + /* Decrement the user's timeout, in case we got interrupted 1036 + * such that the ioctl will be restarted. 1037 + */ 1038 + delta_ns = ktime_to_ns(ktime_sub(ktime_get(), start)); 1039 + if (delta_ns < args->timeout_ns) 1040 + args->timeout_ns -= delta_ns; 1041 + else 1042 + args->timeout_ns = 0; 1043 1043 1044 - drm_gem_object_put(gem_obj); 1045 1044 return ret; 1046 1045 } 1047 1046