drm/i915: Add an i915_gem_vm_lookup helper
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 8 Jul 2021 15:48:24 +0000 (10:48 -0500)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Thu, 8 Jul 2021 17:47:26 +0000 (19:47 +0200)
This is the VM equivalent of i915_gem_context_lookup.  It's only used
once in this patch but future patches will need to duplicate this lookup
code so it's better to have it in a helper.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-20-jason@jlekstrand.net
drivers/gpu/drm/i915/gem/i915_gem_context.c
drivers/gpu/drm/i915/i915_drv.h

index 206721d..3c59d1e 100644 (file)
@@ -1311,11 +1311,7 @@ static int set_ppgtt(struct drm_i915_file_private *file_priv,
        if (upper_32_bits(args->value))
                return -ENOENT;
 
-       rcu_read_lock();
-       vm = xa_load(&file_priv->vm_xa, args->value);
-       if (vm && !kref_get_unless_zero(&vm->ref))
-               vm = NULL;
-       rcu_read_unlock();
+       vm = i915_gem_vm_lookup(file_priv, args->value);
        if (!vm)
                return -ENOENT;
 
index 91a1510..3724bf9 100644 (file)
@@ -1861,6 +1861,20 @@ i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)
        return ctx;
 }
 
+static inline struct i915_address_space *
+i915_gem_vm_lookup(struct drm_i915_file_private *file_priv, u32 id)
+{
+       struct i915_address_space *vm;
+
+       rcu_read_lock();
+       vm = xa_load(&file_priv->vm_xa, id);
+       if (vm && !kref_get_unless_zero(&vm->ref))
+               vm = NULL;
+       rcu_read_unlock();
+
+       return vm;
+}
+
 /* i915_gem_evict.c */
 int __must_check i915_gem_evict_something(struct i915_address_space *vm,
                                          u64 min_size, u64 alignment,