int qxl_surface_id_alloc(struct qxl_device *qdev,
struct qxl_bo *surf)
{
- uint32_t handle;
- int idr_ret;
- int count = 0;
+ int ret;
again:
- idr_preload(GFP_ATOMIC);
- spin_lock(&qdev->surf_id_idr_lock);
- idr_ret = idr_alloc(&qdev->surf_id_idr, NULL, 1, 0, GFP_NOWAIT);
- spin_unlock(&qdev->surf_id_idr_lock);
- idr_preload_end();
- if (idr_ret < 0)
- return idr_ret;
- handle = idr_ret;
-
- if (handle >= qdev->rom->n_surfaces) {
- count++;
- spin_lock(&qdev->surf_id_idr_lock);
- idr_remove(&qdev->surf_id_idr, handle);
- spin_unlock(&qdev->surf_id_idr_lock);
+ ret = xa_alloc(&qdev->surfaces, &surf->surface_id, NULL,
+ XA_LIMIT(0, qdev->rom->n_surfaces - 1), GFP_ATOMIC);
+ if (ret == -EBUSY) {
qxl_reap_surface_id(qdev, 2);
goto again;
}
- surf->surface_id = handle;
+ if (ret < 0)
+ return ret;
- spin_lock(&qdev->surf_id_idr_lock);
- qdev->last_alloced_surf_id = handle;
- spin_unlock(&qdev->surf_id_idr_lock);
+ xa_lock(&qdev->surfaces);
+ qdev->last_alloced_surf_id = surf->surface_id;
+ xa_unlock(&qdev->surfaces);
return 0;
}
void qxl_surface_id_dealloc(struct qxl_device *qdev,
uint32_t surface_id)
{
- spin_lock(&qdev->surf_id_idr_lock);
- idr_remove(&qdev->surf_id_idr, surface_id);
- spin_unlock(&qdev->surf_id_idr_lock);
+ xa_erase(&qdev->surfaces, surface_id);
}
int qxl_hw_surface_alloc(struct qxl_device *qdev,
qxl_release_fence_buffer_objects(release);
surf->hw_surf_alloc = true;
- spin_lock(&qdev->surf_id_idr_lock);
- idr_replace(&qdev->surf_id_idr, surf, surf->surface_id);
- spin_unlock(&qdev->surf_id_idr_lock);
+ xa_store(&qdev->surfaces, surf->surface_id, surf, GFP_KERNEL);
return 0;
}
return ret;
surf->surf_create = NULL;
- /* remove the surface from the idr, but not the surface id yet */
- spin_lock(&qdev->surf_id_idr_lock);
- idr_replace(&qdev->surf_id_idr, NULL, surf->surface_id);
- spin_unlock(&qdev->surf_id_idr_lock);
+ /* remove the surface from the array, but don't free the surface id */
+ xa_store(&qdev->surfaces, surf->surface_id, NULL, 0);
surf->hw_surf_alloc = false;
id = surf->surface_id;
mutex_lock(&qdev->surf_evict_mutex);
again:
- spin_lock(&qdev->surf_id_idr_lock);
+ xa_lock(&qdev->surfaces);
start = qdev->last_alloced_surf_id + 1;
- spin_unlock(&qdev->surf_id_idr_lock);
+ xa_unlock(&qdev->surfaces);
for (i = start; i < start + qdev->rom->n_surfaces; i++) {
void *objptr;
int surfid = i % qdev->rom->n_surfaces;
- /* this avoids the case where the objects is in the
- idr but has been evicted half way - its makes
- the idr lookup atomic with the eviction */
- spin_lock(&qdev->surf_id_idr_lock);
- objptr = idr_find(&qdev->surf_id_idr, surfid);
- spin_unlock(&qdev->surf_id_idr_lock);
+ /* this avoids the case where the object is in the
+ array but has been evicted half way - it makes
+ the array lookup atomic with the eviction */
+ xa_lock(&qdev->surfaces);
+ objptr = xa_load(&qdev->surfaces, surfid);
+ xa_unlock(&qdev->surfaces);
if (!objptr)
continue;