Re: [PATCH 06/10] drm/sun4i: Move and extend format-related helpers and tables

2018-03-27 Thread Maxime Ripard
On Tue, Mar 27, 2018 at 10:27:44AM +0200, Paul Kocialkowski wrote:
> > > +bool sun4i_format_is_rgb(uint32_t format);
> > > +bool sun4i_format_is_yuv(uint32_t format);
> > > +bool sun4i_format_is_yuv411(uint32_t format);
> > > +bool sun4i_format_is_yuv420(uint32_t format);
> > > +bool sun4i_format_is_yuv422(uint32_t format);
> > > +bool sun4i_format_is_yuv444(uint32_t format);
> > > +bool sun4i_format_is_packed(uint32_t format);
> > > +bool sun4i_format_is_semiplanar(uint32_t format);
> > > +bool sun4i_format_is_planar(uint32_t format);
> > > +bool sun4i_format_supports_tiling(uint32_t format);
> > 
> > If we're going to add so many of them, then we should really consider
> > to move them to drm_fourcc.c instead. Every one has some variation of
> > some of these functions, we don't really need to duplicate it all the
> > time.
> 
> Should I try to get that through in this patchset and have sun4i-drm
> be their first user? Also, does introducing such a change require
> identifying duplicates of these functions in each DRM driver's
> codebase?

I guess converting at least one of them would prove how usable it
would be to other drivers, but I won't ask you to convert all of them
as part of this serie :)

Maxime

-- 
Maxime Ripard, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com


signature.asc
Description: PGP signature
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 06/10] drm/sun4i: Move and extend format-related helpers and tables

2018-03-27 Thread Paul Kocialkowski
Hi,

On Fri, 2018-03-23 at 11:13 +0100, Maxime Ripard wrote:
> On Wed, Mar 21, 2018 at 04:29:00PM +0100, Paul Kocialkowski wrote:
> > This moves the various helpers and tables related to format
> > detection
> > and conversion to a dedicated file, while adding a bunch of new
> > helpers
> > (especially for YUV and tiling support) along the way.
> 
> The addition of new helpers should be in a separate patch.

Fair enough.

> > Signed-off-by: Paul Kocialkowski 
> > ---
> >  drivers/gpu/drm/sun4i/Makefile|   1 +
> >  drivers/gpu/drm/sun4i/sun4i_backend.c |  54 ++
> >  drivers/gpu/drm/sun4i/sun4i_format.c  | 193
> > ++
> >  drivers/gpu/drm/sun4i/sun4i_format.h  |  35 ++
> >  4 files changed, 235 insertions(+), 48 deletions(-)
> >  create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.c
> >  create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.h
> > 
> > diff --git a/drivers/gpu/drm/sun4i/Makefile
> > b/drivers/gpu/drm/sun4i/Makefile
> > index 582607c0c488..c89c42ff803e 100644
> > --- a/drivers/gpu/drm/sun4i/Makefile
> > +++ b/drivers/gpu/drm/sun4i/Makefile
> > @@ -4,6 +4,7 @@ sun4i-frontend-y+= sun4i_frontend.o
> >  
> >  sun4i-drm-y+= sun4i_drv.o
> >  sun4i-drm-y+= sun4i_framebuffer.o
> > +sun4i-drm-y+= sun4i_format.o
> >  
> >  sun4i-drm-hdmi-y   += sun4i_hdmi_ddc_clk.o
> >  sun4i-drm-hdmi-y   += sun4i_hdmi_enc.o
> > diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c
> > b/drivers/gpu/drm/sun4i/sun4i_backend.c
> > index 1fad0714c70e..e8af9f3cf20b 100644
> > --- a/drivers/gpu/drm/sun4i/sun4i_backend.c
> > +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
> > @@ -29,6 +29,7 @@
> >  #include "sun4i_drv.h"
> >  #include "sun4i_frontend.h"
> >  #include "sun4i_layer.h"
> > +#include "sun4i_format.h"
> >  #include "sunxi_engine.h"
> >  
> >  struct sun4i_backend_quirks {
> > @@ -36,50 +37,6 @@ struct sun4i_backend_quirks {
> > bool needs_output_muxing;
> >  };
> >  
> > -static const u32 sunxi_rgb2yuv_coef[12] = {
> > -   0x0107, 0x0204, 0x0064, 0x0108,
> > -   0x3f69, 0x3ed6, 0x01c1, 0x0808,
> > -   0x01c1, 0x3e88, 0x3fb8, 0x0808
> > -};
> > -
> > -static const u32 sunxi_bt601_yuv2rgb_coef[12] = {
> > -   0x04a7, 0x1e6f, 0x1cbf, 0x0877,
> > -   0x04a7, 0x, 0x0662, 0x3211,
> > -   0x04a7, 0x0812, 0x, 0x2eb1,
> > -};
> > -
> > -static inline bool sun4i_backend_format_is_planar_yuv(uint32_t
> > format)
> > -{
> > -   switch (format) {
> > -   case DRM_FORMAT_YUV411:
> > -   case DRM_FORMAT_YUV422:
> > -   case DRM_FORMAT_YUV444:
> > -   return true;
> > -   default:
> > -   return false;
> > -   }
> > -}
> > -
> > -static inline bool sun4i_backend_format_is_packed_yuv422(uint32_t
> > format)
> > -{
> > -   switch (format) {
> > -   case DRM_FORMAT_YUYV:
> > -   case DRM_FORMAT_YVYU:
> > -   case DRM_FORMAT_UYVY:
> > -   case DRM_FORMAT_VYUY:
> > -   return true;
> > -
> > -   default:
> > -   return false;
> > -   }
> > -}
> > -
> > -static inline bool sun4i_backend_format_is_yuv(uint32_t format)
> > -{
> > -   return sun4i_backend_format_is_planar_yuv(format) ||
> > -   sun4i_backend_format_is_packed_yuv422(format);
> > -}
> > -
> >  static void sun4i_backend_apply_color_correction(struct
> > sunxi_engine *engine)
> >  {
> > int i;
> > @@ -259,7 +216,7 @@ static int
> > sun4i_backend_update_yuv_format(struct sun4i_backend *backend,
> >SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN,
> >SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN);
> >  
> > -   if (sun4i_backend_format_is_packed_yuv422(format))
> > +   if (sun4i_format_is_packed_yuv422(format))
> > val |= SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV422;
> > else
> > DRM_DEBUG_DRIVER("Unknown YUV format\n");
> > @@ -310,7 +267,7 @@ int sun4i_backend_update_layer_formats(struct
> > sun4i_backend *backend,
> > DRM_DEBUG_DRIVER("Switching display backend interlaced mode
> > %s\n",
> >  interlaced ? "on" : "off");
> >  
> > -   if (sun4i_backend_format_is_yuv(fb->format->format))
> > +   if (sun4i_format_is_yuv(fb->format->format))
> > return sun4i_backend_update_yuv_format(backend,
> > layer, plane);
> >  
> > ret = sun4i_backend_drm_format_to_layer(fb->format->format, 
> > );
> > @@ -404,7 +361,7 @@ int sun4i_backend_update_layer_buffer(struct
> > sun4i_backend *backend,
> >  */
> > paddr -= PHYS_OFFSET;
> >  
> > -   if (sun4i_backend_format_is_yuv(fb->format->format))
> > +   if (sun4i_format_is_yuv(fb->format->format))
> > return sun4i_backend_update_yuv_buffer(backend, fb,
> > paddr);
> >  
> > /* Write the 32 lower bits of the address (in bits) */
> > @@ -549,10 +506,11 @@ static int sun4i_backend_atomic_check(struct
> > 

Re: [PATCH 06/10] drm/sun4i: Move and extend format-related helpers and tables

2018-03-23 Thread Maxime Ripard
On Wed, Mar 21, 2018 at 04:29:00PM +0100, Paul Kocialkowski wrote:
> This moves the various helpers and tables related to format detection
> and conversion to a dedicated file, while adding a bunch of new helpers
> (especially for YUV and tiling support) along the way.

The addition of new helpers should be in a separate patch.

> Signed-off-by: Paul Kocialkowski 
> ---
>  drivers/gpu/drm/sun4i/Makefile|   1 +
>  drivers/gpu/drm/sun4i/sun4i_backend.c |  54 ++
>  drivers/gpu/drm/sun4i/sun4i_format.c  | 193 
> ++
>  drivers/gpu/drm/sun4i/sun4i_format.h  |  35 ++
>  4 files changed, 235 insertions(+), 48 deletions(-)
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.c
>  create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.h
> 
> diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
> index 582607c0c488..c89c42ff803e 100644
> --- a/drivers/gpu/drm/sun4i/Makefile
> +++ b/drivers/gpu/drm/sun4i/Makefile
> @@ -4,6 +4,7 @@ sun4i-frontend-y  += sun4i_frontend.o
>  
>  sun4i-drm-y  += sun4i_drv.o
>  sun4i-drm-y  += sun4i_framebuffer.o
> +sun4i-drm-y  += sun4i_format.o
>  
>  sun4i-drm-hdmi-y += sun4i_hdmi_ddc_clk.o
>  sun4i-drm-hdmi-y += sun4i_hdmi_enc.o
> diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c 
> b/drivers/gpu/drm/sun4i/sun4i_backend.c
> index 1fad0714c70e..e8af9f3cf20b 100644
> --- a/drivers/gpu/drm/sun4i/sun4i_backend.c
> +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
> @@ -29,6 +29,7 @@
>  #include "sun4i_drv.h"
>  #include "sun4i_frontend.h"
>  #include "sun4i_layer.h"
> +#include "sun4i_format.h"
>  #include "sunxi_engine.h"
>  
>  struct sun4i_backend_quirks {
> @@ -36,50 +37,6 @@ struct sun4i_backend_quirks {
>   bool needs_output_muxing;
>  };
>  
> -static const u32 sunxi_rgb2yuv_coef[12] = {
> - 0x0107, 0x0204, 0x0064, 0x0108,
> - 0x3f69, 0x3ed6, 0x01c1, 0x0808,
> - 0x01c1, 0x3e88, 0x3fb8, 0x0808
> -};
> -
> -static const u32 sunxi_bt601_yuv2rgb_coef[12] = {
> - 0x04a7, 0x1e6f, 0x1cbf, 0x0877,
> - 0x04a7, 0x, 0x0662, 0x3211,
> - 0x04a7, 0x0812, 0x, 0x2eb1,
> -};
> -
> -static inline bool sun4i_backend_format_is_planar_yuv(uint32_t format)
> -{
> - switch (format) {
> - case DRM_FORMAT_YUV411:
> - case DRM_FORMAT_YUV422:
> - case DRM_FORMAT_YUV444:
> - return true;
> - default:
> - return false;
> - }
> -}
> -
> -static inline bool sun4i_backend_format_is_packed_yuv422(uint32_t format)
> -{
> - switch (format) {
> - case DRM_FORMAT_YUYV:
> - case DRM_FORMAT_YVYU:
> - case DRM_FORMAT_UYVY:
> - case DRM_FORMAT_VYUY:
> - return true;
> -
> - default:
> - return false;
> - }
> -}
> -
> -static inline bool sun4i_backend_format_is_yuv(uint32_t format)
> -{
> - return sun4i_backend_format_is_planar_yuv(format) ||
> - sun4i_backend_format_is_packed_yuv422(format);
> -}
> -
>  static void sun4i_backend_apply_color_correction(struct sunxi_engine *engine)
>  {
>   int i;
> @@ -259,7 +216,7 @@ static int sun4i_backend_update_yuv_format(struct 
> sun4i_backend *backend,
>  SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN,
>  SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN);
>  
> - if (sun4i_backend_format_is_packed_yuv422(format))
> + if (sun4i_format_is_packed_yuv422(format))
>   val |= SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV422;
>   else
>   DRM_DEBUG_DRIVER("Unknown YUV format\n");
> @@ -310,7 +267,7 @@ int sun4i_backend_update_layer_formats(struct 
> sun4i_backend *backend,
>   DRM_DEBUG_DRIVER("Switching display backend interlaced mode %s\n",
>interlaced ? "on" : "off");
>  
> - if (sun4i_backend_format_is_yuv(fb->format->format))
> + if (sun4i_format_is_yuv(fb->format->format))
>   return sun4i_backend_update_yuv_format(backend, layer, plane);
>  
>   ret = sun4i_backend_drm_format_to_layer(fb->format->format, );
> @@ -404,7 +361,7 @@ int sun4i_backend_update_layer_buffer(struct 
> sun4i_backend *backend,
>*/
>   paddr -= PHYS_OFFSET;
>  
> - if (sun4i_backend_format_is_yuv(fb->format->format))
> + if (sun4i_format_is_yuv(fb->format->format))
>   return sun4i_backend_update_yuv_buffer(backend, fb, paddr);
>  
>   /* Write the 32 lower bits of the address (in bits) */
> @@ -549,10 +506,11 @@ static int sun4i_backend_atomic_check(struct 
> sunxi_engine *engine,
>   DRM_DEBUG_DRIVER("Plane FB format is %s\n",
>drm_get_format_name(fb->format->format,
>_name));
> +
>   if (fb->format->has_alpha)
> 

[PATCH 06/10] drm/sun4i: Move and extend format-related helpers and tables

2018-03-22 Thread Paul Kocialkowski
This moves the various helpers and tables related to format detection
and conversion to a dedicated file, while adding a bunch of new helpers
(especially for YUV and tiling support) along the way.

Signed-off-by: Paul Kocialkowski 
---
 drivers/gpu/drm/sun4i/Makefile|   1 +
 drivers/gpu/drm/sun4i/sun4i_backend.c |  54 ++
 drivers/gpu/drm/sun4i/sun4i_format.c  | 193 ++
 drivers/gpu/drm/sun4i/sun4i_format.h  |  35 ++
 4 files changed, 235 insertions(+), 48 deletions(-)
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.c
 create mode 100644 drivers/gpu/drm/sun4i/sun4i_format.h

diff --git a/drivers/gpu/drm/sun4i/Makefile b/drivers/gpu/drm/sun4i/Makefile
index 582607c0c488..c89c42ff803e 100644
--- a/drivers/gpu/drm/sun4i/Makefile
+++ b/drivers/gpu/drm/sun4i/Makefile
@@ -4,6 +4,7 @@ sun4i-frontend-y+= sun4i_frontend.o
 
 sun4i-drm-y+= sun4i_drv.o
 sun4i-drm-y+= sun4i_framebuffer.o
+sun4i-drm-y+= sun4i_format.o
 
 sun4i-drm-hdmi-y   += sun4i_hdmi_ddc_clk.o
 sun4i-drm-hdmi-y   += sun4i_hdmi_enc.o
diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c 
b/drivers/gpu/drm/sun4i/sun4i_backend.c
index 1fad0714c70e..e8af9f3cf20b 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.c
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
@@ -29,6 +29,7 @@
 #include "sun4i_drv.h"
 #include "sun4i_frontend.h"
 #include "sun4i_layer.h"
+#include "sun4i_format.h"
 #include "sunxi_engine.h"
 
 struct sun4i_backend_quirks {
@@ -36,50 +37,6 @@ struct sun4i_backend_quirks {
bool needs_output_muxing;
 };
 
-static const u32 sunxi_rgb2yuv_coef[12] = {
-   0x0107, 0x0204, 0x0064, 0x0108,
-   0x3f69, 0x3ed6, 0x01c1, 0x0808,
-   0x01c1, 0x3e88, 0x3fb8, 0x0808
-};
-
-static const u32 sunxi_bt601_yuv2rgb_coef[12] = {
-   0x04a7, 0x1e6f, 0x1cbf, 0x0877,
-   0x04a7, 0x, 0x0662, 0x3211,
-   0x04a7, 0x0812, 0x, 0x2eb1,
-};
-
-static inline bool sun4i_backend_format_is_planar_yuv(uint32_t format)
-{
-   switch (format) {
-   case DRM_FORMAT_YUV411:
-   case DRM_FORMAT_YUV422:
-   case DRM_FORMAT_YUV444:
-   return true;
-   default:
-   return false;
-   }
-}
-
-static inline bool sun4i_backend_format_is_packed_yuv422(uint32_t format)
-{
-   switch (format) {
-   case DRM_FORMAT_YUYV:
-   case DRM_FORMAT_YVYU:
-   case DRM_FORMAT_UYVY:
-   case DRM_FORMAT_VYUY:
-   return true;
-
-   default:
-   return false;
-   }
-}
-
-static inline bool sun4i_backend_format_is_yuv(uint32_t format)
-{
-   return sun4i_backend_format_is_planar_yuv(format) ||
-   sun4i_backend_format_is_packed_yuv422(format);
-}
-
 static void sun4i_backend_apply_color_correction(struct sunxi_engine *engine)
 {
int i;
@@ -259,7 +216,7 @@ static int sun4i_backend_update_yuv_format(struct 
sun4i_backend *backend,
   SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN,
   SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN);
 
-   if (sun4i_backend_format_is_packed_yuv422(format))
+   if (sun4i_format_is_packed_yuv422(format))
val |= SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV422;
else
DRM_DEBUG_DRIVER("Unknown YUV format\n");
@@ -310,7 +267,7 @@ int sun4i_backend_update_layer_formats(struct sun4i_backend 
*backend,
DRM_DEBUG_DRIVER("Switching display backend interlaced mode %s\n",
 interlaced ? "on" : "off");
 
-   if (sun4i_backend_format_is_yuv(fb->format->format))
+   if (sun4i_format_is_yuv(fb->format->format))
return sun4i_backend_update_yuv_format(backend, layer, plane);
 
ret = sun4i_backend_drm_format_to_layer(fb->format->format, );
@@ -404,7 +361,7 @@ int sun4i_backend_update_layer_buffer(struct sun4i_backend 
*backend,
 */
paddr -= PHYS_OFFSET;
 
-   if (sun4i_backend_format_is_yuv(fb->format->format))
+   if (sun4i_format_is_yuv(fb->format->format))
return sun4i_backend_update_yuv_buffer(backend, fb, paddr);
 
/* Write the 32 lower bits of the address (in bits) */
@@ -549,10 +506,11 @@ static int sun4i_backend_atomic_check(struct sunxi_engine 
*engine,
DRM_DEBUG_DRIVER("Plane FB format is %s\n",
 drm_get_format_name(fb->format->format,
 _name));
+
if (fb->format->has_alpha)
num_alpha_planes++;
 
-   if (sun4i_backend_format_is_yuv(fb->format->format)) {
+   if (sun4i_format_is_yuv(fb->format->format)) {
DRM_DEBUG_DRIVER("Plane FB format is YUV\n");
num_yuv_planes++;