From patchwork Thu Apr 12 16:12:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10339007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7E3C4602D8 for ; Thu, 12 Apr 2018 16:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EB7A26E74 for ; Thu, 12 Apr 2018 16:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6347726E79; Thu, 12 Apr 2018 16:23:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD9BC27165 for ; Thu, 12 Apr 2018 16:23:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 12FB66E999; Thu, 12 Apr 2018 16:23:53 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0FD3C6E999; Thu, 12 Apr 2018 16:23:51 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:54390 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1f6eqJ-0002mh-MB; Thu, 12 Apr 2018 18:12:59 +0200 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Date: Thu, 12 Apr 2018 18:12:35 +0200 Message-Id: <20180412161237.9314-12-noralf@tronnes.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180412161237.9314-1-noralf@tronnes.org> References: <20180412161237.9314-1-noralf@tronnes.org> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC v4 23/25] drm: Add DRM device registered notifier X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org, =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , laurent.pinchart@ideasonboard.com, mstaudt@suse.de, dh.herrmann@gmail.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Add a notifier that fires when a new DRM device is registered. This can be used by the bootsplash client to connect to all devices. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_drv.c | 32 ++++++++++++++++++++++++++++++++ include/drm/drm_drv.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 6f21bafb29be..e42ce320ad07 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -79,6 +80,8 @@ static struct dentry *drm_debugfs_root; DEFINE_STATIC_SRCU(drm_unplug_srcu); +static BLOCKING_NOTIFIER_HEAD(drm_dev_notifier); + /* * DRM Minors * A DRM device can provide several char-dev interfaces on the DRM-Major. Each @@ -837,6 +840,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) dev->dev ? dev_name(dev->dev) : "virtual device", dev->primary->index); + blocking_notifier_call_chain(&drm_dev_notifier, 0, dev); + goto out_unlock; err_minors: @@ -894,6 +899,33 @@ void drm_dev_unregister(struct drm_device *dev) } EXPORT_SYMBOL(drm_dev_unregister); +/** + * drm_dev_register_notifier - Register a notifier for new DRM devices + * @nb: Notifier block + * + * Register a notifier that fires when a new &drm_device is registered. + * + * Note: + * Users of this function has to be linked into drm.ko. This is done to make + * life simple avoiding tricky race situations. + */ +void drm_dev_register_notifier(struct notifier_block *nb) +{ + /* Currently this can't fail, but catch it in case this changes */ + WARN_ON(blocking_notifier_chain_register(&drm_dev_notifier, nb)); +} + +/** + * drm_dev_unregister_notifier - Unregister DRM device notifier + * @nb: Notifier block + * + * This is a no-op if the notifier isn't registered. + */ +void drm_dev_unregister_notifier(struct notifier_block *nb) +{ + blocking_notifier_chain_unregister(&drm_dev_notifier, nb); +} + /** * drm_dev_set_unique - Set the unique name of a DRM device * @dev: device of which to set the unique name diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 13356e6fd40c..5e6c6ed0d59d 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -40,6 +40,7 @@ struct drm_minor; struct dma_buf_attachment; struct drm_display_mode; struct drm_mode_create_dumb; +struct notifier_block; struct drm_printer; /* driver capabilities and requirements mask */ @@ -641,6 +642,9 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, int drm_dev_register(struct drm_device *dev, unsigned long flags); void drm_dev_unregister(struct drm_device *dev); +void drm_dev_register_notifier(struct notifier_block *nb); +void drm_dev_unregister_notifier(struct notifier_block *nb); + void drm_dev_get(struct drm_device *dev); void drm_dev_put(struct drm_device *dev); void drm_dev_unref(struct drm_device *dev);