From patchwork Wed Oct 10 14:46:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 12110 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 51DAB24189 for ; Wed, 10 Oct 2012 14:47:55 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 0CFB9A18890 for ; Wed, 10 Oct 2012 14:47:54 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so989139iej.11 for ; Wed, 10 Oct 2012 07:47:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=3ty4p66+Eky1XYEr2UYRT68cH+9QlNYH7osg21pTXHo=; b=LhmaAe+M6jt33CttrXqt6me4f2MQPK8Tsi3DOIQEev/qm+fI6mupupLSIQnYYgteVa J6HV6D40iX9A9Kil7kcEpltnRqJbxGc5eFSf98kx73G3B05F86MyRUDAamgtKc8CyEy7 fL0rjZPVQEt8KcYrRjtYg71jjN+oQ8ZzOQJnQt+cFTfV5sbLIzVeGX6sepEqB0TbKY/U drvDFkbRSyw+szAwV/5i9prdpw57cD6OuEM1Ly8mj9bhTStuSG8/5zwejnKlQZKBAod1 rg/07dZpbn8rQE/ZILC8HpJoO/GLRxTAty42dAK2ji2qwS5g0XtpeXUa5heuHgLSfOqQ YEcA== Received: by 10.50.87.134 with SMTP id ay6mr5427502igb.70.1349880474759; Wed, 10 Oct 2012 07:47:54 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp235411igt; Wed, 10 Oct 2012 07:47:53 -0700 (PDT) Received: by 10.204.8.141 with SMTP id h13mr8031425bkh.54.1349880472717; Wed, 10 Oct 2012 07:47:52 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id hu13si2799344bkc.52.2012.10.10.07.47.51; Wed, 10 Oct 2012 07:47:52 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxZe-0000Zx-EN; Wed, 10 Oct 2012 14:47:50 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxZc-0000Zs-Ug for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 14:47:49 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO0034SMFJRZQ0@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:47:47 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-25-50758a93b486 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 0A.09.03783.39A85705; Wed, 10 Oct 2012 23:47:47 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MBO002YDME0EC70@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:47:47 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Wed, 10 Oct 2012 16:46:20 +0200 Message-id: <1349880405-26049-2-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> References: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jAd3JXaUBBm2nVCy+XHnI5MDocfvf Y+YAxigum5TUnMyy1CJ9uwSujA/P1zEW/FevaJjxgq2B8bh8FyMnh4SAicSzpmWsELaYxIV7 69m6GLk4hAQWMUp8WjeZHcJZyyTxZspNJpAqNqCOY0s+M4LYIgIOEqfvzmIGKWIWuMYs8X36 Z2aQhLCAlcTZa/1A3RwcLAKqEldWOIKEeQU8JDYt/AG1TV7i6f0+NhCbU8BT4sK86WCtQkA1 /9dvZprAyLuAkWEVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRrDXn0ntYFzZYHGIUYCDUYmH NyOqJECINbGsuDL3EKMEB7OSCK+pT2mAEG9KYmVValF+fFFpTmrxIUZpDhYlcd5mj5QAIYH0 xJLU7NTUgtQimCwTB6dUA2OfwN3DdXUev7aH/6tVO/eQhV/t1NqLq6N7jHUvl29gCfnc88vB oZxjyb5Jn37cuOLzc7r3PQ0l7l9HPx5k19uwWTiiok96/jEpwxLxv05dB15KH8sVePvI4f7v FwnLZIuWBXNOm5ApcGjdp3i3xQ9zFFOl3j5iXfD9VuTyeY1zZojrhGxiK85TYinOSDTUYi4q TgQAKS9hq/YBAAA= Cc: k.debski@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, sumit.semwal@ti.com, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, airlied@redhat.com, remi@remlab.net Subject: [Linaro-mm-sig] [PATCHv10 01/26] v4l: Add DMABUF as a memory type X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQmA3dMmXKQQrapkAK/uVQBQ85lY/erElLdGXZSELmqkGJ1IAuOIbRZK2y4dSnv6qaf9nOHe From: Sumit Semwal Adds DMABUF memory type to v4l framework. Also adds the related file descriptor in v4l2_plane and v4l2_buffer. Signed-off-by: Tomasz Stanislawski [original work in the PoC for buffer sharing] Signed-off-by: Sumit Semwal Signed-off-by: Sumit Semwal Acked-by: Laurent Pinchart Acked-by: Hans Verkuil --- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 18 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/linux/videodev2.h | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index 83ffb64..cc5998b 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -297,6 +297,7 @@ struct v4l2_plane32 { union { __u32 mem_offset; compat_long_t userptr; + __s32 fd; } m; __u32 data_offset; __u32 reserved[11]; @@ -318,6 +319,7 @@ struct v4l2_buffer32 { __u32 offset; compat_long_t userptr; compat_caddr_t planes; + __s32 fd; } m; __u32 length; __u32 reserved2; @@ -341,6 +343,9 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32, up_pln = compat_ptr(p); if (put_user((unsigned long)up_pln, &up->m.userptr)) return -EFAULT; + } else if (memory == V4L2_MEMORY_DMABUF) { + if (copy_in_user(&up->m.fd, &up32->m.fd, sizeof(int))) + return -EFAULT; } else { if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset, sizeof(__u32))) @@ -364,6 +369,11 @@ static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32, if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset, sizeof(__u32))) return -EFAULT; + /* For DMABUF, driver might've set up the fd, so copy it back. */ + if (memory == V4L2_MEMORY_DMABUF) + if (copy_in_user(&up32->m.fd, &up->m.fd, + sizeof(int))) + return -EFAULT; return 0; } @@ -446,6 +456,10 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user if (get_user(kp->m.offset, &up->m.offset)) return -EFAULT; break; + case V4L2_MEMORY_DMABUF: + if (get_user(kp->m.fd, &up->m.fd)) + return -EFAULT; + break; } } @@ -510,6 +524,10 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user if (put_user(kp->m.offset, &up->m.offset)) return -EFAULT; break; + case V4L2_MEMORY_DMABUF: + if (put_user(kp->m.fd, &up->m.fd)) + return -EFAULT; + break; } } diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 8f388ff..530a67e 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -155,6 +155,7 @@ static const char *v4l2_memory_names[] = { [V4L2_MEMORY_MMAP] = "mmap", [V4L2_MEMORY_USERPTR] = "userptr", [V4L2_MEMORY_OVERLAY] = "overlay", + [V4L2_MEMORY_DMABUF] = "dmabuf", }; #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown") diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index 873adbe..07bc5d6 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -188,6 +188,7 @@ enum v4l2_memory { V4L2_MEMORY_MMAP = 1, V4L2_MEMORY_USERPTR = 2, V4L2_MEMORY_OVERLAY = 3, + V4L2_MEMORY_DMABUF = 4, }; /* see also http://vektor.theorem.ca/graphics/ycbcr/ */ @@ -604,6 +605,8 @@ struct v4l2_requestbuffers { * should be passed to mmap() called on the video node) * @userptr: when memory is V4L2_MEMORY_USERPTR, a userspace pointer * pointing to this plane + * @fd: when memory is V4L2_MEMORY_DMABUF, a userspace file + * descriptor associated with this plane * @data_offset: offset in the plane to the start of data; usually 0, * unless there is a header in front of the data * @@ -618,6 +621,7 @@ struct v4l2_plane { union { __u32 mem_offset; unsigned long userptr; + __s32 fd; } m; __u32 data_offset; __u32 reserved[11]; @@ -642,6 +646,8 @@ struct v4l2_plane { * (or a "cookie" that should be passed to mmap() as offset) * @userptr: for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR; * a userspace pointer pointing to this buffer + * @fd: for non-multiplanar buffers with memory == V4L2_MEMORY_DMABUF; + * a userspace file descriptor associated with this buffer * @planes: for multiplanar buffers; userspace pointer to the array of plane * info structs for this buffer * @length: size in bytes of the buffer (NOT its payload) for single-plane @@ -668,6 +674,7 @@ struct v4l2_buffer { __u32 offset; unsigned long userptr; struct v4l2_plane *planes; + __s32 fd; } m; __u32 length; __u32 reserved2;