mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: dri-devel@lists.freedesktop.org
Cc: dh.herrmann@gmail.com, linux-kernel@vger.kernel.org,
	"Noralf Trønnes" <noralf@tronnes.org>
Subject: [PATCH v3 3/3] drm: simpledrm: honour remove_conflicting_framebuffers()
Date: Sun, 14 Aug 2016 18:52:06 +0200	[thread overview]
Message-ID: <1471193526-22844-4-git-send-email-noralf@tronnes.org> (raw)
In-Reply-To: <1471193526-22844-1-git-send-email-noralf@tronnes.org>

There is currently no non-fbdev mechanism in place to kick out
simpledrm when the real hw-driver is probed. As a stop gap until
that is in place, honour remove_conflicting_framebuffers() and
delete the simple-framebuffer platform device when it's called.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---

Changes from version 2:
- Don't forget to free fb_info when kicked out.

 drivers/gpu/drm/simpledrm/Kconfig           |  5 +++
 drivers/gpu/drm/simpledrm/Makefile          |  2 +-
 drivers/gpu/drm/simpledrm/simpledrm.h       | 11 +++++-
 drivers/gpu/drm/simpledrm/simpledrm_drv.c   |  3 ++
 drivers/gpu/drm/simpledrm/simpledrm_fbdev.c | 55 +++++++++++++++++++++++++++--
 5 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/simpledrm/Kconfig b/drivers/gpu/drm/simpledrm/Kconfig
index 9454536..6205b17 100644
--- a/drivers/gpu/drm/simpledrm/Kconfig
+++ b/drivers/gpu/drm/simpledrm/Kconfig
@@ -16,6 +16,11 @@ config DRM_SIMPLEDRM
 	  If fbdev support is enabled, this driver will also provide an fbdev
 	  compatibility layer.

+	  WARNING
+	  fbdev must be enabled for simpledrm to disable itself when a real
+	  hw-driver is probed. It relies on remove_conflicting_framebuffers()
+	  to be called by the hw-driver.
+
 	  If unsure, say Y.

 	  To compile this driver as a module, choose M here: the
diff --git a/drivers/gpu/drm/simpledrm/Makefile b/drivers/gpu/drm/simpledrm/Makefile
index 7087245..4b4bcdd 100644
--- a/drivers/gpu/drm/simpledrm/Makefile
+++ b/drivers/gpu/drm/simpledrm/Makefile
@@ -1,5 +1,5 @@
 simpledrm-y :=	simpledrm_drv.o simpledrm_kms.o simpledrm_gem.o \
 		simpledrm_damage.o
-simpledrm-$(CONFIG_DRM_FBDEV_EMULATION) += simpledrm_fbdev.o
+simpledrm-$(CONFIG_FB) += simpledrm_fbdev.o

 obj-$(CONFIG_DRM_SIMPLEDRM) := simpledrm.o
diff --git a/drivers/gpu/drm/simpledrm/simpledrm.h b/drivers/gpu/drm/simpledrm/simpledrm.h
index f01b75d..7bc1292 100644
--- a/drivers/gpu/drm/simpledrm/simpledrm.h
+++ b/drivers/gpu/drm/simpledrm/simpledrm.h
@@ -88,13 +88,15 @@ struct sdrm_framebuffer {

 #define to_sdrm_fb(x) container_of(x, struct sdrm_framebuffer, base)

-#ifdef CONFIG_DRM_FBDEV_EMULATION
+#ifdef CONFIG_FB

 void sdrm_fbdev_init(struct sdrm_device *sdrm);
 void sdrm_fbdev_cleanup(struct sdrm_device *sdrm);
 void sdrm_fbdev_display_pipe_update(struct sdrm_device *sdrm,
 				    struct drm_framebuffer *fb);
 void sdrm_fbdev_restore_mode(struct sdrm_device *sdrm);
+void sdrm_fbdev_kickout_init(void);
+void sdrm_fbdev_kickout_exit(void);

 #else

@@ -115,6 +117,13 @@ static inline void sdrm_fbdev_restore_mode(struct sdrm_device *sdrm)
 {
 }

+static inline void sdrm_fbdev_kickout_init(void)
+{
+}
+
+static inline void sdrm_fbdev_kickout_exit(void)
+{
+}
 #endif

 #endif /* SDRM_DRV_H */
diff --git a/drivers/gpu/drm/simpledrm/simpledrm_drv.c b/drivers/gpu/drm/simpledrm/simpledrm_drv.c
index a4e6566..26956c3 100644
--- a/drivers/gpu/drm/simpledrm/simpledrm_drv.c
+++ b/drivers/gpu/drm/simpledrm/simpledrm_drv.c
@@ -527,12 +527,15 @@ static int __init sdrm_init(void)
 		}
 	}

+	sdrm_fbdev_kickout_init();
+
 	return 0;
 }
 module_init(sdrm_init);

 static void __exit sdrm_exit(void)
 {
+	sdrm_fbdev_kickout_exit();
 	platform_driver_unregister(&sdrm_simplefb_driver);
 }
 module_exit(sdrm_exit);
diff --git a/drivers/gpu/drm/simpledrm/simpledrm_fbdev.c b/drivers/gpu/drm/simpledrm/simpledrm_fbdev.c
index 4038dd9..daf5943 100644
--- a/drivers/gpu/drm/simpledrm/simpledrm_fbdev.c
+++ b/drivers/gpu/drm/simpledrm/simpledrm_fbdev.c
@@ -28,6 +28,16 @@ static inline struct sdrm_fbdev *to_sdrm_fbdev(struct drm_fb_helper *helper)
 	return container_of(helper, struct sdrm_fbdev, fb_helper);
 }

+/*
+ * Releasing has to be done outside the notifier callchain when we're
+ * kicked out, since do_unregister_framebuffer() calls put_fb_info()
+ * after the notifier has run.
+ */
+static void sdrm_fbdev_fb_destroy(struct fb_info *info)
+{
+	drm_fb_helper_release_fbi(info->par);
+}
+
 static struct fb_ops sdrm_fbdev_ops = {
 	.owner		= THIS_MODULE,
 	.fb_fillrect	= drm_fb_helper_cfb_fillrect,
@@ -36,6 +46,7 @@ static struct fb_ops sdrm_fbdev_ops = {
 	.fb_check_var	= drm_fb_helper_check_var,
 	.fb_set_par	= drm_fb_helper_set_par,
 	.fb_setcmap	= drm_fb_helper_setcmap,
+	.fb_destroy	= sdrm_fbdev_fb_destroy,
 };

 static struct drm_framebuffer_funcs sdrm_fb_funcs = {
@@ -85,6 +96,9 @@ static int sdrm_fbdev_create(struct drm_fb_helper *helper,
 	fbi->fix.smem_len = sdrm->fb_size;
 	fbi->screen_base = sdrm->fb_map;

+	fbi->apertures->ranges[0].base = sdrm->fb_base;
+	fbi->apertures->ranges[0].size = sdrm->fb_size;
+
 	return 0;

 err_fb_info_destroy:
@@ -154,8 +168,11 @@ void sdrm_fbdev_cleanup(struct sdrm_device *sdrm)
 	sdrm->fbdev = NULL;
 	fb_helper = &fbdev->fb_helper;

-	drm_fb_helper_unregister_fbi(fb_helper);
-	drm_fb_helper_release_fbi(fb_helper);
+	/* it might have been kicked out */
+	if (registered_fb[fbdev->fb_helper.fbdev->node])
+		drm_fb_helper_unregister_fbi(fb_helper);
+
+	/* freeing fb_info is done in fb_ops.fb_destroy() */

 	drm_framebuffer_unregister_private(&fbdev->fb);
 	drm_framebuffer_cleanup(&fbdev->fb);
@@ -199,3 +216,37 @@ void sdrm_fbdev_restore_mode(struct sdrm_device *sdrm)
 	if (fbdev->fb_helper.fbdev->state != FBINFO_STATE_RUNNING)
 		sdrm_fbdev_set_suspend(fbdev->fb_helper.fbdev, 0);
 }
+
+static int sdrm_fbdev_event_notify(struct notifier_block *self,
+				   unsigned long action, void *data)
+{
+	struct sdrm_device *sdrm;
+	struct fb_event *event = data;
+	struct fb_info *info = event->info;
+	struct drm_fb_helper *fb_helper = info->par;
+
+	if (action != FB_EVENT_FB_UNREGISTERED || !fb_helper ||
+	    !fb_helper->dev || fb_helper->fbdev != info)
+		return NOTIFY_DONE;
+
+	sdrm = fb_helper->dev->dev_private;
+
+	if (sdrm && sdrm->fbdev)
+		platform_device_del(sdrm->ddev->platformdev);
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block sdrm_fbdev_event_notifier = {
+	.notifier_call  = sdrm_fbdev_event_notify,
+};
+
+void sdrm_fbdev_kickout_init(void)
+{
+	fb_register_client(&sdrm_fbdev_event_notifier);
+}
+
+void sdrm_fbdev_kickout_exit(void)
+{
+	fb_unregister_client(&sdrm_fbdev_event_notifier);
+}
--
2.8.2

  parent reply	other threads:[~2016-08-14 16:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-14 16:52 [PATCH v3 0/3] drm: add SimpleDRM driver Noralf Trønnes
2016-08-14 16:52 ` [PATCH v3 1/3] " Noralf Trønnes
2016-08-15  6:59   ` Daniel Vetter
2016-08-16 12:58     ` Noralf Trønnes
2016-08-16 15:25       ` Daniel Vetter
2016-08-16 19:38         ` Noralf Trønnes
2016-08-17  9:30           ` Daniel Vetter
2016-08-17 10:19             ` Noralf Trønnes
2016-08-17 10:58               ` Daniel Vetter
2016-08-14 16:52 ` [PATCH v3 2/3] drm: simpledrm: add fbdev fallback support Noralf Trønnes
2016-08-15  6:48   ` Daniel Vetter
2016-08-16 13:10     ` Noralf Trønnes
2016-08-16 15:31       ` Daniel Vetter
2016-08-14 16:52 ` Noralf Trønnes [this message]
2016-08-15  7:12   ` [PATCH v3 3/3] drm: simpledrm: honour remove_conflicting_framebuffers() Daniel Vetter
2016-08-15  7:14 ` [PATCH v3 0/3] drm: add SimpleDRM driver Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471193526-22844-4-git-send-email-noralf@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=dh.herrmann@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®