[PATCH RFC] drm/bridge: panel: Add module_get/but calls to attached panel driver

Thierry Reding thierry.reding at gmail.com
Wed Feb 21 14:26:14 UTC 2018


On Wed, Feb 21, 2018 at 08:18:42AM +0100, Lukas Wunner wrote:
> [+cc Rafael]
> 
> On Tue, Feb 20, 2018 at 05:04:00PM +0200, Jyri Sarha wrote:
> > On 20/02/18 14:03, Thierry Reding wrote:
> > > On Tue, Feb 20, 2018 at 01:28:48PM +0200, Jyri Sarha wrote:
> > >> On 20/02/18 12:34, Thierry Reding wrote:
> > >>>> On Mon, Feb 19, 2018 at 10:06:22PM +0200, Jyri Sarha wrote:
> > >>>>> Currently there is no way for a master drm driver to protect against an
> > >>>>> attached panel driver from being unloaded while it is in use. The
> > >>>>> least we can do is to indicate the usage by incrementing the module
> > >>>>> reference count.
> [...]
> > >>> I disagree. module_get() is only going to protect you from unloading a
> > >>> module that's in use, but there are other ways to unbind a driver from
> > >>> the device and cause subsequent mayhem.
> > >>>
> > >>> struct device_link was "recently" introduced to fix that issue.
> > >>
> > >> Unfortunately I do not have time to do full fix for the issue, but in
> > >> any case I think this patch is a step to the right direction. The module
> > >> reference count should anyway be increased at least to know that the
> > >> driver code remains in memory, even if the device is not there any more.
> > > 
> > > I think device links are actually a lot easier to use and give you a
> > > full solution for this. Essentially the only thing you need to do is add
> > > a call to device_link_add() in the correct place.
> > > 
> > > That said, it seems to me like drm_panel_bridge_add() is not a good
> > > place to add this, because the panel/bridge does not follow a typical
> > > consumer/supplier model. It is rather a helper construct with a well-
> > > defined lifetime.
> > > 
> > > What you do want to protect is the panel (the "parent" of the panel/
> > > bridge) from going away unexpectedly. I think the best way to achieve
> > > that is to make the link in drm_panel_attach() with something like
> > > this:
> > > 
> > > 	u32 flags = DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE;
> > > 	struct device *consumer = connector->dev->dev;
> > > 
> > > 	link = device_link_add(consumer, panel->dev, flags);
> > > 	if (!link) {
> > > 		dev_err(panel->dev, "failed to link panel %s to %s\n",
> > > 			dev_name(panel->dev), dev_name(consumer));
> > > 		return -EINVAL;
> > > 	}
> > > 
> > > Ideally I think we'd link the panel to the connector rather than the
> > > top-level DRM device, but we don't have a struct device * for that, so
> > > this is probably as good as it gets for now.
> > 
> > Thanks for the hint. Adding the link indeed unbinds the master drm
> > device when the panel is unloaded without any complaints.
> > 
> > The annoying thing is that the master drm device does not probe again
> > and bind when the supplier device becomes available again. However,
> > forcing a manual bind brings the whole device back without a problem.
> > 
> > Is there any trivial way to fix this?
> 
> How about the below, would this work for you?
> 
> Or is the device link added in the consumer's driver, hence is gone when
> the consumer is unbound?  If so, it should be added somewhere else,
> or it shouldn't be removed on consumer unbind.
> 
> @Thierry:  Thanks for shifting the discussion in the right direction,
> it's good to see device links getting more adoption, instead of
> proliferating yet more kludges.  However I don't understand why you say
> we don't have a struct device for the connector, drm_sysfs_connector_add()
> does create one.

The problem is that the device created by drm_sysfs_connector_add() is
created purely to represent the device in sysfs. That means it won't
have a driver bound to it, so if you add the device link to that, then
the driver core will try to unbind the sysfs device which isn't bound
in the first place.

I think what we'd need is for drivers to be able to set that device to
whatever their parent is. For example, if there's an IP block on an SoC
that provides the connector, then the corresponding pdev->dev should be
that pointer. That way the device link would work as expected and tear
down the driver for that IP block (hopefully together with the rest of
the DRM device).

However, doing this via the DRM device's ->dev should also work because
a) not all connectors have a parent device and b) the dependency really
is from the DRM device to the panel.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20180221/822d8f48/attachment.sig>


More information about the dri-devel mailing list