]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drm: Convert ctx_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Thu, 14 Feb 2019 12:58:31 +0000 (07:58 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:30 +0000 (23:39 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/gpu/drm/drm_context.c
include/drm/drm_device.h

index 1f802d8e5681e621b27467d4d16675b1f1beca56..7c48cbcc2f5dc7913771ab789bb9d92285cf82bb 100644 (file)
@@ -54,8 +54,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)
 {
@@ -63,9 +62,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);
 }
 
 /**
@@ -74,18 +71,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;
 }
 
 /**
@@ -93,7 +89,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)
 {
@@ -101,7 +97,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);
 }
 
 /**
@@ -109,8 +105,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)
 {
@@ -118,9 +114,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);
 }
 
 /**
@@ -172,7 +166,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,
@@ -188,7 +182,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;
@@ -221,7 +215,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)
@@ -249,7 +243,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);
index d3c3d087d238d392b453e9d65c480315db554019..aba3ce7b1970b80c1d20694bedf85d9055994079 100644 (file)
@@ -318,7 +318,7 @@ struct drm_device {
        struct mutex ctxlist_mutex;
 
        /* Context handle management */
-       struct idr ctx_idr;
+       struct xarray ctxts;
 
        /* Memory management - linked list of regions */
        struct list_head maplist;