Re: [PATCH v5 04/10] drm/bridge: add documentation of refcounted bridges

0 views
Skip to first unread message

Randy Dunlap

unread,
Dec 31, 2024, 12:56:36 PM12/31/24
to Luca Ceresoli, Simona Vetter, Inki Dae, Jagan Teki, Marek Szyprowski, Catalin Marinas, Will Deacon, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam, Daniel Thompson, Andrzej Hajda, Jonathan Corbet, Paul Kocialkowski, Maxime Ripard, Dmitry Baryshkov, Neil Armstrong, Robert Foss, Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Maarten Lankhorst, Thomas Zimmermann, David Airlie, Hervé Codina, Thomas Petazzoni, linux-...@vger.kernel.org, dri-...@lists.freedesktop.org, linu...@vger.kernel.org, Paul Kocialkowski
Hi--

On 12/31/24 2:39 AM, Luca Ceresoli wrote:
> Document in detail the new refcounted bridges as well as the "legacy" way.
>
> Signed-off-by: Luca Ceresoli <luca.c...@bootlin.com>
>
> ---
>
> This patch was added in v5.
> ---
> Documentation/gpu/drm-kms-helpers.rst | 6 ++
> drivers/gpu/drm/drm_bridge.c | 122 ++++++++++++++++++++++++++++++++++
> 2 files changed, 128 insertions(+)
>
> diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
> index 8cf2f041af4704875910ce8228ae04615d0f21bd..ca2cfef2101988933e1464fe146997c1a661a117 100644
> --- a/Documentation/gpu/drm-kms-helpers.rst
> +++ b/Documentation/gpu/drm-kms-helpers.rst
> @@ -151,6 +151,12 @@ Overview
> .. kernel-doc:: drivers/gpu/drm/drm_bridge.c
> :doc: overview
>
> +Bridge lifecycle
> +----------------
> +
> +.. kernel-doc:: drivers/gpu/drm/drm_bridge.c
> + :doc: bridge lifecycle
> +
> Display Driver Integration
> --------------------------
>
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index 6255ef59f73d8041a8cb7f2c6e23e5a67d1ae926..e9f138aa5b3270b4e3a1a56dc8d4b7e5f993c929 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
> @@ -60,6 +60,128 @@
> * encoder chain.
> */
>
> +/**
> + * DOC: bridge lifecycle
> + *
> + * Allocation, initializion and teardown of a bridge can be implemented in

initialization

> + * one of two ways: *refcounted* mode and *legacy* mode.
> + *
> + * In **refcounted** mode:
> + *
> + * - each &struct drm_bridge is reference counted since its instantiation
> + * - any code taking a pointer to a bridge has get and put APIs to refcount
> + * it and so ensure the bridge won't be deallocated while using it
> + * - deallocation is done when the last put happens and the refcount drops
> + * to zero
> + * - the driver instantiating the bridge also holds a reference, but the
> + * allocated struct can survive it
> + *
> + * A bridge using refcounted mode is called a *refcounted bridge*.
> + *
> + * In **legacy** mode the &struct drm_bridge lifetime is tied to the device
> + * instantiating it: it is allocated on probe and freed on removal. Any
> + * other kernel entities holding a pointer to the bridge could incur in
> + * use-after-free in case the bridge is deallocated at runtime.
> + *
> + * Legacy mode used to be the only one until refcounted bridges were
> + * introduced, hance the name. It is still fine in case the bridges are a

hence

> + * fixed part of the pipeline, i.e. if the bridges are removed only when
> + * tearing down the entire card. Refcounted bridges support both that case
> + * and the case of more dynamic hardware with bridges that can be removed
> + * at runtime without tearing down the entire card.
> + *
> + * Usage of refcounted bridges happens in two sides: the driver
> + * implementing the bridge and the code using the bridge.
> + *
> + * For *drivers implemeting the bridge*, in both refcounted and legacy

implementing

> + * modes the common and expected pattern is that the driver declares a
> + * driver-specific struct embedding a &struct drm_bridge. E.g.::


--
~Randy


Reply all
Reply to author
Forward
0 new messages