Re: [PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-07-02 Thread Randy Li



On 06/27/2017 11:49 PM, Nicolas Dufresne wrote:

Le mardi 27 juin 2017 à 23:11 +0800, Jacob Chen a écrit :

Hi Nicolas.

2017-06-26 23:49 GMT+08:00 Nicolas Dufresne :


Le lundi 26 juin 2017 à 22:51 +0800, Jacob Chen a écrit :

Rockchip RGA is a separate 2D raster graphic acceleration unit.
It
accelerates 2D graphics operations, such as point/line drawing,
image
scaling, rotation, BitBLT, alpha blending and image
blur/sharpness.

The drvier is mostly based on s5p-g2d v4l2 m2m driver.
And supports various operations from the rendering pipeline.
  - copy
  - fast solid color fill
  - rotation
  - flip
  - alpha blending

The code in rga-hw.c is used to configure regs accroding to
operations.

The code in rga-buf.c is used to create private mmu table for
RGA.
The tables is stored in a list, and be removed when buffer is
cleanup.

Signed-off-by: Jacob Chen 
---
  drivers/media/platform/Kconfig|  11 +
  drivers/media/platform/Makefile   |   2 +
  drivers/media/platform/rockchip-rga/Makefile  |   3 +
  drivers/media/platform/rockchip-rga/rga-buf.c | 176 +
  drivers/media/platform/rockchip-rga/rga-hw.c  | 456 
  drivers/media/platform/rockchip-rga/rga-hw.h  | 434 
  drivers/media/platform/rockchip-rga/rga.c | 979
++
  drivers/media/platform/rockchip-rga/rga.h | 133 
  8 files changed, 2194 insertions(+)
  create mode 100644 drivers/media/platform/rockchip-rga/Makefile
  create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
  create mode 100644 drivers/media/platform/rockchip-rga/rga.c
  create mode 100644 drivers/media/platform/rockchip-rga/rga.h



Could be nice to generalize. We could setup a control and fill the
values base on porter duff operations, then drivers can implement a
subset. Right now, there is no generic way for userspace to know if
a
driver is just doing copies with some transformations, or if it can
actually do alpha blending hence used for composting streams. Note
that
I haven't looked at all possibilities, Freescale IMX.6 seems to
have a
similar driver, which has been wrapped in GStreamer with this
proposed
elements:

https://bugzilla.gnome.org/show_bug.cgi?id=772766



Yeah, i also want it use a generic api.
"porter duff operations" looks good, i will look at it.


+#define V4L2_CID_RGA_ALHPA_REG0 (V4L2_CID_USER_BASE | 0x1002)
+#define V4L2_CID_RGA_ALHPA_REG1 (V4L2_CID_USER_BASE | 0x1003)


It's not obvious why there is two CID, and how this differ from
existing V4L2_CID_ALPHA (the global alpha control).


They are used to calculate factors for below formulas.

 dst alpha = Factor1 * src alpha + Factor2 * dst alpha
 dst color = Factor3 * src color + Factor4 * dst color

I have no idea how to generalize it, and there is no upstream
application need it,
so i just simply exposed the reg.

In my memory, it is is used for convert AYUV to ARGB.


Then maybe it's better to just not expose it in the public API in the
initial patch (nothing forces you to enable everything). The idea is
that it can be added later as needed, taking the time to figure-out a
new API or to figure-out how this matches anything that exist.




+
+/* Operation values */
+#define OP_COPY 0
+#define OP_SOLID_FILL 1
+#define OP_ALPHA_BLEND 2
+
+struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum
v4l2_buf_type type);
+
+/* RGA Buffers Manage Part */
+extern const struct vb2_ops rga_qops;
+void *rga_buf_find_page(struct vb2_buffer *vb);
+void rga_buf_clean(struct rga_ctx *ctx);
+
+/* RGA Hardware Part */
+void rga_write(struct rockchip_rga *rga, u32 reg, u32 value);
+u32 rga_read(struct rockchip_rga *rga, u32 reg);
+void rga_mod(struct rockchip_rga *rga, u32 reg, u32 val, u32
mask);
+void rga_start(struct rockchip_rga *rga);
+void rga_cmd_set(struct rga_ctx *ctx, void *src_mmu_pages, void
*dst_mmu_pages);
+
+#endif


--
Randy Li



Re: [PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-06-27 Thread Jacob Chen
Hi,

2017-06-27 16:39 GMT+08:00 Tomasz Figa :
> Hi Jacob,
>
> Please see my comments inline.
>
> On Mon, Jun 26, 2017 at 11:51 PM, Jacob Chen  wrote:
>> Rockchip RGA is a separate 2D raster graphic acceleration unit. It
>> accelerates 2D graphics operations, such as point/line drawing, image
>> scaling, rotation, BitBLT, alpha blending and image blur/sharpness.
> [snip]
>> +static int rga_buf_init(struct vb2_buffer *vb)
>> +{
>> +   struct rga_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
>> +   struct rockchip_rga *rga = ctx->rga;
>> +   struct sg_table *sgt;
>> +   struct scatterlist *sgl;
>> +   unsigned int *pages;
>> +   struct rga_buf *buf;
>> +   unsigned int address, len, i, p;
>> +   unsigned int mapped_size = 0;
>> +
>> +   /* Create local MMU table for RGA */
>> +   sgt = vb2_plane_cookie(vb, 0);
>> +
>> +   /*
>> +* Alloc (2^3 * 4K) = 32K byte for storing pages, those space could
>> +* cover 32K * 4K = 128M ram address.
>
> Unless I'm missing something, there is 1024 32-bit values in one 4K
> page, which can point to 4 MB of memory. The code allocates 8 of them,
> which in total allows at most 32 MB per buffer.
>
>> +*/
>> +   pages = (unsigned int *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 3);
>
> This is rather unfortunate and you should expect failures here on
> actively used systems with uptime longer than few hours. Changing this
> to dma_alloc_coherent() and enabling CMA _might_ give you a bit better
> success rate, but...
>

I decide to alloc a page pool when driver probe and get page from that poll.

> Normally, this kind of (scatter-gather capable) hardware would allow
> some kind of linking of separate pages, e.g. last entry in the page
> would point to the next page, or something like that. Doesn't this RGA
> block have something similar?
>
> Best regards,
> Tomasz


Re: [PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-06-27 Thread Nicolas Dufresne
Le mardi 27 juin 2017 à 23:11 +0800, Jacob Chen a écrit :
> Hi Nicolas.
> 
> 2017-06-26 23:49 GMT+08:00 Nicolas Dufresne :
> > 
> > Le lundi 26 juin 2017 à 22:51 +0800, Jacob Chen a écrit :
> > > Rockchip RGA is a separate 2D raster graphic acceleration unit.
> > > It
> > > accelerates 2D graphics operations, such as point/line drawing,
> > > image
> > > scaling, rotation, BitBLT, alpha blending and image
> > > blur/sharpness.
> > > 
> > > The drvier is mostly based on s5p-g2d v4l2 m2m driver.
> > > And supports various operations from the rendering pipeline.
> > >  - copy
> > >  - fast solid color fill
> > >  - rotation
> > >  - flip
> > >  - alpha blending
> > > 
> > > The code in rga-hw.c is used to configure regs accroding to
> > > operations.
> > > 
> > > The code in rga-buf.c is used to create private mmu table for
> > > RGA.
> > > The tables is stored in a list, and be removed when buffer is
> > > cleanup.
> > > 
> > > Signed-off-by: Jacob Chen 
> > > ---
> > >  drivers/media/platform/Kconfig|  11 +
> > >  drivers/media/platform/Makefile   |   2 +
> > >  drivers/media/platform/rockchip-rga/Makefile  |   3 +
> > >  drivers/media/platform/rockchip-rga/rga-buf.c | 176 +
> > >  drivers/media/platform/rockchip-rga/rga-hw.c  | 456 
> > >  drivers/media/platform/rockchip-rga/rga-hw.h  | 434 
> > >  drivers/media/platform/rockchip-rga/rga.c | 979
> > > ++
> > >  drivers/media/platform/rockchip-rga/rga.h | 133 
> > >  8 files changed, 2194 insertions(+)
> > >  create mode 100644 drivers/media/platform/rockchip-rga/Makefile
> > >  create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
> > >  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
> > >  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
> > >  create mode 100644 drivers/media/platform/rockchip-rga/rga.c
> > >  create mode 100644 drivers/media/platform/rockchip-rga/rga.h
> > > 
> > > diff --git a/drivers/media/platform/Kconfig
> > > b/drivers/media/platform/Kconfig
> > > index c9106e1..8199bcf 100644
> > > --- a/drivers/media/platform/Kconfig
> > > +++ b/drivers/media/platform/Kconfig
> > > @@ -411,6 +411,17 @@ config VIDEO_RENESAS_VSP1
> > > To compile this driver as a module, choose M here: the
> > > module
> > > will be called vsp1.
> > > 
> > > +config VIDEO_ROCKCHIP_RGA
> > > + tristate "Rockchip Raster 2d Grapphic Acceleration Unit"
> > > + depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
> > > + depends on ARCH_ROCKCHIP || COMPILE_TEST
> > > + select VIDEOBUF2_DMA_SG
> > > + select V4L2_MEM2MEM_DEV
> > > + default n
> > > + ---help---
> > > +   This is a v4l2 driver for Rockchip SOC RGA2
> > > +   2d graphics accelerator.
> > > +
> > >  config VIDEO_TI_VPE
> > >   tristate "TI VPE (Video Processing Engine) driver"
> > >   depends on VIDEO_DEV && VIDEO_V4L2
> > > diff --git a/drivers/media/platform/Makefile
> > > b/drivers/media/platform/Makefile
> > > index 349ddf6..3bf096f 100644
> > > --- a/drivers/media/platform/Makefile
> > > +++ b/drivers/media/platform/Makefile
> > > @@ -54,6 +54,8 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)+=
> > > rcar_fdp1.o
> > >  obj-$(CONFIG_VIDEO_RENESAS_JPU)  += rcar_jpu.o
> > >  obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/
> > > 
> > > +obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga/
> > > +
> > >  obj-y+= omap/
> > > 
> > >  obj-$(CONFIG_VIDEO_AM437X_VPFE)  += am437x/
> > > diff --git a/drivers/media/platform/rockchip-rga/Makefile
> > > b/drivers/media/platform/rockchip-rga/Makefile
> > > new file mode 100644
> > > index 000..92fe254
> > > --- /dev/null
> > > +++ b/drivers/media/platform/rockchip-rga/Makefile
> > > @@ -0,0 +1,3 @@
> > > +rockchip-rga-objs := rga.o rga-hw.o rga-buf.o
> > > +
> > > +obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
> > > diff --git a/drivers/media/platform/rockchip-rga/rga-buf.c
> > > b/drivers/media/platform/rockchip-rga/rga-buf.c
> > > new file mode 100644
> > > index 000..8582092
> > > --- /dev/null
> > > +++ b/drivers/media/platform/rockchip-rga/rga-buf.c
> > > @@ -0,0 +1,176 @@
> > > +/*
> > > + * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
> > > + * Author: Jacob Chen 
> > > + *
> > > + * This software is licensed under the terms of the GNU General
> > > Public
> > > + * License version 2, as published by the Free Software
> > > Foundation,
> > > and
> > > + * may be copied, distributed, and modified under those terms.
> > > + *
> > > + * This program is distributed in the hope that it will be
> > > useful,
> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty
> > > of
> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > + * GNU General Public License for more details.
> > > + */
> > > +
> > > +#include 
> > > +
> > > +#include 
> > > 

Re: [PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-06-27 Thread Jacob Chen
Hi Tomasz,
Yeah, the comments are wrong, i will correct it

>> +*/
>> +   pages = (unsigned int *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 3);
>
> This is rather unfortunate and you should expect failures here on
> actively used systems with uptime longer than few hours. Changing this
> to dma_alloc_coherent() and enabling CMA _might_ give you a bit better
> success rate, but...
>
> Normally, this kind of (scatter-gather capable) hardware would allow
> some kind of linking of separate pages, e.g. last entry in the page
> would point to the next page, or something like that. Doesn't this RGA
> block have something similar?
>

Thx for pointing it out ! : )

I looked RGA drvier used in rockchip android and i find it use
kmalloc, so i think it might support separate pages.
I will test it.


> Best regards,
> Tomasz


Re: [PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-06-27 Thread Jacob Chen
Hi Nicolas.

2017-06-26 23:49 GMT+08:00 Nicolas Dufresne :
>
> Le lundi 26 juin 2017 à 22:51 +0800, Jacob Chen a écrit :
> > Rockchip RGA is a separate 2D raster graphic acceleration unit. It
> > accelerates 2D graphics operations, such as point/line drawing, image
> > scaling, rotation, BitBLT, alpha blending and image blur/sharpness.
> >
> > The drvier is mostly based on s5p-g2d v4l2 m2m driver.
> > And supports various operations from the rendering pipeline.
> >  - copy
> >  - fast solid color fill
> >  - rotation
> >  - flip
> >  - alpha blending
> >
> > The code in rga-hw.c is used to configure regs accroding to
> > operations.
> >
> > The code in rga-buf.c is used to create private mmu table for RGA.
> > The tables is stored in a list, and be removed when buffer is
> > cleanup.
> >
> > Signed-off-by: Jacob Chen 
> > ---
> >  drivers/media/platform/Kconfig|  11 +
> >  drivers/media/platform/Makefile   |   2 +
> >  drivers/media/platform/rockchip-rga/Makefile  |   3 +
> >  drivers/media/platform/rockchip-rga/rga-buf.c | 176 +
> >  drivers/media/platform/rockchip-rga/rga-hw.c  | 456 
> >  drivers/media/platform/rockchip-rga/rga-hw.h  | 434 
> >  drivers/media/platform/rockchip-rga/rga.c | 979
> > ++
> >  drivers/media/platform/rockchip-rga/rga.h | 133 
> >  8 files changed, 2194 insertions(+)
> >  create mode 100644 drivers/media/platform/rockchip-rga/Makefile
> >  create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
> >  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
> >  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
> >  create mode 100644 drivers/media/platform/rockchip-rga/rga.c
> >  create mode 100644 drivers/media/platform/rockchip-rga/rga.h
> >
> > diff --git a/drivers/media/platform/Kconfig
> > b/drivers/media/platform/Kconfig
> > index c9106e1..8199bcf 100644
> > --- a/drivers/media/platform/Kconfig
> > +++ b/drivers/media/platform/Kconfig
> > @@ -411,6 +411,17 @@ config VIDEO_RENESAS_VSP1
> > To compile this driver as a module, choose M here: the
> > module
> > will be called vsp1.
> >
> > +config VIDEO_ROCKCHIP_RGA
> > + tristate "Rockchip Raster 2d Grapphic Acceleration Unit"
> > + depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
> > + depends on ARCH_ROCKCHIP || COMPILE_TEST
> > + select VIDEOBUF2_DMA_SG
> > + select V4L2_MEM2MEM_DEV
> > + default n
> > + ---help---
> > +   This is a v4l2 driver for Rockchip SOC RGA2
> > +   2d graphics accelerator.
> > +
> >  config VIDEO_TI_VPE
> >   tristate "TI VPE (Video Processing Engine) driver"
> >   depends on VIDEO_DEV && VIDEO_V4L2
> > diff --git a/drivers/media/platform/Makefile
> > b/drivers/media/platform/Makefile
> > index 349ddf6..3bf096f 100644
> > --- a/drivers/media/platform/Makefile
> > +++ b/drivers/media/platform/Makefile
> > @@ -54,6 +54,8 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)+=
> > rcar_fdp1.o
> >  obj-$(CONFIG_VIDEO_RENESAS_JPU)  += rcar_jpu.o
> >  obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/
> >
> > +obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga/
> > +
> >  obj-y+= omap/
> >
> >  obj-$(CONFIG_VIDEO_AM437X_VPFE)  += am437x/
> > diff --git a/drivers/media/platform/rockchip-rga/Makefile
> > b/drivers/media/platform/rockchip-rga/Makefile
> > new file mode 100644
> > index 000..92fe254
> > --- /dev/null
> > +++ b/drivers/media/platform/rockchip-rga/Makefile
> > @@ -0,0 +1,3 @@
> > +rockchip-rga-objs := rga.o rga-hw.o rga-buf.o
> > +
> > +obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
> > diff --git a/drivers/media/platform/rockchip-rga/rga-buf.c
> > b/drivers/media/platform/rockchip-rga/rga-buf.c
> > new file mode 100644
> > index 000..8582092
> > --- /dev/null
> > +++ b/drivers/media/platform/rockchip-rga/rga-buf.c
> > @@ -0,0 +1,176 @@
> > +/*
> > + * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
> > + * Author: Jacob Chen 
> > + *
> > + * This software is licensed under the terms of the GNU General
> > Public
> > + * License version 2, as published by the Free Software Foundation,
> > and
> > + * may be copied, distributed, and modified under those terms.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + */
> > +
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "rga-hw.h"
> > +#include "rga.h"
> > +
> > +static int
> > +rga_queue_setup(struct vb2_queue *vq,
> > +unsigned int *nbuffers, unsigned int *nplanes,
> > +unsigned int sizes[], struct device *alloc_devs[])
> > +{
> > + struct rga_ctx *ctx = 

Re: [PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-06-27 Thread Tomasz Figa
Hi Jacob,

Please see my comments inline.

On Mon, Jun 26, 2017 at 11:51 PM, Jacob Chen  wrote:
> Rockchip RGA is a separate 2D raster graphic acceleration unit. It
> accelerates 2D graphics operations, such as point/line drawing, image
> scaling, rotation, BitBLT, alpha blending and image blur/sharpness.
[snip]
> +static int rga_buf_init(struct vb2_buffer *vb)
> +{
> +   struct rga_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
> +   struct rockchip_rga *rga = ctx->rga;
> +   struct sg_table *sgt;
> +   struct scatterlist *sgl;
> +   unsigned int *pages;
> +   struct rga_buf *buf;
> +   unsigned int address, len, i, p;
> +   unsigned int mapped_size = 0;
> +
> +   /* Create local MMU table for RGA */
> +   sgt = vb2_plane_cookie(vb, 0);
> +
> +   /*
> +* Alloc (2^3 * 4K) = 32K byte for storing pages, those space could
> +* cover 32K * 4K = 128M ram address.

Unless I'm missing something, there is 1024 32-bit values in one 4K
page, which can point to 4 MB of memory. The code allocates 8 of them,
which in total allows at most 32 MB per buffer.

> +*/
> +   pages = (unsigned int *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 3);

This is rather unfortunate and you should expect failures here on
actively used systems with uptime longer than few hours. Changing this
to dma_alloc_coherent() and enabling CMA _might_ give you a bit better
success rate, but...

Normally, this kind of (scatter-gather capable) hardware would allow
some kind of linking of separate pages, e.g. last entry in the page
would point to the next page, or something like that. Doesn't this RGA
block have something similar?

Best regards,
Tomasz


Re: [PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-06-26 Thread Nicolas Dufresne
Le lundi 26 juin 2017 à 22:51 +0800, Jacob Chen a écrit :
> Rockchip RGA is a separate 2D raster graphic acceleration unit. It
> accelerates 2D graphics operations, such as point/line drawing, image
> scaling, rotation, BitBLT, alpha blending and image blur/sharpness.
> 
> The drvier is mostly based on s5p-g2d v4l2 m2m driver.
> And supports various operations from the rendering pipeline.
>  - copy
>  - fast solid color fill
>  - rotation
>  - flip
>  - alpha blending
> 
> The code in rga-hw.c is used to configure regs accroding to
> operations.
> 
> The code in rga-buf.c is used to create private mmu table for RGA.
> The tables is stored in a list, and be removed when buffer is
> cleanup.
> 
> Signed-off-by: Jacob Chen 
> ---
>  drivers/media/platform/Kconfig|  11 +
>  drivers/media/platform/Makefile   |   2 +
>  drivers/media/platform/rockchip-rga/Makefile  |   3 +
>  drivers/media/platform/rockchip-rga/rga-buf.c | 176 +
>  drivers/media/platform/rockchip-rga/rga-hw.c  | 456 
>  drivers/media/platform/rockchip-rga/rga-hw.h  | 434 
>  drivers/media/platform/rockchip-rga/rga.c | 979
> ++
>  drivers/media/platform/rockchip-rga/rga.h | 133 
>  8 files changed, 2194 insertions(+)
>  create mode 100644 drivers/media/platform/rockchip-rga/Makefile
>  create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
>  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
>  create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
>  create mode 100644 drivers/media/platform/rockchip-rga/rga.c
>  create mode 100644 drivers/media/platform/rockchip-rga/rga.h
> 
> diff --git a/drivers/media/platform/Kconfig
> b/drivers/media/platform/Kconfig
> index c9106e1..8199bcf 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -411,6 +411,17 @@ config VIDEO_RENESAS_VSP1
>     To compile this driver as a module, choose M here: the
> module
>     will be called vsp1.
>  
> +config VIDEO_ROCKCHIP_RGA
> + tristate "Rockchip Raster 2d Grapphic Acceleration Unit"
> + depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
> + depends on ARCH_ROCKCHIP || COMPILE_TEST
> + select VIDEOBUF2_DMA_SG
> + select V4L2_MEM2MEM_DEV
> + default n
> + ---help---
> +   This is a v4l2 driver for Rockchip SOC RGA2
> +   2d graphics accelerator.
> +
>  config VIDEO_TI_VPE
>   tristate "TI VPE (Video Processing Engine) driver"
>   depends on VIDEO_DEV && VIDEO_V4L2
> diff --git a/drivers/media/platform/Makefile
> b/drivers/media/platform/Makefile
> index 349ddf6..3bf096f 100644
> --- a/drivers/media/platform/Makefile
> +++ b/drivers/media/platform/Makefile
> @@ -54,6 +54,8 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)+=
> rcar_fdp1.o
>  obj-$(CONFIG_VIDEO_RENESAS_JPU)  += rcar_jpu.o
>  obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/
>  
> +obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga/
> +
>  obj-y+= omap/
>  
>  obj-$(CONFIG_VIDEO_AM437X_VPFE)  += am437x/
> diff --git a/drivers/media/platform/rockchip-rga/Makefile
> b/drivers/media/platform/rockchip-rga/Makefile
> new file mode 100644
> index 000..92fe254
> --- /dev/null
> +++ b/drivers/media/platform/rockchip-rga/Makefile
> @@ -0,0 +1,3 @@
> +rockchip-rga-objs := rga.o rga-hw.o rga-buf.o
> +
> +obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
> diff --git a/drivers/media/platform/rockchip-rga/rga-buf.c
> b/drivers/media/platform/rockchip-rga/rga-buf.c
> new file mode 100644
> index 000..8582092
> --- /dev/null
> +++ b/drivers/media/platform/rockchip-rga/rga-buf.c
> @@ -0,0 +1,176 @@
> +/*
> + * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
> + * Author: Jacob Chen 
> + *
> + * This software is licensed under the terms of the GNU General
> Public
> + * License version 2, as published by the Free Software Foundation,
> and
> + * may be copied, distributed, and modified under those terms.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "rga-hw.h"
> +#include "rga.h"
> +
> +static int
> +rga_queue_setup(struct vb2_queue *vq,
> +unsigned int *nbuffers, unsigned int *nplanes,
> +unsigned int sizes[], struct device *alloc_devs[])
> +{
> + struct rga_ctx *ctx = vb2_get_drv_priv(vq);
> + struct rga_frame *f = rga_get_frame(ctx, vq->type);
> +
> + if (IS_ERR(f))
> + return PTR_ERR(f);
> +
> + sizes[0] = f->size;
> + *nplanes = 1;
> +
> + if (*nbuffers == 0)
> + *nbuffers = 1;
> +
> + return 0;
> +}
> +
> +static int rga_buf_prepare(struct 

[PATCH 1/5] [media] rockchip/rga: v4l2 m2m support

2017-06-26 Thread Jacob Chen
Rockchip RGA is a separate 2D raster graphic acceleration unit. It
accelerates 2D graphics operations, such as point/line drawing, image
scaling, rotation, BitBLT, alpha blending and image blur/sharpness.

The drvier is mostly based on s5p-g2d v4l2 m2m driver.
And supports various operations from the rendering pipeline.
 - copy
 - fast solid color fill
 - rotation
 - flip
 - alpha blending

The code in rga-hw.c is used to configure regs accroding to operations.

The code in rga-buf.c is used to create private mmu table for RGA.
The tables is stored in a list, and be removed when buffer is cleanup.

Signed-off-by: Jacob Chen 
---
 drivers/media/platform/Kconfig|  11 +
 drivers/media/platform/Makefile   |   2 +
 drivers/media/platform/rockchip-rga/Makefile  |   3 +
 drivers/media/platform/rockchip-rga/rga-buf.c | 176 +
 drivers/media/platform/rockchip-rga/rga-hw.c  | 456 
 drivers/media/platform/rockchip-rga/rga-hw.h  | 434 
 drivers/media/platform/rockchip-rga/rga.c | 979 ++
 drivers/media/platform/rockchip-rga/rga.h | 133 
 8 files changed, 2194 insertions(+)
 create mode 100644 drivers/media/platform/rockchip-rga/Makefile
 create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
 create mode 100644 drivers/media/platform/rockchip-rga/rga.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index c9106e1..8199bcf 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -411,6 +411,17 @@ config VIDEO_RENESAS_VSP1
  To compile this driver as a module, choose M here: the module
  will be called vsp1.
 
+config VIDEO_ROCKCHIP_RGA
+   tristate "Rockchip Raster 2d Grapphic Acceleration Unit"
+   depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_SG
+   select V4L2_MEM2MEM_DEV
+   default n
+   ---help---
+ This is a v4l2 driver for Rockchip SOC RGA2
+ 2d graphics accelerator.
+
 config VIDEO_TI_VPE
tristate "TI VPE (Video Processing Engine) driver"
depends on VIDEO_DEV && VIDEO_V4L2
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 349ddf6..3bf096f 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -54,6 +54,8 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip-rga/
+
 obj-y  += omap/
 
 obj-$(CONFIG_VIDEO_AM437X_VPFE)+= am437x/
diff --git a/drivers/media/platform/rockchip-rga/Makefile 
b/drivers/media/platform/rockchip-rga/Makefile
new file mode 100644
index 000..92fe254
--- /dev/null
+++ b/drivers/media/platform/rockchip-rga/Makefile
@@ -0,0 +1,3 @@
+rockchip-rga-objs := rga.o rga-hw.o rga-buf.o
+
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
diff --git a/drivers/media/platform/rockchip-rga/rga-buf.c 
b/drivers/media/platform/rockchip-rga/rga-buf.c
new file mode 100644
index 000..8582092
--- /dev/null
+++ b/drivers/media/platform/rockchip-rga/rga-buf.c
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ * Author: Jacob Chen 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "rga-hw.h"
+#include "rga.h"
+
+static int
+rga_queue_setup(struct vb2_queue *vq,
+unsigned int *nbuffers, unsigned int *nplanes,
+unsigned int sizes[], struct device *alloc_devs[])
+{
+   struct rga_ctx *ctx = vb2_get_drv_priv(vq);
+   struct rga_frame *f = rga_get_frame(ctx, vq->type);
+
+   if (IS_ERR(f))
+   return PTR_ERR(f);
+
+   sizes[0] = f->size;
+   *nplanes = 1;
+
+   if (*nbuffers == 0)
+   *nbuffers = 1;
+
+   return 0;
+}
+
+static int rga_buf_prepare(struct vb2_buffer *vb)
+{
+   struct rga_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+   struct rga_frame *f = rga_get_frame(ctx, vb->vb2_queue->type);
+
+   if (IS_ERR(f))
+   return PTR_ERR(f);
+
+   vb2_set_plane_payload(vb, 0, f->size);
+
+   return 0;
+}
+