Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2587540imb; Mon, 4 Mar 2019 08:50:14 -0800 (PST) X-Google-Smtp-Source: APXvYqwg2EwYmsndKH7Q765E7uyEc6bAFWr0YiqL6WDKZWo83WMx/5ckv7G5t56Ay8ELGO84tBFT X-Received: by 2002:a65:5788:: with SMTP id b8mr18770779pgr.8.1551718214854; Mon, 04 Mar 2019 08:50:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551718214; cv=none; d=google.com; s=arc-20160816; b=IQSLLivRRVZLDNFDrpxRREv5PbU1oEQMfo+gdVLAgbGt5UsRM/R0AoxUnTuYv5IWDA jCDzSPJqhXUFENag3QjxufdrtguQw6bFh7y05Sy0qc46lYQO5CxzP2kallWEf4VxHOyN dAh72JUUgV7lER9Mm47Wm+xhsav7UxA2M6IStkweHn6cYvOuPEpwrx93QV5se6WQJR6X CpKdOk1OLoZUpuYdE4FSsJX8sQjyG3Yg2t6qVHljrBcxH4gfX1bXDOpgSQ9qwbgC5TV2 3v65cmcs2xEXGXEzFeA98kElENMpklT21aCnz3wXoj6tFxwdQAwRnJsyQJU59j9zUj6h Bohg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:reply-to:from:references :cc:to:subject:dkim-signature; bh=S3s1gTx+k7mL7bGE9C0Hv8WzvqnFfVHmuC2lO/HHCiM=; b=1GVBl/ZxDuRvnoVDnC8L6uoUhomlmdqYmbkE70tQdC+yO7vhlgs2uiQf9k7CHvB0Nt HnCaFGrBCSkBtG4rDKp4MW5/NR0pstyvk5JcIRrKzBeHDC6Lnxf+NQ9jw6yzOLsbVb9a bBitll4XVMPZEbuQCWw2QXOkRkDR73puJEHnSOEAly6jzlxMj2chOgilogNIivTIrbbM Fu2xycdMlRePHkuLI2YpoHVdDpxnb5Qw25xmWy3S81xv86WdhlNGfGC8UhvQ4bWY9WX/ pTprgxXIE2u4q1UIOrRsYDHiwET+n/Eic0DQPl7qqDZWTm0uN1J78g06yE97kBPD4drn 3WfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Av0lHtKM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 38si5404367pgn.121.2019.03.04.08.49.59; Mon, 04 Mar 2019 08:50:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Av0lHtKM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727070AbfCDPgk (ORCPT + 99 others); Mon, 4 Mar 2019 10:36:40 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:39028 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726961AbfCDPgj (ORCPT ); Mon, 4 Mar 2019 10:36:39 -0500 Received: from [192.168.0.21] (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6829E2F2; Mon, 4 Mar 2019 16:36:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551713795; bh=xUWbT4Qmu0Dz6YrBofQiqIpXMu5xOmyGpupeEb2OTME=; h=Subject:To:Cc:References:From:Reply-To:Date:In-Reply-To:From; b=Av0lHtKMCLIelqeUymIAjIBK074etxSZD06n50fwoze3rH22xBW+2luhSoYA6qbxe PXWe+qL7Kg1Q7tiugoJ6QIvs5Xv3/dGxw+kPAD4BkSoS3EdIk/gR3vuU9lQwc6whbL gitk6vZAISw4B5RWCOzMAqERtVxPOnXpwy6rvFWg= Subject: Re: [PATCH] media: uvcvideo: Read support To: Hugues Fruchet , Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org References: <1551702925-7739-1-git-send-email-hugues.fruchet@st.com> <1551702925-7739-2-git-send-email-hugues.fruchet@st.com> From: Kieran Bingham Reply-To: kieran.bingham@ideasonboard.com Openpgp: preference=signencrypt Autocrypt: addr=kieran.bingham@ideasonboard.com; keydata= mQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat V/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC rRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C potzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ cSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf Kr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8 RXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko lPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq 8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/PSB6XgQcOdhtd36 Oe9X9dXB8Y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R3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU RCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA JxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q sbsRB8KNNvVXBOVNwko86rQqF9drZuw= Organization: Ideas on Board Message-ID: <8ec96fe6-96af-c101-ff20-ab59d953ad6a@ideasonboard.com> Date: Mon, 4 Mar 2019 15:36:32 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1551702925-7739-2-git-send-email-hugues.fruchet@st.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hughes, On 04/03/2019 12:35, Hugues Fruchet wrote: > Add support of read() call from userspace by implementing > uvc_v4l2_read() with vb2_read() helper. Just thinking out loud, This opens up UVC devices to read raw full frame images through this interface as well. Due to the UVC protocol, there is /already/ a full memcpy to get these images out of the URB packets, so using a read() interface would be another full frame copy. I can perhaps see the usecase for reading compressed data through this interface - but full frames don't seem appropriate. (not impossible of course, just is it reasonable?) If this is to be enabled, should it be enabled for compressed formats only? or would that complicate matters? -- Regards Kieran > Signed-off-by: Hugues Fruchet > --- > drivers/media/usb/uvc/uvc_queue.c | 15 ++++++++++++++- > drivers/media/usb/uvc/uvc_v4l2.c | 11 ++++++++--- > drivers/media/usb/uvc/uvcvideo.h | 2 ++ > 3 files changed, 24 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c > index 682698e..0c8a0a8 100644 > --- a/drivers/media/usb/uvc/uvc_queue.c > +++ b/drivers/media/usb/uvc/uvc_queue.c > @@ -227,7 +227,7 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, > int ret; > > queue->queue.type = type; > - queue->queue.io_modes = VB2_MMAP | VB2_USERPTR; > + queue->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; > queue->queue.drv_priv = queue; > queue->queue.buf_struct_size = sizeof(struct uvc_buffer); > queue->queue.mem_ops = &vb2_vmalloc_memops; > @@ -361,6 +361,19 @@ int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type) > return ret; > } > > +ssize_t uvc_queue_read(struct uvc_video_queue *queue, struct file *file, > + char __user *buf, size_t count, loff_t *ppos) > +{ > + ssize_t ret; > + > + mutex_lock(&queue->mutex); > + ret = vb2_read(&queue->queue, buf, count, ppos, > + file->f_flags & O_NONBLOCK); > + mutex_unlock(&queue->mutex); > + > + return ret; > +} > + > int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) > { > return vb2_mmap(&queue->queue, vma); > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c > index 84be596..3866832 100644 > --- a/drivers/media/usb/uvc/uvc_v4l2.c > +++ b/drivers/media/usb/uvc/uvc_v4l2.c > @@ -594,7 +594,8 @@ static int uvc_ioctl_querycap(struct file *file, void *fh, > strscpy(cap->driver, "uvcvideo", sizeof(cap->driver)); > strscpy(cap->card, vdev->name, sizeof(cap->card)); > usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info)); > - cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING > + cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING | > + V4L2_CAP_READWRITE > | chain->caps; > > return 0; > @@ -1434,8 +1435,12 @@ static long uvc_v4l2_compat_ioctl32(struct file *file, > static ssize_t uvc_v4l2_read(struct file *file, char __user *data, > size_t count, loff_t *ppos) > { > - uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n"); > - return -EINVAL; > + struct uvc_fh *handle = file->private_data; > + struct uvc_streaming *stream = handle->stream; > + > + uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read\n"); > + > + return uvc_queue_read(&stream->queue, file, data, count, ppos); > } > > static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h > index c7c1baa..5d0515c 100644 > --- a/drivers/media/usb/uvc/uvcvideo.h > +++ b/drivers/media/usb/uvc/uvcvideo.h > @@ -766,6 +766,8 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, > struct uvc_buffer *buf); > struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue); > void uvc_queue_buffer_release(struct uvc_buffer *buf); > +ssize_t uvc_queue_read(struct uvc_video_queue *queue, struct file *file, > + char __user *buf, size_t count, loff_t *ppos); > int uvc_queue_mmap(struct uvc_video_queue *queue, > struct vm_area_struct *vma); > __poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, > -- Regards -- Kieran