]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drm/vmwgfx: Convert res_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Fri, 15 Feb 2019 04:11:53 +0000 (23:11 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:36 +0000 (23:39 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c

index 9506190a03009cd0e2e6f51d37a0b42096130bfb..0c724d435b7545366599fb48b1914d6240146eb8 100644 (file)
@@ -637,7 +637,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
        spin_lock_init(&dev_priv->cursor_lock);
 
        for (i = vmw_res_context; i < vmw_res_max; ++i) {
-               idr_init(&dev_priv->res_idr[i]);
+               xa_init_flags(&dev_priv->resources[i], XA_FLAGS_ALLOC1);
                INIT_LIST_HEAD(&dev_priv->res_lru[i]);
        }
 
@@ -950,9 +950,6 @@ out_no_device:
 out_err4:
        memunmap(dev_priv->mmio_virt);
 out_err0:
-       for (i = vmw_res_context; i < vmw_res_max; ++i)
-               idr_destroy(&dev_priv->res_idr[i]);
-
        if (dev_priv->ctx.staged_bindings)
                vmw_binding_state_free(dev_priv->ctx.staged_bindings);
        kfree(dev_priv);
@@ -962,7 +959,6 @@ out_err0:
 static void vmw_driver_unload(struct drm_device *dev)
 {
        struct vmw_private *dev_priv = vmw_priv(dev);
-       enum vmw_res_type i;
 
        unregister_pm_notifier(&dev_priv->pm_nb);
 
@@ -1001,9 +997,6 @@ static void vmw_driver_unload(struct drm_device *dev)
        if (dev_priv->ctx.staged_bindings)
                vmw_binding_state_free(dev_priv->ctx.staged_bindings);
 
-       for (i = vmw_res_context; i < vmw_res_max; ++i)
-               idr_destroy(&dev_priv->res_idr[i]);
-
        kfree(dev_priv);
 }
 
index 366dcfc1f9bbc8ea05c67434d07da950d93041bc..9a64ae01a0472310c471887aaaa02132180e0d16 100644 (file)
@@ -483,7 +483,8 @@ struct vmw_private {
         */
 
        spinlock_t resource_lock;
-       struct idr res_idr[vmw_res_max];
+       struct xarray resources[vmw_res_max];
+
        /*
         * Block lastclose from racing with firstopen.
         */
index 1d38a8b2f2ec8be2839e9b297ab1f1bbf5eb9fdd..7668bc7112d304a6c44996dfc47ca9a9a554c343 100644 (file)
@@ -56,13 +56,11 @@ vmw_resource_reference_unless_doomed(struct vmw_resource *res)
 void vmw_resource_release_id(struct vmw_resource *res)
 {
        struct vmw_private *dev_priv = res->dev_priv;
-       struct idr *idr = &dev_priv->res_idr[res->func->res_type];
+       struct xarray *xa = &dev_priv->resources[res->func->res_type];
 
-       spin_lock(&dev_priv->resource_lock);
        if (res->id != -1)
-               idr_remove(idr, res->id);
+               xa_erase(xa, res->id);
        res->id = -1;
-       spin_unlock(&dev_priv->resource_lock);
 }
 
 static void vmw_resource_release(struct kref *kref)
@@ -70,8 +68,7 @@ static void vmw_resource_release(struct kref *kref)
        struct vmw_resource *res =
            container_of(kref, struct vmw_resource, kref);
        struct vmw_private *dev_priv = res->dev_priv;
-       int id;
-       struct idr *idr = &dev_priv->res_idr[res->func->res_type];
+       struct xarray *xa = &dev_priv->resources[res->func->res_type];
 
        spin_lock(&dev_priv->resource_lock);
        list_del_init(&res->lru_head);
@@ -101,16 +98,12 @@ static void vmw_resource_release(struct kref *kref)
                res->hw_destroy(res);
        }
 
-       id = res->id;
+       if (res->id != -1)
+               xa_erase(xa, res->id);
        if (res->res_free != NULL)
                res->res_free(res);
        else
                kfree(res);
-
-       spin_lock(&dev_priv->resource_lock);
-       if (id != -1)
-               idr_remove(idr, id);
-       spin_unlock(&dev_priv->resource_lock);
 }
 
 void vmw_resource_unreference(struct vmw_resource **p_res)
@@ -133,21 +126,11 @@ void vmw_resource_unreference(struct vmw_resource **p_res)
 int vmw_resource_alloc_id(struct vmw_resource *res)
 {
        struct vmw_private *dev_priv = res->dev_priv;
-       int ret;
-       struct idr *idr = &dev_priv->res_idr[res->func->res_type];
+       struct xarray *xa = &dev_priv->resources[res->func->res_type];
 
        BUG_ON(res->id != -1);
 
-       idr_preload(GFP_KERNEL);
-       spin_lock(&dev_priv->resource_lock);
-
-       ret = idr_alloc(idr, res, 1, 0, GFP_NOWAIT);
-       if (ret >= 0)
-               res->id = ret;
-
-       spin_unlock(&dev_priv->resource_lock);
-       idr_preload_end();
-       return ret < 0 ? ret : 0;
+       return xa_alloc(xa, &res->id, res, xa_limit_31b, GFP_NOWAIT);
 }
 
 /**