diff mbox series

[6/7] accel/qaic: Create a function to initialize BO

Message ID 20230901172247.11410-7-quic_jhugo@quicinc.com (mailing list archive)
State Not Applicable
Headers show
Series accel/qaic: Extend uAPI to support undoing ATTACH_SLICE_BO | expand

Commit Message

Jeffrey Hugo Sept. 1, 2023, 5:22 p.m. UTC
From: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>

This makes sure that we have a single place to initialize and
re-initialize BO.

Use this new API to cleanup release_dbc()

We will need this for next patch to detach slicing to a BO.

Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
---
 drivers/accel/qaic/qaic_data.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Stanislaw Gruszka Sept. 17, 2023, 8:48 a.m. UTC | #1
On Fri, Sep 01, 2023 at 11:22:46AM -0600, Jeffrey Hugo wrote:
> From: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
> 
> This makes sure that we have a single place to initialize and
> re-initialize BO.
> 
> Use this new API to cleanup release_dbc()
> 
> We will need this for next patch to detach slicing to a BO.
> 
> Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
> ---
>  drivers/accel/qaic/qaic_data.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
> index 6e44e00937af..2acb9dbac88b 100644
> --- a/drivers/accel/qaic/qaic_data.c
> +++ b/drivers/accel/qaic/qaic_data.c
> @@ -635,6 +635,18 @@ static const struct drm_gem_object_funcs qaic_gem_funcs = {
>  	.vm_ops = &drm_vm_ops,
>  };
>  
> +static void qaic_init_bo(struct qaic_bo *bo, bool reinit)
> +{
> +	if (reinit) {
> +		bo->sliced = false;
> +		reinit_completion(&bo->xfer_done);
> +	} else {
> +		init_completion(&bo->xfer_done);
> +	}
> +	complete_all(&bo->xfer_done);
Why do you need complete_all() here ? 

Regards
Stanislaw
Jeffrey Hugo Sept. 22, 2023, 2:59 p.m. UTC | #2
On 9/17/2023 2:48 AM, Stanislaw Gruszka wrote:
> On Fri, Sep 01, 2023 at 11:22:46AM -0600, Jeffrey Hugo wrote:
>> From: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
>>
>> This makes sure that we have a single place to initialize and
>> re-initialize BO.
>>
>> Use this new API to cleanup release_dbc()
>>
>> We will need this for next patch to detach slicing to a BO.
>>
>> Signed-off-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com>
>> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
>> Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
>> ---
>>   drivers/accel/qaic/qaic_data.c | 20 ++++++++++++++------
>>   1 file changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
>> index 6e44e00937af..2acb9dbac88b 100644
>> --- a/drivers/accel/qaic/qaic_data.c
>> +++ b/drivers/accel/qaic/qaic_data.c
>> @@ -635,6 +635,18 @@ static const struct drm_gem_object_funcs qaic_gem_funcs = {
>>   	.vm_ops = &drm_vm_ops,
>>   };
>>   
>> +static void qaic_init_bo(struct qaic_bo *bo, bool reinit)
>> +{
>> +	if (reinit) {
>> +		bo->sliced = false;
>> +		reinit_completion(&bo->xfer_done);
>> +	} else {
>> +		init_completion(&bo->xfer_done);
>> +	}
>> +	complete_all(&bo->xfer_done);
> Why do you need complete_all() here ?

This is moved from qaic_alloc_init_bo().

This puts the BO in a state where the wait_exec ioctl will fall through 
and return if userspace immediately calls it after allocating the BO, 
prior to submitting the BO to hardware.  Otherwise we need a special, 
one off check to see that the BO was never submitted to the hardware and 
handle that edge case.

-Jeff
diff mbox series

Patch

diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index 6e44e00937af..2acb9dbac88b 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -635,6 +635,18 @@  static const struct drm_gem_object_funcs qaic_gem_funcs = {
 	.vm_ops = &drm_vm_ops,
 };
 
+static void qaic_init_bo(struct qaic_bo *bo, bool reinit)
+{
+	if (reinit) {
+		bo->sliced = false;
+		reinit_completion(&bo->xfer_done);
+	} else {
+		init_completion(&bo->xfer_done);
+	}
+	complete_all(&bo->xfer_done);
+	INIT_LIST_HEAD(&bo->slices);
+}
+
 static struct qaic_bo *qaic_alloc_init_bo(void)
 {
 	struct qaic_bo *bo;
@@ -643,9 +655,7 @@  static struct qaic_bo *qaic_alloc_init_bo(void)
 	if (!bo)
 		return ERR_PTR(-ENOMEM);
 
-	INIT_LIST_HEAD(&bo->slices);
-	init_completion(&bo->xfer_done);
-	complete_all(&bo->xfer_done);
+	qaic_init_bo(bo, false);
 
 	return bo;
 }
@@ -1880,9 +1890,7 @@  void release_dbc(struct qaic_device *qdev, u32 dbc_id)
 	list_for_each_entry_safe(bo, bo_temp, &dbc->bo_lists, bo_list) {
 		qaic_free_slices_bo(bo);
 		qaic_unprepare_bo(qdev, bo);
-		bo->sliced = false;
-		INIT_LIST_HEAD(&bo->slices);
-		init_completion(&bo->xfer_done);
+		qaic_init_bo(bo, true);
 		list_del(&bo->bo_list);
 	}