From patchwork Mon Nov 10 17:16:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 40520 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4A3FA203C0 for ; Mon, 10 Nov 2014 17:17:22 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id e51sf5809201eek.6 for ; Mon, 10 Nov 2014 09:17:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=f/B94siLYyToxF5bmc5ltF1vsmEu43qiPpH/on2ja1s=; b=VWZNg4ETehzoiNnBTGXyveWe/b5yjT+DWVljt9ULdoMM3ED9zzl1cgxPceFFg3sCw4 Xru7UsDXUii0Ib2RWb9wmLnbKjS366A4F1lCbrJIBKbFKtoQRkQKZtEfix9rjDwnpfFP IC7UVlQGg8RksXywiwCkA6HISdnSUVP0GusDbxdwrMvyXK/f2LZB6MBcGwTQlV1eOl3L zaaKv9Y6MOopXYA24iWQBonwBPmWynRdHHPo2xenWdeGq2DPiW4hwzp6xBXXV/27WnGy rLJiJy/M4z168eTI/O7WsQtCLTQnTjxOaO6zWSSlABxLeJ47/lsaQdiPT+hoCfmjWHSx 93Mw== X-Gm-Message-State: ALoCoQnhA94+NoMXpioi4vy/MhZHOIuDk2j1gQrVCWeCELC8EC1Ol31QG/X9vA6X3mU3w/VfYLM2 X-Received: by 10.112.154.194 with SMTP id vq2mr816194lbb.10.1415639841233; Mon, 10 Nov 2014 09:17:21 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.66 with SMTP id h2ls365978laa.58.gmail; Mon, 10 Nov 2014 09:17:21 -0800 (PST) X-Received: by 10.112.162.73 with SMTP id xy9mr3569187lbb.94.1415639841045; Mon, 10 Nov 2014 09:17:21 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id wr5si28031499lac.11.2014.11.10.09.17.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 09:17:19 -0800 (PST) Received-SPF: temperror (google.com: error in processing during lookup of patch+caf_=patchwork-forward=linaro.org@linaro.org: DNS timeout) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id n15so6255074lbi.32 for ; Mon, 10 Nov 2014 09:17:19 -0800 (PST) X-Received: by 10.152.29.8 with SMTP id f8mr30829410lah.56.1415639839301; Mon, 10 Nov 2014 09:17:19 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp126867lbc; Mon, 10 Nov 2014 09:17:18 -0800 (PST) X-Received: by 10.70.129.135 with SMTP id nw7mr5976227pdb.129.1415639837662; Mon, 10 Nov 2014 09:17:17 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg3si17091174pbc.95.2014.11.10.09.17.14 for ; Mon, 10 Nov 2014 09:17:16 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753599AbaKJRRN (ORCPT + 25 others); Mon, 10 Nov 2014 12:17:13 -0500 Received: from mail-wg0-f51.google.com ([74.125.82.51]:60187 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753160AbaKJRRL (ORCPT ); Mon, 10 Nov 2014 12:17:11 -0500 Received: by mail-wg0-f51.google.com with SMTP id l18so9249484wgh.24 for ; Mon, 10 Nov 2014 09:17:05 -0800 (PST) X-Received: by 10.180.78.36 with SMTP id y4mr31878708wiw.52.1415639823380; Mon, 10 Nov 2014 09:17:03 -0800 (PST) Received: from sundance.lan ([82.33.25.158]) by mx.google.com with ESMTPSA id bf6sm23953752wjb.13.2014.11.10.09.17.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Nov 2014 09:17:02 -0800 (PST) From: Daniel Thompson To: David Airlie Cc: Daniel Thompson , dri-devel@lists.freedesktop.org, Rob Clark , Benjamin Gaignard , linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal Subject: [PATCH v3.18-rc3] drm: msm: Allow exported dma-bufs to be mapped Date: Mon, 10 Nov 2014 17:16:45 +0000 Message-Id: <1415639805-17477-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=temperror (google.com: error in processing during lookup of patch+caf_=patchwork-forward=linaro.org@linaro.org: DNS timeout) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Currently msm does not implement gem_prime_mmap. Without this it is not possible to draw onto a dma-buf from another process (making its very hard to implement the Android rendering model). Implementing this mostly just providing some boilerplate code. However in addition to providing the implementation of mmap itself we must also interfere with the flags during the export. Without this the mmap() will fail the permission checks early in the syscall handling and msm_gem_prime_mmap() will never be called. Signed-off-by: Daniel Thompson --- Notes: I've tested this both with a rather hacked about Android userspace and with a fairly small test case run from debian. Both currently use dumb buffers. Thanks to Benjamin for his help in finding this bit of code. drivers/gpu/drm/msm/msm_drv.c | 3 ++- drivers/gpu/drm/msm/msm_drv.h | 5 +++++ drivers/gpu/drm/msm/msm_gem_prime.c | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) -- 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index b67ef5985125..f0d77ee482a5 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -824,7 +824,7 @@ static struct drm_driver msm_driver = { .dumb_destroy = drm_gem_dumb_destroy, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, - .gem_prime_export = drm_gem_prime_export, + .gem_prime_export = msm_gem_prime_export, .gem_prime_import = drm_gem_prime_import, .gem_prime_pin = msm_gem_prime_pin, .gem_prime_unpin = msm_gem_prime_unpin, @@ -832,6 +832,7 @@ static struct drm_driver msm_driver = { .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, .gem_prime_vmap = msm_gem_prime_vmap, .gem_prime_vunmap = msm_gem_prime_vunmap, + .gem_prime_mmap = msm_gem_prime_mmap, #ifdef CONFIG_DEBUG_FS .debugfs_init = msm_debugfs_init, .debugfs_cleanup = msm_debugfs_cleanup, diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index 67f9d0a2332c..3a1c85f7f241 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -154,6 +154,8 @@ void msm_update_fence(struct drm_device *dev, uint32_t fence); int msm_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_file *file); +int msm_gem_mmap_obj(struct drm_gem_object *obj, + struct vm_area_struct *vma); int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma); int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf); uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj); @@ -167,9 +169,12 @@ int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args); int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev, uint32_t handle, uint64_t *offset); +struct dma_buf *msm_gem_prime_export(struct drm_device *dev, + struct drm_gem_object *obj, int flags); struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj); void *msm_gem_prime_vmap(struct drm_gem_object *obj); void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); +int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sg); int msm_gem_prime_pin(struct drm_gem_object *obj); diff --git a/drivers/gpu/drm/msm/msm_gem_prime.c b/drivers/gpu/drm/msm/msm_gem_prime.c index ad772fe36115..4e4fa5828d5d 100644 --- a/drivers/gpu/drm/msm/msm_gem_prime.c +++ b/drivers/gpu/drm/msm/msm_gem_prime.c @@ -20,6 +20,14 @@ #include +struct dma_buf *msm_gem_prime_export(struct drm_device *dev, + struct drm_gem_object *obj, int flags) +{ + /* we want to be able to write in mmapped buffer */ + flags |= O_RDWR; + return drm_gem_prime_export(dev, obj, flags); +} + struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj) { struct msm_gem_object *msm_obj = to_msm_bo(obj); @@ -37,6 +45,19 @@ void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) /* TODO msm_gem_vunmap() */ } +int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma) +{ + int ret; + + mutex_lock(&obj->dev->struct_mutex); + ret = drm_gem_mmap_obj(obj, obj->size, vma); + mutex_unlock(&obj->dev->struct_mutex); + if (ret < 0) + return ret; + + return msm_gem_mmap_obj(vma->vm_private_data, vma); +} + struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sg) {