#include <linux/bitops.h>
#include <linux/host1x.h>
-#include <linux/idr.h>
+#include <linux/xarray.h>
#include <linux/iommu.h>
#include <drm/drm_atomic.h>
#define CDMA_GATHER_FETCHES_MAX_NB 16383
struct tegra_drm_file {
- struct idr contexts;
+ struct xarray contexts;
struct mutex lock;
};
if (!fpriv)
return -ENOMEM;
- idr_init(&fpriv->contexts);
+ xa_init_flags(&fpriv->contexts, XA_FLAGS_ALLOC1);
mutex_init(&fpriv->lock);
filp->driver_priv = fpriv;
if (err < 0)
return err;
- err = idr_alloc(&fpriv->contexts, context, 1, 0, GFP_KERNEL);
+ err = xa_alloc(&fpriv->contexts, &context->id, context, xa_limit_31b,
+ GFP_KERNEL);
if (err < 0) {
client->ops->close_channel(context);
return err;
}
context->client = client;
- context->id = err;
return 0;
}
mutex_lock(&fpriv->lock);
- context = idr_find(&fpriv->contexts, args->context);
+ context = xa_erase(&fpriv->contexts, args->context);
if (!context) {
err = -EINVAL;
goto unlock;
}
- idr_remove(&fpriv->contexts, context->id);
tegra_drm_context_free(context);
unlock:
mutex_lock(&fpriv->lock);
- context = idr_find(&fpriv->contexts, args->context);
+ context = xa_load(&fpriv->contexts, args->context);
if (!context) {
err = -ENODEV;
goto unlock;
mutex_lock(&fpriv->lock);
- context = idr_find(&fpriv->contexts, args->context);
+ context = xa_load(&fpriv->contexts, args->context);
if (!context) {
err = -ENODEV;
goto unlock;
mutex_lock(&fpriv->lock);
- context = idr_find(&fpriv->contexts, args->context);
+ context = xa_load(&fpriv->contexts, args->context);
if (!context) {
err = -ENODEV;
goto unlock;
.llseek = noop_llseek,
};
-static int tegra_drm_context_cleanup(int id, void *p, void *data)
-{
- struct tegra_drm_context *context = p;
-
- tegra_drm_context_free(context);
-
- return 0;
-}
-
static void tegra_drm_postclose(struct drm_device *drm, struct drm_file *file)
{
struct tegra_drm_file *fpriv = file->driver_priv;
+ struct tegra_drm_context *context;
+ unsigned long index;
mutex_lock(&fpriv->lock);
- idr_for_each(&fpriv->contexts, tegra_drm_context_cleanup, NULL);
+ xa_for_each(&fpriv->contexts, index, context)
+ tegra_drm_context_free(context);
mutex_unlock(&fpriv->lock);
- idr_destroy(&fpriv->contexts);
+ xa_destroy(&fpriv->contexts);
mutex_destroy(&fpriv->lock);
kfree(fpriv);
}