diff mbox series

[28/34] drm/tegra: Convert contexts IDR to XArray

Message ID 20190221184226.2149-55-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Convert DRM to XArray | expand

Commit Message

Matthew Wilcox (Oracle) Feb. 21, 2019, 6:42 p.m. UTC
Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
 drivers/gpu/drm/tegra/drm.c | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index 4b70ce664c41..5daa414cc2cf 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -9,7 +9,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>
@@ -33,7 +33,7 @@ 
 #define CDMA_GATHER_FETCHES_MAX_NB 16383
 
 struct tegra_drm_file {
-	struct idr contexts;
+	struct xarray contexts;
 	struct mutex lock;
 };
 
@@ -246,7 +246,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;
 
@@ -582,14 +582,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;
 }
@@ -637,13 +637,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:
@@ -662,7 +661,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;
@@ -691,7 +690,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;
@@ -716,7 +715,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;
@@ -928,24 +927,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);
 }