Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp319968lqo; Fri, 10 May 2024 00:14:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGZePEIGQbLVaDlHyUMaFJPa5J/LeDQC8ao9M5Ae4nVFJNQilHd3eeDBzEPCFgmL5BjMMkQ3Oc2Xeep/FS7cx1524JSEGBX77OTm164A== X-Google-Smtp-Source: AGHT+IHRp0WalApnQdJZeCoLXHFr0xGTd2YIKEPdFELeTEAUk/1g1KgUB/w8H5JNPhsngCzQ+7wr X-Received: by 2002:a05:6870:214e:b0:22e:c8ee:9307 with SMTP id 586e51a60fabf-24172900b09mr1989980fac.29.1715325240108; Fri, 10 May 2024 00:14:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715325240; cv=pass; d=google.com; s=arc-20160816; b=zsmp9EyqwaxU+OSuPZXI35GC8buWC3HGUHuBmLtYpbZeT2Y64/iWATqSs9LVxhq4Ps 4+fQ3b7u024a9p1tZblUabT6KmPFZhzWcQe61qzhxIcY0Pj1f4qDcUc4n2JHVX7W1v+l kbnOf1iUtTeAjBt5Aa/2WJpJY2dwobcJVbxSNZkPcWgMeJINy3I5WwxtQICZih7pM9uU tC2drZ8OdVoTUSHMdIUj231R10NNjIkLcfi1pmH+xK0Na1TpMUT3Mb7nL7BpuM/PHKsR LBkgiG0WL7hVP6hT0X2wKAFfZBzGPIiAZH97GNEQheWjg/MT1+TOFv2LoubD9zITM3BJ DZHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=sI8WmkUUHY9Zro8RyMVYK+yqLrqdOum7SUJ1HQ/OZVw=; fh=1UkrlD8RjbfPcEjCytvKsF2+DMsNoZ7VTOVVKkrBxCk=; b=sTUGDcvtJytpajmynH/DcVCyDBeuGWYvnQ5TtHrrNx4YnuHLbwyovHAFNR1Enam1fJ ke+w/F6VJ1d/wDh6faB2ltITbELDD3gOYb1pDJj8yHAMg1s344BigZ+wCk6Oq4m2tzA/ c0q74ACXAxHbXGy+iCH49aK2OKi8FY1aZUzJd8hXD24eaBjSJ9ZkJmhNabqO2nc2iaoJ rDr6ofhuz54gXqCzSbadVrNVR3cxPhJEPa+4zAb0x/tl8f8lmQ1hQs4uPEWewBX5idSp DRGvVqGpilWSr9pJfquDjMimdy+DD9QzlrvBcCv9mDpr6XqIGRU+ehrysluCxETYxz5p ZBFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=S8MGmZjU; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-175385-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175385-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2af11e4si3082173b3a.170.2024.05.10.00.13.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 00:14:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175385-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=S8MGmZjU; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-175385-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175385-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 200AFB210C4 for ; Fri, 10 May 2024 07:12:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8374915B147; Fri, 10 May 2024 07:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="S8MGmZjU" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C55715EFAB; Fri, 10 May 2024 07:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715325104; cv=none; b=tsAmFFz4GUpQoaxr8ivldrLJ2ASLiuarrvAyGXl9U8S3cALrEOCpK9MBf/aSrZtlmGUKNahDUiNLzMIWHF77Fk5Db6ObZLWMLB/gp3RRQiBytpsqpGWANn5c/iVTo5oMJDFJFIIGMXSAGxUQ5vc7KNwZHXFeJeUg/azLrBFa3b0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715325104; c=relaxed/simple; bh=nR5TuLci3iFlAYcZ6pedtZwXIkYrkHTO/+6OUO3NIHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pf327DYtjv71PCR2EJ4eh2dzgBdZlXx6ynDmr0SvBhUAPlS/jliSz/0E04lh4KBEbxAtmiG7uuOiAodC5mSj2qRQJugQ8YjBzUkk1M8l0quuqMCkUUK1HF8PUfSLLxkaZQ5WoAfnMRp1aMGR3+AyINbhdSmtK+rlwYQnKA9/v9k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=S8MGmZjU; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 359FF1C0002; Fri, 10 May 2024 07:11:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715325095; 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=sI8WmkUUHY9Zro8RyMVYK+yqLrqdOum7SUJ1HQ/OZVw=; b=S8MGmZjUpe2CwX481FBG08hduF7uyIkuMveONJYOOLVTHn6h+mgL63gD/zfNDOh/ulPrNJ QjXcTH0wLhv67CnH9sQYqNwkDGm1ZJFXlJxWjDUKc+019PVKtdH/vJ6+pIqBQwgxMopRqO uljWnYosVZ+6K4vRpwWQvruErgAmv4wTQaIfralTFZnbvarNOW39D1Cum+mw055ClKcjVe 4d2GqJwpPNDGxX4z6DdYKyNApEbprbbgbbarmspN75ih1dWPtW2kxSVXLum/vxlXeEYazZ MdziLkwmauv5sc4QC9Rq9de8a2r230b4+KF27fXXUUlq3ikUzpn0jkvSeIbXew== From: Luca Ceresoli Date: Fri, 10 May 2024 09:10:38 +0200 Subject: [PATCH v2 2/5] drm/bridge: add bridge notifier to be notified of bridge addition and removal Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240510-hotplug-drm-bridge-v2-2-ec32f2c66d56@bootlin.com> References: <20240510-hotplug-drm-bridge-v2-0-ec32f2c66d56@bootlin.com> In-Reply-To: <20240510-hotplug-drm-bridge-v2-0-ec32f2c66d56@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 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, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.13.0 X-GND-Sasl: luca.ceresoli@bootlin.com From: Paul Kocialkowski In preparation for allowing bridges to be added to and removed from a DRM card without destroying the whole card, add a DRM bridge notifier. Notified events are addition and removal to/from the global bridge list. Co-developed-by: Luca Ceresoli Signed-off-by: Luca Ceresoli Signed-off-by: Paul Kocialkowski --- drivers/gpu/drm/drm_bridge.c | 35 +++++++++++++++++++++++++++++++++++ include/drm/drm_bridge.h | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 521a71c61b16..245f7fa4ea22 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -197,6 +198,36 @@ static DEFINE_MUTEX(bridge_lock); static LIST_HEAD(bridge_list); +static BLOCKING_NOTIFIER_HEAD(bridge_notifier); + +/** + * drm_bridge_notifier_register - add a DRM bridge notifier + * @nb: the notifier block to be registered + * + * The notifier block will be notified of events defined in + * &drm_bridge_notifier_event + */ +int drm_bridge_notifier_register(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&bridge_notifier, nb); +} +EXPORT_SYMBOL(drm_bridge_notifier_register); + +/** + * drm_bridge_notifier_unregister - remove a DRM bridge notifier + * @nb: the notifier block to be unregistered + */ +int drm_bridge_notifier_unregister(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&bridge_notifier, nb); +} +EXPORT_SYMBOL(drm_bridge_notifier_unregister); + +static void drm_bridge_notifier_notify(unsigned long event, + struct drm_bridge *bridge) +{ + blocking_notifier_call_chain(&bridge_notifier, event, bridge); +} /** * drm_bridge_add - add the given bridge to the global bridge list @@ -210,6 +241,8 @@ void drm_bridge_add(struct drm_bridge *bridge) mutex_lock(&bridge_lock); list_add_tail(&bridge->list, &bridge_list); mutex_unlock(&bridge_lock); + + drm_bridge_notifier_notify(DRM_BRIDGE_NOTIFY_ADD, bridge); } EXPORT_SYMBOL(drm_bridge_add); @@ -243,6 +276,8 @@ EXPORT_SYMBOL(devm_drm_bridge_add); */ void drm_bridge_remove(struct drm_bridge *bridge) { + drm_bridge_notifier_notify(DRM_BRIDGE_NOTIFY_REMOVE, bridge); + mutex_lock(&bridge_lock); list_del_init(&bridge->list); mutex_unlock(&bridge_lock); diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 4baca0d9107b..ee48c1eb76ae 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -43,6 +43,22 @@ struct drm_panel; struct edid; struct i2c_adapter; +/** + * enum drm_bridge_notifier_event - DRM bridge events + */ +enum drm_bridge_notifier_event { + /** + * @DRM_BRIDGE_NOTIFY_ADD: A bridge has just been added to the + * global bridge list. See drm_bridge_add(). + */ + DRM_BRIDGE_NOTIFY_ADD, + /** + * @DRM_BRIDGE_NOTIFY_REMOVE: A bridge is about to be removed from + * the global bridge list. See drm_bridge_remove(). + */ + DRM_BRIDGE_NOTIFY_REMOVE, +}; + /** * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach */ @@ -781,6 +797,9 @@ drm_priv_to_bridge(struct drm_private_obj *priv) return container_of(priv, struct drm_bridge, base); } +int drm_bridge_notifier_register(struct notifier_block *nb); +int drm_bridge_notifier_unregister(struct notifier_block *nb); + void drm_bridge_add(struct drm_bridge *bridge); int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge); void drm_bridge_remove(struct drm_bridge *bridge); -- 2.34.1