]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drm/tegra: Convert contexts IDR to XArray
authorMatthew Wilcox <willy@infradead.org>
Fri, 15 Feb 2019 19:08:31 +0000 (14:08 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:35 +0000 (23:39 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/gpu/drm/tegra/drm.c

index ddb802bce0a3252e0ed447f927187cdf0feacd09..4b7d6623171eca43cdd87a07b14272274b66c4ef 100644 (file)
@@ -6,7 +6,7 @@
 
 #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>
@@ -30,7 +30,7 @@
 #define CDMA_GATHER_FETCHES_MAX_NB 16383
 
 struct tegra_drm_file {
-       struct idr contexts;
+       struct xarray contexts;
        struct mutex lock;
 };
 
@@ -248,7 +248,7 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
        if (!fpriv)
                return -ENOMEM;
 
-       idr_init(&fpriv->contexts);
+       xa_init_flags(&fpriv->contexts, XA_FLAGS_ALLOC1);
        mutex_init(&fpriv->lock);
        filp->driver_priv = fpriv;
 
@@ -584,14 +584,14 @@ static int tegra_client_open(struct tegra_drm_file *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;
 }
@@ -639,13 +639,12 @@ static int tegra_close_channel(struct drm_device *drm, void *data,
 
        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:
@@ -664,7 +663,7 @@ static int tegra_get_syncpt(struct drm_device *drm, void *data,
 
        mutex_lock(&fpriv->lock);
 
-       context = idr_find(&fpriv->contexts, args->context);
+       context = xa_load(&fpriv->contexts, args->context);
        if (!context) {
                err = -ENODEV;
                goto unlock;
@@ -693,7 +692,7 @@ static int tegra_submit(struct drm_device *drm, void *data,
 
        mutex_lock(&fpriv->lock);
 
-       context = idr_find(&fpriv->contexts, args->context);
+       context = xa_load(&fpriv->contexts, args->context);
        if (!context) {
                err = -ENODEV;
                goto unlock;
@@ -718,7 +717,7 @@ static int tegra_get_syncpt_base(struct drm_device *drm, void *data,
 
        mutex_lock(&fpriv->lock);
 
-       context = idr_find(&fpriv->contexts, args->context);
+       context = xa_load(&fpriv->contexts, args->context);
        if (!context) {
                err = -ENODEV;
                goto unlock;
@@ -930,24 +929,18 @@ static const struct file_operations tegra_drm_fops = {
        .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);
 }