From patchwork Mon Oct 3 11:27:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Abriou X-Patchwork-Id: 9360481 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 9E9BE607D6 for ; Mon, 3 Oct 2016 11:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90B9828917 for ; Mon, 3 Oct 2016 11:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 849D72891F; Mon, 3 Oct 2016 11:27:41 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7700A28917 for ; Mon, 3 Oct 2016 11:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752796AbcJCL1j (ORCPT ); Mon, 3 Oct 2016 07:27:39 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:64765 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752200AbcJCL1i (ORCPT ); Mon, 3 Oct 2016 07:27:38 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by m0046037.ppops.net (8.16.0.11/8.16.0.11) with SMTP id u93BOOWr015139; Mon, 3 Oct 2016 13:27:36 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 25t2ws244m-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 03 Oct 2016 13:27:36 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4BB4731; Mon, 3 Oct 2016 11:27:35 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 30A3225D8; Mon, 3 Oct 2016 11:27:35 +0000 (GMT) Received: from localhost (10.201.23.35) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 3 Oct 2016 13:27:34 +0200 From: Vincent Abriou To: CC: Benjamin Gaignard , Hugues Fruchet , Jean-Christophe Trotin , Vincent Abriou Subject: [media] uvcvideo: support for contiguous DMA buffers Date: Mon, 3 Oct 2016 13:27:16 +0200 Message-ID: <1475494036-18208-1-git-send-email-vincent.abriou@st.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.201.23.35] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-10-03_07:, , signatures=0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow uvcvideo compatible devices to allocate their output buffers using contiguous DMA buffers. Add the "allocators" module parameter option to let uvcvideo use the dma-contig instead of vmalloc. Signed-off-by: Vincent Abriou --- Documentation/media/v4l-drivers/uvcvideo.rst | 12 ++++++++++++ drivers/media/usb/uvc/Kconfig | 2 ++ drivers/media/usb/uvc/uvc_driver.c | 3 ++- drivers/media/usb/uvc/uvc_queue.c | 23 ++++++++++++++++++++--- drivers/media/usb/uvc/uvcvideo.h | 4 ++-- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Documentation/media/v4l-drivers/uvcvideo.rst b/Documentation/media/v4l-drivers/uvcvideo.rst index d68b3d5..786cff5 100644 --- a/Documentation/media/v4l-drivers/uvcvideo.rst +++ b/Documentation/media/v4l-drivers/uvcvideo.rst @@ -7,6 +7,18 @@ driver-specific ioctls and implementation notes. Questions and remarks can be sent to the Linux UVC development mailing list at linux-uvc-devel@lists.berlios.de. +Configuring the driver +---------------------- + +The driver is configurable using the following module option: + +- allocators: + + memory allocator selection, default is 0. It specifies the way buffers + will be allocated. + + - 0: vmalloc + - 1: dma-contig Extension Unit (XU) support --------------------------- diff --git a/drivers/media/usb/uvc/Kconfig b/drivers/media/usb/uvc/Kconfig index 6ed85efa..71e4d7e 100644 --- a/drivers/media/usb/uvc/Kconfig +++ b/drivers/media/usb/uvc/Kconfig @@ -1,7 +1,9 @@ config USB_VIDEO_CLASS tristate "USB Video Class (UVC)" depends on VIDEO_V4L2 + depends on HAS_DMA select VIDEOBUF2_VMALLOC + select VIDEOBUF2_DMA_CONTIG ---help--- Support for the USB Video Class (UVC). Currently only video input devices, such as webcams, are supported. diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 302e284..1c20aa0 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1757,7 +1757,8 @@ static int uvc_register_video(struct uvc_device *dev, int ret; /* Initialize the video buffers queue. */ - ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param); + ret = uvc_queue_init(dev, &stream->queue, stream->type, + !uvc_no_drop_param); if (ret) return ret; diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c index 77edd20..5eab146 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "uvcvideo.h" @@ -37,6 +38,12 @@ * the driver. */ +static unsigned int allocators; +module_param(allocators, uint, 0444); +MODULE_PARM_DESC(allocators, " memory allocator selection, default is 0.\n" + "\t\t 0 == vmalloc\n" + "\t\t 1 == dma-contig"); + static inline struct uvc_streaming * uvc_queue_to_stream(struct uvc_video_queue *queue) { @@ -188,20 +195,30 @@ static const struct vb2_ops uvc_queue_qops = { .stop_streaming = uvc_stop_streaming, }; -int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, - int drop_corrupted) +int uvc_queue_init(struct uvc_device *dev, struct uvc_video_queue *queue, + enum v4l2_buf_type type, int drop_corrupted) { int ret; + static const struct vb2_mem_ops * const uvc_mem_ops[2] = { + &vb2_vmalloc_memops, + &vb2_dma_contig_memops, + }; + + if (allocators == 1) + dma_coerce_mask_and_coherent(dev->vdev.dev, DMA_BIT_MASK(32)); + else if (allocators >= ARRAY_SIZE(uvc_mem_ops)) + allocators = 0; queue->queue.type = type; queue->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; queue->queue.drv_priv = queue; queue->queue.buf_struct_size = sizeof(struct uvc_buffer); queue->queue.ops = &uvc_queue_qops; - queue->queue.mem_ops = &vb2_vmalloc_memops; + queue->queue.mem_ops = uvc_mem_ops[allocators]; queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC | V4L2_BUF_FLAG_TSTAMP_SRC_SOE; queue->queue.lock = &queue->mutex; + queue->queue.dev = dev->vdev.dev; ret = vb2_queue_init(&queue->queue); if (ret) return ret; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 7e4d3ee..330ba64 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -632,8 +632,8 @@ extern struct uvc_driver uvc_driver; extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id); /* Video buffers queue management. */ -extern int uvc_queue_init(struct uvc_video_queue *queue, - enum v4l2_buf_type type, int drop_corrupted); +extern int uvc_queue_init(struct uvc_device *dev, struct uvc_video_queue *queue, + enum v4l2_buf_type type, int drop_corrupted); extern void uvc_queue_release(struct uvc_video_queue *queue); extern int uvc_request_buffers(struct uvc_video_queue *queue, struct v4l2_requestbuffers *rb);