diff mbox series

[v1,11/18] media: hantro: Add helper function for auxiliary buffers allocation

Message ID 20210217080306.157876-12-benjamin.gaignard@collabora.com (mailing list archive)
State New, archived
Headers show
Series Add HANTRO G2/HEVC decoder support for IMX8MQ | expand

Commit Message

Benjamin Gaignard Feb. 17, 2021, 8:02 a.m. UTC
Add helper functions to allocate and free auxiliary buffers.
These buffers aren't for frames but are needed by the hardware
to store scaling matrix, tiles size, border filters etc...

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 drivers/staging/media/hantro/hantro.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Ezequiel Garcia Feb. 17, 2021, 8:42 p.m. UTC | #1
Hi Benjamin,

On Wed, 2021-02-17 at 09:02 +0100, Benjamin Gaignard wrote:
> Add helper functions to allocate and free auxiliary buffers.
> These buffers aren't for frames but are needed by the hardware
> to store scaling matrix, tiles size, border filters etc...
> 
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
> Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
> ---
>  drivers/staging/media/hantro/hantro.h | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
> index a9b80b2c9124..7f842edbc341 100644
> --- a/drivers/staging/media/hantro/hantro.h
> +++ b/drivers/staging/media/hantro/hantro.h
> @@ -446,6 +446,30 @@ hantro_get_dec_buf(struct hantro_ctx *ctx, struct vb2_buffer *vb)
>         return vb2_plane_vaddr(vb, 0);
>  }
>  
> +static inline int
> +hantro_aux_buf_alloc(struct hantro_dev *vpu,
> +                    struct hantro_aux_buf *buf, size_t size)
> +{

Can you add convert the dma_alloc_ calls in the driver,
and squash it in this patch?

I.e. hantro_h264_dec_init, hantro_vp8_dec_init, etc.

Thanks!
Ezequiel

> +       buf->cpu = dma_alloc_coherent(vpu->dev, size, &buf->dma, GFP_KERNEL);
> +       if (!buf->cpu)
> +               return -ENOMEM;
> +
> +       buf->size = size;
> +       return 0;
> +}
> +
> +static inline void
> +hantro_aux_buf_free(struct hantro_dev *vpu,
> +                   struct hantro_aux_buf *buf)
> +{
> +       if (buf->cpu)
> +               dma_free_coherent(vpu->dev, buf->size, buf->cpu, buf->dma);
> +
> +       buf->cpu = NULL;
> +       buf->dma = 0;
> +       buf->size = 0;
> +}
> +
>  void hantro_postproc_disable(struct hantro_ctx *ctx);
>  void hantro_postproc_enable(struct hantro_ctx *ctx);
>  void hantro_postproc_free(struct hantro_ctx *ctx);
Benjamin Gaignard Feb. 18, 2021, 2:51 p.m. UTC | #2
Le 17/02/2021 à 21:42, Ezequiel Garcia a écrit :
> Hi Benjamin,
>
> On Wed, 2021-02-17 at 09:02 +0100, Benjamin Gaignard wrote:
>> Add helper functions to allocate and free auxiliary buffers.
>> These buffers aren't for frames but are needed by the hardware
>> to store scaling matrix, tiles size, border filters etc...
>>
>> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
>> Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
>> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
>> ---
>>   drivers/staging/media/hantro/hantro.h | 24 ++++++++++++++++++++++++
>>   1 file changed, 24 insertions(+)
>>
>> diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
>> index a9b80b2c9124..7f842edbc341 100644
>> --- a/drivers/staging/media/hantro/hantro.h
>> +++ b/drivers/staging/media/hantro/hantro.h
>> @@ -446,6 +446,30 @@ hantro_get_dec_buf(struct hantro_ctx *ctx, struct vb2_buffer *vb)
>>          return vb2_plane_vaddr(vb, 0);
>>   }
>>   
>> +static inline int
>> +hantro_aux_buf_alloc(struct hantro_dev *vpu,
>> +                    struct hantro_aux_buf *buf, size_t size)
>> +{
> Can you add convert the dma_alloc_ calls in the driver,
> and squash it in this patch?
>
> I.e. hantro_h264_dec_init, hantro_vp8_dec_init, etc.

Sure I will that in v2.
Benjamin

>
> Thanks!
> Ezequiel
>
>> +       buf->cpu = dma_alloc_coherent(vpu->dev, size, &buf->dma, GFP_KERNEL);
>> +       if (!buf->cpu)
>> +               return -ENOMEM;
>> +
>> +       buf->size = size;
>> +       return 0;
>> +}
>> +
>> +static inline void
>> +hantro_aux_buf_free(struct hantro_dev *vpu,
>> +                   struct hantro_aux_buf *buf)
>> +{
>> +       if (buf->cpu)
>> +               dma_free_coherent(vpu->dev, buf->size, buf->cpu, buf->dma);
>> +
>> +       buf->cpu = NULL;
>> +       buf->dma = 0;
>> +       buf->size = 0;
>> +}
>> +
>>   void hantro_postproc_disable(struct hantro_ctx *ctx);
>>   void hantro_postproc_enable(struct hantro_ctx *ctx);
>>   void hantro_postproc_free(struct hantro_ctx *ctx);
>
>
diff mbox series

Patch

diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h
index a9b80b2c9124..7f842edbc341 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -446,6 +446,30 @@  hantro_get_dec_buf(struct hantro_ctx *ctx, struct vb2_buffer *vb)
 	return vb2_plane_vaddr(vb, 0);
 }
 
+static inline int
+hantro_aux_buf_alloc(struct hantro_dev *vpu,
+		     struct hantro_aux_buf *buf, size_t size)
+{
+	buf->cpu = dma_alloc_coherent(vpu->dev, size, &buf->dma, GFP_KERNEL);
+	if (!buf->cpu)
+		return -ENOMEM;
+
+	buf->size = size;
+	return 0;
+}
+
+static inline void
+hantro_aux_buf_free(struct hantro_dev *vpu,
+		    struct hantro_aux_buf *buf)
+{
+	if (buf->cpu)
+		dma_free_coherent(vpu->dev, buf->size, buf->cpu, buf->dma);
+
+	buf->cpu = NULL;
+	buf->dma = 0;
+	buf->size = 0;
+}
+
 void hantro_postproc_disable(struct hantro_ctx *ctx);
 void hantro_postproc_enable(struct hantro_ctx *ctx);
 void hantro_postproc_free(struct hantro_ctx *ctx);