Skip to contentSkip to conversation

drm/simpledrm: Apple M1 / DT platform support fixes

PATCH Superseded Hector Martin 6 participants 18 messages Nov 17, 2021 – Nov 30, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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).

Hector Martin (3):
drm/simpledrm: Bind to OF framebuffers in /chosen drm/format-helper: Add drm_fb_xrgb8888_to_xrgb2101010_dstclip() drm/simpledrm: Enable XRGB2101010 format

 drivers/gpu/drm/drm_format_helper.c | 64 +++++++++++++++++++++++++++++
 drivers/gpu/drm/tiny/simpledrm.c    | 19 ++++++++-
 include/drm/drm_format_helper.h     |  4 ++
 3 files changed, 86 insertions(+), 1 deletion(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/3 drm/simpledrm: Bind to OF framebuffers in /chosen

This matches the simplefb behavior; these nodes are not matched by the standard OF machinery. This fixes a regression when simpledrm replaces simeplefb.

---
 drivers/gpu/drm/tiny/simpledrm.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +17 -0
index 481b48bde047..2c84f2ea1fa2 100644
@@ -2,6 +2,7 @@
 
 #include <linux/clk.h>
 #include <linux/of_clk.h>
+#include <linux/of_platform.h>
 #include <linux/platform_data/simplefb.h>
 #include <linux/platform_device.h>
 #include <linux/regulator/consumer.h>
@@ -897,5 +898,21 @@ static struct platform_driver simpledrm_platform_driver = {
 
 module_platform_driver(simpledrm_platform_driver);
 
+static int __init simpledrm_init(void)
+{
+	struct device_node *np;
+
+	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(simpledrm_init);
+
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL v2");
Signature · 1 line
2.33.0
#2 lore raw

Re: [PATCH 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

Hi

Am 17.11.21 um 15:58 schrieb Hector Martin:

Quoted 31 lines

This matches the simplefb behavior; these nodes are not matched by the standard OF machinery. This fixes a regression when simpledrm replaces simeplefb.

---
  drivers/gpu/drm/tiny/simpledrm.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
drivers/gpu/drm/tiny/simpledrm.c +7 -0
index 481b48bde047..2c84f2ea1fa2 100644
@@ -2,6 +2,7 @@
 
  #include <linux/clk.h>
  #include <linux/of_clk.h>
+#include <linux/of_platform.h>
  #include <linux/platform_data/simplefb.h>
  #include <linux/platform_device.h>
  #include <linux/regulator/consumer.h>
@@ -897,5 +898,21 @@ static struct platform_driver simpledrm_platform_driver = {
 
  module_platform_driver(simpledrm_platform_driver);
 
+static int __init simpledrm_init(void)
+{
+	struct device_node *np;
+
+	if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
+		for_each_child_of_node(of_chosen, np) {

drivers/gpu/drm/tiny/simpledrm.c static struct platform_driver simpledrm_platform_driver = { · line 916

Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +10 -0
+			if (of_device_is_compatible(np, "simple-framebuffer"))
+				of_platform_device_create(np, NULL, NULL);
+		}
+	}
+
+	return 0;
+}
+
+fs_initcall(simpledrm_init);
+

Simpledrm is just a driver, but this is platform setup code. Why is this code located here and not under arch/ or drivers/firmware/?

I know that other drivers do similar things, it doesn't seem to belong here.

Best regards
Thomas

Quoted 3 lines
drivers/gpu/drm/tiny/simpledrm.c +0 -0
  MODULE_DESCRIPTION(DRIVER_DESC);
  MODULE_LICENSE("GPL v2");
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 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

Quoted 27 lines · Thomas Zimmermann

Hi

Am 17.11.21 um 15:58 schrieb Hector Martin:

Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +6 -0
@@ -897,5 +898,21 @@ static struct platform_driver simpledrm_platform_driver = {
 
   module_platform_driver(simpledrm_platform_driver);
 
+static int __init simpledrm_init(void)
+{
+	struct device_node *np;
+
+	if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
+		for_each_child_of_node(of_chosen, np) {

drivers/gpu/drm/tiny/simpledrm.c static struct platform_driver simpledrm_platform_driver = { · line 916

Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +10 -0
+			if (of_device_is_compatible(np, "simple-framebuffer"))
+				of_platform_device_create(np, NULL, NULL);
+		}
+	}
+
+	return 0;
+}
+
+fs_initcall(simpledrm_init);
+

Simpledrm is just a driver, but this is platform setup code. Why is this code located here and not under arch/ or drivers/firmware/?

Quoted 1 line

I know that other drivers do similar things, it doesn't seem to belong here.

This definitely doesn't belong in either of those, since it is not arch- or firmware-specific. It is implementing support for the standard simple-framebuffer OF binding, which specifies that it must be located within the /chosen node (and thus the default OF setup code won't do the matching for you); this applies to all OF platforms [1]

Adding Rob; do you think this should move from simplefb/simpledrm to common OF code? (where?)

[1] Documentation/devicetree/bindings/display/simple-framebuffer.yaml

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

Re: [PATCH 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

Hi

Am 20.11.21 um 04:23 schrieb Hector Martin:

Quoted 27 lines · Thomas Zimmermann
Quoted 26 lines

Hi

Am 17.11.21 um 15:58 schrieb Hector Martin:

Quoted 9 lines
drivers/gpu/drm/tiny/simpledrm.c +6 -0
@@ -897,5 +898,21 @@ static struct platform_driver 
 simpledrm_platform_driver = {
    module_platform_driver(simpledrm_platform_driver);
+static int __init simpledrm_init(void)
+{
+    struct device_node *np;
+
+    if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
+        for_each_child_of_node(of_chosen, np) {

drivers/gpu/drm/tiny/simpledrm.c static struct platform_driver · line 915

Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +10 -0
+            if (of_device_is_compatible(np, "simple-framebuffer"))
+                of_platform_device_create(np, NULL, NULL);
+        }
+    }
+
+    return 0;
+}
+
+fs_initcall(simpledrm_init);
+

Simpledrm is just a driver, but this is platform setup code. Why is this code located here and not under arch/ or drivers/firmware/?

Quoted 5 lines
Quoted 1 line

I know that other drivers do similar things, it doesn't seem to belong here.

This definitely doesn't belong in either of those, since it is not arch- or firmware-specific. It is implementing support for the standard simple-framebuffer OF binding, which specifies that it must be located within the /chosen node (and thus the default OF setup code won't do the matching for you); this applies to all OF platforms [1]

Adding Rob; do you think this should move from simplefb/simpledrm to common OF code? (where?)

ping!

Quoted 3 lines

[1] Documentation/devicetree/bindings/display/simple-framebuffer.yaml

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
#5 lore raw

Re: [PATCH 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

In reply to Hector Martin
Quoted 31 lines · Hector Martin
Quoted 27 lines · Thomas Zimmermann

Hi

Am 17.11.21 um 15:58 schrieb Hector Martin:

Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +6 -0
@@ -897,5 +898,21 @@ static struct platform_driver simpledrm_platform_driver = {
 
   module_platform_driver(simpledrm_platform_driver);
 
+static int __init simpledrm_init(void)
+{
+    struct device_node *np;
+
+    if (IS_ENABLED(CONFIG_OF_ADDRESS) && of_chosen) {
+            for_each_child_of_node(of_chosen, np) {

drivers/gpu/drm/tiny/simpledrm.c static struct platform_driver simpledrm_platform_driver = { · line 916

Quoted 10 lines
drivers/gpu/drm/tiny/simpledrm.c +10 -0
+                    if (of_device_is_compatible(np, "simple-framebuffer"))
+                            of_platform_device_create(np, NULL, NULL);
+            }
+    }
+
+    return 0;
+}
+
+fs_initcall(simpledrm_init);
+

Simpledrm is just a driver, but this is platform setup code. Why is this code located here and not under arch/ or drivers/firmware/?

Quoted 1 line

I know that other drivers do similar things, it doesn't seem to belong here.

Quoted 8 lines

This definitely doesn't belong in either of those, since it is not arch- or firmware-specific. It is implementing support for the standard simple-framebuffer OF binding, which specifies that it must be located within the /chosen node (and thus the default OF setup code won't do the matching for you); this applies to all OF platforms [1]

Adding Rob; do you think this should move from simplefb/simpledrm to common OF code? (where?)

of_platform_default_populate_init() should work.

#6 lore raw

Re: [PATCH 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Simpledrm is just a driver, but this is platform setup code. Why is this code located here and not under arch/ or drivers/firmware/?

Agreed. Creating platform devices is something for platform code and not really a DRM driver.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

I know that other drivers do similar things, it doesn't seem to belong here.

Yeah, the simplefb driver does this but that seems like something that should be changed.

Quoted 10 lines
Quoted 8 lines

This definitely doesn't belong in either of those, since it is not arch- or firmware-specific. It is implementing support for the standard simple-framebuffer OF binding, which specifies that it must be located within the /chosen node (and thus the default OF setup code won't do the matching for you); this applies to all OF platforms [1]

Adding Rob; do you think this should move from simplefb/simpledrm to common OF code? (where?)

of_platform_default_populate_init() should work.

That should work but I still wonder if it is the correct place to add this logic.

I think that instead it could be done in the sysfb_create_simplefb() function [0], which already creates the "simple-framebuffer" device for x86 legacy BIOS and x86/arm64/riscv EFI so it makes sense to do the same for OF. That way the simplefb platform device registration code could also be dropped from the driver and users would just need to enable CONFIG_SYSFB and CONFIG_SYSFB_SIMPLEFB to have the same.

I have a couple of boards with a bootloader that populates a "simple-framebuffer" in the /chosen node so I could attempt to write the patches. But probably won't happen until next week.

[0]: https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/sysfb_simplefb.c#L60

Best regards,
Javier

#7 lore raw

Re: [PATCH 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

Hi

Am 30.11.21 um 07:44 schrieb Javier Martinez Canillas:

Quoted 35 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Simpledrm is just a driver, but this is platform setup code. Why is this code located here and not under arch/ or drivers/firmware/?

Agreed. Creating platform devices is something for platform code and not really a DRM driver.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

I know that other drivers do similar things, it doesn't seem to belong here.

Yeah, the simplefb driver does this but that seems like something that should be changed.

Quoted 10 lines
Quoted 8 lines

This definitely doesn't belong in either of those, since it is not arch- or firmware-specific. It is implementing support for the standard simple-framebuffer OF binding, which specifies that it must be located within the /chosen node (and thus the default OF setup code won't do the matching for you); this applies to all OF platforms [1]

Adding Rob; do you think this should move from simplefb/simpledrm to common OF code? (where?)

of_platform_default_populate_init() should work.

That should work but I still wonder if it is the correct place to add this logic.

I think that instead it could be done in the sysfb_create_simplefb() function [0], which already creates the "simple-framebuffer" device for x86 legacy BIOS and x86/arm64/riscv EFI so it makes sense to do the same for OF. That way the simplefb platform device registration code could also be dropped from the driver and users would just need to enable CONFIG_SYSFB and CONFIG_SYSFB_SIMPLEFB to have the same.

Quoted 3 lines

I have a couple of boards with a bootloader that populates a "simple-framebuffer" in the /chosen node so I could attempt to write the patches. But probably won't happen until next week.

IMHO it's better to keep the OF-related setup in the OF code. The sysfb code is for screen_info. We can try to find common code for OF and sysfb that then lives in a shared location.

Using a single global screen_info variable is somewhat awkward these days. In the long term, I can think of pushing sysfb code into architectures. Each architecture would then setup the platform devices that it supports. But that's not really important right now.

Best regards
Thomas

Quoted 6 lines

[0]: https://elixir.bootlin.com/linux/v5.16-rc3/source/drivers/firmware/sysfb_simplefb.c#L60

Best regards,
Javier

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 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

Hello Thomas,

Quoted 1 line · Thomas Zimmermann

Am 30.11.21 um 07:44 schrieb Javier Martinez Canillas:

[snip]

Quoted 8 lines
Quoted 8 lines

I think that instead it could be done in the sysfb_create_simplefb() function [0], which already creates the "simple-framebuffer" device for x86 legacy BIOS and x86/arm64/riscv EFI so it makes sense to do the same for OF. That way the simplefb platform device registration code could also be dropped from the driver and users would just need to enable CONFIG_SYSFB and CONFIG_SYSFB_SIMPLEFB to have the same.

Quoted 8 lines
Quoted 3 lines

I have a couple of boards with a bootloader that populates a "simple-framebuffer" in the /chosen node so I could attempt to write the patches. But probably won't happen until next week.

IMHO it's better to keep the OF-related setup in the OF code. The sysfb code is for screen_info. We can try to find common code for OF and sysfb that then lives in a shared location.

Ok. As long as we don't end with code duplication then that works for me too.

Quoted 5 lines

Using a single global screen_info variable is somewhat awkward these days. In the long term, I can think of pushing sysfb code into architectures. Each architecture would then setup the platform devices that it supports. But that's not really important right now.

That makes sense. And provide a set of helpers as you mentioned that could be shared across the different architectures and firmware interfaces.

Best regards,
Javier

#9 lore raw

Re: [PATCH 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

In reply to Javier Martinez Canillas
Quoted 21 lines · Javier Martinez Canillas
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Simpledrm is just a driver, but this is platform setup code. Why is this code located here and not under arch/ or drivers/firmware/?

Agreed. Creating platform devices is something for platform code and not really a DRM driver.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

I know that other drivers do similar things, it doesn't seem to belong here.

Yeah, the simplefb driver does this but that seems like something that should be changed.

Quoted 6 lines
Quoted 6 lines

This definitely doesn't belong in either of those, since it is not arch- or firmware-specific. It is implementing support for the standard simple-framebuffer OF binding, which specifies that it must be located within the /chosen node (and thus the default OF setup code won't do the matching for you); this applies to all OF platforms [1]

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Adding Rob; do you think this should move from simplefb/simpledrm to common OF code? (where?)

of_platform_default_populate_init() should work.

That should work but I still wonder if it is the correct place to add this logic.

It is because that is where most of the other devices are created unless the bus handles it.

Quoted 6 lines

I think that instead it could be done in the sysfb_create_simplefb() function [0], which already creates the "simple-framebuffer" device for x86 legacy BIOS and x86/arm64/riscv EFI so it makes sense to do the same for OF. That way the simplefb platform device registration code could also be dropped from the driver and users would just need to enable CONFIG_SYSFB and CONFIG_SYSFB_SIMPLEFB to have the same.

Doesn't look like that would share anything with anything else (BIOS/EFI/ACPI).

Rob

#10 lore raw

Re: [PATCH 1/3] drm/simpledrm: Bind to OF framebuffers in /chosen

In reply to Hector Martin
I love your patch! Yet something to improve:

Hi Hector,

I love your patch! Yet something to improve:

[auto build test ERROR on drm/drm-next]
[also build test ERROR on v5.16-rc1]
[cannot apply to next-20211118]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Hector-Martin/drm-simpledrm-Apple-M1-DT-platform-support-fixes/20211117-230107
base:   git://anongit.freedesktop.org/drm/drm drm-next
config: riscv-randconfig-r035-20211118 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project c46becf500df2a7fb4b4fce16178a036c344315a)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/0be435c1fb3f0722a7099fee532925717a67a42a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Hector-Martin/drm-simpledrm-Apple-M1-DT-platform-support-fixes/20211117-230107 git checkout 0be435c1fb3f0722a7099fee532925717a67a42a
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/gpu/drm/tiny/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/tiny/simpledrm.c:915:1: error: redefinition of '__inittest'
   fs_initcall(simpledrm_init);
   ^
   include/linux/module.h:119:27: note: expanded from macro 'fs_initcall'
   #define fs_initcall(fn)                 module_init(fn)
                                           ^
   include/linux/module.h:131:42: note: expanded from macro 'module_init'
           static inline initcall_t __maybe_unused __inittest(void)                \
                                                   ^
   drivers/gpu/drm/tiny/simpledrm.c:899:1: note: previous definition is here
   module_platform_driver(simpledrm_platform_driver);
   ^
   include/linux/platform_device.h:252:2: note: expanded from macro 'module_platform_driver'
           module_driver(__platform_driver, platform_driver_register, \
           ^
   include/linux/device/driver.h:262:3: note: expanded from macro 'module_driver'
   } \
     ^
   include/linux/module.h:131:42: note: expanded from macro '\
   module_init'
           static inline initcall_t __maybe_unused __inittest(void)                \
                                                   ^
>> drivers/gpu/drm/tiny/simpledrm.c:915:1: error: redefinition of 'init_module'
   fs_initcall(simpledrm_init);
   ^
   include/linux/module.h:119:27: note: expanded from macro 'fs_initcall'
   #define fs_initcall(fn)                 module_init(fn)
                                           ^
   include/linux/module.h:133:6: note: expanded from macro 'module_init'
           int init_module(void) __copy(initfn)                    \
               ^
   drivers/gpu/drm/tiny/simpledrm.c:899:1: note: previous definition is here
   module_platform_driver(simpledrm_platform_driver);
   ^
   include/linux/platform_device.h:252:2: note: expanded from macro 'module_platform_driver'
           module_driver(__platform_driver, platform_driver_register, \
           ^
   include/linux/device/driver.h:262:3: note: expanded from macro 'module_driver'
   } \
     ^
   include/linux/module.h:133:6: note: expanded from macro '\
   module_init'
           int init_module(void) __copy(initfn)                    \
               ^

2 errors generated.

vim +/__inittest +915 drivers/gpu/drm/tiny/simpledrm.c

914

 > 915	fs_initcall(simpledrm_init);

916

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#11 lore raw

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

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, which already works fine with simplefb. This is required to make simpledrm support this too.

---
 drivers/gpu/drm/drm_format_helper.c | 64 +++++++++++++++++++++++++++++
 include/drm/drm_format_helper.h     |  4 ++
 2 files changed, 68 insertions(+)
drivers/gpu/drm/drm_format_helper.c +64 -0
index 69fde60e36b3..5998e57d6ff2 100644
@@ -378,6 +378,60 @@ void drm_fb_xrgb8888_to_rgb888_dstclip(void __iomem *dst, unsigned int dst_pitch
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_dstclip);
 
+static void drm_fb_xrgb8888_to_xrgb2101010_line(u32 *dbuf, 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_dstclip - Convert XRGB8888 to XRGB2101010 clip
+ * buffer
+ * @dst: XRGB2101010 destination buffer (iomem)
+ * @dst_pitch: destination buffer pitch
+ * @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.
+ *
+ * This function applies clipping on dst, i.e. the destination is a
+ * full (iomem) framebuffer but only the clip rect content is copied over.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_dstclip(void __iomem *dst,
+					    unsigned int dst_pitch, void *vaddr,
+					    struct drm_framebuffer *fb,
+					    struct drm_rect *clip)
+{
+	size_t linepixels = clip->x2 - clip->x1;
+	size_t dst_len = linepixels * 4;
+	unsigned int y, lines = clip->y2 - clip->y1;
+	void *dbuf;
+
+	dbuf = kmalloc(dst_len, GFP_KERNEL);
+	if (!dbuf)
+		return;
+
+	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
+	dst += clip_offset(clip, dst_pitch, 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_dstclip);
+
 /**
  * drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale
  * @dst: 8-bit grayscale destination buffer
@@ -464,6 +518,10 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int dst_pitch,
 		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_dstclip(dst, dst_pitch, vmap, fb, clip);
@@ -482,6 +540,12 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int 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_dstclip(dst, dst_pitch,
+							       vmap, fb, clip);
+			return 0;
+		}
 	}
 
 	return -EINVAL;
include/drm/drm_format_helper.h +4 -0
index e86925cf07b9..a0faa710878b 100644
@@ -29,6 +29,10 @@ void drm_fb_xrgb8888_to_rgb888(void *dst, void *src, struct drm_framebuffer *fb,
 void drm_fb_xrgb8888_to_rgb888_dstclip(void __iomem *dst, unsigned int dst_pitch,
 				       void *vaddr, struct drm_framebuffer *fb,
 				       struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_dstclip(void __iomem *dst,
+					    unsigned int dst_pitch, void *vaddr,
+					    struct drm_framebuffer *fb,
+					    struct drm_rect *clip);
 void drm_fb_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
 			      struct drm_rect *clip);
 
Signature · 1 line
2.33.0
#12 lore raw

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

Hi

Am 17.11.21 um 15:58 schrieb Hector Martin:

Quoted 5 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, which already works fine with simplefb. This is required to make simpledrm support this too.

As mentioned in the other review, this requires a rebase onto the latest DRM tree; preferably drm-tip.

Best regards
Thomas

Quoted 112 lines
---
  drivers/gpu/drm/drm_format_helper.c | 64 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  4 ++
  2 files changed, 68 insertions(+)
drivers/gpu/drm/drm_format_helper.c +64 -0
index 69fde60e36b3..5998e57d6ff2 100644
@@ -378,6 +378,60 @@ void drm_fb_xrgb8888_to_rgb888_dstclip(void __iomem *dst, unsigned int dst_pitch
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_dstclip);
 
+static void drm_fb_xrgb8888_to_xrgb2101010_line(u32 *dbuf, 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_dstclip - Convert XRGB8888 to XRGB2101010 clip
+ * buffer
+ * @dst: XRGB2101010 destination buffer (iomem)
+ * @dst_pitch: destination buffer pitch
+ * @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.
+ *
+ * This function applies clipping on dst, i.e. the destination is a
+ * full (iomem) framebuffer but only the clip rect content is copied over.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_dstclip(void __iomem *dst,
+					    unsigned int dst_pitch, void *vaddr,
+					    struct drm_framebuffer *fb,
+					    struct drm_rect *clip)
+{
+	size_t linepixels = clip->x2 - clip->x1;
+	size_t dst_len = linepixels * 4;
+	unsigned int y, lines = clip->y2 - clip->y1;
+	void *dbuf;
+
+	dbuf = kmalloc(dst_len, GFP_KERNEL);
+	if (!dbuf)
+		return;
+
+	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
+	dst += clip_offset(clip, dst_pitch, 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_dstclip);
+
  /**
   * drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale
   * @dst: 8-bit grayscale destination buffer
@@ -464,6 +518,10 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int dst_pitch,
  		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_dstclip(dst, dst_pitch, vmap, fb, clip);
@@ -482,6 +540,12 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int 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_dstclip(dst, dst_pitch,
+							       vmap, fb, clip);
+			return 0;
+		}
  	}
 
  	return -EINVAL;
include/drm/drm_format_helper.h +4 -0
index e86925cf07b9..a0faa710878b 100644
@@ -29,6 +29,10 @@ void drm_fb_xrgb8888_to_rgb888(void *dst, void *src, struct drm_framebuffer *fb,
  void drm_fb_xrgb8888_to_rgb888_dstclip(void __iomem *dst, unsigned int dst_pitch,
  				       void *vaddr, struct drm_framebuffer *fb,
  				       struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_dstclip(void __iomem *dst,
+					    unsigned int dst_pitch, void *vaddr,
+					    struct drm_framebuffer *fb,
+					    struct drm_rect *clip);
  void drm_fb_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
  			      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
#13 lore raw

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

In reply to Hector Martin
Quoted 11 lines · On Wed, 17 Nov 2021 23:58:28 +0900 Hector Martin <[email protected]> wrote:

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, which already works fine with simplefb. This is required to make simpledrm support this too.

---
 drivers/gpu/drm/drm_format_helper.c | 64 +++++++++++++++++++++++++++++
 include/drm/drm_format_helper.h     |  4 ++
 2 files changed, 68 insertions(+)

Hi Hector,

I'm curious, since the bootloader seems to always set up a 10-bit mode, is there a reason for it that you can guess? Is the monitor in WCG or even HDR mode?

Thanks,
pq

#14 lore raw

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

Quoted 15 lines · Pekka Paalanen
Quoted 11 lines · On Wed, 17 Nov 2021 23:58:28 +0900 Hector Martin <[email protected]> wrote:

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, which already works fine with simplefb. This is required to make simpledrm support this too.

---
  drivers/gpu/drm/drm_format_helper.c | 64 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  4 ++
  2 files changed, 68 insertions(+)
Quoted 5 lines

Hi Hector,

I'm curious, since the bootloader seems to always set up a 10-bit mode, is there a reason for it that you can guess? Is the monitor in WCG or even HDR mode?

My guess is that Apple prefer to use 10-bit framebuffers for seamless handover with their graphics stack, which presumably uses 10-bit framebuffers these days. It seems to be unconditional; I've never seen anything but 10 bits across all Apple devices, both with the internal panels on laptops and with bog standard external displays on the Mac Mini via HDMI. HDR is not necessary, even very dumb capture cards and old screens get a 10-bit framebufer in memory.

The only time I see an 8-bit framebuffer is with *no* monitor connected on the Mini, in which case you get an 8-bit 640x1136 dummy framebuffer (that's the iPhone 5 screen resolution... :-) )

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

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

Quoted 22 lines · On Mon, 22 Nov 2021 19:05:16 +0900 Hector Martin <[email protected]> wrote:
Quoted 15 lines · Pekka Paalanen
Quoted 11 lines · On Wed, 17 Nov 2021 23:58:28 +0900 Hector Martin <[email protected]> wrote:

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, which already works fine with simplefb. This is required to make simpledrm support this too.

---
  drivers/gpu/drm/drm_format_helper.c | 64 +++++++++++++++++++++++++++++
  include/drm/drm_format_helper.h     |  4 ++
  2 files changed, 68 insertions(+)  
Quoted 5 lines

Hi Hector,

I'm curious, since the bootloader seems to always set up a 10-bit mode, is there a reason for it that you can guess? Is the monitor in WCG or even HDR mode?

Quoted 7 lines

My guess is that Apple prefer to use 10-bit framebuffers for seamless handover with their graphics stack, which presumably uses 10-bit framebuffers these days. It seems to be unconditional; I've never seen anything but 10 bits across all Apple devices, both with the internal panels on laptops and with bog standard external displays on the Mac Mini via HDMI. HDR is not necessary, even very dumb capture cards and old screens get a 10-bit framebufer in memory.

That makes perfect sense, thanks!

Switching between sRGB and WCG or HDR mode is not a modeset, it's just HDMI/DP/whatever metadata/infoframe.

Quoted 4 lines

The only time I see an 8-bit framebuffer is with *no* monitor connected on the Mini, in which case you get an 8-bit 640x1136 dummy framebuffer (that's the iPhone 5 screen resolution... :-) )

Thanks,
pq

#16 lore raw

PATCH 3/3 drm/simpledrm: Enable XRGB2101010 format

In reply to Hector Martin

This is the format used by the bootloader framebuffer on Apple ARM64 platforms, and is already supported by simplefb. This avoids regressing on these platforms when simpledrm is enabled and replaces simplefb.

---
 drivers/gpu/drm/tiny/simpledrm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/simpledrm.c +1 -1
index 2c84f2ea1fa2..b4b69f3a7e79 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 v1 3/3
#17 lore raw

Re: [PATCH 3/3] drm/simpledrm: Enable XRGB2101010 format

Hi

Am 17.11.21 um 15:58 schrieb Hector Martin:

Quoted 5 lines

This is the format used by the bootloader framebuffer on Apple ARM64 platforms, and is already supported by simplefb. This avoids regressing on these platforms when simpledrm is enabled and replaces simplefb.

Quoted 18 lines
---
  drivers/gpu/drm/tiny/simpledrm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tiny/simpledrm.c +1 -1
index 2c84f2ea1fa2..b4b69f3a7e79 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 · 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