From patchwork Fri May 27 14:00:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9138435 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 A1EA36075C for ; Fri, 27 May 2016 14:01:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AB7C280A3 for ; Fri, 27 May 2016 14:01:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79AF92793B; Fri, 27 May 2016 14:01:12 +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=unavailable 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 1FF6E2793B for ; Fri, 27 May 2016 14:01:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EED666E1F5; Fri, 27 May 2016 14:01:07 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 490E36E1C6; Fri, 27 May 2016 14:00:52 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id e3so15175779wme.2; Fri, 27 May 2016 07:00:52 -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=/mGf/9k8pHVoQw0mhM2ABKs2yg6V0788Qjy8fR0oAK4=; b=YgUcG9zbWHRHDZJYYbSWwMqtLbOB7nKqp0TCurKWZVST77T1bY3jtTmsBBY2zSUXCv ugjT0ucbN3qIQrZ7sYasEaR5doVgn1q1WZhHcZWXQdaIpQxMacTLSz53a2ZJfGYMSv27 T2YTSam1U0LjsJOzPT+er3Jg3yqrD278IQiWdcTS39228trhF3LoVb90vOi2t0Ji9Kzc p6IkwfWvlwOpKJ0XTmgjtIxpQ8jZwb8Bml/2mYIvQOq7+r0K5b5An2GLjO4hGJels5oM /kxdEqVOlB5MeCUr4/QwXG4ftLlkB52liSeJ8vSow7ClmqhQx/07IRe4gJ+7pX6Ryp1+ OD0w== 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=/mGf/9k8pHVoQw0mhM2ABKs2yg6V0788Qjy8fR0oAK4=; b=L/55fpu+phdS/MInf+IYOUY2JAOfoKnmbTnp1GL/RDn9A3YKO30kdZNKsvKPObod8w rK14iA/WxMSMUPve1YBKqOyGVO1duo/QEeFkxrxpBzNNq2pC9zaFP6PyFfCFXjpvRDc5 HDLb1SVgmHPHr9meeacfl6lW4w9OOWEvbW3xSXQ76noGM5Dic9MdT1SpWkUB15XLfjtJ u96gyhsV7/kck9NnL2jnjKfWCIZUFRIWhkaOO2Oonzb72a9xXFvDHM0BQUHKChz7VxuY VOtCihdWESbQhAjLPdelyTC5hqW328usDElAWjFfPAiWndiFElw5ulydyHSwCYFpw2nI N7eg== X-Gm-Message-State: ALyK8tLFFfp4Jil1loCspxwubk56h9kq5FKSSSuMAXS0w2ESGp0fw4X+u+tXusS1PoAMXg== X-Received: by 10.28.44.87 with SMTP id s84mr9045486wms.61.1464357650449; Fri, 27 May 2016 07:00:50 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id e8sm19607200wjm.23.2016.05.27.07.00.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 May 2016 07:00:49 -0700 (PDT) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Fri, 27 May 2016 15:00:34 +0100 Message-Id: <1464357644-16775-2-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464357644-16775-1-git-send-email-chris@chris-wilson.co.uk> References: <1464357644-16775-1-git-send-email-chris@chris-wilson.co.uk> Cc: Daniel Vetter , dri-devel@lists.freedesktop.org Subject: [Intel-gfx] [PATCH 01/11] drm: Export drm_dev_init() for subclassing X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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. Signed-off-by: Chris Wilson Cc: Daniel Vetter Cc: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/drm_drv.c | 63 ++++++++++++++++++++++++++++++++++++----------- include/drm/drmP.h | 3 +++ 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index bff89226a344..ceb85e611a07 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 @@ -565,18 +566,14 @@ static void drm_fs_inode_free(struct inode *inode) * Note that for purely virtual devices @parent can be NULL. * * 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; @@ -638,7 +635,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 +650,46 @@ err_minors: drm_fs_inode_free(dev->anon_inode); err_free: mutex_destroy(&dev->master_mutex); - kfree(dev); - return NULL; + return 0; +} +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. + * + * 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 c5d29505f937..12dc5f9cad89 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1075,6 +1075,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);