From patchwork Wed Dec 19 04:41:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Airlie X-Patchwork-Id: 1894451 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 2820B3FC64 for ; Wed, 19 Dec 2012 04:52:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 26368E6449 for ; Tue, 18 Dec 2012 20:52:05 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from ipmail06.adl6.internode.on.net (ipmail06.adl6.internode.on.net [150.101.137.145]) by gabe.freedesktop.org (Postfix) with ESMTP id B31DDE5F2F for ; Tue, 18 Dec 2012 20:48:24 -0800 (PST) Received: from ppp118-208-134-74.lns20.bne1.internode.on.net (HELO optimus.redhat.com) ([118.208.134.74]) by ipmail06.adl6.internode.on.net with ESMTP; 19 Dec 2012 15:18:17 +1030 From: Dave Airlie To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm/gem: start adding support for per-file object mmaps Date: Wed, 19 Dec 2012 14:41:59 +1000 Message-Id: <1355892119-13926-4-git-send-email-airlied@gmail.com> X-Mailer: git-send-email 1.8.0.2 In-Reply-To: <1355892119-13926-1-git-send-email-airlied@gmail.com> References: <1355892119-13926-1-git-send-email-airlied@gmail.com> 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+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org From: Dave Airlie This adds the support for drivers that use the gem mmap call, they need to specify DRIVER_GEM_MMAP in their feature set, so they get this behaviour. This saves me adding 10 open/close handlers for now, if someone would like to do that instead of midlayer, then I'd be happy to watch. TODO: all other non-i915 drivers. Signed-off-by: Dave Airlie --- drivers/gpu/drm/drm_gem.c | 17 +++++++++++++++++ drivers/gpu/drm/i915/i915_drv.c | 2 +- include/drm/drmP.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index bb5ac23..dbbd736 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -240,6 +240,8 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle) drm_gem_remove_prime_handles(obj, filp); + if (drm_core_check_feature(dev, DRIVER_GEM_MMAP)) + drm_vma_offset_node_remove_file(&obj->vma_offset, filp->filp); if (dev->driver->gem_close_object) dev->driver->gem_close_object(obj, filp); drm_gem_object_handle_unreference_unlocked(obj); @@ -280,9 +282,19 @@ again: drm_gem_object_handle_reference(obj); + if (drm_core_check_feature(dev, DRIVER_GEM_MMAP)) { + ret = drm_vma_offset_node_add_file(&obj->vma_offset, + file_priv->filp); + if (ret) { + drm_gem_handle_delete(file_priv, *handlep); + return ret; + } + } if (dev->driver->gem_open_object) { ret = dev->driver->gem_open_object(obj, file_priv); if (ret) { + if (drm_core_check_feature(dev, DRIVER_GEM_MMAP)) + drm_vma_offset_node_remove_file(&obj->vma_offset, file_priv->filp); drm_gem_handle_delete(file_priv, *handlep); return ret; } @@ -633,6 +645,11 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) return drm_mmap(filp, vma); } + if (drm_vma_offset_node_valid_file(offset_node, filp) == false) { + ret = -EINVAL; + goto out_unlock; + } + obj = container_of(offset_node, struct drm_gem_object, vma_offset); /* Check for valid size. */ diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 530db83..a42cb8f 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -1017,7 +1017,7 @@ static struct drm_driver driver = { */ .driver_features = DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/ - DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME, + DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME | DRIVER_GEM_MMAP, .load = i915_driver_load, .unload = i915_driver_unload, .open = i915_driver_open, diff --git a/include/drm/drmP.h b/include/drm/drmP.h index f7186e8..b6bce07 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -155,6 +155,7 @@ int drm_err(const char *func, const char *format, ...); #define DRIVER_GEM 0x1000 #define DRIVER_MODESET 0x2000 #define DRIVER_PRIME 0x4000 +#define DRIVER_GEM_MMAP 0x8000 #define DRIVER_BUS_PCI 0x1 #define DRIVER_BUS_PLATFORM 0x2