Skip to contentSkip to conversation

drm/simpledrm: Apple M1 / DT platform support fixes

PATCH Superseded Hector Martin 3 participants 13 messages Dec 7, 2021 – Dec 9, 2021

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/simpledrm: Apple M1 / DT platform support fixes

Hi DRM folks,

This short series makes simpledrm work on Apple M1 (including Pro/Max) platforms the way simplefb already does, by adding XRGB2101010 support and making it bind to framebuffers in /chosen the same way simplefb does.

This avoids breaking the bootloader-provided framebuffer console when simpledrm is selected to replace simplefb, as these FBs always seem to be 10-bit (at least when a real screen is attached).

Changes since v1:
- Moved the OF platform device setup code from simplefb into common code, instead of duplicating it in simpledrm
- Rebased on drm-tip

Hector Martin (3):
of: Move simple-framebuffer device handling from simplefb to of drm/format-helper: Add drm_fb_xrgb8888_to_xrgb2101010_toio() drm/simpledrm: Add XRGB2101010 format

 drivers/gpu/drm/drm_format_helper.c | 62 +++++++++++++++++++++++++++++
 drivers/gpu/drm/tiny/simpledrm.c    |  2 +-
 drivers/of/platform.c               |  5 +++
 drivers/video/fbdev/simplefb.c      | 21 +---------
 include/drm/drm_format_helper.h     |  3 ++
 5 files changed, 72 insertions(+), 21 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH v2 1/3 of: Move simple-framebuffer device handling from simplefb to of

This code is required for both simplefb and simpledrm, so let's move it into the OF core instead of having it as an ad-hoc initcall in the drivers.

---
 drivers/of/platform.c          |  5 +++++
 drivers/video/fbdev/simplefb.c | 21 +--------------------
 2 files changed, 6 insertions(+), 20 deletions(-)
drivers/of/platform.c +5 -0
index b3faf89744aa..e097f40b03c0 100644
@@ -540,6 +540,11 @@ static int __init of_platform_default_populate_init(void)
 		of_node_put(node);
 	}
 
+	for_each_child_of_node(of_chosen, node) {
+		if (of_device_is_compatible(node, "simple-framebuffer"))
+			of_platform_device_create(node, NULL, NULL);
+	}
+
 	/* Populate everything else. */
 	of_platform_default_populate(NULL, NULL, NULL);
 
drivers/video/fbdev/simplefb.c +1 -20
index b63074fd892e..57541887188b 100644
@@ -541,26 +541,7 @@ static struct platform_driver simplefb_driver = {
 	.remove = simplefb_remove,
 };
 
-static int __init simplefb_init(void)
-{
-	int ret;
-	struct device_node *np;
-
-	ret = platform_driver_register(&simplefb_driver);
-	if (ret)
-		return ret;
-
-	if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
-		for_each_child_of_node(of_chosen, np) {
-			if (of_device_is_compatible(np, "simple-framebuffer"))
-				of_platform_device_create(np, NULL, NULL);
-		}
-	}
-
-	return 0;
-}
-
-fs_initcall(simplefb_init);
+module_platform_driver(simplefb_driver);
 
 MODULE_AUTHOR("Stephen Warren <[email protected]>");
 MODULE_DESCRIPTION("Simple framebuffer driver");
Signature · 1 line
2.33.0
maintainer Acked-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] of: Move simple-framebuffer device handling from simplefb to of

Hi

Am 07.12.21 um 08:29 schrieb Hector Martin:

Quoted 5 lines

This code is required for both simplefb and simpledrm, so let's move it into the OF core instead of having it as an ad-hoc initcall in the drivers.

This looks much better than before. Thank you.

Quoted 54 lines
---
  drivers/of/platform.c          |  5 +++++
  drivers/video/fbdev/simplefb.c | 21 +--------------------
  2 files changed, 6 insertions(+), 20 deletions(-)
drivers/of/platform.c +5 -0
index b3faf89744aa..e097f40b03c0 100644
@@ -540,6 +540,11 @@ static int __init of_platform_default_populate_init(void)
  		of_node_put(node);
  	}
 
+	for_each_child_of_node(of_chosen, node) {
+		if (of_device_is_compatible(node, "simple-framebuffer"))
+			of_platform_device_create(node, NULL, NULL);
+	}
+
  	/* Populate everything else. */
  	of_platform_default_populate(NULL, NULL, NULL);
 
drivers/video/fbdev/simplefb.c +1 -20
index b63074fd892e..57541887188b 100644
@@ -541,26 +541,7 @@ static struct platform_driver simplefb_driver = {
  	.remove = simplefb_remove,
  };
 
-static int __init simplefb_init(void)
-{
-	int ret;
-	struct device_node *np;
-
-	ret = platform_driver_register(&simplefb_driver);
-	if (ret)
-		return ret;
-
-	if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
-		for_each_child_of_node(of_chosen, np) {
-			if (of_device_is_compatible(np, "simple-framebuffer"))
-				of_platform_device_create(np, NULL, NULL);
-		}
-	}
-
-	return 0;
-}
-
-fs_initcall(simplefb_init);
+module_platform_driver(simplefb_driver);
 
  MODULE_AUTHOR("Stephen Warren <[email protected]>");
  MODULE_DESCRIPTION("Simple framebuffer driver");
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#3 lore raw

Re: [PATCH v2 1/3] of: Move simple-framebuffer device handling from simplefb to of

Am 07.12.21 um 10:02 schrieb Thomas Zimmermann:

Quoted 10 lines

Hi

Am 07.12.21 um 08:29 schrieb Hector Martin:

Quoted 5 lines

This code is required for both simplefb and simpledrm, so let's move it into the OF core instead of having it as an ad-hoc initcall in the drivers.

Well, please don't take this as a review. :)

Quoted 55 lines

This looks much better than before. Thank you.

Quoted 51 lines

---
  drivers/of/platform.c          |  5 +++++ drivers/video/fbdev/simplefb.c | 21 +--------------------

  2 files changed, 6 insertions(+), 20 deletions(-)
drivers/of/platform.c +5 -0
index b3faf89744aa..e097f40b03c0 100644
@@ -540,6 +540,11 @@ static int __init 
 of_platform_default_populate_init(void)
           of_node_put(node);
       }
+    for_each_child_of_node(of_chosen, node) {
+        if (of_device_is_compatible(node, "simple-framebuffer"))
+            of_platform_device_create(node, NULL, NULL);
+    }
+
       /* Populate everything else. */
       of_platform_default_populate(NULL, NULL, NULL);
drivers/video/fbdev/simplefb.c +1 -20
index b63074fd892e..57541887188b 100644
@@ -541,26 +541,7 @@ static struct platform_driver simplefb_driver = {
       .remove = simplefb_remove,
   };
-static int __init simplefb_init(void)
-{
-    int ret;
-    struct device_node *np;
-
-    ret = platform_driver_register(&simplefb_driver);
-    if (ret)
-        return ret;
-
-    if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
-        for_each_child_of_node(of_chosen, np) {
-            if (of_device_is_compatible(np, "simple-framebuffer"))
-                of_platform_device_create(np, NULL, NULL);
-        }
-    }
-
-    return 0;
-}
-
-fs_initcall(simplefb_init);
+module_platform_driver(simplefb_driver);
   MODULE_AUTHOR("Stephen Warren <[email protected]>");
   MODULE_DESCRIPTION("Simple framebuffer driver");
 
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#4 lore raw

Re: [PATCH v2 1/3] of: Move simple-framebuffer device handling from simplefb to of

In reply to Hector Martin
Quoted 16 lines · Hector Martin

This code is required for both simplefb and simpledrm, so let's move it into the OF core instead of having it as an ad-hoc initcall in the drivers.

---
 drivers/of/platform.c          |  5 +++++
 drivers/video/fbdev/simplefb.c | 21 +--------------------
 2 files changed, 6 insertions(+), 20 deletions(-)
drivers/of/platform.c +0 -0
index b3faf89744aa..e097f40b03c0 100644

drivers/of/platform.c static int __init of_platform_default_populate_init(void) · line 544

Quoted 5 lines
drivers/of/platform.c +2 -0
@@ -540,6 +540,11 @@ static int __init of_platform_default_populate_init(void)
                of_node_put(node);
        }
 
+       for_each_child_of_node(of_chosen, node) {
+               if (of_device_is_compatible(node, "simple-framebuffer"))

node = of_get_compatible_child(of_chosen, "simple-framebuffer"); of_platform_device_create(node, NULL, NULL); of_node_put(node);

Please Cc the DT list. Looks like this patch can be applied independently. (Better get the other 2 into drm-misc soon or it will miss 5.17).

Rob

#5 lore raw

Re: [PATCH v2 1/3] of: Move simple-framebuffer device handling from simplefb to of

Hi

Am 08.12.21 um 18:49 schrieb Rob Herring:

Quoted 27 lines · Hector Martin
Quoted 16 lines

This code is required for both simplefb and simpledrm, so let's move it into the OF core instead of having it as an ad-hoc initcall in the drivers.

---
  drivers/of/platform.c          |  5 +++++
  drivers/video/fbdev/simplefb.c | 21 +--------------------
  2 files changed, 6 insertions(+), 20 deletions(-)
drivers/of/platform.c +0 -0
index b3faf89744aa..e097f40b03c0 100644

drivers/of/platform.c static int __init of_platform_default_populate_init(void) · line 544

Quoted 5 lines
drivers/of/platform.c +2 -0
@@ -540,6 +540,11 @@ static int __init of_platform_default_populate_init(void)
                 of_node_put(node);
         }
 
+       for_each_child_of_node(of_chosen, node) {
+               if (of_device_is_compatible(node, "simple-framebuffer"))

node = of_get_compatible_child(of_chosen, "simple-framebuffer"); of_platform_device_create(node, NULL, NULL); of_node_put(node);

Quoted 3 lines

Please Cc the DT list. Looks like this patch can be applied independently. (Better get the other 2 into drm-misc soon or it will miss 5.17).

Can we merge the whole patchset through drm-misc? Patches 2 and 3 are useless without the first one.

Best regards
Thomas

Quoted 3 lines

Rob

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#6 lore raw

PATCH v2 2/3 drm/format-helper: Add drm_fb_xrgb8888_to_xrgb2101010_toio()

In reply to Hector Martin

Add XRGB8888 emulation support for devices that can only do XRGB2101010.

This is chiefly useful for simpledrm on Apple devices where the bootloader-provided framebuffer is 10-bit.

---
 drivers/gpu/drm/drm_format_helper.c | 62 +++++++++++++++++++++++++++++
 include/drm/drm_format_helper.h     |  3 ++
 2 files changed, 65 insertions(+)
drivers/gpu/drm/drm_format_helper.c +62 -0
index dbe3e830096e..edd611d3ab6a 100644
@@ -409,6 +409,59 @@ void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch,
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_toio);
 
+static void drm_fb_xrgb8888_to_xrgb2101010_line(u32 *dbuf, const u32 *sbuf,
+						unsigned int pixels)
+{
+	unsigned int x;
+
+	for (x = 0; x < pixels; x++) {
+		*dbuf++ = ((sbuf[x] & 0x000000FF) << 2) |
+			  ((sbuf[x] & 0x0000FF00) << 4) |
+			  ((sbuf[x] & 0x00FF0000) << 6);
+	}
+}
+
+/**
+ * drm_fb_xrgb8888_to_xrgb2101010_toio - Convert XRGB8888 to XRGB2101010 clip
+ * buffer
+ * @dst: XRGB2101010 destination buffer (iomem)
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
+ * @vaddr: XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ *
+ * Drivers can use this function for XRGB2101010 devices that don't natively
+ * support XRGB8888.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_toio(void __iomem *dst,
+					 unsigned int dst_pitch, const void *vaddr,
+					 const struct drm_framebuffer *fb,
+					 const struct drm_rect *clip)
+{
+	size_t linepixels = clip->x2 - clip->x1;
+	size_t dst_len = linepixels * sizeof(u32);
+	unsigned y, lines = clip->y2 - clip->y1;
+	void *dbuf;
+
+	if (!dst_pitch)
+		dst_pitch = dst_len;
+
+	dbuf = kmalloc(dst_len, GFP_KERNEL);
+	if (!dbuf)
+		return;
+
+	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
+	for (y = 0; y < lines; y++) {
+		drm_fb_xrgb8888_to_xrgb2101010_line(dbuf, vaddr, linepixels);
+		memcpy_toio(dst, dbuf, dst_len);
+		vaddr += fb->pitches[0];
+		dst += dst_pitch;
+	}
+
+	kfree(dbuf);
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_toio);
+
 /**
  * drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale
  * @dst: 8-bit grayscale destination buffer
@@ -500,6 +553,10 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
 		fb_format = DRM_FORMAT_XRGB8888;
 	if (dst_format == DRM_FORMAT_ARGB8888)
 		dst_format = DRM_FORMAT_XRGB8888;
+	if (fb_format == DRM_FORMAT_ARGB2101010)
+		fb_format = DRM_FORMAT_XRGB2101010;
+	if (dst_format == DRM_FORMAT_ARGB2101010)
+		dst_format = DRM_FORMAT_XRGB2101010;
 
 	if (dst_format == fb_format) {
 		drm_fb_memcpy_toio(dst, dst_pitch, vmap, fb, clip);
@@ -515,6 +572,11 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
 			drm_fb_xrgb8888_to_rgb888_toio(dst, dst_pitch, vmap, fb, clip);
 			return 0;
 		}
+	} else if (dst_format == DRM_FORMAT_XRGB2101010) {
+		if (fb_format == DRM_FORMAT_XRGB8888) {
+			drm_fb_xrgb8888_to_xrgb2101010_toio(dst, dst_pitch, vmap, fb, clip);
+			return 0;
+		}
 	}
 
 	return -EINVAL;
include/drm/drm_format_helper.h +3 -0
index 97e4c3223af3..b30ed5de0a33 100644
@@ -33,6 +33,9 @@ void drm_fb_xrgb8888_to_rgb888(void *dst, unsigned int dst_pitch, const void *sr
 void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch,
 				    const void *vaddr, const struct drm_framebuffer *fb,
 				    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_toio(void __iomem *dst, unsigned int dst_pitch,
+					 const void *vaddr, const struct drm_framebuffer *fb,
+					 const struct drm_rect *clip);
 void drm_fb_xrgb8888_to_gray8(void *dst, unsigned int dst_pitch, const void *vaddr,
 			      const struct drm_framebuffer *fb, const struct drm_rect *clip);
 
Signature · 1 line
2.33.0
#7 lore raw

Re: [PATCH v2 2/3] drm/format-helper: Add drm_fb_xrgb8888_to_xrgb2101010_toio()

Hi

Am 07.12.21 um 08:29 schrieb Hector Martin:

Quoted 18 lines

Add XRGB8888 emulation support for devices that can only do XRGB2101010.

This is chiefly useful for simpledrm on Apple devices where the bootloader-provided framebuffer is 10-bit.

---
  drivers/gpu/drm/drm_format_helper.c | 62 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  3 ++
  2 files changed, 65 insertions(+)
drivers/gpu/drm/drm_format_helper.c +0 -0
index dbe3e830096e..edd611d3ab6a 100644
@@ -409,6 +409,59 @@ void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch,
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_toio);

drivers/gpu/drm/drm_format_helper.c void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch, · line 420

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
 
+static void drm_fb_xrgb8888_to_xrgb2101010_line(u32 *dbuf, const u32 *sbuf,
+						unsigned int pixels)
+{
+	unsigned int x;
+
+	for (x = 0; x < pixels; x++) {
+		*dbuf++ = ((sbuf[x] & 0x000000FF) << 2) |
+			  ((sbuf[x] & 0x0000FF00) << 4) |
+			  ((sbuf[x] & 0x00FF0000) << 6);

This isn't quite right. The lowest two destination bits in each component will always be zero. You have to do the shifting as above and for each component the two highest source bits have to be OR'ed into the two lowest destination bits. For example the source bits in a component are numbered 7 to 0

| 7 6 5 4 3 2 1 0 |

then the destination bits should be

| 7 6 5 4 3 2 1 0 7 6 |

Best regards
Thomas

Quoted 85 lines
drivers/gpu/drm/drm_format_helper.c +53 -0
+	}
+}
+
+/**
+ * drm_fb_xrgb8888_to_xrgb2101010_toio - Convert XRGB8888 to XRGB2101010 clip
+ * buffer
+ * @dst: XRGB2101010 destination buffer (iomem)
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
+ * @vaddr: XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ *
+ * Drivers can use this function for XRGB2101010 devices that don't natively
+ * support XRGB8888.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_toio(void __iomem *dst,
+					 unsigned int dst_pitch, const void *vaddr,
+					 const struct drm_framebuffer *fb,
+					 const struct drm_rect *clip)
+{
+	size_t linepixels = clip->x2 - clip->x1;
+	size_t dst_len = linepixels * sizeof(u32);
+	unsigned y, lines = clip->y2 - clip->y1;
+	void *dbuf;
+
+	if (!dst_pitch)
+		dst_pitch = dst_len;
+
+	dbuf = kmalloc(dst_len, GFP_KERNEL);
+	if (!dbuf)
+		return;
+
+	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
+	for (y = 0; y < lines; y++) {
+		drm_fb_xrgb8888_to_xrgb2101010_line(dbuf, vaddr, linepixels);
+		memcpy_toio(dst, dbuf, dst_len);
+		vaddr += fb->pitches[0];
+		dst += dst_pitch;
+	}
+
+	kfree(dbuf);
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_toio);
+
  /**
   * drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale
   * @dst: 8-bit grayscale destination buffer
@@ -500,6 +553,10 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
  		fb_format = DRM_FORMAT_XRGB8888;
  	if (dst_format == DRM_FORMAT_ARGB8888)
  		dst_format = DRM_FORMAT_XRGB8888;
+	if (fb_format == DRM_FORMAT_ARGB2101010)
+		fb_format = DRM_FORMAT_XRGB2101010;
+	if (dst_format == DRM_FORMAT_ARGB2101010)
+		dst_format = DRM_FORMAT_XRGB2101010;
 
  	if (dst_format == fb_format) {
  		drm_fb_memcpy_toio(dst, dst_pitch, vmap, fb, clip);
@@ -515,6 +572,11 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for
  			drm_fb_xrgb8888_to_rgb888_toio(dst, dst_pitch, vmap, fb, clip);
  			return 0;
  		}
+	} else if (dst_format == DRM_FORMAT_XRGB2101010) {
+		if (fb_format == DRM_FORMAT_XRGB8888) {
+			drm_fb_xrgb8888_to_xrgb2101010_toio(dst, dst_pitch, vmap, fb, clip);
+			return 0;
+		}
  	}
 
  	return -EINVAL;
include/drm/drm_format_helper.h +3 -0
index 97e4c3223af3..b30ed5de0a33 100644
@@ -33,6 +33,9 @@ void drm_fb_xrgb8888_to_rgb888(void *dst, unsigned int dst_pitch, const void *sr
  void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch,
  				    const void *vaddr, const struct drm_framebuffer *fb,
  				    const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_toio(void __iomem *dst, unsigned int dst_pitch,
+					 const void *vaddr, const struct drm_framebuffer *fb,
+					 const struct drm_rect *clip);
  void drm_fb_xrgb8888_to_gray8(void *dst, unsigned int dst_pitch, const void *vaddr,
  			      const struct drm_framebuffer *fb, const struct drm_rect *clip);
 
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#8 lore raw

Re: [PATCH v2 2/3] drm/format-helper: Add drm_fb_xrgb8888_to_xrgb2101010_toio()

Hi, thanks for the review!

Quoted 38 lines · Thomas Zimmermann

Hi

Am 07.12.21 um 08:29 schrieb Hector Martin:

Quoted 18 lines

Add XRGB8888 emulation support for devices that can only do XRGB2101010.

This is chiefly useful for simpledrm on Apple devices where the bootloader-provided framebuffer is 10-bit.

---
   drivers/gpu/drm/drm_format_helper.c | 62 +++++++++++++++++++++++++++++
   include/drm/drm_format_helper.h     |  3 ++
   2 files changed, 65 insertions(+)
drivers/gpu/drm/drm_format_helper.c +0 -0
index dbe3e830096e..edd611d3ab6a 100644
@@ -409,6 +409,59 @@ void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch,
   }
   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_toio);

drivers/gpu/drm/drm_format_helper.c void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch, · line 420

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
 
+static void drm_fb_xrgb8888_to_xrgb2101010_line(u32 *dbuf, const u32 *sbuf,
+						unsigned int pixels)
+{
+	unsigned int x;
+
+	for (x = 0; x < pixels; x++) {
+		*dbuf++ = ((sbuf[x] & 0x000000FF) << 2) |
+			  ((sbuf[x] & 0x0000FF00) << 4) |
+			  ((sbuf[x] & 0x00FF0000) << 6);

This isn't quite right. The lowest two destination bits in each component will always be zero. You have to do the shifting as above and for each component the two highest source bits have to be OR'ed into the two lowest destination bits. For example the source bits in a component are numbered 7 to 0

Quoted 6 lines
   | 7 6 5 4 3 2 1 0 |

then the destination bits should be

   | 7 6 5 4 3 2 1 0 7 6 |

I think both approaches have pros and cons. Leaving the two LSBs always at 0 yields a fully linear transfer curve with no discontinuities, but means the maximum brightness is slightly less than full. Setting them fully maps the brightness range, but creates 4 double wide steps in the transfer curve (also it's potentially slightly slower CPU-wise).

If you prefer the latter I'll do that for v2.

Signature · 2 lines
Hector Martin ([email protected])
Public Key: https://mrcn.st/pub
#9 lore raw

Re: [PATCH v2 2/3] drm/format-helper: Add drm_fb_xrgb8888_to_xrgb2101010_toio()

Hi

Am 07.12.21 um 10:54 schrieb Hector Martin:

Quoted 45 lines

Hi, thanks for the review!

Quoted 42 lines · Thomas Zimmermann

Hi

Am 07.12.21 um 08:29 schrieb Hector Martin:

Quoted 20 lines

Add XRGB8888 emulation support for devices that can only do XRGB2101010.

This is chiefly useful for simpledrm on Apple devices where the bootloader-provided framebuffer is 10-bit.

---
   drivers/gpu/drm/drm_format_helper.c | 62
+++++++++++++++++++++++++++++
   include/drm/drm_format_helper.h     |  3 ++

   2 files changed, 65 insertions(+)
drivers/gpu/drm/drm_format_helper.c +0 -0
index dbe3e830096e..edd611d3ab6a 100644
@@ -409,6 +409,59 @@ void drm_fb_xrgb8888_to_rgb888_toio(void __iomem 
 *dst, unsigned int dst_pitch,
    }
    EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_toio);

drivers/gpu/drm/drm_format_helper.c void drm_fb_xrgb8888_to_rgb888_toio(void __iomem · line 421

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
+static void drm_fb_xrgb8888_to_xrgb2101010_line(u32 *dbuf, const u32 
 *sbuf,
+                        unsigned int pixels)
+{
+    unsigned int x;
+
+    for (x = 0; x < pixels; x++) {
+        *dbuf++ = ((sbuf[x] & 0x000000FF) << 2) |
+              ((sbuf[x] & 0x0000FF00) << 4) |
+              ((sbuf[x] & 0x00FF0000) << 6);

This isn't quite right. The lowest two destination bits in each component will always be zero. You have to do the shifting as above and for each component the two highest source bits have to be OR'ed into the two lowest destination bits. For example the source bits in a component are numbered 7 to 0

   | 7 6 5 4 3 2 1 0 |

Quoted 8 lines
Quoted 4 lines

then the destination bits should be

   | 7 6 5 4 3 2 1 0 7 6 |

I think both approaches have pros and cons. Leaving the two LSBs always at 0 yields a fully linear transfer curve with no discontinuities, but means the maximum brightness is slightly less than full. Setting them fully maps the brightness range, but creates 4 double wide steps in the transfer curve (also it's potentially slightly slower CPU-wise).

If you prefer the latter I'll do that for v2.

We don't give guarantees for color output unless color spaces are involved. But the lack of LSB bits can be more visible than larger steps in the curve. With the current formats here, it's probably a non-issue. But there can be conversions, such as RGB444 to RGB88, where these missing LSBs make a visible difference.

Therefore, please change the algorithm. It produces more consistent results over a variety of format conversion. It's better to have the same (default) algorithm for all of them.

Best regards
Thomas

Quoted 1 line
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#10 lore raw

Re: [PATCH v2 2/3] drm/format-helper: Add drm_fb_xrgb8888_to_xrgb2101010_toio()

Am 07.12.21 um 11:20 schrieb Thomas Zimmermann:

Quoted 53 lines

Hi

Am 07.12.21 um 10:54 schrieb Hector Martin:

Quoted 50 lines

Hi, thanks for the review!

Quoted 46 lines · Thomas Zimmermann

Hi

Am 07.12.21 um 08:29 schrieb Hector Martin:

Quoted 20 lines

Add XRGB8888 emulation support for devices that can only do XRGB2101010.

This is chiefly useful for simpledrm on Apple devices where the bootloader-provided framebuffer is 10-bit.

---
   drivers/gpu/drm/drm_format_helper.c | 62
+++++++++++++++++++++++++++++
   include/drm/drm_format_helper.h     |  3 ++

   2 files changed, 65 insertions(+)
drivers/gpu/drm/drm_format_helper.c +0 -0
index dbe3e830096e..edd611d3ab6a 100644
@@ -409,6 +409,59 @@ void drm_fb_xrgb8888_to_rgb888_toio(void 
 __iomem *dst, unsigned int dst_pitch,
    }
    EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_toio);

drivers/gpu/drm/drm_format_helper.c void drm_fb_xrgb8888_to_rgb888_toio(void · line 421

Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +9 -0
+static void drm_fb_xrgb8888_to_xrgb2101010_line(u32 *dbuf, const 
 u32 *sbuf,
+                        unsigned int pixels)
+{
+    unsigned int x;
+
+    for (x = 0; x < pixels; x++) {
+        *dbuf++ = ((sbuf[x] & 0x000000FF) << 2) |
+              ((sbuf[x] & 0x0000FF00) << 4) |
+              ((sbuf[x] & 0x00FF0000) << 6);

This isn't quite right. The lowest two destination bits in each component will always be zero. You have to do the shifting as above and for each component the two highest source bits have to be OR'ed into the two lowest destination bits. For example the source bits in a component are numbered 7 to 0

   | 7 6 5 4 3 2 1 0 |

then the destination bits should be

   | 7 6 5 4 3 2 1 0 7 6 |

Quoted 7 lines
Quoted 3 lines

I think both approaches have pros and cons. Leaving the two LSBs always at 0 yields a fully linear transfer curve with no discontinuities, but means the maximum brightness is slightly less than full. Setting them fully maps the brightness range, but creates 4 double wide steps in the transfer curve (also it's potentially slightly slower CPU-wise).

If you prefer the latter I'll do that for v2.

We don't give guarantees for color output unless color spaces are involved. But the lack of LSB bits can be more visible than larger steps in the curve. With the current formats here, it's probably a non-issue. But there can be conversions, such as RGB444 to RGB88, where these missing LSBs make a visible difference.

Therefore, please change the algorithm. It produces more consistent results over a variety of format conversion. It's better to have the same (default) algorithm for all of them.

FTR, I just tested this in a painting program. I can see a difference between ffffff and fcfcfc iff both are next to each other. f8f8f8 is obviously gray.

Quoted 6 lines

Best regards
Thomas

Quoted 1 line
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#11 lore raw

PATCH v2 3/3 drm/simpledrm: Add XRGB2101010 format

In reply to Hector Martin

This is the format used by the bootloader framebuffer on Apple ARM64 platforms.

---
 drivers/gpu/drm/tiny/simpledrm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/simpledrm.c +1 -1
index 2f999915b9aa..edadfd9ee882 100644
@@ -571,7 +571,7 @@ static const uint32_t simpledrm_default_formats[] = {
 	//DRM_FORMAT_XRGB1555,
 	//DRM_FORMAT_ARGB1555,
 	DRM_FORMAT_RGB888,
-	//DRM_FORMAT_XRGB2101010,
+	DRM_FORMAT_XRGB2101010,
 	//DRM_FORMAT_ARGB2101010,
 };
 
Signature · 1 line
2.33.0
maintainer Reviewed-by on v2 3/3
#12 lore raw

Re: [PATCH v2 3/3] drm/simpledrm: Add XRGB2101010 format

Hi

Am 07.12.21 um 08:29 schrieb Hector Martin:

Quoted 14 lines

This is the format used by the bootloader framebuffer on Apple ARM64 platforms.

---
  drivers/gpu/drm/tiny/simpledrm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/simpledrm.c +0 -0
index 2f999915b9aa..edadfd9ee882 100644

drivers/gpu/drm/tiny/simpledrm.c static const uint32_t simpledrm_default_formats[] = { · line 575

Quoted 6 lines
drivers/gpu/drm/tiny/simpledrm.c +1 -1
@@ -571,7 +571,7 @@ static const uint32_t simpledrm_default_formats[] = {
  	//DRM_FORMAT_XRGB1555,
  	//DRM_FORMAT_ARGB1555,
  	DRM_FORMAT_RGB888,
-	//DRM_FORMAT_XRGB2101010,
+	DRM_FORMAT_XRGB2101010,
  	//DRM_FORMAT_ARGB2101010,

You should also enable DRM_FORMAT_ARGB2101010 here. You added the conversion function, so DRM can deal with it. Having an alpha channel isn't typically supported for primary planes, but the format is listed in SIMPLEFB_FORMATS. [1]

With this change:

Best regards

[1] https://elixir.bootlin.com/linux/latest/source/include/linux/platform_data/simplefb.h#L16

Quoted 3 lines
drivers/gpu/drm/tiny/simpledrm.c +0 -0
  };
 
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev