From patchwork Mon Feb 25 14:42:27 2019 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: 10828647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C13417EF for ; Mon, 25 Feb 2019 14:42:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AE112B96C for ; Mon, 25 Feb 2019 14:42:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 785B22B9CC; Mon, 25 Feb 2019 14:42:48 +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=unavailable 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 444522BA03 for ; Mon, 25 Feb 2019 14:42:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8351B89322; Mon, 25 Feb 2019 14:42:45 +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 BF041892C5; Mon, 25 Feb 2019 14:42:44 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:45266 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1gyHSs-0003wA-Sz; Mon, 25 Feb 2019 15:42:42 +0100 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Date: Mon, 25 Feb 2019 15:42:27 +0100 Message-Id: <20190225144232.20761-3-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225144232.20761-1-noralf@tronnes.org> References: <20190225144232.20761-1-noralf@tronnes.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=gbaRNmsjhV5ArVjqm3fCfD6T7KLLL2cLenaQ8qSO14k=; b=RDNfpRwms7/zLU0fu9y4rEQXGmW00OP1EcWhov+gaEm2a8G3xG3V49lTpnJjDxmiX/ahkUi3M4dX5S+MxdZIY80bmUiBqZUEzRl0GtjTjXKiEZ6SCIeoMahcyuSbZ0eLnoP074SlKnWfTMGdFnt6cxgIWf5MgS64FXplDolay5+6PG+iAre9AXDFBg0LtI9F61iimvZesWI5b8rnTDvbdvNUjGckS4OiiGiYpAjkP5Sbn1f0/XVHC2uykkH1XypO4LfaJS0IV9AgNa/8YBfYSFt+5dnyRqFgt7l6MPunjXaekCHM+upSw9EopZzXZBw+D8rjXKH7CA4tLNLzaYt+TQ==; Subject: [Intel-gfx] [PATCH v3 2/7] drm: Add devm_drm_dev_init() 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: david@lechnology.com, daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org, =?utf-8?q?Noralf_Tr=C3=B8nnes?= , Greg KH , sam@ravnborg.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This adds a resource managed (devres) version of drm_dev_init(). v2: Remove devm_drm_dev_register() since we can't touch hw in devm release functions and drivers want to disable hw on driver module unload (Daniel Vetter, Greg KH) Cc: Daniel Vetter Cc: Greg KH Signed-off-by: Noralf Trønnes Acked-by: Gerd Hoffmann --- Documentation/driver-model/devres.txt | 3 +++ drivers/gpu/drm/drm_drv.c | 39 +++++++++++++++++++++++++++ include/drm/drm_drv.h | 3 +++ 3 files changed, 45 insertions(+) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index b277cafce71e..351b7ac65a1e 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -254,6 +254,9 @@ DMA dmam_pool_create() dmam_pool_destroy() +DRM + devm_drm_dev_init() + GPIO devm_gpiod_get() devm_gpiod_get_index() diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index ce65f12db0fe..934780a4c033 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -601,6 +601,45 @@ int drm_dev_init(struct drm_device *dev, } EXPORT_SYMBOL(drm_dev_init); +static void devm_drm_dev_init_release(void *data) +{ + drm_dev_put(data); +} + +/** + * devm_drm_dev_init - Resource managed drm_dev_init() + * @parent: Parent device object + * @dev: DRM device + * @driver: DRM driver + * + * Managed drm_dev_init(). The DRM device initialized with this function is + * automatically put on driver detach using drm_dev_put(). You must supply a + * &drm_driver.release callback to control the finalization explicitly. + * + * RETURNS: + * 0 on success, or error code on failure. + */ +int devm_drm_dev_init(struct device *parent, + struct drm_device *dev, + struct drm_driver *driver) +{ + int ret; + + if (WARN_ON(!parent || !driver->release)) + return -EINVAL; + + ret = drm_dev_init(dev, driver, parent); + if (ret) + return ret; + + ret = devm_add_action(parent, devm_drm_dev_init_release, dev); + if (ret) + devm_drm_dev_init_release(dev); + + return ret; +} +EXPORT_SYMBOL(devm_drm_dev_init); + /** * drm_dev_fini - Finalize a dead DRM device * @dev: DRM device diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index ca46a45a9cce..e81bce2698e3 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -718,6 +718,9 @@ extern unsigned int drm_debug; int drm_dev_init(struct drm_device *dev, struct drm_driver *driver, struct device *parent); +int devm_drm_dev_init(struct device *parent, + struct drm_device *dev, + struct drm_driver *driver); void drm_dev_fini(struct drm_device *dev); struct drm_device *drm_dev_alloc(struct drm_driver *driver,