drm/imagination: Populate FW common context ID before passing to the FW

Initialise the context ID for the FW common context correctly by moving
the context allocation earlier.

Signed-off-by: Brajesh Gupta <brajesh.gupta@imgtec.com>
Reviewed-by: Matt Coster <matt.coster@imgtec.com>
Link: https://patch.msgid.link/20260519-b4-context_reset-v2-1-931018a7131d@imgtec.com
Signed-off-by: Matt Coster <matt.coster@imgtec.com>
This commit is contained in:
Brajesh Gupta 2026-05-19 13:55:26 +05:30 committed by Matt Coster
parent 0d5da248ea
commit de1e8a590f
No known key found for this signature in database
GPG Key ID: 79BC19F3D9DE6AB0

View File

@ -318,10 +318,14 @@ int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_co
goto err_put_vm;
}
err = pvr_context_create_queues(ctx, args, ctx->data);
err = xa_alloc(&pvr_dev->ctx_ids, &ctx->ctx_id, ctx, xa_limit_32b, GFP_KERNEL);
if (err)
goto err_free_ctx_data;
err = pvr_context_create_queues(ctx, args, ctx->data);
if (err)
goto err_free_ctx_id;
err = init_fw_objs(ctx, args, ctx->data);
if (err)
goto err_destroy_queues;
@ -329,22 +333,11 @@ int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_co
err = pvr_fw_object_create(pvr_dev, ctx_size, PVR_BO_FW_FLAGS_DEVICE_UNCACHED,
ctx_fw_data_init, ctx, &ctx->fw_obj);
if (err)
goto err_free_ctx_data;
err = xa_alloc(&pvr_dev->ctx_ids, &ctx->ctx_id, ctx, xa_limit_32b, GFP_KERNEL);
if (err)
goto err_destroy_fw_obj;
goto err_destroy_queues;
err = xa_alloc(&pvr_file->ctx_handles, &args->handle, ctx, xa_limit_32b, GFP_KERNEL);
if (err) {
/*
* It's possible that another thread could have taken a reference on the context at
* this point as it is in the ctx_ids xarray. Therefore instead of directly
* destroying the context, drop a reference instead.
*/
pvr_context_put(ctx);
return err;
}
if (err)
goto err_destroy_fw_obj;
spin_lock(&pvr_dev->ctx_list_lock);
list_add_tail(&ctx->file_link, &pvr_file->contexts);
@ -358,6 +351,15 @@ int pvr_context_create(struct pvr_file *pvr_file, struct drm_pvr_ioctl_create_co
err_destroy_queues:
pvr_context_destroy_queues(ctx);
err_free_ctx_id:
/*
* Ctx_id is not exposed to userspace and not visible yet within
* the kernel/FW, plus a matching context handle (exposed to userspace)
* hasn't been allocated yet, so it is safe to remove ctx_id
* from the ctx_ids xarray.
*/
xa_erase(&pvr_dev->ctx_ids, ctx->ctx_id);
err_free_ctx_data:
kfree(ctx->data);