Signed-off-by: Matthew Wilcox <wi...@infradead.org>
---
 drivers/gpu/drm/drm_context.c | 42 +++++++++++++++--------------------
 include/drm/drm_device.h      |  2 +-
 2 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c
index 506663c69b0a..b498e311cf57 100644
--- a/drivers/gpu/drm/drm_context.c
+++ b/drivers/gpu/drm/drm_context.c
@@ -48,8 +48,7 @@ struct drm_ctx_list {
  * \param ctx_handle context handle.
  *
  * Clears the bit specified by \p ctx_handle in drm_device::ctx_bitmap and the 
entry
- * in drm_device::ctx_idr, while holding the drm_device::struct_mutex
- * lock.
+ * in drm_device::ctxts.
  */
 void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle)
 {
@@ -57,9 +56,7 @@ void drm_legacy_ctxbitmap_free(struct drm_device * dev, int 
ctx_handle)
            !drm_core_check_feature(dev, DRIVER_LEGACY))
                return;
 
-       mutex_lock(&dev->struct_mutex);
-       idr_remove(&dev->ctx_idr, ctx_handle);
-       mutex_unlock(&dev->struct_mutex);
+       xa_erase(&dev->ctxts, ctx_handle);
 }
 
 /**
@@ -68,18 +65,17 @@ void drm_legacy_ctxbitmap_free(struct drm_device * dev, int 
ctx_handle)
  * \param dev DRM device.
  * \return (non-negative) context handle on success or a negative number on 
failure.
  *
- * Allocate a new idr from drm_device::ctx_idr while holding the
- * drm_device::struct_mutex lock.
+ * Allocate a new id from drm_device::ctxts.
  */
 static int drm_legacy_ctxbitmap_next(struct drm_device * dev)
 {
-       int ret;
+       int ret, id;
 
-       mutex_lock(&dev->struct_mutex);
-       ret = idr_alloc(&dev->ctx_idr, NULL, DRM_RESERVED_CONTEXTS, 0,
-                       GFP_KERNEL);
-       mutex_unlock(&dev->struct_mutex);
-       return ret;
+       ret = xa_alloc(&dev->ctxts, &id, NULL,
+                       XA_LIMIT(DRM_RESERVED_CONTEXTS, INT_MAX), GFP_KERNEL);
+       if (ret < 0)
+               return ret;
+       return id;
 }
 
 /**
@@ -87,7 +83,7 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * dev)
  *
  * \param dev DRM device.
  *
- * Initialise the drm_device::ctx_idr
+ * Initialise the drm_device::ctxts
  */
 void drm_legacy_ctxbitmap_init(struct drm_device * dev)
 {
@@ -95,7 +91,7 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev)
            !drm_core_check_feature(dev, DRIVER_LEGACY))
                return;
 
-       idr_init(&dev->ctx_idr);
+       xa_init_flags(&dev->ctxts, XA_FLAGS_ALLOC);
 }
 
 /**
@@ -103,8 +99,8 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev)
  *
  * \param dev DRM device.
  *
- * Free all idr members using drm_ctx_sarea_free helper function
- * while holding the drm_device::struct_mutex lock.
+ * Free all memory used by the ctxts data structure.  Does not free the
+ * pointers in that data structures.
  */
 void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
 {
@@ -112,9 +108,7 @@ void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev)
            !drm_core_check_feature(dev, DRIVER_LEGACY))
                return;
 
-       mutex_lock(&dev->struct_mutex);
-       idr_destroy(&dev->ctx_idr);
-       mutex_unlock(&dev->struct_mutex);
+       xa_destroy(&dev->ctxts);
 }
 
 /**
@@ -166,7 +160,7 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, 
struct drm_file *file)
  * \param arg user argument pointing to a drm_ctx_priv_map structure.
  * \return zero on success or a negative number on failure.
  *
- * Gets the map from drm_device::ctx_idr with the handle specified and
+ * Gets the map from drm_device::ctxts with the handle specified and
  * returns its handle.
  */
 int drm_legacy_getsareactx(struct drm_device *dev, void *data,
@@ -182,7 +176,7 @@ int drm_legacy_getsareactx(struct drm_device *dev, void 
*data,
 
        mutex_lock(&dev->struct_mutex);
 
-       map = idr_find(&dev->ctx_idr, request->ctx_id);
+       map = xa_load(&dev->ctxts, request->ctx_id);
        if (!map) {
                mutex_unlock(&dev->struct_mutex);
                return -EINVAL;
@@ -215,7 +209,7 @@ int drm_legacy_getsareactx(struct drm_device *dev, void 
*data,
  * \return zero on success or a negative number on failure.
  *
  * Searches the mapping specified in \p arg and update the entry in
- * drm_device::ctx_idr with it.
+ * drm_device::ctxts with it.
  */
 int drm_legacy_setsareactx(struct drm_device *dev, void *data,
                           struct drm_file *file_priv)
@@ -243,7 +237,7 @@ int drm_legacy_setsareactx(struct drm_device *dev, void 
*data,
        if (!map)
                goto bad;
 
-       if (IS_ERR(idr_replace(&dev->ctx_idr, map, request->ctx_id)))
+       if (xa_is_err(xa_store(&dev->ctxts, request->ctx_id, map, GFP_KERNEL)))
                goto bad;
 
        mutex_unlock(&dev->struct_mutex);
diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h
index 52e271b97de8..b3b025b76f3e 100644
--- a/include/drm/drm_device.h
+++ b/include/drm/drm_device.h
@@ -115,7 +115,7 @@ struct drm_device {
        struct list_head ctxlist;       /**< Linked list of context handles */
        struct mutex ctxlist_mutex;     /**< For ctxlist */
 
-       struct idr ctx_idr;
+       struct xarray ctxts;
 
        struct list_head vmalist;       /**< List of vmas (for debugging) */
 
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reply via email to