From patchwork Fri Jun 3 14:36:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9153223 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 85B0460221 for ; Fri, 3 Jun 2016 14:37:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7606F26C9B for ; Fri, 3 Jun 2016 14:37:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AD44282E8; Fri, 3 Jun 2016 14:37:35 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D205926C9B for ; Fri, 3 Jun 2016 14:37:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6FA806E4D7; Fri, 3 Jun 2016 14:37:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id E3CB26E4D7; Fri, 3 Jun 2016 14:37:24 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id e3so24020012wme.2; Fri, 03 Jun 2016 07:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+O4CfC5rc+kCfcq7VX0kFhzpm+TZ5pPVw3LpPYutCro=; b=XUaZmpVMYEk9f8oQySaHKN8YC6/kgboucWZ2UzjFV74QS2LDhYu2D+RXPKV1jrt2HI WtV99yF3gsyHrmfu+yKWhWJY1GXqUDh9Ad3cKl2Xr8LqWxP4q/CSIT776b8ckVE3vMb0 aBV6uydHgoVMq1vZnTEijuv9iasoQf+7FXwa+K7pa/Uw5pjkFur5cj4QGQSe4e9MX061 l+BiqNBJqntgCADbnEiMlUWexk+DaZWA3HEKkEchLsAOaMTgTRIHext60RQdzhhPTKoZ yOIu2bD1Hv6uGDaHSe6Tgrx4e3q0egKbGTcyy6gxtacr6zamCH5f5q1Ov5cRS5vO3d7k 4Dmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=+O4CfC5rc+kCfcq7VX0kFhzpm+TZ5pPVw3LpPYutCro=; b=LOHKSjW+3SAS0xJ4th5R+GUr/0QUQ37W6OIUAbOaHuNxHyAoN4I0vp2HR1VVzUKaMN xh0bRIULB7khLOwo6EMPxN0SUXXWDxjjk6r18tr97FpWSDGQTfTspL8F8MeQAr6YfXg2 FDo5mVJP3OZe9CSAS2cHxGa2///E7psSjKtJ0bec4YfHTwqrw8sSYjroA3OwsW0/AxNt bqG+acfZPZTEJopni9JaWXr9UJileUiHTPqHLXDi83nx3WH+MSJShT3udOxQ6uIFTk7w HXAHU0OV76gS/R6gLbd+28hZvzxJ3l3Uox4QHq8Zbda6F/ari5WIkIebN5ZH4zxsg1Mu JHUg== X-Gm-Message-State: ALyK8tKUrd1zesjHiVlmjKIyAuePizwoMeQpDrwSJohZgAzuMpl+N8AWz2YIwLDm1NOzuQ== X-Received: by 10.28.88.206 with SMTP id m197mr4206957wmb.43.1464964643137; Fri, 03 Jun 2016 07:37:23 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id e1sm6060275wjv.9.2016.06.03.07.37.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jun 2016 07:37:22 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Subject: [PATCH v3 01/33] drm: Export drm_dev_init() for subclassing Date: Fri, 3 Jun 2016 15:36:44 +0100 Message-Id: <1464964636-3877-2-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464964636-3877-1-git-send-email-chris@chris-wilson.co.uk> References: <1464964636-3877-1-git-send-email-chris@chris-wilson.co.uk> Cc: Daniel Vetter , Dave Airlie , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In order to allow drivers to pack their privates and drm_device into one struct (e.g. for subclassing), export the initialisation routines for struct drm_device. v2: Missed return ret. That error path had only one job to do! v3: Cross-referencing drm_dev_init/drm_dev_alloc in kerneldoc, fix missed error code for goto err_minors. Signed-off-by: Chris Wilson Cc: Dave Airlie Cc: Daniel Vetter Cc: dri-devel@lists.freedesktop.org Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_drv.c | 72 +++++++++++++++++++++++++++++++++++++---------- include/drm/drmP.h | 3 ++ 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index bff89226a344..81fccc26e319 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -549,11 +549,12 @@ static void drm_fs_inode_free(struct inode *inode) } /** - * drm_dev_alloc - Allocate new DRM device - * @driver: DRM driver to allocate device for + * drm_dev_init - Initialise new DRM device + * @dev: DRM device + * @driver: DRM driver * @parent: Parent device object * - * Allocate and initialize a new DRM device. No device registration is done. + * Initialize a new DRM device. No device registration is done. * Call drm_dev_register() to advertice the device to user space and register it * with other core subsystems. This should be done last in the device * initialization sequence to make sure userspace can't access an inconsistent @@ -564,19 +565,18 @@ static void drm_fs_inode_free(struct inode *inode) * * Note that for purely virtual devices @parent can be NULL. * + * Drivers that do not want to allocate their own device struct + * embedding struct &drm_device can call drm_dev_alloc() instead. + * * RETURNS: - * Pointer to new DRM device, or NULL if out of memory. + * 0 on success, or error code on failure. */ -struct drm_device *drm_dev_alloc(struct drm_driver *driver, - struct device *parent) +int drm_dev_init(struct drm_device *dev, + struct drm_driver *driver, + struct device *parent) { - struct drm_device *dev; int ret; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (!dev) - return NULL; - kref_init(&dev->ref); dev->dev = parent; dev->driver = driver; @@ -619,7 +619,8 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, if (ret) goto err_minors; - if (drm_ht_create(&dev->map_hash, 12)) + ret = drm_ht_create(&dev->map_hash, 12); + if (ret) goto err_minors; drm_legacy_ctxbitmap_init(dev); @@ -638,7 +639,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, goto err_setunique; } - return dev; + return 0; err_setunique: if (drm_core_check_feature(dev, DRIVER_GEM)) @@ -653,8 +654,49 @@ err_minors: drm_fs_inode_free(dev->anon_inode); err_free: mutex_destroy(&dev->master_mutex); - kfree(dev); - return NULL; + return ret; +} +EXPORT_SYMBOL(drm_dev_init); + +/** + * drm_dev_alloc - Allocate new DRM device + * @driver: DRM driver to allocate device for + * @parent: Parent device object + * + * Allocate and initialize a new DRM device. No device registration is done. + * Call drm_dev_register() to advertice the device to user space and register it + * with other core subsystems. This should be done last in the device + * initialization sequence to make sure userspace can't access an inconsistent + * state. + * + * The initial ref-count of the object is 1. Use drm_dev_ref() and + * drm_dev_unref() to take and drop further ref-counts. + * + * Note that for purely virtual devices @parent can be NULL. + * + * Drivers that wish to subclass or embed struct &drm_device into their + * own struct should look at using drm_dev_init() instead. + * + * RETURNS: + * Pointer to new DRM device, or NULL if out of memory. + */ +struct drm_device *drm_dev_alloc(struct drm_driver *driver, + struct device *parent) +{ + struct drm_device *dev; + int ret; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) + return NULL; + + ret = drm_dev_init(dev, driver, parent); + if (ret) { + kfree(dev); + return NULL; + } + + return dev; } EXPORT_SYMBOL(drm_dev_alloc); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 9e5eefd6f733..c49fddb0708c 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1076,6 +1076,9 @@ extern void drm_sysfs_hotplug_event(struct drm_device *dev); struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct device *parent); +int drm_dev_init(struct drm_device *dev, + struct drm_driver *driver, + struct device *parent); void drm_dev_ref(struct drm_device *dev); void drm_dev_unref(struct drm_device *dev); int drm_dev_register(struct drm_device *dev, unsigned long flags);