From patchwork Wed Jan 8 18:31:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lespiau, Damien" X-Patchwork-Id: 3455201 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 713F59F1C4 for ; Wed, 8 Jan 2014 18:32:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 615D720145 for ; Wed, 8 Jan 2014 18:32:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id A5E1620109 for ; Wed, 8 Jan 2014 18:32:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 23273FB325; Wed, 8 Jan 2014 10:32:17 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id 5168FFB327; Wed, 8 Jan 2014 10:32:11 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 08 Jan 2014 10:28:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,625,1384329600"; d="scan'208";a="435872331" Received: from unknown (HELO strange.amr.corp.intel.com) ([10.255.15.235]) by orsmga001.jf.intel.com with ESMTP; 08 Jan 2014 10:32:08 -0800 From: Damien Lespiau To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm: Add support for subclassing struct drm_device Date: Wed, 8 Jan 2014 18:31:51 +0000 Message-Id: <1389205912-16632-5-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1389205912-16632-1-git-send-email-damien.lespiau@intel.com> References: <1389205912-16632-1-git-send-email-damien.lespiau@intel.com> Cc: intel-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 Currently, drivers are expected to allocate private data and attach it to dev_private in struct drm_device. This has the unfortunate property to require driver code to juggle between the pointer to struct drm_device and dev->dev_private instead of using the same pointer if they could embed the device structure. This patch enables drivers to declare the size of the device structure they want DRM core to create for them. Signed-off-by: Damien Lespiau --- drivers/gpu/drm/drm_stub.c | 8 +++++++- include/drm/drmP.h | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c index 98a33c580..161dd9a 100644 --- a/drivers/gpu/drm/drm_stub.c +++ b/drivers/gpu/drm/drm_stub.c @@ -433,8 +433,14 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, { struct drm_device *dev; int ret; + size_t device_struct_size; - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (driver->device_struct_size) + device_struct_size = driver->device_struct_size; + else + device_struct_size = sizeof(*dev); + + dev = kzalloc(device_struct_size, GFP_KERNEL); if (!dev) return NULL; diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 6800c20..219b153 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -996,6 +996,14 @@ struct drm_driver { u32 driver_features; /* size of the private data attached to a struct drm_buf */ int buf_priv_size; + /* + * DRM drivers can subclass struct drm_device to have their own device + * structure to store private data. In this case, they need to declare + * the size of the child structure (ie the structure embedding a struct + * drm_device as first field) for the DRM core to allocate a big + * enough device structure. + */ + size_t device_struct_size; const struct drm_ioctl_desc *ioctls; int num_ioctls; const struct file_operations *fops;