mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: uvc_driver: add NO-MMU arch support
@ 2011-03-10  2:44 Bob Liu
  2011-03-10 11:03 ` Laurent Pinchart
  0 siblings, 1 reply; 2+ messages in thread
From: Bob Liu @ 2011-03-10  2:44 UTC (permalink / raw)
  To: linux-kernel
  Cc: mchehab, hverkuil, laurent.pinchart, sakari.ailus, martin_rubli,
	jarod, tj, arnd, fweisbec, agust, gregkh, vapier.adi,
	uclinux-dist-devel, Bob Liu

UVC driver used to have partial no-mmu arch support, but it's removed by
commit c29fcff3daafbf46d64a543c1950bbd206ad8c1c.

This patch added them back and expanded to fully support no-mmu arch, so that
uvc cameras can be used on no-mmu platforms like Blackfin.

Signed-off-by: Bob Liu <lliubbo@gmail.com>
---
 drivers/media/video/uvc/uvc_v4l2.c |   36 ++++++++++++++++++++++++++++++++++++
 drivers/media/video/v4l2-dev.c     |   18 ++++++++++++++++++
 drivers/usb/gadget/uvc_queue.c     |   15 +++++++++++++++
 include/media/v4l2-dev.h           |    2 ++
 4 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 9005a8d..2413ec9 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -1081,6 +1081,39 @@ static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
 	return uvc_queue_poll(&stream->queue, file, wait);
 }
 
+#ifndef CONFIG_MMU
+static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
+		unsigned long addr, unsigned long len, unsigned long pgoff,
+		unsigned long flags)
+{
+	struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
+	struct uvc_streaming *stream = handle->stream;
+	struct uvc_video_queue *queue = &stream->queue;
+	struct uvc_buffer *uninitialized_var(buffer);
+	unsigned int i;
+	int ret = 0;
+
+	mutex_lock(&queue->mutex);
+	for (i = 0; i < queue->count; ++i) {
+		buffer = &queue->buffer[i];
+		if ((buffer->buf.m.offset >> PAGE_SHIFT) == pgoff)
+			break;
+	}
+
+	if (i == queue->count ||
+		PAGE_ALIGN(len) != queue->buf_size) {
+		ret = -EINVAL;
+		goto done;
+	}
+
+	addr = (unsigned long)queue->mem + buffer->buf.m.offset;
+	ret = addr;
+done:
+	mutex_unlock(&queue->mutex);
+	return ret;
+}
+#endif
+
 const struct v4l2_file_operations uvc_fops = {
 	.owner		= THIS_MODULE,
 	.open		= uvc_v4l2_open,
@@ -1089,5 +1122,8 @@ const struct v4l2_file_operations uvc_fops = {
 	.read		= uvc_v4l2_read,
 	.mmap		= uvc_v4l2_mmap,
 	.poll		= uvc_v4l2_poll,
+#ifndef CONFIG_MMU
+	.get_unmapped_area = uvc_v4l2_get_unmapped_area,
+#endif
 };
 
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 341764a..bdcf413 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -299,6 +299,21 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
 	return ret;
 }
 
+#ifndef CONFIG_MMU
+static unsigned long v4l2_get_unmapped_area(struct file *filp,
+		unsigned long addr, unsigned long len, unsigned long pgoff,
+		unsigned long flags)
+{
+	struct video_device *vdev = video_devdata(filp);
+
+	if (!vdev->fops->get_unmapped_area)
+		return -ENOSYS;
+	if (!video_is_registered(vdev))
+		return -ENODEV;
+	return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
+}
+#endif
+
 /* Override for the open function */
 static int v4l2_open(struct inode *inode, struct file *filp)
 {
@@ -362,6 +377,9 @@ static const struct file_operations v4l2_fops = {
 	.write = v4l2_write,
 	.open = v4l2_open,
 	.mmap = v4l2_mmap,
+#ifndef CONFIG_MMU
+	.get_unmapped_area = v4l2_get_unmapped_area,
+#endif
 	.unlocked_ioctl = v4l2_ioctl,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = v4l2_compat_ioctl32,
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c
index f7395ac..24378fb 100644
--- a/drivers/usb/gadget/uvc_queue.c
+++ b/drivers/usb/gadget/uvc_queue.c
@@ -431,6 +431,7 @@ uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma)
 			break;
 	}
 
+#ifdef CONFIG_MMU
 	if (i == queue->count || size != queue->buf_size) {
 		ret = -EINVAL;
 		goto done;
@@ -452,6 +453,20 @@ uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma)
 		addr += PAGE_SIZE;
 		size -= PAGE_SIZE;
 	}
+#else
+	if (i == queue->count ||
+		PAGE_ALIGN(size) != queue->buf_size) {
+		ret = -EINVAL;
+		goto done;
+	}
+
+	/* documentation/nommu-mmap.txt */
+	vma->vm_flags |= VM_IO | VM_MAYSHARE;
+
+	addr = (unsigned long)queue->mem + buffer->buf.m.offset;
+	vma->vm_start = addr;
+	vma->vm_end = addr +  queue->buf_size;
+#endif
 
 	vma->vm_ops = &uvc_vm_ops;
 	vma->vm_private_data = buffer;
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 15802a0..a0af49a 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -42,6 +42,8 @@ struct v4l2_file_operations {
 	long (*ioctl) (struct file *, unsigned int, unsigned long);
 	long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
 	int (*mmap) (struct file *, struct vm_area_struct *);
+	unsigned long (*get_unmapped_area) (struct file *, unsigned long,
+				unsigned long, unsigned long, unsigned long);
 	int (*open) (struct file *);
 	int (*release) (struct file *);
 };
-- 
1.6.3.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: uvc_driver: add NO-MMU arch support
  2011-03-10  2:44 [PATCH] media: uvc_driver: add NO-MMU arch support Bob Liu
@ 2011-03-10 11:03 ` Laurent Pinchart
  0 siblings, 0 replies; 2+ messages in thread
From: Laurent Pinchart @ 2011-03-10 11:03 UTC (permalink / raw)
  To: Bob Liu
  Cc: linux-kernel, mchehab, hverkuil, sakari.ailus, martin_rubli,
	jarod, tj, arnd, fweisbec, agust, gregkh, vapier.adi,
	uclinux-dist-devel

Hi Bob,

Thanks for the patch.

On Thursday 10 March 2011 03:44:37 Bob Liu wrote:
> UVC driver used to have partial no-mmu arch support, but it's removed by
> commit c29fcff3daafbf46d64a543c1950bbd206ad8c1c.
> 
> This patch added them back and expanded to fully support no-mmu arch, so
> that uvc cameras can be used on no-mmu platforms like Blackfin.
> 
> Signed-off-by: Bob Liu <lliubbo@gmail.com>
> ---
>  drivers/media/video/uvc/uvc_v4l2.c |   36
> ++++++++++++++++++++++++++++++++++++ drivers/media/video/v4l2-dev.c     | 
>  18 ++++++++++++++++++
>  drivers/usb/gadget/uvc_queue.c     |   15 +++++++++++++++
>  include/media/v4l2-dev.h           |    2 ++
>  4 files changed, 71 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/media/video/uvc/uvc_v4l2.c
> b/drivers/media/video/uvc/uvc_v4l2.c index 9005a8d..2413ec9 100644
> --- a/drivers/media/video/uvc/uvc_v4l2.c
> +++ b/drivers/media/video/uvc/uvc_v4l2.c
> @@ -1081,6 +1081,39 @@ static unsigned int uvc_v4l2_poll(struct file *file,
> poll_table *wait) return uvc_queue_poll(&stream->queue, file, wait);
>  }
> 
> +#ifndef CONFIG_MMU
> +static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
> +		unsigned long addr, unsigned long len, unsigned long pgoff,
> +		unsigned long flags)
> +{
> +	struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
> +	struct uvc_streaming *stream = handle->stream;
> +	struct uvc_video_queue *queue = &stream->queue;
> +	struct uvc_buffer *uninitialized_var(buffer);
> +	unsigned int i;
> +	int ret = 0;
> +
> +	mutex_lock(&queue->mutex);
> +	for (i = 0; i < queue->count; ++i) {
> +		buffer = &queue->buffer[i];
> +		if ((buffer->buf.m.offset >> PAGE_SHIFT) == pgoff)
> +			break;
> +	}
> +
> +	if (i == queue->count ||
> +		PAGE_ALIGN(len) != queue->buf_size) {
> +		ret = -EINVAL;
> +		goto done;
> +	}
> +
> +	addr = (unsigned long)queue->mem + buffer->buf.m.offset;
> +	ret = addr;
> +done:
> +	mutex_unlock(&queue->mutex);
> +	return ret;
> +}
> +#endif
> +

Could you move the core of this function to uvc_queue.c ? Something like

unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
	unsigned long addr, unsigned long len, unsigned long pgoff,
	unsigned long flags),

static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
		unsigned long addr, unsigned long len, unsigned long pgoff,
		unsigned long flags)
{
	struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
	struct uvc_streaming *stream = handle->stream;

	return uvc_queue_get_unmapped_area(queue, addr, len, pgoff, flags);
}

> diff --git a/drivers/usb/gadget/uvc_queue.c
> b/drivers/usb/gadget/uvc_queue.c index f7395ac..24378fb 100644
> --- a/drivers/usb/gadget/uvc_queue.c
> +++ b/drivers/usb/gadget/uvc_queue.c
> @@ -431,6 +431,7 @@ uvc_queue_mmap(struct uvc_video_queue *queue, struct
> vm_area_struct *vma) break;
>  	}
> 
> +#ifdef CONFIG_MMU
>  	if (i == queue->count || size != queue->buf_size) {
>  		ret = -EINVAL;
>  		goto done;
> @@ -452,6 +453,20 @@ uvc_queue_mmap(struct uvc_video_queue *queue, struct
> vm_area_struct *vma) addr += PAGE_SIZE;
>  		size -= PAGE_SIZE;
>  	}
> +#else
> +	if (i == queue->count ||
> +		PAGE_ALIGN(size) != queue->buf_size) {
> +		ret = -EINVAL;
> +		goto done;
> +	}
> +
> +	/* documentation/nommu-mmap.txt */
> +	vma->vm_flags |= VM_IO | VM_MAYSHARE;
> +
> +	addr = (unsigned long)queue->mem + buffer->buf.m.offset;
> +	vma->vm_start = addr;
> +	vma->vm_end = addr +  queue->buf_size;
> +#endif
> 
>  	vma->vm_ops = &uvc_vm_ops;
>  	vma->vm_private_data = buffer;

Note that uvc_queue.c will be replaced by videobuf2 in the (near ?) future. 
NOMMU support will thus be removed once again. If you want to keep it, you 
should add a patch to videobuf2 to implement NOMMU support there.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-10 11:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-10  2:44 [PATCH] media: uvc_driver: add NO-MMU arch support Bob Liu
2011-03-10 11:03 ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®