Fwd: [PATCH v2] media: uvc_driver: add NO-MMU arch support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---------- Forwarded message ----------
From: Bob Liu <lliubbo@xxxxxxxxx>
Date: Fri, Apr 8, 2011 at 7:16 PM
Subject: [PATCH v2] media: uvc_driver: add NO-MMU arch support
To: linux-kernel@xxxxxxxxxxxxxxx
Cc: mchehab@xxxxxxxxxx, hverkuil@xxxxxxxxx,
laurent.pinchart@xxxxxxxxxxxxxxxx,
sakari.ailus@xxxxxxxxxxxxxxxxxxxxxxxxxx, martin_rubli@xxxxxxxxxxxx,
jarod@xxxxxxxxxx, tj@xxxxxxxxxx, arnd@xxxxxxxx, fweisbec@xxxxxxxxx,
agust@xxxxxxx, gregkh@xxxxxxx, Bob Liu <lliubbo@xxxxxxxxx>


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@xxxxxxxxx>
---
Âdrivers/media/video/uvc/uvc_queue.c | Â 47 +++++++++++++++++++++++++++++++++++
Âdrivers/media/video/uvc/uvc_v4l2.c Â| Â 13 +++++++++
Âdrivers/media/video/uvc/uvcvideo.h Â| Â Â6 ++++
Âdrivers/media/video/v4l2-dev.c   Â|  18 +++++++++++++
Âinclude/media/v4l2-dev.h      Â|  Â2 +
Â5 files changed, 86 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/uvc/uvc_queue.c
b/drivers/media/video/uvc/uvc_queue.c
index f14581b..e505afe 100644
--- a/drivers/media/video/uvc/uvc_queue.c
+++ b/drivers/media/video/uvc/uvc_queue.c
@@ -424,6 +424,7 @@ int 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;
@@ -445,6 +446,20 @@ int 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;
@@ -489,6 +504,38 @@ done:
Â}

Â/*
+ * Get unmapped area.
+ *
+ * NO-MMU arch need this function to make mmap() work correctly.
+ */
+unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
+ Â Â Â Â Â Â Â unsigned long addr, unsigned long len, unsigned long pgoff)
+{
+ Â Â Â struct uvc_buffer *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;
+}
+
+/*
Â* Enable or disable the video buffers queue.
Â*
Â* The queue must be enabled before starting video acquisition and must be
diff --git a/drivers/media/video/uvc/uvc_v4l2.c
b/drivers/media/video/uvc/uvc_v4l2.c
index 9005a8d..9efab61 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -1081,6 +1081,18 @@ static unsigned int uvc_v4l2_poll(struct file
*file, poll_table *wait)
   Âreturn uvc_queue_poll(&stream->queue, file, wait);
Â}

+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 = file->private_data;
+ Â Â Â struct uvc_streaming *stream = handle->stream;
+
+ Â Â Â uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_get_unmapped_area\n");
+
+ Â Â Â return uvc_queue_get_unmapped_area(&stream->queue, addr, len, pgoff);
+}
+
Âconst struct v4l2_file_operations uvc_fops = {
   Â.owner     Â= THIS_MODULE,
   Â.open      = uvc_v4l2_open,
@@ -1089,5 +1101,6 @@ const struct v4l2_file_operations uvc_fops = {
   Â.read      = uvc_v4l2_read,
   Â.mmap      = uvc_v4l2_mmap,
   Â.poll      = uvc_v4l2_poll,
+ Â Â Â .get_unmapped_area = uvc_v4l2_get_unmapped_area,
Â};

diff --git a/drivers/media/video/uvc/uvcvideo.h
b/drivers/media/video/uvc/uvcvideo.h
index 45f01e7..48a2378 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -580,6 +580,12 @@ extern int uvc_queue_mmap(struct uvc_video_queue *queue,
       Âstruct vm_area_struct *vma);
Âextern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
       Âstruct file *file, poll_table *wait);
+#ifdef CONFIG_MMU
+#define uvc_queue_get_unmapped_area NULL
+#else
+extern unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
+ Â Â Â Â Â Â Â unsigned long addr, unsigned long len, unsigned long pgoff);
+#endif
Âextern int uvc_queue_allocated(struct uvc_video_queue *queue);
Âstatic inline int uvc_queue_streaming(struct uvc_video_queue *queue)
Â{
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 498e674..221e73f 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -368,6 +368,23 @@ static int v4l2_mmap(struct file *filp, struct
vm_area_struct *vm)
   Âreturn ret;
Â}

+#ifdef CONFIG_MMU
+#define v4l2_get_unmapped_area NULL
+#else
+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)
Â{
@@ -452,6 +469,7 @@ static const struct file_operations v4l2_fops = {
   Â.write = v4l2_write,
   Â.open = v4l2_open,
   Â.mmap = v4l2_mmap,
+ Â Â Â .get_unmapped_area = v4l2_get_unmapped_area,
   Â.unlocked_ioctl = v4l2_ioctl,
Â#ifdef CONFIG_COMPAT
   Â.compat_ioctl = v4l2_compat_ioctl32,
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 8266d5a..0616a43 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -63,6 +63,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




-- 
Regards,
--Bob
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux