Skip to contentSkip to conversation

drm/omapdrm: Convert fbdev to DRM client

PATCH Superseded Thomas Zimmermann 3 participants 11 messages Apr 3, 2023 – Apr 6, 2023

Subsystems (3)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

v2 cover drm/omapdrm: Convert fbdev to DRM client

Convert omapdrm's fbdev code to struct drm_client. Replaces the current ad-hoc integration. The conversion includes a number of cleanups. As with most other drivers' fbdev emulation, fbdev in omapdrm is now just another DRM client that runs after the DRM device has been registered.

Once all drivers' fbdev emulation has been converted to struct drm_client, we can attempt to add additional in-kernel clients. A DRM-based dmesg log or a bootsplash are commonly mentioned. DRM can then switch easily among the existing clients if/when required.

I did the conversion from similar experience with other drivers. But I don't have the hardware to test this. Any testing is welcome.

v2:
* squashed patch 6 in to patch 5 (Tomi)
* minor cleanups (Tomi)

Thomas Zimmermann (5):
drm/omapdrm: Include <linux/of.h>
drm/omapdrm: Remove fb from struct omap_fbdev drm/omapdrm: Remove bo from struct omap_fbdev drm/omapdrm: Remove fbdev from struct omap_drm_private drm/omapdrm: Implement fbdev emulation as in-kernel client

 drivers/gpu/drm/omapdrm/omap_debugfs.c |   6 +-
 drivers/gpu/drm/omapdrm/omap_drv.c     |  13 +-
 drivers/gpu/drm/omapdrm/omap_drv.h     |   3 -
 drivers/gpu/drm/omapdrm/omap_fbdev.c   | 163 ++++++++++++++++---------
 drivers/gpu/drm/omapdrm/omap_fbdev.h   |   9 +-
 5 files changed, 112 insertions(+), 82 deletions(-)
Signature · 1 line
2.40.0
author maintainer
#1 lore raw

PATCH v2 1/5 drm/omapdrm: Include <linux/of.h>

Include <linux/of.h> to get the contained declarations. No functional changes.

---
 drivers/gpu/drm/omapdrm/omap_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/omapdrm/omap_drv.c +1 -0
index 699ed814e021..fb403b44769c 100644
@@ -6,6 +6,7 @@
 
 #include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
 #include <linux/sort.h>
 #include <linux/sys_soc.h>
 
Signature · 1 line
2.40.0
author maintainer
#2 lore raw

PATCH v2 2/5 drm/omapdrm: Remove fb from struct omap_fbdev

In reply to Thomas Zimmermann

Fbdev's struct fb_helper stores a pointer to the framebuffer. Remove struct omap_fbdev.fb, which contains the same value. No functional changes.

---
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/omapdrm/omap_fbdev.c +6 -5
index a6c8542087ec..b3d57fe4e6ac 100644
@@ -25,7 +25,6 @@ module_param_named(ywrap, ywrap_enabled, bool, 0644);
 
 struct omap_fbdev {
 	struct drm_fb_helper base;
-	struct drm_framebuffer *fb;
 	struct drm_gem_object *bo;
 	bool ywrap_enabled;
 
@@ -170,7 +169,6 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
 
 	DBG("fbi=%p, dev=%p", fbi, dev);
 
-	fbdev->fb = fb;
 	helper->fb = fb;
 
 	fbi->fbops = &omap_fb_ops;
@@ -193,7 +191,7 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
 
 
 	DBG("par=%p, %dx%d", fbi->par, fbi->var.xres, fbi->var.yres);
-	DBG("allocated %dx%d fb", fbdev->fb->width, fbdev->fb->height);
+	DBG("allocated %dx%d fb", fb->width, fb->height);
 
 	return 0;
 
@@ -266,6 +264,7 @@ void omap_fbdev_fini(struct drm_device *dev)
 {
 	struct omap_drm_private *priv = dev->dev_private;
 	struct drm_fb_helper *helper = priv->fbdev;
+	struct drm_framebuffer *fb;
 	struct omap_fbdev *fbdev;
 
 	DBG();
@@ -273,6 +272,8 @@ void omap_fbdev_fini(struct drm_device *dev)
 	if (!helper)
 		return;
 
+	fb = helper->fb;
+
 	drm_fb_helper_unregister_info(helper);
 
 	drm_fb_helper_fini(helper);
@@ -284,8 +285,8 @@ void omap_fbdev_fini(struct drm_device *dev)
 		omap_gem_unpin(fbdev->bo);
 
 	/* this will free the backing object */
-	if (fbdev->fb)
-		drm_framebuffer_remove(fbdev->fb);
+	if (fb)
+		drm_framebuffer_remove(fb);
 
 	drm_fb_helper_unprepare(helper);
 	kfree(fbdev);
Signature · 1 line
2.40.0
author maintainer
#3 lore raw

PATCH v2 3/5 drm/omapdrm: Remove bo from struct omap_fbdev

In reply to Thomas Zimmermann

Fbdev's framebuffer stores a pointer to the GEM object. Remove struct omap_fbdev.bo, which contains the same value. No functional changes.

v2:
* fix commit message (Tomi)

---
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 32 +++++++++++++++++-----------
 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/gpu/drm/omapdrm/omap_fbdev.c +19 -13
index b3d57fe4e6ac..d04a20f95e3d 100644
@@ -10,6 +10,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem_framebuffer_helper.h>
 
 #include "omap_drv.h"
 
@@ -25,7 +26,6 @@ module_param_named(ywrap, ywrap_enabled, bool, 0644);
 
 struct omap_fbdev {
 	struct drm_fb_helper base;
-	struct drm_gem_object *bo;
 	bool ywrap_enabled;
 
 	/* for deferred dmm roll when getting called in atomic ctx */
@@ -37,12 +37,14 @@ static struct drm_fb_helper *get_fb(struct fb_info *fbi);
 static void pan_worker(struct work_struct *work)
 {
 	struct omap_fbdev *fbdev = container_of(work, struct omap_fbdev, work);
-	struct fb_info *fbi = fbdev->base.info;
+	struct drm_fb_helper *helper = &fbdev->base;
+	struct fb_info *fbi = helper->info;
+	struct drm_gem_object *bo = drm_gem_fb_get_obj(helper->fb, 0);
 	int npages;
 
 	/* DMM roll shifts in 4K pages: */
 	npages = fbi->fix.line_length >> PAGE_SHIFT;
-	omap_gem_roll(fbdev->bo, fbi->var.yoffset * npages);
+	omap_gem_roll(bo, fbi->var.yoffset * npages);
 }
 
 static int omap_fbdev_pan_display(struct fb_var_screeninfo *var,
@@ -97,6 +99,7 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
 	union omap_gem_size gsize;
 	struct fb_info *fbi = NULL;
 	struct drm_mode_fb_cmd2 mode_cmd = {0};
+	struct drm_gem_object *bo;
 	dma_addr_t dma_addr;
 	int ret;
 
@@ -127,20 +130,20 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
 		.bytes = PAGE_ALIGN(mode_cmd.pitches[0] * mode_cmd.height),
 	};
 	DBG("allocating %d bytes for fb %d", gsize.bytes, dev->primary->index);
-	fbdev->bo = omap_gem_new(dev, gsize, OMAP_BO_SCANOUT | OMAP_BO_WC);
-	if (!fbdev->bo) {
+	bo = omap_gem_new(dev, gsize, OMAP_BO_SCANOUT | OMAP_BO_WC);
+	if (!bo) {
 		dev_err(dev->dev, "failed to allocate buffer object\n");
 		ret = -ENOMEM;
 		goto fail;
 	}
 
-	fb = omap_framebuffer_init(dev, &mode_cmd, &fbdev->bo);
+	fb = omap_framebuffer_init(dev, &mode_cmd, &bo);
 	if (IS_ERR(fb)) {
 		dev_err(dev->dev, "failed to allocate fb\n");
 		/* note: if fb creation failed, we can't rely on fb destroy
 		 * to unref the bo:
 		 */
-		drm_gem_object_put(fbdev->bo);
+		drm_gem_object_put(bo);
 		ret = PTR_ERR(fb);
 		goto fail;
 	}
@@ -153,7 +156,7 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
 	 * to it).  Then we just need to be sure that we are able to re-
 	 * pin it in case of an opps.
 	 */
-	ret = omap_gem_pin(fbdev->bo, &dma_addr);
+	ret = omap_gem_pin(bo, &dma_addr);
 	if (ret) {
 		dev_err(dev->dev, "could not pin framebuffer\n");
 		ret = -ENOMEM;
@@ -175,10 +178,10 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
 
 	drm_fb_helper_fill_info(fbi, helper, sizes);
 
-	fbi->screen_buffer = omap_gem_vaddr(fbdev->bo);
-	fbi->screen_size = fbdev->bo->size;
+	fbi->screen_buffer = omap_gem_vaddr(bo);
+	fbi->screen_size = bo->size;
 	fbi->fix.smem_start = dma_addr;
-	fbi->fix.smem_len = fbdev->bo->size;
+	fbi->fix.smem_len = bo->size;
 
 	/* if we have DMM, then we can use it for scrolling by just
 	 * shuffling pages around in DMM rather than doing sw blit.
@@ -265,6 +268,7 @@ void omap_fbdev_fini(struct drm_device *dev)
 	struct omap_drm_private *priv = dev->dev_private;
 	struct drm_fb_helper *helper = priv->fbdev;
 	struct drm_framebuffer *fb;
+	struct drm_gem_object *bo;
 	struct omap_fbdev *fbdev;
 
 	DBG();
@@ -280,9 +284,11 @@ void omap_fbdev_fini(struct drm_device *dev)
 
 	fbdev = to_omap_fbdev(helper);
 
+	bo = drm_gem_fb_get_obj(fb, 0);
+
 	/* unpin the GEM object pinned in omap_fbdev_create() */
-	if (fbdev->bo)
-		omap_gem_unpin(fbdev->bo);
+	if (bo)
+		omap_gem_unpin(bo);
 
 	/* this will free the backing object */
 	if (fb)
Signature · 1 line
2.40.0
author maintainer
#4 lore raw

PATCH v2 4/5 drm/omapdrm: Remove fbdev from struct omap_drm_private

In reply to Thomas Zimmermann

The DRM device stores a pointer to the fbdev helper. Remove struct omap_drm_private.fbdev, which contains the same value. No functional changes.

v2:
* don't clear dev->fb_helper unnecessarily (Tomi)
* include omap_fbdev.h in omap_fbdev.c (kernel test robot)

---
 drivers/gpu/drm/omapdrm/omap_debugfs.c | 6 +++---
 drivers/gpu/drm/omapdrm/omap_drv.c     | 1 +
 drivers/gpu/drm/omapdrm/omap_drv.h     | 3 ---
 drivers/gpu/drm/omapdrm/omap_fbdev.c   | 8 ++------
 4 files changed, 6 insertions(+), 12 deletions(-)
drivers/gpu/drm/omapdrm/omap_debugfs.c +3 -3
index bfb2ccb40bd1..a3d470468e5b 100644
@@ -47,15 +47,15 @@ static int fb_show(struct seq_file *m, void *arg)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_device *dev = node->minor->dev;
-	struct omap_drm_private *priv = dev->dev_private;
+	struct drm_fb_helper *helper = dev->fb_helper;
 	struct drm_framebuffer *fb;
 
 	seq_printf(m, "fbcon ");
-	omap_framebuffer_describe(priv->fbdev->fb, m);
+	omap_framebuffer_describe(helper->fb, m);
 
 	mutex_lock(&dev->mode_config.fb_lock);
 	list_for_each_entry(fb, &dev->mode_config.fb_list, head) {
-		if (fb == priv->fbdev->fb)
+		if (fb == helper->fb)
 			continue;
 
 		seq_printf(m, "user ");
drivers/gpu/drm/omapdrm/omap_drv.c +1 -0
index fb403b44769c..6a2f446c960f 100644
@@ -25,6 +25,7 @@
 
 #include "omap_dmm_tiler.h"
 #include "omap_drv.h"
+#include "omap_fbdev.h"
 
 #define DRIVER_NAME		MODULE_NAME
 #define DRIVER_DESC		"OMAP DRM"
drivers/gpu/drm/omapdrm/omap_drv.h +0 -3
index 825960fd3ea9..4c7217b35f6b 100644
@@ -21,7 +21,6 @@
 #include "omap_crtc.h"
 #include "omap_encoder.h"
 #include "omap_fb.h"
-#include "omap_fbdev.h"
 #include "omap_gem.h"
 #include "omap_irq.h"
 #include "omap_plane.h"
@@ -77,8 +76,6 @@ struct omap_drm_private {
 
 	struct drm_private_obj glob_obj;
 
-	struct drm_fb_helper *fbdev;
-
 	struct workqueue_struct *wq;
 
 	/* lock for obj_list below */
drivers/gpu/drm/omapdrm/omap_fbdev.c +2 -6
index d04a20f95e3d..9ea863781ac6 100644
@@ -13,6 +13,7 @@
 #include <drm/drm_gem_framebuffer_helper.h>
 
 #include "omap_drv.h"
+#include "omap_fbdev.h"
 
 MODULE_PARM_DESC(ywrap, "Enable ywrap scrolling (omap44xx and later, default 'y')");
 static bool ywrap_enabled = true;
@@ -250,8 +251,6 @@ void omap_fbdev_init(struct drm_device *dev)
 	if (ret)
 		goto fini;
 
-	priv->fbdev = helper;
-
 	return;
 
 fini:
@@ -265,8 +264,7 @@ void omap_fbdev_init(struct drm_device *dev)
 
 void omap_fbdev_fini(struct drm_device *dev)
 {
-	struct omap_drm_private *priv = dev->dev_private;
-	struct drm_fb_helper *helper = priv->fbdev;
+	struct drm_fb_helper *helper = dev->fb_helper;
 	struct drm_framebuffer *fb;
 	struct drm_gem_object *bo;
 	struct omap_fbdev *fbdev;
@@ -296,6 +294,4 @@ void omap_fbdev_fini(struct drm_device *dev)
 
 	drm_fb_helper_unprepare(helper);
 	kfree(fbdev);
-
-	priv->fbdev = NULL;
 }
Signature · 1 line
2.40.0
author maintainer
#5 lore raw

PATCH v2 5/5 drm/omapdrm: Implement fbdev emulation as in-kernel client

In reply to Thomas Zimmermann

Move code from ad-hoc fbdev callbacks into DRM client functions and remove the old callbacks. The functions instruct the client to poll for changed output or restore the display. The DRM core calls both, the old callbacks and the new client helpers, from the same places. The new functions perform the same operation as before, so there's no change in functionality.

Replace all code that initializes or releases fbdev emulation throughout the driver. Instead initialize the fbdev client by a single call to omapdrm_fbdev_setup() after omapdrm has registered its DRM device. As in most drivers, omapdrm's fbdev emulation now acts like a regular DRM client.

The fbdev client setup consists of the initial preparation and the hot-plugging of the display. The latter creates the fbdev device and sets up the fbdev framebuffer. The setup performs display hot-plugging once. If no display can be detected, DRM probe helpers re-run the detection on each hotplug event.

A call to drm_dev_unregister() releases the client automatically. No further action is required within omapdrm. If the fbdev framebuffer has been fully set up, struct fb_ops.fb_destroy implements the release. For partially initialized emulation, the fbdev client reverts the initial setup.

v2:
* init drm_client in this patch (Tomi)
* don't handle non-atomic modesetting (Tomi)

---
 drivers/gpu/drm/omapdrm/omap_drv.c   |  11 +--
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 132 +++++++++++++++++----------
 drivers/gpu/drm/omapdrm/omap_fbdev.h |   9 +-
 3 files changed, 90 insertions(+), 62 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +2 -9
index 6a2f446c960f..5ed549726104 100644
@@ -15,7 +15,6 @@
 #include <drm/drm_bridge.h>
 #include <drm/drm_bridge_connector.h>
 #include <drm/drm_drv.h>
-#include <drm/drm_fb_helper.h>
 #include <drm/drm_file.h>
 #include <drm/drm_ioctl.h>
 #include <drm/drm_panel.h>
@@ -221,7 +220,6 @@ static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs =
 
 static const struct drm_mode_config_funcs omap_mode_config_funcs = {
 	.fb_create = omap_framebuffer_create,
-	.output_poll_changed = drm_fb_helper_output_poll_changed,
 	.atomic_check = omap_atomic_check,
 	.atomic_commit = drm_atomic_helper_commit,
 };
@@ -654,7 +652,6 @@ static const struct drm_driver omap_drm_driver = {
 	.driver_features = DRIVER_MODESET | DRIVER_GEM  |
 		DRIVER_ATOMIC | DRIVER_RENDER,
 	.open = dev_open,
-	.lastclose = drm_fb_helper_lastclose,
 #ifdef CONFIG_DEBUG_FS
 	.debugfs_init = omap_debugfs_init,
 #endif
@@ -743,8 +740,6 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 		goto err_cleanup_modeset;
 	}
 
-	omap_fbdev_init(ddev);
-
 	drm_kms_helper_poll_init(ddev);
 
 	/*
@@ -755,12 +750,12 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 	if (ret)
 		goto err_cleanup_helpers;
 
+	omap_fbdev_setup(ddev);
+
 	return 0;
 
 err_cleanup_helpers:
 	drm_kms_helper_poll_fini(ddev);
-
-	omap_fbdev_fini(ddev);
 err_cleanup_modeset:
 	omap_modeset_fini(ddev);
 err_free_overlays:
@@ -786,8 +781,6 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
 
 	drm_kms_helper_poll_fini(ddev);
 
-	omap_fbdev_fini(ddev);
-
 	drm_atomic_helper_shutdown(ddev);
 
 	omap_modeset_fini(ddev);
drivers/gpu/drm/omapdrm/omap_fbdev.c +86 -46

187 lines not on this page · raw message

drivers/gpu/drm/omapdrm/omap_fbdev.h +2 -7
index 74a68a5a6eab..74c691a8d45f 100644
@@ -10,16 +10,11 @@
 #define __OMAPDRM_FBDEV_H__
 
 struct drm_device;
-struct drm_fb_helper;
 
 #ifdef CONFIG_DRM_FBDEV_EMULATION
-void omap_fbdev_init(struct drm_device *dev);
-void omap_fbdev_fini(struct drm_device *dev);
+void omap_fbdev_setup(struct drm_device *dev);
 #else
-static inline void omap_fbdev_init(struct drm_device *dev)
-{
-}
-static inline void omap_fbdev_fini(struct drm_device *dev)
+static inline void omap_fbdev_setup(struct drm_device *dev)
 {
 }
 #endif
Signature · 1 line
2.40.0
#6 lore raw

Re: [PATCH v2 5/5] drm/omapdrm: Implement fbdev emulation as in-kernel client

Quoted 39 lines · Thomas Zimmermann

Move code from ad-hoc fbdev callbacks into DRM client functions and remove the old callbacks. The functions instruct the client to poll for changed output or restore the display. The DRM core calls both, the old callbacks and the new client helpers, from the same places. The new functions perform the same operation as before, so there's no change in functionality.

Replace all code that initializes or releases fbdev emulation throughout the driver. Instead initialize the fbdev client by a single call to omapdrm_fbdev_setup() after omapdrm has registered its DRM device. As in most drivers, omapdrm's fbdev emulation now acts like a regular DRM client.

The fbdev client setup consists of the initial preparation and the hot-plugging of the display. The latter creates the fbdev device and sets up the fbdev framebuffer. The setup performs display hot-plugging once. If no display can be detected, DRM probe helpers re-run the detection on each hotplug event.

A call to drm_dev_unregister() releases the client automatically. No further action is required within omapdrm. If the fbdev framebuffer has been fully set up, struct fb_ops.fb_destroy implements the release. For partially initialized emulation, the fbdev client reverts the initial setup.

v2:
* init drm_client in this patch (Tomi)
* don't handle non-atomic modesetting (Tomi)

---
 drivers/gpu/drm/omapdrm/omap_drv.c   |  11 +--
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 132 +++++++++++++++++----------
 drivers/gpu/drm/omapdrm/omap_fbdev.h |   9 +-
 3 files changed, 90 insertions(+), 62 deletions(-)

drivers/gpu/drm/omapdrm/omap_fbdev.c static int omap_fbdev_pan_display(struct fb_var_screeninfo *var, · line 85

Quoted 9 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +9 -0
+static void omap_fbdev_fb_destroy(struct fb_info *info)
+{
+       struct drm_fb_helper *helper = info->par;
+       struct drm_framebuffer *fb = helper->fb;
+       struct drm_gem_object *bo = drm_gem_fb_get_obj(fb, 0);
+       struct omap_fbdev *fbdev = to_omap_fbdev(helper);
+
+       DBG();
+

What a lovely little surprise. It's a pre-existing "feature", so let's ignore that for now ;-)

Quoted 7 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +7 -0
+       drm_fb_helper_fini(helper);
+
+       omap_gem_unpin(bo);
+       drm_framebuffer_remove(fb);
+
+       drm_client_release(&helper->client);
+       drm_fb_helper_unprepare(helper);

drivers/gpu/drm/omapdrm/omap_fbdev.c static int omap_fbdev_pan_display(struct fb_var_screeninfo *var,

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +7 -1
+       kfree(fbdev);
+}
 
 
-void omap_fbdev_fini(struct drm_device *dev)
+static const struct drm_client_funcs omap_fbdev_client_funcs = {
+       .owner          = THIS_MODULE,
+       .unregister     = omap_fbdev_client_unregister,
+       .restore        = omap_fbdev_client_restore,
+       .hotplug        = omap_fbdev_client_hotplug,

AFAICT the fbdev client helpers above are identical to the generic ones in drm_fbdev_generic.c. Why aren't we reusing those but copy/pasting them in the driver?

Thanks
Emil

author maintainer
#7 lore raw

Re: [PATCH v2 5/5] drm/omapdrm: Implement fbdev emulation as in-kernel client

Hi

Am 03.04.23 um 16:27 schrieb Emil Velikov:

Quoted 40 lines · Thomas Zimmermann
Quoted 38 lines

Move code from ad-hoc fbdev callbacks into DRM client functions and remove the old callbacks. The functions instruct the client to poll for changed output or restore the display. The DRM core calls both, the old callbacks and the new client helpers, from the same places. The new functions perform the same operation as before, so there's no change in functionality.

Replace all code that initializes or releases fbdev emulation throughout the driver. Instead initialize the fbdev client by a single call to omapdrm_fbdev_setup() after omapdrm has registered its DRM device. As in most drivers, omapdrm's fbdev emulation now acts like a regular DRM client.

The fbdev client setup consists of the initial preparation and the hot-plugging of the display. The latter creates the fbdev device and sets up the fbdev framebuffer. The setup performs display hot-plugging once. If no display can be detected, DRM probe helpers re-run the detection on each hotplug event.

A call to drm_dev_unregister() releases the client automatically. No further action is required within omapdrm. If the fbdev framebuffer has been fully set up, struct fb_ops.fb_destroy implements the release. For partially initialized emulation, the fbdev client reverts the initial setup.

v2:
* init drm_client in this patch (Tomi)
* don't handle non-atomic modesetting (Tomi)

---
  drivers/gpu/drm/omapdrm/omap_drv.c   |  11 +--
  drivers/gpu/drm/omapdrm/omap_fbdev.c | 132 +++++++++++++++++----------
  drivers/gpu/drm/omapdrm/omap_fbdev.h |   9 +-
  3 files changed, 90 insertions(+), 62 deletions(-)
Quoted 12 lines

drivers/gpu/drm/omapdrm/omap_fbdev.c static int omap_fbdev_pan_display(struct fb_var_screeninfo *var, · line 85

Quoted 9 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +9 -0
+static void omap_fbdev_fb_destroy(struct fb_info *info)
+{
+       struct drm_fb_helper *helper = info->par;
+       struct drm_framebuffer *fb = helper->fb;
+       struct drm_gem_object *bo = drm_gem_fb_get_obj(fb, 0);
+       struct omap_fbdev *fbdev = to_omap_fbdev(helper);
+
+       DBG();
+

What a lovely little surprise. It's a pre-existing "feature", so let's ignore that for now ;-)

I have no idea what you're talking about. This code was in the original clean-up function. If it is not supposed to be here, I can remove it.

Quoted 12 lines
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +9 -0
+       drm_fb_helper_fini(helper);
+
+       omap_gem_unpin(bo);
+       drm_framebuffer_remove(fb);
+
+       drm_client_release(&helper->client);
+       drm_fb_helper_unprepare(helper);
+       kfree(fbdev);
+}
Quoted 10 lines

drivers/gpu/drm/omapdrm/omap_fbdev.c static struct drm_fb_helper *get_fb(struct fb_info *fbi) · line 301

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +5 -1
-void omap_fbdev_fini(struct drm_device *dev)
+static const struct drm_client_funcs omap_fbdev_client_funcs = {
+       .owner          = THIS_MODULE,
+       .unregister     = omap_fbdev_client_unregister,
+       .restore        = omap_fbdev_client_restore,
+       .hotplug        = omap_fbdev_client_hotplug,

AFAICT the fbdev client helpers above are identical to the generic ones in drm_fbdev_generic.c. Why aren't we reusing those but copy/pasting them in the driver?

The code in drm_fbdev_generic.c (and other fbdev files) might be shareable at some point when I know what exactly I need. I already plan to move some of the damage handling from drm_fb_helper.c to drm_fbdev_generic.c and that will affect the helpers that are currently identical. There's little point in code sharing right now.

I know that the fbdev emulation is convoluted and confusing at times. It's the result of various redesigns and false starts. Things are getting better, though.

Best regards
Thomas

Quoted 3 lines

Thanks
Emil

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
Reviewed-by
#8 lore raw

Re: [PATCH v2 5/5] drm/omapdrm: Implement fbdev emulation as in-kernel client

Quoted 57 lines · Thomas Zimmermann

Hi

Am 03.04.23 um 16:27 schrieb Emil Velikov:

Quoted 40 lines · Thomas Zimmermann
Quoted 38 lines

Move code from ad-hoc fbdev callbacks into DRM client functions and remove the old callbacks. The functions instruct the client to poll for changed output or restore the display. The DRM core calls both, the old callbacks and the new client helpers, from the same places. The new functions perform the same operation as before, so there's no change in functionality.

Replace all code that initializes or releases fbdev emulation throughout the driver. Instead initialize the fbdev client by a single call to omapdrm_fbdev_setup() after omapdrm has registered its DRM device. As in most drivers, omapdrm's fbdev emulation now acts like a regular DRM client.

The fbdev client setup consists of the initial preparation and the hot-plugging of the display. The latter creates the fbdev device and sets up the fbdev framebuffer. The setup performs display hot-plugging once. If no display can be detected, DRM probe helpers re-run the detection on each hotplug event.

A call to drm_dev_unregister() releases the client automatically. No further action is required within omapdrm. If the fbdev framebuffer has been fully set up, struct fb_ops.fb_destroy implements the release. For partially initialized emulation, the fbdev client reverts the initial setup.

v2:
* init drm_client in this patch (Tomi)
* don't handle non-atomic modesetting (Tomi)

---
  drivers/gpu/drm/omapdrm/omap_drv.c   |  11 +--
  drivers/gpu/drm/omapdrm/omap_fbdev.c | 132 +++++++++++++++++----------
  drivers/gpu/drm/omapdrm/omap_fbdev.h |   9 +-
  3 files changed, 90 insertions(+), 62 deletions(-)
Quoted 12 lines

drivers/gpu/drm/omapdrm/omap_fbdev.c static int omap_fbdev_pan_display(struct fb_var_screeninfo *var, · line 85

Quoted 9 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +9 -0
+static void omap_fbdev_fb_destroy(struct fb_info *info)
+{
+       struct drm_fb_helper *helper = info->par;
+       struct drm_framebuffer *fb = helper->fb;
+       struct drm_gem_object *bo = drm_gem_fb_get_obj(fb, 0);
+       struct omap_fbdev *fbdev = to_omap_fbdev(helper);
+
+       DBG();
+

What a lovely little surprise. It's a pre-existing "feature", so let's ignore that for now ;-)

Quoted 3 lines

I have no idea what you're talking about. This code was in the original clean-up function. If it is not supposed to be here, I can remove it.

Precisely - the original code had the DBG() and your change preserves it. Based on my reading, it shouldn't be there ... then again don't read too much into that.

Quoted 23 lines
Quoted 12 lines
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +9 -0
+       drm_fb_helper_fini(helper);
+
+       omap_gem_unpin(bo);
+       drm_framebuffer_remove(fb);
+
+       drm_client_release(&helper->client);
+       drm_fb_helper_unprepare(helper);
+       kfree(fbdev);
+}
Quoted 10 lines

drivers/gpu/drm/omapdrm/omap_fbdev.c static struct drm_fb_helper *get_fb(struct fb_info *fbi) · line 301

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +5 -1
-void omap_fbdev_fini(struct drm_device *dev)
+static const struct drm_client_funcs omap_fbdev_client_funcs = {
+       .owner          = THIS_MODULE,
+       .unregister     = omap_fbdev_client_unregister,
+       .restore        = omap_fbdev_client_restore,
+       .hotplug        = omap_fbdev_client_hotplug,

AFAICT the fbdev client helpers above are identical to the generic ones in drm_fbdev_generic.c. Why aren't we reusing those but copy/pasting them in the driver?

Quoted 7 lines

The code in drm_fbdev_generic.c (and other fbdev files) might be shareable at some point when I know what exactly I need.

I already plan
to move some of the damage handling from drm_fb_helper.c to drm_fbdev_generic.c and that will affect the helpers that are currently identical.

Now that's the piece that I was missing.

Quoted 6 lines

There's little point in code sharing right now.

I know that the fbdev emulation is convoluted and confusing at times. It's the result of various redesigns and false starts. Things are getting better, though.

Been keeping an eye on your work and it's shaping up great. It's deeply appreciated.

Fwiw the series is:

-Emil

author maintainer
#9 lore raw

Re: [PATCH v2 5/5] drm/omapdrm: Implement fbdev emulation as in-kernel client

Hi

Am 03.04.23 um 17:07 schrieb Emil Velikov:

Quoted 106 lines · Thomas Zimmermann
Quoted 57 lines

Hi

Am 03.04.23 um 16:27 schrieb Emil Velikov:

Quoted 40 lines · Thomas Zimmermann
Quoted 38 lines

Move code from ad-hoc fbdev callbacks into DRM client functions and remove the old callbacks. The functions instruct the client to poll for changed output or restore the display. The DRM core calls both, the old callbacks and the new client helpers, from the same places. The new functions perform the same operation as before, so there's no change in functionality.

Replace all code that initializes or releases fbdev emulation throughout the driver. Instead initialize the fbdev client by a single call to omapdrm_fbdev_setup() after omapdrm has registered its DRM device. As in most drivers, omapdrm's fbdev emulation now acts like a regular DRM client.

The fbdev client setup consists of the initial preparation and the hot-plugging of the display. The latter creates the fbdev device and sets up the fbdev framebuffer. The setup performs display hot-plugging once. If no display can be detected, DRM probe helpers re-run the detection on each hotplug event.

A call to drm_dev_unregister() releases the client automatically. No further action is required within omapdrm. If the fbdev framebuffer has been fully set up, struct fb_ops.fb_destroy implements the release. For partially initialized emulation, the fbdev client reverts the initial setup.

v2:
* init drm_client in this patch (Tomi)
* don't handle non-atomic modesetting (Tomi)

---
   drivers/gpu/drm/omapdrm/omap_drv.c   |  11 +--
   drivers/gpu/drm/omapdrm/omap_fbdev.c | 132 +++++++++++++++++----------
   drivers/gpu/drm/omapdrm/omap_fbdev.h |   9 +-
   3 files changed, 90 insertions(+), 62 deletions(-)
Quoted 12 lines

drivers/gpu/drm/omapdrm/omap_fbdev.c static int omap_fbdev_pan_display(struct fb_var_screeninfo *var, · line 85

Quoted 9 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +9 -0
+static void omap_fbdev_fb_destroy(struct fb_info *info)
+{
+       struct drm_fb_helper *helper = info->par;
+       struct drm_framebuffer *fb = helper->fb;
+       struct drm_gem_object *bo = drm_gem_fb_get_obj(fb, 0);
+       struct omap_fbdev *fbdev = to_omap_fbdev(helper);
+
+       DBG();
+

What a lovely little surprise. It's a pre-existing "feature", so let's ignore that for now ;-)

Quoted 3 lines

I have no idea what you're talking about. This code was in the original clean-up function. If it is not supposed to be here, I can remove it.

Precisely - the original code had the DBG() and your change preserves it. Based on my reading, it shouldn't be there ... then again don't read too much into that.

Quoted 23 lines
Quoted 12 lines
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +9 -0
+       drm_fb_helper_fini(helper);
+
+       omap_gem_unpin(bo);
+       drm_framebuffer_remove(fb);
+
+       drm_client_release(&helper->client);
+       drm_fb_helper_unprepare(helper);
+       kfree(fbdev);
+}
Quoted 10 lines

drivers/gpu/drm/omapdrm/omap_fbdev.c static struct drm_fb_helper *get_fb(struct fb_info *fbi) · line 301

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_fbdev.c +5 -1
-void omap_fbdev_fini(struct drm_device *dev)
+static const struct drm_client_funcs omap_fbdev_client_funcs = {
+       .owner          = THIS_MODULE,
+       .unregister     = omap_fbdev_client_unregister,
+       .restore        = omap_fbdev_client_restore,
+       .hotplug        = omap_fbdev_client_hotplug,

AFAICT the fbdev client helpers above are identical to the generic ones in drm_fbdev_generic.c. Why aren't we reusing those but copy/pasting them in the driver?

Quoted 7 lines

The code in drm_fbdev_generic.c (and other fbdev files) might be shareable at some point when I know what exactly I need.

I already plan
to move some of the damage handling from drm_fb_helper.c to drm_fbdev_generic.c and that will affect the helpers that are currently identical.

Now that's the piece that I was missing.

Quoted 6 lines

There's little point in code sharing right now.

I know that the fbdev emulation is convoluted and confusing at times. It's the result of various redesigns and false starts. Things are getting better, though.

Quoted 5 lines

Been keeping an eye on your work and it's shaping up great. It's deeply appreciated.

Fwiw the series is:

Thanks for reviewing.

Best regards
Thomas

Quoted 2 lines

-Emil

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
maintainer
#10 lore raw
In reply to Thomas Zimmermann

Hi Thomas,

Quoted 24 lines · Thomas Zimmermann

Convert omapdrm's fbdev code to struct drm_client. Replaces the current ad-hoc integration. The conversion includes a number of cleanups. As with most other drivers' fbdev emulation, fbdev in omapdrm is now just another DRM client that runs after the DRM device has been registered.

Once all drivers' fbdev emulation has been converted to struct drm_client, we can attempt to add additional in-kernel clients. A DRM-based dmesg log or a bootsplash are commonly mentioned. DRM can then switch easily among the existing clients if/when required.

I did the conversion from similar experience with other drivers. But I don't have the hardware to test this. Any testing is welcome.

v2:
* squashed patch 6 in to patch 5 (Tomi)
* minor cleanups (Tomi)

Thomas Zimmermann (5):
drm/omapdrm: Include <linux/of.h>
drm/omapdrm: Remove fb from struct omap_fbdev drm/omapdrm: Remove bo from struct omap_fbdev drm/omapdrm: Remove fbdev from struct omap_drm_private drm/omapdrm: Implement fbdev emulation as in-kernel client

Quoted 7 lines
  drivers/gpu/drm/omapdrm/omap_debugfs.c |   6 +-
  drivers/gpu/drm/omapdrm/omap_drv.c     |  13 +-
  drivers/gpu/drm/omapdrm/omap_drv.h     |   3 -
  drivers/gpu/drm/omapdrm/omap_fbdev.c   | 163 ++++++++++++++++---------
  drivers/gpu/drm/omapdrm/omap_fbdev.h   |   9 +-
  5 files changed, 112 insertions(+), 82 deletions(-)

I have pushed this to drm-misc-next. Thanks!

Tomi