All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/15] Centralize format information
@ 2016-06-08 23:32 Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 01/15] drm: Move format-related helpers to drm_fourcc.c Laurent Pinchart
                   ` (14 more replies)
  0 siblings, 15 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

Hello,

(Repost with the drivers maintainers CC'ed, sorry about the noise)

Various pieces of information about DRM formats (number of planes, color
depth, chroma subsampling, ...) are scattered across different helper
functions in the DRM core. Callers of those functions often need to access
more than a single parameter of the format, leading to inefficiencies due to
multiple lookups.

This patch series addresses this issue by centralizing all format information
in a single data structure (02/15). It reimplements the existing format helper
functions based on that structure (03/15) and converts the DRM core code to
use the new structure (04/15). The DRM core now WARNs when a driver tries to
query information about an unsupported format (05/15).

The second part of the patch series removes the drm_fb_get_bpp_depth() legacy
function that shouldn't be used directly by drivers. It modifies all its users
to use the appropriate API instead (06/15 to 14/15) and finally merges the
function into its only caller in the DRM core (15/15).

The new API is also useful for drivers as shown by the "[PATCH v2 00/20] OMAP
DRM fixes and improvements" patch series posted yesterday.

Changes since v2:

- Remove bpp field from drm_format_info structure
- Replace all users of drm_fb_get_bpp_depth() with the appropriate API
- Merge drm_fb_get_bpp_depth() into its only caller

Changes since v1:

- Move format-related helpers to drm_fourcc.c
- Use named initializers for the formats array
- WARN when calling drm_format_info() for an unsupported format
- Don't drop the drm_format_plane_width() and drm_format_plane_height()
  helpers

Laurent Pinchart (15):
  drm: Move format-related helpers to drm_fourcc.c
  drm: Centralize format information
  drm: Implement the drm_format_*() helpers as drm_format_info()
    wrappers
  drm: Use drm_format_info() in DRM core code
  drm: WARN when calling drm_format_info() for an unsupported format
  drm: msm: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  drm: sti: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  drm: tilcdc: Replace drm_fb_get_bpp_depth() with
    drm_format_plane_cpp()
  drm: cirrus: Replace drm_fb_get_bpp_depth() with
    drm_format_plane_cpp()
  drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info()
  drm: amdgpu: Replace drm_fb_get_bpp_depth() with
    drm_format_plane_cpp()
  drm: radeon: Replace drm_fb_get_bpp_depth() with
    drm_format_plane_cpp()
  drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info()
  drm: Don't export the drm_fb_get_bpp_depth() function

 Documentation/DocBook/gpu.tmpl           |   5 +
 drivers/gpu/drm/Makefile                 |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   |  10 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c  |   3 +-
 drivers/gpu/drm/arm/hdlcd_crtc.c         |   5 +-
 drivers/gpu/drm/cirrus/cirrus_fbdev.c    |   6 +-
 drivers/gpu/drm/cirrus/cirrus_main.c     |   4 +-
 drivers/gpu/drm/drm_crtc.c               | 389 +------------------------------
 drivers/gpu/drm/drm_crtc_helper.c        |  14 +-
 drivers/gpu/drm/drm_fb_cma_helper.c      |  23 +-
 drivers/gpu/drm/drm_fourcc.c             | 280 ++++++++++++++++++++++
 drivers/gpu/drm/gma500/framebuffer.c     |  20 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c |   6 +-
 drivers/gpu/drm/radeon/radeon_fb.c       |  14 +-
 drivers/gpu/drm/radeon/radeon_gem.c      |   3 +-
 drivers/gpu/drm/sti/sti_gdp.c            |   6 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c     |  23 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c      |  12 +-
 include/drm/drmP.h                       |   1 +
 include/drm/drm_crtc.h                   |   9 -
 include/drm/drm_fourcc.h                 |  56 +++++
 21 files changed, 437 insertions(+), 454 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_fourcc.c
 create mode 100644 include/drm/drm_fourcc.h

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v3 01/15] drm: Move format-related helpers to drm_fourcc.c
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-09  8:36   ` Daniel Vetter
  2016-06-08 23:32 ` [PATCH v3 02/15] drm: Centralize format information Laurent Pinchart
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

The drm_crtc.c file is a mess, making the ABI documentation confusing
since all functions are in the same bag. Split the format-related
helpers to a new drm_fourcc.c file.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/DocBook/gpu.tmpl |   5 +
 drivers/gpu/drm/Makefile       |   2 +-
 drivers/gpu/drm/drm_crtc.c     | 289 -------------------------------------
 drivers/gpu/drm/drm_fourcc.c   | 320 +++++++++++++++++++++++++++++++++++++++++
 include/drm/drmP.h             |   1 +
 include/drm/drm_crtc.h         |   9 --
 include/drm/drm_fourcc.h       |  37 +++++
 7 files changed, 364 insertions(+), 299 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_fourcc.c
 create mode 100644 include/drm/drm_fourcc.h

diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index 7586bf75f62e..d32363cb1ff1 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -1656,6 +1656,11 @@ void intel_crt_init(struct drm_device *dev)
 !Edrivers/gpu/drm/drm_rect.c
     </sect2>
     <sect2>
+      <title>Formats Utilities Reference</title>
+!Iinclude/drm/drm_fourcc.h
+!Edrivers/gpu/drm/drm_fourcc.c
+    </sect2>
+    <sect2>
       <title>Flip-work Helper Reference</title>
 !Pinclude/drm/drm_flip_work.h flip utils
 !Iinclude/drm/drm_flip_work.h
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index be43afb08c69..aa24af35c068 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -8,7 +8,7 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
 		drm_lock.o drm_memory.o drm_drv.o drm_vm.o \
 		drm_scatter.o drm_pci.o \
 		drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
-		drm_crtc.o drm_modes.o drm_edid.o \
+		drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
 		drm_info.o drm_debugfs.o drm_encoder_slave.o \
 		drm_trace_points.o drm_global.o drm_prime.o \
 		drm_rect.o drm_vma_manager.o drm_flip_work.o \
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 0e3cc66aa8b7..e5369529af06 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -239,37 +239,6 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
 }
 EXPORT_SYMBOL(drm_get_subpixel_order_name);
 
-static char printable_char(int c)
-{
-	return isascii(c) && isprint(c) ? c : '?';
-}
-
-/**
- * drm_get_format_name - return a string for drm fourcc format
- * @format: format to compute name of
- *
- * Note that the buffer used by this function is globally shared and owned by
- * the function itself.
- *
- * FIXME: This isn't really multithreading safe.
- */
-const char *drm_get_format_name(uint32_t format)
-{
-	static char buf[32];
-
-	snprintf(buf, sizeof(buf),
-		 "%c%c%c%c %s-endian (0x%08x)",
-		 printable_char(format & 0xff),
-		 printable_char((format >> 8) & 0xff),
-		 printable_char((format >> 16) & 0xff),
-		 printable_char((format >> 24) & 0x7f),
-		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
-		 format);
-
-	return buf;
-}
-EXPORT_SYMBOL(drm_get_format_name);
-
 /*
  * Internal function to assign a slot in the object idr and optionally
  * register the object into the idr.
@@ -5544,264 +5513,6 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
 }
 
 /**
- * drm_fb_get_bpp_depth - get the bpp/depth values for format
- * @format: pixel format (DRM_FORMAT_*)
- * @depth: storage for the depth value
- * @bpp: storage for the bpp value
- *
- * This only supports RGB formats here for compat with code that doesn't use
- * pixel formats directly yet.
- */
-void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
-			  int *bpp)
-{
-	switch (format) {
-	case DRM_FORMAT_C8:
-	case DRM_FORMAT_RGB332:
-	case DRM_FORMAT_BGR233:
-		*depth = 8;
-		*bpp = 8;
-		break;
-	case DRM_FORMAT_XRGB1555:
-	case DRM_FORMAT_XBGR1555:
-	case DRM_FORMAT_RGBX5551:
-	case DRM_FORMAT_BGRX5551:
-	case DRM_FORMAT_ARGB1555:
-	case DRM_FORMAT_ABGR1555:
-	case DRM_FORMAT_RGBA5551:
-	case DRM_FORMAT_BGRA5551:
-		*depth = 15;
-		*bpp = 16;
-		break;
-	case DRM_FORMAT_RGB565:
-	case DRM_FORMAT_BGR565:
-		*depth = 16;
-		*bpp = 16;
-		break;
-	case DRM_FORMAT_RGB888:
-	case DRM_FORMAT_BGR888:
-		*depth = 24;
-		*bpp = 24;
-		break;
-	case DRM_FORMAT_XRGB8888:
-	case DRM_FORMAT_XBGR8888:
-	case DRM_FORMAT_RGBX8888:
-	case DRM_FORMAT_BGRX8888:
-		*depth = 24;
-		*bpp = 32;
-		break;
-	case DRM_FORMAT_XRGB2101010:
-	case DRM_FORMAT_XBGR2101010:
-	case DRM_FORMAT_RGBX1010102:
-	case DRM_FORMAT_BGRX1010102:
-	case DRM_FORMAT_ARGB2101010:
-	case DRM_FORMAT_ABGR2101010:
-	case DRM_FORMAT_RGBA1010102:
-	case DRM_FORMAT_BGRA1010102:
-		*depth = 30;
-		*bpp = 32;
-		break;
-	case DRM_FORMAT_ARGB8888:
-	case DRM_FORMAT_ABGR8888:
-	case DRM_FORMAT_RGBA8888:
-	case DRM_FORMAT_BGRA8888:
-		*depth = 32;
-		*bpp = 32;
-		break;
-	default:
-		DRM_DEBUG_KMS("unsupported pixel format %s\n",
-			      drm_get_format_name(format));
-		*depth = 0;
-		*bpp = 0;
-		break;
-	}
-}
-EXPORT_SYMBOL(drm_fb_get_bpp_depth);
-
-/**
- * drm_format_num_planes - get the number of planes for format
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The number of planes used by the specified pixel format.
- */
-int drm_format_num_planes(uint32_t format)
-{
-	switch (format) {
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV444:
-	case DRM_FORMAT_YVU444:
-		return 3;
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_NV24:
-	case DRM_FORMAT_NV42:
-		return 2;
-	default:
-		return 1;
-	}
-}
-EXPORT_SYMBOL(drm_format_num_planes);
-
-/**
- * drm_format_plane_cpp - determine the bytes per pixel value
- * @format: pixel format (DRM_FORMAT_*)
- * @plane: plane index
- *
- * Returns:
- * The bytes per pixel value for the specified plane.
- */
-int drm_format_plane_cpp(uint32_t format, int plane)
-{
-	unsigned int depth;
-	int bpp;
-
-	if (plane >= drm_format_num_planes(format))
-		return 0;
-
-	switch (format) {
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-		return 2;
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_NV24:
-	case DRM_FORMAT_NV42:
-		return plane ? 2 : 1;
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV444:
-	case DRM_FORMAT_YVU444:
-		return 1;
-	default:
-		drm_fb_get_bpp_depth(format, &depth, &bpp);
-		return bpp >> 3;
-	}
-}
-EXPORT_SYMBOL(drm_format_plane_cpp);
-
-/**
- * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The horizontal chroma subsampling factor for the
- * specified pixel format.
- */
-int drm_format_horz_chroma_subsampling(uint32_t format)
-{
-	switch (format) {
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-		return 4;
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-		return 2;
-	default:
-		return 1;
-	}
-}
-EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
-
-/**
- * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The vertical chroma subsampling factor for the
- * specified pixel format.
- */
-int drm_format_vert_chroma_subsampling(uint32_t format)
-{
-	switch (format) {
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-		return 4;
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-		return 2;
-	default:
-		return 1;
-	}
-}
-EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
-
-/**
- * drm_format_plane_width - width of the plane given the first plane
- * @width: width of the first plane
- * @format: pixel format
- * @plane: plane index
- *
- * Returns:
- * The width of @plane, given that the width of the first plane is @width.
- */
-int drm_format_plane_width(int width, uint32_t format, int plane)
-{
-	if (plane >= drm_format_num_planes(format))
-		return 0;
-
-	if (plane == 0)
-		return width;
-
-	return width / drm_format_horz_chroma_subsampling(format);
-}
-EXPORT_SYMBOL(drm_format_plane_width);
-
-/**
- * drm_format_plane_height - height of the plane given the first plane
- * @height: height of the first plane
- * @format: pixel format
- * @plane: plane index
- *
- * Returns:
- * The height of @plane, given that the height of the first plane is @height.
- */
-int drm_format_plane_height(int height, uint32_t format, int plane)
-{
-	if (plane >= drm_format_num_planes(format))
-		return 0;
-
-	if (plane == 0)
-		return height;
-
-	return height / drm_format_vert_chroma_subsampling(format);
-}
-EXPORT_SYMBOL(drm_format_plane_height);
-
-/**
  * drm_rotation_simplify() - Try to simplify the rotation
  * @rotation: Rotation to be simplified
  * @supported_rotations: Supported rotations
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
new file mode 100644
index 000000000000..0645c85d5f95
--- /dev/null
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -0,0 +1,320 @@
+/*
+ * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * DRM core format related functions
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include <linux/bug.h>
+#include <linux/ctype.h>
+#include <linux/export.h>
+#include <linux/kernel.h>
+
+#include <drm/drmP.h>
+#include <drm/drm_fourcc.h>
+
+static char printable_char(int c)
+{
+	return isascii(c) && isprint(c) ? c : '?';
+}
+
+/**
+ * drm_get_format_name - return a string for drm fourcc format
+ * @format: format to compute name of
+ *
+ * Note that the buffer used by this function is globally shared and owned by
+ * the function itself.
+ *
+ * FIXME: This isn't really multithreading safe.
+ */
+const char *drm_get_format_name(uint32_t format)
+{
+	static char buf[32];
+
+	snprintf(buf, sizeof(buf),
+		 "%c%c%c%c %s-endian (0x%08x)",
+		 printable_char(format & 0xff),
+		 printable_char((format >> 8) & 0xff),
+		 printable_char((format >> 16) & 0xff),
+		 printable_char((format >> 24) & 0x7f),
+		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
+		 format);
+
+	return buf;
+}
+EXPORT_SYMBOL(drm_get_format_name);
+
+/**
+ * drm_fb_get_bpp_depth - get the bpp/depth values for format
+ * @format: pixel format (DRM_FORMAT_*)
+ * @depth: storage for the depth value
+ * @bpp: storage for the bpp value
+ *
+ * This only supports RGB formats here for compat with code that doesn't use
+ * pixel formats directly yet.
+ */
+void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
+			  int *bpp)
+{
+	switch (format) {
+	case DRM_FORMAT_C8:
+	case DRM_FORMAT_RGB332:
+	case DRM_FORMAT_BGR233:
+		*depth = 8;
+		*bpp = 8;
+		break;
+	case DRM_FORMAT_XRGB1555:
+	case DRM_FORMAT_XBGR1555:
+	case DRM_FORMAT_RGBX5551:
+	case DRM_FORMAT_BGRX5551:
+	case DRM_FORMAT_ARGB1555:
+	case DRM_FORMAT_ABGR1555:
+	case DRM_FORMAT_RGBA5551:
+	case DRM_FORMAT_BGRA5551:
+		*depth = 15;
+		*bpp = 16;
+		break;
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+		*depth = 16;
+		*bpp = 16;
+		break;
+	case DRM_FORMAT_RGB888:
+	case DRM_FORMAT_BGR888:
+		*depth = 24;
+		*bpp = 24;
+		break;
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_RGBX8888:
+	case DRM_FORMAT_BGRX8888:
+		*depth = 24;
+		*bpp = 32;
+		break;
+	case DRM_FORMAT_XRGB2101010:
+	case DRM_FORMAT_XBGR2101010:
+	case DRM_FORMAT_RGBX1010102:
+	case DRM_FORMAT_BGRX1010102:
+	case DRM_FORMAT_ARGB2101010:
+	case DRM_FORMAT_ABGR2101010:
+	case DRM_FORMAT_RGBA1010102:
+	case DRM_FORMAT_BGRA1010102:
+		*depth = 30;
+		*bpp = 32;
+		break;
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_ABGR8888:
+	case DRM_FORMAT_RGBA8888:
+	case DRM_FORMAT_BGRA8888:
+		*depth = 32;
+		*bpp = 32;
+		break;
+	default:
+		DRM_DEBUG_KMS("unsupported pixel format %s\n",
+			      drm_get_format_name(format));
+		*depth = 0;
+		*bpp = 0;
+		break;
+	}
+}
+EXPORT_SYMBOL(drm_fb_get_bpp_depth);
+
+/**
+ * drm_format_num_planes - get the number of planes for format
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The number of planes used by the specified pixel format.
+ */
+int drm_format_num_planes(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+	case DRM_FORMAT_YUV411:
+	case DRM_FORMAT_YVU411:
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+	case DRM_FORMAT_YUV422:
+	case DRM_FORMAT_YVU422:
+	case DRM_FORMAT_YUV444:
+	case DRM_FORMAT_YVU444:
+		return 3;
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+	case DRM_FORMAT_NV24:
+	case DRM_FORMAT_NV42:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_num_planes);
+
+/**
+ * drm_format_plane_cpp - determine the bytes per pixel value
+ * @format: pixel format (DRM_FORMAT_*)
+ * @plane: plane index
+ *
+ * Returns:
+ * The bytes per pixel value for the specified plane.
+ */
+int drm_format_plane_cpp(uint32_t format, int plane)
+{
+	unsigned int depth;
+	int bpp;
+
+	if (plane >= drm_format_num_planes(format))
+		return 0;
+
+	switch (format) {
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+		return 2;
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+	case DRM_FORMAT_NV24:
+	case DRM_FORMAT_NV42:
+		return plane ? 2 : 1;
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+	case DRM_FORMAT_YUV411:
+	case DRM_FORMAT_YVU411:
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+	case DRM_FORMAT_YUV422:
+	case DRM_FORMAT_YVU422:
+	case DRM_FORMAT_YUV444:
+	case DRM_FORMAT_YVU444:
+		return 1;
+	default:
+		drm_fb_get_bpp_depth(format, &depth, &bpp);
+		return bpp >> 3;
+	}
+}
+EXPORT_SYMBOL(drm_format_plane_cpp);
+
+/**
+ * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The horizontal chroma subsampling factor for the
+ * specified pixel format.
+ */
+int drm_format_horz_chroma_subsampling(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_YUV411:
+	case DRM_FORMAT_YVU411:
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+		return 4;
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+	case DRM_FORMAT_YUV422:
+	case DRM_FORMAT_YVU422:
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
+
+/**
+ * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The vertical chroma subsampling factor for the
+ * specified pixel format.
+ */
+int drm_format_vert_chroma_subsampling(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+		return 4;
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
+
+/**
+ * drm_format_plane_width - width of the plane given the first plane
+ * @width: width of the first plane
+ * @format: pixel format
+ * @plane: plane index
+ *
+ * Returns:
+ * The width of @plane, given that the width of the first plane is @width.
+ */
+int drm_format_plane_width(int width, uint32_t format, int plane)
+{
+	if (plane >= drm_format_num_planes(format))
+		return 0;
+
+	if (plane == 0)
+		return width;
+
+	return width / drm_format_horz_chroma_subsampling(format);
+}
+EXPORT_SYMBOL(drm_format_plane_width);
+
+/**
+ * drm_format_plane_height - height of the plane given the first plane
+ * @height: height of the first plane
+ * @format: pixel format
+ * @plane: plane index
+ *
+ * Returns:
+ * The height of @plane, given that the height of the first plane is @height.
+ */
+int drm_format_plane_height(int height, uint32_t format, int plane)
+{
+	if (plane >= drm_format_num_planes(format))
+		return 0;
+
+	if (plane == 0)
+		return height;
+
+	return height / drm_format_vert_chroma_subsampling(format);
+}
+EXPORT_SYMBOL(drm_format_plane_height);
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 84f1a8eefbdb..c8879057084e 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -66,6 +66,7 @@
 
 #include <drm/drm_agpsupport.h>
 #include <drm/drm_crtc.h>
+#include <drm/drm_fourcc.h>
 #include <drm/drm_global.h>
 #include <drm/drm_hashtab.h>
 #include <drm/drm_mem_util.h>
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index d1559cd04e3d..1b80c0268d8f 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -2540,15 +2540,6 @@ extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
 extern int drm_mode_atomic_ioctl(struct drm_device *dev,
 				 void *data, struct drm_file *file_priv);
 
-extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
-				 int *bpp);
-extern int drm_format_num_planes(uint32_t format);
-extern int drm_format_plane_cpp(uint32_t format, int plane);
-extern int drm_format_horz_chroma_subsampling(uint32_t format);
-extern int drm_format_vert_chroma_subsampling(uint32_t format);
-extern int drm_format_plane_width(int width, uint32_t format, int plane);
-extern int drm_format_plane_height(int height, uint32_t format, int plane);
-extern const char *drm_get_format_name(uint32_t format);
 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
 							      unsigned int supported_rotations);
 extern unsigned int drm_rotation_simplify(unsigned int rotation,
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
new file mode 100644
index 000000000000..7f90a396cf2b
--- /dev/null
+++ b/include/drm/drm_fourcc.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+#ifndef __DRM_FOURCC_H__
+#define __DRM_FOURCC_H__
+
+#include <linux/types.h>
+#include <uapi/drm/drm_fourcc.h>
+
+void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
+int drm_format_num_planes(uint32_t format);
+int drm_format_plane_cpp(uint32_t format, int plane);
+int drm_format_horz_chroma_subsampling(uint32_t format);
+int drm_format_vert_chroma_subsampling(uint32_t format);
+int drm_format_plane_width(int width, uint32_t format, int plane);
+int drm_format_plane_height(int height, uint32_t format, int plane);
+const char *drm_get_format_name(uint32_t format);
+
+#endif /* __DRM_FOURCC_H__ */
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 02/15] drm: Centralize format information
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 01/15] drm: Move format-related helpers to drm_fourcc.c Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-09  8:52   ` Daniel Vetter
  2016-06-08 23:32 ` [PATCH v3 03/15] drm: Implement the drm_format_*() helpers as drm_format_info() wrappers Laurent Pinchart
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

Various pieces of information about DRM formats (number of planes, color
depth, chroma subsampling, ...) are scattered across different helper
functions in the DRM core. Callers of those functions often need to
access more than a single parameter of the format, leading to
inefficiencies due to multiple lookups.

Centralize all format information in a data structure and create a
function to look up information based on the format 4CC.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_fourcc.h     | 19 ++++++++++
 2 files changed, 103 insertions(+)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 0645c85d5f95..47b9abd743be 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t format)
 EXPORT_SYMBOL(drm_get_format_name);
 
 /**
+ * drm_format_info - query information for a given format
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The instance of struct drm_format_info that describes the pixel format, or
+ * NULL if the format is unsupported.
+ */
+const struct drm_format_info *drm_format_info(u32 format)
+{
+	static const struct drm_format_info formats[] = { 
+		{ .format = DRM_FORMAT_C8,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGB332,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGR233,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XRGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XBGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ARGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ABGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XRGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XBGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ARGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ABGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGB565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGR565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGB888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGR888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XRGB8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XBGR8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XRGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_XBGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ARGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ABGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ARGB8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_ABGR8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_RGBA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_BGRA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_YUV410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
+		{ .format = DRM_FORMAT_YVU410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
+		{ .format = DRM_FORMAT_YUV411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
+		{ .format = DRM_FORMAT_YVU411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
+		{ .format = DRM_FORMAT_YUV420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
+		{ .format = DRM_FORMAT_YVU420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
+		{ .format = DRM_FORMAT_YUV422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_YVU422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_YUV444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_YVU444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_NV12,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
+		{ .format = DRM_FORMAT_NV21,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
+		{ .format = DRM_FORMAT_NV16,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_NV61,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_NV24,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_NV42,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
+		{ .format = DRM_FORMAT_YUYV,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_YVYU,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_UYVY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_VYUY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
+		{ .format = DRM_FORMAT_AYUV,		.depth = 0,  .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
+	};
+
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(formats); ++i) {
+		if (formats[i].format == format)
+			return &formats[i];
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(drm_format_info);
+
+/**
  * drm_fb_get_bpp_depth - get the bpp/depth values for format
  * @format: pixel format (DRM_FORMAT_*)
  * @depth: storage for the depth value
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index 7f90a396cf2b..b077df507b51 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -25,6 +25,25 @@
 #include <linux/types.h>
 #include <uapi/drm/drm_fourcc.h>
 
+/**
+ * struct drm_format_info - information about a DRM format
+ * @format: 4CC format identifier (DRM_FORMAT_*)
+ * @depth: color depth (number of bits per pixel excluding padding bits)
+ * @num_planes: number of color planes (1 to 3)
+ * @cpp: number of bytes per pixel (per plane)
+ * @hsub: horizontal chroma subsampling factor
+ * @vsub: vertical chroma subsampling factor
+ */
+struct drm_format_info {
+	u32 format;
+	u8 depth;
+	u8 num_planes;
+	u8 cpp[3];
+	u8 hsub;
+	u8 vsub;
+};
+
+const struct drm_format_info *drm_format_info(u32 format);
 void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
 int drm_format_num_planes(uint32_t format);
 int drm_format_plane_cpp(uint32_t format, int plane);
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 03/15] drm: Implement the drm_format_*() helpers as drm_format_info() wrappers
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 01/15] drm: Move format-related helpers to drm_fourcc.c Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 02/15] drm: Centralize format information Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 04/15] drm: Use drm_format_info() in DRM core code Laurent Pinchart
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

Turn the drm_format_*() helpers into wrappers around the drm_format_info
lookup function to centralize all format information in a single place.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/drm_fourcc.c | 180 ++++++++-----------------------------------
 1 file changed, 34 insertions(+), 146 deletions(-)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 47b9abd743be..ef59e7f8032e 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -157,66 +157,19 @@ EXPORT_SYMBOL(drm_format_info);
 void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
 			  int *bpp)
 {
-	switch (format) {
-	case DRM_FORMAT_C8:
-	case DRM_FORMAT_RGB332:
-	case DRM_FORMAT_BGR233:
-		*depth = 8;
-		*bpp = 8;
-		break;
-	case DRM_FORMAT_XRGB1555:
-	case DRM_FORMAT_XBGR1555:
-	case DRM_FORMAT_RGBX5551:
-	case DRM_FORMAT_BGRX5551:
-	case DRM_FORMAT_ARGB1555:
-	case DRM_FORMAT_ABGR1555:
-	case DRM_FORMAT_RGBA5551:
-	case DRM_FORMAT_BGRA5551:
-		*depth = 15;
-		*bpp = 16;
-		break;
-	case DRM_FORMAT_RGB565:
-	case DRM_FORMAT_BGR565:
-		*depth = 16;
-		*bpp = 16;
-		break;
-	case DRM_FORMAT_RGB888:
-	case DRM_FORMAT_BGR888:
-		*depth = 24;
-		*bpp = 24;
-		break;
-	case DRM_FORMAT_XRGB8888:
-	case DRM_FORMAT_XBGR8888:
-	case DRM_FORMAT_RGBX8888:
-	case DRM_FORMAT_BGRX8888:
-		*depth = 24;
-		*bpp = 32;
-		break;
-	case DRM_FORMAT_XRGB2101010:
-	case DRM_FORMAT_XBGR2101010:
-	case DRM_FORMAT_RGBX1010102:
-	case DRM_FORMAT_BGRX1010102:
-	case DRM_FORMAT_ARGB2101010:
-	case DRM_FORMAT_ABGR2101010:
-	case DRM_FORMAT_RGBA1010102:
-	case DRM_FORMAT_BGRA1010102:
-		*depth = 30;
-		*bpp = 32;
-		break;
-	case DRM_FORMAT_ARGB8888:
-	case DRM_FORMAT_ABGR8888:
-	case DRM_FORMAT_RGBA8888:
-	case DRM_FORMAT_BGRA8888:
-		*depth = 32;
-		*bpp = 32;
-		break;
-	default:
+	const struct drm_format_info *info;
+
+	info = drm_format_info(format);
+	if (!info || !info->depth) {
 		DRM_DEBUG_KMS("unsupported pixel format %s\n",
 			      drm_get_format_name(format));
 		*depth = 0;
 		*bpp = 0;
-		break;
+		return;
 	}
+
+	*depth = info->depth;
+	*bpp = info->cpp[0] << 3;
 }
 EXPORT_SYMBOL(drm_fb_get_bpp_depth);
 
@@ -229,28 +182,10 @@ EXPORT_SYMBOL(drm_fb_get_bpp_depth);
  */
 int drm_format_num_planes(uint32_t format)
 {
-	switch (format) {
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV444:
-	case DRM_FORMAT_YVU444:
-		return 3;
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_NV24:
-	case DRM_FORMAT_NV42:
-		return 2;
-	default:
-		return 1;
-	}
+	const struct drm_format_info *info;
+
+	info = drm_format_info(format);
+	return info ? info->num_planes : 1;
 }
 EXPORT_SYMBOL(drm_format_num_planes);
 
@@ -264,40 +199,13 @@ EXPORT_SYMBOL(drm_format_num_planes);
  */
 int drm_format_plane_cpp(uint32_t format, int plane)
 {
-	unsigned int depth;
-	int bpp;
+	const struct drm_format_info *info;
 
-	if (plane >= drm_format_num_planes(format))
+	info = drm_format_info(format);
+	if (!info || plane >= info->num_planes)
 		return 0;
 
-	switch (format) {
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-		return 2;
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_NV24:
-	case DRM_FORMAT_NV42:
-		return plane ? 2 : 1;
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV444:
-	case DRM_FORMAT_YVU444:
-		return 1;
-	default:
-		drm_fb_get_bpp_depth(format, &depth, &bpp);
-		return bpp >> 3;
-	}
+	return info->cpp[plane];
 }
 EXPORT_SYMBOL(drm_format_plane_cpp);
 
@@ -311,28 +219,10 @@ EXPORT_SYMBOL(drm_format_plane_cpp);
  */
 int drm_format_horz_chroma_subsampling(uint32_t format)
 {
-	switch (format) {
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-		return 4;
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-		return 2;
-	default:
-		return 1;
-	}
+	const struct drm_format_info *info;
+
+	info = drm_format_info(format);
+	return info ? info->hsub : 1;
 }
 EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
 
@@ -346,18 +236,10 @@ EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
  */
 int drm_format_vert_chroma_subsampling(uint32_t format)
 {
-	switch (format) {
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-		return 4;
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-		return 2;
-	default:
-		return 1;
-	}
+	const struct drm_format_info *info;
+
+	info = drm_format_info(format);
+	return info ? info->vsub : 1;
 }
 EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
 
@@ -372,13 +254,16 @@ EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
  */
 int drm_format_plane_width(int width, uint32_t format, int plane)
 {
-	if (plane >= drm_format_num_planes(format))
+	const struct drm_format_info *info;
+
+	info = drm_format_info(format);
+	if (!info || plane >= info->num_planes)
 		return 0;
 
 	if (plane == 0)
 		return width;
 
-	return width / drm_format_horz_chroma_subsampling(format);
+	return width / info->hsub;
 }
 EXPORT_SYMBOL(drm_format_plane_width);
 
@@ -393,12 +278,15 @@ EXPORT_SYMBOL(drm_format_plane_width);
  */
 int drm_format_plane_height(int height, uint32_t format, int plane)
 {
-	if (plane >= drm_format_num_planes(format))
+	const struct drm_format_info *info;
+
+	info = drm_format_info(format);
+	if (!info || plane >= info->num_planes)
 		return 0;
 
 	if (plane == 0)
 		return height;
 
-	return height / drm_format_vert_chroma_subsampling(format);
+	return height / info->vsub;
 }
 EXPORT_SYMBOL(drm_format_plane_height);
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 04/15] drm: Use drm_format_info() in DRM core code
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (2 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 03/15] drm: Implement the drm_format_*() helpers as drm_format_info() wrappers Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 05/15] drm: WARN when calling drm_format_info() for an unsupported format Laurent Pinchart
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

Replace calls to the drm_format_*() helper functions with direct use of
the drm_format_info structure. This improves efficiency by removing
duplicate lookups.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/drm_crtc.c          | 100 +++++-------------------------------
 drivers/gpu/drm/drm_fb_cma_helper.c |  23 +++++----
 2 files changed, 25 insertions(+), 98 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index e5369529af06..73fa7f2a1a04 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -3173,108 +3173,32 @@ int drm_mode_addfb(struct drm_device *dev,
 	return 0;
 }
 
-static int format_check(const struct drm_mode_fb_cmd2 *r)
-{
-	uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
-
-	switch (format) {
-	case DRM_FORMAT_C8:
-	case DRM_FORMAT_RGB332:
-	case DRM_FORMAT_BGR233:
-	case DRM_FORMAT_XRGB4444:
-	case DRM_FORMAT_XBGR4444:
-	case DRM_FORMAT_RGBX4444:
-	case DRM_FORMAT_BGRX4444:
-	case DRM_FORMAT_ARGB4444:
-	case DRM_FORMAT_ABGR4444:
-	case DRM_FORMAT_RGBA4444:
-	case DRM_FORMAT_BGRA4444:
-	case DRM_FORMAT_XRGB1555:
-	case DRM_FORMAT_XBGR1555:
-	case DRM_FORMAT_RGBX5551:
-	case DRM_FORMAT_BGRX5551:
-	case DRM_FORMAT_ARGB1555:
-	case DRM_FORMAT_ABGR1555:
-	case DRM_FORMAT_RGBA5551:
-	case DRM_FORMAT_BGRA5551:
-	case DRM_FORMAT_RGB565:
-	case DRM_FORMAT_BGR565:
-	case DRM_FORMAT_RGB888:
-	case DRM_FORMAT_BGR888:
-	case DRM_FORMAT_XRGB8888:
-	case DRM_FORMAT_XBGR8888:
-	case DRM_FORMAT_RGBX8888:
-	case DRM_FORMAT_BGRX8888:
-	case DRM_FORMAT_ARGB8888:
-	case DRM_FORMAT_ABGR8888:
-	case DRM_FORMAT_RGBA8888:
-	case DRM_FORMAT_BGRA8888:
-	case DRM_FORMAT_XRGB2101010:
-	case DRM_FORMAT_XBGR2101010:
-	case DRM_FORMAT_RGBX1010102:
-	case DRM_FORMAT_BGRX1010102:
-	case DRM_FORMAT_ARGB2101010:
-	case DRM_FORMAT_ABGR2101010:
-	case DRM_FORMAT_RGBA1010102:
-	case DRM_FORMAT_BGRA1010102:
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-	case DRM_FORMAT_AYUV:
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_NV24:
-	case DRM_FORMAT_NV42:
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV444:
-	case DRM_FORMAT_YVU444:
-		return 0;
-	default:
-		DRM_DEBUG_KMS("invalid pixel format %s\n",
-			      drm_get_format_name(r->pixel_format));
-		return -EINVAL;
-	}
-}
-
 static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 {
-	int ret, hsub, vsub, num_planes, i;
+	const struct drm_format_info *info;
+	int i;
 
-	ret = format_check(r);
-	if (ret) {
+	info = drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
+	if (!info) {
 		DRM_DEBUG_KMS("bad framebuffer format %s\n",
 			      drm_get_format_name(r->pixel_format));
-		return ret;
+		return -EINVAL;
 	}
 
-	hsub = drm_format_horz_chroma_subsampling(r->pixel_format);
-	vsub = drm_format_vert_chroma_subsampling(r->pixel_format);
-	num_planes = drm_format_num_planes(r->pixel_format);
-
-	if (r->width == 0 || r->width % hsub) {
+	if (r->width == 0 || r->width % info->hsub) {
 		DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
 		return -EINVAL;
 	}
 
-	if (r->height == 0 || r->height % vsub) {
+	if (r->height == 0 || r->height % info->vsub) {
 		DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height);
 		return -EINVAL;
 	}
 
-	for (i = 0; i < num_planes; i++) {
-		unsigned int width = r->width / (i != 0 ? hsub : 1);
-		unsigned int height = r->height / (i != 0 ? vsub : 1);
-		unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i);
+	for (i = 0; i < info->num_planes; i++) {
+		unsigned int width = r->width / (i != 0 ? info->hsub : 1);
+		unsigned int height = r->height / (i != 0 ? info->vsub : 1);
+		unsigned int cpp = info->cpp[i];
 
 		if (!r->handles[i]) {
 			DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
@@ -3317,7 +3241,7 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 		}
 	}
 
-	for (i = num_planes; i < 4; i++) {
+	for (i = info->num_planes; i < 4; i++) {
 		if (r->modifier[i]) {
 			DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i);
 			return -EINVAL;
diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c
index 5075fae3c4e2..47e6d2616d39 100644
--- a/drivers/gpu/drm/drm_fb_cma_helper.c
+++ b/drivers/gpu/drm/drm_fb_cma_helper.c
@@ -171,20 +171,20 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct drm_device *dev,
 	struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd,
 	const struct drm_framebuffer_funcs *funcs)
 {
+	const struct drm_format_info *info;
 	struct drm_fb_cma *fb_cma;
 	struct drm_gem_cma_object *objs[4];
 	struct drm_gem_object *obj;
-	unsigned int hsub;
-	unsigned int vsub;
 	int ret;
 	int i;
 
-	hsub = drm_format_horz_chroma_subsampling(mode_cmd->pixel_format);
-	vsub = drm_format_vert_chroma_subsampling(mode_cmd->pixel_format);
+	info = drm_format_info(mode_cmd->pixel_format);
+	if (!info)
+		return ERR_PTR(-EINVAL);
 
-	for (i = 0; i < drm_format_num_planes(mode_cmd->pixel_format); i++) {
-		unsigned int width = mode_cmd->width / (i ? hsub : 1);
-		unsigned int height = mode_cmd->height / (i ? vsub : 1);
+	for (i = 0; i < info->num_planes; i++) {
+		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
+		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
 		unsigned int min_size;
 
 		obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[i]);
@@ -195,7 +195,7 @@ struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct drm_device *dev,
 		}
 
 		min_size = (height - 1) * mode_cmd->pitches[i]
-			 + width * drm_format_plane_cpp(mode_cmd->pixel_format, i)
+			 + width * info->cpp[i]
 			 + mode_cmd->offsets[i];
 
 		if (obj->size < min_size) {
@@ -265,12 +265,15 @@ EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj);
 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
 {
 	struct drm_fb_cma *fb_cma = to_fb_cma(fb);
-	int i, n = drm_format_num_planes(fb->pixel_format);
+	const struct drm_format_info *info;
+	int i;
 
 	seq_printf(m, "fb: %dx%d@%4.4s\n", fb->width, fb->height,
 			(char *)&fb->pixel_format);
 
-	for (i = 0; i < n; i++) {
+	info = drm_format_info(fb->pixel_format);
+
+	for (i = 0; i < info->num_planes; i++) {
 		seq_printf(m, "   %d: offset=%d pitch=%d, obj: ",
 				i, fb->offsets[i], fb->pitches[i]);
 		drm_gem_cma_describe(fb_cma->obj[i], m);
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 05/15] drm: WARN when calling drm_format_info() for an unsupported format
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (3 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 04/15] drm: Use drm_format_info() in DRM core code Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 06/15] drm: msm: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

The format helpers have historically treated unsupported formats as part
of the default case, returning values that are likely wrong. We can't
change this behaviour now without risking breaking drivers in difficult
to detect ways, but we can WARN on unsupported formats to catch faulty
callers.

The only exception is the framebuffer_check() function that calls
drm_format_info() to validate the format passed from userspace. This is
a valid use case that shouldn't generate a warning.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/drm_crtc.c   |  2 +-
 drivers/gpu/drm/drm_fourcc.c | 32 ++++++++++++++++++++++++--------
 include/drm/drm_fourcc.h     |  1 +
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 73fa7f2a1a04..1777ab37890a 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -3178,7 +3178,7 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
 	const struct drm_format_info *info;
 	int i;
 
-	info = drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
+	info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
 	if (!info) {
 		DRM_DEBUG_KMS("bad framebuffer format %s\n",
 			      drm_get_format_name(r->pixel_format));
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index ef59e7f8032e..cb316e511ba9 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -61,15 +61,11 @@ const char *drm_get_format_name(uint32_t format)
 }
 EXPORT_SYMBOL(drm_get_format_name);
 
-/**
- * drm_format_info - query information for a given format
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The instance of struct drm_format_info that describes the pixel format, or
- * NULL if the format is unsupported.
+/*
+ * Internal function to query information for a given format. See
+ * drm_format_info() for the public API.
  */
-const struct drm_format_info *drm_format_info(u32 format)
+const struct drm_format_info *__drm_format_info(u32 format)
 {
 	static const struct drm_format_info formats[] = { 
 		{ .format = DRM_FORMAT_C8,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
@@ -143,6 +139,26 @@ const struct drm_format_info *drm_format_info(u32 format)
 
 	return NULL;
 }
+
+/**
+ * drm_format_info - query information for a given format
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * The caller should only pass a supported pixel format to this function.
+ * Unsupported pixel formats will generate a warning in the kernel log.
+ *
+ * Returns:
+ * The instance of struct drm_format_info that describes the pixel format, or
+ * NULL if the format is unsupported.
+ */
+const struct drm_format_info *drm_format_info(u32 format)
+{
+	const struct drm_format_info *info;
+
+	info = __drm_format_info(format);
+	WARN_ON(!info);
+	return info;
+}
 EXPORT_SYMBOL(drm_format_info);
 
 /**
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index b077df507b51..c9aa4e459358 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -43,6 +43,7 @@ struct drm_format_info {
 	u8 vsub;
 };
 
+const struct drm_format_info *__drm_format_info(u32 format);
 const struct drm_format_info *drm_format_info(u32 format);
 void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
 int drm_format_num_planes(uint32_t format);
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 06/15] drm: msm: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (4 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 05/15] drm: WARN when calling drm_format_info() for an unsupported format Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 07/15] drm: sti: " Laurent Pinchart
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel
  Cc: Tomi Valkeinen, Daniel Vetter, Ville Syrjälä,
	Eric Engestrom, Rob Clark, linux-arm-msm, freedreno

The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Cc: Rob Clark <robdclark@gmail.com>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org

diff --git a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
index 88fe256c1931..aa097b2376e7 100644
--- a/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
+++ b/drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c
@@ -496,8 +496,7 @@ static int mdp5_crtc_cursor_set(struct drm_crtc *crtc,
 	struct mdp5_kms *mdp5_kms = get_kms(crtc);
 	struct drm_gem_object *cursor_bo, *old_bo = NULL;
 	uint32_t blendcfg, cursor_addr, stride;
-	int ret, bpp, lm;
-	unsigned int depth;
+	int ret, lm;
 	enum mdp5_cursor_alpha cur_alpha = CURSOR_ALPHA_PER_PIXEL;
 	uint32_t flush_mask = mdp_ctl_flush_mask_cursor(0);
 	uint32_t roi_w, roi_h;
@@ -527,8 +526,7 @@ static int mdp5_crtc_cursor_set(struct drm_crtc *crtc,
 		return -EINVAL;
 
 	lm = mdp5_crtc->lm;
-	drm_fb_get_bpp_depth(DRM_FORMAT_ARGB8888, &depth, &bpp);
-	stride = width * (bpp >> 3);
+	stride = width * drm_format_plane_cpp(DRM_FORMAT_ARGB8888, 0);
 
 	spin_lock_irqsave(&mdp5_crtc->cursor.lock, flags);
 	old_bo = mdp5_crtc->cursor.scanout_bo;
-- 
Regards,

Laurent Pinchart

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 07/15] drm: sti: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (5 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 06/15] drm: msm: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-09  7:52   ` Vincent ABRIOU
  2016-06-08 23:32 ` [PATCH v3 08/15] drm: hdlcd: " Laurent Pinchart
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Tomi Valkeinen, Daniel Vetter, Vincent Abriou

The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/sti/sti_gdp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Cc: Vincent Abriou <vincent.abriou@st.com>

diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
index ff33c38da197..be7e80535083 100644
--- a/drivers/gpu/drm/sti/sti_gdp.c
+++ b/drivers/gpu/drm/sti/sti_gdp.c
@@ -733,7 +733,7 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
 	u32 dma_updated_top;
 	u32 dma_updated_btm;
 	int format;
-	unsigned int depth, bpp;
+	unsigned int bpp;
 	u32 ydo, xdo, yds, xds;
 
 	if (!crtc || !fb)
@@ -772,9 +772,9 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
 			 (unsigned long)cma_obj->paddr);
 
 	/* pixel memory location */
-	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
+	bpp = drm_format_plane_cpp(fb->pixel_format, 0);
 	top_field->gam_gdp_pml = (u32)cma_obj->paddr + fb->offsets[0];
-	top_field->gam_gdp_pml += src_x * (bpp >> 3);
+	top_field->gam_gdp_pml += src_x * bpp;
 	top_field->gam_gdp_pml += src_y * fb->pitches[0];
 
 	/* output parameters (clamped / cropped) */
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 08/15] drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (6 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 07/15] drm: sti: " Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-09  9:01   ` Liviu Dudau
  2016-06-08 23:32 ` [PATCH v3 09/15] drm: tilcdc: " Laurent Pinchart
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Liviu Dudau, Tomi Valkeinen

The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/arm/hdlcd_crtc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Cc: Liviu Dudau <liviu.dudau@arm.com>

diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
index 0813c2f06931..b93a4ce01c50 100644
--- a/drivers/gpu/drm/arm/hdlcd_crtc.c
+++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
@@ -242,14 +242,12 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane,
 {
 	struct hdlcd_drm_private *hdlcd;
 	struct drm_gem_cma_object *gem;
-	unsigned int depth, bpp;
 	u32 src_w, src_h, dest_w, dest_h;
 	dma_addr_t scanout_start;
 
 	if (!plane->state->fb)
 		return;
 
-	drm_fb_get_bpp_depth(plane->state->fb->pixel_format, &depth, &bpp);
 	src_w = plane->state->src_w >> 16;
 	src_h = plane->state->src_h >> 16;
 	dest_w = plane->state->crtc_w;
@@ -257,7 +255,8 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane,
 	gem = drm_fb_cma_get_gem_obj(plane->state->fb, 0);
 	scanout_start = gem->paddr + plane->state->fb->offsets[0] +
 		plane->state->crtc_y * plane->state->fb->pitches[0] +
-		plane->state->crtc_x * bpp / 8;
+		plane->state->crtc_x *
+		drm_format_plane_cpp(plane->state->fb->pixel_format, 0);
 
 	hdlcd = plane->dev->dev_private;
 	hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, plane->state->fb->pitches[0]);
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (7 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 08/15] drm: hdlcd: " Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-10 11:51   ` Tomi Valkeinen
  2016-06-08 23:32 ` [PATCH v3 10/15] drm: cirrus: " Laurent Pinchart
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen, Jyri Sarha

The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

In the tilcdc_crtc_mode_set() function compute the hardware register
value directly from the pixel format instead of computing the number of
bits per pixels first.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

Cc: Jyri Sarha <jsarha@ti.com>

diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
index 79027b1c64d3..d63c7363dabc 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
@@ -65,15 +65,13 @@ static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
 	struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
 	struct drm_device *dev = crtc->dev;
 	struct drm_gem_cma_object *gem;
-	unsigned int depth, bpp;
 	dma_addr_t start, end;
 
-	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
 	gem = drm_fb_cma_get_gem_obj(fb, 0);
 
 	start = gem->paddr + fb->offsets[0] +
 		crtc->y * fb->pitches[0] +
-		crtc->x * bpp / 8;
+		crtc->x * drm_format_plane_cpp(fb->pixel_format, 0);
 
 	end = start + (crtc->mode.vdisplay * fb->pitches[0]);
 
@@ -132,11 +130,12 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
 static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb)
 {
 	struct drm_device *dev = crtc->dev;
-	unsigned int depth, bpp;
+	unsigned int min_pitch;
 
-	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
+	min_pitch = crtc->mode.hdisplay
+		  * drm_format_plane_cpp(fb->pixel_format, 0);
 
-	if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) {
+	if (fb->pitches[0] != min_pitch) {
 		dev_err(dev->dev,
 			"Invalid pitch: fb and crtc widths must be the same");
 		return -EINVAL;
@@ -401,16 +400,14 @@ static int tilcdc_crtc_mode_set(struct drm_crtc *crtc,
 	if (info->tft_alt_mode)
 		reg |= LCDC_TFT_ALT_ENABLE;
 	if (priv->rev == 2) {
-		unsigned int depth, bpp;
-
-		drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp);
-		switch (bpp) {
-		case 16:
+		switch (crtc->primary->fb->pixel_format) {
+		case DRM_FORMAT_RGB565:
 			break;
-		case 32:
+		case DRM_FORMAT_XRGB8888:
+		case DRM_FORMAT_ARGB8888:
 			reg |= LCDC_V2_TFT_24BPP_UNPACK;
 			/* fallthrough */
-		case 24:
+		case DRM_FORMAT_RGB888:
 			reg |= LCDC_V2_TFT_24BPP_MODE;
 			break;
 		default:
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 10/15] drm: cirrus: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (8 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 09/15] drm: tilcdc: " Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 11/15] drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen, Dave Airlie

The driver doesn't need the color depth, only the number of bits per
pixel. Use the right API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/cirrus/cirrus_fbdev.c | 6 +++---
 drivers/gpu/drm/cirrus/cirrus_main.c  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

Cc: Dave Airlie <airlied@redhat.com>

diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
index 3b5be7272357..3d0e900c8f95 100644
--- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c
+++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c
@@ -140,12 +140,12 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev,
 {
 	struct drm_device *dev = afbdev->helper.dev;
 	struct cirrus_device *cdev = dev->dev_private;
-	u32 bpp, depth;
+	u32 bpp;
 	u32 size;
 	struct drm_gem_object *gobj;
-
 	int ret = 0;
-	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+
+	bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0) * 8;
 
 	if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
 				      bpp, mode_cmd->pitches[0]))
diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c b/drivers/gpu/drm/cirrus/cirrus_main.c
index 32d32c5b7b17..4c9df1fbdece 100644
--- a/drivers/gpu/drm/cirrus/cirrus_main.c
+++ b/drivers/gpu/drm/cirrus/cirrus_main.c
@@ -52,10 +52,10 @@ cirrus_user_framebuffer_create(struct drm_device *dev,
 	struct cirrus_device *cdev = dev->dev_private;
 	struct drm_gem_object *obj;
 	struct cirrus_framebuffer *cirrus_fb;
+	u32 bpp;
 	int ret;
-	u32 bpp, depth;
 
-	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+	bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0) * 8;
 
 	if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
 				      bpp, mode_cmd->pitches[0]))
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 11/15] drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (9 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 10/15] drm: cirrus: " Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 12/15] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

The driver uses drm_fb_get_bpp_depth() to check whether it can support
the format requested by userspace when creating a framebuffer. This
isn't the right API, as it doesn't differentiate between RGB formats
other than on a depth and bpp basis.

Fixing this requires non trivial changes to the drivers internals. As a
first step, replace usage of the drm_fb_get_bpp_depth() function with an
equivalent check based on drm_format_info(). This is part of a wider
effort to remove usage of the drm_fb_get_bpp_depth() function in
drivers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/gma500/framebuffer.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

Cc: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>

diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c
index 7440bf90ac9c..659707a5e85d 100644
--- a/drivers/gpu/drm/gma500/framebuffer.c
+++ b/drivers/gpu/drm/gma500/framebuffer.c
@@ -246,22 +246,20 @@ static int psb_framebuffer_init(struct drm_device *dev,
 					const struct drm_mode_fb_cmd2 *mode_cmd,
 					struct gtt_range *gt)
 {
-	u32 bpp, depth;
+	const struct drm_format_info *info;
 	int ret;
 
-	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+	/*
+	 * Reject unknown formats, YUV formats, and formats with more than
+	 * 4 bytes per pixel.
+	 */
+	info = drm_format_info(mode_cmd->pixel_format);
+	if (!info || !info->depth || info->cpp[0] > 4)
+		return -EINVAL;
 
 	if (mode_cmd->pitches[0] & 63)
 		return -EINVAL;
-	switch (bpp) {
-	case 8:
-	case 16:
-	case 24:
-	case 32:
-		break;
-	default:
-		return -EINVAL;
-	}
+
 	drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd);
 	fb->gtt = gt;
 	ret = drm_framebuffer_init(dev, &fb->base, &psb_fb_funcs);
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 12/15] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (10 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 11/15] drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-09  1:42   ` Michel Dänzer
  2016-06-08 23:32 ` [PATCH v3 13/15] drm: radeon: " Laurent Pinchart
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel
  Cc: Tomi Valkeinen, Alex Deucher, Daniel Vetter, Christian König

The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  | 10 +++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c |  3 ++-
 2 files changed, 7 insertions(+), 6 deletions(-)

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 919146780a15..306f626d3e80 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -68,7 +68,7 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int width, int bpp, bool tile
 	int aligned = width;
 	int pitch_mask = 0;
 
-	switch (bpp / 8) {
+	switch (bpp) {
 	case 1:
 		pitch_mask = 255;
 		break;
@@ -83,7 +83,7 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int width, int bpp, bool tile
 
 	aligned += pitch_mask;
 	aligned &= ~pitch_mask;
-	return aligned;
+	return aligned * bpp;
 }
 
 static void amdgpufb_destroy_pinned_object(struct drm_gem_object *gobj)
@@ -112,13 +112,13 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,
 	int ret;
 	int aligned_size, size;
 	int height = mode_cmd->height;
-	u32 bpp, depth;
+	u32 bpp;
 
-	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+	bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);
 
 	/* need to align pitch with crtc limits */
 	mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, bpp,
-						  fb_tiled) * ((bpp + 1) / 8);
+						  fb_tiled);
 
 	height = ALIGN(mode_cmd->height, 8);
 	size = mode_cmd->pitches[0] * height;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 8fab6486064f..232230f14769 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -704,7 +704,8 @@ int amdgpu_mode_dumb_create(struct drm_file *file_priv,
 	uint32_t handle;
 	int r;
 
-	args->pitch = amdgpu_align_pitch(adev, args->width, args->bpp, 0) * ((args->bpp + 1) / 8);
+	args->pitch = amdgpu_align_pitch(adev, args->width,
+					 DIV_ROUND_UP(args->bpp, 8), 0);
 	args->size = (u64)args->pitch * args->height;
 	args->size = ALIGN(args->size, PAGE_SIZE);
 
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 13/15] drm: radeon: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (11 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 12/15] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 14/15] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
  2016-06-08 23:32 ` [PATCH v3 15/15] drm: Don't export the drm_fb_get_bpp_depth() function Laurent Pinchart
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel
  Cc: Tomi Valkeinen, Alex Deucher, Daniel Vetter, Christian König

The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/radeon/radeon_fb.c  | 14 +++++++-------
 drivers/gpu/drm/radeon/radeon_gem.c |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>

diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c
index 0e3143acb565..f5878ca7d730 100644
--- a/drivers/gpu/drm/radeon/radeon_fb.c
+++ b/drivers/gpu/drm/radeon/radeon_fb.c
@@ -68,7 +68,7 @@ int radeon_align_pitch(struct radeon_device *rdev, int width, int bpp, bool tile
 	int align_large = (ASIC_IS_AVIVO(rdev)) || tiled;
 	int pitch_mask = 0;
 
-	switch (bpp / 8) {
+	switch (bpp) {
 	case 1:
 		pitch_mask = align_large ? 255 : 127;
 		break;
@@ -83,7 +83,7 @@ int radeon_align_pitch(struct radeon_device *rdev, int width, int bpp, bool tile
 
 	aligned += pitch_mask;
 	aligned &= ~pitch_mask;
-	return aligned;
+	return aligned * bpp;
 }
 
 static void radeonfb_destroy_pinned_object(struct drm_gem_object *gobj)
@@ -112,13 +112,13 @@ static int radeonfb_create_pinned_object(struct radeon_fbdev *rfbdev,
 	int ret;
 	int aligned_size, size;
 	int height = mode_cmd->height;
-	u32 bpp, depth;
+	u32 bpp;
 
-	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
+	bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);
 
 	/* need to align pitch with crtc limits */
 	mode_cmd->pitches[0] = radeon_align_pitch(rdev, mode_cmd->width, bpp,
-						  fb_tiled) * ((bpp + 1) / 8);
+						  fb_tiled);
 
 	if (rdev->family >= CHIP_R600)
 		height = ALIGN(mode_cmd->height, 8);
@@ -139,10 +139,10 @@ static int radeonfb_create_pinned_object(struct radeon_fbdev *rfbdev,
 
 #ifdef __BIG_ENDIAN
 	switch (bpp) {
-	case 32:
+	case 4:
 		tiling_flags |= RADEON_TILING_SWAP_32BIT;
 		break;
-	case 16:
+	case 2:
 		tiling_flags |= RADEON_TILING_SWAP_16BIT;
 	default:
 		break;
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index deb9511725c9..0bcffd8a7bd3 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -745,7 +745,8 @@ int radeon_mode_dumb_create(struct drm_file *file_priv,
 	uint32_t handle;
 	int r;
 
-	args->pitch = radeon_align_pitch(rdev, args->width, args->bpp, 0) * ((args->bpp + 1) / 8);
+	args->pitch = radeon_align_pitch(rdev, args->width,
+					 DIV_ROUND_UP(args->bpp, 8), 0);
 	args->size = args->pitch * args->height;
 	args->size = ALIGN(args->size, PAGE_SIZE);
 
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 14/15] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info()
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (12 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 13/15] drm: radeon: " Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  2016-06-27 17:51   ` Sinclair Yeh
  2016-06-08 23:32 ` [PATCH v3 15/15] drm: Don't export the drm_fb_get_bpp_depth() function Laurent Pinchart
  14 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel
  Cc: Thomas Hellstrom, Tomi Valkeinen, VMware Graphics, Daniel Vetter

The driver is the last users of the drm_fb_get_bpp_depth() function. It
should ideally be converted to use struct drm_mode_fb_cmd2 instead of
the legacy struct drm_mode_fb_cmd internally, but that will require
broad changes across the code base. As a first step, replace
drm_fb_get_bpp_depth() with drm_format_info() in order to stop exporting
the function to drivers.

The new DRM_ERROR() message comes from the vmw_create_dmabuf_proxy(),
vmw_kms_new_framebuffer_surface() and vmw_kms_new_framebuffer_dmabuf()
functions that currently print an error if the pixel format is
unsupported.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Cc: VMware Graphics <linux-graphics-maintainer@vmware.com>
Cc: Sinclair Yeh <syeh@vmware.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 55231cce73a0..1a7187f472de 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -980,14 +980,22 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
 	struct vmw_dma_buffer *bo = NULL;
 	struct ttm_base_object *user_obj;
 	struct drm_mode_fb_cmd mode_cmd;
+	const struct drm_format_info *info;
 	int ret;
 
+	info = drm_format_info(mode_cmd2->pixel_format);
+	if (!info || !info->depth) {
+		DRM_ERROR("Unsupported framebuffer format %s\n",
+			  drm_get_format_name(mode_cmd2->pixel_format));
+		return ERR_PTR(-EINVAL);
+	}
+
 	mode_cmd.width = mode_cmd2->width;
 	mode_cmd.height = mode_cmd2->height;
 	mode_cmd.pitch = mode_cmd2->pitches[0];
 	mode_cmd.handle = mode_cmd2->handles[0];
-	drm_fb_get_bpp_depth(mode_cmd2->pixel_format, &mode_cmd.depth,
-				    &mode_cmd.bpp);
+	mode_cmd.depth = info->depth;
+	mode_cmd.bpp = info->cpp[0] * 8;
 
 	/**
 	 * This code should be conditioned on Screen Objects not being used.
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH v3 15/15] drm: Don't export the drm_fb_get_bpp_depth() function
  2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
                   ` (13 preceding siblings ...)
  2016-06-08 23:32 ` [PATCH v3 14/15] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
@ 2016-06-08 23:32 ` Laurent Pinchart
  14 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-08 23:32 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

The function is only used by the drm_helper_mode_fill_fb_struct() core
function to fill the drm_framebuffer bpp and depth fields, used by
drivers that haven't been converted to use pixel formats directly yet.
It should not be used by new drivers, so inline it in its only caller.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/drm_crtc_helper.c | 14 ++++++++++++--
 drivers/gpu/drm/drm_fourcc.c      | 28 ----------------------------
 include/drm/drm_fourcc.h          |  1 -
 3 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index a6e42433ef0e..3619af2cbe96 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -918,8 +918,20 @@ EXPORT_SYMBOL(drm_helper_connector_dpms);
 void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
 				    const struct drm_mode_fb_cmd2 *mode_cmd)
 {
+	const struct drm_format_info *info;
 	int i;
 
+	info = drm_format_info(mode_cmd->pixel_format);
+	if (!info || !info->depth) {
+		DRM_DEBUG_KMS("non-RGB pixel format %s\n",
+			      drm_get_format_name(mode_cmd->pixel_format));
+		fb->depth = 0;
+		fb->bits_per_pixel = 0;
+	} else {
+		fb->depth = info->depth;
+		fb->bits_per_pixel = info->cpp[0] << 3;
+	}
+
 	fb->width = mode_cmd->width;
 	fb->height = mode_cmd->height;
 	for (i = 0; i < 4; i++) {
@@ -927,8 +939,6 @@ void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
 		fb->offsets[i] = mode_cmd->offsets[i];
 		fb->modifier[i] = mode_cmd->modifier[i];
 	}
-	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &fb->depth,
-				    &fb->bits_per_pixel);
 	fb->pixel_format = mode_cmd->pixel_format;
 	fb->flags = mode_cmd->flags;
 }
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index cb316e511ba9..d8f3fdfe57eb 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -162,34 +162,6 @@ const struct drm_format_info *drm_format_info(u32 format)
 EXPORT_SYMBOL(drm_format_info);
 
 /**
- * drm_fb_get_bpp_depth - get the bpp/depth values for format
- * @format: pixel format (DRM_FORMAT_*)
- * @depth: storage for the depth value
- * @bpp: storage for the bpp value
- *
- * This only supports RGB formats here for compat with code that doesn't use
- * pixel formats directly yet.
- */
-void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
-			  int *bpp)
-{
-	const struct drm_format_info *info;
-
-	info = drm_format_info(format);
-	if (!info || !info->depth) {
-		DRM_DEBUG_KMS("unsupported pixel format %s\n",
-			      drm_get_format_name(format));
-		*depth = 0;
-		*bpp = 0;
-		return;
-	}
-
-	*depth = info->depth;
-	*bpp = info->cpp[0] << 3;
-}
-EXPORT_SYMBOL(drm_fb_get_bpp_depth);
-
-/**
  * drm_format_num_planes - get the number of planes for format
  * @format: pixel format (DRM_FORMAT_*)
  *
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index c9aa4e459358..1f4746bc0eae 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -45,7 +45,6 @@ struct drm_format_info {
 
 const struct drm_format_info *__drm_format_info(u32 format);
 const struct drm_format_info *drm_format_info(u32 format);
-void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
 int drm_format_num_planes(uint32_t format);
 int drm_format_plane_cpp(uint32_t format, int plane);
 int drm_format_horz_chroma_subsampling(uint32_t format);
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 12/15] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 ` [PATCH v3 12/15] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
@ 2016-06-09  1:42   ` Michel Dänzer
  2016-06-09  9:18     ` Laurent Pinchart
  0 siblings, 1 reply; 49+ messages in thread
From: Michel Dänzer @ 2016-06-09  1:42 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Alex Deucher, Daniel Vetter, Tomi Valkeinen,
	Christian König, dri-devel

On 09.06.2016 08:32, Laurent Pinchart wrote:
> The driver needs the number of bytes per pixel, not the bpp and depth
> info meant for fbdev compatibility. Use the right API.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  | 10 +++++-----
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c |  3 ++-
>  2 files changed, 7 insertions(+), 6 deletions(-)
> 
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> index 919146780a15..306f626d3e80 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> @@ -68,7 +68,7 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int width, int bpp, bool tile
>  	int aligned = width;
>  	int pitch_mask = 0;
>  
> -	switch (bpp / 8) {
> +	switch (bpp) {
>  	case 1:
>  		pitch_mask = 255;
>  		break;
> @@ -83,7 +83,7 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int width, int bpp, bool tile
>  
>  	aligned += pitch_mask;
>  	aligned &= ~pitch_mask;
> -	return aligned;
> +	return aligned * bpp;
>  }
>  
>  static void amdgpufb_destroy_pinned_object(struct drm_gem_object *gobj)
> @@ -112,13 +112,13 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,
>  	int ret;
>  	int aligned_size, size;
>  	int height = mode_cmd->height;
> -	u32 bpp, depth;
> +	u32 bpp;
>  
> -	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
> +	bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);

I think renaming bpp (for "bits per pixel") to cpp (for "chars (bytes)
per pixel") in these two functions would avoid confusion.

Same comment for the radeon patch.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 07/15] drm: sti: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 ` [PATCH v3 07/15] drm: sti: " Laurent Pinchart
@ 2016-06-09  7:52   ` Vincent ABRIOU
  2016-06-09  9:17     ` Laurent Pinchart
  0 siblings, 1 reply; 49+ messages in thread
From: Vincent ABRIOU @ 2016-06-09  7:52 UTC (permalink / raw)
  To: Laurent Pinchart, dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen


On 06/09/2016 01:32 AM, Laurent Pinchart wrote:
> The driver needs the number of bytes per pixel, not the bpp and depth
> info meant for fbdev compatibility. Use the right API.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>   drivers/gpu/drm/sti/sti_gdp.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> Cc: Vincent Abriou <vincent.abriou@st.com>
>
> diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
> index ff33c38da197..be7e80535083 100644
> --- a/drivers/gpu/drm/sti/sti_gdp.c
> +++ b/drivers/gpu/drm/sti/sti_gdp.c
> @@ -733,7 +733,7 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
>   	u32 dma_updated_top;
>   	u32 dma_updated_btm;
>   	int format;
> -	unsigned int depth, bpp;
> +	unsigned int bpp;
>   	u32 ydo, xdo, yds, xds;
>
>   	if (!crtc || !fb)
> @@ -772,9 +772,9 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
>   			 (unsigned long)cma_obj->paddr);
>
>   	/* pixel memory location */
> -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> +	bpp = drm_format_plane_cpp(fb->pixel_format, 0);

Hi Laurent,

The patch is fine for me but what does "cpp" means in drm_format_plane_cpp?

Vincent

>   	top_field->gam_gdp_pml = (u32)cma_obj->paddr + fb->offsets[0];
> -	top_field->gam_gdp_pml += src_x * (bpp >> 3);
> +	top_field->gam_gdp_pml += src_x * bpp;
>   	top_field->gam_gdp_pml += src_y * fb->pitches[0];
>
>   	/* output parameters (clamped / cropped) */
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 01/15] drm: Move format-related helpers to drm_fourcc.c
  2016-06-08 23:32 ` [PATCH v3 01/15] drm: Move format-related helpers to drm_fourcc.c Laurent Pinchart
@ 2016-06-09  8:36   ` Daniel Vetter
  2016-06-09  9:54     ` [PATCH v3.1 " Laurent Pinchart
  0 siblings, 1 reply; 49+ messages in thread
From: Daniel Vetter @ 2016-06-09  8:36 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Daniel Vetter, Tomi Valkeinen, dri-devel

On Thu, Jun 09, 2016 at 02:32:05AM +0300, Laurent Pinchart wrote:
> The drm_crtc.c file is a mess, making the ABI documentation confusing
> since all functions are in the same bag. Split the format-related
> helpers to a new drm_fourcc.c file.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  Documentation/DocBook/gpu.tmpl |   5 +
>  drivers/gpu/drm/Makefile       |   2 +-
>  drivers/gpu/drm/drm_crtc.c     | 289 -------------------------------------
>  drivers/gpu/drm/drm_fourcc.c   | 320 +++++++++++++++++++++++++++++++++++++++++
>  include/drm/drmP.h             |   1 +
>  include/drm/drm_crtc.h         |   9 --
>  include/drm/drm_fourcc.h       |  37 +++++
>  7 files changed, 364 insertions(+), 299 deletions(-)
>  create mode 100644 drivers/gpu/drm/drm_fourcc.c
>  create mode 100644 include/drm/drm_fourcc.h
> 
> diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
> index 7586bf75f62e..d32363cb1ff1 100644
> --- a/Documentation/DocBook/gpu.tmpl
> +++ b/Documentation/DocBook/gpu.tmpl
> @@ -1656,6 +1656,11 @@ void intel_crt_init(struct drm_device *dev)
>  !Edrivers/gpu/drm/drm_rect.c
>      </sect2>
>      <sect2>
> +      <title>Formats Utilities Reference</title>
> +!Iinclude/drm/drm_fourcc.h
> +!Edrivers/gpu/drm/drm_fourcc.c

Not sure this is correct in the helper section of KMS. drm_fourcc is part
of the uabi, including all the metadata definitions. Please move one
section up, and resend just this patch so I can merge it (to avoid
needless conflicts and rebase pain).
-Daniel

> +    </sect2>
> +    <sect2>
>        <title>Flip-work Helper Reference</title>
>  !Pinclude/drm/drm_flip_work.h flip utils
>  !Iinclude/drm/drm_flip_work.h
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index be43afb08c69..aa24af35c068 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -8,7 +8,7 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
>  		drm_lock.o drm_memory.o drm_drv.o drm_vm.o \
>  		drm_scatter.o drm_pci.o \
>  		drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
> -		drm_crtc.o drm_modes.o drm_edid.o \
> +		drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
>  		drm_info.o drm_debugfs.o drm_encoder_slave.o \
>  		drm_trace_points.o drm_global.o drm_prime.o \
>  		drm_rect.o drm_vma_manager.o drm_flip_work.o \
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 0e3cc66aa8b7..e5369529af06 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -239,37 +239,6 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
>  }
>  EXPORT_SYMBOL(drm_get_subpixel_order_name);
>  
> -static char printable_char(int c)
> -{
> -	return isascii(c) && isprint(c) ? c : '?';
> -}
> -
> -/**
> - * drm_get_format_name - return a string for drm fourcc format
> - * @format: format to compute name of
> - *
> - * Note that the buffer used by this function is globally shared and owned by
> - * the function itself.
> - *
> - * FIXME: This isn't really multithreading safe.
> - */
> -const char *drm_get_format_name(uint32_t format)
> -{
> -	static char buf[32];
> -
> -	snprintf(buf, sizeof(buf),
> -		 "%c%c%c%c %s-endian (0x%08x)",
> -		 printable_char(format & 0xff),
> -		 printable_char((format >> 8) & 0xff),
> -		 printable_char((format >> 16) & 0xff),
> -		 printable_char((format >> 24) & 0x7f),
> -		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
> -		 format);
> -
> -	return buf;
> -}
> -EXPORT_SYMBOL(drm_get_format_name);
> -
>  /*
>   * Internal function to assign a slot in the object idr and optionally
>   * register the object into the idr.
> @@ -5544,264 +5513,6 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
>  }
>  
>  /**
> - * drm_fb_get_bpp_depth - get the bpp/depth values for format
> - * @format: pixel format (DRM_FORMAT_*)
> - * @depth: storage for the depth value
> - * @bpp: storage for the bpp value
> - *
> - * This only supports RGB formats here for compat with code that doesn't use
> - * pixel formats directly yet.
> - */
> -void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> -			  int *bpp)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_C8:
> -	case DRM_FORMAT_RGB332:
> -	case DRM_FORMAT_BGR233:
> -		*depth = 8;
> -		*bpp = 8;
> -		break;
> -	case DRM_FORMAT_XRGB1555:
> -	case DRM_FORMAT_XBGR1555:
> -	case DRM_FORMAT_RGBX5551:
> -	case DRM_FORMAT_BGRX5551:
> -	case DRM_FORMAT_ARGB1555:
> -	case DRM_FORMAT_ABGR1555:
> -	case DRM_FORMAT_RGBA5551:
> -	case DRM_FORMAT_BGRA5551:
> -		*depth = 15;
> -		*bpp = 16;
> -		break;
> -	case DRM_FORMAT_RGB565:
> -	case DRM_FORMAT_BGR565:
> -		*depth = 16;
> -		*bpp = 16;
> -		break;
> -	case DRM_FORMAT_RGB888:
> -	case DRM_FORMAT_BGR888:
> -		*depth = 24;
> -		*bpp = 24;
> -		break;
> -	case DRM_FORMAT_XRGB8888:
> -	case DRM_FORMAT_XBGR8888:
> -	case DRM_FORMAT_RGBX8888:
> -	case DRM_FORMAT_BGRX8888:
> -		*depth = 24;
> -		*bpp = 32;
> -		break;
> -	case DRM_FORMAT_XRGB2101010:
> -	case DRM_FORMAT_XBGR2101010:
> -	case DRM_FORMAT_RGBX1010102:
> -	case DRM_FORMAT_BGRX1010102:
> -	case DRM_FORMAT_ARGB2101010:
> -	case DRM_FORMAT_ABGR2101010:
> -	case DRM_FORMAT_RGBA1010102:
> -	case DRM_FORMAT_BGRA1010102:
> -		*depth = 30;
> -		*bpp = 32;
> -		break;
> -	case DRM_FORMAT_ARGB8888:
> -	case DRM_FORMAT_ABGR8888:
> -	case DRM_FORMAT_RGBA8888:
> -	case DRM_FORMAT_BGRA8888:
> -		*depth = 32;
> -		*bpp = 32;
> -		break;
> -	default:
> -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> -			      drm_get_format_name(format));
> -		*depth = 0;
> -		*bpp = 0;
> -		break;
> -	}
> -}
> -EXPORT_SYMBOL(drm_fb_get_bpp_depth);
> -
> -/**
> - * drm_format_num_planes - get the number of planes for format
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The number of planes used by the specified pixel format.
> - */
> -int drm_format_num_planes(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV444:
> -	case DRM_FORMAT_YVU444:
> -		return 3;
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_NV24:
> -	case DRM_FORMAT_NV42:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_num_planes);
> -
> -/**
> - * drm_format_plane_cpp - determine the bytes per pixel value
> - * @format: pixel format (DRM_FORMAT_*)
> - * @plane: plane index
> - *
> - * Returns:
> - * The bytes per pixel value for the specified plane.
> - */
> -int drm_format_plane_cpp(uint32_t format, int plane)
> -{
> -	unsigned int depth;
> -	int bpp;
> -
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	switch (format) {
> -	case DRM_FORMAT_YUYV:
> -	case DRM_FORMAT_YVYU:
> -	case DRM_FORMAT_UYVY:
> -	case DRM_FORMAT_VYUY:
> -		return 2;
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_NV24:
> -	case DRM_FORMAT_NV42:
> -		return plane ? 2 : 1;
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV444:
> -	case DRM_FORMAT_YVU444:
> -		return 1;
> -	default:
> -		drm_fb_get_bpp_depth(format, &depth, &bpp);
> -		return bpp >> 3;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_plane_cpp);
> -
> -/**
> - * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The horizontal chroma subsampling factor for the
> - * specified pixel format.
> - */
> -int drm_format_horz_chroma_subsampling(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -		return 4;
> -	case DRM_FORMAT_YUYV:
> -	case DRM_FORMAT_YVYU:
> -	case DRM_FORMAT_UYVY:
> -	case DRM_FORMAT_VYUY:
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
> -
> -/**
> - * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The vertical chroma subsampling factor for the
> - * specified pixel format.
> - */
> -int drm_format_vert_chroma_subsampling(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -		return 4;
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
> -
> -/**
> - * drm_format_plane_width - width of the plane given the first plane
> - * @width: width of the first plane
> - * @format: pixel format
> - * @plane: plane index
> - *
> - * Returns:
> - * The width of @plane, given that the width of the first plane is @width.
> - */
> -int drm_format_plane_width(int width, uint32_t format, int plane)
> -{
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	if (plane == 0)
> -		return width;
> -
> -	return width / drm_format_horz_chroma_subsampling(format);
> -}
> -EXPORT_SYMBOL(drm_format_plane_width);
> -
> -/**
> - * drm_format_plane_height - height of the plane given the first plane
> - * @height: height of the first plane
> - * @format: pixel format
> - * @plane: plane index
> - *
> - * Returns:
> - * The height of @plane, given that the height of the first plane is @height.
> - */
> -int drm_format_plane_height(int height, uint32_t format, int plane)
> -{
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	if (plane == 0)
> -		return height;
> -
> -	return height / drm_format_vert_chroma_subsampling(format);
> -}
> -EXPORT_SYMBOL(drm_format_plane_height);
> -
> -/**
>   * drm_rotation_simplify() - Try to simplify the rotation
>   * @rotation: Rotation to be simplified
>   * @supported_rotations: Supported rotations
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> new file mode 100644
> index 000000000000..0645c85d5f95
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -0,0 +1,320 @@
> +/*
> + * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + *
> + * DRM core format related functions
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#include <linux/bug.h>
> +#include <linux/ctype.h>
> +#include <linux/export.h>
> +#include <linux/kernel.h>
> +
> +#include <drm/drmP.h>
> +#include <drm/drm_fourcc.h>
> +
> +static char printable_char(int c)
> +{
> +	return isascii(c) && isprint(c) ? c : '?';
> +}
> +
> +/**
> + * drm_get_format_name - return a string for drm fourcc format
> + * @format: format to compute name of
> + *
> + * Note that the buffer used by this function is globally shared and owned by
> + * the function itself.
> + *
> + * FIXME: This isn't really multithreading safe.
> + */
> +const char *drm_get_format_name(uint32_t format)
> +{
> +	static char buf[32];
> +
> +	snprintf(buf, sizeof(buf),
> +		 "%c%c%c%c %s-endian (0x%08x)",
> +		 printable_char(format & 0xff),
> +		 printable_char((format >> 8) & 0xff),
> +		 printable_char((format >> 16) & 0xff),
> +		 printable_char((format >> 24) & 0x7f),
> +		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
> +		 format);
> +
> +	return buf;
> +}
> +EXPORT_SYMBOL(drm_get_format_name);
> +
> +/**
> + * drm_fb_get_bpp_depth - get the bpp/depth values for format
> + * @format: pixel format (DRM_FORMAT_*)
> + * @depth: storage for the depth value
> + * @bpp: storage for the bpp value
> + *
> + * This only supports RGB formats here for compat with code that doesn't use
> + * pixel formats directly yet.
> + */
> +void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> +			  int *bpp)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_C8:
> +	case DRM_FORMAT_RGB332:
> +	case DRM_FORMAT_BGR233:
> +		*depth = 8;
> +		*bpp = 8;
> +		break;
> +	case DRM_FORMAT_XRGB1555:
> +	case DRM_FORMAT_XBGR1555:
> +	case DRM_FORMAT_RGBX5551:
> +	case DRM_FORMAT_BGRX5551:
> +	case DRM_FORMAT_ARGB1555:
> +	case DRM_FORMAT_ABGR1555:
> +	case DRM_FORMAT_RGBA5551:
> +	case DRM_FORMAT_BGRA5551:
> +		*depth = 15;
> +		*bpp = 16;
> +		break;
> +	case DRM_FORMAT_RGB565:
> +	case DRM_FORMAT_BGR565:
> +		*depth = 16;
> +		*bpp = 16;
> +		break;
> +	case DRM_FORMAT_RGB888:
> +	case DRM_FORMAT_BGR888:
> +		*depth = 24;
> +		*bpp = 24;
> +		break;
> +	case DRM_FORMAT_XRGB8888:
> +	case DRM_FORMAT_XBGR8888:
> +	case DRM_FORMAT_RGBX8888:
> +	case DRM_FORMAT_BGRX8888:
> +		*depth = 24;
> +		*bpp = 32;
> +		break;
> +	case DRM_FORMAT_XRGB2101010:
> +	case DRM_FORMAT_XBGR2101010:
> +	case DRM_FORMAT_RGBX1010102:
> +	case DRM_FORMAT_BGRX1010102:
> +	case DRM_FORMAT_ARGB2101010:
> +	case DRM_FORMAT_ABGR2101010:
> +	case DRM_FORMAT_RGBA1010102:
> +	case DRM_FORMAT_BGRA1010102:
> +		*depth = 30;
> +		*bpp = 32;
> +		break;
> +	case DRM_FORMAT_ARGB8888:
> +	case DRM_FORMAT_ABGR8888:
> +	case DRM_FORMAT_RGBA8888:
> +	case DRM_FORMAT_BGRA8888:
> +		*depth = 32;
> +		*bpp = 32;
> +		break;
> +	default:
> +		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> +			      drm_get_format_name(format));
> +		*depth = 0;
> +		*bpp = 0;
> +		break;
> +	}
> +}
> +EXPORT_SYMBOL(drm_fb_get_bpp_depth);
> +
> +/**
> + * drm_format_num_planes - get the number of planes for format
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The number of planes used by the specified pixel format.
> + */
> +int drm_format_num_planes(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV444:
> +	case DRM_FORMAT_YVU444:
> +		return 3;
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_NV24:
> +	case DRM_FORMAT_NV42:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_num_planes);
> +
> +/**
> + * drm_format_plane_cpp - determine the bytes per pixel value
> + * @format: pixel format (DRM_FORMAT_*)
> + * @plane: plane index
> + *
> + * Returns:
> + * The bytes per pixel value for the specified plane.
> + */
> +int drm_format_plane_cpp(uint32_t format, int plane)
> +{
> +	unsigned int depth;
> +	int bpp;
> +
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	switch (format) {
> +	case DRM_FORMAT_YUYV:
> +	case DRM_FORMAT_YVYU:
> +	case DRM_FORMAT_UYVY:
> +	case DRM_FORMAT_VYUY:
> +		return 2;
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_NV24:
> +	case DRM_FORMAT_NV42:
> +		return plane ? 2 : 1;
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV444:
> +	case DRM_FORMAT_YVU444:
> +		return 1;
> +	default:
> +		drm_fb_get_bpp_depth(format, &depth, &bpp);
> +		return bpp >> 3;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_plane_cpp);
> +
> +/**
> + * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The horizontal chroma subsampling factor for the
> + * specified pixel format.
> + */
> +int drm_format_horz_chroma_subsampling(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +		return 4;
> +	case DRM_FORMAT_YUYV:
> +	case DRM_FORMAT_YVYU:
> +	case DRM_FORMAT_UYVY:
> +	case DRM_FORMAT_VYUY:
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
> +
> +/**
> + * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The vertical chroma subsampling factor for the
> + * specified pixel format.
> + */
> +int drm_format_vert_chroma_subsampling(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +		return 4;
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
> +
> +/**
> + * drm_format_plane_width - width of the plane given the first plane
> + * @width: width of the first plane
> + * @format: pixel format
> + * @plane: plane index
> + *
> + * Returns:
> + * The width of @plane, given that the width of the first plane is @width.
> + */
> +int drm_format_plane_width(int width, uint32_t format, int plane)
> +{
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	if (plane == 0)
> +		return width;
> +
> +	return width / drm_format_horz_chroma_subsampling(format);
> +}
> +EXPORT_SYMBOL(drm_format_plane_width);
> +
> +/**
> + * drm_format_plane_height - height of the plane given the first plane
> + * @height: height of the first plane
> + * @format: pixel format
> + * @plane: plane index
> + *
> + * Returns:
> + * The height of @plane, given that the height of the first plane is @height.
> + */
> +int drm_format_plane_height(int height, uint32_t format, int plane)
> +{
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	if (plane == 0)
> +		return height;
> +
> +	return height / drm_format_vert_chroma_subsampling(format);
> +}
> +EXPORT_SYMBOL(drm_format_plane_height);
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 84f1a8eefbdb..c8879057084e 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -66,6 +66,7 @@
>  
>  #include <drm/drm_agpsupport.h>
>  #include <drm/drm_crtc.h>
> +#include <drm/drm_fourcc.h>
>  #include <drm/drm_global.h>
>  #include <drm/drm_hashtab.h>
>  #include <drm/drm_mem_util.h>
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index d1559cd04e3d..1b80c0268d8f 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -2540,15 +2540,6 @@ extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
>  extern int drm_mode_atomic_ioctl(struct drm_device *dev,
>  				 void *data, struct drm_file *file_priv);
>  
> -extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> -				 int *bpp);
> -extern int drm_format_num_planes(uint32_t format);
> -extern int drm_format_plane_cpp(uint32_t format, int plane);
> -extern int drm_format_horz_chroma_subsampling(uint32_t format);
> -extern int drm_format_vert_chroma_subsampling(uint32_t format);
> -extern int drm_format_plane_width(int width, uint32_t format, int plane);
> -extern int drm_format_plane_height(int height, uint32_t format, int plane);
> -extern const char *drm_get_format_name(uint32_t format);
>  extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
>  							      unsigned int supported_rotations);
>  extern unsigned int drm_rotation_simplify(unsigned int rotation,
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> new file mode 100644
> index 000000000000..7f90a396cf2b
> --- /dev/null
> +++ b/include/drm/drm_fourcc.h
> @@ -0,0 +1,37 @@
> +/*
> + * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +#ifndef __DRM_FOURCC_H__
> +#define __DRM_FOURCC_H__
> +
> +#include <linux/types.h>
> +#include <uapi/drm/drm_fourcc.h>
> +
> +void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
> +int drm_format_num_planes(uint32_t format);
> +int drm_format_plane_cpp(uint32_t format, int plane);
> +int drm_format_horz_chroma_subsampling(uint32_t format);
> +int drm_format_vert_chroma_subsampling(uint32_t format);
> +int drm_format_plane_width(int width, uint32_t format, int plane);
> +int drm_format_plane_height(int height, uint32_t format, int plane);
> +const char *drm_get_format_name(uint32_t format);
> +
> +#endif /* __DRM_FOURCC_H__ */
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/15] drm: Centralize format information
  2016-06-08 23:32 ` [PATCH v3 02/15] drm: Centralize format information Laurent Pinchart
@ 2016-06-09  8:52   ` Daniel Vetter
  2016-06-09 12:23     ` Ville Syrjälä
  0 siblings, 1 reply; 49+ messages in thread
From: Daniel Vetter @ 2016-06-09  8:52 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Daniel Vetter, Tomi Valkeinen, dri-devel

On Thu, Jun 09, 2016 at 02:32:06AM +0300, Laurent Pinchart wrote:
> Various pieces of information about DRM formats (number of planes, color
> depth, chroma subsampling, ...) are scattered across different helper
> functions in the DRM core. Callers of those functions often need to
> access more than a single parameter of the format, leading to
> inefficiencies due to multiple lookups.
> 
> Centralize all format information in a data structure and create a
> function to look up information based on the format 4CC.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_fourcc.h     | 19 ++++++++++
>  2 files changed, 103 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index 0645c85d5f95..47b9abd743be 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t format)
>  EXPORT_SYMBOL(drm_get_format_name);
>  
>  /**
> + * drm_format_info - query information for a given format
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The instance of struct drm_format_info that describes the pixel format, or
> + * NULL if the format is unsupported.
> + */
> +const struct drm_format_info *drm_format_info(u32 format)

Bikeshed on your pixel format description table. I think the approach I've
seen in gallium/mesa to describe pixel formats is a lot more generic, and
we might as well adopt it when we change. Idea is to have a block size
measure in pixels (both h and v), and then cpp is bytes_per_block. This is
essentially what you have with hsub and vsub already, except confusing
names, more ill-defined (since it only makes sense for yuv) and less
generic. A few examples:
	h_blocksize	v_blocksize	bytes_per_block (per-plane)
YUV410	4		4		{4, 1, 1}
YUV411	4		1		{4, 1, 1}

hsub = h_blocksize / bytes_per_block[U/V plane]
vsub = v_blocksize / bytes_per_block[U/V plane]

*_blocksize is in pixels

[not entirely sure on the precise data, but that's kinda the point.]

Ofc should maybe check that those helpers are only called on yuv planar
formats, too. This way we could also remove some of the comments in
drm_fourcc.h, or at least make the more clear. Another benefit is that
with this it's possible to write entirely generic size/stride checking
functions

Oh and if we go with this, some asciiart for what's meant (in sphinx/rst,
that will happen in 4.8) would be awesome.
-Daniel

> +{
> +	static const struct drm_format_info formats[] = { 
> +		{ .format = DRM_FORMAT_C8,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGB332,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGR233,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XRGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XBGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ARGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ABGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XRGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XBGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ARGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ABGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGB565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGR565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGB888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGR888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XRGB8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XBGR8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XRGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_XBGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ARGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ABGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ARGB8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_ABGR8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_RGBA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_BGRA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YUV410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
> +		{ .format = DRM_FORMAT_YVU410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
> +		{ .format = DRM_FORMAT_YUV411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YVU411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YUV420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
> +		{ .format = DRM_FORMAT_YVU420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
> +		{ .format = DRM_FORMAT_YUV422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YVU422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YUV444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YVU444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_NV12,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
> +		{ .format = DRM_FORMAT_NV21,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
> +		{ .format = DRM_FORMAT_NV16,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_NV61,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_NV24,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_NV42,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YUYV,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_YVYU,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_UYVY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_VYUY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> +		{ .format = DRM_FORMAT_AYUV,		.depth = 0,  .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> +	};
> +
> +	unsigned int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(formats); ++i) {
> +		if (formats[i].format == format)
> +			return &formats[i];
> +	}
> +
> +	return NULL;
> +}
> +EXPORT_SYMBOL(drm_format_info);
> +
> +/**
>   * drm_fb_get_bpp_depth - get the bpp/depth values for format
>   * @format: pixel format (DRM_FORMAT_*)
>   * @depth: storage for the depth value
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index 7f90a396cf2b..b077df507b51 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -25,6 +25,25 @@
>  #include <linux/types.h>
>  #include <uapi/drm/drm_fourcc.h>
>  
> +/**
> + * struct drm_format_info - information about a DRM format
> + * @format: 4CC format identifier (DRM_FORMAT_*)
> + * @depth: color depth (number of bits per pixel excluding padding bits)
> + * @num_planes: number of color planes (1 to 3)
> + * @cpp: number of bytes per pixel (per plane)
> + * @hsub: horizontal chroma subsampling factor
> + * @vsub: vertical chroma subsampling factor
> + */
> +struct drm_format_info {
> +	u32 format;
> +	u8 depth;
> +	u8 num_planes;
> +	u8 cpp[3];
> +	u8 hsub;
> +	u8 vsub;
> +};
> +
> +const struct drm_format_info *drm_format_info(u32 format);
>  void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
>  int drm_format_num_planes(uint32_t format);
>  int drm_format_plane_cpp(uint32_t format, int plane);
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 08/15] drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 ` [PATCH v3 08/15] drm: hdlcd: " Laurent Pinchart
@ 2016-06-09  9:01   ` Liviu Dudau
  2016-07-25 11:10     ` Liviu Dudau
  0 siblings, 1 reply; 49+ messages in thread
From: Liviu Dudau @ 2016-06-09  9:01 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Daniel Vetter, Tomi Valkeinen, dri-devel

On Thu, Jun 09, 2016 at 02:32:12AM +0300, Laurent Pinchart wrote:
> The driver needs the number of bytes per pixel, not the bpp and depth
> info meant for fbdev compatibility. Use the right API.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/gpu/drm/arm/hdlcd_crtc.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> Cc: Liviu Dudau <liviu.dudau@arm.com>

Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>

Thanks for the cleanup!

Best regards,
Liviu

> 
> diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
> index 0813c2f06931..b93a4ce01c50 100644
> --- a/drivers/gpu/drm/arm/hdlcd_crtc.c
> +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
> @@ -242,14 +242,12 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane,
>  {
>  	struct hdlcd_drm_private *hdlcd;
>  	struct drm_gem_cma_object *gem;
> -	unsigned int depth, bpp;
>  	u32 src_w, src_h, dest_w, dest_h;
>  	dma_addr_t scanout_start;
>  
>  	if (!plane->state->fb)
>  		return;
>  
> -	drm_fb_get_bpp_depth(plane->state->fb->pixel_format, &depth, &bpp);
>  	src_w = plane->state->src_w >> 16;
>  	src_h = plane->state->src_h >> 16;
>  	dest_w = plane->state->crtc_w;
> @@ -257,7 +255,8 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane,
>  	gem = drm_fb_cma_get_gem_obj(plane->state->fb, 0);
>  	scanout_start = gem->paddr + plane->state->fb->offsets[0] +
>  		plane->state->crtc_y * plane->state->fb->pitches[0] +
> -		plane->state->crtc_x * bpp / 8;
> +		plane->state->crtc_x *
> +		drm_format_plane_cpp(plane->state->fb->pixel_format, 0);
>  
>  	hdlcd = plane->dev->dev_private;
>  	hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, plane->state->fb->pitches[0]);
> -- 
> Regards,
> 
> Laurent Pinchart
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 07/15] drm: sti: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-09  7:52   ` Vincent ABRIOU
@ 2016-06-09  9:17     ` Laurent Pinchart
  2016-06-09 12:10       ` Vincent ABRIOU
  0 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-09  9:17 UTC (permalink / raw)
  To: Vincent ABRIOU; +Cc: dri-devel, Tomi Valkeinen, Daniel Vetter

Hi Vincent,

On Thursday 09 Jun 2016 09:52:05 Vincent ABRIOU wrote:
> On 06/09/2016 01:32 AM, Laurent Pinchart wrote:
> > The driver needs the number of bytes per pixel, not the bpp and depth
> > info meant for fbdev compatibility. Use the right API.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > 
> >   drivers/gpu/drm/sti/sti_gdp.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> > Cc: Vincent Abriou <vincent.abriou@st.com>
> > 
> > diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
> > index ff33c38da197..be7e80535083 100644
> > --- a/drivers/gpu/drm/sti/sti_gdp.c
> > +++ b/drivers/gpu/drm/sti/sti_gdp.c
> > @@ -733,7 +733,7 @@ static void sti_gdp_atomic_update(struct drm_plane
> > *drm_plane,> 
> >   	u32 dma_updated_top;
> >   	u32 dma_updated_btm;
> >   	int format;
> > -	unsigned int depth, bpp;
> > +	unsigned int bpp;
> >   	u32 ydo, xdo, yds, xds;
> >   	
> >   	if (!crtc || !fb)
> > @@ -772,9 +772,9 @@ static void sti_gdp_atomic_update(struct drm_plane
> > *drm_plane,
> >   			 (unsigned long)cma_obj->paddr);
> >   	
> >   	/* pixel memory location */
> > -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> > +	bpp = drm_format_plane_cpp(fb->pixel_format, 0);
> 
> Hi Laurent,
> 
> The patch is fine for me but what does "cpp" means in drm_format_plane_cpp?

As far as I know it stands for character per pixel. It's really unfortunate 
that bit and byte both start with the same letter.

> >   	top_field->gam_gdp_pml = (u32)cma_obj->paddr + fb->offsets[0];
> > -	top_field->gam_gdp_pml += src_x * (bpp >> 3);
> > +	top_field->gam_gdp_pml += src_x * bpp;
> >   	top_field->gam_gdp_pml += src_y * fb->pitches[0];
> >   	
> >   	/* output parameters (clamped / cropped) */

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 12/15] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-09  1:42   ` Michel Dänzer
@ 2016-06-09  9:18     ` Laurent Pinchart
  0 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-09  9:18 UTC (permalink / raw)
  To: Michel Dänzer
  Cc: Alex Deucher, Daniel Vetter, Tomi Valkeinen,
	Christian König, dri-devel

Hi Michel,

On Thursday 09 Jun 2016 10:42:54 Michel Dänzer wrote:
> On 09.06.2016 08:32, Laurent Pinchart wrote:
> > The driver needs the number of bytes per pixel, not the bpp and depth
> > info meant for fbdev compatibility. Use the right API.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > 
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c  | 10 +++++-----
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c |  3 ++-
> >  2 files changed, 7 insertions(+), 6 deletions(-)
> > 
> > Cc: Alex Deucher <alexander.deucher@amd.com>
> > Cc: "Christian König" <christian.koenig@amd.com>
> > 
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c index 919146780a15..306f626d3e80
> > 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
> > @@ -68,7 +68,7 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int
> > width, int bpp, bool tile> 
> >  	int aligned = width;
> >  	int pitch_mask = 0;
> > 
> > -	switch (bpp / 8) {
> > +	switch (bpp) {
> >  	case 1:
> >  		pitch_mask = 255;
> >  		break;
> > @@ -83,7 +83,7 @@ int amdgpu_align_pitch(struct amdgpu_device *adev, int
> > width, int bpp, bool tile> 
> >  	aligned += pitch_mask;
> >  	aligned &= ~pitch_mask;
> > 
> > -	return aligned;
> > +	return aligned * bpp;
> >  }
> >  
> >  static void amdgpufb_destroy_pinned_object(struct drm_gem_object *gobj)
> > @@ -112,13 +112,13 @@ static int amdgpufb_create_pinned_object(struct
> > amdgpu_fbdev *rfbdev,
> >  	int ret;
> >  	int aligned_size, size;
> >  	int height = mode_cmd->height;
> > -	u32 bpp, depth;
> > +	u32 bpp;
> > 
> > -	drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
> > +	bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);
> 
> I think renaming bpp (for "bits per pixel") to cpp (for "chars (bytes)
> per pixel") in these two functions would avoid confusion.
> 
> Same comment for the radeon patch.

Thanks for the review, I'll fix that in both drivers.

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v3.1 01/15] drm: Move format-related helpers to drm_fourcc.c
  2016-06-09  8:36   ` Daniel Vetter
@ 2016-06-09  9:54     ` Laurent Pinchart
  2016-06-09 10:03       ` Daniel Vetter
  0 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-09  9:54 UTC (permalink / raw)
  To: dri-devel; +Cc: Daniel Vetter, Tomi Valkeinen

The drm_crtc.c file is a mess, making the ABI documentation confusing
since all functions are in the same bag. Split the format-related
helpers to a new drm_fourcc.c file.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/DocBook/gpu.tmpl |   5 +
 drivers/gpu/drm/Makefile       |   2 +-
 drivers/gpu/drm/drm_crtc.c     | 289 -------------------------------------
 drivers/gpu/drm/drm_fourcc.c   | 320 +++++++++++++++++++++++++++++++++++++++++
 include/drm/drmP.h             |   1 +
 include/drm/drm_crtc.h         |   9 --
 include/drm/drm_fourcc.h       |  37 +++++
 7 files changed, 364 insertions(+), 299 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_fourcc.c
 create mode 100644 include/drm/drm_fourcc.h

Changes since v3:

- Moved the documentation to a new subsection of the modesetting chapter

diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index 7586bf75f62e..7043b270cf54 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -1018,6 +1018,11 @@ int max_width, max_height;</synopsis>
       </para>
     </sect2>
     <sect2>
+      <title>DRM Format Handling</title>
+!Iinclude/drm/drm_fourcc.h
+!Edrivers/gpu/drm/drm_fourcc.c
+    </sect2>
+    <sect2>
       <title>Dumb Buffer Objects</title>
       <para>
 	The KMS API doesn't standardize backing storage object creation and
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index be43afb08c69..aa24af35c068 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -8,7 +8,7 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
 		drm_lock.o drm_memory.o drm_drv.o drm_vm.o \
 		drm_scatter.o drm_pci.o \
 		drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
-		drm_crtc.o drm_modes.o drm_edid.o \
+		drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
 		drm_info.o drm_debugfs.o drm_encoder_slave.o \
 		drm_trace_points.o drm_global.o drm_prime.o \
 		drm_rect.o drm_vma_manager.o drm_flip_work.o \
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 0e3cc66aa8b7..e5369529af06 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -239,37 +239,6 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
 }
 EXPORT_SYMBOL(drm_get_subpixel_order_name);
 
-static char printable_char(int c)
-{
-	return isascii(c) && isprint(c) ? c : '?';
-}
-
-/**
- * drm_get_format_name - return a string for drm fourcc format
- * @format: format to compute name of
- *
- * Note that the buffer used by this function is globally shared and owned by
- * the function itself.
- *
- * FIXME: This isn't really multithreading safe.
- */
-const char *drm_get_format_name(uint32_t format)
-{
-	static char buf[32];
-
-	snprintf(buf, sizeof(buf),
-		 "%c%c%c%c %s-endian (0x%08x)",
-		 printable_char(format & 0xff),
-		 printable_char((format >> 8) & 0xff),
-		 printable_char((format >> 16) & 0xff),
-		 printable_char((format >> 24) & 0x7f),
-		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
-		 format);
-
-	return buf;
-}
-EXPORT_SYMBOL(drm_get_format_name);
-
 /*
  * Internal function to assign a slot in the object idr and optionally
  * register the object into the idr.
@@ -5544,264 +5513,6 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
 }
 
 /**
- * drm_fb_get_bpp_depth - get the bpp/depth values for format
- * @format: pixel format (DRM_FORMAT_*)
- * @depth: storage for the depth value
- * @bpp: storage for the bpp value
- *
- * This only supports RGB formats here for compat with code that doesn't use
- * pixel formats directly yet.
- */
-void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
-			  int *bpp)
-{
-	switch (format) {
-	case DRM_FORMAT_C8:
-	case DRM_FORMAT_RGB332:
-	case DRM_FORMAT_BGR233:
-		*depth = 8;
-		*bpp = 8;
-		break;
-	case DRM_FORMAT_XRGB1555:
-	case DRM_FORMAT_XBGR1555:
-	case DRM_FORMAT_RGBX5551:
-	case DRM_FORMAT_BGRX5551:
-	case DRM_FORMAT_ARGB1555:
-	case DRM_FORMAT_ABGR1555:
-	case DRM_FORMAT_RGBA5551:
-	case DRM_FORMAT_BGRA5551:
-		*depth = 15;
-		*bpp = 16;
-		break;
-	case DRM_FORMAT_RGB565:
-	case DRM_FORMAT_BGR565:
-		*depth = 16;
-		*bpp = 16;
-		break;
-	case DRM_FORMAT_RGB888:
-	case DRM_FORMAT_BGR888:
-		*depth = 24;
-		*bpp = 24;
-		break;
-	case DRM_FORMAT_XRGB8888:
-	case DRM_FORMAT_XBGR8888:
-	case DRM_FORMAT_RGBX8888:
-	case DRM_FORMAT_BGRX8888:
-		*depth = 24;
-		*bpp = 32;
-		break;
-	case DRM_FORMAT_XRGB2101010:
-	case DRM_FORMAT_XBGR2101010:
-	case DRM_FORMAT_RGBX1010102:
-	case DRM_FORMAT_BGRX1010102:
-	case DRM_FORMAT_ARGB2101010:
-	case DRM_FORMAT_ABGR2101010:
-	case DRM_FORMAT_RGBA1010102:
-	case DRM_FORMAT_BGRA1010102:
-		*depth = 30;
-		*bpp = 32;
-		break;
-	case DRM_FORMAT_ARGB8888:
-	case DRM_FORMAT_ABGR8888:
-	case DRM_FORMAT_RGBA8888:
-	case DRM_FORMAT_BGRA8888:
-		*depth = 32;
-		*bpp = 32;
-		break;
-	default:
-		DRM_DEBUG_KMS("unsupported pixel format %s\n",
-			      drm_get_format_name(format));
-		*depth = 0;
-		*bpp = 0;
-		break;
-	}
-}
-EXPORT_SYMBOL(drm_fb_get_bpp_depth);
-
-/**
- * drm_format_num_planes - get the number of planes for format
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The number of planes used by the specified pixel format.
- */
-int drm_format_num_planes(uint32_t format)
-{
-	switch (format) {
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV444:
-	case DRM_FORMAT_YVU444:
-		return 3;
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_NV24:
-	case DRM_FORMAT_NV42:
-		return 2;
-	default:
-		return 1;
-	}
-}
-EXPORT_SYMBOL(drm_format_num_planes);
-
-/**
- * drm_format_plane_cpp - determine the bytes per pixel value
- * @format: pixel format (DRM_FORMAT_*)
- * @plane: plane index
- *
- * Returns:
- * The bytes per pixel value for the specified plane.
- */
-int drm_format_plane_cpp(uint32_t format, int plane)
-{
-	unsigned int depth;
-	int bpp;
-
-	if (plane >= drm_format_num_planes(format))
-		return 0;
-
-	switch (format) {
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-		return 2;
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_NV24:
-	case DRM_FORMAT_NV42:
-		return plane ? 2 : 1;
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV444:
-	case DRM_FORMAT_YVU444:
-		return 1;
-	default:
-		drm_fb_get_bpp_depth(format, &depth, &bpp);
-		return bpp >> 3;
-	}
-}
-EXPORT_SYMBOL(drm_format_plane_cpp);
-
-/**
- * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The horizontal chroma subsampling factor for the
- * specified pixel format.
- */
-int drm_format_horz_chroma_subsampling(uint32_t format)
-{
-	switch (format) {
-	case DRM_FORMAT_YUV411:
-	case DRM_FORMAT_YVU411:
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-		return 4;
-	case DRM_FORMAT_YUYV:
-	case DRM_FORMAT_YVYU:
-	case DRM_FORMAT_UYVY:
-	case DRM_FORMAT_VYUY:
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-	case DRM_FORMAT_NV16:
-	case DRM_FORMAT_NV61:
-	case DRM_FORMAT_YUV422:
-	case DRM_FORMAT_YVU422:
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-		return 2;
-	default:
-		return 1;
-	}
-}
-EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
-
-/**
- * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
- * @format: pixel format (DRM_FORMAT_*)
- *
- * Returns:
- * The vertical chroma subsampling factor for the
- * specified pixel format.
- */
-int drm_format_vert_chroma_subsampling(uint32_t format)
-{
-	switch (format) {
-	case DRM_FORMAT_YUV410:
-	case DRM_FORMAT_YVU410:
-		return 4;
-	case DRM_FORMAT_YUV420:
-	case DRM_FORMAT_YVU420:
-	case DRM_FORMAT_NV12:
-	case DRM_FORMAT_NV21:
-		return 2;
-	default:
-		return 1;
-	}
-}
-EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
-
-/**
- * drm_format_plane_width - width of the plane given the first plane
- * @width: width of the first plane
- * @format: pixel format
- * @plane: plane index
- *
- * Returns:
- * The width of @plane, given that the width of the first plane is @width.
- */
-int drm_format_plane_width(int width, uint32_t format, int plane)
-{
-	if (plane >= drm_format_num_planes(format))
-		return 0;
-
-	if (plane == 0)
-		return width;
-
-	return width / drm_format_horz_chroma_subsampling(format);
-}
-EXPORT_SYMBOL(drm_format_plane_width);
-
-/**
- * drm_format_plane_height - height of the plane given the first plane
- * @height: height of the first plane
- * @format: pixel format
- * @plane: plane index
- *
- * Returns:
- * The height of @plane, given that the height of the first plane is @height.
- */
-int drm_format_plane_height(int height, uint32_t format, int plane)
-{
-	if (plane >= drm_format_num_planes(format))
-		return 0;
-
-	if (plane == 0)
-		return height;
-
-	return height / drm_format_vert_chroma_subsampling(format);
-}
-EXPORT_SYMBOL(drm_format_plane_height);
-
-/**
  * drm_rotation_simplify() - Try to simplify the rotation
  * @rotation: Rotation to be simplified
  * @supported_rotations: Supported rotations
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
new file mode 100644
index 000000000000..0645c85d5f95
--- /dev/null
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -0,0 +1,320 @@
+/*
+ * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * DRM core format related functions
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include <linux/bug.h>
+#include <linux/ctype.h>
+#include <linux/export.h>
+#include <linux/kernel.h>
+
+#include <drm/drmP.h>
+#include <drm/drm_fourcc.h>
+
+static char printable_char(int c)
+{
+	return isascii(c) && isprint(c) ? c : '?';
+}
+
+/**
+ * drm_get_format_name - return a string for drm fourcc format
+ * @format: format to compute name of
+ *
+ * Note that the buffer used by this function is globally shared and owned by
+ * the function itself.
+ *
+ * FIXME: This isn't really multithreading safe.
+ */
+const char *drm_get_format_name(uint32_t format)
+{
+	static char buf[32];
+
+	snprintf(buf, sizeof(buf),
+		 "%c%c%c%c %s-endian (0x%08x)",
+		 printable_char(format & 0xff),
+		 printable_char((format >> 8) & 0xff),
+		 printable_char((format >> 16) & 0xff),
+		 printable_char((format >> 24) & 0x7f),
+		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
+		 format);
+
+	return buf;
+}
+EXPORT_SYMBOL(drm_get_format_name);
+
+/**
+ * drm_fb_get_bpp_depth - get the bpp/depth values for format
+ * @format: pixel format (DRM_FORMAT_*)
+ * @depth: storage for the depth value
+ * @bpp: storage for the bpp value
+ *
+ * This only supports RGB formats here for compat with code that doesn't use
+ * pixel formats directly yet.
+ */
+void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
+			  int *bpp)
+{
+	switch (format) {
+	case DRM_FORMAT_C8:
+	case DRM_FORMAT_RGB332:
+	case DRM_FORMAT_BGR233:
+		*depth = 8;
+		*bpp = 8;
+		break;
+	case DRM_FORMAT_XRGB1555:
+	case DRM_FORMAT_XBGR1555:
+	case DRM_FORMAT_RGBX5551:
+	case DRM_FORMAT_BGRX5551:
+	case DRM_FORMAT_ARGB1555:
+	case DRM_FORMAT_ABGR1555:
+	case DRM_FORMAT_RGBA5551:
+	case DRM_FORMAT_BGRA5551:
+		*depth = 15;
+		*bpp = 16;
+		break;
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+		*depth = 16;
+		*bpp = 16;
+		break;
+	case DRM_FORMAT_RGB888:
+	case DRM_FORMAT_BGR888:
+		*depth = 24;
+		*bpp = 24;
+		break;
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_RGBX8888:
+	case DRM_FORMAT_BGRX8888:
+		*depth = 24;
+		*bpp = 32;
+		break;
+	case DRM_FORMAT_XRGB2101010:
+	case DRM_FORMAT_XBGR2101010:
+	case DRM_FORMAT_RGBX1010102:
+	case DRM_FORMAT_BGRX1010102:
+	case DRM_FORMAT_ARGB2101010:
+	case DRM_FORMAT_ABGR2101010:
+	case DRM_FORMAT_RGBA1010102:
+	case DRM_FORMAT_BGRA1010102:
+		*depth = 30;
+		*bpp = 32;
+		break;
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_ABGR8888:
+	case DRM_FORMAT_RGBA8888:
+	case DRM_FORMAT_BGRA8888:
+		*depth = 32;
+		*bpp = 32;
+		break;
+	default:
+		DRM_DEBUG_KMS("unsupported pixel format %s\n",
+			      drm_get_format_name(format));
+		*depth = 0;
+		*bpp = 0;
+		break;
+	}
+}
+EXPORT_SYMBOL(drm_fb_get_bpp_depth);
+
+/**
+ * drm_format_num_planes - get the number of planes for format
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The number of planes used by the specified pixel format.
+ */
+int drm_format_num_planes(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+	case DRM_FORMAT_YUV411:
+	case DRM_FORMAT_YVU411:
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+	case DRM_FORMAT_YUV422:
+	case DRM_FORMAT_YVU422:
+	case DRM_FORMAT_YUV444:
+	case DRM_FORMAT_YVU444:
+		return 3;
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+	case DRM_FORMAT_NV24:
+	case DRM_FORMAT_NV42:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_num_planes);
+
+/**
+ * drm_format_plane_cpp - determine the bytes per pixel value
+ * @format: pixel format (DRM_FORMAT_*)
+ * @plane: plane index
+ *
+ * Returns:
+ * The bytes per pixel value for the specified plane.
+ */
+int drm_format_plane_cpp(uint32_t format, int plane)
+{
+	unsigned int depth;
+	int bpp;
+
+	if (plane >= drm_format_num_planes(format))
+		return 0;
+
+	switch (format) {
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+		return 2;
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+	case DRM_FORMAT_NV24:
+	case DRM_FORMAT_NV42:
+		return plane ? 2 : 1;
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+	case DRM_FORMAT_YUV411:
+	case DRM_FORMAT_YVU411:
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+	case DRM_FORMAT_YUV422:
+	case DRM_FORMAT_YVU422:
+	case DRM_FORMAT_YUV444:
+	case DRM_FORMAT_YVU444:
+		return 1;
+	default:
+		drm_fb_get_bpp_depth(format, &depth, &bpp);
+		return bpp >> 3;
+	}
+}
+EXPORT_SYMBOL(drm_format_plane_cpp);
+
+/**
+ * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The horizontal chroma subsampling factor for the
+ * specified pixel format.
+ */
+int drm_format_horz_chroma_subsampling(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_YUV411:
+	case DRM_FORMAT_YVU411:
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+		return 4;
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+	case DRM_FORMAT_YUV422:
+	case DRM_FORMAT_YVU422:
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
+
+/**
+ * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
+ * @format: pixel format (DRM_FORMAT_*)
+ *
+ * Returns:
+ * The vertical chroma subsampling factor for the
+ * specified pixel format.
+ */
+int drm_format_vert_chroma_subsampling(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_YUV410:
+	case DRM_FORMAT_YVU410:
+		return 4;
+	case DRM_FORMAT_YUV420:
+	case DRM_FORMAT_YVU420:
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+		return 2;
+	default:
+		return 1;
+	}
+}
+EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
+
+/**
+ * drm_format_plane_width - width of the plane given the first plane
+ * @width: width of the first plane
+ * @format: pixel format
+ * @plane: plane index
+ *
+ * Returns:
+ * The width of @plane, given that the width of the first plane is @width.
+ */
+int drm_format_plane_width(int width, uint32_t format, int plane)
+{
+	if (plane >= drm_format_num_planes(format))
+		return 0;
+
+	if (plane == 0)
+		return width;
+
+	return width / drm_format_horz_chroma_subsampling(format);
+}
+EXPORT_SYMBOL(drm_format_plane_width);
+
+/**
+ * drm_format_plane_height - height of the plane given the first plane
+ * @height: height of the first plane
+ * @format: pixel format
+ * @plane: plane index
+ *
+ * Returns:
+ * The height of @plane, given that the height of the first plane is @height.
+ */
+int drm_format_plane_height(int height, uint32_t format, int plane)
+{
+	if (plane >= drm_format_num_planes(format))
+		return 0;
+
+	if (plane == 0)
+		return height;
+
+	return height / drm_format_vert_chroma_subsampling(format);
+}
+EXPORT_SYMBOL(drm_format_plane_height);
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 84f1a8eefbdb..c8879057084e 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -66,6 +66,7 @@
 
 #include <drm/drm_agpsupport.h>
 #include <drm/drm_crtc.h>
+#include <drm/drm_fourcc.h>
 #include <drm/drm_global.h>
 #include <drm/drm_hashtab.h>
 #include <drm/drm_mem_util.h>
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index d1559cd04e3d..1b80c0268d8f 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -2540,15 +2540,6 @@ extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
 extern int drm_mode_atomic_ioctl(struct drm_device *dev,
 				 void *data, struct drm_file *file_priv);
 
-extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
-				 int *bpp);
-extern int drm_format_num_planes(uint32_t format);
-extern int drm_format_plane_cpp(uint32_t format, int plane);
-extern int drm_format_horz_chroma_subsampling(uint32_t format);
-extern int drm_format_vert_chroma_subsampling(uint32_t format);
-extern int drm_format_plane_width(int width, uint32_t format, int plane);
-extern int drm_format_plane_height(int height, uint32_t format, int plane);
-extern const char *drm_get_format_name(uint32_t format);
 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
 							      unsigned int supported_rotations);
 extern unsigned int drm_rotation_simplify(unsigned int rotation,
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
new file mode 100644
index 000000000000..7f90a396cf2b
--- /dev/null
+++ b/include/drm/drm_fourcc.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+#ifndef __DRM_FOURCC_H__
+#define __DRM_FOURCC_H__
+
+#include <linux/types.h>
+#include <uapi/drm/drm_fourcc.h>
+
+void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
+int drm_format_num_planes(uint32_t format);
+int drm_format_plane_cpp(uint32_t format, int plane);
+int drm_format_horz_chroma_subsampling(uint32_t format);
+int drm_format_vert_chroma_subsampling(uint32_t format);
+int drm_format_plane_width(int width, uint32_t format, int plane);
+int drm_format_plane_height(int height, uint32_t format, int plane);
+const char *drm_get_format_name(uint32_t format);
+
+#endif /* __DRM_FOURCC_H__ */
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH v3.1 01/15] drm: Move format-related helpers to drm_fourcc.c
  2016-06-09  9:54     ` [PATCH v3.1 " Laurent Pinchart
@ 2016-06-09 10:03       ` Daniel Vetter
  0 siblings, 0 replies; 49+ messages in thread
From: Daniel Vetter @ 2016-06-09 10:03 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Daniel Vetter, Tomi Valkeinen, dri-devel

On Thu, Jun 09, 2016 at 12:54:08PM +0300, Laurent Pinchart wrote:
> The drm_crtc.c file is a mess, making the ABI documentation confusing
> since all functions are in the same bag. Split the format-related
> helpers to a new drm_fourcc.c file.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Applied to drm-misc, thanks.

> ---
>  Documentation/DocBook/gpu.tmpl |   5 +
>  drivers/gpu/drm/Makefile       |   2 +-
>  drivers/gpu/drm/drm_crtc.c     | 289 -------------------------------------
>  drivers/gpu/drm/drm_fourcc.c   | 320 +++++++++++++++++++++++++++++++++++++++++
>  include/drm/drmP.h             |   1 +
>  include/drm/drm_crtc.h         |   9 --
>  include/drm/drm_fourcc.h       |  37 +++++
>  7 files changed, 364 insertions(+), 299 deletions(-)
>  create mode 100644 drivers/gpu/drm/drm_fourcc.c
>  create mode 100644 include/drm/drm_fourcc.h
> 
> Changes since v3:
> 
> - Moved the documentation to a new subsection of the modesetting chapter

Bikeshed: I know it's against kernel standards, but I like to include the
per-patch changelog with the merged commit. I think that's a better
tradeoff on the clean history vs. full history tradeoff scale. Some links
for why and all that:

http://jamey.thesharps.us/2016/05/perspectives-on-commit-history.html

with links to more in there. tl;dr; Also including the messy way needed to
get to a clean final patch is valuable. Same reasons why we add links to
bugzilla and other auxiliary information.

Cheers, Daniel
> 
> diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
> index 7586bf75f62e..7043b270cf54 100644
> --- a/Documentation/DocBook/gpu.tmpl
> +++ b/Documentation/DocBook/gpu.tmpl
> @@ -1018,6 +1018,11 @@ int max_width, max_height;</synopsis>
>        </para>
>      </sect2>
>      <sect2>
> +      <title>DRM Format Handling</title>
> +!Iinclude/drm/drm_fourcc.h
> +!Edrivers/gpu/drm/drm_fourcc.c
> +    </sect2>
> +    <sect2>
>        <title>Dumb Buffer Objects</title>
>        <para>
>  	The KMS API doesn't standardize backing storage object creation and
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index be43afb08c69..aa24af35c068 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -8,7 +8,7 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
>  		drm_lock.o drm_memory.o drm_drv.o drm_vm.o \
>  		drm_scatter.o drm_pci.o \
>  		drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
> -		drm_crtc.o drm_modes.o drm_edid.o \
> +		drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
>  		drm_info.o drm_debugfs.o drm_encoder_slave.o \
>  		drm_trace_points.o drm_global.o drm_prime.o \
>  		drm_rect.o drm_vma_manager.o drm_flip_work.o \
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 0e3cc66aa8b7..e5369529af06 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -239,37 +239,6 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
>  }
>  EXPORT_SYMBOL(drm_get_subpixel_order_name);
>  
> -static char printable_char(int c)
> -{
> -	return isascii(c) && isprint(c) ? c : '?';
> -}
> -
> -/**
> - * drm_get_format_name - return a string for drm fourcc format
> - * @format: format to compute name of
> - *
> - * Note that the buffer used by this function is globally shared and owned by
> - * the function itself.
> - *
> - * FIXME: This isn't really multithreading safe.
> - */
> -const char *drm_get_format_name(uint32_t format)
> -{
> -	static char buf[32];
> -
> -	snprintf(buf, sizeof(buf),
> -		 "%c%c%c%c %s-endian (0x%08x)",
> -		 printable_char(format & 0xff),
> -		 printable_char((format >> 8) & 0xff),
> -		 printable_char((format >> 16) & 0xff),
> -		 printable_char((format >> 24) & 0x7f),
> -		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
> -		 format);
> -
> -	return buf;
> -}
> -EXPORT_SYMBOL(drm_get_format_name);
> -
>  /*
>   * Internal function to assign a slot in the object idr and optionally
>   * register the object into the idr.
> @@ -5544,264 +5513,6 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
>  }
>  
>  /**
> - * drm_fb_get_bpp_depth - get the bpp/depth values for format
> - * @format: pixel format (DRM_FORMAT_*)
> - * @depth: storage for the depth value
> - * @bpp: storage for the bpp value
> - *
> - * This only supports RGB formats here for compat with code that doesn't use
> - * pixel formats directly yet.
> - */
> -void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> -			  int *bpp)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_C8:
> -	case DRM_FORMAT_RGB332:
> -	case DRM_FORMAT_BGR233:
> -		*depth = 8;
> -		*bpp = 8;
> -		break;
> -	case DRM_FORMAT_XRGB1555:
> -	case DRM_FORMAT_XBGR1555:
> -	case DRM_FORMAT_RGBX5551:
> -	case DRM_FORMAT_BGRX5551:
> -	case DRM_FORMAT_ARGB1555:
> -	case DRM_FORMAT_ABGR1555:
> -	case DRM_FORMAT_RGBA5551:
> -	case DRM_FORMAT_BGRA5551:
> -		*depth = 15;
> -		*bpp = 16;
> -		break;
> -	case DRM_FORMAT_RGB565:
> -	case DRM_FORMAT_BGR565:
> -		*depth = 16;
> -		*bpp = 16;
> -		break;
> -	case DRM_FORMAT_RGB888:
> -	case DRM_FORMAT_BGR888:
> -		*depth = 24;
> -		*bpp = 24;
> -		break;
> -	case DRM_FORMAT_XRGB8888:
> -	case DRM_FORMAT_XBGR8888:
> -	case DRM_FORMAT_RGBX8888:
> -	case DRM_FORMAT_BGRX8888:
> -		*depth = 24;
> -		*bpp = 32;
> -		break;
> -	case DRM_FORMAT_XRGB2101010:
> -	case DRM_FORMAT_XBGR2101010:
> -	case DRM_FORMAT_RGBX1010102:
> -	case DRM_FORMAT_BGRX1010102:
> -	case DRM_FORMAT_ARGB2101010:
> -	case DRM_FORMAT_ABGR2101010:
> -	case DRM_FORMAT_RGBA1010102:
> -	case DRM_FORMAT_BGRA1010102:
> -		*depth = 30;
> -		*bpp = 32;
> -		break;
> -	case DRM_FORMAT_ARGB8888:
> -	case DRM_FORMAT_ABGR8888:
> -	case DRM_FORMAT_RGBA8888:
> -	case DRM_FORMAT_BGRA8888:
> -		*depth = 32;
> -		*bpp = 32;
> -		break;
> -	default:
> -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> -			      drm_get_format_name(format));
> -		*depth = 0;
> -		*bpp = 0;
> -		break;
> -	}
> -}
> -EXPORT_SYMBOL(drm_fb_get_bpp_depth);
> -
> -/**
> - * drm_format_num_planes - get the number of planes for format
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The number of planes used by the specified pixel format.
> - */
> -int drm_format_num_planes(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV444:
> -	case DRM_FORMAT_YVU444:
> -		return 3;
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_NV24:
> -	case DRM_FORMAT_NV42:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_num_planes);
> -
> -/**
> - * drm_format_plane_cpp - determine the bytes per pixel value
> - * @format: pixel format (DRM_FORMAT_*)
> - * @plane: plane index
> - *
> - * Returns:
> - * The bytes per pixel value for the specified plane.
> - */
> -int drm_format_plane_cpp(uint32_t format, int plane)
> -{
> -	unsigned int depth;
> -	int bpp;
> -
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	switch (format) {
> -	case DRM_FORMAT_YUYV:
> -	case DRM_FORMAT_YVYU:
> -	case DRM_FORMAT_UYVY:
> -	case DRM_FORMAT_VYUY:
> -		return 2;
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_NV24:
> -	case DRM_FORMAT_NV42:
> -		return plane ? 2 : 1;
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV444:
> -	case DRM_FORMAT_YVU444:
> -		return 1;
> -	default:
> -		drm_fb_get_bpp_depth(format, &depth, &bpp);
> -		return bpp >> 3;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_plane_cpp);
> -
> -/**
> - * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The horizontal chroma subsampling factor for the
> - * specified pixel format.
> - */
> -int drm_format_horz_chroma_subsampling(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -		return 4;
> -	case DRM_FORMAT_YUYV:
> -	case DRM_FORMAT_YVYU:
> -	case DRM_FORMAT_UYVY:
> -	case DRM_FORMAT_VYUY:
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
> -
> -/**
> - * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The vertical chroma subsampling factor for the
> - * specified pixel format.
> - */
> -int drm_format_vert_chroma_subsampling(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -		return 4;
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
> -
> -/**
> - * drm_format_plane_width - width of the plane given the first plane
> - * @width: width of the first plane
> - * @format: pixel format
> - * @plane: plane index
> - *
> - * Returns:
> - * The width of @plane, given that the width of the first plane is @width.
> - */
> -int drm_format_plane_width(int width, uint32_t format, int plane)
> -{
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	if (plane == 0)
> -		return width;
> -
> -	return width / drm_format_horz_chroma_subsampling(format);
> -}
> -EXPORT_SYMBOL(drm_format_plane_width);
> -
> -/**
> - * drm_format_plane_height - height of the plane given the first plane
> - * @height: height of the first plane
> - * @format: pixel format
> - * @plane: plane index
> - *
> - * Returns:
> - * The height of @plane, given that the height of the first plane is @height.
> - */
> -int drm_format_plane_height(int height, uint32_t format, int plane)
> -{
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	if (plane == 0)
> -		return height;
> -
> -	return height / drm_format_vert_chroma_subsampling(format);
> -}
> -EXPORT_SYMBOL(drm_format_plane_height);
> -
> -/**
>   * drm_rotation_simplify() - Try to simplify the rotation
>   * @rotation: Rotation to be simplified
>   * @supported_rotations: Supported rotations
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> new file mode 100644
> index 000000000000..0645c85d5f95
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -0,0 +1,320 @@
> +/*
> + * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + *
> + * DRM core format related functions
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#include <linux/bug.h>
> +#include <linux/ctype.h>
> +#include <linux/export.h>
> +#include <linux/kernel.h>
> +
> +#include <drm/drmP.h>
> +#include <drm/drm_fourcc.h>
> +
> +static char printable_char(int c)
> +{
> +	return isascii(c) && isprint(c) ? c : '?';
> +}
> +
> +/**
> + * drm_get_format_name - return a string for drm fourcc format
> + * @format: format to compute name of
> + *
> + * Note that the buffer used by this function is globally shared and owned by
> + * the function itself.
> + *
> + * FIXME: This isn't really multithreading safe.
> + */
> +const char *drm_get_format_name(uint32_t format)
> +{
> +	static char buf[32];
> +
> +	snprintf(buf, sizeof(buf),
> +		 "%c%c%c%c %s-endian (0x%08x)",
> +		 printable_char(format & 0xff),
> +		 printable_char((format >> 8) & 0xff),
> +		 printable_char((format >> 16) & 0xff),
> +		 printable_char((format >> 24) & 0x7f),
> +		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
> +		 format);
> +
> +	return buf;
> +}
> +EXPORT_SYMBOL(drm_get_format_name);
> +
> +/**
> + * drm_fb_get_bpp_depth - get the bpp/depth values for format
> + * @format: pixel format (DRM_FORMAT_*)
> + * @depth: storage for the depth value
> + * @bpp: storage for the bpp value
> + *
> + * This only supports RGB formats here for compat with code that doesn't use
> + * pixel formats directly yet.
> + */
> +void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> +			  int *bpp)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_C8:
> +	case DRM_FORMAT_RGB332:
> +	case DRM_FORMAT_BGR233:
> +		*depth = 8;
> +		*bpp = 8;
> +		break;
> +	case DRM_FORMAT_XRGB1555:
> +	case DRM_FORMAT_XBGR1555:
> +	case DRM_FORMAT_RGBX5551:
> +	case DRM_FORMAT_BGRX5551:
> +	case DRM_FORMAT_ARGB1555:
> +	case DRM_FORMAT_ABGR1555:
> +	case DRM_FORMAT_RGBA5551:
> +	case DRM_FORMAT_BGRA5551:
> +		*depth = 15;
> +		*bpp = 16;
> +		break;
> +	case DRM_FORMAT_RGB565:
> +	case DRM_FORMAT_BGR565:
> +		*depth = 16;
> +		*bpp = 16;
> +		break;
> +	case DRM_FORMAT_RGB888:
> +	case DRM_FORMAT_BGR888:
> +		*depth = 24;
> +		*bpp = 24;
> +		break;
> +	case DRM_FORMAT_XRGB8888:
> +	case DRM_FORMAT_XBGR8888:
> +	case DRM_FORMAT_RGBX8888:
> +	case DRM_FORMAT_BGRX8888:
> +		*depth = 24;
> +		*bpp = 32;
> +		break;
> +	case DRM_FORMAT_XRGB2101010:
> +	case DRM_FORMAT_XBGR2101010:
> +	case DRM_FORMAT_RGBX1010102:
> +	case DRM_FORMAT_BGRX1010102:
> +	case DRM_FORMAT_ARGB2101010:
> +	case DRM_FORMAT_ABGR2101010:
> +	case DRM_FORMAT_RGBA1010102:
> +	case DRM_FORMAT_BGRA1010102:
> +		*depth = 30;
> +		*bpp = 32;
> +		break;
> +	case DRM_FORMAT_ARGB8888:
> +	case DRM_FORMAT_ABGR8888:
> +	case DRM_FORMAT_RGBA8888:
> +	case DRM_FORMAT_BGRA8888:
> +		*depth = 32;
> +		*bpp = 32;
> +		break;
> +	default:
> +		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> +			      drm_get_format_name(format));
> +		*depth = 0;
> +		*bpp = 0;
> +		break;
> +	}
> +}
> +EXPORT_SYMBOL(drm_fb_get_bpp_depth);
> +
> +/**
> + * drm_format_num_planes - get the number of planes for format
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The number of planes used by the specified pixel format.
> + */
> +int drm_format_num_planes(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV444:
> +	case DRM_FORMAT_YVU444:
> +		return 3;
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_NV24:
> +	case DRM_FORMAT_NV42:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_num_planes);
> +
> +/**
> + * drm_format_plane_cpp - determine the bytes per pixel value
> + * @format: pixel format (DRM_FORMAT_*)
> + * @plane: plane index
> + *
> + * Returns:
> + * The bytes per pixel value for the specified plane.
> + */
> +int drm_format_plane_cpp(uint32_t format, int plane)
> +{
> +	unsigned int depth;
> +	int bpp;
> +
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	switch (format) {
> +	case DRM_FORMAT_YUYV:
> +	case DRM_FORMAT_YVYU:
> +	case DRM_FORMAT_UYVY:
> +	case DRM_FORMAT_VYUY:
> +		return 2;
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_NV24:
> +	case DRM_FORMAT_NV42:
> +		return plane ? 2 : 1;
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV444:
> +	case DRM_FORMAT_YVU444:
> +		return 1;
> +	default:
> +		drm_fb_get_bpp_depth(format, &depth, &bpp);
> +		return bpp >> 3;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_plane_cpp);
> +
> +/**
> + * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The horizontal chroma subsampling factor for the
> + * specified pixel format.
> + */
> +int drm_format_horz_chroma_subsampling(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +		return 4;
> +	case DRM_FORMAT_YUYV:
> +	case DRM_FORMAT_YVYU:
> +	case DRM_FORMAT_UYVY:
> +	case DRM_FORMAT_VYUY:
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
> +
> +/**
> + * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The vertical chroma subsampling factor for the
> + * specified pixel format.
> + */
> +int drm_format_vert_chroma_subsampling(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +		return 4;
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
> +
> +/**
> + * drm_format_plane_width - width of the plane given the first plane
> + * @width: width of the first plane
> + * @format: pixel format
> + * @plane: plane index
> + *
> + * Returns:
> + * The width of @plane, given that the width of the first plane is @width.
> + */
> +int drm_format_plane_width(int width, uint32_t format, int plane)
> +{
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	if (plane == 0)
> +		return width;
> +
> +	return width / drm_format_horz_chroma_subsampling(format);
> +}
> +EXPORT_SYMBOL(drm_format_plane_width);
> +
> +/**
> + * drm_format_plane_height - height of the plane given the first plane
> + * @height: height of the first plane
> + * @format: pixel format
> + * @plane: plane index
> + *
> + * Returns:
> + * The height of @plane, given that the height of the first plane is @height.
> + */
> +int drm_format_plane_height(int height, uint32_t format, int plane)
> +{
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	if (plane == 0)
> +		return height;
> +
> +	return height / drm_format_vert_chroma_subsampling(format);
> +}
> +EXPORT_SYMBOL(drm_format_plane_height);
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 84f1a8eefbdb..c8879057084e 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -66,6 +66,7 @@
>  
>  #include <drm/drm_agpsupport.h>
>  #include <drm/drm_crtc.h>
> +#include <drm/drm_fourcc.h>
>  #include <drm/drm_global.h>
>  #include <drm/drm_hashtab.h>
>  #include <drm/drm_mem_util.h>
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index d1559cd04e3d..1b80c0268d8f 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -2540,15 +2540,6 @@ extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
>  extern int drm_mode_atomic_ioctl(struct drm_device *dev,
>  				 void *data, struct drm_file *file_priv);
>  
> -extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> -				 int *bpp);
> -extern int drm_format_num_planes(uint32_t format);
> -extern int drm_format_plane_cpp(uint32_t format, int plane);
> -extern int drm_format_horz_chroma_subsampling(uint32_t format);
> -extern int drm_format_vert_chroma_subsampling(uint32_t format);
> -extern int drm_format_plane_width(int width, uint32_t format, int plane);
> -extern int drm_format_plane_height(int height, uint32_t format, int plane);
> -extern const char *drm_get_format_name(uint32_t format);
>  extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
>  							      unsigned int supported_rotations);
>  extern unsigned int drm_rotation_simplify(unsigned int rotation,
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> new file mode 100644
> index 000000000000..7f90a396cf2b
> --- /dev/null
> +++ b/include/drm/drm_fourcc.h
> @@ -0,0 +1,37 @@
> +/*
> + * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +#ifndef __DRM_FOURCC_H__
> +#define __DRM_FOURCC_H__
> +
> +#include <linux/types.h>
> +#include <uapi/drm/drm_fourcc.h>
> +
> +void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
> +int drm_format_num_planes(uint32_t format);
> +int drm_format_plane_cpp(uint32_t format, int plane);
> +int drm_format_horz_chroma_subsampling(uint32_t format);
> +int drm_format_vert_chroma_subsampling(uint32_t format);
> +int drm_format_plane_width(int width, uint32_t format, int plane);
> +int drm_format_plane_height(int height, uint32_t format, int plane);
> +const char *drm_get_format_name(uint32_t format);
> +
> +#endif /* __DRM_FOURCC_H__ */
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 07/15] drm: sti: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-09  9:17     ` Laurent Pinchart
@ 2016-06-09 12:10       ` Vincent ABRIOU
  0 siblings, 0 replies; 49+ messages in thread
From: Vincent ABRIOU @ 2016-06-09 12:10 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: dri-devel, Tomi Valkeinen, Daniel Vetter

Hi Laurent,

On 06/09/2016 11:17 AM, Laurent Pinchart wrote:
> Hi Vincent,
>
> On Thursday 09 Jun 2016 09:52:05 Vincent ABRIOU wrote:
>> On 06/09/2016 01:32 AM, Laurent Pinchart wrote:
>>> The driver needs the number of bytes per pixel, not the bpp and depth
>>> info meant for fbdev compatibility. Use the right API.
>>>
>>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>>> ---
>>>
>>>    drivers/gpu/drm/sti/sti_gdp.c | 6 +++---
>>>    1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> Cc: Benjamin Gaignard <benjamin.gaignard@linaro.org>
>>> Cc: Vincent Abriou <vincent.abriou@st.com>
>>>
>>> diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
>>> index ff33c38da197..be7e80535083 100644
>>> --- a/drivers/gpu/drm/sti/sti_gdp.c
>>> +++ b/drivers/gpu/drm/sti/sti_gdp.c
>>> @@ -733,7 +733,7 @@ static void sti_gdp_atomic_update(struct drm_plane
>>> *drm_plane,>
>>>    	u32 dma_updated_top;
>>>    	u32 dma_updated_btm;
>>>    	int format;
>>> -	unsigned int depth, bpp;
>>> +	unsigned int bpp;
>>>    	u32 ydo, xdo, yds, xds;
>>>    	
>>>    	if (!crtc || !fb)
>>> @@ -772,9 +772,9 @@ static void sti_gdp_atomic_update(struct drm_plane
>>> *drm_plane,
>>>    			 (unsigned long)cma_obj->paddr);
>>>    	
>>>    	/* pixel memory location */
>>> -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
>>> +	bpp = drm_format_plane_cpp(fb->pixel_format, 0);
>>
>> Hi Laurent,
>>
>> The patch is fine for me but what does "cpp" means in drm_format_plane_cpp?
>
> As far as I know it stands for character per pixel. It's really unfortunate
> that bit and byte both start with the same letter.
>

Thanks

Acked-by: Vincent Abriou <vincent.abriou@st.com>

>>>    	top_field->gam_gdp_pml = (u32)cma_obj->paddr + fb->offsets[0];
>>> -	top_field->gam_gdp_pml += src_x * (bpp >> 3);
>>> +	top_field->gam_gdp_pml += src_x * bpp;
>>>    	top_field->gam_gdp_pml += src_y * fb->pitches[0];
>>>    	
>>>    	/* output parameters (clamped / cropped) */
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/15] drm: Centralize format information
  2016-06-09  8:52   ` Daniel Vetter
@ 2016-06-09 12:23     ` Ville Syrjälä
  2016-06-09 12:40       ` Daniel Vetter
  0 siblings, 1 reply; 49+ messages in thread
From: Ville Syrjälä @ 2016-06-09 12:23 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Daniel Vetter, Tomi Valkeinen, Laurent Pinchart, dri-devel

On Thu, Jun 09, 2016 at 10:52:23AM +0200, Daniel Vetter wrote:
> On Thu, Jun 09, 2016 at 02:32:06AM +0300, Laurent Pinchart wrote:
> > Various pieces of information about DRM formats (number of planes, color
> > depth, chroma subsampling, ...) are scattered across different helper
> > functions in the DRM core. Callers of those functions often need to
> > access more than a single parameter of the format, leading to
> > inefficiencies due to multiple lookups.
> > 
> > Centralize all format information in a data structure and create a
> > function to look up information based on the format 4CC.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
> >  include/drm/drm_fourcc.h     | 19 ++++++++++
> >  2 files changed, 103 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> > index 0645c85d5f95..47b9abd743be 100644
> > --- a/drivers/gpu/drm/drm_fourcc.c
> > +++ b/drivers/gpu/drm/drm_fourcc.c
> > @@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t format)
> >  EXPORT_SYMBOL(drm_get_format_name);
> >  
> >  /**
> > + * drm_format_info - query information for a given format
> > + * @format: pixel format (DRM_FORMAT_*)
> > + *
> > + * Returns:
> > + * The instance of struct drm_format_info that describes the pixel format, or
> > + * NULL if the format is unsupported.
> > + */
> > +const struct drm_format_info *drm_format_info(u32 format)
> 
> Bikeshed on your pixel format description table. I think the approach I've
> seen in gallium/mesa to describe pixel formats is a lot more generic, and
> we might as well adopt it when we change. Idea is to have a block size
> measure in pixels (both h and v), and then cpp is bytes_per_block. This is
> essentially what you have with hsub and vsub already, except confusing
> names, more ill-defined (since it only makes sense for yuv) and less
> generic. A few examples:

I think you have your confusion backwards. Calling something a block in
planar formats would be more confusing. The only thing that really
matters is the relative position of the samples between the planes.
So there really is no "block" in there.

> 	h_blocksize	v_blocksize	bytes_per_block (per-plane)
> YUV410	4		4		{4, 1, 1}
> YUV411	4		1		{4, 1, 1}
> 
> hsub = h_blocksize / bytes_per_block[U/V plane]
> vsub = v_blocksize / bytes_per_block[U/V plane]
> 
> *_blocksize is in pixels
> 
> [not entirely sure on the precise data, but that's kinda the point.]
> 
> Ofc should maybe check that those helpers are only called on yuv planar
> formats, too. This way we could also remove some of the comments in
> drm_fourcc.h, or at least make the more clear. Another benefit is that
> with this it's possible to write entirely generic size/stride checking
> functions
> 
> Oh and if we go with this, some asciiart for what's meant (in sphinx/rst,
> that will happen in 4.8) would be awesome.
> -Daniel
> 
> > +{
> > +	static const struct drm_format_info formats[] = { 
> > +		{ .format = DRM_FORMAT_C8,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGB332,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGR233,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XRGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XBGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ARGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ABGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XRGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XBGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ARGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ABGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGB565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGR565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGB888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGR888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XRGB8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XBGR8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XRGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_XBGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ARGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ABGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ARGB8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_ABGR8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_RGBA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_BGRA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YUV410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
> > +		{ .format = DRM_FORMAT_YVU410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
> > +		{ .format = DRM_FORMAT_YUV411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YVU411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YUV420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
> > +		{ .format = DRM_FORMAT_YVU420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
> > +		{ .format = DRM_FORMAT_YUV422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YVU422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YUV444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YVU444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_NV12,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
> > +		{ .format = DRM_FORMAT_NV21,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
> > +		{ .format = DRM_FORMAT_NV16,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_NV61,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_NV24,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_NV42,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YUYV,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_YVYU,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_UYVY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_VYUY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > +		{ .format = DRM_FORMAT_AYUV,		.depth = 0,  .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > +	};
> > +
> > +	unsigned int i;
> > +
> > +	for (i = 0; i < ARRAY_SIZE(formats); ++i) {
> > +		if (formats[i].format == format)
> > +			return &formats[i];
> > +	}
> > +
> > +	return NULL;
> > +}
> > +EXPORT_SYMBOL(drm_format_info);
> > +
> > +/**
> >   * drm_fb_get_bpp_depth - get the bpp/depth values for format
> >   * @format: pixel format (DRM_FORMAT_*)
> >   * @depth: storage for the depth value
> > diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> > index 7f90a396cf2b..b077df507b51 100644
> > --- a/include/drm/drm_fourcc.h
> > +++ b/include/drm/drm_fourcc.h
> > @@ -25,6 +25,25 @@
> >  #include <linux/types.h>
> >  #include <uapi/drm/drm_fourcc.h>
> >  
> > +/**
> > + * struct drm_format_info - information about a DRM format
> > + * @format: 4CC format identifier (DRM_FORMAT_*)
> > + * @depth: color depth (number of bits per pixel excluding padding bits)
> > + * @num_planes: number of color planes (1 to 3)
> > + * @cpp: number of bytes per pixel (per plane)
> > + * @hsub: horizontal chroma subsampling factor
> > + * @vsub: vertical chroma subsampling factor
> > + */
> > +struct drm_format_info {
> > +	u32 format;
> > +	u8 depth;
> > +	u8 num_planes;
> > +	u8 cpp[3];
> > +	u8 hsub;
> > +	u8 vsub;
> > +};
> > +
> > +const struct drm_format_info *drm_format_info(u32 format);
> >  void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
> >  int drm_format_num_planes(uint32_t format);
> >  int drm_format_plane_cpp(uint32_t format, int plane);
> > -- 
> > Regards,
> > 
> > Laurent Pinchart
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/15] drm: Centralize format information
  2016-06-09 12:23     ` Ville Syrjälä
@ 2016-06-09 12:40       ` Daniel Vetter
  2016-06-09 13:05         ` Ville Syrjälä
  0 siblings, 1 reply; 49+ messages in thread
From: Daniel Vetter @ 2016-06-09 12:40 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, dri-devel, Tomi Valkeinen, Laurent Pinchart

On Thu, Jun 09, 2016 at 03:23:17PM +0300, Ville Syrjälä wrote:
> On Thu, Jun 09, 2016 at 10:52:23AM +0200, Daniel Vetter wrote:
> > On Thu, Jun 09, 2016 at 02:32:06AM +0300, Laurent Pinchart wrote:
> > > Various pieces of information about DRM formats (number of planes, color
> > > depth, chroma subsampling, ...) are scattered across different helper
> > > functions in the DRM core. Callers of those functions often need to
> > > access more than a single parameter of the format, leading to
> > > inefficiencies due to multiple lookups.
> > > 
> > > Centralize all format information in a data structure and create a
> > > function to look up information based on the format 4CC.
> > > 
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > ---
> > >  drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
> > >  include/drm/drm_fourcc.h     | 19 ++++++++++
> > >  2 files changed, 103 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> > > index 0645c85d5f95..47b9abd743be 100644
> > > --- a/drivers/gpu/drm/drm_fourcc.c
> > > +++ b/drivers/gpu/drm/drm_fourcc.c
> > > @@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t format)
> > >  EXPORT_SYMBOL(drm_get_format_name);
> > >  
> > >  /**
> > > + * drm_format_info - query information for a given format
> > > + * @format: pixel format (DRM_FORMAT_*)
> > > + *
> > > + * Returns:
> > > + * The instance of struct drm_format_info that describes the pixel format, or
> > > + * NULL if the format is unsupported.
> > > + */
> > > +const struct drm_format_info *drm_format_info(u32 format)
> > 
> > Bikeshed on your pixel format description table. I think the approach I've
> > seen in gallium/mesa to describe pixel formats is a lot more generic, and
> > we might as well adopt it when we change. Idea is to have a block size
> > measure in pixels (both h and v), and then cpp is bytes_per_block. This is
> > essentially what you have with hsub and vsub already, except confusing
> > names, more ill-defined (since it only makes sense for yuv) and less
> > generic. A few examples:
> 
> I think you have your confusion backwards. Calling something a block in
> planar formats would be more confusing. The only thing that really
> matters is the relative position of the samples between the planes.
> So there really is no "block" in there.

Atm U/V planes have a cpp of 1, which is definitely not true. There's much
less than 1 byte per visible pixel in those planes. And that's the part
that annoys me.

block here is an entirely free-standing concept that just means "group of
pixels over which the bytes-per-group is counted in each group". It's a
concept stolen from gallium and makes a lot more sense when talking about
compressed formats. But I think it also makes sense when talking about yuv
formats.

Maybe if you object "block" we can call it "group_of_pixels" instead. It's
_not_ meant to be a continuous block of bytes in memory at all.

E.g. for YUYV formats the gropu size would be (2, 1), with 4
bytes-per-group for an interleaved format of Y8U8Y8V8. In a way the
hsub/vsub stuff describes more the color data, the group-of-pixels stuff
is more useful imo to describe how much space you need on each plane.
-Daniel

> 
> > 	h_blocksize	v_blocksize	bytes_per_block (per-plane)
> > YUV410	4		4		{4, 1, 1}
> > YUV411	4		1		{4, 1, 1}
> > 
> > hsub = h_blocksize / bytes_per_block[U/V plane]
> > vsub = v_blocksize / bytes_per_block[U/V plane]
> > 
> > *_blocksize is in pixels
> > 
> > [not entirely sure on the precise data, but that's kinda the point.]
> > 
> > Ofc should maybe check that those helpers are only called on yuv planar
> > formats, too. This way we could also remove some of the comments in
> > drm_fourcc.h, or at least make the more clear. Another benefit is that
> > with this it's possible to write entirely generic size/stride checking
> > functions
> > 
> > Oh and if we go with this, some asciiart for what's meant (in sphinx/rst,
> > that will happen in 4.8) would be awesome.
> > -Daniel
> > 
> > > +{
> > > +	static const struct drm_format_info formats[] = { 
> > > +		{ .format = DRM_FORMAT_C8,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGB332,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGR233,		.depth = 8,  .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XRGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XBGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRX4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ARGB4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ABGR4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRA4444,	.depth = 12, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XRGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XBGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRX5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ARGB1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ABGR1555,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRA5551,	.depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGB565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGR565,		.depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGB888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGR888,		.depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XRGB8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XBGR8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRX8888,	.depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XRGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_XBGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRX1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ARGB2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ABGR2101010,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRA1010102,	.depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ARGB8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_ABGR8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_RGBA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_BGRA8888,	.depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YUV410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
> > > +		{ .format = DRM_FORMAT_YVU410,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4 },
> > > +		{ .format = DRM_FORMAT_YUV411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YVU411,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YUV420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
> > > +		{ .format = DRM_FORMAT_YVU420,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2 },
> > > +		{ .format = DRM_FORMAT_YUV422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YVU422,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YUV444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YVU444,		.depth = 0,  .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_NV12,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
> > > +		{ .format = DRM_FORMAT_NV21,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2 },
> > > +		{ .format = DRM_FORMAT_NV16,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_NV61,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_NV24,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_NV42,		.depth = 0,  .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YUYV,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_YVYU,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_UYVY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_VYUY,		.depth = 0,  .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1 },
> > > +		{ .format = DRM_FORMAT_AYUV,		.depth = 0,  .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 },
> > > +	};
> > > +
> > > +	unsigned int i;
> > > +
> > > +	for (i = 0; i < ARRAY_SIZE(formats); ++i) {
> > > +		if (formats[i].format == format)
> > > +			return &formats[i];
> > > +	}
> > > +
> > > +	return NULL;
> > > +}
> > > +EXPORT_SYMBOL(drm_format_info);
> > > +
> > > +/**
> > >   * drm_fb_get_bpp_depth - get the bpp/depth values for format
> > >   * @format: pixel format (DRM_FORMAT_*)
> > >   * @depth: storage for the depth value
> > > diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> > > index 7f90a396cf2b..b077df507b51 100644
> > > --- a/include/drm/drm_fourcc.h
> > > +++ b/include/drm/drm_fourcc.h
> > > @@ -25,6 +25,25 @@
> > >  #include <linux/types.h>
> > >  #include <uapi/drm/drm_fourcc.h>
> > >  
> > > +/**
> > > + * struct drm_format_info - information about a DRM format
> > > + * @format: 4CC format identifier (DRM_FORMAT_*)
> > > + * @depth: color depth (number of bits per pixel excluding padding bits)
> > > + * @num_planes: number of color planes (1 to 3)
> > > + * @cpp: number of bytes per pixel (per plane)
> > > + * @hsub: horizontal chroma subsampling factor
> > > + * @vsub: vertical chroma subsampling factor
> > > + */
> > > +struct drm_format_info {
> > > +	u32 format;
> > > +	u8 depth;
> > > +	u8 num_planes;
> > > +	u8 cpp[3];
> > > +	u8 hsub;
> > > +	u8 vsub;
> > > +};
> > > +
> > > +const struct drm_format_info *drm_format_info(u32 format);
> > >  void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
> > >  int drm_format_num_planes(uint32_t format);
> > >  int drm_format_plane_cpp(uint32_t format, int plane);
> > > -- 
> > > Regards,
> > > 
> > > Laurent Pinchart
> > > 
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> > 
> > -- 
> > Daniel Vetter
> > Software Engineer, Intel Corporation
> > http://blog.ffwll.ch
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
> -- 
> Ville Syrjälä
> Intel OTC

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/15] drm: Centralize format information
  2016-06-09 12:40       ` Daniel Vetter
@ 2016-06-09 13:05         ` Ville Syrjälä
  2016-06-09 13:29           ` Daniel Vetter
  0 siblings, 1 reply; 49+ messages in thread
From: Ville Syrjälä @ 2016-06-09 13:05 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Daniel Vetter, Tomi Valkeinen, Laurent Pinchart, dri-devel

On Thu, Jun 09, 2016 at 02:40:28PM +0200, Daniel Vetter wrote:
> On Thu, Jun 09, 2016 at 03:23:17PM +0300, Ville Syrjälä wrote:
> > On Thu, Jun 09, 2016 at 10:52:23AM +0200, Daniel Vetter wrote:
> > > On Thu, Jun 09, 2016 at 02:32:06AM +0300, Laurent Pinchart wrote:
> > > > Various pieces of information about DRM formats (number of planes, color
> > > > depth, chroma subsampling, ...) are scattered across different helper
> > > > functions in the DRM core. Callers of those functions often need to
> > > > access more than a single parameter of the format, leading to
> > > > inefficiencies due to multiple lookups.
> > > > 
> > > > Centralize all format information in a data structure and create a
> > > > function to look up information based on the format 4CC.
> > > > 
> > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > > ---
> > > >  drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
> > > >  include/drm/drm_fourcc.h     | 19 ++++++++++
> > > >  2 files changed, 103 insertions(+)
> > > > 
> > > > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> > > > index 0645c85d5f95..47b9abd743be 100644
> > > > --- a/drivers/gpu/drm/drm_fourcc.c
> > > > +++ b/drivers/gpu/drm/drm_fourcc.c
> > > > @@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t format)
> > > >  EXPORT_SYMBOL(drm_get_format_name);
> > > >  
> > > >  /**
> > > > + * drm_format_info - query information for a given format
> > > > + * @format: pixel format (DRM_FORMAT_*)
> > > > + *
> > > > + * Returns:
> > > > + * The instance of struct drm_format_info that describes the pixel format, or
> > > > + * NULL if the format is unsupported.
> > > > + */
> > > > +const struct drm_format_info *drm_format_info(u32 format)
> > > 
> > > Bikeshed on your pixel format description table. I think the approach I've
> > > seen in gallium/mesa to describe pixel formats is a lot more generic, and
> > > we might as well adopt it when we change. Idea is to have a block size
> > > measure in pixels (both h and v), and then cpp is bytes_per_block. This is
> > > essentially what you have with hsub and vsub already, except confusing
> > > names, more ill-defined (since it only makes sense for yuv) and less
> > > generic. A few examples:
> > 
> > I think you have your confusion backwards. Calling something a block in
> > planar formats would be more confusing. The only thing that really
> > matters is the relative position of the samples between the planes.
> > So there really is no "block" in there.
> 
> Atm U/V planes have a cpp of 1, which is definitely not true. There's much
> less than 1 byte per visible pixel in those planes. And that's the part
> that annoys me.

That's exactly as it should be. The cpp value isn't some average thing
for the whole, it's per-plane.

> 
> block here is an entirely free-standing concept that just means "group of
> pixels over which the bytes-per-group is counted in each group". It's a
> concept stolen from gallium and makes a lot more sense when talking about
> compressed formats. But I think it also makes sense when talking about yuv
> formats.

For packed YUV formats the usual term I've heard is macropixel, and there
it does make sense. I could live with calling it a block. So I guess eg.
for 422 packed formats we'd have h_block_size=2 v_block_size=1, and
bytes_per_block=4.

For planar formats, each plane should be considered individually,
and trying to come up with some kind of cpp value etc. for the whole
thing is pointless. I think eg. with for all the NVxx formats the
chroma plane should have h_block_size=2 v_block_size=1 bytes_per_block=2
regardless the sub-sampling factor.

So if we start using the block size concept, I think that too should be
per-plane. Anything else will just get really confusing.

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/15] drm: Centralize format information
  2016-06-09 13:05         ` Ville Syrjälä
@ 2016-06-09 13:29           ` Daniel Vetter
  2016-06-09 14:13             ` Ville Syrjälä
  0 siblings, 1 reply; 49+ messages in thread
From: Daniel Vetter @ 2016-06-09 13:29 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, dri-devel, Tomi Valkeinen, Laurent Pinchart

On Thu, Jun 09, 2016 at 04:05:11PM +0300, Ville Syrjälä wrote:
> On Thu, Jun 09, 2016 at 02:40:28PM +0200, Daniel Vetter wrote:
> > On Thu, Jun 09, 2016 at 03:23:17PM +0300, Ville Syrjälä wrote:
> > > On Thu, Jun 09, 2016 at 10:52:23AM +0200, Daniel Vetter wrote:
> > > > On Thu, Jun 09, 2016 at 02:32:06AM +0300, Laurent Pinchart wrote:
> > > > > Various pieces of information about DRM formats (number of planes, color
> > > > > depth, chroma subsampling, ...) are scattered across different helper
> > > > > functions in the DRM core. Callers of those functions often need to
> > > > > access more than a single parameter of the format, leading to
> > > > > inefficiencies due to multiple lookups.
> > > > > 
> > > > > Centralize all format information in a data structure and create a
> > > > > function to look up information based on the format 4CC.
> > > > > 
> > > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > > > ---
> > > > >  drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
> > > > >  include/drm/drm_fourcc.h     | 19 ++++++++++
> > > > >  2 files changed, 103 insertions(+)
> > > > > 
> > > > > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> > > > > index 0645c85d5f95..47b9abd743be 100644
> > > > > --- a/drivers/gpu/drm/drm_fourcc.c
> > > > > +++ b/drivers/gpu/drm/drm_fourcc.c
> > > > > @@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t format)
> > > > >  EXPORT_SYMBOL(drm_get_format_name);
> > > > >  
> > > > >  /**
> > > > > + * drm_format_info - query information for a given format
> > > > > + * @format: pixel format (DRM_FORMAT_*)
> > > > > + *
> > > > > + * Returns:
> > > > > + * The instance of struct drm_format_info that describes the pixel format, or
> > > > > + * NULL if the format is unsupported.
> > > > > + */
> > > > > +const struct drm_format_info *drm_format_info(u32 format)
> > > > 
> > > > Bikeshed on your pixel format description table. I think the approach I've
> > > > seen in gallium/mesa to describe pixel formats is a lot more generic, and
> > > > we might as well adopt it when we change. Idea is to have a block size
> > > > measure in pixels (both h and v), and then cpp is bytes_per_block. This is
> > > > essentially what you have with hsub and vsub already, except confusing
> > > > names, more ill-defined (since it only makes sense for yuv) and less
> > > > generic. A few examples:
> > > 
> > > I think you have your confusion backwards. Calling something a block in
> > > planar formats would be more confusing. The only thing that really
> > > matters is the relative position of the samples between the planes.
> > > So there really is no "block" in there.
> > 
> > Atm U/V planes have a cpp of 1, which is definitely not true. There's much
> > less than 1 byte per visible pixel in those planes. And that's the part
> > that annoys me.
> 
> That's exactly as it should be. The cpp value isn't some average thing
> for the whole, it's per-plane.

On a 4x subsampled U or V plane you have 1 byte for 4 pixels. That's just
plain not 1 character-per-pixel, even when you just look at that plane.

> > block here is an entirely free-standing concept that just means "group of
> > pixels over which the bytes-per-group is counted in each group". It's a
> > concept stolen from gallium and makes a lot more sense when talking about
> > compressed formats. But I think it also makes sense when talking about yuv
> > formats.
> 
> For packed YUV formats the usual term I've heard is macropixel, and there
> it does make sense. I could live with calling it a block. So I guess eg.
> for 422 packed formats we'd have h_block_size=2 v_block_size=1, and
> bytes_per_block=4.
> 
> For planar formats, each plane should be considered individually,
> and trying to come up with some kind of cpp value etc. for the whole
> thing is pointless. I think eg. with for all the NVxx formats the
> chroma plane should have h_block_size=2 v_block_size=1 bytes_per_block=2
> regardless the sub-sampling factor.

Hm yeah NV12 is a case where 2 have 2 bytes per 2 pixel block (since
they're together in 1 2ndary plane), but still a subsampling of 2x. Maybe
we'd need both? And then perhaps define subsampling per color channel, but
block size and bytes-per-block per plane?

> So if we start using the block size concept, I think that too should be
> per-plane. Anything else will just get really confusing.

You can always merge blocks together by using the lcm.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/15] drm: Centralize format information
  2016-06-09 13:29           ` Daniel Vetter
@ 2016-06-09 14:13             ` Ville Syrjälä
  2016-09-08 13:49               ` Laurent Pinchart
  0 siblings, 1 reply; 49+ messages in thread
From: Ville Syrjälä @ 2016-06-09 14:13 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Daniel Vetter, Tomi Valkeinen, Laurent Pinchart, dri-devel

On Thu, Jun 09, 2016 at 03:29:10PM +0200, Daniel Vetter wrote:
> On Thu, Jun 09, 2016 at 04:05:11PM +0300, Ville Syrjälä wrote:
> > On Thu, Jun 09, 2016 at 02:40:28PM +0200, Daniel Vetter wrote:
> > > On Thu, Jun 09, 2016 at 03:23:17PM +0300, Ville Syrjälä wrote:
> > > > On Thu, Jun 09, 2016 at 10:52:23AM +0200, Daniel Vetter wrote:
> > > > > On Thu, Jun 09, 2016 at 02:32:06AM +0300, Laurent Pinchart wrote:
> > > > > > Various pieces of information about DRM formats (number of planes, color
> > > > > > depth, chroma subsampling, ...) are scattered across different helper
> > > > > > functions in the DRM core. Callers of those functions often need to
> > > > > > access more than a single parameter of the format, leading to
> > > > > > inefficiencies due to multiple lookups.
> > > > > > 
> > > > > > Centralize all format information in a data structure and create a
> > > > > > function to look up information based on the format 4CC.
> > > > > > 
> > > > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > > > > ---
> > > > > >  drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++++++++++++++++++
> > > > > >  include/drm/drm_fourcc.h     | 19 ++++++++++
> > > > > >  2 files changed, 103 insertions(+)
> > > > > > 
> > > > > > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> > > > > > index 0645c85d5f95..47b9abd743be 100644
> > > > > > --- a/drivers/gpu/drm/drm_fourcc.c
> > > > > > +++ b/drivers/gpu/drm/drm_fourcc.c
> > > > > > @@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t format)
> > > > > >  EXPORT_SYMBOL(drm_get_format_name);
> > > > > >  
> > > > > >  /**
> > > > > > + * drm_format_info - query information for a given format
> > > > > > + * @format: pixel format (DRM_FORMAT_*)
> > > > > > + *
> > > > > > + * Returns:
> > > > > > + * The instance of struct drm_format_info that describes the pixel format, or
> > > > > > + * NULL if the format is unsupported.
> > > > > > + */
> > > > > > +const struct drm_format_info *drm_format_info(u32 format)
> > > > > 
> > > > > Bikeshed on your pixel format description table. I think the approach I've
> > > > > seen in gallium/mesa to describe pixel formats is a lot more generic, and
> > > > > we might as well adopt it when we change. Idea is to have a block size
> > > > > measure in pixels (both h and v), and then cpp is bytes_per_block. This is
> > > > > essentially what you have with hsub and vsub already, except confusing
> > > > > names, more ill-defined (since it only makes sense for yuv) and less
> > > > > generic. A few examples:
> > > > 
> > > > I think you have your confusion backwards. Calling something a block in
> > > > planar formats would be more confusing. The only thing that really
> > > > matters is the relative position of the samples between the planes.
> > > > So there really is no "block" in there.
> > > 
> > > Atm U/V planes have a cpp of 1, which is definitely not true. There's much
> > > less than 1 byte per visible pixel in those planes. And that's the part
> > > that annoys me.
> > 
> > That's exactly as it should be. The cpp value isn't some average thing
> > for the whole, it's per-plane.
> 
> On a 4x subsampled U or V plane you have 1 byte for 4 pixels. That's just
> plain not 1 character-per-pixel, even when you just look at that plane.

OK. So let's stop calling it a pixel and call it a sample instead.
It's 1 byte per sample, which is the only thing that should matter
to anyone.

> 
> > > block here is an entirely free-standing concept that just means "group of
> > > pixels over which the bytes-per-group is counted in each group". It's a
> > > concept stolen from gallium and makes a lot more sense when talking about
> > > compressed formats. But I think it also makes sense when talking about yuv
> > > formats.
> > 
> > For packed YUV formats the usual term I've heard is macropixel, and there
> > it does make sense. I could live with calling it a block. So I guess eg.
> > for 422 packed formats we'd have h_block_size=2 v_block_size=1, and
> > bytes_per_block=4.
> > 
> > For planar formats, each plane should be considered individually,
> > and trying to come up with some kind of cpp value etc. for the whole
> > thing is pointless. I think eg. with for all the NVxx formats the
> > chroma plane should have h_block_size=2 v_block_size=1 bytes_per_block=2
> > regardless the sub-sampling factor.

Actually meant to write h_block_size=1 here obviously. 1 sample of
each chroma component, 2 bytes in total.

> 
> Hm yeah NV12 is a case where 2 have 2 bytes per 2 pixel block (since
> they're together in 1 2ndary plane), but still a subsampling of 2x. Maybe
> we'd need both? And then perhaps define subsampling per color channel, but
> block size and bytes-per-block per plane?

Well given all the formats we have today, it's always chroma that's
sub-sampled. I guess if we were to have a more complicated mix of
planes that may or may not be sub-sampled then it might make sense to
define things in a more complicated way. Right now I don't see any
need for that though.

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-08 23:32 ` [PATCH v3 09/15] drm: tilcdc: " Laurent Pinchart
@ 2016-06-10 11:51   ` Tomi Valkeinen
  2016-06-10 12:05     ` Ville Syrjälä
                       ` (2 more replies)
  0 siblings, 3 replies; 49+ messages in thread
From: Tomi Valkeinen @ 2016-06-10 11:51 UTC (permalink / raw)
  To: Laurent Pinchart, dri-devel; +Cc: Daniel Vetter, Jyri Sarha


[-- Attachment #1.1.1: Type: text/plain, Size: 2855 bytes --]



On 09/06/16 02:32, Laurent Pinchart wrote:
> The driver needs the number of bytes per pixel, not the bpp and depth
> info meant for fbdev compatibility. Use the right API.
> 
> In the tilcdc_crtc_mode_set() function compute the hardware register
> value directly from the pixel format instead of computing the number of
> bits per pixels first.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> Cc: Jyri Sarha <jsarha@ti.com>
> 
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> index 79027b1c64d3..d63c7363dabc 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> @@ -65,15 +65,13 @@ static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
>  	struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
>  	struct drm_device *dev = crtc->dev;
>  	struct drm_gem_cma_object *gem;
> -	unsigned int depth, bpp;
>  	dma_addr_t start, end;
>  
> -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
>  	gem = drm_fb_cma_get_gem_obj(fb, 0);
>  
>  	start = gem->paddr + fb->offsets[0] +
>  		crtc->y * fb->pitches[0] +
> -		crtc->x * bpp / 8;
> +		crtc->x * drm_format_plane_cpp(fb->pixel_format, 0);
>  
>  	end = start + (crtc->mode.vdisplay * fb->pitches[0]);
>  
> @@ -132,11 +130,12 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
>  static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb)
>  {
>  	struct drm_device *dev = crtc->dev;
> -	unsigned int depth, bpp;
> +	unsigned int min_pitch;
>  
> -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> +	min_pitch = crtc->mode.hdisplay
> +		  * drm_format_plane_cpp(fb->pixel_format, 0);

Why 'min_pitch'? Plain 'pitch' should be fine here.

>  
> -	if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) {
> +	if (fb->pitches[0] != min_pitch) {
>  		dev_err(dev->dev,
>  			"Invalid pitch: fb and crtc widths must be the same");
>  		return -EINVAL;
> @@ -401,16 +400,14 @@ static int tilcdc_crtc_mode_set(struct drm_crtc *crtc,
>  	if (info->tft_alt_mode)
>  		reg |= LCDC_TFT_ALT_ENABLE;
>  	if (priv->rev == 2) {
> -		unsigned int depth, bpp;
> -
> -		drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp);
> -		switch (bpp) {
> -		case 16:
> +		switch (crtc->primary->fb->pixel_format) {
> +		case DRM_FORMAT_RGB565:
>  			break;
> -		case 32:
> +		case DRM_FORMAT_XRGB8888:
> +		case DRM_FORMAT_ARGB8888:

I'm not sure what's the common way, but tilcdc doesn't support alpha.
ARGB works, of course, by ignoring A, but... If an userspace app creates
ARGB buffer, does the app expect alpha to work?

 Tomi


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 11:51   ` Tomi Valkeinen
@ 2016-06-10 12:05     ` Ville Syrjälä
  2016-06-10 12:08       ` Tomi Valkeinen
  2016-06-10 12:07     ` Laurent Pinchart
  2016-06-10 12:08     ` [PATCH v3.1 " Laurent Pinchart
  2 siblings, 1 reply; 49+ messages in thread
From: Ville Syrjälä @ 2016-06-10 12:05 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Daniel Vetter, Jyri Sarha, Laurent Pinchart, dri-devel

On Fri, Jun 10, 2016 at 02:51:45PM +0300, Tomi Valkeinen wrote:
> 
> 
> On 09/06/16 02:32, Laurent Pinchart wrote:
> > The driver needs the number of bytes per pixel, not the bpp and depth
> > info meant for fbdev compatibility. Use the right API.
> > 
> > In the tilcdc_crtc_mode_set() function compute the hardware register
> > value directly from the pixel format instead of computing the number of
> > bits per pixels first.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 23 ++++++++++-------------
> >  1 file changed, 10 insertions(+), 13 deletions(-)
> > 
> > Cc: Jyri Sarha <jsarha@ti.com>
> > 
> > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> > index 79027b1c64d3..d63c7363dabc 100644
> > --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> > +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> > @@ -65,15 +65,13 @@ static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
> >  	struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
> >  	struct drm_device *dev = crtc->dev;
> >  	struct drm_gem_cma_object *gem;
> > -	unsigned int depth, bpp;
> >  	dma_addr_t start, end;
> >  
> > -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> >  	gem = drm_fb_cma_get_gem_obj(fb, 0);
> >  
> >  	start = gem->paddr + fb->offsets[0] +
> >  		crtc->y * fb->pitches[0] +
> > -		crtc->x * bpp / 8;
> > +		crtc->x * drm_format_plane_cpp(fb->pixel_format, 0);
> >  
> >  	end = start + (crtc->mode.vdisplay * fb->pitches[0]);
> >  
> > @@ -132,11 +130,12 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
> >  static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb)
> >  {
> >  	struct drm_device *dev = crtc->dev;
> > -	unsigned int depth, bpp;
> > +	unsigned int min_pitch;
> >  
> > -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> > +	min_pitch = crtc->mode.hdisplay
> > +		  * drm_format_plane_cpp(fb->pixel_format, 0);
> 
> Why 'min_pitch'? Plain 'pitch' should be fine here.
> 
> >  
> > -	if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) {
> > +	if (fb->pitches[0] != min_pitch) {
> >  		dev_err(dev->dev,
> >  			"Invalid pitch: fb and crtc widths must be the same");
> >  		return -EINVAL;
> > @@ -401,16 +400,14 @@ static int tilcdc_crtc_mode_set(struct drm_crtc *crtc,
> >  	if (info->tft_alt_mode)
> >  		reg |= LCDC_TFT_ALT_ENABLE;
> >  	if (priv->rev == 2) {
> > -		unsigned int depth, bpp;
> > -
> > -		drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp);
> > -		switch (bpp) {
> > -		case 16:
> > +		switch (crtc->primary->fb->pixel_format) {
> > +		case DRM_FORMAT_RGB565:
> >  			break;
> > -		case 32:
> > +		case DRM_FORMAT_XRGB8888:
> > +		case DRM_FORMAT_ARGB8888:
> 
> I'm not sure what's the common way, but tilcdc doesn't support alpha.
> ARGB works, of course, by ignoring A, but... If an userspace app creates
> ARGB buffer, does the app expect alpha to work?

I think what we decided a while ago (at least for i915, but would be good
to use the same convention everywhere) was that ARGB will be assumed to be
pre-multiplied and will enable blending using 1.0*sc+(1.0-sa)*dc as the
function. There have been some efforts at defining some new properties to
control the blend equation, but I guess those got bogged down again.

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 11:51   ` Tomi Valkeinen
  2016-06-10 12:05     ` Ville Syrjälä
@ 2016-06-10 12:07     ` Laurent Pinchart
  2016-06-10 12:08     ` [PATCH v3.1 " Laurent Pinchart
  2 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-10 12:07 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Daniel Vetter, Jyri Sarha, dri-devel

Hi Tomi,

On Friday 10 Jun 2016 14:51:45 Tomi Valkeinen wrote:
> On 09/06/16 02:32, Laurent Pinchart wrote:
> > The driver needs the number of bytes per pixel, not the bpp and depth
> > info meant for fbdev compatibility. Use the right API.
> > 
> > In the tilcdc_crtc_mode_set() function compute the hardware register
> > value directly from the pixel format instead of computing the number of
> > bits per pixels first.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > 
> >  drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 23 ++++++++++-------------
> >  1 file changed, 10 insertions(+), 13 deletions(-)
> > 
> > Cc: Jyri Sarha <jsarha@ti.com>
> > 
> > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> > b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c index 79027b1c64d3..d63c7363dabc
> > 100644
> > --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> > +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> > @@ -65,15 +65,13 @@ static void set_scanout(struct drm_crtc *crtc, struct
> > drm_framebuffer *fb)> 
> >  	struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
> >  	struct drm_device *dev = crtc->dev;
> >  	struct drm_gem_cma_object *gem;
> > -	unsigned int depth, bpp;
> >  	dma_addr_t start, end;
> > 
> > -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> >  	gem = drm_fb_cma_get_gem_obj(fb, 0);
> >  	start = gem->paddr + fb->offsets[0] +
> >  		crtc->y * fb->pitches[0] +
> > -		crtc->x * bpp / 8;
> > +		crtc->x * drm_format_plane_cpp(fb->pixel_format, 0);
> > 
> >  	end = start + (crtc->mode.vdisplay * fb->pitches[0]);
> > 
> > @@ -132,11 +130,12 @@ static void tilcdc_crtc_destroy(struct drm_crtc
> > *crtc)
> >  static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer
> >  *fb) {
> >  	struct drm_device *dev = crtc->dev;
> > -	unsigned int depth, bpp;
> > +	unsigned int min_pitch;
> > 
> > -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> > +	min_pitch = crtc->mode.hdisplay
> > +		  * drm_format_plane_cpp(fb->pixel_format, 0);
> 
> Why 'min_pitch'? Plain 'pitch' should be fine here.

You're right, the hardware doesn't seem to support configurable strides, I'll 
rename this.

> > -	if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) {
> > +	if (fb->pitches[0] != min_pitch) {
> >  		dev_err(dev->dev,
> >  			"Invalid pitch: fb and crtc widths must be the same");
> >  		return -EINVAL;
> > @@ -401,16 +400,14 @@ static int tilcdc_crtc_mode_set(struct drm_crtc
> > *crtc,
> >  	if (info->tft_alt_mode)
> >  		reg |= LCDC_TFT_ALT_ENABLE;
> >  	
> >  	if (priv->rev == 2) {
> > -		unsigned int depth, bpp;
> > -
> > -		drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp);
> > -		switch (bpp) {
> > -		case 16:
> > +		switch (crtc->primary->fb->pixel_format) {
> > +		case DRM_FORMAT_RGB565:
> >  			break;
> > -		case 32:
> > +		case DRM_FORMAT_XRGB8888:
> > +		case DRM_FORMAT_ARGB8888:
>
> I'm not sure what's the common way, but tilcdc doesn't support alpha.
> ARGB works, of course, by ignoring A, but... If an userspace app creates
> ARGB buffer, does the app expect alpha to work?

The driver currently accepts DRM_FORMAT_ARGB8888 and ignores the alpha 
component. I didn't want to risk breaking userspace by removing that, so I 
decided to take a conservative approach. If you think we can safely drop 
DRM_FORMAT_ARGB8888 then we can do so in a separate patch.

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v3.1 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 11:51   ` Tomi Valkeinen
  2016-06-10 12:05     ` Ville Syrjälä
  2016-06-10 12:07     ` Laurent Pinchart
@ 2016-06-10 12:08     ` Laurent Pinchart
  2016-06-10 12:21       ` Tomi Valkeinen
  2 siblings, 1 reply; 49+ messages in thread
From: Laurent Pinchart @ 2016-06-10 12:08 UTC (permalink / raw)
  To: dri-devel; +Cc: Tomi Valkeinen

The driver needs the number of bytes per pixel, not the bpp and depth
info meant for fbdev compatibility. Use the right API.

In the tilcdc_crtc_mode_set() function compute the hardware register
value directly from the pixel format instead of computing the number of
bits per pixels first.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
index 79027b1c64d3..1f3f3a1c7b5f 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
@@ -65,15 +65,13 @@ static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
 	struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
 	struct drm_device *dev = crtc->dev;
 	struct drm_gem_cma_object *gem;
-	unsigned int depth, bpp;
 	dma_addr_t start, end;
 
-	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
 	gem = drm_fb_cma_get_gem_obj(fb, 0);
 
 	start = gem->paddr + fb->offsets[0] +
 		crtc->y * fb->pitches[0] +
-		crtc->x * bpp / 8;
+		crtc->x * drm_format_plane_cpp(fb->pixel_format, 0);
 
 	end = start + (crtc->mode.vdisplay * fb->pitches[0]);
 
@@ -132,11 +130,12 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
 static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb)
 {
 	struct drm_device *dev = crtc->dev;
-	unsigned int depth, bpp;
+	unsigned int pitch;
 
-	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
+	pitch = crtc->mode.hdisplay
+	      * drm_format_plane_cpp(fb->pixel_format, 0);
 
-	if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) {
+	if (fb->pitches[0] != pitch) {
 		dev_err(dev->dev,
 			"Invalid pitch: fb and crtc widths must be the same");
 		return -EINVAL;
@@ -401,16 +400,14 @@ static int tilcdc_crtc_mode_set(struct drm_crtc *crtc,
 	if (info->tft_alt_mode)
 		reg |= LCDC_TFT_ALT_ENABLE;
 	if (priv->rev == 2) {
-		unsigned int depth, bpp;
-
-		drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp);
-		switch (bpp) {
-		case 16:
+		switch (crtc->primary->fb->pixel_format) {
+		case DRM_FORMAT_RGB565:
 			break;
-		case 32:
+		case DRM_FORMAT_XRGB8888:
+		case DRM_FORMAT_ARGB8888:
 			reg |= LCDC_V2_TFT_24BPP_UNPACK;
 			/* fallthrough */
-		case 24:
+		case DRM_FORMAT_RGB888:
 			reg |= LCDC_V2_TFT_24BPP_MODE;
 			break;
 		default:
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 12:05     ` Ville Syrjälä
@ 2016-06-10 12:08       ` Tomi Valkeinen
  2016-06-10 12:23         ` Ville Syrjälä
  0 siblings, 1 reply; 49+ messages in thread
From: Tomi Valkeinen @ 2016-06-10 12:08 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, Jyri Sarha, Laurent Pinchart, dri-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 803 bytes --]

On 10/06/16 15:05, Ville Syrjälä wrote:

>> I'm not sure what's the common way, but tilcdc doesn't support alpha.
>> ARGB works, of course, by ignoring A, but... If an userspace app creates
>> ARGB buffer, does the app expect alpha to work?
> 
> I think what we decided a while ago (at least for i915, but would be good
> to use the same convention everywhere) was that ARGB will be assumed to be
> pre-multiplied and will enable blending using 1.0*sc+(1.0-sa)*dc as the
> function. There have been some efforts at defining some new properties to
> control the blend equation, but I guess those got bogged down again.

Ok, but that's a bit different topic. The question here is, if the HW
doesn't support alpha (no planes, so nothing to blend), should it accept
ARGB or not.

 Tomi


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3.1 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 12:08     ` [PATCH v3.1 " Laurent Pinchart
@ 2016-06-10 12:21       ` Tomi Valkeinen
  0 siblings, 0 replies; 49+ messages in thread
From: Tomi Valkeinen @ 2016-06-10 12:21 UTC (permalink / raw)
  To: Laurent Pinchart, dri-devel; +Cc: Sarha, Jyri


[-- Attachment #1.1.1: Type: text/plain, Size: 3106 bytes --]

On 10/06/16 15:08, Laurent Pinchart wrote:
> The driver needs the number of bytes per pixel, not the bpp and depth
> info meant for fbdev compatibility. Use the right API.
> 
> In the tilcdc_crtc_mode_set() function compute the hardware register
> value directly from the pixel format instead of computing the number of
> bits per pixels first.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> index 79027b1c64d3..1f3f3a1c7b5f 100644
> --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c
> @@ -65,15 +65,13 @@ static void set_scanout(struct drm_crtc *crtc, struct drm_framebuffer *fb)
>  	struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc);
>  	struct drm_device *dev = crtc->dev;
>  	struct drm_gem_cma_object *gem;
> -	unsigned int depth, bpp;
>  	dma_addr_t start, end;
>  
> -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
>  	gem = drm_fb_cma_get_gem_obj(fb, 0);
>  
>  	start = gem->paddr + fb->offsets[0] +
>  		crtc->y * fb->pitches[0] +
> -		crtc->x * bpp / 8;
> +		crtc->x * drm_format_plane_cpp(fb->pixel_format, 0);
>  
>  	end = start + (crtc->mode.vdisplay * fb->pitches[0]);
>  
> @@ -132,11 +130,12 @@ static void tilcdc_crtc_destroy(struct drm_crtc *crtc)
>  static int tilcdc_verify_fb(struct drm_crtc *crtc, struct drm_framebuffer *fb)
>  {
>  	struct drm_device *dev = crtc->dev;
> -	unsigned int depth, bpp;
> +	unsigned int pitch;
>  
> -	drm_fb_get_bpp_depth(fb->pixel_format, &depth, &bpp);
> +	pitch = crtc->mode.hdisplay
> +	      * drm_format_plane_cpp(fb->pixel_format, 0);

I see you're using this form of having + or * at the start of the
continuation line in some patches... I don't like it =). And it's not
what's being used elsewhere in the driver, afaics.

>  
> -	if (fb->pitches[0] != crtc->mode.hdisplay * bpp / 8) {
> +	if (fb->pitches[0] != pitch) {
>  		dev_err(dev->dev,
>  			"Invalid pitch: fb and crtc widths must be the same");
>  		return -EINVAL;
> @@ -401,16 +400,14 @@ static int tilcdc_crtc_mode_set(struct drm_crtc *crtc,
>  	if (info->tft_alt_mode)
>  		reg |= LCDC_TFT_ALT_ENABLE;
>  	if (priv->rev == 2) {
> -		unsigned int depth, bpp;
> -
> -		drm_fb_get_bpp_depth(crtc->primary->fb->pixel_format, &depth, &bpp);
> -		switch (bpp) {
> -		case 16:
> +		switch (crtc->primary->fb->pixel_format) {
> +		case DRM_FORMAT_RGB565:
>  			break;
> -		case 32:
> +		case DRM_FORMAT_XRGB8888:
> +		case DRM_FORMAT_ARGB8888:
>  			reg |= LCDC_V2_TFT_24BPP_UNPACK;
>  			/* fallthrough */
> -		case 24:
> +		case DRM_FORMAT_RGB888:
>  			reg |= LCDC_V2_TFT_24BPP_MODE;
>  			break;
>  		default:
> 

I think it's better to keep ARGB allowed for now. If we want to disallow
it, it's better to be done in a separate patch.

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>

 Tomi


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 12:08       ` Tomi Valkeinen
@ 2016-06-10 12:23         ` Ville Syrjälä
  2016-06-10 12:26           ` Tomi Valkeinen
  0 siblings, 1 reply; 49+ messages in thread
From: Ville Syrjälä @ 2016-06-10 12:23 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Daniel Vetter, Jyri Sarha, Laurent Pinchart, dri-devel

On Fri, Jun 10, 2016 at 03:08:18PM +0300, Tomi Valkeinen wrote:
> On 10/06/16 15:05, Ville Syrjälä wrote:
> 
> >> I'm not sure what's the common way, but tilcdc doesn't support alpha.
> >> ARGB works, of course, by ignoring A, but... If an userspace app creates
> >> ARGB buffer, does the app expect alpha to work?
> > 
> > I think what we decided a while ago (at least for i915, but would be good
> > to use the same convention everywhere) was that ARGB will be assumed to be
> > pre-multiplied and will enable blending using 1.0*sc+(1.0-sa)*dc as the
> > function. There have been some efforts at defining some new properties to
> > control the blend equation, but I guess those got bogged down again.
> 
> Ok, but that's a bit different topic. The question here is, if the HW
> doesn't support alpha (no planes, so nothing to blend), should it accept
> ARGB or not.

What do you mean "no planes"? You have to have a plane if you want
to scanout a framebuffer. And even if you have just one plane with
alpha blending, it should be blended with the background color
(which is black until we get a property to change it).

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 12:23         ` Ville Syrjälä
@ 2016-06-10 12:26           ` Tomi Valkeinen
  2016-06-10 12:29             ` Ville Syrjälä
  0 siblings, 1 reply; 49+ messages in thread
From: Tomi Valkeinen @ 2016-06-10 12:26 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, Jyri Sarha, Laurent Pinchart, dri-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 1384 bytes --]

On 10/06/16 15:23, Ville Syrjälä wrote:
> On Fri, Jun 10, 2016 at 03:08:18PM +0300, Tomi Valkeinen wrote:
>> On 10/06/16 15:05, Ville Syrjälä wrote:
>>
>>>> I'm not sure what's the common way, but tilcdc doesn't support alpha.
>>>> ARGB works, of course, by ignoring A, but... If an userspace app creates
>>>> ARGB buffer, does the app expect alpha to work?
>>>
>>> I think what we decided a while ago (at least for i915, but would be good
>>> to use the same convention everywhere) was that ARGB will be assumed to be
>>> pre-multiplied and will enable blending using 1.0*sc+(1.0-sa)*dc as the
>>> function. There have been some efforts at defining some new properties to
>>> control the blend equation, but I guess those got bogged down again.
>>
>> Ok, but that's a bit different topic. The question here is, if the HW
>> doesn't support alpha (no planes, so nothing to blend), should it accept
>> ARGB or not.
> 
> What do you mean "no planes"? You have to have a plane if you want
> to scanout a framebuffer. And even if you have just one plane with
> alpha blending, it should be blended with the background color
> (which is black until we get a property to change it).

I mean there's only the crtc with fb. So yes, one plane if you want to
call that a plane. The HW does not support any kind of blending to black
or to anything else.

 Tomi


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 12:26           ` Tomi Valkeinen
@ 2016-06-10 12:29             ` Ville Syrjälä
  2016-06-10 12:48               ` Tomi Valkeinen
  0 siblings, 1 reply; 49+ messages in thread
From: Ville Syrjälä @ 2016-06-10 12:29 UTC (permalink / raw)
  To: Tomi Valkeinen; +Cc: Daniel Vetter, Jyri Sarha, Laurent Pinchart, dri-devel

On Fri, Jun 10, 2016 at 03:26:30PM +0300, Tomi Valkeinen wrote:
> On 10/06/16 15:23, Ville Syrjälä wrote:
> > On Fri, Jun 10, 2016 at 03:08:18PM +0300, Tomi Valkeinen wrote:
> >> On 10/06/16 15:05, Ville Syrjälä wrote:
> >>
> >>>> I'm not sure what's the common way, but tilcdc doesn't support alpha.
> >>>> ARGB works, of course, by ignoring A, but... If an userspace app creates
> >>>> ARGB buffer, does the app expect alpha to work?
> >>>
> >>> I think what we decided a while ago (at least for i915, but would be good
> >>> to use the same convention everywhere) was that ARGB will be assumed to be
> >>> pre-multiplied and will enable blending using 1.0*sc+(1.0-sa)*dc as the
> >>> function. There have been some efforts at defining some new properties to
> >>> control the blend equation, but I guess those got bogged down again.
> >>
> >> Ok, but that's a bit different topic. The question here is, if the HW
> >> doesn't support alpha (no planes, so nothing to blend), should it accept
> >> ARGB or not.
> > 
> > What do you mean "no planes"? You have to have a plane if you want
> > to scanout a framebuffer. And even if you have just one plane with
> > alpha blending, it should be blended with the background color
> > (which is black until we get a property to change it).
> 
> I mean there's only the crtc with fb. So yes, one plane if you want to
> call that a plane.

We do ;)

> The HW does not support any kind of blending to black
> or to anything else.

Right. Then formats with alpha shouldn't be advertized.

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 12:29             ` Ville Syrjälä
@ 2016-06-10 12:48               ` Tomi Valkeinen
  2016-06-10 13:08                 ` Tomi Valkeinen
  0 siblings, 1 reply; 49+ messages in thread
From: Tomi Valkeinen @ 2016-06-10 12:48 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, Jyri Sarha, Laurent Pinchart, dri-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 340 bytes --]

On 10/06/16 15:29, Ville Syrjälä wrote:

>> The HW does not support any kind of blending to black
>> or to anything else.
> 
> Right. Then formats with alpha shouldn't be advertized.

I don't think tilcdc does. It comes from the DRM core. With universal
planes this will be fixed as the driver can define the formats.

 Tomi


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 12:48               ` Tomi Valkeinen
@ 2016-06-10 13:08                 ` Tomi Valkeinen
  2016-06-10 13:16                   ` Jyri Sarha
  0 siblings, 1 reply; 49+ messages in thread
From: Tomi Valkeinen @ 2016-06-10 13:08 UTC (permalink / raw)
  To: Ville Syrjälä, Jyri Sarha
  Cc: Daniel Vetter, Laurent Pinchart, dri-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 666 bytes --]

On 10/06/16 15:48, Tomi Valkeinen wrote:
> On 10/06/16 15:29, Ville Syrjälä wrote:
> 
>>> The HW does not support any kind of blending to black
>>> or to anything else.
>>
>> Right. Then formats with alpha shouldn't be advertized.
> 
> I don't think tilcdc does. It comes from the DRM core. With universal
> planes this will be fixed as the driver can define the formats.

Actually, Jyri told that modetest only reports "RG16 RG24 XR24", which
is correct. I think it did contain AR24 at some point, but maybe I
remember wrong. I have no idea where those come from, though, as they
are not defined in tilcdc (at least not in that form)...

 Tomi


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 13:08                 ` Tomi Valkeinen
@ 2016-06-10 13:16                   ` Jyri Sarha
  2016-06-10 13:25                     ` Ville Syrjälä
  0 siblings, 1 reply; 49+ messages in thread
From: Jyri Sarha @ 2016-06-10 13:16 UTC (permalink / raw)
  To: Tomi Valkeinen, Ville Syrjälä
  Cc: Daniel Vetter, Laurent Pinchart, dri-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 837 bytes --]

On 06/10/16 16:08, Tomi Valkeinen wrote:
> On 10/06/16 15:48, Tomi Valkeinen wrote:
>> On 10/06/16 15:29, Ville Syrjälä wrote:
>>
>>>> The HW does not support any kind of blending to black
>>>> or to anything else.
>>>
>>> Right. Then formats with alpha shouldn't be advertized.
>>
>> I don't think tilcdc does. It comes from the DRM core. With universal
>> planes this will be fixed as the driver can define the formats.
> 
> Actually, Jyri told that modetest only reports "RG16 RG24 XR24", which
> is correct. I think it did contain AR24 at some point, but maybe I
> remember wrong. I have no idea where those come from, though, as they
> are not defined in tilcdc (at least not in that form)...
> 

That was on top of my atomic modeset patches. The current mainline
version reports "XR24 AR24".

BR,
Jyri



[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 13:16                   ` Jyri Sarha
@ 2016-06-10 13:25                     ` Ville Syrjälä
  2016-06-10 14:21                       ` Daniel Vetter
  0 siblings, 1 reply; 49+ messages in thread
From: Ville Syrjälä @ 2016-06-10 13:25 UTC (permalink / raw)
  To: Jyri Sarha; +Cc: Daniel Vetter, Tomi Valkeinen, Laurent Pinchart, dri-devel

On Fri, Jun 10, 2016 at 04:16:06PM +0300, Jyri Sarha wrote:
> On 06/10/16 16:08, Tomi Valkeinen wrote:
> > On 10/06/16 15:48, Tomi Valkeinen wrote:
> >> On 10/06/16 15:29, Ville Syrjälä wrote:
> >>
> >>>> The HW does not support any kind of blending to black
> >>>> or to anything else.
> >>>
> >>> Right. Then formats with alpha shouldn't be advertized.
> >>
> >> I don't think tilcdc does. It comes from the DRM core. With universal
> >> planes this will be fixed as the driver can define the formats.
> > 
> > Actually, Jyri told that modetest only reports "RG16 RG24 XR24", which
> > is correct. I think it did contain AR24 at some point, but maybe I
> > remember wrong. I have no idea where those come from, though, as they
> > are not defined in tilcdc (at least not in that form)...
> > 
> 
> That was on top of my atomic modeset patches. The current mainline
> version reports "XR24 AR24".

Hmm. Oh, I guess we should kill ARGB8888 from safe_modeset_formats[]
and drm_mode_legacy_fb_format(). That should do it I think.

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 09/15] drm: tilcdc: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-10 13:25                     ` Ville Syrjälä
@ 2016-06-10 14:21                       ` Daniel Vetter
  0 siblings, 0 replies; 49+ messages in thread
From: Daniel Vetter @ 2016-06-10 14:21 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, dri-devel, Tomi Valkeinen, Laurent Pinchart, Jyri Sarha

On Fri, Jun 10, 2016 at 04:25:47PM +0300, Ville Syrjälä wrote:
> On Fri, Jun 10, 2016 at 04:16:06PM +0300, Jyri Sarha wrote:
> > On 06/10/16 16:08, Tomi Valkeinen wrote:
> > > On 10/06/16 15:48, Tomi Valkeinen wrote:
> > >> On 10/06/16 15:29, Ville Syrjälä wrote:
> > >>
> > >>>> The HW does not support any kind of blending to black
> > >>>> or to anything else.
> > >>>
> > >>> Right. Then formats with alpha shouldn't be advertized.
> > >>
> > >> I don't think tilcdc does. It comes from the DRM core. With universal
> > >> planes this will be fixed as the driver can define the formats.
> > > 
> > > Actually, Jyri told that modetest only reports "RG16 RG24 XR24", which
> > > is correct. I think it did contain AR24 at some point, but maybe I
> > > remember wrong. I have no idea where those come from, though, as they
> > > are not defined in tilcdc (at least not in that form)...
> > > 
> > 
> > That was on top of my atomic modeset patches. The current mainline
> > version reports "XR24 AR24".
> 
> Hmm. Oh, I guess we should kill ARGB8888 from safe_modeset_formats[]
> and drm_mode_legacy_fb_format(). That should do it I think.

Just convert over to universal planes already, because without those
userspace has no way to figure out what works (except by trying).
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 14/15] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info()
  2016-06-08 23:32 ` [PATCH v3 14/15] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
@ 2016-06-27 17:51   ` Sinclair Yeh
  0 siblings, 0 replies; 49+ messages in thread
From: Sinclair Yeh @ 2016-06-27 17:51 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Thomas Hellstrom, dri-devel, Tomi Valkeinen, VMware Graphics,
	Daniel Vetter

This patch looks good to me:

Reviewed-by: Sinclair Yeh <syeh@vmware.com>

On Thu, Jun 09, 2016 at 02:32:18AM +0300, Laurent Pinchart wrote:
> The driver is the last users of the drm_fb_get_bpp_depth() function. It
> should ideally be converted to use struct drm_mode_fb_cmd2 instead of
> the legacy struct drm_mode_fb_cmd internally, but that will require
> broad changes across the code base. As a first step, replace
> drm_fb_get_bpp_depth() with drm_format_info() in order to stop exporting
> the function to drivers.
> 
> The new DRM_ERROR() message comes from the vmw_create_dmabuf_proxy(),
> vmw_kms_new_framebuffer_surface() and vmw_kms_new_framebuffer_dmabuf()
> functions that currently print an error if the pixel format is
> unsupported.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> Cc: VMware Graphics <linux-graphics-maintainer@vmware.com>
> Cc: Sinclair Yeh <syeh@vmware.com>
> Cc: Thomas Hellstrom <thellstrom@vmware.com>
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> index 55231cce73a0..1a7187f472de 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
> @@ -980,14 +980,22 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
>  	struct vmw_dma_buffer *bo = NULL;
>  	struct ttm_base_object *user_obj;
>  	struct drm_mode_fb_cmd mode_cmd;
> +	const struct drm_format_info *info;
>  	int ret;
>  
> +	info = drm_format_info(mode_cmd2->pixel_format);
> +	if (!info || !info->depth) {
> +		DRM_ERROR("Unsupported framebuffer format %s\n",
> +			  drm_get_format_name(mode_cmd2->pixel_format));
> +		return ERR_PTR(-EINVAL);
> +	}
> +
>  	mode_cmd.width = mode_cmd2->width;
>  	mode_cmd.height = mode_cmd2->height;
>  	mode_cmd.pitch = mode_cmd2->pitches[0];
>  	mode_cmd.handle = mode_cmd2->handles[0];
> -	drm_fb_get_bpp_depth(mode_cmd2->pixel_format, &mode_cmd.depth,
> -				    &mode_cmd.bpp);
> +	mode_cmd.depth = info->depth;
> +	mode_cmd.bpp = info->cpp[0] * 8;
>  
>  	/**
>  	 * This code should be conditioned on Screen Objects not being used.
> -- 
> Regards,
> 
> Laurent Pinchart
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 08/15] drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-06-09  9:01   ` Liviu Dudau
@ 2016-07-25 11:10     ` Liviu Dudau
  2016-09-08 14:45       ` Laurent Pinchart
  0 siblings, 1 reply; 49+ messages in thread
From: Liviu Dudau @ 2016-07-25 11:10 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Daniel Vetter, Tomi Valkeinen, dri-devel

On Thu, Jun 09, 2016 at 10:01:40AM +0100, Liviu Dudau wrote:
> On Thu, Jun 09, 2016 at 02:32:12AM +0300, Laurent Pinchart wrote:
> > The driver needs the number of bytes per pixel, not the bpp and depth
> > info meant for fbdev compatibility. Use the right API.
> > 
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/gpu/drm/arm/hdlcd_crtc.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> > 
> > Cc: Liviu Dudau <liviu.dudau@arm.com>
> 
> Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>
> 
> Thanks for the cleanup!
> 
> Best regards,
> Liviu

Hi Laurent,

What is the status of this patchset? Are you going to send it for v4.8?


Best regards,
Liviu

> 
> > 
> > diff --git a/drivers/gpu/drm/arm/hdlcd_crtc.c b/drivers/gpu/drm/arm/hdlcd_crtc.c
> > index 0813c2f06931..b93a4ce01c50 100644
> > --- a/drivers/gpu/drm/arm/hdlcd_crtc.c
> > +++ b/drivers/gpu/drm/arm/hdlcd_crtc.c
> > @@ -242,14 +242,12 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane,
> >  {
> >  	struct hdlcd_drm_private *hdlcd;
> >  	struct drm_gem_cma_object *gem;
> > -	unsigned int depth, bpp;
> >  	u32 src_w, src_h, dest_w, dest_h;
> >  	dma_addr_t scanout_start;
> >  
> >  	if (!plane->state->fb)
> >  		return;
> >  
> > -	drm_fb_get_bpp_depth(plane->state->fb->pixel_format, &depth, &bpp);
> >  	src_w = plane->state->src_w >> 16;
> >  	src_h = plane->state->src_h >> 16;
> >  	dest_w = plane->state->crtc_w;
> > @@ -257,7 +255,8 @@ static void hdlcd_plane_atomic_update(struct drm_plane *plane,
> >  	gem = drm_fb_cma_get_gem_obj(plane->state->fb, 0);
> >  	scanout_start = gem->paddr + plane->state->fb->offsets[0] +
> >  		plane->state->crtc_y * plane->state->fb->pitches[0] +
> > -		plane->state->crtc_x * bpp / 8;
> > +		plane->state->crtc_x *
> > +		drm_format_plane_cpp(plane->state->fb->pixel_format, 0);
> >  
> >  	hdlcd = plane->dev->dev_private;
> >  	hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, plane->state->fb->pitches[0]);
> > -- 
> > Regards,
> > 
> > Laurent Pinchart
> > 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 02/15] drm: Centralize format information
  2016-06-09 14:13             ` Ville Syrjälä
@ 2016-09-08 13:49               ` Laurent Pinchart
  0 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-09-08 13:49 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: Daniel Vetter, Tomi Valkeinen, dri-devel

Hello Daniel and Ville,

On Thursday 09 Jun 2016 17:13:15 Ville Syrjälä wrote:
> On Thu, Jun 09, 2016 at 03:29:10PM +0200, Daniel Vetter wrote:
> > On Thu, Jun 09, 2016 at 04:05:11PM +0300, Ville Syrjälä wrote:
> >> On Thu, Jun 09, 2016 at 02:40:28PM +0200, Daniel Vetter wrote:
> >>> On Thu, Jun 09, 2016 at 03:23:17PM +0300, Ville Syrjälä wrote:
> >>>> On Thu, Jun 09, 2016 at 10:52:23AM +0200, Daniel Vetter wrote:
> >>>>> On Thu, Jun 09, 2016 at 02:32:06AM +0300, Laurent Pinchart wrote:
> >>>>>> Various pieces of information about DRM formats (number of
> >>>>>> planes, color depth, chroma subsampling, ...) are scattered
> >>>>>> across different helper functions in the DRM core. Callers of
> >>>>>> those functions often need to access more than a single
> >>>>>> parameter of the format, leading to
> >>>>>> inefficiencies due to multiple lookups.
> >>>>>> 
> >>>>>> Centralize all format information in a data structure and create
> >>>>>> a function to look up information based on the format 4CC.
> >>>>>> 
> >>>>>> Signed-off-by: Laurent Pinchart
> >>>>>> <laurent.pinchart@ideasonboard.com>
> >>>>>> ---
> >>>>>> 
> >>>>>>  drivers/gpu/drm/drm_fourcc.c | 84 ++++++++++++++++++++++++++++
> >>>>>>  include/drm/drm_fourcc.h     | 19 ++++++++++
> >>>>>>  2 files changed, 103 insertions(+)
> >>>>>> 
> >>>>>> diff --git a/drivers/gpu/drm/drm_fourcc.c
> >>>>>> b/drivers/gpu/drm/drm_fourcc.c
> >>>>>> index 0645c85d5f95..47b9abd743be 100644
> >>>>>> --- a/drivers/gpu/drm/drm_fourcc.c
> >>>>>> +++ b/drivers/gpu/drm/drm_fourcc.c
> >>>>>> @@ -62,6 +62,90 @@ const char *drm_get_format_name(uint32_t
> >>>>>> format)
> >>>>>> 
> >>>>>>  EXPORT_SYMBOL(drm_get_format_name);
> >>>>>>  
> >>>>>>  /**
> >>>>>> + * drm_format_info - query information for a given format
> >>>>>> + * @format: pixel format (DRM_FORMAT_*)
> >>>>>> + *
> >>>>>> + * Returns:
> >>>>>> + * The instance of struct drm_format_info that describes the pixel
> >>>>>> format, or
> >>>>>> + * NULL if the format is unsupported.
> >>>>>> + */
> >>>>>> +const struct drm_format_info *drm_format_info(u32 format)
> >>>>> 
> >>>>> Bikeshed on your pixel format description table.

As much as I like a good bikeshed myself, we haven't reached a conclusion 
here, so I'll keep the current approach until someone proposes something 
better :-)

> >>>>> I think the
> >>>>> approach I've seen in gallium/mesa to describe pixel formats is a
> >>>>> lot more generic, and we might as well adopt it when we change.
> >>>>> Idea is to have a block size measure in pixels (both h and v), and
> >>>>> then cpp is bytes_per_block. This is essentially what you have
> >>>>> with hsub and vsub already, except confusing names, more ill-
> >>>>> defined (since it only makes sense for yuv) and less generic. A
> >>>>> few examples:
> >>>>
> >>>> I think you have your confusion backwards. Calling something a block
> >>>> in planar formats would be more confusing. The only thing that
> >>>> really matters is the relative position of the samples between the
> >>>> planes. So there really is no "block" in there.
> >>> 
> >>> Atm U/V planes have a cpp of 1, which is definitely not true. There's
> >>> much less than 1 byte per visible pixel in those planes. And that's
> >>> the part that annoys me.
> >> 
> >> That's exactly as it should be. The cpp value isn't some average thing
> >> for the whole, it's per-plane.
> > 
> > On a 4x subsampled U or V plane you have 1 byte for 4 pixels. That's just
> > plain not 1 character-per-pixel, even when you just look at that plane.
> 
> OK. So let's stop calling it a pixel and call it a sample instead.
> It's 1 byte per sample, which is the only thing that should matter
> to anyone.
> 
> >>> block here is an entirely free-standing concept that just means "group
> >>> of pixels over which the bytes-per-group is counted in each group".
> >>> It's a concept stolen from gallium and makes a lot more sense when
> >>> talking about compressed formats. But I think it also makes sense when
> >>> talking about yuv formats.
> >> 
> >> For packed YUV formats the usual term I've heard is macropixel, and
> >> there it does make sense. I could live with calling it a block. So I
> >> guess eg. for 422 packed formats we'd have h_block_size=2
> >> v_block_size=1, and bytes_per_block=4.
> >> 
> >> For planar formats, each plane should be considered individually,
> >> and trying to come up with some kind of cpp value etc. for the whole
> >> thing is pointless. I think eg. with for all the NVxx formats the
> >> chroma plane should have h_block_size=2 v_block_size=1 bytes_per_block=2
> >> regardless the sub-sampling factor.
> 
> Actually meant to write h_block_size=1 here obviously. 1 sample of
> each chroma component, 2 bytes in total.
> 
> > Hm yeah NV12 is a case where 2 have 2 bytes per 2 pixel block (since
> > they're together in 1 2ndary plane), but still a subsampling of 2x. Maybe
> > we'd need both? And then perhaps define subsampling per color channel, but
> > block size and bytes-per-block per plane?
> 
> Well given all the formats we have today, it's always chroma that's
> sub-sampled. I guess if we were to have a more complicated mix of
> planes that may or may not be sub-sampled then it might make sense to
> define things in a more complicated way. Right now I don't see any
> need for that though.

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH v3 08/15] drm: hdlcd: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp()
  2016-07-25 11:10     ` Liviu Dudau
@ 2016-09-08 14:45       ` Laurent Pinchart
  0 siblings, 0 replies; 49+ messages in thread
From: Laurent Pinchart @ 2016-09-08 14:45 UTC (permalink / raw)
  To: Liviu Dudau; +Cc: Daniel Vetter, Tomi Valkeinen, dri-devel

Hi Liviu,

On Monday 25 Jul 2016 12:10:24 Liviu Dudau wrote:
> On Thu, Jun 09, 2016 at 10:01:40AM +0100, Liviu Dudau wrote:
> > On Thu, Jun 09, 2016 at 02:32:12AM +0300, Laurent Pinchart wrote:
> > > The driver needs the number of bytes per pixel, not the bpp and depth
> > > info meant for fbdev compatibility. Use the right API.
> > > 
> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > ---
> > > 
> > >  drivers/gpu/drm/arm/hdlcd_crtc.c | 5 ++---
> > >  1 file changed, 2 insertions(+), 3 deletions(-)
> > > 
> > > Cc: Liviu Dudau <liviu.dudau@arm.com>
> > 
> > Acked-by: Liviu Dudau <Liviu.Dudau@arm.com>
> > 
> > Thanks for the cleanup!
> > 
> > Best regards,
> > Liviu
> 
> Hi Laurent,
> 
> What is the status of this patchset? Are you going to send it for v4.8?

I'm afraid not :-) I have just sent a rebased version (v4).

-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2016-09-08 14:44 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-08 23:32 [PATCH v3 00/15] Centralize format information Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 01/15] drm: Move format-related helpers to drm_fourcc.c Laurent Pinchart
2016-06-09  8:36   ` Daniel Vetter
2016-06-09  9:54     ` [PATCH v3.1 " Laurent Pinchart
2016-06-09 10:03       ` Daniel Vetter
2016-06-08 23:32 ` [PATCH v3 02/15] drm: Centralize format information Laurent Pinchart
2016-06-09  8:52   ` Daniel Vetter
2016-06-09 12:23     ` Ville Syrjälä
2016-06-09 12:40       ` Daniel Vetter
2016-06-09 13:05         ` Ville Syrjälä
2016-06-09 13:29           ` Daniel Vetter
2016-06-09 14:13             ` Ville Syrjälä
2016-09-08 13:49               ` Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 03/15] drm: Implement the drm_format_*() helpers as drm_format_info() wrappers Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 04/15] drm: Use drm_format_info() in DRM core code Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 05/15] drm: WARN when calling drm_format_info() for an unsupported format Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 06/15] drm: msm: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 07/15] drm: sti: " Laurent Pinchart
2016-06-09  7:52   ` Vincent ABRIOU
2016-06-09  9:17     ` Laurent Pinchart
2016-06-09 12:10       ` Vincent ABRIOU
2016-06-08 23:32 ` [PATCH v3 08/15] drm: hdlcd: " Laurent Pinchart
2016-06-09  9:01   ` Liviu Dudau
2016-07-25 11:10     ` Liviu Dudau
2016-09-08 14:45       ` Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 09/15] drm: tilcdc: " Laurent Pinchart
2016-06-10 11:51   ` Tomi Valkeinen
2016-06-10 12:05     ` Ville Syrjälä
2016-06-10 12:08       ` Tomi Valkeinen
2016-06-10 12:23         ` Ville Syrjälä
2016-06-10 12:26           ` Tomi Valkeinen
2016-06-10 12:29             ` Ville Syrjälä
2016-06-10 12:48               ` Tomi Valkeinen
2016-06-10 13:08                 ` Tomi Valkeinen
2016-06-10 13:16                   ` Jyri Sarha
2016-06-10 13:25                     ` Ville Syrjälä
2016-06-10 14:21                       ` Daniel Vetter
2016-06-10 12:07     ` Laurent Pinchart
2016-06-10 12:08     ` [PATCH v3.1 " Laurent Pinchart
2016-06-10 12:21       ` Tomi Valkeinen
2016-06-08 23:32 ` [PATCH v3 10/15] drm: cirrus: " Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 11/15] drm: gma500: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 12/15] drm: amdgpu: Replace drm_fb_get_bpp_depth() with drm_format_plane_cpp() Laurent Pinchart
2016-06-09  1:42   ` Michel Dänzer
2016-06-09  9:18     ` Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 13/15] drm: radeon: " Laurent Pinchart
2016-06-08 23:32 ` [PATCH v3 14/15] drm: vmwgfx: Replace drm_fb_get_bpp_depth() with drm_format_info() Laurent Pinchart
2016-06-27 17:51   ` Sinclair Yeh
2016-06-08 23:32 ` [PATCH v3 15/15] drm: Don't export the drm_fb_get_bpp_depth() function Laurent Pinchart

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.