From patchwork Fri May 25 13:42:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 10427441 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 F38AD6025B for ; Fri, 25 May 2018 13:43:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA3BD2968A for ; Fri, 25 May 2018 13:43:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCB36296A6; Fri, 25 May 2018 13:43:00 +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=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 43A6C2968A for ; Fri, 25 May 2018 13:42:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B2966E1CA; Fri, 25 May 2018 13:42:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 88AD86E1D0 for ; Fri, 25 May 2018 13:42:57 +0000 (UTC) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7] helo=dude.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1fMCzf-0007AB-CM; Fri, 25 May 2018 15:42:55 +0200 From: Lucas Stach To: Tomi Valkeinen Subject: [PATCH 1/2] drm: split out buffer lookup from fake VMA offset Date: Fri, 25 May 2018 15:42:53 +0200 Message-Id: <20180525134254.30686-1-l.stach@pengutronix.de> X-Mailer: git-send-email 2.17.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Boulnois , dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Drivers that want to implement mmap handling different to what drm_gem_mmap provides need a way to look up the GEM BO from the fake VMA offset. Split this out to make it reusable. Signed-off-by: Lucas Stach --- drivers/gpu/drm/drm_gem.c | 56 +++++++++++++++++++++++++++------------ include/drm/drm_gem.h | 2 ++ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 4975ba9a7bc8..f476bc45266f 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -979,30 +979,21 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, EXPORT_SYMBOL(drm_gem_mmap_obj); /** - * drm_gem_mmap - memory map routine for GEM objects + * drm_gem_bo_vm_lookup - look up a GEM object based on its offset in the DRM VM * @filp: DRM file pointer - * @vma: VMA for the area to be mapped - * - * If a driver supports GEM object mapping, mmap calls on the DRM file - * descriptor will end up here. + * @vma: VMA containing the mmap offset of the buffer * * Look up the GEM object based on the offset passed in (vma->vm_pgoff will * contain the fake offset we created when the GTT map ioctl was called on - * the object) and map it with a call to drm_gem_mmap_obj(). - * - * If the caller is not granted access to the buffer object, the mmap will fail - * with EACCES. Please see the vma manager for more information. + * the object). */ -int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) +struct drm_gem_object * +drm_gem_bo_vm_lookup(struct file *filp, struct vm_area_struct *vma) { struct drm_file *priv = filp->private_data; struct drm_device *dev = priv->minor->dev; - struct drm_gem_object *obj = NULL; struct drm_vma_offset_node *node; - int ret; - - if (drm_dev_is_unplugged(dev)) - return -ENODEV; + struct drm_gem_object *obj = NULL; drm_vma_offset_lock_lookup(dev->vma_offset_manager); node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, @@ -1025,15 +1016,46 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) } drm_vma_offset_unlock_lookup(dev->vma_offset_manager); + return obj; +} +EXPORT_SYMBOL(drm_gem_bo_vm_lookup); + +/** + * drm_gem_mmap - memory map routine for GEM objects + * @filp: DRM file pointer + * @vma: VMA for the area to be mapped + * + * If a driver supports GEM object mapping, mmap calls on the DRM file + * descriptor will end up here. + * + * Look up the GEM object based on the offset passed in (vma->vm_pgoff will + * contain the fake offset we created when the GTT map ioctl was called on + * the object) and map it with a call to drm_gem_mmap_obj(). + * + * If the caller is not granted access to the buffer object, the mmap will fail + * with EACCES. Please see the vma manager for more information. + */ +int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct drm_file *priv = filp->private_data; + struct drm_device *dev = priv->minor->dev; + struct drm_gem_object *obj = NULL; + int ret; + + if (drm_dev_is_unplugged(dev)) + return -ENODEV; + + obj = drm_gem_bo_vm_lookup(filp, vma); if (!obj) return -EINVAL; - if (!drm_vma_node_is_allowed(node, priv)) { + if (!drm_vma_node_is_allowed(&obj->vma_node, priv)) { drm_gem_object_put_unlocked(obj); return -EACCES; } - ret = drm_gem_mmap_obj(obj, drm_vma_node_size(node) << PAGE_SHIFT, + ret = drm_gem_mmap_obj(obj, + drm_vma_node_size(&obj->vma_node) << PAGE_SHIFT, vma); drm_gem_object_put_unlocked(obj); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 3583b98a1718..ae3eccc9f8cb 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -182,6 +182,8 @@ void drm_gem_private_object_init(struct drm_device *dev, struct drm_gem_object *obj, size_t size); void drm_gem_vm_open(struct vm_area_struct *vma); void drm_gem_vm_close(struct vm_area_struct *vma); +struct drm_gem_object * +drm_gem_bo_vm_lookup(struct file *filp, struct vm_area_struct *vma); int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, struct vm_area_struct *vma); int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);