ida_destroy(&i915->contexts.hw_ida);
}
-static int vm_idr_cleanup(int id, void *p, void *data)
-{
- i915_vm_put(p);
- return 0;
-}
-
static int gem_context_register(struct i915_gem_context *ctx,
struct drm_i915_file_private *fpriv)
{
struct i915_gem_context *ctx;
int err;
- mutex_init(&file_priv->vm_idr_lock);
-
xa_init_flags(&file_priv->contexts, XA_FLAGS_ALLOC);
- idr_init_base(&file_priv->vm_idr, 1);
+ xa_init_flags(&file_priv->vms, XA_FLAGS_ALLOC1);
mutex_lock(&i915->drm.struct_mutex);
ctx = i915_gem_create_context(i915, 0);
err_ctx:
context_close(ctx);
err:
- idr_destroy(&file_priv->vm_idr);
+ xa_destroy(&file_priv->vms);
xa_destroy(&file_priv->contexts);
- mutex_destroy(&file_priv->vm_idr_lock);
return err;
}
{
struct drm_i915_file_private *file_priv = file->driver_priv;
struct i915_gem_context *ctx;
+ struct i915_address_space *vm;
unsigned long index;
xa_for_each(&file_priv->contexts, index, ctx)
context_close(ctx);
xa_destroy(&file_priv->contexts);
- idr_for_each(&file_priv->vm_idr, vm_idr_cleanup, NULL);
- idr_destroy(&file_priv->vm_idr);
- mutex_destroy(&file_priv->vm_idr_lock);
+ xa_for_each(&file_priv->vms, index, vm)
+ i915_vm_put(vm);
+ xa_destroy(&file_priv->vms);
}
int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
goto err_put;
}
- err = mutex_lock_interruptible(&file_priv->vm_idr_lock);
- if (err)
- goto err_put;
-
- err = idr_alloc(&file_priv->vm_idr, &ppgtt->vm, 0, 0, GFP_KERNEL);
+ err = xa_alloc(&file_priv->vms, &args->vm_id, &ppgtt->vm,
+ xa_limit_32b, GFP_KERNEL);
if (err < 0)
- goto err_unlock;
-
- GEM_BUG_ON(err == 0); /* reserved for invalid/unassigned ppgtt */
+ goto err_put;
- mutex_unlock(&file_priv->vm_idr_lock);
+ GEM_BUG_ON(args->vm_id == 0); /* reserved for invalid/unassigned */
- args->vm_id = err;
return 0;
-err_unlock:
- mutex_unlock(&file_priv->vm_idr_lock);
err_put:
i915_vm_put(&ppgtt->vm);
return err;
struct drm_i915_file_private *file_priv = file->driver_priv;
struct drm_i915_gem_vm_control *args = data;
struct i915_address_space *vm;
- int err;
u32 id;
if (args->flags)
if (!id)
return -ENOENT;
- err = mutex_lock_interruptible(&file_priv->vm_idr_lock);
- if (err)
- return err;
-
- vm = idr_remove(&file_priv->vm_idr, id);
-
- mutex_unlock(&file_priv->vm_idr_lock);
+ vm = xa_erase(&file_priv->vms, id);
if (!vm)
return -ENOENT;
{
struct i915_address_space *vm;
int ret;
+ u32 id;
if (!ctx->vm)
return -ENODEV;
vm = i915_vm_get(ctx->vm);
mutex_unlock(&ctx->i915->drm.struct_mutex);
- ret = mutex_lock_interruptible(&file_priv->vm_idr_lock);
- if (ret)
- goto err_put;
-
- ret = idr_alloc(&file_priv->vm_idr, vm, 0, 0, GFP_KERNEL);
- GEM_BUG_ON(!ret);
+ ret = xa_alloc(&file_priv->vms, &id, vm, xa_limit_32b, GFP_KERNEL);
if (ret < 0)
- goto err_unlock;
-
- i915_vm_get(vm);
+ goto err_put;
+ GEM_BUG_ON(!id);
args->size = 0;
- args->value = ret;
+ args->value = id;
- ret = 0;
-err_unlock:
- mutex_unlock(&file_priv->vm_idr_lock);
+ return 0;
err_put:
i915_vm_put(vm);
return ret;
if (upper_32_bits(args->value))
return -ENOENT;
- err = mutex_lock_interruptible(&file_priv->vm_idr_lock);
- if (err)
- return err;
-
- vm = idr_find(&file_priv->vm_idr, args->value);
+ xa_lock(&file_priv->vms);
+ vm = xa_load(&file_priv->vms, args->value);
if (vm)
i915_vm_get(vm);
- mutex_unlock(&file_priv->vm_idr_lock);
+ xa_unlock(&file_priv->vms);
if (!vm)
return -ENOENT;