Skip to contentSkip to conversation

drm/exynos: Convert fbdev to DRM client

PATCH In review Thomas Zimmermann 2 participants 8 messages Mar 30, 2023 – Apr 3, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drm/exynos: Convert fbdev to DRM client

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

Thomas Zimmermann (5):
drm/exynos: Remove exynos_gem from struct exynos_drm_fbdev drm/exynos: Remove struct exynos_drm_fbdev drm/exynos: Remove fb_helper from struct exynos_drm_private drm/exynos: Initialize fbdev DRM client drm/exynos: Implement fbdev emulation as in-kernel client

 drivers/gpu/drm/exynos/exynos_drm_drv.c   |  13 +-
 drivers/gpu/drm/exynos/exynos_drm_drv.h   |   2 -
 drivers/gpu/drm/exynos/exynos_drm_fb.c    |   2 -
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 174 +++++++++++-----------
 drivers/gpu/drm/exynos/exynos_drm_fbdev.h |  20 +--
 5 files changed, 94 insertions(+), 117 deletions(-)
Signature · 1 line
2.40.0
#2 lore raw

PATCH 2/5 drm/exynos: Remove struct exynos_drm_fbdev

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

---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +5 -16
index f11895d32982..e7059850baa2 100644
@@ -28,13 +28,6 @@
 #define MAX_CONNECTOR		4
 #define PREFERRED_BPP		32
 
-#define to_exynos_fbdev(x)	container_of(x, struct exynos_drm_fbdev,\
-				drm_fb_helper)
-
-struct exynos_drm_fbdev {
-	struct drm_fb_helper	drm_fb_helper;
-};
-
 static int exynos_drm_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	struct drm_fb_helper *helper = info->par;
@@ -144,7 +137,6 @@ static const struct drm_fb_helper_funcs exynos_drm_fb_helper_funcs = {
 
 int exynos_drm_fbdev_init(struct drm_device *dev)
 {
-	struct exynos_drm_fbdev *fbdev;
 	struct exynos_drm_private *private = dev->dev_private;
 	struct drm_fb_helper *helper;
 	int ret;
@@ -152,11 +144,11 @@ int exynos_drm_fbdev_init(struct drm_device *dev)
 	if (!dev->mode_config.num_crtc)
 		return 0;
 
-	fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
-	if (!fbdev)
+	helper = kzalloc(sizeof(*helper), GFP_KERNEL);
+	if (!helper)
 		return -ENOMEM;
 
-	private->fb_helper = helper = &fbdev->drm_fb_helper;
+	private->fb_helper = helper;
 
 	drm_fb_helper_prepare(dev, helper, PREFERRED_BPP, &exynos_drm_fb_helper_funcs);
 
@@ -181,7 +173,7 @@ int exynos_drm_fbdev_init(struct drm_device *dev)
 err_init:
 	drm_fb_helper_unprepare(helper);
 	private->fb_helper = NULL;
-	kfree(fbdev);
+	kfree(helper);
 
 	return ret;
 }
@@ -206,16 +198,13 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
 void exynos_drm_fbdev_fini(struct drm_device *dev)
 {
 	struct exynos_drm_private *private = dev->dev_private;
-	struct exynos_drm_fbdev *fbdev;
 
 	if (!private || !private->fb_helper)
 		return;
 
-	fbdev = to_exynos_fbdev(private->fb_helper);
-
 	exynos_drm_fbdev_destroy(dev, private->fb_helper);
 	drm_fb_helper_unprepare(private->fb_helper);
-	kfree(fbdev);
+	kfree(private->fb_helper);
 	private->fb_helper = NULL;
 }
 
Signature · 1 line
2.40.0
#3 lore raw

PATCH 3/5 drm/exynos: Remove fb_helper from struct exynos_drm_private

In reply to Thomas Zimmermann

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

---
 drivers/gpu/drm/exynos/exynos_drm_drv.h   |  2 --
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 15 +++++----------
 2 files changed, 5 insertions(+), 12 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_drv.h +0 -2
index 6ae9056e7a18..81d501efd013 100644
@@ -197,8 +197,6 @@ struct drm_exynos_file_private {
  * @wait: wait an atomic commit to finish
  */
 struct exynos_drm_private {
-	struct drm_fb_helper *fb_helper;
-
 	struct device *g2d_dev;
 	struct device *dma_dev;
 	void *mapping;
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +5 -10
index e7059850baa2..81f909cb5c9b 100644
@@ -137,7 +137,6 @@ static const struct drm_fb_helper_funcs exynos_drm_fb_helper_funcs = {
 
 int exynos_drm_fbdev_init(struct drm_device *dev)
 {
-	struct exynos_drm_private *private = dev->dev_private;
 	struct drm_fb_helper *helper;
 	int ret;
 
@@ -148,8 +147,6 @@ int exynos_drm_fbdev_init(struct drm_device *dev)
 	if (!helper)
 		return -ENOMEM;
 
-	private->fb_helper = helper;
-
 	drm_fb_helper_prepare(dev, helper, PREFERRED_BPP, &exynos_drm_fb_helper_funcs);
 
 	ret = drm_fb_helper_init(dev, helper);
@@ -172,7 +169,6 @@ int exynos_drm_fbdev_init(struct drm_device *dev)
 	drm_fb_helper_fini(helper);
 err_init:
 	drm_fb_helper_unprepare(helper);
-	private->fb_helper = NULL;
 	kfree(helper);
 
 	return ret;
@@ -197,14 +193,13 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
 
 void exynos_drm_fbdev_fini(struct drm_device *dev)
 {
-	struct exynos_drm_private *private = dev->dev_private;
+	struct drm_fb_helper *fb_helper = dev->fb_helper;
 
-	if (!private || !private->fb_helper)
+	if (!fb_helper)
 		return;
 
-	exynos_drm_fbdev_destroy(dev, private->fb_helper);
-	drm_fb_helper_unprepare(private->fb_helper);
-	kfree(private->fb_helper);
-	private->fb_helper = NULL;
+	exynos_drm_fbdev_destroy(dev, fb_helper);
+	drm_fb_helper_unprepare(fb_helper);
+	kfree(fb_helper);
 }
 
Signature · 1 line
2.40.0
#1 lore raw

PATCH 1/5 drm/exynos: Remove exynos_gem from struct exynos_drm_fbdev

In reply to Thomas Zimmermann

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

---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +4 -9
index 4929ffe5a09a..f11895d32982 100644
@@ -16,6 +16,7 @@
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_prime.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/exynos_drm.h>
@@ -32,17 +33,14 @@
 
 struct exynos_drm_fbdev {
 	struct drm_fb_helper	drm_fb_helper;
-	struct exynos_drm_gem	*exynos_gem;
 };
 
-static int exynos_drm_fb_mmap(struct fb_info *info,
-			struct vm_area_struct *vma)
+static int exynos_drm_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
 {
 	struct drm_fb_helper *helper = info->par;
-	struct exynos_drm_fbdev *exynos_fbd = to_exynos_fbdev(helper);
-	struct exynos_drm_gem *exynos_gem = exynos_fbd->exynos_gem;
+	struct drm_gem_object *obj = drm_gem_fb_get_obj(helper->fb, 0);
 
-	return drm_gem_prime_mmap(&exynos_gem->base, vma);
+	return drm_gem_prime_mmap(obj, vma);
 }
 
 static const struct fb_ops exynos_drm_fb_ops = {
@@ -89,7 +87,6 @@ static int exynos_drm_fbdev_update(struct drm_fb_helper *helper,
 static int exynos_drm_fbdev_create(struct drm_fb_helper *helper,
 				    struct drm_fb_helper_surface_size *sizes)
 {
-	struct exynos_drm_fbdev *exynos_fbdev = to_exynos_fbdev(helper);
 	struct exynos_drm_gem *exynos_gem;
 	struct drm_device *dev = helper->dev;
 	struct drm_mode_fb_cmd2 mode_cmd = { 0 };
@@ -113,8 +110,6 @@ static int exynos_drm_fbdev_create(struct drm_fb_helper *helper,
 	if (IS_ERR(exynos_gem))
 		return PTR_ERR(exynos_gem);
 
-	exynos_fbdev->exynos_gem = exynos_gem;
-
 	helper->fb =
 		exynos_drm_framebuffer_init(dev, &mode_cmd, &exynos_gem, 1);
 	if (IS_ERR(helper->fb)) {
Signature · 1 line
2.40.0
#4 lore raw

PATCH 4/5 drm/exynos: 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/exynos/exynos_drm_fbdev.c | 35 +++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +33 -2
index 81f909cb5c9b..d1de49530c48 100644
@@ -135,6 +135,30 @@ static const struct drm_fb_helper_funcs exynos_drm_fb_helper_funcs = {
 	.fb_probe =	exynos_drm_fbdev_create,
 };
 
+/*
+ * struct drm_client
+ */
+
+static void exynos_drm_fbdev_client_unregister(struct drm_client_dev *client)
+{ }
+
+static int exynos_drm_fbdev_client_restore(struct drm_client_dev *client)
+{
+	return 0;
+}
+
+static int exynos_drm_fbdev_client_hotplug(struct drm_client_dev *client)
+{
+	return 0;
+}
+
+static const struct drm_client_funcs exynos_drm_fbdev_client_funcs = {
+	.owner		= THIS_MODULE,
+	.unregister	= exynos_drm_fbdev_client_unregister,
+	.restore	= exynos_drm_fbdev_client_restore,
+	.hotplug	= exynos_drm_fbdev_client_hotplug,
+};
+
 int exynos_drm_fbdev_init(struct drm_device *dev)
 {
 	struct drm_fb_helper *helper;
@@ -149,11 +173,15 @@ int exynos_drm_fbdev_init(struct drm_device *dev)
 
 	drm_fb_helper_prepare(dev, helper, PREFERRED_BPP, &exynos_drm_fb_helper_funcs);
 
+	ret = drm_client_init(dev, &helper->client, "exynos-fbdev", &exynos_drm_fbdev_client_funcs);
+	if (ret)
+		goto err_drm_fb_helper_unprepare;
+
 	ret = drm_fb_helper_init(dev, helper);
 	if (ret < 0) {
 		DRM_DEV_ERROR(dev->dev,
 			      "failed to initialize drm fb helper.\n");
-		goto err_init;
+		goto err_drm_client_release;
 	}
 
 	ret = drm_fb_helper_initial_config(helper);
@@ -167,7 +195,9 @@ int exynos_drm_fbdev_init(struct drm_device *dev)
 
 err_setup:
 	drm_fb_helper_fini(helper);
-err_init:
+err_drm_client_release:
+	drm_client_release(&helper->client);
+err_drm_fb_helper_unprepare:
 	drm_fb_helper_unprepare(helper);
 	kfree(helper);
 
@@ -199,6 +229,7 @@ void exynos_drm_fbdev_fini(struct drm_device *dev)
 		return;
 
 	exynos_drm_fbdev_destroy(dev, fb_helper);
+	drm_client_release(&fb_helper->client);
 	drm_fb_helper_unprepare(fb_helper);
 	kfree(fb_helper);
 }
Signature · 1 line
2.40.0
#5 lore raw

PATCH 5/5 drm/exynos: 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 exynos_fbdev_setup() after exynos has registered its DRM device. As in most drivers, exynos' 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 exynos. 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.

---
 drivers/gpu/drm/exynos/exynos_drm_drv.c   |  13 +-
 drivers/gpu/drm/exynos/exynos_drm_fb.c    |   2 -
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 150 +++++++++++-----------
 drivers/gpu/drm/exynos/exynos_drm_fbdev.h |  20 +--
 4 files changed, 77 insertions(+), 108 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_drv.c +3 -10
index 16c539657f73..6b73fb7a83c3 100644
@@ -16,7 +16,6 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_drv.h>
-#include <drm/drm_fb_helper.h>
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_ioctl.h>
@@ -108,7 +107,6 @@ static const struct drm_driver exynos_drm_driver = {
 	.driver_features	= DRIVER_MODESET | DRIVER_GEM
 				  | DRIVER_ATOMIC | DRIVER_RENDER,
 	.open			= exynos_drm_open,
-	.lastclose		= drm_fb_helper_lastclose,
 	.postclose		= exynos_drm_postclose,
 	.dumb_create		= exynos_drm_gem_dumb_create,
 	.prime_handle_to_fd	= drm_gem_prime_handle_to_fd,
@@ -288,19 +286,15 @@ static int exynos_drm_bind(struct device *dev)
 	/* init kms poll for handling hpd */
 	drm_kms_helper_poll_init(drm);
 
-	ret = exynos_drm_fbdev_init(drm);
-	if (ret)
-		goto err_cleanup_poll;
-
 	/* register the DRM device */
 	ret = drm_dev_register(drm, 0);
 	if (ret < 0)
-		goto err_cleanup_fbdev;
+		goto err_cleanup_poll;
+
+	exynos_drm_fbdev_setup(drm);
 
 	return 0;
 
-err_cleanup_fbdev:
-	exynos_drm_fbdev_fini(drm);
 err_cleanup_poll:
 	drm_kms_helper_poll_fini(drm);
 err_unbind_all:
@@ -321,7 +315,6 @@ static void exynos_drm_unbind(struct device *dev)
 
 	drm_dev_unregister(drm);
 
-	exynos_drm_fbdev_fini(drm);
 	drm_kms_helper_poll_fini(drm);
 
 	component_unbind_all(drm->dev, drm);
drivers/gpu/drm/exynos/exynos_drm_fb.c +0 -2
index 97f2dee2db29..fc1c5608db96 100644
@@ -11,7 +11,6 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc.h>
-#include <drm/drm_fb_helper.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_gem_framebuffer_helper.h>
@@ -157,7 +156,6 @@ static struct drm_mode_config_helper_funcs exynos_drm_mode_config_helpers = {
 
 static const struct drm_mode_config_funcs exynos_drm_mode_config_funcs = {
 	.fb_create = exynos_user_fb_create,
-	.output_poll_changed = drm_fb_helper_output_poll_changed,
 	.atomic_check = drm_atomic_helper_check,
 	.atomic_commit = drm_atomic_helper_commit,
 };
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +72 -78

214 lines not on this page · raw message

drivers/gpu/drm/exynos/exynos_drm_fbdev.h +2 -18
index 3b1e98e84580..1e1dea627cd9 100644
@@ -12,27 +12,11 @@
 #define _EXYNOS_DRM_FBDEV_H_
 
 #ifdef CONFIG_DRM_FBDEV_EMULATION
-
-int exynos_drm_fbdev_init(struct drm_device *dev);
-void exynos_drm_fbdev_fini(struct drm_device *dev);
-
+void exynos_drm_fbdev_setup(struct drm_device *dev);
 #else
-
-static inline int exynos_drm_fbdev_init(struct drm_device *dev)
-{
-	return 0;
-}
-
-static inline void exynos_drm_fbdev_fini(struct drm_device *dev)
+static inline void exynos_drm_fbdev_setup(struct drm_device *dev)
 {
 }
-
-static inline void exynos_drm_fbdev_restore_mode(struct drm_device *dev)
-{
-}
-
-#define exynos_drm_output_poll_changed (NULL)
-
 #endif
 
 #endif
Signature · 1 line
2.40.0
Tested-by on the v1 series
#6 lore raw
In reply to Thomas Zimmermann
Quoted 5 lines · Thomas Zimmermann

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

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

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

Seems to be working fine. Tested with default framebuffer based console and simple tool that writes RGB data to /dev/fb0.

Quoted 7 lines

Thomas Zimmermann (5):
drm/exynos: Remove exynos_gem from struct exynos_drm_fbdev drm/exynos: Remove struct exynos_drm_fbdev drm/exynos: Remove fb_helper from struct exynos_drm_private drm/exynos: Initialize fbdev DRM client drm/exynos: Implement fbdev emulation as in-kernel client

Quoted 7 lines
  drivers/gpu/drm/exynos/exynos_drm_drv.c   |  13 +-
  drivers/gpu/drm/exynos/exynos_drm_drv.h   |   2 -
  drivers/gpu/drm/exynos/exynos_drm_fb.c    |   2 -
  drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 174 +++++++++++-----------
  drivers/gpu/drm/exynos/exynos_drm_fbdev.h |  20 +--
  5 files changed, 94 insertions(+), 117 deletions(-)

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#7 lore raw

Am 31.03.23 um 12:36 schrieb Marek Szyprowski:

Quoted 11 lines · Thomas Zimmermann
Quoted 10 lines

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

Quoted 7 lines
Quoted 2 lines

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

Seems to be working fine. Tested with default framebuffer based console and simple tool that writes RGB data to /dev/fb0.

Thanks a lot for testing.

Quoted 17 lines
Quoted 9 lines

Thomas Zimmermann (5):
drm/exynos: Remove exynos_gem from struct exynos_drm_fbdev drm/exynos: Remove struct exynos_drm_fbdev drm/exynos: Remove fb_helper from struct exynos_drm_private drm/exynos: Initialize fbdev DRM client drm/exynos: Implement fbdev emulation as in-kernel client

Quoted 7 lines
   drivers/gpu/drm/exynos/exynos_drm_drv.c   |  13 +-
   drivers/gpu/drm/exynos/exynos_drm_drv.h   |   2 -
   drivers/gpu/drm/exynos/exynos_drm_fb.c    |   2 -
   drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 174 +++++++++++-----------
   drivers/gpu/drm/exynos/exynos_drm_fbdev.h |  20 +--
   5 files changed, 94 insertions(+), 117 deletions(-)

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