linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] drm: fourcc byteorder: drop DRM_FORMAT_BIG_ENDIAN
       [not found] <20170424062532.26722-1-kraxel@redhat.com>
@ 2017-04-24  6:25 ` Gerd Hoffmann
  2017-04-24  6:25 ` [PATCH 2/6] drm: fourcc byteorder: add DRM_FORMAT_CPU_* Gerd Hoffmann
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-24  6:25 UTC (permalink / raw)
  To: dri-devel
  Cc: Ville Syrjälä,
	Daniel Vetter, Pekka Paalanen, Ilia Mirkin, Michel Dänzer,
	Alex Deucher, amd-gfx, Jani Nikula, Sean Paul, David Airlie,
	Gerd Hoffmann, open list

It's unused.

Suggested-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/uapi/drm/drm_fourcc.h     | 2 --
 drivers/gpu/drm/drm_fourcc.c      | 3 +--
 drivers/gpu/drm/drm_framebuffer.c | 2 +-
 3 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
index 995c8f9c69..305bc34be0 100644
--- a/include/uapi/drm/drm_fourcc.h
+++ b/include/uapi/drm/drm_fourcc.h
@@ -33,8 +33,6 @@ extern "C" {
 #define fourcc_code(a, b, c, d) ((__u32)(a) | ((__u32)(b) << 8) | \
 				 ((__u32)(c) << 16) | ((__u32)(d) << 24))
 
-#define DRM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */
-
 /* color index */
 #define DRM_FORMAT_C8		fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
 
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index 9c0152df45..adb3ff59a4 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -86,12 +86,11 @@ EXPORT_SYMBOL(drm_mode_legacy_fb_format);
 const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf)
 {
 	snprintf(buf->str, sizeof(buf->str),
-		 "%c%c%c%c %s-endian (0x%08x)",
+		 "%c%c%c%c (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->str;
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index fc8ef42203..efe8b5ece5 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -152,7 +152,7 @@ static int framebuffer_check(struct drm_device *dev,
 	int i;
 
 	/* check if the format is supported at all */
-	info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
+	info = __drm_format_info(r->pixel_format);
 	if (!info) {
 		struct drm_format_name_buf format_name;
 		DRM_DEBUG_KMS("bad framebuffer format %s\n",
-- 
2.9.3

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

* [PATCH 2/6] drm: fourcc byteorder: add DRM_FORMAT_CPU_*
       [not found] <20170424062532.26722-1-kraxel@redhat.com>
  2017-04-24  6:25 ` [PATCH 1/6] drm: fourcc byteorder: drop DRM_FORMAT_BIG_ENDIAN Gerd Hoffmann
@ 2017-04-24  6:25 ` Gerd Hoffmann
  2017-04-24  6:25 ` [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format Gerd Hoffmann
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-24  6:25 UTC (permalink / raw)
  To: dri-devel
  Cc: Ville Syrjälä,
	Daniel Vetter, Pekka Paalanen, Ilia Mirkin, Michel Dänzer,
	Alex Deucher, amd-gfx, Jani Nikula, Sean Paul, David Airlie,
	Gerd Hoffmann, open list

Add fourcc variants in cpu byte order.  With these at hand we don't
need #ifdefs in drivers want support framebuffers in cpu endianess.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/drm/drm_fourcc.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index 6942e84b6e..cae05153e8 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -25,6 +25,18 @@
 #include <linux/types.h>
 #include <uapi/drm/drm_fourcc.h>
 
+/*
+ * DRM formats are little endian.  define cpu endian variants here, to
+ * reduce the #ifdefs needed in drivers.
+ */
+#ifdef __BIG_ENDIAN
+# define DRM_FORMAT_CPU_XRGB8888 DRM_FORMAT_BGRX8888
+# define DRM_FORMAT_CPU_ARGB8888 DRM_FORMAT_BGRA8888
+#else
+# define DRM_FORMAT_CPU_XRGB8888 DRM_FORMAT_XRGB8888
+# define DRM_FORMAT_CPU_ARGB8888 DRM_FORMAT_ARGB8888
+#endif
+
 struct drm_device;
 struct drm_mode_fb_cmd2;
 
-- 
2.9.3

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

* [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
       [not found] <20170424062532.26722-1-kraxel@redhat.com>
  2017-04-24  6:25 ` [PATCH 1/6] drm: fourcc byteorder: drop DRM_FORMAT_BIG_ENDIAN Gerd Hoffmann
  2017-04-24  6:25 ` [PATCH 2/6] drm: fourcc byteorder: add DRM_FORMAT_CPU_* Gerd Hoffmann
@ 2017-04-24  6:25 ` Gerd Hoffmann
  2017-04-25  3:18   ` Michel Dänzer
  2017-04-24  6:25 ` [PATCH 4/6] drm: fourcc byteorder: adapt bochs-drm to drm_mode_legacy_fb_format update Gerd Hoffmann
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-24  6:25 UTC (permalink / raw)
  To: dri-devel
  Cc: Ville Syrjälä,
	Daniel Vetter, Pekka Paalanen, Ilia Mirkin, Michel Dänzer,
	Alex Deucher, amd-gfx, Jani Nikula, Sean Paul, David Airlie,
	Gerd Hoffmann, open list

Return correct fourcc codes on bigendian.  Drivers must be adapted to
this change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/drm_fourcc.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index adb3ff59a4..28401d3745 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -42,11 +42,34 @@ static char printable_char(int c)
  *
  * Computes a drm fourcc pixel format code for the given @bpp/@depth values.
  * Useful in fbdev emulation code, since that deals in those values.
+ *
+ * DRM_FORMAT_* are little endian, we'll pick cpu endian here, therefore we
+ * results differ depending on byte order.
  */
 uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 {
 	uint32_t fmt;
 
+#ifdef __BIG_ENDIAN
+	switch (bpp) {
+	case 8:
+		fmt = DRM_FORMAT_C8;
+		break;
+	case 24:
+		fmt = DRM_FORMAT_BGR888;
+		break;
+	case 32:
+		if (depth == 24)
+			fmt = DRM_FORMAT_BGRX8888;
+		else
+			fmt = DRM_FORMAT_BGRA8888;
+		break;
+	default:
+		DRM_ERROR("bad bpp, assuming b8g8r8x8 pixel format\n");
+		fmt = DRM_FORMAT_BGRX8888;
+		break;
+	}
+#else
 	switch (bpp) {
 	case 8:
 		fmt = DRM_FORMAT_C8;
@@ -73,6 +96,7 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
 		fmt = DRM_FORMAT_XRGB8888;
 		break;
 	}
+#endif
 
 	return fmt;
 }
-- 
2.9.3

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

* [PATCH 4/6] drm: fourcc byteorder: adapt bochs-drm to drm_mode_legacy_fb_format update
       [not found] <20170424062532.26722-1-kraxel@redhat.com>
                   ` (2 preceding siblings ...)
  2017-04-24  6:25 ` [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format Gerd Hoffmann
@ 2017-04-24  6:25 ` Gerd Hoffmann
  2017-04-24  6:25 ` [PATCH 5/6] drm: fourcc byteorder: adapt virtio " Gerd Hoffmann
  2017-04-24  6:25 ` [PATCH 6/6] drm: fourcc byteorder: virtio restrict to XRGB8888 Gerd Hoffmann
  5 siblings, 0 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-24  6:25 UTC (permalink / raw)
  To: dri-devel
  Cc: Ville Syrjälä,
	Daniel Vetter, Pekka Paalanen, Ilia Mirkin, Michel Dänzer,
	Alex Deucher, amd-gfx, Jani Nikula, Sean Paul, David Airlie,
	Gerd Hoffmann, open list:DRM DRIVER FOR BOCHS VIRTUAL GPU,
	open list

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/bochs/bochs_mm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bochs/bochs_mm.c b/drivers/gpu/drm/bochs/bochs_mm.c
index 857755ac2d..781d35bdff 100644
--- a/drivers/gpu/drm/bochs/bochs_mm.c
+++ b/drivers/gpu/drm/bochs/bochs_mm.c
@@ -508,7 +508,7 @@ bochs_user_framebuffer_create(struct drm_device *dev,
 	       (mode_cmd->pixel_format >> 16) & 0xff,
 	       (mode_cmd->pixel_format >> 24) & 0xff);
 
-	if (mode_cmd->pixel_format != DRM_FORMAT_XRGB8888)
+	if (mode_cmd->pixel_format != DRM_FORMAT_CPU_XRGB8888)
 		return ERR_PTR(-ENOENT);
 
 	obj = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
-- 
2.9.3

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

* [PATCH 5/6] drm: fourcc byteorder: adapt virtio to drm_mode_legacy_fb_format update
       [not found] <20170424062532.26722-1-kraxel@redhat.com>
                   ` (3 preceding siblings ...)
  2017-04-24  6:25 ` [PATCH 4/6] drm: fourcc byteorder: adapt bochs-drm to drm_mode_legacy_fb_format update Gerd Hoffmann
@ 2017-04-24  6:25 ` Gerd Hoffmann
  2017-04-24  6:25 ` [PATCH 6/6] drm: fourcc byteorder: virtio restrict to XRGB8888 Gerd Hoffmann
  5 siblings, 0 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-24  6:25 UTC (permalink / raw)
  To: dri-devel
  Cc: Ville Syrjälä,
	Daniel Vetter, Pekka Paalanen, Ilia Mirkin, Michel Dänzer,
	Alex Deucher, amd-gfx, Jani Nikula, Sean Paul, David Airlie,
	Gerd Hoffmann, open list:VIRTIO GPU DRIVER, open list

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/virtio/virtgpu_gem.c   |  2 +-
 drivers/gpu/drm/virtio/virtgpu_plane.c | 31 -------------------------------
 2 files changed, 1 insertion(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c
index cc025d8fbe..4f2c2dc731 100644
--- a/drivers/gpu/drm/virtio/virtgpu_gem.c
+++ b/drivers/gpu/drm/virtio/virtgpu_gem.c
@@ -99,7 +99,7 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
 	if (ret)
 		goto fail;
 
-	format = virtio_gpu_translate_format(DRM_FORMAT_XRGB8888);
+	format = virtio_gpu_translate_format(DRM_FORMAT_CPU_XRGB8888);
 	virtio_gpu_resource_id_get(vgdev, &resid);
 	virtio_gpu_cmd_create_resource(vgdev, resid, format,
 				       args->width, args->height);
diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c
index adcdbd0abe..f40ffc9a70 100644
--- a/drivers/gpu/drm/virtio/virtgpu_plane.c
+++ b/drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -39,11 +39,7 @@ static const uint32_t virtio_gpu_formats[] = {
 };
 
 static const uint32_t virtio_gpu_cursor_formats[] = {
-#ifdef __BIG_ENDIAN
-	DRM_FORMAT_BGRA8888,
-#else
 	DRM_FORMAT_ARGB8888,
-#endif
 };
 
 uint32_t virtio_gpu_translate_format(uint32_t drm_fourcc)
@@ -51,32 +47,6 @@ uint32_t virtio_gpu_translate_format(uint32_t drm_fourcc)
 	uint32_t format;
 
 	switch (drm_fourcc) {
-#ifdef __BIG_ENDIAN
-	case DRM_FORMAT_XRGB8888:
-		format = VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM;
-		break;
-	case DRM_FORMAT_ARGB8888:
-		format = VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM;
-		break;
-	case DRM_FORMAT_BGRX8888:
-		format = VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM;
-		break;
-	case DRM_FORMAT_BGRA8888:
-		format = VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM;
-		break;
-	case DRM_FORMAT_RGBX8888:
-		format = VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM;
-		break;
-	case DRM_FORMAT_RGBA8888:
-		format = VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM;
-		break;
-	case DRM_FORMAT_XBGR8888:
-		format = VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM;
-		break;
-	case DRM_FORMAT_ABGR8888:
-		format = VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM;
-		break;
-#else
 	case DRM_FORMAT_XRGB8888:
 		format = VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM;
 		break;
@@ -101,7 +71,6 @@ uint32_t virtio_gpu_translate_format(uint32_t drm_fourcc)
 	case DRM_FORMAT_ABGR8888:
 		format = VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM;
 		break;
-#endif
 	default:
 		/*
 		 * This should not happen, we handle everything listed
-- 
2.9.3

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

* [PATCH 6/6] drm: fourcc byteorder: virtio restrict to XRGB8888
       [not found] <20170424062532.26722-1-kraxel@redhat.com>
                   ` (4 preceding siblings ...)
  2017-04-24  6:25 ` [PATCH 5/6] drm: fourcc byteorder: adapt virtio " Gerd Hoffmann
@ 2017-04-24  6:25 ` Gerd Hoffmann
  5 siblings, 0 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-24  6:25 UTC (permalink / raw)
  To: dri-devel
  Cc: Ville Syrjälä,
	Daniel Vetter, Pekka Paalanen, Ilia Mirkin, Michel Dänzer,
	Alex Deucher, amd-gfx, Jani Nikula, Sean Paul, David Airlie,
	Gerd Hoffmann, open list:VIRTIO GPU DRIVER, open list

While wading through the code I've noticed we have a little issue in
virtio:  We attach a format to the bo when it is created
(DRM_IOCTL_MODE_CREATE_DUMB), not when we map it as framebuffer
(DRM_IOCTL_MODE_ADDFB).

Easy way out:  support a single format only.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 drivers/gpu/drm/virtio/virtgpu_gem.c   | 5 ++++-
 drivers/gpu/drm/virtio/virtgpu_plane.c | 9 +--------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c
index 4f2c2dc731..b09e5e5ae4 100644
--- a/drivers/gpu/drm/virtio/virtgpu_gem.c
+++ b/drivers/gpu/drm/virtio/virtgpu_gem.c
@@ -90,7 +90,10 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
 	uint32_t resid;
 	uint32_t format;
 
-	pitch = args->width * ((args->bpp + 1) / 8);
+	if (args->bpp != 32)
+		return -EINVAL;
+
+	pitch = args->width * 4;
 	args->size = pitch * args->height;
 	args->size = ALIGN(args->size, PAGE_SIZE);
 
diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c
index f40ffc9a70..3a4498a223 100644
--- a/drivers/gpu/drm/virtio/virtgpu_plane.c
+++ b/drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -28,14 +28,7 @@
 #include <drm/drm_atomic_helper.h>
 
 static const uint32_t virtio_gpu_formats[] = {
-	DRM_FORMAT_XRGB8888,
-	DRM_FORMAT_ARGB8888,
-	DRM_FORMAT_BGRX8888,
-	DRM_FORMAT_BGRA8888,
-	DRM_FORMAT_RGBX8888,
-	DRM_FORMAT_RGBA8888,
-	DRM_FORMAT_XBGR8888,
-	DRM_FORMAT_ABGR8888,
+	DRM_FORMAT_CPU_XRGB8888,
 };
 
 static const uint32_t virtio_gpu_cursor_formats[] = {
-- 
2.9.3

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-24  6:25 ` [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format Gerd Hoffmann
@ 2017-04-25  3:18   ` Michel Dänzer
  2017-04-25  9:52     ` Ville Syrjälä
  2017-04-26  5:53     ` Gerd Hoffmann
  0 siblings, 2 replies; 19+ messages in thread
From: Michel Dänzer @ 2017-04-25  3:18 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: dri-devel, open list, amd-gfx, Daniel Vetter

On 24/04/17 03:25 PM, Gerd Hoffmann wrote:
> Return correct fourcc codes on bigendian.  Drivers must be adapted to
> this change.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Just to reiterate, this won't work for the radeon driver, which programs
the GPU to use (effectively, per the current definition that these are
little endian GPU formats) DRM_FORMAT_XRGB8888 with pre-R600 and
DRM_FORMAT_BGRX8888 with >= R600.


> +#ifdef __BIG_ENDIAN
> +	switch (bpp) {
> +	case 8:
> +		fmt = DRM_FORMAT_C8;
> +		break;
> +	case 24:
> +		fmt = DRM_FORMAT_BGR888;
> +		break;

BTW, endianness as a concept cannot apply to 8 or 24 bpp formats.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-25  3:18   ` Michel Dänzer
@ 2017-04-25  9:52     ` Ville Syrjälä
  2017-04-26  2:00       ` Michel Dänzer
  2017-04-26  5:53     ` Gerd Hoffmann
  1 sibling, 1 reply; 19+ messages in thread
From: Ville Syrjälä @ 2017-04-25  9:52 UTC (permalink / raw)
  To: Michel Dänzer
  Cc: Gerd Hoffmann, Daniel Vetter, amd-gfx, open list, dri-devel

On Tue, Apr 25, 2017 at 12:18:52PM +0900, Michel Dänzer wrote:
> On 24/04/17 03:25 PM, Gerd Hoffmann wrote:
> > Return correct fourcc codes on bigendian.  Drivers must be adapted to
> > this change.
> > 
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> 
> Just to reiterate, this won't work for the radeon driver, which programs
> the GPU to use (effectively, per the current definition that these are
> little endian GPU formats) DRM_FORMAT_XRGB8888 with pre-R600 and
> DRM_FORMAT_BGRX8888 with >= R600.
> 
> 
> > +#ifdef __BIG_ENDIAN
> > +	switch (bpp) {
> > +	case 8:
> > +		fmt = DRM_FORMAT_C8;
> > +		break;
> > +	case 24:
> > +		fmt = DRM_FORMAT_BGR888;
> > +		break;
> 
> BTW, endianness as a concept cannot apply to 8 or 24 bpp formats.

To 8bpp no, but it can easily apply to 24bpp. Same was as it applies to
16bpp. Neither matches the word size of the CPU or anything like that
but still the bytes have to stored in memory in some order.

-- 
Ville Syrjälä
Intel OTC

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-25  9:52     ` Ville Syrjälä
@ 2017-04-26  2:00       ` Michel Dänzer
  2017-04-26 14:30         ` Ville Syrjälä
  0 siblings, 1 reply; 19+ messages in thread
From: Michel Dänzer @ 2017-04-26  2:00 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Daniel Vetter, dri-devel, Gerd Hoffmann, amd-gfx, open list

On 25/04/17 06:52 PM, Ville Syrjälä wrote:
> On Tue, Apr 25, 2017 at 12:18:52PM +0900, Michel Dänzer wrote:
>> On 24/04/17 03:25 PM, Gerd Hoffmann wrote:
>>> +#ifdef __BIG_ENDIAN
>>> +	switch (bpp) {
>>> +	case 8:
>>> +		fmt = DRM_FORMAT_C8;
>>> +		break;
>>> +	case 24:
>>> +		fmt = DRM_FORMAT_BGR888;
>>> +		break;
>>
>> BTW, endianness as a concept cannot apply to 8 or 24 bpp formats.
> 
> To 8bpp no, but it can easily apply to 24bpp.

Any byte swapping rips apart the bytes of a 24bpp pixel, so those
formats only make sense as straight array formats.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-25  3:18   ` Michel Dänzer
  2017-04-25  9:52     ` Ville Syrjälä
@ 2017-04-26  5:53     ` Gerd Hoffmann
  2017-04-26  9:21       ` Michel Dänzer
  2017-04-26 13:28       ` Eric Engestrom
  1 sibling, 2 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-26  5:53 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: dri-devel, open list, amd-gfx, Daniel Vetter

On Di, 2017-04-25 at 12:18 +0900, Michel Dänzer wrote:
> On 24/04/17 03:25 PM, Gerd Hoffmann wrote:
> > Return correct fourcc codes on bigendian.  Drivers must be adapted to
> > this change.
> > 
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> 
> Just to reiterate, this won't work for the radeon driver, which programs
> the GPU to use (effectively, per the current definition that these are
> little endian GPU formats) DRM_FORMAT_XRGB8888 with pre-R600 and
> DRM_FORMAT_BGRX8888 with >= R600.

Hmm, ok, how does bigendian fbdev emulation work on pre-R600 then?

> > +#ifdef __BIG_ENDIAN
> > +	switch (bpp) {
> > +	case 8:
> > +		fmt = DRM_FORMAT_C8;
> > +		break;
> > +	case 24:
> > +		fmt = DRM_FORMAT_BGR888;
> > +		break;
> 
> BTW, endianness as a concept cannot apply to 8 or 24 bpp formats.

I could move the 8 bpp case out of the #ifdef somehow, but code
readability will suffer then I think ...

For 24 we have different byte orderings, but yes, you can't switch from
one to the other with byteswapping.  Probably one of the reasons why
this format is pretty much out of fashion these days ...

cheers,
  Gerd

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-26  5:53     ` Gerd Hoffmann
@ 2017-04-26  9:21       ` Michel Dänzer
  2017-04-26 12:11         ` Gerd Hoffmann
  2017-04-26 13:28       ` Eric Engestrom
  1 sibling, 1 reply; 19+ messages in thread
From: Michel Dänzer @ 2017-04-26  9:21 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Daniel Vetter, amd-gfx, open list, dri-devel

On 26/04/17 02:53 PM, Gerd Hoffmann wrote:
> On Di, 2017-04-25 at 12:18 +0900, Michel Dänzer wrote:
>> On 24/04/17 03:25 PM, Gerd Hoffmann wrote:
>>> Return correct fourcc codes on bigendian.  Drivers must be adapted to
>>> this change.
>>>
>>> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>>
>> Just to reiterate, this won't work for the radeon driver, which programs
>> the GPU to use (effectively, per the current definition that these are
>> little endian GPU formats) DRM_FORMAT_XRGB8888 with pre-R600 and
>> DRM_FORMAT_BGRX8888 with >= R600.
> 
> Hmm, ok, how does bigendian fbdev emulation work on pre-R600 then?

Using a GPU byte swapping mechanism which only affects CPU access to
video RAM.


>>> +#ifdef __BIG_ENDIAN
>>> +	switch (bpp) {
>>> +	case 8:
>>> +		fmt = DRM_FORMAT_C8;
>>> +		break;
>>> +	case 24:
>>> +		fmt = DRM_FORMAT_BGR888;
>>> +		break;
>>
>> BTW, endianness as a concept cannot apply to 8 or 24 bpp formats.
> 
> I could move the 8 bpp case out of the #ifdef somehow, but code
> readability will suffer then I think ...

How so?

At least it would make clearer which formats are affected by endianness
and which aren't.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-26  9:21       ` Michel Dänzer
@ 2017-04-26 12:11         ` Gerd Hoffmann
  2017-04-27  0:52           ` Michel Dänzer
  0 siblings, 1 reply; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-26 12:11 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: Daniel Vetter, amd-gfx, open list, dri-devel

  Hi,

> >> Just to reiterate, this won't work for the radeon driver, which programs
> >> the GPU to use (effectively, per the current definition that these are
> >> little endian GPU formats) DRM_FORMAT_XRGB8888 with pre-R600 and
> >> DRM_FORMAT_BGRX8888 with >= R600.
> > 
> > Hmm, ok, how does bigendian fbdev emulation work on pre-R600 then?
> 
> Using a GPU byte swapping mechanism which only affects CPU access to
> video RAM.

That is done using the RADEON_TILING_SWAP_{16,32}BIT flag mentioned in
another thread?

Ok, so the cpu view to fbdev is DRM_FORMAT_BGRX8888 in all cases.

What about dumb bos?  You've mentioned the swap flag isn't used for
those.  Which implies they are in little endian byte order (both gpu and
cpu view).  Does the modesetting driver work correctly on that hardware?

cheers,
  Gerd

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-26  5:53     ` Gerd Hoffmann
  2017-04-26  9:21       ` Michel Dänzer
@ 2017-04-26 13:28       ` Eric Engestrom
  2017-04-26 13:57         ` Gerd Hoffmann
  1 sibling, 1 reply; 19+ messages in thread
From: Eric Engestrom @ 2017-04-26 13:28 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Michel Dänzer, Daniel Vetter, amd-gfx, open list, dri-devel

On Wednesday, 2017-04-26 07:53:10 +0200, Gerd Hoffmann wrote:
> On Di, 2017-04-25 at 12:18 +0900, Michel Dänzer wrote:
> > On 24/04/17 03:25 PM, Gerd Hoffmann wrote:
> > > Return correct fourcc codes on bigendian.  Drivers must be adapted to
> > > this change.
> > > 
> > > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> > 
> > Just to reiterate, this won't work for the radeon driver, which programs
> > the GPU to use (effectively, per the current definition that these are
> > little endian GPU formats) DRM_FORMAT_XRGB8888 with pre-R600 and
> > DRM_FORMAT_BGRX8888 with >= R600.
> 
> Hmm, ok, how does bigendian fbdev emulation work on pre-R600 then?
> 
> > > +#ifdef __BIG_ENDIAN
> > > +	switch (bpp) {
> > > +	case 8:
> > > +		fmt = DRM_FORMAT_C8;
> > > +		break;
> > > +	case 24:
> > > +		fmt = DRM_FORMAT_BGR888;
> > > +		break;
> > 
> > BTW, endianness as a concept cannot apply to 8 or 24 bpp formats.
> 
> I could move the 8 bpp case out of the #ifdef somehow, but code
> readability will suffer then I think ...

How about something like this?

	uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
	{
		uint32_t fmt;
	#ifdef __BIG_ENDIAN
		enum { LITTLE_ENDIAN = 0 };
	#else
		enum { LITTLE_ENDIAN = 1 };
	#endif
	/* ... */

(using an enum for compile-time constness)

and then
	fmt = DRM_FORMAT_ARGB8888;
becomes
	fmt = LITTLE_ENDIAN ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_BGRA8888;

Might be easier to read than duplicating the whole switch?

> 
> For 24 we have different byte orderings, but yes, you can't switch from
> one to the other with byteswapping.  Probably one of the reasons why
> this format is pretty much out of fashion these days ...
> 
> cheers,
>   Gerd
> 

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-26 13:28       ` Eric Engestrom
@ 2017-04-26 13:57         ` Gerd Hoffmann
  0 siblings, 0 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-26 13:57 UTC (permalink / raw)
  To: Eric Engestrom
  Cc: Michel Dänzer, Daniel Vetter, amd-gfx, open list, dri-devel

> 	uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
> 	{
> 		uint32_t fmt;
> 	#ifdef __BIG_ENDIAN
> 		enum { LITTLE_ENDIAN = 0 };
> 	#else
> 		enum { LITTLE_ENDIAN = 1 };
> 	#endif
> 	/* ... */
> 
> (using an enum for compile-time constness)
> 
> and then
> 	fmt = DRM_FORMAT_ARGB8888;
> becomes
> 	fmt = LITTLE_ENDIAN ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_BGRA8888;
> 
> Might be easier to read than duplicating the whole switch?

Well, there are more differences, like rgb565 and xrgb2101010 not being
supported for bigendian, so it isn't *that* simple.

cheers,
  Gerd

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-26  2:00       ` Michel Dänzer
@ 2017-04-26 14:30         ` Ville Syrjälä
  0 siblings, 0 replies; 19+ messages in thread
From: Ville Syrjälä @ 2017-04-26 14:30 UTC (permalink / raw)
  To: Michel Dänzer
  Cc: Daniel Vetter, dri-devel, Gerd Hoffmann, amd-gfx, open list

On Wed, Apr 26, 2017 at 11:00:09AM +0900, Michel Dänzer wrote:
> On 25/04/17 06:52 PM, Ville Syrjälä wrote:
> > On Tue, Apr 25, 2017 at 12:18:52PM +0900, Michel Dänzer wrote:
> >> On 24/04/17 03:25 PM, Gerd Hoffmann wrote:
> >>> +#ifdef __BIG_ENDIAN
> >>> +	switch (bpp) {
> >>> +	case 8:
> >>> +		fmt = DRM_FORMAT_C8;
> >>> +		break;
> >>> +	case 24:
> >>> +		fmt = DRM_FORMAT_BGR888;
> >>> +		break;
> >>
> >> BTW, endianness as a concept cannot apply to 8 or 24 bpp formats.
> > 
> > To 8bpp no, but it can easily apply to 24bpp.
> 
> Any byte swapping rips apart the bytes of a 24bpp pixel, so those
> formats only make sense as straight array formats.

In my book little endian just means "lsb is stored in the lowest
memory address". The fact that your CPU/GPU can't do 3 byte swaps
is not relevant for that definition IMO.

-- 
Ville Syrjälä
Intel OTC

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-26 12:11         ` Gerd Hoffmann
@ 2017-04-27  0:52           ` Michel Dänzer
  2017-04-27  6:45             ` Gerd Hoffmann
  0 siblings, 1 reply; 19+ messages in thread
From: Michel Dänzer @ 2017-04-27  0:52 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Daniel Vetter, dri-devel, open list, amd-gfx

On 26/04/17 09:11 PM, Gerd Hoffmann wrote:
>   Hi,
> 
>>>> Just to reiterate, this won't work for the radeon driver, which programs
>>>> the GPU to use (effectively, per the current definition that these are
>>>> little endian GPU formats) DRM_FORMAT_XRGB8888 with pre-R600 and
>>>> DRM_FORMAT_BGRX8888 with >= R600.
>>>
>>> Hmm, ok, how does bigendian fbdev emulation work on pre-R600 then?
>>
>> Using a GPU byte swapping mechanism which only affects CPU access to
>> video RAM.
> 
> That is done using the RADEON_TILING_SWAP_{16,32}BIT flag mentioned in
> another thread?

Right.


> What about dumb bos?  You've mentioned the swap flag isn't used for
> those.  Which implies they are in little endian byte order (both gpu and
> cpu view).

Right, AFAICT from looking at the code.


> Does the modesetting driver work correctly on that hardware?

Not sure.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-27  0:52           ` Michel Dänzer
@ 2017-04-27  6:45             ` Gerd Hoffmann
  2017-04-27  7:02               ` Michel Dänzer
  0 siblings, 1 reply; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-27  6:45 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: Daniel Vetter, dri-devel, open list, amd-gfx

  Hi,

> > That is done using the RADEON_TILING_SWAP_{16,32}BIT flag mentioned in
> > another thread?
> 
> Right.
> 
> 
> > What about dumb bos?  You've mentioned the swap flag isn't used for
> > those.  Which implies they are in little endian byte order (both gpu and
> > cpu view).
> 
> Right, AFAICT from looking at the code.

Ok.

And I also don't see an easy way to make them big endian (cpu view)
using swapping with the existing drm interfaces, given we apply a format
when we put the bo into use as framebuffer, not when creating it.  So
userspace can: (1) create dumb bo, (2) map bo, (3) write something bo,
(4) create fb + attach to crtc.  And at (3) we don't know the format
yet, so we can't configure swapping accordingly.

So just not using the swapping indeed looks like the only sensible
option.  Which in turn implies there is no BGRA8888 support for dumb
bos.  Hmm, I can see the problem.  Userspace expectation appears to be
that ADDFB configures a native endian framebuffer, which the driver
simply can't do on bigendian.

So, what can/should the driver do here?  Throw errors for ADDFB and
force userspace to use ADDFB2?  From a design point of view the best
option, but in the other hand I suspect that could break the xorg radeon
driver ...

cheers,
  Gerd

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-27  6:45             ` Gerd Hoffmann
@ 2017-04-27  7:02               ` Michel Dänzer
  2017-04-28 10:02                 ` Gerd Hoffmann
  0 siblings, 1 reply; 19+ messages in thread
From: Michel Dänzer @ 2017-04-27  7:02 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Daniel Vetter, amd-gfx, open list, dri-devel

On 27/04/17 03:45 PM, Gerd Hoffmann wrote:
>   Hi,
> 
>>> That is done using the RADEON_TILING_SWAP_{16,32}BIT flag mentioned in
>>> another thread?
>>
>> Right.
>>
>>
>>> What about dumb bos?  You've mentioned the swap flag isn't used for
>>> those.  Which implies they are in little endian byte order (both gpu and
>>> cpu view).
>>
>> Right, AFAICT from looking at the code.
> 
> Ok.
> 
> And I also don't see an easy way to make them big endian (cpu view)
> using swapping with the existing drm interfaces, given we apply a format
> when we put the bo into use as framebuffer, not when creating it.  So
> userspace can: (1) create dumb bo, (2) map bo, (3) write something bo,
> (4) create fb + attach to crtc.  And at (3) we don't know the format
> yet, so we can't configure swapping accordingly.
> 
> So just not using the swapping indeed looks like the only sensible
> option.  Which in turn implies there is no BGRA8888 support for dumb
> bos.  Hmm, I can see the problem.  Userspace expectation appears to be
> that ADDFB configures a native endian framebuffer, which the driver
> simply can't do on bigendian.

... with pre-R600 GPUs.


> So, what can/should the driver do here?  Throw errors for ADDFB and
> force userspace to use ADDFB2?  From a design point of view the best
> option, but in the other hand I suspect that could break the xorg radeon
> driver ...

Yes, it would.

One thing we could do is provide a way for userspace to query the
effective format(s) as seen by the GPU and/or CPU.

It might also make sense for the radeon driver to set the
RADEON_TILING_SWAP_{16,32}BIT flags for dumb BOs. I wonder about the
status of apps using dumb BOs directly wrt this discussion.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

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

* Re: [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format
  2017-04-27  7:02               ` Michel Dänzer
@ 2017-04-28 10:02                 ` Gerd Hoffmann
  0 siblings, 0 replies; 19+ messages in thread
From: Gerd Hoffmann @ 2017-04-28 10:02 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: Daniel Vetter, amd-gfx, open list, dri-devel

  Hi,

> > So just not using the swapping indeed looks like the only sensible
> > option.  Which in turn implies there is no BGRA8888 support for dumb
> > bos.  Hmm, I can see the problem.  Userspace expectation appears to be
> > that ADDFB configures a native endian framebuffer, which the driver
> > simply can't do on bigendian.
> 
> ... with pre-R600 GPUs.

Sure.

> > So, what can/should the driver do here?  Throw errors for ADDFB and
> > force userspace to use ADDFB2?  From a design point of view the best
> > option, but in the other hand I suspect that could break the xorg radeon
> > driver ...
> 
> Yes, it would.

> One thing we could do is provide a way for userspace to query the
> effective format(s) as seen by the GPU and/or CPU.

We already have almost no testing on bigendian.  I doubt adding generic
interfaces specifically to handle this case is going to work because
most userspace will simply not implement that correctly (or at all).

Having support for this in the radeon ioctls might work, because only
radeon kernel + xorg driver have to get things right then.  But I
suspect we already have that.  You've mentioned elsewhere in the thread
that the xorg driver doesn't turn on byteswapping, so the ability to
configure that seems to be somewhere in the API ...

> It might also make sense for the radeon driver to set the
> RADEON_TILING_SWAP_{16,32}BIT flags for dumb BOs.

That could work.  But I guess someone with test hardware needs to try,
to make sure we don't miss corner cases here.

cheers,
  Gerd

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

end of thread, other threads:[~2017-04-28 10:02 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20170424062532.26722-1-kraxel@redhat.com>
2017-04-24  6:25 ` [PATCH 1/6] drm: fourcc byteorder: drop DRM_FORMAT_BIG_ENDIAN Gerd Hoffmann
2017-04-24  6:25 ` [PATCH 2/6] drm: fourcc byteorder: add DRM_FORMAT_CPU_* Gerd Hoffmann
2017-04-24  6:25 ` [PATCH 3/6] drm: fourcc byteorder: add bigendian support to drm_mode_legacy_fb_format Gerd Hoffmann
2017-04-25  3:18   ` Michel Dänzer
2017-04-25  9:52     ` Ville Syrjälä
2017-04-26  2:00       ` Michel Dänzer
2017-04-26 14:30         ` Ville Syrjälä
2017-04-26  5:53     ` Gerd Hoffmann
2017-04-26  9:21       ` Michel Dänzer
2017-04-26 12:11         ` Gerd Hoffmann
2017-04-27  0:52           ` Michel Dänzer
2017-04-27  6:45             ` Gerd Hoffmann
2017-04-27  7:02               ` Michel Dänzer
2017-04-28 10:02                 ` Gerd Hoffmann
2017-04-26 13:28       ` Eric Engestrom
2017-04-26 13:57         ` Gerd Hoffmann
2017-04-24  6:25 ` [PATCH 4/6] drm: fourcc byteorder: adapt bochs-drm to drm_mode_legacy_fb_format update Gerd Hoffmann
2017-04-24  6:25 ` [PATCH 5/6] drm: fourcc byteorder: adapt virtio " Gerd Hoffmann
2017-04-24  6:25 ` [PATCH 6/6] drm: fourcc byteorder: virtio restrict to XRGB8888 Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).