cb->hdev = hdev;
cb->ctx_id = ctx_id;
- spin_lock(&mgr->cb_lock);
- rc = idr_alloc(&mgr->cb_handles, cb, 1, 0, GFP_ATOMIC);
- spin_unlock(&mgr->cb_lock);
-
+ rc = xa_alloc(&mgr->cb_handles, &cb->id, cb, xa_limit_31b, GFP_KERNEL);
if (rc < 0) {
- dev_err(hdev->dev, "Failed to allocate IDR for a new CB\n");
+ dev_err(hdev->dev, "Failed to allocate ID for a new CB\n");
goto release_cb;
}
- cb->id = rc;
-
kref_init(&cb->refcount);
spin_lock_init(&cb->lock);
/*
- * idr is 32-bit so we can safely OR it with a mask that is above
+ * id is 32-bit so we can safely OR it with a mask that is above
* 32 bit
*/
*handle = cb->id | HL_MMAP_CB_MASK;
u32 handle;
int rc = 0;
- /*
- * handle was given to user to do mmap, I need to shift it back to
- * how the idr module gave it to me
- */
+ /* convert the handle back to an ID */
cb_handle >>= PAGE_SHIFT;
handle = (u32) cb_handle;
- spin_lock(&mgr->cb_lock);
-
- cb = idr_find(&mgr->cb_handles, handle);
+ cb = xa_erase(&mgr->cb_handles, handle);
if (cb) {
- idr_remove(&mgr->cb_handles, handle);
- spin_unlock(&mgr->cb_lock);
kref_put(&cb->refcount, cb_release);
} else {
- spin_unlock(&mgr->cb_lock);
dev_err(hdev->dev,
"CB destroy failed, no match to handle 0x%x\n", handle);
rc = -EINVAL;
{
struct hl_cb *cb;
- spin_lock(&mgr->cb_lock);
- cb = idr_find(&mgr->cb_handles, handle);
+ xa_lock(&mgr->cb_handles);
+ cb = xa_load(&mgr->cb_handles, handle);
if (!cb) {
- spin_unlock(&mgr->cb_lock);
+ xa_unlock(&mgr->cb_handles);
dev_warn(hdev->dev,
"CB get failed, no match to handle %d\n", handle);
return NULL;
kref_get(&cb->refcount);
- spin_unlock(&mgr->cb_lock);
+ xa_unlock(&mgr->cb_handles);
return cb;
void hl_cb_mgr_init(struct hl_cb_mgr *mgr)
{
- spin_lock_init(&mgr->cb_lock);
- idr_init(&mgr->cb_handles);
+ xa_init_flags(&mgr->cb_handles, XA_FLAGS_ALLOC1);
}
void hl_cb_mgr_fini(struct hl_device *hdev, struct hl_cb_mgr *mgr)
{
struct hl_cb *cb;
- struct idr *idp;
- u32 id;
-
- idp = &mgr->cb_handles;
+ unsigned long id;
- idr_for_each_entry(idp, cb, id) {
+ xa_for_each(&mgr->cb_handles, id, cb) {
if (kref_put(&cb->refcount, cb_release) != 1)
dev_err(hdev->dev,
- "CB %d for CTX ID %d is still alive\n",
+ "CB %ld for CTX ID %d is still alive\n",
id, cb->ctx_id);
}
-
- idr_destroy(&mgr->cb_handles);
}
struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size)