From patchwork Tue May 13 15:30:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 4168921 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CD783BFF02 for ; Tue, 13 May 2014 15:32:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECBCA20373 for ; Tue, 13 May 2014 15:32:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id F1C9720353 for ; Tue, 13 May 2014 15:32:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 482566EB0F; Tue, 13 May 2014 08:32:55 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ee0-f43.google.com (mail-ee0-f43.google.com [74.125.83.43]) by gabe.freedesktop.org (Postfix) with ESMTP id DEC316EB16 for ; Tue, 13 May 2014 08:32:53 -0700 (PDT) Received: by mail-ee0-f43.google.com with SMTP id d17so552298eek.2 for ; Tue, 13 May 2014 08:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eoO+dn96gmksV+ZBxY+G0HwwhdFjqmCFI5maObJDUwk=; b=Jo6DqlXBufbM/SBmJk54dkVIuduJ0o6WKwHXyNxkvPb10zvj0jJO6AXHhOSqooQ5wW a9s06PMfsx9AtLe/YanYFWqaRfI4WPUiOmv4E5wqgr7SDeqV+NqoXkzER/k7teBJlNI2 ANCHg58DxjIaCB+8TFbto3dV3tzzmswoxNBus5wfLiJF7jWrs3t3N4QPkiVfVu6UYROg c5JSwf4TozkxJPMSntHf2jDeVCjuQmNfvE//cnD35pj7S6HXIGsL22J3xbWlp9WmxUfI mcfe/hfYDKYupKWOVGcJXgmRwa53G2QyLko9VYNsyLmmk8xYDysidfsndX3+3qUrsCpm BKCA== X-Received: by 10.14.110.2 with SMTP id t2mr4080836eeg.108.1399995172741; Tue, 13 May 2014 08:32:52 -0700 (PDT) Received: from localhost (port-31899.pppoe.wtnet.de. [46.59.175.115]) by mx.google.com with ESMTPSA id w9sm18834474eev.4.2014.05.13.08.32.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 May 2014 08:32:51 -0700 (PDT) From: Thierry Reding To: Greg Kroah-Hartman , Russell King , dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/7] drm: Introduce drm_set_unique() Date: Tue, 13 May 2014 17:30:44 +0200 Message-Id: <1399995050-28435-2-git-send-email-thierry.reding@gmail.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1399995050-28435-1-git-send-email-thierry.reding@gmail.com> References: <1399995050-28435-1-git-send-email-thierry.reding@gmail.com> Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 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-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding Add a helper function that allows drivers to statically set the unique name of the device. This will allow platform and USB drivers to get rid of their DRM bus implementations and directly use drm_dev_alloc() and drm_dev_register(). Reviewed-by: Daniel Vetter Signed-off-by: Thierry Reding Reviewed-by: David Herrmann --- Changes in v2: - move drm_set_unique() to drivers/gpu/drm/drm_stub.c - add kernel-doc drivers/gpu/drm/drm_ioctl.c | 23 +++++++++++++++++------ drivers/gpu/drm/drm_stub.c | 24 ++++++++++++++++++++++++ include/drm/drmP.h | 3 +++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 38269d5aa333..a59f6c2d7586 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -131,13 +131,24 @@ static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv) if (master->unique != NULL) drm_unset_busid(dev, master); - ret = dev->driver->bus->set_busid(dev, master); - if (ret) - goto err; + if (dev->driver->bus && dev->driver->bus->set_busid) { + ret = dev->driver->bus->set_busid(dev, master); + if (ret) { + drm_unset_busid(dev, master); + return ret; + } + } else { + WARN(dev->unique == NULL, + "No drm_bus.set_busid() implementation provided by %ps. " + "Set the unique name explicitly using drm_set_unique().", + dev->driver); + + master->unique = kstrdup(dev->unique, GFP_KERNEL); + if (master->unique) + master->unique_len = strlen(dev->unique); + } + return 0; -err: - drm_unset_busid(dev, master); - return ret; } /** diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c index 1447b0ee3676..64cf97dc4ce4 100644 --- a/drivers/gpu/drm/drm_stub.c +++ b/drivers/gpu/drm/drm_stub.c @@ -535,6 +535,29 @@ static void drm_fs_inode_free(struct inode *inode) } /** + * drm_set_unique - Set the unique name of a DRM device + * @dev: device of which to set the unique name + * @fmt: format string for unique name + * + * Sets the unique name of a DRM device using the specified format string and + * a variable list of arguments. Drivers can use this at driver probe time if + * the unique name of the devices they drive is static. + */ +int drm_set_unique(struct drm_device *dev, const char *fmt, ...) +{ + va_list ap; + + kfree(dev->unique); + + va_start(ap, fmt); + dev->unique = kvasprintf(GFP_KERNEL, fmt, ap); + va_end(ap); + + return dev->unique ? 0 : -ENOMEM; +} +EXPORT_SYMBOL(drm_set_unique); + +/** * drm_dev_alloc - Allocate new drm device * @driver: DRM driver to allocate device for * @parent: Parent device object @@ -649,6 +672,7 @@ static void drm_dev_release(struct kref *ref) drm_minor_free(dev, DRM_MINOR_CONTROL); mutex_destroy(&dev->master_mutex); + kfree(dev->unique); kfree(dev); } diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 6b4ed9e84e6f..dcec96b1154c 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1235,6 +1235,8 @@ struct drm_device { struct drm_vma_offset_manager *vma_offset_manager; /*@} */ int switch_power_state; + + char *unique; }; #define DRM_SWITCH_POWER_ON 0 @@ -1680,6 +1682,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map) #include +int drm_set_unique(struct drm_device *dev, const char *fmt, ...); struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct device *parent); void drm_dev_ref(struct drm_device *dev);