Skip to contentSkip to conversation

drm/fb-helper: Fix hpd vs. initial config races

PATCH In review Daniel Vetter 3 participants 6 messages Apr 16, 2014 – Apr 22, 2014

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

PATCH 1/1 drm/fb-helper: Fix hpd vs. initial config races

Some drivers need to be able to have a perfect race-free fbcon setup. Current drivers only enable hotplug processing after the call to drm_fb_helper_initial_config which leaves a tiny but important race.

This race is especially noticable on embedded platforms where the driver itself enables the voltage for the hdmi output, since only then will monitors (after a bit of delay, as usual) respond by asserting the hpd pin.

Most of the infrastructure is already there with the split-out drm_fb_helper_init. And drm_fb_helper_initial_config already has all the required locking to handle concurrent hpd events since

commit 53f1904bced78d7c00f5d874c662ec3ac85d0f9f

Author: Daniel Vetter <[email protected]>
Date:   Thu Mar 20 14:26:35 2014 +0100

drm/fb-helper: improve drm_fb_helper_initial_config locking

The only missing bit is making drm_fb_helper_hotplug_event save against concurrent calls of drm_fb_helper_initial_config. The only unprotected bit is the check for fb_helper->fb.

With that drivers can first initialize the fb helper, then enabel hotplug processing and then set up the initial config all in a completely race-free manner. Update kerneldoc and convert i915 as a proof of concept.

Feature requested by Thierry since his tegra driver atm reliably boots slowly enough to misses the hotplug event for an external hdmi screen, but also reliably boots to quickly for the hpd pin to be asserted when the fb helper calls into the hdmi ->detect function.

---
 drivers/gpu/drm/drm_fb_helper.c | 11 +++++------
 drivers/gpu/drm/i915/i915_dma.c |  3 ---
 drivers/gpu/drm/i915/i915_drv.c |  2 --
 drivers/gpu/drm/i915/i915_drv.h |  1 -
 drivers/gpu/drm/i915/i915_irq.c |  4 ----
 5 files changed, 5 insertions(+), 16 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +5 -6
index 04d3fd3658f3..9b775ddb8697 100644
@@ -1578,8 +1578,10 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
  * either the output polling work or a work item launched from the driver's
  * hotplug interrupt).
  *
- * Note that the driver must ensure that this is only called _after_ the fb has
- * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
+ * Note that drivers may call this even before calling
+ * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows
+ * for a race-free fbcon setup and will make sure that the fbdev emulation will
+ * not miss any hotplug events.
  *
  * RETURNS:
  * 0 on success and a non-zero error code otherwise.
@@ -1589,11 +1591,8 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
 	struct drm_device *dev = fb_helper->dev;
 	u32 max_width, max_height;
 
-	if (!fb_helper->fb)
-		return 0;
-
 	mutex_lock(&fb_helper->dev->mode_config.mutex);
-	if (!drm_fb_helper_is_bound(fb_helper)) {
+	if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) {
 		fb_helper->delayed_hotplug = true;
 		mutex_unlock(&fb_helper->dev->mode_config.mutex);
 		return 0;
drivers/gpu/drm/i915/i915_dma.c +0 -3
index 96177eec0a0e..8254056f22d8 100644
@@ -1369,9 +1369,6 @@ static int i915_load_modeset_init(struct drm_device *dev)
 	 */
 	intel_fbdev_initial_config(dev);
 
-	/* Only enable hotplug handling once the fbdev is fully set up. */
-	dev_priv->enable_hotplug_processing = true;
-
 	drm_kms_helper_poll_init(dev);
 
 	return 0;
drivers/gpu/drm/i915/i915_drv.c +0 -2
index 82f4d1f47d3b..aba9552e95e2 100644
@@ -448,7 +448,6 @@ static int i915_drm_freeze(struct drm_device *dev)
 		cancel_delayed_work_sync(&dev_priv->rps.delayed_resume_work);
 
 		drm_irq_uninstall(dev);
-		dev_priv->enable_hotplug_processing = false;
 		/*
 		 * Disable CRTCs directly since we want to preserve sw state
 		 * for _thaw.
@@ -589,7 +588,6 @@ static int __i915_drm_thaw(struct drm_device *dev, bool restore_gtt_mappings)
 		 * notifications.
 		 * */
 		intel_hpd_init(dev);
-		dev_priv->enable_hotplug_processing = true;
 		/* Config may have changed between suspend and resume */
 		intel_resume_hotplug(dev);
 	}
drivers/gpu/drm/i915/i915_drv.h +0 -1
index 0905cd915589..646a1f9a0db9 100644
@@ -1469,7 +1469,6 @@ typedef struct drm_i915_private {
 	u32 pipestat_irq_mask[I915_MAX_PIPES];
 
 	struct work_struct hotplug_work;
-	bool enable_hotplug_processing;
 	struct {
 		unsigned long hpd_last_jiffies;
 		int hpd_cnt;
drivers/gpu/drm/i915/i915_irq.c +0 -4
index 7753249b3a95..9e7c35a33c83 100644
@@ -971,10 +971,6 @@ static void i915_hotplug_work_func(struct work_struct *work)
 	bool changed = false;
 	u32 hpd_event_bits;
 
-	/* HPD irq before everything is fully set up. */
-	if (!dev_priv->enable_hotplug_processing)
-		return;
-
 	mutex_lock(&mode_config->mutex);
 	DRM_DEBUG_KMS("running encoder hotplug functions\n");
 
Signature · 1 line
1.9.2
Tested-by on v1 1/1
#1 lore raw
Quoted 35 lines · Daniel Vetter

Some drivers need to be able to have a perfect race-free fbcon setup. Current drivers only enable hotplug processing after the call to drm_fb_helper_initial_config which leaves a tiny but important race.

This race is especially noticable on embedded platforms where the driver itself enables the voltage for the hdmi output, since only then will monitors (after a bit of delay, as usual) respond by asserting the hpd pin.

Most of the infrastructure is already there with the split-out drm_fb_helper_init. And drm_fb_helper_initial_config already has all the required locking to handle concurrent hpd events since

commit 53f1904bced78d7c00f5d874c662ec3ac85d0f9f

Author: Daniel Vetter <[email protected]>
Date:   Thu Mar 20 14:26:35 2014 +0100

drm/fb-helper: improve drm_fb_helper_initial_config locking

The only missing bit is making drm_fb_helper_hotplug_event save against concurrent calls of drm_fb_helper_initial_config. The only unprotected bit is the check for fb_helper->fb.

With that drivers can first initialize the fb helper, then enabel hotplug processing and then set up the initial config all in a completely race-free manner. Update kerneldoc and convert i915 as a proof of concept.

Feature requested by Thierry since his tegra driver atm reliably boots slowly enough to misses the hotplug event for an external hdmi screen, but also reliably boots to quickly for the hpd pin to be asserted when the fb helper calls into the hdmi ->detect function.

Quoted 7 lines
---
 drivers/gpu/drm/drm_fb_helper.c | 11 +++++------
 drivers/gpu/drm/i915/i915_dma.c |  3 ---
 drivers/gpu/drm/i915/i915_drv.c |  2 --
 drivers/gpu/drm/i915/i915_drv.h |  1 -
 drivers/gpu/drm/i915/i915_irq.c |  4 ----
 5 files changed, 5 insertions(+), 16 deletions(-)

The FB helper parts:

But I have one comment below...

Quoted 1 line
drivers/gpu/drm/drm_fb_helper.c +0 -0

[...]

Quoted 4 lines

- * Note that the driver must ensure that this is only called _after_ the fb has
- * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
+ * Note that drivers may call this even before calling
+ * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows

I don't think the requirement is that strict. To elaborate: on Tegra we cannot call drm_fb_helper_init() because the number of CRTCs and connectors isn't known this early. We determine that dynamically after all sub-devices have been initialized. So instead of calling drm_fb_helper_init() before drm_kms_helper_poll_init(), I did something more minimal (see attached patch). It's kind of difficult to tell because of the context, but tegra_drm_fb_prepare() sets up the mode config and functions and allocate memory for the FB helper and sets the FB helper functions.

This may not be enough for all drivers, but on Tegra the implementation of .output_poll_changed() simply calls drm_fb_helper_hotplug_event(), which will work fine with just that rudimentary initialization.

Thierry

From ea394150524c8b54ee4131ad830bf5beb6b1056e Mon Sep 17 00:00:00 2001
From: Thierry Reding <[email protected]>
Date: Thu, 17 Apr 2014 10:02:17 +0200
Subject: [PATCH] drm/tegra: Implement race-free hotplug detection

A race condition currently exists on Tegra, where it can happen that a monitor attached via HDMI isn't detected during the initial FB helper setup, but the hotplug event happens too early to be processed by the poll helpers because they haven't been initialized yet. This happens because on some boards the HDMI driver can control the regulator that supplies the +5V pin on the HDMI connector. Therefore depending on the timing between the initialization of the HDMI driver and the rest of DRM, it's possible that the monitor returns the hotplug signal right within the window where we would miss it.

Unfortunately, drm_kms_helper_poll_init() will wreak havoc when called before at least some parts of the FB helpers have been set up.

This commit fixes this by splitting out the minimum of initialization required to make drm_kms_helper_poll_init() work into a separate function that can be called early. It is then safe to move all of the poll helper initialization to an earlier point in time (before the HDMI output driver has a chance to enable the +5V supply). That way if the hotplug signal is returned before the initial FB helper setup, the monitor will be forcefully detected at that point, and if the hotplug signal is returned after that it will be properly handled by the poll helpers.

---
 drivers/gpu/drm/tegra/drm.c |  8 ++++++--
 drivers/gpu/drm/tegra/drm.h |  1 +
 drivers/gpu/drm/tegra/fb.c  | 50 ++++++++++++++++++++++++++++++---------------
 3 files changed, 40 insertions(+), 19 deletions(-)
drivers/gpu/drm/tegra/drm.c +6 -2
index 09ee77923d67..d492c2f12ca8 100644
@@ -41,6 +41,12 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 
 	drm_mode_config_init(drm);
 
+	err = tegra_drm_fb_prepare(drm);
+	if (err < 0)
+		return err;
+
+	drm_kms_helper_poll_init(drm);
+
 	err = host1x_device_init(device);
 	if (err < 0)
 		return err;
@@ -60,8 +66,6 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 	if (err < 0)
 		return err;
 
-	drm_kms_helper_poll_init(drm);
-
 	return 0;
 }
 
drivers/gpu/drm/tegra/drm.h +1 -0
index 784fd5c77441..d100f706d818 100644
@@ -284,6 +284,7 @@ struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
 				    unsigned int index);
 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
 bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
+int tegra_drm_fb_prepare(struct drm_device *drm);
 int tegra_drm_fb_init(struct drm_device *drm);
 void tegra_drm_fb_exit(struct drm_device *drm);
 #ifdef CONFIG_DRM_TEGRA_FBDEV
drivers/gpu/drm/tegra/fb.c +33 -17

101 lines not on this page · raw message

Signature · 1 line
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw
Quoted 67 lines · Thierry Reding
Quoted 35 lines · Daniel Vetter

Some drivers need to be able to have a perfect race-free fbcon setup. Current drivers only enable hotplug processing after the call to drm_fb_helper_initial_config which leaves a tiny but important race.

This race is especially noticable on embedded platforms where the driver itself enables the voltage for the hdmi output, since only then will monitors (after a bit of delay, as usual) respond by asserting the hpd pin.

Most of the infrastructure is already there with the split-out drm_fb_helper_init. And drm_fb_helper_initial_config already has all the required locking to handle concurrent hpd events since

commit 53f1904bced78d7c00f5d874c662ec3ac85d0f9f

Author: Daniel Vetter <[email protected]>
Date:   Thu Mar 20 14:26:35 2014 +0100

drm/fb-helper: improve drm_fb_helper_initial_config locking

The only missing bit is making drm_fb_helper_hotplug_event save against concurrent calls of drm_fb_helper_initial_config. The only unprotected bit is the check for fb_helper->fb.

With that drivers can first initialize the fb helper, then enabel hotplug processing and then set up the initial config all in a completely race-free manner. Update kerneldoc and convert i915 as a proof of concept.

Feature requested by Thierry since his tegra driver atm reliably boots slowly enough to misses the hotplug event for an external hdmi screen, but also reliably boots to quickly for the hpd pin to be asserted when the fb helper calls into the hdmi ->detect function.

Quoted 7 lines
---
 drivers/gpu/drm/drm_fb_helper.c | 11 +++++------
 drivers/gpu/drm/i915/i915_dma.c |  3 ---
 drivers/gpu/drm/i915/i915_drv.c |  2 --
 drivers/gpu/drm/i915/i915_drv.h |  1 -
 drivers/gpu/drm/i915/i915_irq.c |  4 ----
 5 files changed, 5 insertions(+), 16 deletions(-)

The FB helper parts:

But I have one comment below...

Quoted 1 line
drivers/gpu/drm/drm_fb_helper.c +0 -0

[...]

Quoted 4 lines

- * Note that the driver must ensure that this is only called _after_ the fb has
- * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
+ * Note that drivers may call this even before calling
+ * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows

I don't think the requirement is that strict. To elaborate: on Tegra we cannot call drm_fb_helper_init() because the number of CRTCs and connectors isn't known this early. We determine that dynamically after all sub-devices have been initialized. So instead of calling drm_fb_helper_init() before drm_kms_helper_poll_init(), I did something more minimal (see attached patch). It's kind of difficult to tell because of the context, but tegra_drm_fb_prepare() sets up the mode config and functions and allocate memory for the FB helper and sets the FB helper functions.

Quoted 3 lines

This may not be enough for all drivers, but on Tegra the implementation of .output_poll_changed() simply calls drm_fb_helper_hotplug_event(), which will work fine with just that rudimentary initialization.

Hm yeah I think this should be sufficient, too. It would be good to extract this minimal initialization into a new drm_fb_helper_prepare function and update the kerneldoc a bit more. Maybe as a patch on top of mine?

Then we could merge this all as an early tegra-next pull to Dave. -Daniel

Quoted 190 lines

Thierry

From ea394150524c8b54ee4131ad830bf5beb6b1056e Mon Sep 17 00:00:00 2001
From: Thierry Reding <[email protected]>
Date: Thu, 17 Apr 2014 10:02:17 +0200
Subject: [PATCH] drm/tegra: Implement race-free hotplug detection

A race condition currently exists on Tegra, where it can happen that a monitor attached via HDMI isn't detected during the initial FB helper setup, but the hotplug event happens too early to be processed by the poll helpers because they haven't been initialized yet. This happens because on some boards the HDMI driver can control the regulator that supplies the +5V pin on the HDMI connector. Therefore depending on the timing between the initialization of the HDMI driver and the rest of DRM, it's possible that the monitor returns the hotplug signal right within the window where we would miss it.

Unfortunately, drm_kms_helper_poll_init() will wreak havoc when called before at least some parts of the FB helpers have been set up.

This commit fixes this by splitting out the minimum of initialization required to make drm_kms_helper_poll_init() work into a separate function that can be called early. It is then safe to move all of the poll helper initialization to an earlier point in time (before the HDMI output driver has a chance to enable the +5V supply). That way if the hotplug signal is returned before the initial FB helper setup, the monitor will be forcefully detected at that point, and if the hotplug signal is returned after that it will be properly handled by the poll helpers.

---
 drivers/gpu/drm/tegra/drm.c |  8 ++++++--
 drivers/gpu/drm/tegra/drm.h |  1 +
 drivers/gpu/drm/tegra/fb.c  | 50 ++++++++++++++++++++++++++++++---------------
 3 files changed, 40 insertions(+), 19 deletions(-)
drivers/gpu/drm/tegra/drm.c +6 -2
index 09ee77923d67..d492c2f12ca8 100644
@@ -41,6 +41,12 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 
 	drm_mode_config_init(drm);
 
+	err = tegra_drm_fb_prepare(drm);
+	if (err < 0)
+		return err;
+
+	drm_kms_helper_poll_init(drm);
+
 	err = host1x_device_init(device);
 	if (err < 0)
 		return err;
@@ -60,8 +66,6 @@ static int tegra_drm_load(struct drm_device *drm, unsigned long flags)
 	if (err < 0)
 		return err;
 
-	drm_kms_helper_poll_init(drm);
-
 	return 0;
 }
 
drivers/gpu/drm/tegra/drm.h +1 -0
index 784fd5c77441..d100f706d818 100644
@@ -284,6 +284,7 @@ struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
 				    unsigned int index);
 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
 bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
+int tegra_drm_fb_prepare(struct drm_device *drm);
 int tegra_drm_fb_init(struct drm_device *drm);
 void tegra_drm_fb_exit(struct drm_device *drm);
 #ifdef CONFIG_DRM_TEGRA_FBDEV
drivers/gpu/drm/tegra/fb.c +33 -17
index f7fca09d4921..2d7c589b550a 100644
@@ -271,14 +271,9 @@ static struct drm_fb_helper_funcs tegra_fb_helper_funcs = {
 	.fb_probe = tegra_fbdev_probe,
 };
 
-static struct tegra_fbdev *tegra_fbdev_create(struct drm_device *drm,
-					      unsigned int preferred_bpp,
-					      unsigned int num_crtc,
-					      unsigned int max_connectors)
+static struct tegra_fbdev *tegra_fbdev_create(struct drm_device *drm)
 {
-	struct drm_fb_helper *helper;
 	struct tegra_fbdev *fbdev;
-	int err;
 
 	fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
 	if (!fbdev) {
@@ -287,12 +282,23 @@ static struct tegra_fbdev *tegra_fbdev_create(struct drm_device *drm,
 	}
 
 	fbdev->base.funcs = &tegra_fb_helper_funcs;
-	helper = &fbdev->base;
+	fbdev->base.dev = drm;
+
+	return fbdev;
+}
+
+static int tegra_fbdev_init(struct tegra_fbdev *fbdev,
+			    unsigned int preferred_bpp,
+			    unsigned int num_crtc,
+			    unsigned int max_connectors)
+{
+	struct drm_device *drm = fbdev->base.dev;
+	int err;
 
 	err = drm_fb_helper_init(drm, &fbdev->base, num_crtc, max_connectors);
 	if (err < 0) {
 		dev_err(drm->dev, "failed to initialize DRM FB helper\n");
-		goto free;
+		return err;
 	}
 
 	err = drm_fb_helper_single_add_all_connectors(&fbdev->base);
@@ -301,21 +307,17 @@ static struct tegra_fbdev *tegra_fbdev_create(struct drm_device *drm,
 		goto fini;
 	}
 
-	drm_helper_disable_unused_functions(drm);
-
 	err = drm_fb_helper_initial_config(&fbdev->base, preferred_bpp);
 	if (err < 0) {
 		dev_err(drm->dev, "failed to set initial configuration\n");
 		goto fini;
 	}
 
-	return fbdev;
+	return 0;
 
 fini:
 	drm_fb_helper_fini(&fbdev->base);
-free:
-	kfree(fbdev);
-	return ERR_PTR(err);
+	return err;
 }
 
 static void tegra_fbdev_free(struct tegra_fbdev *fbdev)
@@ -369,7 +371,7 @@ static const struct drm_mode_config_funcs tegra_drm_mode_funcs = {
 #endif
 };
 
-int tegra_drm_fb_init(struct drm_device *drm)
+int tegra_drm_fb_prepare(struct drm_device *drm)
 {
 #ifdef CONFIG_DRM_TEGRA_FBDEV
 	struct tegra_drm *tegra = drm->dev_private;
@@ -384,8 +386,7 @@ int tegra_drm_fb_init(struct drm_device *drm)
 	drm->mode_config.funcs = &tegra_drm_mode_funcs;
 
 #ifdef CONFIG_DRM_TEGRA_FBDEV
-	tegra->fbdev = tegra_fbdev_create(drm, 32, drm->mode_config.num_crtc,
-					  drm->mode_config.num_connector);
+	tegra->fbdev = tegra_fbdev_create(drm);
 	if (IS_ERR(tegra->fbdev))
 		return PTR_ERR(tegra->fbdev);
 #endif
@@ -393,6 +394,21 @@ int tegra_drm_fb_init(struct drm_device *drm)
 	return 0;
 }
 
+int tegra_drm_fb_init(struct drm_device *drm)
+{
+#ifdef CONFIG_DRM_TEGRA_FBDEV
+	struct tegra_drm *tegra = drm->dev_private;
+	int err;
+
+	err = tegra_fbdev_init(tegra->fbdev, 32, drm->mode_config.num_crtc,
+			       drm->mode_config.num_connector);
+	if (err < 0)
+		return err;
+#endif
+
+	return 0;
+}
+
 void tegra_drm_fb_exit(struct drm_device *drm)
 {
 #ifdef CONFIG_DRM_TEGRA_FBDEV
Signature · 1 line
1.9.2
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw
Quoted 72 lines · Daniel Vetter
Quoted 67 lines · Thierry Reding
Quoted 35 lines · Daniel Vetter

Some drivers need to be able to have a perfect race-free fbcon setup. Current drivers only enable hotplug processing after the call to drm_fb_helper_initial_config which leaves a tiny but important race.

This race is especially noticable on embedded platforms where the driver itself enables the voltage for the hdmi output, since only then will monitors (after a bit of delay, as usual) respond by asserting the hpd pin.

Most of the infrastructure is already there with the split-out drm_fb_helper_init. And drm_fb_helper_initial_config already has all the required locking to handle concurrent hpd events since

commit 53f1904bced78d7c00f5d874c662ec3ac85d0f9f

Author: Daniel Vetter <[email protected]>
Date:   Thu Mar 20 14:26:35 2014 +0100

drm/fb-helper: improve drm_fb_helper_initial_config locking

The only missing bit is making drm_fb_helper_hotplug_event save against concurrent calls of drm_fb_helper_initial_config. The only unprotected bit is the check for fb_helper->fb.

With that drivers can first initialize the fb helper, then enabel hotplug processing and then set up the initial config all in a completely race-free manner. Update kerneldoc and convert i915 as a proof of concept.

Feature requested by Thierry since his tegra driver atm reliably boots slowly enough to misses the hotplug event for an external hdmi screen, but also reliably boots to quickly for the hpd pin to be asserted when the fb helper calls into the hdmi ->detect function.

Quoted 7 lines
---
 drivers/gpu/drm/drm_fb_helper.c | 11 +++++------
 drivers/gpu/drm/i915/i915_dma.c |  3 ---
 drivers/gpu/drm/i915/i915_drv.c |  2 --
 drivers/gpu/drm/i915/i915_drv.h |  1 -
 drivers/gpu/drm/i915/i915_irq.c |  4 ----
 5 files changed, 5 insertions(+), 16 deletions(-)

The FB helper parts:

But I have one comment below...

Quoted 1 line
drivers/gpu/drm/drm_fb_helper.c +0 -0

[...]

Quoted 4 lines

- * Note that the driver must ensure that this is only called _after_ the fb has
- * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
+ * Note that drivers may call this even before calling
+ * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows

I don't think the requirement is that strict. To elaborate: on Tegra we cannot call drm_fb_helper_init() because the number of CRTCs and connectors isn't known this early. We determine that dynamically after all sub-devices have been initialized. So instead of calling drm_fb_helper_init() before drm_kms_helper_poll_init(), I did something more minimal (see attached patch). It's kind of difficult to tell because of the context, but tegra_drm_fb_prepare() sets up the mode config and functions and allocate memory for the FB helper and sets the FB helper functions.

Quoted 3 lines

This may not be enough for all drivers, but on Tegra the implementation of .output_poll_changed() simply calls drm_fb_helper_hotplug_event(), which will work fine with just that rudimentary initialization.

Quoted 6 lines

Hm yeah I think this should be sufficient, too. It would be good to extract this minimal initialization into a new drm_fb_helper_prepare function and update the kerneldoc a bit more. Maybe as a patch on top of mine?

Then we could merge this all as an early tegra-next pull to Dave.

Sounds like a good idea. I'll go prepare a patch.

Thierry

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
In reply to Daniel Vetter
Quoted 68 lines · Daniel Vetter
Quoted 67 lines · Thierry Reding
Quoted 35 lines · Daniel Vetter

Some drivers need to be able to have a perfect race-free fbcon setup. Current drivers only enable hotplug processing after the call to drm_fb_helper_initial_config which leaves a tiny but important race.

This race is especially noticable on embedded platforms where the driver itself enables the voltage for the hdmi output, since only then will monitors (after a bit of delay, as usual) respond by asserting the hpd pin.

Most of the infrastructure is already there with the split-out drm_fb_helper_init. And drm_fb_helper_initial_config already has all the required locking to handle concurrent hpd events since

commit 53f1904bced78d7c00f5d874c662ec3ac85d0f9f

Author: Daniel Vetter <[email protected]>
Date:   Thu Mar 20 14:26:35 2014 +0100

drm/fb-helper: improve drm_fb_helper_initial_config locking

The only missing bit is making drm_fb_helper_hotplug_event save against concurrent calls of drm_fb_helper_initial_config. The only unprotected bit is the check for fb_helper->fb.

With that drivers can first initialize the fb helper, then enabel hotplug processing and then set up the initial config all in a completely race-free manner. Update kerneldoc and convert i915 as a proof of concept.

Feature requested by Thierry since his tegra driver atm reliably boots slowly enough to misses the hotplug event for an external hdmi screen, but also reliably boots to quickly for the hpd pin to be asserted when the fb helper calls into the hdmi ->detect function.

Quoted 7 lines
---
 drivers/gpu/drm/drm_fb_helper.c | 11 +++++------
 drivers/gpu/drm/i915/i915_dma.c |  3 ---
 drivers/gpu/drm/i915/i915_drv.c |  2 --
 drivers/gpu/drm/i915/i915_drv.h |  1 -
 drivers/gpu/drm/i915/i915_irq.c |  4 ----
 5 files changed, 5 insertions(+), 16 deletions(-)

The FB helper parts:

But I have one comment below...

Quoted 1 line
drivers/gpu/drm/drm_fb_helper.c +0 -0

[...]

Quoted 4 lines

- * Note that the driver must ensure that this is only called _after_ the fb has
- * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
+ * Note that drivers may call this even before calling
+ * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows

I don't think the requirement is that strict. To elaborate: on Tegra we cannot call drm_fb_helper_init() because the number of CRTCs and connectors isn't known this early. We determine that dynamically after all sub-devices have been initialized. So instead of calling drm_fb_helper_init() before drm_kms_helper_poll_init(), I did something more minimal (see attached patch). It's kind of difficult to tell because of the context, but tegra_drm_fb_prepare() sets up the mode config and functions and allocate memory for the FB helper and sets the FB helper functions.

Quoted 8 lines
Quoted 3 lines

This may not be enough for all drivers, but on Tegra the implementation of .output_poll_changed() simply calls drm_fb_helper_hotplug_event(), which will work fine with just that rudimentary initialization.

Hm yeah I think this should be sufficient, too. It would be good to extract this minimal initialization into a new drm_fb_helper_prepare function and update the kerneldoc a bit more. Maybe as a patch on top of mine?

It would be essentially this:

void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
const struct drm_fb_helper_funcs *funcs)

{
	helper->funcs = funcs;
	helper->dev = dev;
}

So I wonder if that's still what we want or whether drivers should simply be doing that manually if they need to. Having a function for it gives us a place to document things, though, and perhaps at some point we'll have to extend this, so it may be a good idea after all, even if it's just the two lines currently.

Thierry

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw
Quoted 7 lines · Thierry Reding

void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
const struct drm_fb_helper_funcs *funcs)

{
        helper->funcs = funcs;
        helper->dev = dev;
}
Quoted 5 lines

So I wonder if that's still what we want or whether drivers should simply be doing that manually if they need to. Having a function for it gives us a place to document things, though, and perhaps at some point we'll have to extend this, so it may be a good idea after all, even if it's just the two lines currently.

Yeah the usefulness of this will be in the documentation that explains how to use it, not in the code sharing/extraction. For critical code we could just plunk it into a static inline, but since this is init code I wouldn't really care with that.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch