From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A0F0606A31A for ; Tue, 1 Dec 2026 16:06:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=PKcd4w1V; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oGZfCbQi DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=vBoVBvZ9cdNHzoAsxjIynw8nLbbE1uw/MX8mUMebHgA=; b=PKcd4w1Vsqid2n5N4uIvBAbGNG dohz6qDtZu9xc2zwppVnK6XFbS0HO/ySd14q84Ah99l0ONnQidD6MwHjz3ibm54IcCagncfVA8fFJ uJDCqLp8KwIK3Psbv9xMGFm8MoIDgJXj6svVrnuHlnHpOqOnFDyU3pb/1HWAvtn3fbNHtNnSEjf9e xVccFSPqa2Dq2JWXvzDG6dSN8MacTC9XrVnNmpV4MVw9wHpEQIoHTj/N7vtL+MLU4NBVLU0dcn6SC 8q33uEwYu5GOqLRoHSM/xdW3Num/O7WWnoS2qL1qSBtJKzDKG5uTvLuwwAa3dkd5BnliliwUcSG6s qBOlLhsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYQMr-00000008eqs-17l7; Tue, 01 Dec 2026 16:06:09 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYQMm-00000008eqA-45vl for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 16:06:05 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id ED285611DD; Tue, 1 Dec 2026 16:06:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02E341F000C1; Tue, 1 Dec 2026 16:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796141163; bh=vBoVBvZ9cdNHzoAsxjIynw8nLbbE1uw/MX8mUMebHgA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=oGZfCbQiDwS7G6cGHsP9wY/6sSFg+5ckb/ZrFDboRafFrpek+S7azLA5wmi+oCDqh tnkIZwGfecnOVnAPrX9WwbMsnjJ3yeqDISkFFEjAigPsqDaFOVojbZPRO3QH2nO2Go JiMejKPX+i1Vf7r9ezzCP48K88A656xuzbh2dSamkDlV3ax/gDJ7jhpZOaSEchjIEw oSVfIzJixWP1S1cSIVJ0KDq/P0PnHvscpQCIpmy8oVXNhz+CeqY2U1tADP222VHL3p abzVqgF+TH2V1OU7Wfxdjzd/IOHxBI9EguENqt6t4sVxwqCVt9el6DFOTOkL3AXHll a49nPJmNiQY4A== Date: Tue, 1 Dec 2026 17:06:00 +0100 From: Maxime Ripard To: Luca Ceresoli Cc: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Inki Dae , Jagan Teki , Marek Szyprowski , Jessica Zhang , Douglas Anderson , Marek Vasut , Stefan Agner , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Javier Martinez Canillas , Dmitry Baryshkov , Hui Pu , Ian Ray , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Message-ID: References: <20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com> <20261125-drm-bridge-hotplug-v4-31-822722850492@bootlin.com> X-Archived-By: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha384; protocol="application/pgp-signature"; boundary="fvzkhm22ano67jzd" Content-Disposition: inline In-Reply-To: <20261125-drm-bridge-hotplug-v4-31-822722850492@bootlin.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 --fvzkhm22ano67jzd Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug MIME-Version: 1.0 On Wed, Nov 25, 2026 at 06:50:44PM +0100, Luca Ceresoli wrote: > Add a new helper to support cards implementing hotpluggable drm_bridges. >=20 > drmm_hotplug_helper_init() registers to get notified of relevant events a= nd > react by creating a bridge (if the pipeline is complete in the hardware) > and destroying it on bridge removal. >=20 > Signed-off-by: Luca Ceresoli >=20 > --- >=20 > Changes in v3: > - Do not require the first bridge is non-hotpluggable > - Support non-DSI bridges too > - Add callback to report connector add/remove > - Do not store the drm_device pointer, get it from the encoder > - use new v3 notifier API name >=20 > Changes in v2: > - Add callback to report connector addition/removal > - Sanity-check drmm_hotplug_helper_init() parameters > - Reformat kdoc comment > --- > MAINTAINERS | 8 + > drivers/gpu/drm/display/Kconfig | 7 + > drivers/gpu/drm/display/Makefile | 2 + > drivers/gpu/drm/display/drm_hotplug_helper.c | 325 +++++++++++++++++++++= ++++++ > include/drm/drm_hotplug_helper.h | 30 +++ > 5 files changed, 372 insertions(+) >=20 > diff --git a/MAINTAINERS b/MAINTAINERS > index a5e2bf15e59f..18ecb7bb39f4 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -8219,6 +8219,14 @@ F: Documentation/devicetree/bindings/npu/rockchip,= rk3588-rknn-core.yaml > F: drivers/accel/rocket/ > F: include/uapi/drm/rocket_accel.h > =20 > +DRM BRIDGE HOTPLUG HELPER > +M: Luca Ceresoli > +S: Maintained > +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git > +F: Documentation/devicetree/bindings/display/bridge/ > +F: drivers/gpu/drm/display/drm_hotplug_helper.c > +F: include/drm/drm_hotplug_helper.h > + I don't think we want to add a new maintainer entry for each new file we create under drivers/gpu/drm. > DRM COMPUTE ACCELERATORS DRIVERS AND FRAMEWORK > M: Oded Gabbay > L: dri-devel@lists.freedesktop.org > diff --git a/drivers/gpu/drm/display/Kconfig b/drivers/gpu/drm/display/Kc= onfig > index df09cf9a8ca1..e086e2fd08a4 100644 > --- a/drivers/gpu/drm/display/Kconfig > +++ b/drivers/gpu/drm/display/Kconfig > @@ -22,6 +22,13 @@ config DRM_BRIDGE_CONNECTOR > help > DRM connector implementation terminating DRM bridge chains. > =20 > +config DRM_HOTPLUG_HELPER > + bool > + depends on OF > + select DRM_BRIDGE_CONNECTOR > + help > + Helper code to implement a card supporting hotpluggable bridges. > + > config DRM_DISPLAY_DP_AUX_CEC > bool "Enable DisplayPort CEC-Tunneling-over-AUX HDMI support" > select DRM_DISPLAY_DP_HELPER > diff --git a/drivers/gpu/drm/display/Makefile b/drivers/gpu/drm/display/M= akefile > index 0ff4a1ad0222..ce6dbd65833b 100644 > --- a/drivers/gpu/drm/display/Makefile > +++ b/drivers/gpu/drm/display/Makefile > @@ -5,6 +5,8 @@ obj-$(CONFIG_DRM_DISPLAY_DP_AUX_BUS) +=3D drm_dp_aux_bus.o > drm_display_helper-y :=3D drm_display_helper_mod.o > drm_display_helper-$(CONFIG_DRM_BRIDGE_CONNECTOR) +=3D \ > drm_bridge_connector.o > +drm_display_helper-$(CONFIG_DRM_HOTPLUG_HELPER) +=3D \ > + drm_hotplug_helper.o > drm_display_helper-$(CONFIG_DRM_DISPLAY_DP_HELPER) +=3D \ > drm_dp_dual_mode_helper.o \ > drm_dp_helper.o \ > diff --git a/drivers/gpu/drm/display/drm_hotplug_helper.c b/drivers/gpu/d= rm/display/drm_hotplug_helper.c > new file mode 100644 > index 000000000000..ea32bdb0af8f > --- /dev/null > +++ b/drivers/gpu/drm/display/drm_hotplug_helper.c > @@ -0,0 +1,325 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (C) 2026 GE HealthCare > + * Author: Luca Ceresoli > + */ > + > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +struct drm_hotplug_helper { > + /** > + * @encoder: The encoder at the start of the bridges chain > + */ > + struct drm_encoder *encoder; > + /** > + * @event_cb: Callback to report connector addition/removal > + */ > + drm_hotplug_helper_event_cb event_cb; > + /** > + * @drm_event_nb: Notifier to receive DRM hotplug-related events > + */ > + struct notifier_block drm_event_nb; > + /** > + * @connector: The drm_connector added/removed on plug/unplug > + */ > + struct drm_connector *connector; > + /** > + * @event_mutex: Protect entry points (init, fini, event notifier) > + * from concurrent attach and connector creation or destruction > + */ > + struct mutex event_mutex; > + /** > + * @first_bridge_ep: Device tree node of the encoder endpoint > + * connected to the first bridge > + */ > + struct device_node *first_bridge_ep; > +}; > + > +/* > + * True if the encoder bridge chain is complete, i.e. the last bridge in > + * the chain is the last bridge expected in the hardware (e.g. a panel). > + */ > +static bool drm_hotplug_helper_bridge_chain_is_complete(struct drm_hotpl= ug_helper *hotplug_helper) > +{ > + struct drm_bridge *last_bridge __free(drm_bridge_put) =3D > + drm_bridge_chain_get_last_bridge(hotplug_helper->encoder); > + struct drm_device *drm =3D hotplug_helper->encoder->dev; > + > + /* We expect at least one bridge */ > + if (!last_bridge) { > + drm_dbg_driver(drm, "no bridges in pipeline (yet)\n"); > + return false; > + } > + > + struct drm_bridge *next_bridge __free(drm_bridge_put) =3D > + drm_bridge_get_next(last_bridge); > + > + /* No next bridge expected, pipeline is complete */ > + if (!next_bridge) { > + drm_dbg_driver(drm, "pipeline complete\n"); > + return true; > + } > + > + /* Next bridge expected but not there now, pipeline incomplete */ > + if (next_bridge =3D=3D ERR_PTR(-ENODEV)) { > + drm_dbg_driver(drm, "pipeline not (yet) complete\n"); > + return false; > + } I'd drop these yet. We don't know if it ever will be here, so I think it's more confusing than anything. > + /* Unexpected error */ > + if (IS_ERR(next_bridge)) > + drm_warn(drm, "%s error %pe\n", __func__, next_bridge); > + > + /* next_bridge is valid, but not (yet|anymore) in chain */ > + return false; > +} > + > +/** > + * drm_hotplug_helper_connector_add - add the drm_connector > + * @hotplug_helper: drm_hotplug_helper to add the drm_connector to > + * > + * Returns 0 on success or a negative error otherwise. > + */ > +static int drm_hotplug_helper_connector_add(struct drm_hotplug_helper *h= otplug_helper) > +{ > + struct drm_device *drm =3D hotplug_helper->encoder->dev; > + struct drm_connector *connector; > + > + if (drm_WARN_ON(drm, hotplug_helper->connector)) > + return -EBUSY; > + > + connector =3D drm_bridge_connector_dynamic_add(drm, hotplug_helper->enc= oder); > + if (IS_ERR(connector)) > + return PTR_ERR(connector); > + > + hotplug_helper->connector =3D connector; > + hotplug_helper->event_cb(DRM_HOTPLUG_HELPER_CONNECTOR_ADDED, connector); > + > + dev_dbg(drm->dev, "added bridge connector\n"); > + > + return 0; > +} > + > +/* > + * Removes the connector, which must be present. > + * > + * Must be called with the hotplug_helper->event_mutex locked. > + */ > +static void drm_hotplug_helper_connector_remove(struct drm_hotplug_helpe= r *hotplug_helper) > +{ > + struct drm_device *drm =3D hotplug_helper->encoder->dev; > + > + if (drm_WARN_ON(drm, !hotplug_helper->connector)) > + return; > + > + dev_dbg(drm->dev, "removing bridge connector\n"); > + > + hotplug_helper->event_cb(DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING, hotplug= _helper->connector); > + drm_bridge_connector_dynamic_remove(hotplug_helper->connector); > + hotplug_helper->connector =3D NULL; > +} > + > +/* > + * Propagate the attach chain and possibly add a drm_bridge_connector af= ter > + * a new drm_bridge is hot-plugged. > + * > + * The connector is added only if the pipeline is now complete. This cou= ld > + * not be the case for various reasons: > + * > + * - the new bridge is just unrelated to our encoder > + * - the new bridge is not the next one in the pipeline > + * - the new bridge is the next in the pipeline but the pipeline is not = yet > + * complete > + * > + * All these cases are normal, not an error. > + * > + * Must be called with the hotplug_helper->event_mutex locked. > + */ > +static void drm_hotplug_helper_try_complete(struct drm_hotplug_helper *h= otplug_helper) > +{ > + struct device *dev =3D hotplug_helper->encoder->dev->dev; > + int err; > + > + WARN_ON(!mutex_is_locked(&hotplug_helper->event_mutex)); > + > + /* > + * drm_connector already present, the new bridge must be for > + * another card > + */ > + if (hotplug_helper->connector) > + return; > + > + struct drm_bridge *last_bridge __free(drm_bridge_put) =3D > + drm_bridge_chain_get_last_bridge(hotplug_helper->encoder); > + > + if (last_bridge) { > + /* > + * Some bridge(s) already in the chain, propagate the > + * attach call chain from the current chain tail to newly > + * hotplugged bridge(s) > + */ > + dev_dbg(dev, "propagate attach after %ps\n", last_bridge->funcs); > + > + err =3D last_bridge->funcs->attach(last_bridge, hotplug_helper->encode= r, > + DRM_BRIDGE_ATTACH_NO_CONNECTOR); > + if (err) > + return; > + } else { > + /* Bridge chain still empty, find first bridge and attach */ > + > + const struct device_node *first_bridge_node __free(device_node) =3D > + of_graph_get_remote_port_parent(hotplug_helper->first_bridge_ep); > + if (!of_device_is_available(first_bridge_node)) > + return; > + > + struct drm_bridge *first_bridge __free(drm_bridge_put) =3D > + of_drm_find_and_get_bridge(first_bridge_node); > + if (!first_bridge) > + return; > + > + dev_dbg(dev, "attach chain starting at %ps\n", first_bridge->funcs); > + > + err =3D drm_bridge_attach(hotplug_helper->encoder, first_bridge, NULL, > + DRM_BRIDGE_ATTACH_NO_CONNECTOR); > + if (err) > + return; > + } > + > + /* Add the connector if the encoder chain is now complete */ > + if (drm_hotplug_helper_bridge_chain_is_complete(hotplug_helper)) > + drm_hotplug_helper_connector_add(hotplug_helper); > +} > + > +static int drm_hotplug_helper_handle_event(struct notifier_block *nb, > + unsigned long event, void *data) > +{ > + struct drm_hotplug_helper *hotplug_helper =3D > + container_of(nb, struct drm_hotplug_helper, drm_event_nb); > + struct device *dev =3D hotplug_helper->encoder->dev->dev; > + > + guard(mutex)(&hotplug_helper->event_mutex); > + > + dev_dbg(dev, "received event %lu\n", event); > + > + switch (event) { > + case DRM_BRIDGE_ADDED: > + case DRM_MIPI_DSI_ATTACHED: > + /* > + * A bridges hot-plugged, try adding the > + * drm_bridge_connector > + */ > + drm_hotplug_helper_try_complete(hotplug_helper); > + break; I'm still not quite sure why we need to special-case MIPI-DSI here. If the bridge is added, then who cares about the bus it's using? Maxime >=20 --fvzkhm22ano67jzd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iJUEABMJAB0WIQTkHFbLp4ejekA/qfgnX84Zoj2+dgUCaw7wWwAKCRAnX84Zoj2+ dh5rAYCnvOPqvOUOrP7MDEVSAzge/5cQgFiNaCSB4iq4rQnSOUyQp6KxH9OR8VKq nRQScMoBgKGdeLUXFhA5TkZ7U4tcDPtAXR0Lj3Dr4RaXwFdU9AZqpjCz0AGNOl/U JU1xN6mSaw== =9YyX -----END PGP SIGNATURE----- --fvzkhm22ano67jzd--