Skip to content

Commit bc2ceb7

Browse files
gfxstranddanvet
authored andcommitted
drm/i915: Add an i915_gem_vm_lookup helper
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
1 parent 263ae12 commit bc2ceb7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,11 +1311,7 @@ static int set_ppgtt(struct drm_i915_file_private *file_priv,
13111311
if (upper_32_bits(args->value))
13121312
return -ENOENT;
13131313

1314-
rcu_read_lock();
1315-
vm = xa_load(&file_priv->vm_xa, args->value);
1316-
if (vm && !kref_get_unless_zero(&vm->ref))
1317-
vm = NULL;
1318-
rcu_read_unlock();
1314+
vm = i915_gem_vm_lookup(file_priv, args->value);
13191315
if (!vm)
13201316
return -ENOENT;
13211317

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,20 @@ i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)
18611861
return ctx;
18621862
}
18631863

1864+
static inline struct i915_address_space *
1865+
i915_gem_vm_lookup(struct drm_i915_file_private *file_priv, u32 id)
1866+
{
1867+
struct i915_address_space *vm;
1868+
1869+
rcu_read_lock();
1870+
vm = xa_load(&file_priv->vm_xa, id);
1871+
if (vm && !kref_get_unless_zero(&vm->ref))
1872+
vm = NULL;
1873+
rcu_read_unlock();
1874+
1875+
return vm;
1876+
}
1877+
18641878
/* i915_gem_evict.c */
18651879
int __must_check i915_gem_evict_something(struct i915_address_space *vm,
18661880
u64 min_size, u64 alignment,

0 commit comments

Comments
 (0)