From patchwork Thu Jun 19 12:34:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ander Conselvan de Oliveira X-Patchwork-Id: 4382861 Return-Path: X-Original-To: patchwork-intel-gfx@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 AB66ABEEAA for ; Thu, 19 Jun 2014 12:35:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D1DE320386 for ; Thu, 19 Jun 2014 12:35:23 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id ED37920384 for ; Thu, 19 Jun 2014 12:35:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9D4656E89B; Thu, 19 Jun 2014 05:35:22 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-la0-f52.google.com (mail-la0-f52.google.com [209.85.215.52]) by gabe.freedesktop.org (Postfix) with ESMTP id D0DBC6E89B for ; Thu, 19 Jun 2014 05:35:20 -0700 (PDT) Received: by mail-la0-f52.google.com with SMTP id ty20so1388542lab.25 for ; Thu, 19 Jun 2014 05:35:19 -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; bh=YW1mdNgc8Nm173EepKQJMK0Koasoo4kc7/RnZXExH9E=; b=niTO3D36ehytBhbmUB7JvSFBfBSJ4vi+PHPlHEiV3oEyGeLU0T89OZuIZ0jO3rje5I NlEpmY/5+BV46qzhUnOs17zlXfOt300mt5AiVqwh9BCEnkSpLL47WoxLn0KGe121ckMg PclpHf5FI5jbpHGSiX0vCKe5mylKrIYk9amc6Pe4DFPoz8w/UmAUvgF5k8JVrZuqDpJO oc+oAx0uXtmzQQqhXz896AytF7ACpfcMq+As4B+kfV0nB049o1uj9dTeU2T1GQZpxcgw iZSdttWfLvMZt41lXkmKOb0tWt3CvkdJfQgR8YWZ5WrHSefoENdcQK/ELtWdozJWp3lV v6WA== X-Received: by 10.112.16.40 with SMTP id c8mr2955592lbd.17.1403181319339; Thu, 19 Jun 2014 05:35:19 -0700 (PDT) Received: from localhost.localdomain ([194.136.86.45]) by mx.google.com with ESMTPSA id f9sm2149535lae.16.2014.06.19.05.35.18 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Jun 2014 05:35:18 -0700 (PDT) From: Ander Conselvan de Oliveira To: intel-gfx@lists.freedesktop.org Date: Thu, 19 Jun 2014 15:34:34 +0300 Message-Id: <1403181274-7167-1-git-send-email-conselvan2@gmail.com> X-Mailer: git-send-email 1.8.3.2 Cc: Ander Conselvan de Oliveira Subject: [Intel-gfx] [PATCH v3] drm/i915: Implement dma-buf mmap() for userspace access X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 From: Rob Bradford The aim is that this is functionally equivalent to using the I915_GEM_MMAP ioctl. v2: Add aperture check limit, limit to SNB+ and improve error handling. v3 (anderco): Map without using the GTT. Signed-off-by: Rob Bradford Signed-off-by: Ander Conselvan de Oliveira --- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c index 580aa42..2d31fca 100644 --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c @@ -193,7 +193,24 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma) { - return -EINVAL; + struct drm_i915_gem_object *obj = dma_buf_to_obj(dma_buf); + struct drm_device *dev = obj->base.dev; + struct drm_i915_private *dev_priv = dev->dev_private; + int ret; + + if (INTEL_INFO(dev)->gen < 6) + return -EINVAL; + + ret = i915_mutex_lock_interruptible(dev); + if (ret) + return ret; + + ret = obj->base.filp->f_op->mmap(obj->base.filp, vma); + fput(vma->vm_file); + vma->vm_file = get_file(obj->base.filp); + + mutex_unlock(&dev->struct_mutex); + return ret; } static int i915_gem_begin_cpu_access(struct dma_buf *dma_buf, size_t start, size_t length, enum dma_data_direction direction)