struct mmal_msg_context {
struct vchiq_mmal_instance *instance;
- /* Index in the context_map idr so that we can find the
+ /* Index in the context_map so that we can find the
* mmal_msg_context again when servicing the VCHI reply.
*/
int handle;
/* vmalloc page to receive scratch bulk xfers into */
void *bulk_scratch;
- struct idr context_map;
- /* protect accesses to context_map */
- struct mutex context_map_lock;
+ struct xarray context_map;
/* component to use next */
int component_idx;
get_msg_context(struct vchiq_mmal_instance *instance)
{
struct mmal_msg_context *msg_context;
- int handle;
+ int err;
/* todo: should this be allocated from a pool to avoid kzalloc */
msg_context = kzalloc(sizeof(*msg_context), GFP_KERNEL);
if (!msg_context)
return ERR_PTR(-ENOMEM);
- /* Create an ID that will be passed along with our message so
+ msg_context->instance = instance;
+
+ /*
+ * Create an ID that will be passed along with our message so
* that when we service the VCHI reply, we can look up what
* message is being replied to.
*/
- mutex_lock(&instance->context_map_lock);
- handle = idr_alloc(&instance->context_map, msg_context,
- 0, 0, GFP_KERNEL);
- mutex_unlock(&instance->context_map_lock);
-
- if (handle < 0) {
+ err = xa_alloc(&instance->context_map, &msg_context->handle,
+ msg_context, xa_limit_32b, GFP_KERNEL);
+ if (err < 0) {
kfree(msg_context);
- return ERR_PTR(handle);
+ return ERR_PTR(err);
}
- msg_context->instance = instance;
- msg_context->handle = handle;
-
return msg_context;
}
static struct mmal_msg_context *
lookup_msg_context(struct vchiq_mmal_instance *instance, int handle)
{
- return idr_find(&instance->context_map, handle);
+ return xa_load(&instance->context_map, handle);
}
static void
{
struct vchiq_mmal_instance *instance = msg_context->instance;
- mutex_lock(&instance->context_map_lock);
- idr_remove(&instance->context_map, msg_context->handle);
- mutex_unlock(&instance->context_map_lock);
+ xa_erase(&instance->context_map, msg_context->handle);
kfree(msg_context);
}
vfree(instance->bulk_scratch);
- idr_destroy(&instance->context_map);
-
kfree(instance);
return status;
instance->bulk_scratch = vmalloc(PAGE_SIZE);
- mutex_init(&instance->context_map_lock);
- idr_init_base(&instance->context_map, 1);
+ xa_init_flags(&instance->context_map, XA_FLAGS_ALLOC1);
params.callback_param = instance;