From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Subject: Re: [PATCH] drm/fb-helper: Fix hpd vs. initial config races Date: Thu, 17 Apr 2014 10:38:17 +0200 Message-ID: <20140417083814.GA23723@ulmo> References: <1397659521-32027-1-git-send-email-daniel.vetter@ffwll.ch> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0729530460==" Return-path: In-Reply-To: <1397659521-32027-1-git-send-email-daniel.vetter@ffwll.ch> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: Daniel Vetter Cc: Intel Graphics Development , Thierry Reding , DRI Development List-Id: intel-gfx@lists.freedesktop.org --===============0729530460== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="CblX+4bnyfN0pR09" Content-Disposition: inline --CblX+4bnyfN0pR09 Content-Type: multipart/mixed; boundary="K8nIJk4ghYZn606h" Content-Disposition: inline --K8nIJk4ghYZn606h Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 16, 2014 at 04:45:21PM +0200, Daniel Vetter wrote: > 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. >=20 > 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. >=20 > 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 >=20 > commit 53f1904bced78d7c00f5d874c662ec3ac85d0f9f > Author: Daniel Vetter > Date: Thu Mar 20 14:26:35 2014 +0100 >=20 > drm/fb-helper: improve drm_fb_helper_initial_config locking >=20 > 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. >=20 > 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. >=20 > 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. >=20 > Cc: Thierry Reding > Signed-off-by: Daniel Vetter > --- > 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: Tested-by: Thierry Reding But I have one comment below... > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_hel= per.c [...] > - * 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_confi= g. > + * 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 --K8nIJk4ghYZn606h Content-Type: text/x-diff; charset=us-ascii Content-Disposition: inline; filename="0001-drm-tegra-Implement-race-free-hotplug-detection.patch" Content-Transfer-Encoding: quoted-printable =46rom ea394150524c8b54ee4131ad830bf5beb6b1056e Mon Sep 17 00:00:00 2001 =46rom: Thierry Reding 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. Signed-off-by: Thierry Reding --- 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(-) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index 09ee77923d67..d492c2f12ca8 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -41,6 +41,12 @@ static int tegra_drm_load(struct drm_device *drm, unsign= ed long flags) =20 drm_mode_config_init(drm); =20 + err =3D tegra_drm_fb_prepare(drm); + if (err < 0) + return err; + + drm_kms_helper_poll_init(drm); + err =3D host1x_device_init(device); if (err < 0) return err; @@ -60,8 +66,6 @@ static int tegra_drm_load(struct drm_device *drm, unsigne= d long flags) if (err < 0) return err; =20 - drm_kms_helper_poll_init(drm); - return 0; } =20 diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h index 784fd5c77441..d100f706d818 100644 --- a/drivers/gpu/drm/tegra/drm.h +++ b/drivers/gpu/drm/tegra/drm.h @@ -284,6 +284,7 @@ struct tegra_bo *tegra_fb_get_plane(struct drm_framebuf= fer *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 diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c index f7fca09d4921..2d7c589b550a 100644 --- a/drivers/gpu/drm/tegra/fb.c +++ b/drivers/gpu/drm/tegra/fb.c @@ -271,14 +271,9 @@ static struct drm_fb_helper_funcs tegra_fb_helper_func= s =3D { .fb_probe =3D tegra_fbdev_probe, }; =20 -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; =20 fbdev =3D kzalloc(sizeof(*fbdev), GFP_KERNEL); if (!fbdev) { @@ -287,12 +282,23 @@ static struct tegra_fbdev *tegra_fbdev_create(struct = drm_device *drm, } =20 fbdev->base.funcs =3D &tegra_fb_helper_funcs; - helper =3D &fbdev->base; + fbdev->base.dev =3D 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 =3D fbdev->base.dev; + int err; =20 err =3D 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; } =20 err =3D 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; } =20 - drm_helper_disable_unused_functions(drm); - err =3D drm_fb_helper_initial_config(&fbdev->base, preferred_bpp); if (err < 0) { dev_err(drm->dev, "failed to set initial configuration\n"); goto fini; } =20 - return fbdev; + return 0; =20 fini: drm_fb_helper_fini(&fbdev->base); -free: - kfree(fbdev); - return ERR_PTR(err); + return err; } =20 static void tegra_fbdev_free(struct tegra_fbdev *fbdev) @@ -369,7 +371,7 @@ static const struct drm_mode_config_funcs tegra_drm_mod= e_funcs =3D { #endif }; =20 -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 =3D drm->dev_private; @@ -384,8 +386,7 @@ int tegra_drm_fb_init(struct drm_device *drm) drm->mode_config.funcs =3D &tegra_drm_mode_funcs; =20 #ifdef CONFIG_DRM_TEGRA_FBDEV - tegra->fbdev =3D tegra_fbdev_create(drm, 32, drm->mode_config.num_crtc, - drm->mode_config.num_connector); + tegra->fbdev =3D 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; } =20 +int tegra_drm_fb_init(struct drm_device *drm) +{ +#ifdef CONFIG_DRM_TEGRA_FBDEV + struct tegra_drm *tegra =3D drm->dev_private; + int err; + + err =3D 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 --=20 1.9.2 --K8nIJk4ghYZn606h-- --CblX+4bnyfN0pR09 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJTT5L2AAoJEN0jrNd/PrOhK3gQAKJtOH6OHqjz7c/pJrchZQgY zZsfdJGinS5dCQLzYktSbgJfvSJfsuF3K9P7aLWLR6orhvDeGmeWkTJZj31mhORA sbGz3sSlF4i7nQSzP1qN/gDPLuqhh0gpPGhfYo256UUP660r/cCUM3DRPxyOMqFs SztoOdh6WqA4DdlU9nYZ2EoMwgNy2x+S4IUGo5+fpGt+SRM33aTAhj9+kLMPaTcl q4UVUC/TYG2vWBHWAt0CF5wydcN0mQzmvryuDpfF0nf3BeW82lv36UmMd4Twl2F6 ZUVZqTGt5nC9wjKiIPYbzi+a7DekMsBFeJpRlg52i8CY+s2WaVDi3s8sbwNdwMWe GhaUa0VLeeVQdfJnkuZTKxuIS3xQavyL9n8wDTDMnJcuuDVIOWM9wI0YXise+AoW hgyvIpmqcjLnPwwtFkNX8f4qDYUek/WAyqjrk++YJN00G8LPqPVYmlJy8V1zZq84 fh+mnt9sq3MBn+hv6f0hKgMZtYeJw4SRafuMDzDJQmYBeKKp66cW8a2GrRPUYX4w IBdI98nt1dyPA1uWCAgAJfHh6tCpgVwbvn+6LLSs2rIeQ9lVNxe2IU+/PrkCxTwA dNUrWabyJkGr8ulcIKH6kF8p74DrJOFc3lriavkjEqHAKHhbkz6itLfjSxWyWSZb jOUNlA34Z356dE68QxfK =Iv8g -----END PGP SIGNATURE----- --CblX+4bnyfN0pR09-- --===============0729530460== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/intel-gfx --===============0729530460==--