Commit 1938d1ae authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Gerd Hoffmann

drm/virtio: Replace IDRs with IDAs

These IDRs were only being used to allocate unique numbers, not to look
up pointers, so they can use the more space-efficient IDA instead.
Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20180926160031.15721-2-willy@infradead.org

[ kraxel: resolve conflict ]
Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 6c1cd97b
...@@ -191,8 +191,7 @@ struct virtio_gpu_device { ...@@ -191,8 +191,7 @@ struct virtio_gpu_device {
struct kmem_cache *vbufs; struct kmem_cache *vbufs;
bool vqs_ready; bool vqs_ready;
struct idr resource_idr; struct ida resource_ida;
spinlock_t resource_idr_lock;
wait_queue_head_t resp_wq; wait_queue_head_t resp_wq;
/* current display info */ /* current display info */
...@@ -201,8 +200,7 @@ struct virtio_gpu_device { ...@@ -201,8 +200,7 @@ struct virtio_gpu_device {
struct virtio_gpu_fence_driver fence_drv; struct virtio_gpu_fence_driver fence_drv;
struct idr ctx_id_idr; struct ida ctx_id_ida;
spinlock_t ctx_id_idr_lock;
bool has_virgl_3d; bool has_virgl_3d;
......
...@@ -55,21 +55,13 @@ static void virtio_gpu_config_changed_work_func(struct work_struct *work) ...@@ -55,21 +55,13 @@ static void virtio_gpu_config_changed_work_func(struct work_struct *work)
static void virtio_gpu_ctx_id_get(struct virtio_gpu_device *vgdev, static void virtio_gpu_ctx_id_get(struct virtio_gpu_device *vgdev,
uint32_t *resid) uint32_t *resid)
{ {
int handle; int handle = ida_alloc_min(&vgdev->ctx_id_ida, 1, GFP_KERNEL);
idr_preload(GFP_KERNEL);
spin_lock(&vgdev->ctx_id_idr_lock);
handle = idr_alloc(&vgdev->ctx_id_idr, NULL, 1, 0, 0);
spin_unlock(&vgdev->ctx_id_idr_lock);
idr_preload_end();
*resid = handle; *resid = handle;
} }
static void virtio_gpu_ctx_id_put(struct virtio_gpu_device *vgdev, uint32_t id) static void virtio_gpu_ctx_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
{ {
spin_lock(&vgdev->ctx_id_idr_lock); ida_free(&vgdev->ctx_id_ida, id);
idr_remove(&vgdev->ctx_id_idr, id);
spin_unlock(&vgdev->ctx_id_idr_lock);
} }
static void virtio_gpu_context_create(struct virtio_gpu_device *vgdev, static void virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
...@@ -151,10 +143,8 @@ int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags) ...@@ -151,10 +143,8 @@ int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags)
vgdev->dev = dev->dev; vgdev->dev = dev->dev;
spin_lock_init(&vgdev->display_info_lock); spin_lock_init(&vgdev->display_info_lock);
spin_lock_init(&vgdev->ctx_id_idr_lock); ida_init(&vgdev->ctx_id_ida);
idr_init(&vgdev->ctx_id_idr); ida_init(&vgdev->resource_ida);
spin_lock_init(&vgdev->resource_idr_lock);
idr_init(&vgdev->resource_idr);
init_waitqueue_head(&vgdev->resp_wq); init_waitqueue_head(&vgdev->resp_wq);
virtio_gpu_init_vq(&vgdev->ctrlq, virtio_gpu_dequeue_ctrl_func); virtio_gpu_init_vq(&vgdev->ctrlq, virtio_gpu_dequeue_ctrl_func);
virtio_gpu_init_vq(&vgdev->cursorq, virtio_gpu_dequeue_cursor_func); virtio_gpu_init_vq(&vgdev->cursorq, virtio_gpu_dequeue_cursor_func);
......
...@@ -28,21 +28,13 @@ ...@@ -28,21 +28,13 @@
static void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev, static void virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
uint32_t *resid) uint32_t *resid)
{ {
int handle; int handle = ida_alloc_min(&vgdev->resource_ida, 1, GFP_KERNEL);
idr_preload(GFP_KERNEL);
spin_lock(&vgdev->resource_idr_lock);
handle = idr_alloc(&vgdev->resource_idr, NULL, 1, 0, GFP_NOWAIT);
spin_unlock(&vgdev->resource_idr_lock);
idr_preload_end();
*resid = handle; *resid = handle;
} }
static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id) static void virtio_gpu_resource_id_put(struct virtio_gpu_device *vgdev, uint32_t id)
{ {
spin_lock(&vgdev->resource_idr_lock); ida_free(&vgdev->resource_ida, id);
idr_remove(&vgdev->resource_idr, id);
spin_unlock(&vgdev->resource_idr_lock);
} }
static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo) static void virtio_gpu_ttm_bo_destroy(struct ttm_buffer_object *tbo)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment