From patchwork Thu Aug 8 13:44:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11084193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F215614DB for ; Thu, 8 Aug 2019 13:44:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E174320881 for ; Thu, 8 Aug 2019 13:44:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D40CB28849; Thu, 8 Aug 2019 13:44:35 +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 9176920881 for ; Thu, 8 Aug 2019 13:44:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1643C6E853; Thu, 8 Aug 2019 13:44:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id E384D6E84A for ; Thu, 8 Aug 2019 13:44:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B01E30EE12B; Thu, 8 Aug 2019 13:44:23 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-144.ams2.redhat.com [10.36.116.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2720D10016E9; Thu, 8 Aug 2019 13:44:23 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 276F19D20; Thu, 8 Aug 2019 15:44:19 +0200 (CEST) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 05/17] drm: add mmap() to drm_gem_object_funcs Date: Thu, 8 Aug 2019 15:44:05 +0200 Message-Id: <20190808134417.10610-6-kraxel@redhat.com> In-Reply-To: <20190808134417.10610-1-kraxel@redhat.com> References: <20190808134417.10610-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 08 Aug 2019 13:44:23 +0000 (UTC) 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: Maxime Ripard , open list , David Airlie , Gerd Hoffmann , tzimmermann@suse.de, Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drm_gem_object_funcs->vm_ops alone can't handle everything mmap() needs. Add a new callback for it. Signed-off-by: Gerd Hoffmann Signed-off-by: Gerd Hoffmann --- include/drm/drm_gem.h | 9 +++++++++ drivers/gpu/drm/drm_gem.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index ae693c0666cd..ee3c4ad742c6 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -150,6 +150,15 @@ struct drm_gem_object_funcs { */ void (*vunmap)(struct drm_gem_object *obj, void *vaddr); + /** + * @mmap: + * + * Called by drm_gem_mmap() for additional checks/setup. + * + * This callback is optional. + */ + int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma); + /** * @vm_ops: * diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index afc38cece3f5..84db8de217e1 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1105,6 +1105,8 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, vma->vm_ops = obj->funcs->vm_ops; else if (dev->driver->gem_vm_ops) vma->vm_ops = dev->driver->gem_vm_ops; + else if (obj->funcs && obj->funcs->mmap) + /* obj->funcs->mmap must set vma->vm_ops */; else return -EINVAL; @@ -1192,6 +1194,10 @@ int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) ret = drm_gem_mmap_obj(obj, drm_vma_node_size(node) << PAGE_SHIFT, vma); + if (ret == 0) + if (obj->funcs->mmap) + ret = obj->funcs->mmap(obj, vma); + drm_gem_object_put_unlocked(obj); return ret;