@@ -47,7 +47,7 @@ static int sis_driver_load(struct drm_device *dev, unsigned long chipset)
if (dev_priv == NULL)
return -ENOMEM;
- idr_init(&dev_priv->object_idr);
+ xa_init_flags(&dev_priv->objects, XA_FLAGS_ALLOC1);
dev->dev_private = (void *)dev_priv;
dev_priv->chipset = chipset;
@@ -58,8 +58,6 @@ static void sis_driver_unload(struct drm_device *dev)
{
drm_sis_private_t *dev_priv = dev->dev_private;
- idr_destroy(&dev_priv->object_idr);
-
kfree(dev_priv);
}
@@ -64,7 +64,7 @@ typedef struct drm_sis_private {
struct drm_mm vram_mm;
struct drm_mm agp_mm;
/** Mapping of userspace keys to mm objects */
- struct idr object_idr;
+ struct xarray objects;
} drm_sis_private_t;
struct sis_file_private {
@@ -84,9 +84,10 @@ static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file,
{
drm_sis_private_t *dev_priv = dev->dev_private;
drm_sis_mem_t *mem = data;
- int retval = 0, user_key;
+ int retval = 0;
struct sis_memblock *item;
struct sis_file_private *file_priv = file->driver_priv;
+ unsigned int id;
unsigned long offset;
mutex_lock(&dev->struct_mutex);
@@ -128,23 +129,22 @@ static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file,
if (retval)
goto fail_alloc;
- retval = idr_alloc(&dev_priv->object_idr, item, 1, 0, GFP_KERNEL);
+ retval = xa_alloc(&dev_priv->objects, &id, item, xa_limit_31b,
+ GFP_KERNEL);
if (retval < 0)
- goto fail_idr;
- user_key = retval;
-
+ goto fail_xa;
list_add(&item->owner_list, &file_priv->obj_list);
mutex_unlock(&dev->struct_mutex);
+ mem->free = id;
mem->offset = ((pool == 0) ?
dev_priv->vram_offset : dev_priv->agp_offset) +
(offset << SIS_MM_ALIGN_SHIFT);
- mem->free = user_key;
mem->size = mem->size << SIS_MM_ALIGN_SHIFT;
return 0;
-fail_idr:
+fail_xa:
drm_mm_remove_node(&item->mm_node);
fail_alloc:
kfree(item);
@@ -167,13 +167,12 @@ static int sis_drm_free(struct drm_device *dev, void *data, struct drm_file *fil
struct sis_memblock *obj;
mutex_lock(&dev->struct_mutex);
- obj = idr_find(&dev_priv->object_idr, mem->free);
+ obj = xa_erase(&dev_priv->objects, mem->free);
if (obj == NULL) {
mutex_unlock(&dev->struct_mutex);
return -EINVAL;
}
- idr_remove(&dev_priv->object_idr, mem->free);
list_del(&obj->owner_list);
if (drm_mm_node_allocated(&obj->mm_node))
drm_mm_remove_node(&obj->mm_node);
Signed-off-by: Matthew Wilcox <willy@infradead.org> --- drivers/gpu/drm/sis/sis_drv.c | 4 +--- drivers/gpu/drm/sis/sis_drv.h | 2 +- drivers/gpu/drm/sis/sis_mm.c | 17 ++++++++--------- 3 files changed, 10 insertions(+), 13 deletions(-)