From patchwork Tue Sep 17 08:53:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13805998 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F4CEC35FF9 for ; Tue, 17 Sep 2024 08:53:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 886DF10E43C; Tue, 17 Sep 2024 08:53:25 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="BJoY7kvf"; dkim-atps=neutral Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id E195510E43C for ; Tue, 17 Sep 2024 08:53:22 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 85DE124000F; Tue, 17 Sep 2024 08:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726563201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pWWypgKRB8PzJi/zpHcCz4egF/NFlS15AogNtOzFzH8=; b=BJoY7kvfpFe1zSibqxQQNoKTYHNxxjT6wRGANCnxMw9l7S7rFpSQxG84DayuEhby1UaiP3 DfiYsGJKo4tWhBKLv9J/4X+/JkhNuI+bUGgzaGj+vj5U4k0WnuGMGliEPvdvcBhVHlbskB zyfDCTWRja3Qei9vXfn0Nng0aUAFesbTZxEETB75ax1YAcpDauVKJPCUkzz7UqRpDRJfEc RBxhRIwAnlVi0wBmJkUoIDj8ohXeOe/+T2a790TJ5dd7plwcEW6A8FwkvnIh9/14SH11B3 qMwb3LuFegweEC6Q4amanAs1bHZf/MmIOrZOSS4Qrcc38lgTeaj6d/GFu4W2NA== From: Luca Ceresoli Date: Tue, 17 Sep 2024 10:53:06 +0200 Subject: [PATCH v4 2/8] drm/bridge: allow bridges to be informed about added and removed bridges MIME-Version: 1.0 Message-Id: <20240917-hotplug-drm-bridge-v4-2-bc4dfee61be6@bootlin.com> References: <20240917-hotplug-drm-bridge-v4-0-bc4dfee61be6@bootlin.com> In-Reply-To: <20240917-hotplug-drm-bridge-v4-0-bc4dfee61be6@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" , Lee Jones , Daniel Thompson , Jingoo Han , Helge Deller Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, linux-fbdev@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.1 X-GND-Sasl: luca.ceresoli@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for allowing bridges to be added to and removed from a DRM card without destroying the whole card, add a new DRM bridge function called on addition and removal of bridges. Signed-off-by: Luca Ceresoli --- drivers/gpu/drm/drm_bridge.c | 12 ++++++++++++ include/drm/drm_bridge.h | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index d44f055dbe3e..c98117f1abec 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -205,8 +205,14 @@ static LIST_HEAD(bridge_list); */ void drm_bridge_add(struct drm_bridge *bridge) { + struct drm_bridge *br, *tmp; + mutex_init(&bridge->hpd_mutex); + list_for_each_entry_safe(br, tmp, &bridge_list, list) + if (br->funcs->bridge_event_notify) + br->funcs->bridge_event_notify(br, DRM_EVENT_BRIDGE_ADD, bridge); + mutex_lock(&bridge_lock); list_add_tail(&bridge->list, &bridge_list); mutex_unlock(&bridge_lock); @@ -243,10 +249,16 @@ EXPORT_SYMBOL(devm_drm_bridge_add); */ void drm_bridge_remove(struct drm_bridge *bridge) { + struct drm_bridge *br, *tmp; + mutex_lock(&bridge_lock); list_del_init(&bridge->list); mutex_unlock(&bridge_lock); + list_for_each_entry_safe(br, tmp, &bridge_list, list) + if (br->funcs->bridge_event_notify) + br->funcs->bridge_event_notify(br, DRM_EVENT_BRIDGE_REMOVE, bridge); + mutex_destroy(&bridge->hpd_mutex); } EXPORT_SYMBOL(drm_bridge_remove); diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 75019d16be64..635cc24bdeba 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -54,6 +54,11 @@ enum drm_bridge_attach_flags { DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0), }; +enum drm_bridge_event_type { + DRM_EVENT_BRIDGE_ADD, + DRM_EVENT_BRIDGE_REMOVE, +}; + /** * struct drm_bridge_funcs - drm_bridge control functions */ @@ -676,6 +681,24 @@ struct drm_bridge_funcs { enum hdmi_infoframe_type type, const u8 *buffer, size_t len); + /** + * @bridge_event_notify: + * + * Notify that another bridge is being added or removed. + * + * This callback is optional. Bridges implementing it must always + * check whether the event refers to a bridge they actually need to + * interact with. + * + * @bridge: bridge being notified + * @event: event happened (add/remove bridge) + * @new_bridge: the bridge mentioned by the event (i.e. the bridge + * being added or removed) + */ + void (*bridge_event_notify)(struct drm_bridge *bridge, + enum drm_bridge_event_type event, + struct drm_bridge *event_bridge); + /** * @debugfs_init: *