Skip to contentSkip to conversation

drm/bridge: introduce bridge detaching mechanism

PATCH Superseded Andrea Merello 2 participants 2 messages Aug 23, 2016

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: introduce bridge detaching mechanism

Up to now, once a bridge has been attached to a DRM device, it cannot be undone.

In particular you couldn't rmmod/insmod a DRM driver that uses a bridge, because the bridge would remain bound to the first (dead) driver instance.

This patch fixes this by introducing drm_encoder_detach() and a ->detach callback in drm_bridge_funcs for the bridge to be notified about detaches.

It's DRM/KMS driver responsibility to call drm_encoder_detach().

drivers/gpu/drm/drm_bridge.c +33 -0
index 2555430..c4ace90 100644
@@ -125,6 +125,39 @@ int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge)
 EXPORT_SYMBOL(drm_bridge_attach);
 
 /**
+ * drm_bridge_detach - deassociate given bridge from its DRM device
+ *
+ * @bridge: bridge control structure
+ *
+ * called by a kms driver to unlink one of our encoder/bridge to the given
+ * bridge.
+ *
+ * Note that tearing down links between the bridge and our encoder/bridge
+ * objects needs to be handled by the kms driver itself
+ *
+ * RETURNS:
+ * Zero on success, error code on failure
+ */
+int drm_bridge_detach(struct drm_bridge *bridge)
+{
+	int ret;
+
+	if (!bridge || !bridge->dev)
+		return -EINVAL;
+
+	if (bridge->funcs->detach) {
+		ret = bridge->funcs->detach(bridge);
+		if (ret)
+			return ret;
+	}
+
+	bridge->dev = NULL;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_bridge_detach);
+
+/**
  * DOC: bridge callbacks
  *
  * The &drm_bridge_funcs ops are populated by the bridge driver. The DRM
include/drm/drm_crtc.h +2 -0
index b618b50..eef4db8 100644
@@ -1766,6 +1766,7 @@ struct drm_plane {
  */
 struct drm_bridge_funcs {
 	int (*attach)(struct drm_bridge *bridge);
+	int (*detach)(struct drm_bridge *bridge);
 
 	/**
 	 * @mode_fixup:
@@ -3196,6 +3197,7 @@ extern int drm_bridge_add(struct drm_bridge *bridge);
 extern void drm_bridge_remove(struct drm_bridge *bridge);
 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
+extern int drm_bridge_detach(struct drm_bridge *bridge);
 
 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
 			const struct drm_display_mode *mode,

--
2.7.4
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw
Quoted 31 lines · Andrea Merello

Up to now, once a bridge has been attached to a DRM device, it cannot be undone.

In particular you couldn't rmmod/insmod a DRM driver that uses a bridge, because the bridge would remain bound to the first (dead) driver instance.

This patch fixes this by introducing drm_encoder_detach() and a ->detach callback in drm_bridge_funcs for the bridge to be notified about detaches.

It's DRM/KMS driver responsibility to call drm_encoder_detach().

drivers/gpu/drm/drm_bridge.c +4 -0
index 2555430..c4ace90 100644
@@ -125,6 +125,39 @@ int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge)
 EXPORT_SYMBOL(drm_bridge_attach);
 
 /**
+ * drm_bridge_detach - deassociate given bridge from its DRM device
+ *
+ * @bridge: bridge control structure
+ *

drivers/gpu/drm/drm_bridge.c int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge) · line 141

Quoted 10 lines
drivers/gpu/drm/drm_bridge.c +10 -0
+ * called by a kms driver to unlink one of our encoder/bridge to the given
+ * bridge.
+ *
+ * Note that tearing down links between the bridge and our encoder/bridge
+ * objects needs to be handled by the kms driver itself
+ *
+ * RETURNS:
+ * Zero on success, error code on failure
+ */
+int drm_bridge_detach(struct drm_bridge *bridge)

Generally detach/cleanup functions have a return type of void - there's no way (usually) to bail out on errors anyway.

drivers/gpu/drm/drm_bridge.c int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge) · line 145

Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +4 -0
+{
+	int ret;
+
+	if (!bridge || !bridge->dev)

Hence WARN_ON here probably.

drivers/gpu/drm/drm_bridge.c int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge) · line 149

Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +4 -0
+		return -EINVAL;
+
+	if (bridge->funcs->detach) {
+		ret = bridge->funcs->detach(bridge);

Same for the callback to the backend.

Quoted 19 lines
drivers/gpu/drm/drm_bridge.c +11 -0
+		if (ret)
+			return ret;
+	}
+
+	bridge->dev = NULL;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_bridge_detach);
+
+/**
  * DOC: bridge callbacks
  *
  * The &drm_bridge_funcs ops are populated by the bridge driver. The DRM
include/drm/drm_crtc.h +0 -0
index b618b50..eef4db8 100644

include/drm/drm_crtc.h struct drm_plane { · line 1769

Quoted 4 lines
include/drm/drm_crtc.h +1 -0
@@ -1766,6 +1766,7 @@ struct drm_plane {
  */
 struct drm_bridge_funcs {
 	int (*attach)(struct drm_bridge *bridge);
+	int (*detach)(struct drm_bridge *bridge);

kerneldoc for @detach is missing here. And I think it'd be good to also make the kerneldoc for @attach a stand-alone comment and flesh it out a bit.

You might also need to include this into the simple pipe series so that you can wire up detach support for those helpers too.

Otherwise looks all good I think.

Thanks, Daniel

Quoted 13 lines
include/drm/drm_crtc.h +1 -1
 	/**
 	 * @mode_fixup:
@@ -3196,6 +3197,7 @@ extern int drm_bridge_add(struct drm_bridge *bridge);
 extern void drm_bridge_remove(struct drm_bridge *bridge);
 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
+extern int drm_bridge_detach(struct drm_bridge *bridge);
 
 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
 			const struct drm_display_mode *mode,
--

2.7.4

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel