Skip to contentSkip to conversation

drm/msm: Convert fbdev to DRM client

PATCH Applied Thomas Zimmermann 3 participants 18 messages Apr 3, 2023 – Apr 5, 2023

Subsystems (3)

v2 of 8 Applied Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover drm/msm: Convert fbdev to DRM client

Convert msm' 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 msm 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:
* handle 'fbdev' module parameter in fbdev code
* add missing kfree()
* minor fixes

Thomas Zimmermann (8):
drm/msm: Include <linux/io.h>
drm/msm: Clear aperture ownership outside of fbdev code drm/msm: Remove fb from struct msm_fbdev drm/msm: Remove struct msm_fbdev
drm/msm: Remove fbdev from struct msm_drm_private drm/msm: Move module parameter 'fbdev' to fbdev code drm/msm: Initialize fbdev DRM client
drm/msm: Implement fbdev emulation as in-kernel client

 drivers/gpu/drm/msm/msm_debugfs.c  |   6 +-
 drivers/gpu/drm/msm/msm_drv.c      |  27 ++---
 drivers/gpu/drm/msm/msm_drv.h      |  12 +-
 drivers/gpu/drm/msm/msm_fbdev.c    | 173 +++++++++++++++++------------
 drivers/gpu/drm/msm/msm_io_utils.c |   1 +
 5 files changed, 125 insertions(+), 94 deletions(-)

base-commit: a7180debb9c631375684f4d717466cfb9f238660

Signature · 1 line
2.40.0
#1 lore raw

PATCH v2 1/8 drm/msm: Include <linux/io.h>

Include <linux/io.h> to get the declaration of devm_ioremap() on sparc64. No functional changes.

---
 drivers/gpu/drm/msm/msm_io_utils.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/msm_io_utils.c +1 -0
index d02cd29ce829..59d2788c4510 100644
@@ -6,6 +6,7 @@
  */
 
 #include <linux/interconnect.h>
+#include <linux/io.h>
 
 #include "msm_drv.h"
 
Signature · 1 line
2.40.0
Reviewed-by on v2 1/8
#2 lore raw

Re: [v2,1/8] drm/msm: Include <linux/io.h>

Quoted 22 lines · Thomas Zimmermann

Include <linux/io.h> to get the declaration of devm_ioremap() on sparc64. No functional changes.

---
  drivers/gpu/drm/msm/msm_io_utils.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/msm_io_utils.c +1 -0
index d02cd29ce829..59d2788c4510 100644
@@ -6,6 +6,7 @@
   */
 
  #include <linux/interconnect.h>
+#include <linux/io.h>
 
  #include "msm_drv.h"
 
Reviewed-by on v2 1/8
#3 lore raw

Re: [PATCH v2 1/8] drm/msm: Include <linux/io.h>

In reply to Thomas Zimmermann
Quoted 9 lines · Thomas Zimmermann

Include <linux/io.h> to get the declaration of devm_ioremap() on sparc64. No functional changes.

---
  drivers/gpu/drm/msm/msm_io_utils.c | 1 +
  1 file changed, 1 insertion(+)
Signature · 2 lines
With best wishes
Dmitry
#4 lore raw

PATCH v2 2/8 drm/msm: Clear aperture ownership outside of fbdev code

In reply to Thomas Zimmermann

Move aperture management out of the fbdev code. It is unrelated and needs to run even if fbdev support has been disabled. Call the helper at the top of msm_drm_init() to take over hardware from other drivers.

v2:
* bind all subdevices before acquiring device (Dmitri)

---
 drivers/gpu/drm/msm/msm_drv.c   | 6 ++++++
 drivers/gpu/drm/msm/msm_fbdev.c | 6 ------
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +6 -0
index aca48c868c14..2a1c6ced82c9 100644
@@ -12,6 +12,7 @@
 #include <linux/uaccess.h>
 #include <uapi/linux/sched/types.h>
 
+#include <drm/drm_aperture.h>
 #include <drm/drm_bridge.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
@@ -451,6 +452,11 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
 	if (ret)
 		goto err_drm_dev_put;
 
+	/* the fw fb could be anywhere in memory */
+	ret = drm_aperture_remove_framebuffers(false, drv);
+	if (ret)
+		goto err_drm_dev_put;
+
 	dma_set_max_seg_size(dev, UINT_MAX);
 
 	msm_gem_shrinker_init(ddev);
drivers/gpu/drm/msm/msm_fbdev.c +0 -6
index d26aa52217ce..fc7d0406a9f9 100644
@@ -4,7 +4,6 @@
  * Author: Rob Clark <[email protected]>
  */
 
-#include <drm/drm_aperture.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_fourcc.h>
@@ -154,11 +153,6 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 		goto fail;
 	}
 
-	/* the fw fb could be anywhere in memory */
-	ret = drm_aperture_remove_framebuffers(false, dev->driver);
-	if (ret)
-		goto fini;
-
 	ret = drm_fb_helper_initial_config(helper);
 	if (ret)
 		goto fini;
Signature · 1 line
2.40.0
Reviewed-by on v2 2/8
#5 lore raw

Re: [PATCH v2 2/8] drm/msm: Clear aperture ownership outside of fbdev code

Quoted 5 lines · Thomas Zimmermann

Move aperture management out of the fbdev code. It is unrelated and needs to run even if fbdev support has been disabled. Call the helper at the top of msm_drm_init() to take over hardware from other drivers.

Quoted 8 lines

v2:
* bind all subdevices before acquiring device (Dmitri)

---
  drivers/gpu/drm/msm/msm_drv.c   | 6 ++++++
  drivers/gpu/drm/msm/msm_fbdev.c | 6 ------
  2 files changed, 6 insertions(+), 6 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#6 lore raw

Re: [PATCH v2 2/8] drm/msm: Clear aperture ownership outside of fbdev code

In reply to Thomas Zimmermann
Quoted 27 lines · Thomas Zimmermann

Move aperture management out of the fbdev code. It is unrelated and needs to run even if fbdev support has been disabled. Call the helper at the top of msm_drm_init() to take over hardware from other drivers.

v2:
* bind all subdevices before acquiring device (Dmitri)

---
  drivers/gpu/drm/msm/msm_drv.c   | 6 ++++++
  drivers/gpu/drm/msm/msm_fbdev.c | 6 ------
  2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +1 -0
index aca48c868c14..2a1c6ced82c9 100644
@@ -12,6 +12,7 @@
  #include <linux/uaccess.h>
  #include <uapi/linux/sched/types.h>
 
+#include <drm/drm_aperture.h>
  #include <drm/drm_bridge.h>
  #include <drm/drm_drv.h>
  #include <drm/drm_file.h>

drivers/gpu/drm/msm/msm_drv.c static int msm_drm_init(struct device *dev, const struct drm_driver *drv) · line 458

Quoted 7 lines
drivers/gpu/drm/msm/msm_drv.c +4 -0
@@ -451,6 +452,11 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
  	if (ret)
  		goto err_drm_dev_put;
 
+	/* the fw fb could be anywhere in memory */
+	ret = drm_aperture_remove_framebuffers(false, drv);
+	if (ret)
+		goto err_drm_dev_put;

This should be goto err_msm_uninit to unbind devices. I'll fix this while applying.

Quoted 28 lines
drivers/gpu/drm/msm/msm_drv.c +1 -0
+
  	dma_set_max_seg_size(dev, UINT_MAX);
 
  	msm_gem_shrinker_init(ddev);
drivers/gpu/drm/msm/msm_fbdev.c +0 -6
index d26aa52217ce..fc7d0406a9f9 100644
@@ -4,7 +4,6 @@
   * Author: Rob Clark <[email protected]>
   */
 
-#include <drm/drm_aperture.h>
  #include <drm/drm_crtc.h>
  #include <drm/drm_fb_helper.h>
  #include <drm/drm_fourcc.h>
@@ -154,11 +153,6 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
  		goto fail;
  	}
 
-	/* the fw fb could be anywhere in memory */
-	ret = drm_aperture_remove_framebuffers(false, dev->driver);
-	if (ret)
-		goto fini;
-
  	ret = drm_fb_helper_initial_config(helper);
  	if (ret)
  		goto fini;
Signature · 2 lines
With best wishes
Dmitry
#7 lore raw

PATCH v2 3/8 drm/msm: Remove fb from struct msm_fbdev

In reply to Thomas Zimmermann

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

---
 drivers/gpu/drm/msm/msm_fbdev.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +13 -19
index fc7d0406a9f9..323a79d9ef83 100644
@@ -14,8 +14,6 @@
 #include "msm_gem.h"
 #include "msm_kms.h"
 
-static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma);
-
 /*
  * fbdev funcs, to implement legacy fbdev interface on top of drm driver
  */
@@ -24,9 +22,16 @@ static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma);
 
 struct msm_fbdev {
 	struct drm_fb_helper base;
-	struct drm_framebuffer *fb;
 };
 
+static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)
+{
+	struct drm_fb_helper *helper = (struct drm_fb_helper *)info->par;
+	struct drm_gem_object *bo = msm_framebuffer_bo(helper->fb, 0);
+
+	return drm_gem_prime_mmap(bo, vma);
+}
+
 static const struct fb_ops msm_fb_ops = {
 	.owner = THIS_MODULE,
 	DRM_FB_HELPER_DEFAULT_OPS,
@@ -42,19 +47,9 @@ static const struct fb_ops msm_fb_ops = {
 	.fb_mmap = msm_fbdev_mmap,
 };
 
-static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)
-{
-	struct drm_fb_helper *helper = (struct drm_fb_helper *)info->par;
-	struct msm_fbdev *fbdev = to_msm_fbdev(helper);
-	struct drm_gem_object *bo = msm_framebuffer_bo(fbdev->fb, 0);
-
-	return drm_gem_prime_mmap(bo, vma);
-}
-
 static int msm_fbdev_create(struct drm_fb_helper *helper,
 		struct drm_fb_helper_surface_size *sizes)
 {
-	struct msm_fbdev *fbdev = to_msm_fbdev(helper);
 	struct drm_device *dev = helper->dev;
 	struct msm_drm_private *priv = dev->dev_private;
 	struct drm_framebuffer *fb = NULL;
@@ -101,7 +96,6 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,
 
 	DBG("fbi=%p, dev=%p", fbi, dev);
 
-	fbdev->fb = fb;
 	helper->fb = fb;
 
 	fbi->fbops = &msm_fb_ops;
@@ -118,7 +112,7 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,
 	fbi->fix.smem_len = bo->size;
 
 	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;
 
@@ -173,6 +167,7 @@ void msm_fbdev_free(struct drm_device *dev)
 {
 	struct msm_drm_private *priv = dev->dev_private;
 	struct drm_fb_helper *helper = priv->fbdev;
+	struct drm_framebuffer *fb = helper->fb;
 	struct msm_fbdev *fbdev;
 
 	DBG();
@@ -184,11 +179,10 @@ void msm_fbdev_free(struct drm_device *dev)
 	fbdev = to_msm_fbdev(priv->fbdev);
 
 	/* this will free the backing object */
-	if (fbdev->fb) {
-		struct drm_gem_object *bo =
-			msm_framebuffer_bo(fbdev->fb, 0);
+	if (fb) {
+		struct drm_gem_object *bo = msm_framebuffer_bo(fb, 0);
 		msm_gem_put_vaddr(bo);
-		drm_framebuffer_remove(fbdev->fb);
+		drm_framebuffer_remove(fb);
 	}
 
 	drm_fb_helper_unprepare(helper);
Signature · 1 line
2.40.0
#8 lore raw

PATCH v2 4/8 drm/msm: Remove struct msm_fbdev

In reply to Thomas Zimmermann

Remove struct msm_fbdev, which is an empty wrapper around struct drm_fb_helper. Use the latter directly. No functional changes.

v2:
* kfree fbdev helper instance on init errors (Dmitri)

---
 drivers/gpu/drm/msm/msm_fbdev.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +4 -16
index 323a79d9ef83..81a4ae189a44 100644
@@ -18,12 +18,6 @@
  * fbdev funcs, to implement legacy fbdev interface on top of drm driver
  */
 
-#define to_msm_fbdev(x) container_of(x, struct msm_fbdev, base)
-
-struct msm_fbdev {
-	struct drm_fb_helper base;
-};
-
 static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	struct drm_fb_helper *helper = (struct drm_fb_helper *)info->par;
@@ -129,16 +123,13 @@ static const struct drm_fb_helper_funcs msm_fb_helper_funcs = {
 struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 {
 	struct msm_drm_private *priv = dev->dev_private;
-	struct msm_fbdev *fbdev;
 	struct drm_fb_helper *helper;
 	int ret;
 
-	fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
-	if (!fbdev)
+	helper = kzalloc(sizeof(*helper), GFP_KERNEL);
+	if (!helper)
 		return NULL;
 
-	helper = &fbdev->base;
-
 	drm_fb_helper_prepare(dev, helper, 32, &msm_fb_helper_funcs);
 
 	ret = drm_fb_helper_init(dev, helper);
@@ -159,7 +150,7 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 	drm_fb_helper_fini(helper);
 fail:
 	drm_fb_helper_unprepare(helper);
-	kfree(fbdev);
+	kfree(helper);
 	return NULL;
 }
 
@@ -168,7 +159,6 @@ void msm_fbdev_free(struct drm_device *dev)
 	struct msm_drm_private *priv = dev->dev_private;
 	struct drm_fb_helper *helper = priv->fbdev;
 	struct drm_framebuffer *fb = helper->fb;
-	struct msm_fbdev *fbdev;
 
 	DBG();
 
@@ -176,8 +166,6 @@ void msm_fbdev_free(struct drm_device *dev)
 
 	drm_fb_helper_fini(helper);
 
-	fbdev = to_msm_fbdev(priv->fbdev);
-
 	/* this will free the backing object */
 	if (fb) {
 		struct drm_gem_object *bo = msm_framebuffer_bo(fb, 0);
@@ -186,7 +174,7 @@ void msm_fbdev_free(struct drm_device *dev)
 	}
 
 	drm_fb_helper_unprepare(helper);
-	kfree(fbdev);
+	kfree(helper);
 
 	priv->fbdev = NULL;
 }
Signature · 1 line
2.40.0
Reviewed-by on v2 4/8
#9 lore raw

Re: [PATCH v2 4/8] drm/msm: Remove struct msm_fbdev

Quoted 11 lines · Thomas Zimmermann

Remove struct msm_fbdev, which is an empty wrapper around struct drm_fb_helper. Use the latter directly. No functional changes.

v2:
* kfree fbdev helper instance on init errors (Dmitri)

---
  drivers/gpu/drm/msm/msm_fbdev.c | 20 ++++----------------
  1 file changed, 4 insertions(+), 16 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#10 lore raw

PATCH v2 5/8 drm/msm: Remove fbdev from struct msm_drm_private

In reply to Thomas Zimmermann

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

v2:
* test for fb_helper->fb in debugfs code

---
 drivers/gpu/drm/msm/msm_debugfs.c | 5 ++---
 drivers/gpu/drm/msm/msm_drv.c     | 4 ++--
 drivers/gpu/drm/msm/msm_drv.h     | 2 --
 drivers/gpu/drm/msm/msm_fbdev.c   | 8 ++------
 4 files changed, 6 insertions(+), 13 deletions(-)
drivers/gpu/drm/msm/msm_debugfs.c +2 -3
index d6ecff0ab618..7de9e39f051e 100644
@@ -241,12 +241,11 @@ static int msm_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 msm_drm_private *priv = dev->dev_private;
 	struct drm_framebuffer *fb, *fbdev_fb = NULL;
 
-	if (priv->fbdev) {
+	if (dev->fb_helper && dev->fb_helper->fb) {
 		seq_printf(m, "fbcon ");
-		fbdev_fb = priv->fbdev->fb;
+		fbdev_fb = dev->fb_helper->fb;
 		msm_framebuffer_describe(fbdev_fb, m);
 	}
 
drivers/gpu/drm/msm/msm_drv.c +2 -2
index 2a1c6ced82c9..14f4bc33b50b 100644
@@ -242,7 +242,7 @@ static int msm_drm_uninit(struct device *dev)
 	msm_rd_debugfs_cleanup(priv);
 
 #ifdef CONFIG_DRM_FBDEV_EMULATION
-	if (fbdev && priv->fbdev)
+	if (fbdev && ddev->fb_helper)
 		msm_fbdev_free(ddev);
 #endif
 
@@ -537,7 +537,7 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
 
 #ifdef CONFIG_DRM_FBDEV_EMULATION
 	if (kms && fbdev)
-		priv->fbdev = msm_fbdev_init(ddev);
+		msm_fbdev_init(ddev);
 #endif
 
 	ret = msm_debugfs_late_init(ddev);
drivers/gpu/drm/msm/msm_drv.h +0 -2
index 9f0c184b02a0..852f88c36621 100644
@@ -129,8 +129,6 @@ struct msm_drm_private {
 	bool is_a2xx;
 	bool has_cached_coherent;
 
-	struct drm_fb_helper *fbdev;
-
 	struct msm_rd_state *rd;       /* debugfs to dump all submits */
 	struct msm_rd_state *hangrd;   /* debugfs to dump hanging submits */
 	struct msm_perf_state *perf;
drivers/gpu/drm/msm/msm_fbdev.c +2 -6
index 81a4ae189a44..0bd0cb85c538 100644
@@ -122,7 +122,6 @@ static const struct drm_fb_helper_funcs msm_fb_helper_funcs = {
 /* initialize fbdev helper */
 struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 {
-	struct msm_drm_private *priv = dev->dev_private;
 	struct drm_fb_helper *helper;
 	int ret;
 
@@ -142,8 +141,6 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 	if (ret)
 		goto fini;
 
-	priv->fbdev = helper;
-
 	return helper;
 
 fini:
@@ -156,8 +153,7 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 
 void msm_fbdev_free(struct drm_device *dev)
 {
-	struct msm_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 = helper->fb;
 
 	DBG();
@@ -176,5 +172,5 @@ void msm_fbdev_free(struct drm_device *dev)
 	drm_fb_helper_unprepare(helper);
 	kfree(helper);
 
-	priv->fbdev = NULL;
+	dev->fb_helper = NULL;
 }
Signature · 1 line
2.40.0
#11 lore raw

PATCH v2 6/8 drm/msm: Move module parameter 'fbdev' to fbdev code

In reply to Thomas Zimmermann

Define the module's parameter 'fbdev' in fbdev code. No other code uses it. No functional changes, but simplifies the later conversion to struct drm_client.

---
 drivers/gpu/drm/msm/msm_drv.c   | 10 ++--------
 drivers/gpu/drm/msm/msm_fbdev.c |  7 +++++++
 2 files changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +2 -8
index 14f4bc33b50b..4bf486f0ebb9 100644
@@ -63,12 +63,6 @@ static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = {
 	.atomic_commit_tail = msm_atomic_commit_tail,
 };
 
-#ifdef CONFIG_DRM_FBDEV_EMULATION
-static bool fbdev = true;
-MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
-module_param(fbdev, bool, 0600);
-#endif
-
 static char *vram = "16m";
 MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
 module_param(vram, charp, 0);
@@ -242,7 +236,7 @@ static int msm_drm_uninit(struct device *dev)
 	msm_rd_debugfs_cleanup(priv);
 
 #ifdef CONFIG_DRM_FBDEV_EMULATION
-	if (fbdev && ddev->fb_helper)
+	if (ddev->fb_helper)
 		msm_fbdev_free(ddev);
 #endif
 
@@ -536,7 +530,7 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
 	drm_mode_config_reset(ddev);
 
 #ifdef CONFIG_DRM_FBDEV_EMULATION
-	if (kms && fbdev)
+	if (kms)
 		msm_fbdev_init(ddev);
 #endif
 
drivers/gpu/drm/msm/msm_fbdev.c +7 -0
index 0bd0cb85c538..7d205632b165 100644
@@ -14,6 +14,10 @@
 #include "msm_gem.h"
 #include "msm_kms.h"
 
+static bool fbdev = true;
+MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
+module_param(fbdev, bool, 0600);
+
 /*
  * fbdev funcs, to implement legacy fbdev interface on top of drm driver
  */
@@ -125,6 +129,9 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 	struct drm_fb_helper *helper;
 	int ret;
 
+	if (!fbdev)
+		return NULL;
+
 	helper = kzalloc(sizeof(*helper), GFP_KERNEL);
 	if (!helper)
 		return NULL;
Signature · 1 line
2.40.0
Reviewed-by on v2 6/8
#12 lore raw

Re: [PATCH v2 6/8] drm/msm: Move module parameter 'fbdev' to fbdev code

Quoted 9 lines · Thomas Zimmermann

Define the module's parameter 'fbdev' in fbdev code. No other code uses it. No functional changes, but simplifies the later conversion to struct drm_client.

---
  drivers/gpu/drm/msm/msm_drv.c   | 10 ++--------
  drivers/gpu/drm/msm/msm_fbdev.c |  7 +++++++
  2 files changed, 9 insertions(+), 8 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#13 lore raw

PATCH v2 7/8 drm/msm: Initialize fbdev DRM client

In reply to Thomas Zimmermann

Initialize the fbdev client in the fbdev code with empty helper functions. Also clean up the client. The helpers will later implement various functionality of the DRM client. No functional changes.

---
 drivers/gpu/drm/msm/msm_fbdev.c | 37 +++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +35 -2
index 7d205632b165..77788c6c802d 100644
@@ -123,6 +123,30 @@ static const struct drm_fb_helper_funcs msm_fb_helper_funcs = {
 	.fb_probe = msm_fbdev_create,
 };
 
+/*
+ * struct drm_client
+ */
+
+static void msm_fbdev_client_unregister(struct drm_client_dev *client)
+{ }
+
+static int msm_fbdev_client_restore(struct drm_client_dev *client)
+{
+	return 0;
+}
+
+static int msm_fbdev_client_hotplug(struct drm_client_dev *client)
+{
+	return 0;
+}
+
+static const struct drm_client_funcs msm_fbdev_client_funcs = {
+	.owner		= THIS_MODULE,
+	.unregister	= msm_fbdev_client_unregister,
+	.restore	= msm_fbdev_client_restore,
+	.hotplug	= msm_fbdev_client_hotplug,
+};
+
 /* initialize fbdev helper */
 struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 {
@@ -138,10 +162,16 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 
 	drm_fb_helper_prepare(dev, helper, 32, &msm_fb_helper_funcs);
 
+	ret = drm_client_init(dev, &helper->client, "fbdev", &msm_fbdev_client_funcs);
+	if (ret) {
+		drm_err(dev, "Failed to register client: %d\n", ret);
+		goto err_drm_fb_helper_unprepare;
+	}
+
 	ret = drm_fb_helper_init(dev, helper);
 	if (ret) {
 		DRM_DEV_ERROR(dev->dev, "could not init fbdev: ret=%d\n", ret);
-		goto fail;
+		goto err_drm_client_release;
 	}
 
 	ret = drm_fb_helper_initial_config(helper);
@@ -152,7 +182,9 @@ struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev)
 
 fini:
 	drm_fb_helper_fini(helper);
-fail:
+err_drm_client_release:
+	drm_client_release(&helper->client);
+err_drm_fb_helper_unprepare:
 	drm_fb_helper_unprepare(helper);
 	kfree(helper);
 	return NULL;
@@ -176,6 +208,7 @@ void msm_fbdev_free(struct drm_device *dev)
 		drm_framebuffer_remove(fb);
 	}
 
+	drm_client_release(&helper->client);
 	drm_fb_helper_unprepare(helper);
 	kfree(helper);
 
Signature · 1 line
2.40.0
#14 lore raw

PATCH v2 8/8 drm/msm: 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 msm_fbdev_setup() after msm has registered its DRM device. As in most drivers, msm'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 msm. 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:
* handle fbdev module parameter correctly (kernel test robot)

---
 drivers/gpu/drm/msm/msm_debugfs.c |   1 +
 drivers/gpu/drm/msm/msm_drv.c     |  15 +---
 drivers/gpu/drm/msm/msm_drv.h     |  10 ++-
 drivers/gpu/drm/msm/msm_fbdev.c   | 115 ++++++++++++++++++------------
 4 files changed, 81 insertions(+), 60 deletions(-)
drivers/gpu/drm/msm/msm_debugfs.c +1 -0
index 7de9e39f051e..9c0e633a3a61 100644
@@ -10,6 +10,7 @@
 #include <linux/fault-inject.h>
 
 #include <drm/drm_debugfs.h>
+#include <drm/drm_fb_helper.h>
 #include <drm/drm_file.h>
 #include <drm/drm_framebuffer.h>
 
drivers/gpu/drm/msm/msm_drv.c +3 -12
index 4bf486f0ebb9..b4d7968e4251 100644
@@ -54,7 +54,6 @@
 
 static const struct drm_mode_config_funcs mode_config_funcs = {
 	.fb_create = msm_framebuffer_create,
-	.output_poll_changed = drm_fb_helper_output_poll_changed,
 	.atomic_check = drm_atomic_helper_check,
 	.atomic_commit = drm_atomic_helper_commit,
 };
@@ -235,11 +234,6 @@ static int msm_drm_uninit(struct device *dev)
 	msm_perf_debugfs_cleanup(priv);
 	msm_rd_debugfs_cleanup(priv);
 
-#ifdef CONFIG_DRM_FBDEV_EMULATION
-	if (ddev->fb_helper)
-		msm_fbdev_free(ddev);
-#endif
-
 	msm_disp_snapshot_destroy(ddev);
 
 	drm_mode_config_cleanup(ddev);
@@ -529,17 +523,15 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv)
 	}
 	drm_mode_config_reset(ddev);
 
-#ifdef CONFIG_DRM_FBDEV_EMULATION
-	if (kms)
-		msm_fbdev_init(ddev);
-#endif
-
 	ret = msm_debugfs_late_init(ddev);
 	if (ret)
 		goto err_msm_uninit;
 
 	drm_kms_helper_poll_init(ddev);
 
+	if (kms)
+		msm_fbdev_setup(ddev);
+
 	return 0;
 
 err_msm_uninit:
@@ -1068,7 +1060,6 @@ static const struct drm_driver msm_driver = {
 				DRIVER_SYNCOBJ,
 	.open               = msm_open,
 	.postclose           = msm_postclose,
-	.lastclose          = drm_fb_helper_lastclose,
 	.dumb_create        = msm_gem_dumb_create,
 	.dumb_map_offset    = msm_gem_dumb_map_offset,
 	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
drivers/gpu/drm/msm/msm_drv.h +7 -3
index 852f88c36621..11a9d2ce07a1 100644
@@ -29,7 +29,6 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_probe_helper.h>
-#include <drm/drm_fb_helper.h>
 #include <drm/display/drm_dsc.h>
 #include <drm/msm_drm.h>
 #include <drm/drm_gem.h>
@@ -304,8 +303,13 @@ struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
 struct drm_framebuffer * msm_alloc_stolen_fb(struct drm_device *dev,
 		int w, int h, int p, uint32_t format);
 
-struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
-void msm_fbdev_free(struct drm_device *dev);
+#ifdef CONFIG_DRM_FBDEV_EMULATION
+void msm_fbdev_setup(struct drm_device *dev);
+#else
+static inline void msm_fbdev_setup(struct drm_device *dev)
+{
+}
+#endif
 
 struct hdmi;
 #ifdef CONFIG_DRM_MSM_HDMI
drivers/gpu/drm/msm/msm_fbdev.c +70 -45

172 lines not on this page · raw message

Signature · 1 line
2.40.0
Reviewed-by Tested-by on v2 8/8
#15 lore raw

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

Quoted 28 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 msm_fbdev_setup() after msm has registered its DRM device. As in most drivers, msm'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 msm. 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:
* handle fbdev module parameter correctly (kernel test robot)

Quoted 8 lines
---
  drivers/gpu/drm/msm/msm_debugfs.c |   1 +
  drivers/gpu/drm/msm/msm_drv.c     |  15 +---
  drivers/gpu/drm/msm/msm_drv.h     |  10 ++-
  drivers/gpu/drm/msm/msm_fbdev.c   | 115 ++++++++++++++++++------------
  4 files changed, 81 insertions(+), 60 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#16 lore raw
In reply to Thomas Zimmermann
Quoted 11 lines · Thomas Zimmermann

Convert msm' 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 msm 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.

[...]

Applied, thanks!

[1/8] drm/msm: Include <linux/io.h>

      https://gitlab.freedesktop.org/lumag/msm/-/commit/62c58ffe011d
[2/8] drm/msm: Clear aperture ownership outside of fbdev code
      https://gitlab.freedesktop.org/lumag/msm/-/commit/f4de16da5b40

[3/8] drm/msm: Remove fb from struct msm_fbdev
https://gitlab.freedesktop.org/lumag/msm/-/commit/a5ddc0f1a7bc
[4/8] drm/msm: Remove struct msm_fbdev
https://gitlab.freedesktop.org/lumag/msm/-/commit/09cbdbafbe9f
[5/8] drm/msm: Remove fbdev from struct msm_drm_private

      https://gitlab.freedesktop.org/lumag/msm/-/commit/37e8bad3ae5d
[6/8] drm/msm: Move module parameter 'fbdev' to fbdev code
      https://gitlab.freedesktop.org/lumag/msm/-/commit/2fa4748b5ad8
[7/8] drm/msm: Initialize fbdev DRM client
      https://gitlab.freedesktop.org/lumag/msm/-/commit/7e563538d210
[8/8] drm/msm: Implement fbdev emulation as in-kernel client
      https://gitlab.freedesktop.org/lumag/msm/-/commit/5ba5b96d3327

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>
#17 lore raw

Am 05.04.23 um 03:35 schrieb Dmitry Baryshkov:

Quoted 7 lines · Thomas Zimmermann
Quoted 5 lines

Convert msm' 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 msm is now just another DRM client that runs after the DRM device has been registered.

Quoted 8 lines
Quoted 6 lines

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.

[...]

Applied, thanks!

Great, thanks a lot!

Best regards
Thomas

Quoted 19 lines

[1/8] drm/msm: Include <linux/io.h>

       https://gitlab.freedesktop.org/lumag/msm/-/commit/62c58ffe011d
[2/8] drm/msm: Clear aperture ownership outside of fbdev code
       https://gitlab.freedesktop.org/lumag/msm/-/commit/f4de16da5b40

[3/8] drm/msm: Remove fb from struct msm_fbdev
https://gitlab.freedesktop.org/lumag/msm/-/commit/a5ddc0f1a7bc
[4/8] drm/msm: Remove struct msm_fbdev
https://gitlab.freedesktop.org/lumag/msm/-/commit/09cbdbafbe9f
[5/8] drm/msm: Remove fbdev from struct msm_drm_private

       https://gitlab.freedesktop.org/lumag/msm/-/commit/37e8bad3ae5d
[6/8] drm/msm: Move module parameter 'fbdev' to fbdev code
       https://gitlab.freedesktop.org/lumag/msm/-/commit/2fa4748b5ad8
[7/8] drm/msm: Initialize fbdev DRM client
       https://gitlab.freedesktop.org/lumag/msm/-/commit/7e563538d210
[8/8] drm/msm: Implement fbdev emulation as in-kernel client
       https://gitlab.freedesktop.org/lumag/msm/-/commit/5ba5b96d3327

Best regards,

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