Skip to contentSkip to conversation

of: Register platform device for each framebuffer

PATCH Superseded Thomas Zimmermann 4 participants 15 messages Apr 13, 2022 – Apr 19, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover of: Register platform device for each framebuffer

Move the detection of OF framebuffers from fbdev into of platform code and register a Linux platform device for each framebuffer. Allows for DRM-based OF drivers and real hot-unplugging of the framebuffer.

This patchset has been tested with qemu's ppc64le emulation, which provides a framebuffer via OF display node. If someone has an older 32-bit system with BootX available, please test.

Thomas Zimmermann (2):
of: Create platform devices for OF framebuffers
fbdev: Remove hot-unplug workaround for framebuffers without device

 drivers/of/platform.c            | 73 ++++++++++++++++++++++--
 drivers/video/fbdev/core/fbmem.c |  9 +--
 drivers/video/fbdev/offb.c       | 98 +++++++++++++++++++++-----------
 3 files changed, 135 insertions(+), 45 deletions(-)

base-commit: 74ee32cc715cd9557c62aba937d6995851c68fe7
prerequisite-patch-id: c2b2f08f0eccc9f5df0c0da49fa1d36267deb11d
prerequisite-patch-id: c67e5d886a47b7d0266d81100837557fda34cb24
prerequisite-patch-id: 6e1032c6302461624f33194c8b8f37103a3fa6ef
prerequisite-patch-id: dbf45768338ff1d944d093dc54bdffb3dc054b44
prerequisite-patch-id: 9c12c87b13a3519a93b81ca18299fae96ae4fefe
prerequisite-patch-id: 3f204510fcbf9530d6540bd8e6128cce598988b6
prerequisite-patch-id: ab7611d28d07723ab1dd392dcf9a6345de3b1040

Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/2 of: Create platform devices for OF framebuffers

Create a platform device for each OF-declared framebuffer and have offb bind to these devices. Allows for real hot-unplugging and other drivers besides offb.

Originally, offb created framebuffer devices while initializing its module by parsing the OF device tree. No actual Linux device was set up. This tied OF framebuffers to offb and makes writing other drivers for the OF framebuffers complicated. The absence of a Linux device prevented real hot-unplugging. Adding a distinct platform device for each OF framebuffer solves both problems. Specifically, a DRM drivers can now provide graphics output with modern userspace.

Some of the offb init code is now located in the OF initialization. There's now also an implementation of of_platform_default_populate_init(), which was missing before. The OF side creates different devices for either OF display nodes or bootx displays as they require different handling by the driver. The offb drivers picks up each type of device and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

---
 drivers/of/platform.c      | 73 ++++++++++++++++++++++++++--
 drivers/video/fbdev/offb.c | 98 +++++++++++++++++++++++++-------------
 2 files changed, 134 insertions(+), 37 deletions(-)
drivers/of/platform.c +69 -4
index a16b74f32aa9..4c63b9a73587 100644
@@ -447,6 +447,60 @@ int of_platform_bus_probe(struct device_node *root,
 }
 EXPORT_SYMBOL(of_platform_bus_probe);
 
+static int __init of_platform_populate_framebuffers(void)
+{
+	struct device_node *boot_display = NULL;
+	struct device_node *node;
+	struct platform_device *dev;
+	int ret;
+
+	node = of_get_compatible_child(of_chosen, "simple-framebuffer");
+	of_platform_device_create(node, NULL, NULL);
+	of_node_put(node);
+
+	/* Check if we have a MacOS display without a node spec */
+	if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL)) {
+		/*
+		 * The old code tried to work out which node was the MacOS
+		 * display based on the address. I'm dropping that since the
+		 * lack of a node spec only happens with old BootX versions
+		 * (users can update) and with this code, they'll still get
+		 * a display (just not the palette hacks).
+		 */
+		dev = platform_device_alloc("bootx-noscreen", 0);
+		if (WARN_ON(!dev))
+			return -ENOMEM;
+		ret = platform_device_add(dev);
+		if (WARN_ON(ret)) {
+			platform_device_put(dev);
+			return ret;
+		}
+	}
+
+	/*
+	 * For OF framebuffers, first create the device for the boot display,
+	 * then for the other framebuffers. Only fail for the boot display;
+	 * ignore errors for the rest.
+	 */
+	for_each_node_by_type(node, "display") {
+		if (!of_get_property(node, "linux,opened", NULL) ||
+		    !of_get_property(node, "linux,boot-display", NULL))
+			continue;
+		dev = of_platform_device_create(node, "of-display", NULL);
+		if (WARN_ON(!dev))
+			return -ENOMEM;
+		boot_display = node;
+		break;
+	}
+	for_each_node_by_type(node, "display") {
+		if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
+			continue;
+		of_platform_device_create(node, "of-display", NULL);
+	}
+
+	return 0;
+}
+
 /**
  * of_platform_populate() - Populate platform_devices from device tree data
  * @root: parent of the first level to probe or NULL for the root of the tree
@@ -541,9 +595,7 @@ static int __init of_platform_default_populate_init(void)
 		of_node_put(node);
 	}
 
-	node = of_get_compatible_child(of_chosen, "simple-framebuffer");
-	of_platform_device_create(node, NULL, NULL);
-	of_node_put(node);
+	of_platform_populate_framebuffers();
 
 	/* Populate everything else. */
 	of_platform_default_populate(NULL, NULL, NULL);
@@ -551,6 +603,20 @@ static int __init of_platform_default_populate_init(void)
 	return 0;
 }
 arch_initcall_sync(of_platform_default_populate_init);
+#else
+static int __init of_platform_default_populate_init(void)
+{
+	device_links_supplier_sync_state_pause();
+
+	if (!of_have_populated_dt())
+		return -ENODEV;
+
+	of_platform_populate_framebuffers();
+
+	return 0;
+}
+arch_initcall_sync(of_platform_default_populate_init);
+#endif
 
 static int __init of_platform_sync_state_init(void)
 {
@@ -558,7 +624,6 @@ static int __init of_platform_sync_state_init(void)
 	return 0;
 }
 late_initcall_sync(of_platform_sync_state_init);
-#endif
 
 int of_platform_device_destroy(struct device *dev, void *data)
 {
drivers/video/fbdev/offb.c +65 -33

140 lines not on this page · raw message

Signature · 1 line
2.35.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] of: Create platform devices for OF framebuffers

Hello Thomas,

Thanks for working on this.

Quoted 23 lines · Thomas Zimmermann

Create a platform device for each OF-declared framebuffer and have offb bind to these devices. Allows for real hot-unplugging and other drivers besides offb.

Originally, offb created framebuffer devices while initializing its module by parsing the OF device tree. No actual Linux device was set up. This tied OF framebuffers to offb and makes writing other drivers for the OF framebuffers complicated. The absence of a Linux device prevented real hot-unplugging. Adding a distinct platform device for each OF framebuffer solves both problems. Specifically, a DRM drivers can now provide graphics output with modern userspace.

Some of the offb init code is now located in the OF initialization. There's now also an implementation of of_platform_default_populate_init(), which was missing before. The OF side creates different devices for either OF display nodes or bootx displays as they require different handling by the driver. The offb drivers picks up each type of device and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

---

[snip]

Quoted 4 lines
drivers/of/platform.c +4 -0
+	for_each_node_by_type(node, "display") {
+		if (!of_get_property(node, "linux,opened", NULL) ||
+		    !of_get_property(node, "linux,boot-display", NULL))
+			continue;

drivers/of/platform.c int of_platform_bus_probe(struct device_node *root, · line 498

Quoted 10 lines
drivers/of/platform.c +10 -0
+		dev = of_platform_device_create(node, "of-display", NULL);
+		if (WARN_ON(!dev))
+			return -ENOMEM;
+		boot_display = node;
+		break;
+	}
+	for_each_node_by_type(node, "display") {
+		if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
+			continue;
+		of_platform_device_create(node, "of-display", NULL);

Shouldn't check for the return value here too ?

Other than this small nit, it looks good to me.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat
#3 lore raw

Re: [PATCH 1/2] of: Create platform devices for OF framebuffers

Hi

Am 13.04.22 um 12:45 schrieb Javier Martinez Canillas:

Quoted 31 lines

Hello Thomas,

Thanks for working on this.

Quoted 23 lines · Thomas Zimmermann

Create a platform device for each OF-declared framebuffer and have offb bind to these devices. Allows for real hot-unplugging and other drivers besides offb.

Originally, offb created framebuffer devices while initializing its module by parsing the OF device tree. No actual Linux device was set up. This tied OF framebuffers to offb and makes writing other drivers for the OF framebuffers complicated. The absence of a Linux device prevented real hot-unplugging. Adding a distinct platform device for each OF framebuffer solves both problems. Specifically, a DRM drivers can now provide graphics output with modern userspace.

Some of the offb init code is now located in the OF initialization. There's now also an implementation of of_platform_default_populate_init(), which was missing before. The OF side creates different devices for either OF display nodes or bootx displays as they require different handling by the driver. The offb drivers picks up each type of device and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

---

[snip]

Quoted 16 lines
Quoted 4 lines
drivers/of/platform.c +4 -0
+	for_each_node_by_type(node, "display") {
+		if (!of_get_property(node, "linux,opened", NULL) ||
+		    !of_get_property(node, "linux,boot-display", NULL))
+			continue;

drivers/of/platform.c int of_platform_bus_probe(struct device_node *root, · line 498

Quoted 10 lines
drivers/of/platform.c +10 -0
+		dev = of_platform_device_create(node, "of-display", NULL);
+		if (WARN_ON(!dev))
+			return -ENOMEM;
+		boot_display = node;
+		break;
+	}
+	for_each_node_by_type(node, "display") {
+		if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
+			continue;
+		of_platform_device_create(node, "of-display", NULL);

Shouldn't check for the return value here too ?

Failing is probably not useful, as it's not the main FB used for booting. Printing an error message wouldn't hurt, I guess. I'll also update the new driver registration in offb with an error message.

Quoted 5 lines

Other than this small nit, it looks good to me.

Thanks.

Best regards
Thomas

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 1/2] of: Create platform devices for OF framebuffers

In reply to Thomas Zimmermann
Quoted 37 lines · Thomas Zimmermann

Create a platform device for each OF-declared framebuffer and have offb bind to these devices. Allows for real hot-unplugging and other drivers besides offb.

Originally, offb created framebuffer devices while initializing its module by parsing the OF device tree. No actual Linux device was set up. This tied OF framebuffers to offb and makes writing other drivers for the OF framebuffers complicated. The absence of a Linux device prevented real hot-unplugging. Adding a distinct platform device for each OF framebuffer solves both problems. Specifically, a DRM drivers can now provide graphics output with modern userspace.

Some of the offb init code is now located in the OF initialization. There's now also an implementation of of_platform_default_populate_init(), which was missing before. The OF side creates different devices for either OF display nodes or bootx displays as they require different handling by the driver. The offb drivers picks up each type of device and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

---
 drivers/of/platform.c      | 73 ++++++++++++++++++++++++++--
 drivers/video/fbdev/offb.c | 98 +++++++++++++++++++++++++-------------
 2 files changed, 134 insertions(+), 37 deletions(-)
drivers/of/platform.c +1 -0
index a16b74f32aa9..4c63b9a73587 100644
@@ -447,6 +447,60 @@ int of_platform_bus_probe(struct device_node *root,
 }
 EXPORT_SYMBOL(of_platform_bus_probe);
 
+static int __init of_platform_populate_framebuffers(void)

drivers/of/platform.c int of_platform_bus_probe(struct device_node *root, · line 460

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+       struct device_node *boot_display = NULL;
+       struct device_node *node;
+       struct platform_device *dev;
+       int ret;
+
+       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
+       of_platform_device_create(node, NULL, NULL);
+       of_node_put(node);
+

The rest is PPC only, so bail out here if !PPC.

Quoted 47 lines
drivers/of/platform.c +43 -0
+       /* Check if we have a MacOS display without a node spec */
+       if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL)) {
+               /*
+                * The old code tried to work out which node was the MacOS
+                * display based on the address. I'm dropping that since the
+                * lack of a node spec only happens with old BootX versions
+                * (users can update) and with this code, they'll still get
+                * a display (just not the palette hacks).
+                */
+               dev = platform_device_alloc("bootx-noscreen", 0);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               ret = platform_device_add(dev);
+               if (WARN_ON(ret)) {
+                       platform_device_put(dev);
+                       return ret;
+               }
+       }
+
+       /*
+        * For OF framebuffers, first create the device for the boot display,
+        * then for the other framebuffers. Only fail for the boot display;
+        * ignore errors for the rest.
+        */
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) ||
+                   !of_get_property(node, "linux,boot-display", NULL))
+                       continue;
+               dev = of_platform_device_create(node, "of-display", NULL);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               boot_display = node;
+               break;
+       }
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
+                       continue;
+               of_platform_device_create(node, "of-display", NULL);
+       }
+
+       return 0;
+}
+
 /**
  * of_platform_populate() - Populate platform_devices from device tree data
  * @root: parent of the first level to probe or NULL for the root of the tree

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

Quoted 10 lines
drivers/of/platform.c +1 -3
@@ -541,9 +595,7 @@ static int __init of_platform_default_populate_init(void)
                of_node_put(node);
        }
 
-       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
-       of_platform_device_create(node, NULL, NULL);
-       of_node_put(node);
+       of_platform_populate_framebuffers();
 
        /* Populate everything else. */
        of_platform_default_populate(NULL, NULL, NULL);

I'm pretty sure it's just this call that's the problem for PPC though none of the above existed when adding this caused a regression. Can we remove the ifdef and just make this call conditional on !IS_ENABLED(CONFIG_PPC).

Quoted 29 lines
drivers/of/platform.c +14 -1
@@ -551,6 +603,20 @@ static int __init of_platform_default_populate_init(void)
        return 0;
 }
 arch_initcall_sync(of_platform_default_populate_init);
+#else
+static int __init of_platform_default_populate_init(void)
+{
+       device_links_supplier_sync_state_pause();
+
+       if (!of_have_populated_dt())
+               return -ENODEV;
+
+       of_platform_populate_framebuffers();
+
+       return 0;
+}
+arch_initcall_sync(of_platform_default_populate_init);
+#endif
 
 static int __init of_platform_sync_state_init(void)
 {
@@ -558,7 +624,6 @@ static int __init of_platform_sync_state_init(void)
        return 0;
 }
 late_initcall_sync(of_platform_sync_state_init);
-#endif
 
 int of_platform_device_destroy(struct device *dev, void *data)
 {
#5 lore raw

Re: [PATCH 1/2] of: Create platform devices for OF framebuffers

Hi

Am 13.04.22 um 14:51 schrieb Rob Herring:

Quoted 106 lines · Thomas Zimmermann
Quoted 37 lines

Create a platform device for each OF-declared framebuffer and have offb bind to these devices. Allows for real hot-unplugging and other drivers besides offb.

Originally, offb created framebuffer devices while initializing its module by parsing the OF device tree. No actual Linux device was set up. This tied OF framebuffers to offb and makes writing other drivers for the OF framebuffers complicated. The absence of a Linux device prevented real hot-unplugging. Adding a distinct platform device for each OF framebuffer solves both problems. Specifically, a DRM drivers can now provide graphics output with modern userspace.

Some of the offb init code is now located in the OF initialization. There's now also an implementation of of_platform_default_populate_init(), which was missing before. The OF side creates different devices for either OF display nodes or bootx displays as they require different handling by the driver. The offb drivers picks up each type of device and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

---
  drivers/of/platform.c      | 73 ++++++++++++++++++++++++++--
  drivers/video/fbdev/offb.c | 98 +++++++++++++++++++++++++-------------
  2 files changed, 134 insertions(+), 37 deletions(-)
drivers/of/platform.c +1 -0
index a16b74f32aa9..4c63b9a73587 100644
@@ -447,6 +447,60 @@ int of_platform_bus_probe(struct device_node *root,
  }
  EXPORT_SYMBOL(of_platform_bus_probe);
 
+static int __init of_platform_populate_framebuffers(void)

drivers/of/platform.c int of_platform_bus_probe(struct device_node *root, · line 460

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+       struct device_node *boot_display = NULL;
+       struct device_node *node;
+       struct platform_device *dev;
+       int ret;
+
+       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
+       of_platform_device_create(node, NULL, NULL);
+       of_node_put(node);
+

The rest is PPC only, so bail out here if !PPC.

Quoted 55 lines
drivers/of/platform.c +44 -3
+       /* Check if we have a MacOS display without a node spec */
+       if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL)) {
+               /*
+                * The old code tried to work out which node was the MacOS
+                * display based on the address. I'm dropping that since the
+                * lack of a node spec only happens with old BootX versions
+                * (users can update) and with this code, they'll still get
+                * a display (just not the palette hacks).
+                */
+               dev = platform_device_alloc("bootx-noscreen", 0);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               ret = platform_device_add(dev);
+               if (WARN_ON(ret)) {
+                       platform_device_put(dev);
+                       return ret;
+               }
+       }
+
+       /*
+        * For OF framebuffers, first create the device for the boot display,
+        * then for the other framebuffers. Only fail for the boot display;
+        * ignore errors for the rest.
+        */
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) ||
+                   !of_get_property(node, "linux,boot-display", NULL))
+                       continue;
+               dev = of_platform_device_create(node, "of-display", NULL);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               boot_display = node;
+               break;
+       }
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
+                       continue;
+               of_platform_device_create(node, "of-display", NULL);
+       }
+
+       return 0;
+}
+
  /**
   * of_platform_populate() - Populate platform_devices from device tree data
   * @root: parent of the first level to probe or NULL for the root of the tree
@@ -541,9 +595,7 @@ static int __init of_platform_default_populate_init(void)
                 of_node_put(node);
         }
 
-       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
-       of_platform_device_create(node, NULL, NULL);
-       of_node_put(node);
+       of_platform_populate_framebuffers();
 
Quoted 7 lines

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

Quoted 2 lines
drivers/of/platform.c +0 -0
         /* Populate everything else. */
         of_platform_default_populate(NULL, NULL, NULL);

I'm pretty sure it's just this call that's the problem for PPC though none of the above existed when adding this caused a regression. Can we remove the ifdef and just make this call conditional on !IS_ENABLED(CONFIG_PPC).

Together with the changes in of_platform_populate_framebuffers(), the code is more or less an "if-else" depending on PPC. I'll drop of_platform_populate_framebuffers() from the patch and make a separate implementation of of_platform_default_populate_init for PPC. Seems like the easiest solution to me.

Best regards
Thomas

Quoted 31 lines
Quoted 31 lines
drivers/of/platform.c +14 -1
@@ -551,6 +603,20 @@ static int __init of_platform_default_populate_init(void)
         return 0;
  }
  arch_initcall_sync(of_platform_default_populate_init);
+#else
+static int __init of_platform_default_populate_init(void)
+{
+       device_links_supplier_sync_state_pause();
+
+       if (!of_have_populated_dt())
+               return -ENODEV;
+
+       of_platform_populate_framebuffers();
+
+       return 0;
+}
+arch_initcall_sync(of_platform_default_populate_init);
+#endif
 
  static int __init of_platform_sync_state_init(void)
  {
@@ -558,7 +624,6 @@ static int __init of_platform_sync_state_init(void)
         return 0;
  }
  late_initcall_sync(of_platform_sync_state_init);
-#endif
 
  int of_platform_device_destroy(struct device *dev, void *data)
  {
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

Re: [PATCH 1/2] of: Create platform devices for OF framebuffers

Quoted 1 line · Thomas Zimmermann

Hi

[snip]

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
         /* Populate everything else. */
         of_platform_default_populate(NULL, NULL, NULL);

I'm pretty sure it's just this call that's the problem for PPC though none of the above existed when adding this caused a regression. Can we remove the ifdef and just make this call conditional on !IS_ENABLED(CONFIG_PPC).

Quoted 6 lines

Together with the changes in of_platform_populate_framebuffers(), the code is more or less an "if-else" depending on PPC. I'll drop of_platform_populate_framebuffers() from the patch and make a separate implementation of of_platform_default_populate_init for PPC. Seems like the easiest solution to me.

That sounds reasonable to me as well. Feel free to retain my R-B tag when posting v2.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat
#7 lore raw

Re: [PATCH 1/2] of: Create platform devices for OF framebuffers

In reply to Thomas Zimmermann
Quoted 118 lines · Thomas Zimmermann

Hi

Am 13.04.22 um 14:51 schrieb Rob Herring:

Quoted 106 lines · Thomas Zimmermann
Quoted 37 lines

Create a platform device for each OF-declared framebuffer and have offb bind to these devices. Allows for real hot-unplugging and other drivers besides offb.

Originally, offb created framebuffer devices while initializing its module by parsing the OF device tree. No actual Linux device was set up. This tied OF framebuffers to offb and makes writing other drivers for the OF framebuffers complicated. The absence of a Linux device prevented real hot-unplugging. Adding a distinct platform device for each OF framebuffer solves both problems. Specifically, a DRM drivers can now provide graphics output with modern userspace.

Some of the offb init code is now located in the OF initialization. There's now also an implementation of of_platform_default_populate_init(), which was missing before. The OF side creates different devices for either OF display nodes or bootx displays as they require different handling by the driver. The offb drivers picks up each type of device and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

---
  drivers/of/platform.c      | 73 ++++++++++++++++++++++++++--
  drivers/video/fbdev/offb.c | 98 +++++++++++++++++++++++++-------------
  2 files changed, 134 insertions(+), 37 deletions(-)
drivers/of/platform.c +1 -0
index a16b74f32aa9..4c63b9a73587 100644
@@ -447,6 +447,60 @@ int of_platform_bus_probe(struct device_node *root,
  }
  EXPORT_SYMBOL(of_platform_bus_probe);
 
+static int __init of_platform_populate_framebuffers(void)

drivers/of/platform.c int of_platform_bus_probe(struct device_node *root, · line 460

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+       struct device_node *boot_display = NULL;
+       struct device_node *node;
+       struct platform_device *dev;
+       int ret;
+
+       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
+       of_platform_device_create(node, NULL, NULL);
+       of_node_put(node);
+

The rest is PPC only, so bail out here if !PPC.

Quoted 55 lines
drivers/of/platform.c +44 -3
+       /* Check if we have a MacOS display without a node spec */
+       if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL)) {
+               /*
+                * The old code tried to work out which node was the MacOS
+                * display based on the address. I'm dropping that since the
+                * lack of a node spec only happens with old BootX versions
+                * (users can update) and with this code, they'll still get
+                * a display (just not the palette hacks).
+                */
+               dev = platform_device_alloc("bootx-noscreen", 0);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               ret = platform_device_add(dev);
+               if (WARN_ON(ret)) {
+                       platform_device_put(dev);
+                       return ret;
+               }
+       }
+
+       /*
+        * For OF framebuffers, first create the device for the boot display,
+        * then for the other framebuffers. Only fail for the boot display;
+        * ignore errors for the rest.
+        */
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) ||
+                   !of_get_property(node, "linux,boot-display", NULL))
+                       continue;
+               dev = of_platform_device_create(node, "of-display", NULL);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               boot_display = node;
+               break;
+       }
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
+                       continue;
+               of_platform_device_create(node, "of-display", NULL);
+       }
+
+       return 0;
+}
+
  /**
   * of_platform_populate() - Populate platform_devices from device tree data
   * @root: parent of the first level to probe or NULL for the root of the tree
@@ -541,9 +595,7 @@ static int __init of_platform_default_populate_init(void)
                 of_node_put(node);
         }
 
-       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
-       of_platform_device_create(node, NULL, NULL);
-       of_node_put(node);
+       of_platform_populate_framebuffers();
 
Quoted 7 lines

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

Quoted 2 lines
drivers/of/platform.c +0 -0
         /* Populate everything else. */
         of_platform_default_populate(NULL, NULL, NULL);

I'm pretty sure it's just this call that's the problem for PPC though none of the above existed when adding this caused a regression. Can we remove the ifdef and just make this call conditional on !IS_ENABLED(CONFIG_PPC).

Quoted 5 lines

Together with the changes in of_platform_populate_framebuffers(), the code is more or less an "if-else" depending on PPC. I'll drop of_platform_populate_framebuffers() from the patch and make a separate implementation of of_platform_default_populate_init for PPC. Seems like the easiest solution to me.

That just moves us farther from PPC ever using of_platform_default_populate_init(). But I don't know that anyone in PPC cares about that, so fine I guess.

Rob

#8 lore raw

Re: [PATCH 1/2] of: Create platform devices for OF framebuffers

Quoted 126 lines · Rob Herring
Quoted 118 lines · Thomas Zimmermann

Hi

Am 13.04.22 um 14:51 schrieb Rob Herring:

Quoted 106 lines · Thomas Zimmermann
Quoted 37 lines

Create a platform device for each OF-declared framebuffer and have offb bind to these devices. Allows for real hot-unplugging and other drivers besides offb.

Originally, offb created framebuffer devices while initializing its module by parsing the OF device tree. No actual Linux device was set up. This tied OF framebuffers to offb and makes writing other drivers for the OF framebuffers complicated. The absence of a Linux device prevented real hot-unplugging. Adding a distinct platform device for each OF framebuffer solves both problems. Specifically, a DRM drivers can now provide graphics output with modern userspace.

Some of the offb init code is now located in the OF initialization. There's now also an implementation of of_platform_default_populate_init(), which was missing before. The OF side creates different devices for either OF display nodes or bootx displays as they require different handling by the driver. The offb drivers picks up each type of device and runs the appropriate fbdev initialization.

Tested with OF display nodes on qemu's ppc64le target.

---
  drivers/of/platform.c      | 73 ++++++++++++++++++++++++++--
  drivers/video/fbdev/offb.c | 98 +++++++++++++++++++++++++-------------
  2 files changed, 134 insertions(+), 37 deletions(-)
drivers/of/platform.c +1 -0
index a16b74f32aa9..4c63b9a73587 100644
@@ -447,6 +447,60 @@ int of_platform_bus_probe(struct device_node *root,
  }
  EXPORT_SYMBOL(of_platform_bus_probe);
 
+static int __init of_platform_populate_framebuffers(void)

drivers/of/platform.c int of_platform_bus_probe(struct device_node *root, · line 460

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+       struct device_node *boot_display = NULL;
+       struct device_node *node;
+       struct platform_device *dev;
+       int ret;
+
+       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
+       of_platform_device_create(node, NULL, NULL);
+       of_node_put(node);
+

The rest is PPC only, so bail out here if !PPC.

Quoted 55 lines
drivers/of/platform.c +44 -3
+       /* Check if we have a MacOS display without a node spec */
+       if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL)) {
+               /*
+                * The old code tried to work out which node was the MacOS
+                * display based on the address. I'm dropping that since the
+                * lack of a node spec only happens with old BootX versions
+                * (users can update) and with this code, they'll still get
+                * a display (just not the palette hacks).
+                */
+               dev = platform_device_alloc("bootx-noscreen", 0);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               ret = platform_device_add(dev);
+               if (WARN_ON(ret)) {
+                       platform_device_put(dev);
+                       return ret;
+               }
+       }
+
+       /*
+        * For OF framebuffers, first create the device for the boot display,
+        * then for the other framebuffers. Only fail for the boot display;
+        * ignore errors for the rest.
+        */
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) ||
+                   !of_get_property(node, "linux,boot-display", NULL))
+                       continue;
+               dev = of_platform_device_create(node, "of-display", NULL);
+               if (WARN_ON(!dev))
+                       return -ENOMEM;
+               boot_display = node;
+               break;
+       }
+       for_each_node_by_type(node, "display") {
+               if (!of_get_property(node, "linux,opened", NULL) || node == boot_display)
+                       continue;
+               of_platform_device_create(node, "of-display", NULL);
+       }
+
+       return 0;
+}
+
  /**
   * of_platform_populate() - Populate platform_devices from device tree data
   * @root: parent of the first level to probe or NULL for the root of the tree
@@ -541,9 +595,7 @@ static int __init of_platform_default_populate_init(void)
                 of_node_put(node);
         }
 
-       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
-       of_platform_device_create(node, NULL, NULL);
-       of_node_put(node);
+       of_platform_populate_framebuffers();
 
Quoted 7 lines

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

Quoted 2 lines
drivers/of/platform.c +0 -0
         /* Populate everything else. */
         of_platform_default_populate(NULL, NULL, NULL);

I'm pretty sure it's just this call that's the problem for PPC though none of the above existed when adding this caused a regression. Can we remove the ifdef and just make this call conditional on !IS_ENABLED(CONFIG_PPC).

Quoted 5 lines

Together with the changes in of_platform_populate_framebuffers(), the code is more or less an "if-else" depending on PPC. I'll drop of_platform_populate_framebuffers() from the patch and make a separate implementation of of_platform_default_populate_init for PPC. Seems like the easiest solution to me.

Quoted 3 lines

That just moves us farther from PPC ever using of_platform_default_populate_init(). But I don't know that anyone in PPC cares about that, so fine I guess.

Actually, no. Make it work with IS_ENABLED(CONFIG_PPC) rather than an #ifdef. Currently, I don't have to build this (or any of drivers/of/) for PPC because it is IS_ENABLED(CONFIG_PPC) everywhere. Yes, there's an #ifdef already, but there's not an #else and no PPC only code compiled.

Rob

#9 lore raw

Re: [PATCH 1/2] of: Create platform devices for OF framebuffers

In reply to Rob Herring

Hi

Am 13.04.22 um 14:51 schrieb Rob Herring:
...

Quoted 13 lines
Quoted 13 lines
drivers/of/platform.c +2 -3
+
  /**
   * of_platform_populate() - Populate platform_devices from device tree data
   * @root: parent of the first level to probe or NULL for the root of the tree
@@ -541,9 +595,7 @@ static int __init of_platform_default_populate_init(void)
                 of_node_put(node);
         }
 
-       node = of_get_compatible_child(of_chosen, "simple-framebuffer");
-       of_platform_device_create(node, NULL, NULL);
-       of_node_put(node);
+       of_platform_populate_framebuffers();
 
Quoted 7 lines

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

Quoted 2 lines
drivers/of/platform.c +0 -0
         /* Populate everything else. */
         of_platform_default_populate(NULL, NULL, NULL);

I'm pretty sure it's just this call that's the problem for PPC though none of the above existed when adding this caused a regression. Can we remove the ifdef and just make this call conditional on !IS_ENABLED(CONFIG_PPC).

That didn't work. The boot process stops at some point. I'll send you an updated patch that covers most of the function with IS_ENABLED(CONFIG_PPC)

Best regards
Thomas

Quoted 31 lines
Quoted 31 lines
drivers/of/platform.c +14 -1
@@ -551,6 +603,20 @@ static int __init of_platform_default_populate_init(void)
         return 0;
  }
  arch_initcall_sync(of_platform_default_populate_init);
+#else
+static int __init of_platform_default_populate_init(void)
+{
+       device_links_supplier_sync_state_pause();
+
+       if (!of_have_populated_dt())
+               return -ENODEV;
+
+       of_platform_populate_framebuffers();
+
+       return 0;
+}
+arch_initcall_sync(of_platform_default_populate_init);
+#endif
 
  static int __init of_platform_sync_state_init(void)
  {
@@ -558,7 +624,6 @@ static int __init of_platform_sync_state_init(void)
         return 0;
  }
  late_initcall_sync(of_platform_sync_state_init);
-#endif
 
  int of_platform_device_destroy(struct device *dev, void *data)
  {
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

PATCH 2/2 fbdev: Remove hot-unplug workaround for framebuffers without device

In reply to Thomas Zimmermann

A workaround makes fbdev hot-unplugging work for framebuffers without device. The only user for this feature was offb. As each OF framebuffer now has an associated platform device, the workaround is no longer needed. Remove it. Effectively reverts commit 0f525289ff0d ("fbdev: Fix unregistering of framebuffers without device").

---
 drivers/video/fbdev/core/fbmem.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/video/fbdev/core/fbmem.c +1 -8
index bc6ed750e915..bdd00d381bbc 100644
@@ -1579,14 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
 			 * If it's not a platform device, at least print a warning. A
 			 * fix would add code to remove the device from the system.
 			 */
-			if (!device) {
-				/* TODO: Represent each OF framebuffer as its own
-				 * device in the device hierarchy. For now, offb
-				 * doesn't have such a device, so unregister the
-				 * framebuffer as before without warning.
-				 */
-				do_unregister_framebuffer(registered_fb[i]);
-			} else if (dev_is_platform(device)) {
+			if (dev_is_platform(device)) {
 				registered_fb[i]->forced_out = true;
 				platform_device_unregister(to_platform_device(device));
 			} else {
Signature · 1 line
2.35.1
Reviewed-by on v1 2/2
#11 lore raw

Re: [PATCH 2/2] fbdev: Remove hot-unplug workaround for framebuffers without device

Quoted 16 lines · Thomas Zimmermann

A workaround makes fbdev hot-unplugging work for framebuffers without device. The only user for this feature was offb. As each OF framebuffer now has an associated platform device, the workaround is no longer needed. Remove it. Effectively reverts commit 0f525289ff0d ("fbdev: Fix unregistering of framebuffers without device").

---
 drivers/video/fbdev/core/fbmem.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/video/fbdev/core/fbmem.c +0 -0
index bc6ed750e915..bdd00d381bbc 100644

drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1588

Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +0 -7
@@ -1579,14 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
 			 * If it's not a platform device, at least print a warning. A
 			 * fix would add code to remove the device from the system.
 			 */
-			if (!device) {
-				/* TODO: Represent each OF framebuffer as its own
-				 * device in the device hierarchy. For now, offb
-				 * doesn't have such a device, so unregister the
-				 * framebuffer as before without warning.
-				 */
-				do_unregister_framebuffer(registered_fb[i]);

Maybe we could still keep this for a couple of releases but with a big warning that's not supported in case there are out-of-tree drivers out there that still do this ?

Or at least a warning if the do_unregister_framebuffer() call is removed.

Regardless of what you chose to do, the patch looks good to me.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat
#12 lore raw

Re: [PATCH 2/2] fbdev: Remove hot-unplug workaround for framebuffers without device

Quoted 32 lines · Javier Martinez Canillas
Quoted 16 lines · Thomas Zimmermann

A workaround makes fbdev hot-unplugging work for framebuffers without device. The only user for this feature was offb. As each OF framebuffer now has an associated platform device, the workaround is no longer needed. Remove it. Effectively reverts commit 0f525289ff0d ("fbdev: Fix unregistering of framebuffers without device").

---
 drivers/video/fbdev/core/fbmem.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/video/fbdev/core/fbmem.c +0 -0
index bc6ed750e915..bdd00d381bbc 100644

drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1588

Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +0 -7
@@ -1579,14 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
 			 * If it's not a platform device, at least print a warning. A
 			 * fix would add code to remove the device from the system.
 			 */
-			if (!device) {
-				/* TODO: Represent each OF framebuffer as its own
-				 * device in the device hierarchy. For now, offb
-				 * doesn't have such a device, so unregister the
-				 * framebuffer as before without warning.
-				 */
-				do_unregister_framebuffer(registered_fb[i]);

Maybe we could still keep this for a couple of releases but with a big warning that's not supported in case there are out-of-tree drivers out there that still do this ?

Quoted 1 line

Or at least a warning if the do_unregister_framebuffer() call is removed.

Yeah dying while holding console_lock isn't fun, and not having a WARN_ON
+ bail-out code pretty much forces bug reporters to do a bisect here to give us something more than "machine dies at boot with no messages".

I'd just outright keep the WARN_ON here for 1-2 years even to really make sure we got all the bug reports, since often these older machines only update onto LTS releases.

And it needs to be a WARN_ON + bail out since BUG_ON is as bad as just oopsing.
-Daniel

Quoted 12 lines

Regardless of what you chose to do, the patch looks good to me.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#13 lore raw

Re: [PATCH 2/2] fbdev: Remove hot-unplug workaround for framebuffers without device

Hi

Am 13.04.22 um 18:05 schrieb Daniel Vetter:

Quoted 35 lines · Javier Martinez Canillas
Quoted 32 lines · Thomas Zimmermann
Quoted 16 lines

A workaround makes fbdev hot-unplugging work for framebuffers without device. The only user for this feature was offb. As each OF framebuffer now has an associated platform device, the workaround is no longer needed. Remove it. Effectively reverts commit 0f525289ff0d ("fbdev: Fix unregistering of framebuffers without device").

---
  drivers/video/fbdev/core/fbmem.c | 9 +--------
  1 file changed, 1 insertion(+), 8 deletions(-)
drivers/video/fbdev/core/fbmem.c +0 -0
index bc6ed750e915..bdd00d381bbc 100644

drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1588

Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +0 -7
@@ -1579,14 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
  			 * If it's not a platform device, at least print a warning. A
  			 * fix would add code to remove the device from the system.
  			 */
-			if (!device) {
-				/* TODO: Represent each OF framebuffer as its own
-				 * device in the device hierarchy. For now, offb
-				 * doesn't have such a device, so unregister the
-				 * framebuffer as before without warning.
-				 */
-				do_unregister_framebuffer(registered_fb[i]);

Maybe we could still keep this for a couple of releases but with a big warning that's not supported in case there are out-of-tree drivers out there that still do this ?

Quoted 1 line

Or at least a warning if the do_unregister_framebuffer() call is removed.

Quoted 7 lines

Yeah dying while holding console_lock isn't fun, and not having a WARN_ON
+ bail-out code pretty much forces bug reporters to do a bisect here to give us something more than "machine dies at boot with no messages".

I'd just outright keep the WARN_ON here for 1-2 years even to really make sure we got all the bug reports, since often these older machines only update onto LTS releases.

If that's what the consent is, I'll go with it.

I'm just not sure if we talk about the same problem. offb didn't have a platform device, so we recently added this workaround with 'if (!device)'. All the other fbdev drivers have a platform device; and anything else that could fail is out-of-tree. We don't really care about those AFAIK.

With offb converted, we could practically remove all of the checks here and call platform_device_unregister() unconditionally.

Best regards
Thomas

Quoted 18 lines

And it needs to be a WARN_ON + bail out since BUG_ON is as bad as just oopsing.
-Daniel

Quoted 12 lines

Regardless of what you chose to do, the patch looks good to me.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat
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
#14 lore raw

Re: [PATCH 2/2] fbdev: Remove hot-unplug workaround for framebuffers without device

Hello Thomas,

On 4/13/22 20:09, Thomas Zimmermann wrote:

[snip]

Quoted 29 lines
Quoted 21 lines
Quoted 19 lines
Quoted 4 lines

index bc6ed750e915..bdd00d381bbc 100644

drivers/video/fbdev/core/fbmem.c static void do_remove_conflicting_framebuffers(struct apertures_struct *a, · line 1588

Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +0 -7
@@ -1579,14 +1579,7 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
  			 * If it's not a platform device, at least print a warning. A
  			 * fix would add code to remove the device from the system.
  			 */
-			if (!device) {
-				/* TODO: Represent each OF framebuffer as its own
-				 * device in the device hierarchy. For now, offb
-				 * doesn't have such a device, so unregister the
-				 * framebuffer as before without warning.
-				 */
-				do_unregister_framebuffer(registered_fb[i]);

Maybe we could still keep this for a couple of releases but with a big warning that's not supported in case there are out-of-tree drivers out there that still do this ?

Quoted 1 line

Or at least a warning if the do_unregister_framebuffer() call is removed.

Quoted 7 lines

Yeah dying while holding console_lock isn't fun, and not having a WARN_ON
+ bail-out code pretty much forces bug reporters to do a bisect here to give us something more than "machine dies at boot with no messages".

I'd just outright keep the WARN_ON here for 1-2 years even to really make sure we got all the bug reports, since often these older machines only update onto LTS releases.

Quoted 8 lines

If that's what the consent is, I'll go with it.

I'm just not sure if we talk about the same problem. offb didn't have a platform device, so we recently added this workaround with 'if (!device)'. All the other fbdev drivers have a platform device; and anything else that could fail is out-of-tree. We don't really care about those AFAIK.

Yes, agreed on the offb change but I'm not really sure if we don't care about out-of-tree modules. I mean, you are right in theory but I still feel that we are changing a core behavior without giving people time to sort out if needed.

Since before commit 27599aacbaef ("fbdev: Hot-unplug firmware fb devices on forced removal") registered FBs didn't need to have a device, but now that will lead to a NULL pointer dereference in dev_is_platform(device).

And that change only landed in v5.18-rc1, so it is fairly recent.

I know that we follow https://www.kernel.org/doc/Documentation/process/stable-api-nonsense.rst
but still my opinion is that having a warning for a couple of releases
if registered_fb[i]->device is NULL, instead of just crashing would be
a better way to handle this.

Quoted 3 lines

With offb converted, we could practically remove all of the checks here and call platform_device_unregister() unconditionally.

Yes for mainline, but as mentioned I thought mostly about out-of-tree. If folks agree that we shouldn't care about these, I'm Ok with that as well.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat