Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3469497lqp; Tue, 26 Mar 2024 09:55:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXU1bu3TCAt/oJTiL3khpXBoqQPtGUradgC6VNjaK7RBgGzc70bA2YXNWq+HP3ngC8Y5TTfX+Cx1hQwdoFWxiBVIl91Q85CSLEk9iOKtA== X-Google-Smtp-Source: AGHT+IHo1RcvWWQ1FMWSYR3jXiyk7iSvevYeOjKM/nUK5Q8mtsG/Yoa9H2qhrBYgrhO0cHTqCvF9 X-Received: by 2002:a05:6a21:9188:b0:1a3:dc27:1f01 with SMTP id tp8-20020a056a21918800b001a3dc271f01mr1439204pzb.11.1711472155776; Tue, 26 Mar 2024 09:55:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711472155; cv=pass; d=google.com; s=arc-20160816; b=vFkE1CGmwNRmI7V4ultCkRJ19h3Qw4bbG/eV9DwIBaAKsja/Zx5prqn9NKqkYzIsyh jf+1oJoaXdmrAPLYG4Vvieo33HUkvMXeaimLOXHTuDTIlnyEmewNtHUWjlt7uyxbqojk 9L8c9Pu9w/hSAHDZL3/nDgv5ua+YehuoD+Zfi3QK+bWOF/MHN0R2otUYwvQEdSBEGkjx Urwu6uiQVX1VB69SCwB/UM/dT/ta2FSjnNZgTqBvobB1nE0e7SPVi9a9xJdtoh2eXW/o ArmIUf0gABe6KXKRvg9hsscGTTH/KJ/okwhKdgii5FORXl0qpUxrobJB9moOi1lNjhPS LJfg== 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=5/lQOR7r8Ck3BuCEedTmMI8LwJogFIXUogeiYwjvopw=; b=QIBb2CiEhdWLfacIJkPsq7odoZV8xz5IHcwGAbg9rY8sR38MdF7giu1IdGWscLCnH4 AAiDJ+SaiaQa/lsm1mauHGqCn+TmCS85TGSNQ2gR7KedIMxvMs4Xz769OZcgWHJ9szSH TvJfzuaBo3Y9h4eIonIXD0If6MenPoL5T1yZDHtMCf+E/c0KTOzQzZAMV16KIlZdKSnm ymZd1iivnJYXBiYGvSqzypmDT1smD/zhJoIyPudnTEgo/FPx8M3MBf3+B1Afg1yl3aIo Qf+4BbIbno2fG34njzAsISdA25JwJnZnUpx7NCS+4O9qqQafsOAVvb314sWSSQCZMaMX UPBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HVtj1YeZ; 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-119455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119455-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. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s16-20020a056a00179000b006eaa6766facsi5724579pfg.23.2024.03.26.09.55.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 09:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HVtj1YeZ; 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-119455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119455-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 4F2B8B27C63 for ; Tue, 26 Mar 2024 16:29:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 671EF13CC78; Tue, 26 Mar 2024 16:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="HVtj1YeZ" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 32D3413CA97; Tue, 26 Mar 2024 16:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711470520; cv=none; b=dpKEWJ+qL8Id+Aqws31aJ0EUiRQ4buKwW4e7RaC5dhmBqe5N69GotSpHJN1NthSc0oGnM7Rl6SiADRInmJVH4N0TuhCPtXFI3VF03Q3vp8batZ7AHz8iAJITvrpqk95AgfYawrAzr1RDwZk1JwyokC2nBGWWqx3wZNMSKFZ2XSw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711470520; c=relaxed/simple; bh=nR5TuLci3iFlAYcZ6pedtZwXIkYrkHTO/+6OUO3NIHI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PmB8pSUfCcGtlwIgnBBojk6giayLnrlGL5lZCICOwNtL9r8V/ahPNlQniZp4oCtdm7g/p1LNvTiWb2zYdyiqD4qKuV+TuiMeOS6uflynRbyXhxEjAoxxnVoQnYNQRblT8wdkPkTf2qz0q5O9SBZ3AK8yBPgLCl399UdDevlcXB8= 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=HVtj1YeZ; arc=none smtp.client-ip=217.70.183.200 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 A2D5820003; Tue, 26 Mar 2024 16:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711470516; 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=HVtj1YeZm6CRmYhskLomAR0SwckgFSmqlvAg460JM8EsoW+eCTsVP1edT8mjLLL9i8R3zV /+WLl3nwInPBxbfj50BizLlh6CdPyRBcFiLZ1hQUm3m3JzBnTVLsDFlkktpnhmpMEGH3Tm zrOD4Tz+zOouLrlxA0nHbgbwVRqouCAjuxos6NvwYnlGzOXH31hjXfb2bITDynpRXp1zmM 8C/Y0rCiZvR6tpt98ppSgZbJa4+onTqRXvnSyxHptSaasWEUTscgIMn7P2mXURB4y4fWzU a4n0Gdp/chmSOVnte1nm0Y2Jnjo2YJhD9EShu97dsMYov5aGzYbs1v27EOgKGA== From: Luca Ceresoli Date: Tue, 26 Mar 2024 17:28:12 +0100 Subject: [PATCH 2/4] 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: <20240326-hotplug-drm-bridge-v1-2-4b51b5eb75d5@bootlin.com> References: <20240326-hotplug-drm-bridge-v1-0-4b51b5eb75d5@bootlin.com> In-Reply-To: <20240326-hotplug-drm-bridge-v1-0-4b51b5eb75d5@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.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