* \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)
{
!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);
}
/**
* \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;
}
/**
*
* \param dev DRM device.
*
- * Initialise the drm_device::ctx_idr
+ * Initialise the drm_device::ctxts
*/
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);
}
/**
*
* \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)
{
!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);
}
/**
* \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,
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;
* \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)
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);