* [PATCH 01/04] soc_camera: Move spinlocks
2008-07-05 2:53 [PATCH 00/04] soc_camera: SuperH Mobile CEU support V2 Magnus Damm
@ 2008-07-05 2:53 ` Magnus Damm
2008-07-05 4:19 ` Guennadi Liakhovetski
2008-07-05 2:53 ` [PATCH 02/04] soc_camera: Add 16-bit bus width support Magnus Damm
` (2 subsequent siblings)
3 siblings, 1 reply; 15+ messages in thread
From: Magnus Damm @ 2008-07-05 2:53 UTC (permalink / raw)
To: video4linux-list
Cc: paulius.zaleckas, linux-sh, mchehab, lethal, akpm, g.liakhovetski
This patch moves the spinlock handling from soc_camera.c to the actual
camera host driver. The spinlock alloc/free callbacks are replaced with
code in init_videobuf().
Signed-off-by: Magnus Damm <damm@igel.co.jp>
---
drivers/media/video/pxa_camera.c | 17 ++++------------
drivers/media/video/soc_camera.c | 39 --------------------------------------
include/media/soc_camera.h | 5 ----
3 files changed, 7 insertions(+), 54 deletions(-)
--- 0002/drivers/media/video/pxa_camera.c
+++ work/drivers/media/video/pxa_camera.c 2008-07-04 17:24:53.000000000 +0900
@@ -583,12 +583,15 @@ static struct videobuf_queue_ops pxa_vid
.buf_release = pxa_videobuf_release,
};
-static void pxa_camera_init_videobuf(struct videobuf_queue *q, spinlock_t *lock,
+static void pxa_camera_init_videobuf(struct videobuf_queue *q,
struct soc_camera_device *icd)
{
+ struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+ struct pxa_camera_dev *pcdev = ici->priv;
+
/* We must pass NULL as dev pointer, then all pci_* dma operations
* transform to normal dma_* ones. */
- videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, lock,
+ videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock,
V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
sizeof(struct pxa_buffer), icd);
}
@@ -994,15 +997,6 @@ static int pxa_camera_querycap(struct so
return 0;
}
-static spinlock_t *pxa_camera_spinlock_alloc(struct soc_camera_file *icf)
-{
- struct soc_camera_host *ici =
- to_soc_camera_host(icf->icd->dev.parent);
- struct pxa_camera_dev *pcdev = ici->priv;
-
- return &pcdev->lock;
-}
-
static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
.owner = THIS_MODULE,
.add = pxa_camera_add_device,
@@ -1015,7 +1009,6 @@ static struct soc_camera_host_ops pxa_so
.querycap = pxa_camera_querycap,
.try_bus_param = pxa_camera_try_bus_param,
.set_bus_param = pxa_camera_set_bus_param,
- .spinlock_alloc = pxa_camera_spinlock_alloc,
};
/* Should be allocated dynamically too, but we have only one. */
--- 0002/drivers/media/video/soc_camera.c
+++ work/drivers/media/video/soc_camera.c 2008-07-04 17:24:53.000000000 +0900
@@ -183,7 +183,6 @@ static int soc_camera_open(struct inode
struct soc_camera_device *icd;
struct soc_camera_host *ici;
struct soc_camera_file *icf;
- spinlock_t *lock;
int ret;
icf = vmalloc(sizeof(*icf));
@@ -210,13 +209,6 @@ static int soc_camera_open(struct inode
}
icf->icd = icd;
-
- icf->lock = ici->ops->spinlock_alloc(icf);
- if (!icf->lock) {
- ret = -ENOMEM;
- goto esla;
- }
-
icd->use_count++;
/* Now we really have to activate the camera */
@@ -234,17 +226,12 @@ static int soc_camera_open(struct inode
file->private_data = icf;
dev_dbg(&icd->dev, "camera device open\n");
- ici->ops->init_videobuf(&icf->vb_vidq, icf->lock, icd);
+ ici->ops->init_videobuf(&icf->vb_vidq, icd);
return 0;
/* All errors are entered with the video_lock held */
eiciadd:
- lock = icf->lock;
- icf->lock = NULL;
- if (ici->ops->spinlock_free)
- ici->ops->spinlock_free(lock);
-esla:
module_put(ici->ops->owner);
emgi:
module_put(icd->ops->owner);
@@ -260,15 +247,11 @@ static int soc_camera_close(struct inode
struct soc_camera_device *icd = icf->icd;
struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
struct video_device *vdev = icd->vdev;
- spinlock_t *lock = icf->lock;
mutex_lock(&video_lock);
icd->use_count--;
if (!icd->use_count)
ici->ops->remove(icd);
- icf->lock = NULL;
- if (ici->ops->spinlock_free)
- ici->ops->spinlock_free(lock);
module_put(icd->ops->owner);
module_put(ici->ops->owner);
mutex_unlock(&video_lock);
@@ -764,21 +747,6 @@ static void dummy_release(struct device
{
}
-static spinlock_t *spinlock_alloc(struct soc_camera_file *icf)
-{
- spinlock_t *lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
-
- if (lock)
- spin_lock_init(lock);
-
- return lock;
-}
-
-static void spinlock_free(spinlock_t *lock)
-{
- kfree(lock);
-}
-
int soc_camera_host_register(struct soc_camera_host *ici)
{
int ret;
@@ -808,11 +776,6 @@ int soc_camera_host_register(struct soc_
if (ret)
goto edevr;
- if (!ici->ops->spinlock_alloc) {
- ici->ops->spinlock_alloc = spinlock_alloc;
- ici->ops->spinlock_free = spinlock_free;
- }
-
scan_add_host(ici);
return 0;
--- 0002/include/media/soc_camera.h
+++ work/include/media/soc_camera.h 2008-07-04 18:06:00.000000000 +0900
@@ -48,7 +48,6 @@ struct soc_camera_device {
struct soc_camera_file {
struct soc_camera_device *icd;
struct videobuf_queue vb_vidq;
- spinlock_t *lock;
};
struct soc_camera_host {
@@ -67,15 +66,13 @@ struct soc_camera_host_ops {
int (*set_fmt_cap)(struct soc_camera_device *, __u32,
struct v4l2_rect *);
int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
- void (*init_videobuf)(struct videobuf_queue*, spinlock_t *,
+ void (*init_videobuf)(struct videobuf_queue *,
struct soc_camera_device *);
int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
int (*try_bus_param)(struct soc_camera_device *, __u32);
int (*set_bus_param)(struct soc_camera_device *, __u32);
unsigned int (*poll)(struct file *, poll_table *);
- spinlock_t* (*spinlock_alloc)(struct soc_camera_file *);
- void (*spinlock_free)(spinlock_t *);
};
struct soc_camera_link {
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH 01/04] soc_camera: Move spinlocks
2008-07-05 2:53 ` [PATCH 01/04] soc_camera: Move spinlocks Magnus Damm
@ 2008-07-05 4:19 ` Guennadi Liakhovetski
2008-07-05 4:24 ` Magnus Damm
0 siblings, 1 reply; 15+ messages in thread
From: Guennadi Liakhovetski @ 2008-07-05 4:19 UTC (permalink / raw)
To: Magnus Damm
Cc: video4linux-list, paulius.zaleckas, linux-sh,
Mauro Carvalho Chehab, lethal, akpm
On Sat, 5 Jul 2008, Magnus Damm wrote:
> This patch moves the spinlock handling from soc_camera.c to the actual
> camera host driver. The spinlock alloc/free callbacks are replaced with
> code in init_videobuf().
Does this mean, that you have found a possibility to port your
spinlock-removal patch on the top of the "make videobuf independent" patch
without any loss of functionality? This looks good on a first glance. I am
on a holiday now (:-)), so, I unfortunately cannot review your patches
ATM. I'll try to do this in a week, hope, this still will be in time for
the 2.6.27 merge window.
Thanks
Guennadi
>
> Signed-off-by: Magnus Damm <damm@igel.co.jp>
> ---
>
> drivers/media/video/pxa_camera.c | 17 ++++------------
> drivers/media/video/soc_camera.c | 39 --------------------------------------
> include/media/soc_camera.h | 5 ----
> 3 files changed, 7 insertions(+), 54 deletions(-)
>
> --- 0002/drivers/media/video/pxa_camera.c
> +++ work/drivers/media/video/pxa_camera.c 2008-07-04 17:24:53.000000000 +0900
> @@ -583,12 +583,15 @@ static struct videobuf_queue_ops pxa_vid
> .buf_release = pxa_videobuf_release,
> };
>
> -static void pxa_camera_init_videobuf(struct videobuf_queue *q, spinlock_t *lock,
> +static void pxa_camera_init_videobuf(struct videobuf_queue *q,
> struct soc_camera_device *icd)
> {
> + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
> + struct pxa_camera_dev *pcdev = ici->priv;
> +
> /* We must pass NULL as dev pointer, then all pci_* dma operations
> * transform to normal dma_* ones. */
> - videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, lock,
> + videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock,
> V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
> sizeof(struct pxa_buffer), icd);
> }
> @@ -994,15 +997,6 @@ static int pxa_camera_querycap(struct so
> return 0;
> }
>
> -static spinlock_t *pxa_camera_spinlock_alloc(struct soc_camera_file *icf)
> -{
> - struct soc_camera_host *ici =
> - to_soc_camera_host(icf->icd->dev.parent);
> - struct pxa_camera_dev *pcdev = ici->priv;
> -
> - return &pcdev->lock;
> -}
> -
> static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
> .owner = THIS_MODULE,
> .add = pxa_camera_add_device,
> @@ -1015,7 +1009,6 @@ static struct soc_camera_host_ops pxa_so
> .querycap = pxa_camera_querycap,
> .try_bus_param = pxa_camera_try_bus_param,
> .set_bus_param = pxa_camera_set_bus_param,
> - .spinlock_alloc = pxa_camera_spinlock_alloc,
> };
>
> /* Should be allocated dynamically too, but we have only one. */
> --- 0002/drivers/media/video/soc_camera.c
> +++ work/drivers/media/video/soc_camera.c 2008-07-04 17:24:53.000000000 +0900
> @@ -183,7 +183,6 @@ static int soc_camera_open(struct inode
> struct soc_camera_device *icd;
> struct soc_camera_host *ici;
> struct soc_camera_file *icf;
> - spinlock_t *lock;
> int ret;
>
> icf = vmalloc(sizeof(*icf));
> @@ -210,13 +209,6 @@ static int soc_camera_open(struct inode
> }
>
> icf->icd = icd;
> -
> - icf->lock = ici->ops->spinlock_alloc(icf);
> - if (!icf->lock) {
> - ret = -ENOMEM;
> - goto esla;
> - }
> -
> icd->use_count++;
>
> /* Now we really have to activate the camera */
> @@ -234,17 +226,12 @@ static int soc_camera_open(struct inode
> file->private_data = icf;
> dev_dbg(&icd->dev, "camera device open\n");
>
> - ici->ops->init_videobuf(&icf->vb_vidq, icf->lock, icd);
> + ici->ops->init_videobuf(&icf->vb_vidq, icd);
>
> return 0;
>
> /* All errors are entered with the video_lock held */
> eiciadd:
> - lock = icf->lock;
> - icf->lock = NULL;
> - if (ici->ops->spinlock_free)
> - ici->ops->spinlock_free(lock);
> -esla:
> module_put(ici->ops->owner);
> emgi:
> module_put(icd->ops->owner);
> @@ -260,15 +247,11 @@ static int soc_camera_close(struct inode
> struct soc_camera_device *icd = icf->icd;
> struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
> struct video_device *vdev = icd->vdev;
> - spinlock_t *lock = icf->lock;
>
> mutex_lock(&video_lock);
> icd->use_count--;
> if (!icd->use_count)
> ici->ops->remove(icd);
> - icf->lock = NULL;
> - if (ici->ops->spinlock_free)
> - ici->ops->spinlock_free(lock);
> module_put(icd->ops->owner);
> module_put(ici->ops->owner);
> mutex_unlock(&video_lock);
> @@ -764,21 +747,6 @@ static void dummy_release(struct device
> {
> }
>
> -static spinlock_t *spinlock_alloc(struct soc_camera_file *icf)
> -{
> - spinlock_t *lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
> -
> - if (lock)
> - spin_lock_init(lock);
> -
> - return lock;
> -}
> -
> -static void spinlock_free(spinlock_t *lock)
> -{
> - kfree(lock);
> -}
> -
> int soc_camera_host_register(struct soc_camera_host *ici)
> {
> int ret;
> @@ -808,11 +776,6 @@ int soc_camera_host_register(struct soc_
> if (ret)
> goto edevr;
>
> - if (!ici->ops->spinlock_alloc) {
> - ici->ops->spinlock_alloc = spinlock_alloc;
> - ici->ops->spinlock_free = spinlock_free;
> - }
> -
> scan_add_host(ici);
>
> return 0;
> --- 0002/include/media/soc_camera.h
> +++ work/include/media/soc_camera.h 2008-07-04 18:06:00.000000000 +0900
> @@ -48,7 +48,6 @@ struct soc_camera_device {
> struct soc_camera_file {
> struct soc_camera_device *icd;
> struct videobuf_queue vb_vidq;
> - spinlock_t *lock;
> };
>
> struct soc_camera_host {
> @@ -67,15 +66,13 @@ struct soc_camera_host_ops {
> int (*set_fmt_cap)(struct soc_camera_device *, __u32,
> struct v4l2_rect *);
> int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
> - void (*init_videobuf)(struct videobuf_queue*, spinlock_t *,
> + void (*init_videobuf)(struct videobuf_queue *,
> struct soc_camera_device *);
> int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
> int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
> int (*try_bus_param)(struct soc_camera_device *, __u32);
> int (*set_bus_param)(struct soc_camera_device *, __u32);
> unsigned int (*poll)(struct file *, poll_table *);
> - spinlock_t* (*spinlock_alloc)(struct soc_camera_file *);
> - void (*spinlock_free)(spinlock_t *);
> };
>
> struct soc_camera_link {
>
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH 01/04] soc_camera: Move spinlocks
2008-07-05 4:19 ` Guennadi Liakhovetski
@ 2008-07-05 4:24 ` Magnus Damm
0 siblings, 0 replies; 15+ messages in thread
From: Magnus Damm @ 2008-07-05 4:24 UTC (permalink / raw)
To: Guennadi Liakhovetski
Cc: video4linux-list, paulius.zaleckas, linux-sh,
Mauro Carvalho Chehab, lethal, akpm
On Sat, Jul 5, 2008 at 1:19 PM, Guennadi Liakhovetski
<g.liakhovetski@gmx.de> wrote:
> On Sat, 5 Jul 2008, Magnus Damm wrote:
>
>> This patch moves the spinlock handling from soc_camera.c to the actual
>> camera host driver. The spinlock alloc/free callbacks are replaced with
>> code in init_videobuf().
>
> Does this mean, that you have found a possibility to port your
> spinlock-removal patch on the top of the "make videobuf independent" patch
> without any loss of functionality? This looks good on a first glance. I am
> on a holiday now (:-)), so, I unfortunately cannot review your patches
> ATM. I'll try to do this in a week, hope, this still will be in time for
> the 2.6.27 merge window.
Yes, you are correct. It was much easier than I expected. Have a good holiday!
/ magnus
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 02/04] soc_camera: Add 16-bit bus width support
2008-07-05 2:53 [PATCH 00/04] soc_camera: SuperH Mobile CEU support V2 Magnus Damm
2008-07-05 2:53 ` [PATCH 01/04] soc_camera: Move spinlocks Magnus Damm
@ 2008-07-05 2:53 ` Magnus Damm
2008-07-05 2:54 ` [PATCH 03/04] videobuf: Add physically contiguous queue code V2 Magnus Damm
2008-07-05 2:54 ` [PATCH 04/04] sh_mobile_ceu_camera: Add SuperH Mobile CEU driver V2 Magnus Damm
3 siblings, 0 replies; 15+ messages in thread
From: Magnus Damm @ 2008-07-05 2:53 UTC (permalink / raw)
To: video4linux-list
Cc: paulius.zaleckas, linux-sh, mchehab, lethal, akpm, g.liakhovetski
The SuperH Mobile CEU hardware supports 16-bit width bus,
so extend the soc_camera code with SOCAM_DATAWIDTH_16.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
---
include/media/soc_camera.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--- 0008/include/media/soc_camera.h
+++ work/include/media/soc_camera.h 2008-07-01 14:38:34.000000000 +0900
@@ -153,11 +153,12 @@ static inline struct v4l2_queryctrl cons
#define SOCAM_DATAWIDTH_8 (1 << 6)
#define SOCAM_DATAWIDTH_9 (1 << 7)
#define SOCAM_DATAWIDTH_10 (1 << 8)
-#define SOCAM_PCLK_SAMPLE_RISING (1 << 9)
-#define SOCAM_PCLK_SAMPLE_FALLING (1 << 10)
+#define SOCAM_DATAWIDTH_16 (1 << 9)
+#define SOCAM_PCLK_SAMPLE_RISING (1 << 10)
+#define SOCAM_PCLK_SAMPLE_FALLING (1 << 11)
#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
- SOCAM_DATAWIDTH_10)
+ SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_16)
static inline unsigned long soc_camera_bus_param_compatible(
unsigned long camera_flags, unsigned long bus_flags)
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-05 2:53 [PATCH 00/04] soc_camera: SuperH Mobile CEU support V2 Magnus Damm
2008-07-05 2:53 ` [PATCH 01/04] soc_camera: Move spinlocks Magnus Damm
2008-07-05 2:53 ` [PATCH 02/04] soc_camera: Add 16-bit bus width support Magnus Damm
@ 2008-07-05 2:54 ` Magnus Damm
2008-07-08 14:33 ` Paulius Zaleckas
2008-07-11 13:38 ` Karicheri, Muralidharan
2008-07-05 2:54 ` [PATCH 04/04] sh_mobile_ceu_camera: Add SuperH Mobile CEU driver V2 Magnus Damm
3 siblings, 2 replies; 15+ messages in thread
From: Magnus Damm @ 2008-07-05 2:54 UTC (permalink / raw)
To: video4linux-list
Cc: paulius.zaleckas, linux-sh, mchehab, lethal, akpm, g.liakhovetski
This is V2 of the physically contiguous videobuf queues patch.
Useful for hardware such as the SuperH Mobile CEU which doesn't
support scatter gatter bus mastering.
Since it may be difficult to allocate large chunks of physically
contiguous memory after some uptime due to fragmentation, this code
allocates memory using dma_alloc_coherent(). Architectures supporting
dma_declare_coherent_memory() can easily avoid fragmentation issues
by using dma_declare_coherent_memory() to force dma_alloc_coherent()
to allocate from a certain pre-allocated memory area.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
---
Changes since V1:
- use dev_err() instead of pr_err()
- remember size in struct videobuf_dma_contig_memory
- keep struct videobuf_dma_contig_memory in .c file
- let videobuf_to_dma_contig() return dma_addr_t
- implement __videobuf_sync()
- return statements, white space and other minor fixes
drivers/media/video/Kconfig | 5
drivers/media/video/Makefile | 1
drivers/media/video/videobuf-dma-contig.c | 417 +++++++++++++++++++++++++++++
include/media/videobuf-dma-contig.h | 32 ++
4 files changed, 455 insertions(+)
--- 0002/drivers/media/video/Kconfig
+++ work/drivers/media/video/Kconfig 2008-07-05 09:47:22.000000000 +0900
@@ -24,6 +24,11 @@ config VIDEOBUF_VMALLOC
select VIDEOBUF_GEN
tristate
+config VIDEOBUF_DMA_CONTIG
+ depends on HAS_DMA
+ select VIDEOBUF_GEN
+ tristate
+
config VIDEOBUF_DVB
tristate
select VIDEOBUF_GEN
--- 0001/drivers/media/video/Makefile
+++ work/drivers/media/video/Makefile 2008-07-05 09:47:22.000000000 +0900
@@ -88,6 +88,7 @@ obj-$(CONFIG_VIDEO_TUNER) += tuner.o
obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
+obj-$(CONFIG_VIDEOBUF_DMA_CONTIG) += videobuf-dma-contig.o
obj-$(CONFIG_VIDEOBUF_VMALLOC) += videobuf-vmalloc.o
obj-$(CONFIG_VIDEOBUF_DVB) += videobuf-dvb.o
obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o
--- /dev/null
+++ work/drivers/media/video/videobuf-dma-contig.c 2008-07-05 10:09:12.000000000 +0900
@@ -0,0 +1,417 @@
+/*
+ * helper functions for physically contiguous capture buffers
+ *
+ * The functions support hardware lacking scatter gatter support
+ * (i.e. the buffers must be linear in physical memory)
+ *
+ * Copyright (c) 2008 Magnus Damm
+ *
+ * Based on videobuf-vmalloc.c,
+ * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/dma-mapping.h>
+#include <media/videobuf-dma-contig.h>
+
+struct videobuf_dma_contig_memory {
+ u32 magic;
+ void *vaddr;
+ dma_addr_t dma_handle;
+ unsigned long size;
+};
+
+#define MAGIC_DC_MEM 0x0733ac61
+#define MAGIC_CHECK(is, should) \
+ if (unlikely((is) != (should))) { \
+ pr_err("magic mismatch: %x expected %x\n", is, should); \
+ BUG(); \
+ }
+
+static void
+videobuf_vm_open(struct vm_area_struct *vma)
+{
+ struct videobuf_mapping *map = vma->vm_private_data;
+
+ dev_dbg(map->q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n",
+ map, map->count, vma->vm_start, vma->vm_end);
+
+ map->count++;
+}
+
+static void videobuf_vm_close(struct vm_area_struct *vma)
+{
+ struct videobuf_mapping *map = vma->vm_private_data;
+ struct videobuf_queue *q = map->q;
+ int i;
+
+ dev_dbg(map->q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
+ map, map->count, vma->vm_start, vma->vm_end);
+
+ map->count--;
+ if (0 == map->count) {
+ struct videobuf_dma_contig_memory *mem;
+
+ dev_dbg(map->q->dev, "munmap %p q=%p\n", map, q);
+ mutex_lock(&q->vb_lock);
+
+ /* We need first to cancel streams, before unmapping */
+ if (q->streaming)
+ videobuf_queue_cancel(q);
+
+ for (i = 0; i < VIDEO_MAX_FRAME; i++) {
+ if (NULL == q->bufs[i])
+ continue;
+
+ if (q->bufs[i]->map != map)
+ continue;
+
+ mem = q->bufs[i]->priv;
+ if (mem) {
+ /* This callback is called only if kernel has
+ allocated memory and this memory is mmapped.
+ In this case, memory should be freed,
+ in order to do memory unmap.
+ */
+
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ /* vfree is not atomic - can't be
+ called with IRQ's disabled
+ */
+ dev_dbg(map->q->dev, "buf[%d] freeing %p\n",
+ i, mem->vaddr);
+
+ dma_free_coherent(q->dev, mem->size,
+ mem->vaddr, mem->dma_handle);
+ mem->vaddr = NULL;
+ }
+
+ q->bufs[i]->map = NULL;
+ q->bufs[i]->baddr = 0;
+ }
+
+ kfree(map);
+
+ mutex_unlock(&q->vb_lock);
+ }
+}
+
+static struct vm_operations_struct videobuf_vm_ops = {
+ .open = videobuf_vm_open,
+ .close = videobuf_vm_close,
+};
+
+static void *__videobuf_alloc(size_t size)
+{
+ struct videobuf_dma_contig_memory *mem;
+ struct videobuf_buffer *vb;
+
+ vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
+ if (vb) {
+ mem = vb->priv = ((char *)vb) + size;
+ mem->magic = MAGIC_DC_MEM;
+ }
+
+ return vb;
+}
+
+static void *__videobuf_to_vmalloc(struct videobuf_buffer *buf)
+{
+ struct videobuf_dma_contig_memory *mem = buf->priv;
+
+ BUG_ON(!mem);
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ return mem->vaddr;
+}
+
+static int __videobuf_iolock(struct videobuf_queue *q,
+ struct videobuf_buffer *vb,
+ struct v4l2_framebuffer *fbuf)
+{
+ struct videobuf_dma_contig_memory *mem = vb->priv;
+
+ BUG_ON(!mem);
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ switch (vb->memory) {
+ case V4L2_MEMORY_MMAP:
+ dev_dbg(q->dev, "%s memory method MMAP\n", __func__);
+
+ /* All handling should be done by __videobuf_mmap_mapper() */
+ if (!mem->vaddr) {
+ dev_err(q->dev, "memory is not alloced/mmapped.\n");
+ return -EINVAL;
+ }
+ break;
+ case V4L2_MEMORY_USERPTR:
+ dev_dbg(q->dev, "%s memory method USERPTR\n", __func__);
+
+ /* The only USERPTR currently supported is the one needed for
+ read() method.
+ */
+ if (vb->baddr)
+ return -EINVAL;
+
+ mem->size = PAGE_ALIGN(vb->size);
+ mem->vaddr = dma_alloc_coherent(q->dev, mem->size,
+ &mem->dma_handle, GFP_KERNEL);
+ if (!mem->vaddr) {
+ dev_err(q->dev, "dma_alloc_coherent %ld failed\n",
+ mem->size);
+ return -ENOMEM;
+ }
+
+ dev_dbg(q->dev, "dma_alloc_coherent data is at %p (%ld)\n",
+ mem->vaddr, mem->size);
+ break;
+ case V4L2_MEMORY_OVERLAY:
+ default:
+ dev_dbg(q->dev, "%s memory method OVERLAY/unknown\n",
+ __func__);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int __videobuf_sync(struct videobuf_queue *q,
+ struct videobuf_buffer *buf)
+{
+ struct videobuf_dma_contig_memory *mem = buf->priv;
+
+ BUG_ON(!mem);
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ dma_sync_single_for_cpu(q->dev, mem->dma_handle, mem->size,
+ DMA_FROM_DEVICE);
+ return 0;
+}
+
+static int __videobuf_mmap_free(struct videobuf_queue *q)
+{
+ unsigned int i;
+
+ dev_dbg(q->dev, "%s\n", __func__);
+ for (i = 0; i < VIDEO_MAX_FRAME; i++) {
+ if (q->bufs[i] && q->bufs[i]->map)
+ return -EBUSY;
+ }
+
+ return 0;
+}
+
+static int __videobuf_mmap_mapper(struct videobuf_queue *q,
+ struct vm_area_struct *vma)
+{
+ struct videobuf_dma_contig_memory *mem;
+ struct videobuf_mapping *map;
+ unsigned int first;
+ int retval;
+ unsigned long size, offset = vma->vm_pgoff << PAGE_SHIFT;
+
+ dev_dbg(q->dev, "%s\n", __func__);
+ if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
+ return -EINVAL;
+
+ /* look for first buffer to map */
+ for (first = 0; first < VIDEO_MAX_FRAME; first++) {
+ if (!q->bufs[first])
+ continue;
+
+ if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
+ continue;
+ if (q->bufs[first]->boff == offset)
+ break;
+ }
+ if (VIDEO_MAX_FRAME == first) {
+ dev_dbg(q->dev, "invalid user space offset [offset=0x%lx]\n",
+ offset);
+ return -EINVAL;
+ }
+
+ /* create mapping + update buffer list */
+ map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
+ if (!map)
+ return -ENOMEM;
+
+ q->bufs[first]->map = map;
+ map->start = vma->vm_start;
+ map->end = vma->vm_end;
+ map->q = q;
+
+ q->bufs[first]->baddr = vma->vm_start;
+
+ mem = q->bufs[first]->priv;
+ BUG_ON(!mem);
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ mem->size = PAGE_ALIGN(q->bufs[first]->bsize);
+ mem->vaddr = dma_alloc_coherent(q->dev, mem->size,
+ &mem->dma_handle, GFP_KERNEL);
+ if (!mem->vaddr) {
+ dev_err(q->dev, "dma_alloc_coherent size %ld failed\n",
+ mem->size);
+ goto error;
+ }
+ dev_dbg(q->dev, "dma_alloc_coherent data is at addr %p (size %ld)\n",
+ mem->vaddr, mem->size);
+
+ /* Try to remap memory */
+
+ size = vma->vm_end - vma->vm_start;
+ size = (size < mem->size) ? size : mem->size;
+
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+ retval = remap_pfn_range(vma, vma->vm_start,
+ __pa(mem->vaddr) >> PAGE_SHIFT,
+ size, vma->vm_page_prot);
+ if (retval) {
+ dev_err(q->dev, "mmap: remap failed with error %d. ", retval);
+ dma_free_coherent(q->dev, mem->size,
+ mem->vaddr, mem->dma_handle);
+ goto error;
+ }
+
+ vma->vm_ops = &videobuf_vm_ops;
+ vma->vm_flags |= VM_DONTEXPAND;
+ vma->vm_private_data = map;
+
+ dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
+ map, q, vma->vm_start, vma->vm_end,
+ (long int) q->bufs[first]->bsize,
+ vma->vm_pgoff, first);
+
+ videobuf_vm_open(vma);
+
+ return 0;
+
+error:
+ kfree(map);
+ return -ENOMEM;
+}
+
+static int __videobuf_copy_to_user(struct videobuf_queue *q,
+ char __user *data, size_t count,
+ int nonblocking)
+{
+ struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
+ void *vaddr;
+
+ BUG_ON(!mem);
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+ BUG_ON(!mem->vaddr);
+
+ /* copy to userspace */
+ if (count > q->read_buf->size - q->read_off)
+ count = q->read_buf->size - q->read_off;
+
+ vaddr = mem->vaddr;
+
+ if (copy_to_user(data, vaddr + q->read_off, count))
+ return -EFAULT;
+
+ return count;
+}
+
+static int __videobuf_copy_stream(struct videobuf_queue *q,
+ char __user *data, size_t count, size_t pos,
+ int vbihack, int nonblocking)
+{
+ unsigned int *fc;
+ struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
+
+ BUG_ON(!mem);
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ if (vbihack) {
+ /* dirty, undocumented hack -- pass the frame counter
+ * within the last four bytes of each vbi data block.
+ * We need that one to maintain backward compatibility
+ * to all vbi decoding software out there ... */
+ fc = (unsigned int *)mem->vaddr;
+ fc += (q->read_buf->size >> 2) - 1;
+ *fc = q->read_buf->field_count >> 1;
+ dev_dbg(q->dev, "vbihack: %d\n", *fc);
+ }
+
+ /* copy stuff using the common method */
+ count = __videobuf_copy_to_user(q, data, count, nonblocking);
+
+ if ((count == -EFAULT) && (pos == 0))
+ return -EFAULT;
+
+ return count;
+}
+
+static struct videobuf_qtype_ops qops = {
+ .magic = MAGIC_QTYPE_OPS,
+
+ .alloc = __videobuf_alloc,
+ .iolock = __videobuf_iolock,
+ .sync = __videobuf_sync,
+ .mmap_free = __videobuf_mmap_free,
+ .mmap_mapper = __videobuf_mmap_mapper,
+ .video_copy_to_user = __videobuf_copy_to_user,
+ .copy_stream = __videobuf_copy_stream,
+ .vmalloc = __videobuf_to_vmalloc,
+};
+
+void videobuf_queue_dma_contig_init(struct videobuf_queue *q,
+ struct videobuf_queue_ops *ops,
+ struct device *dev,
+ spinlock_t *irqlock,
+ enum v4l2_buf_type type,
+ enum v4l2_field field,
+ unsigned int msize,
+ void *priv)
+{
+ videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
+ priv, &qops);
+}
+EXPORT_SYMBOL_GPL(videobuf_queue_dma_contig_init);
+
+dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf)
+{
+ struct videobuf_dma_contig_memory *mem = buf->priv;
+
+ BUG_ON(!mem);
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ return mem->dma_handle;
+}
+EXPORT_SYMBOL_GPL(videobuf_to_dma_contig);
+
+void videobuf_dma_contig_free(struct videobuf_queue *q,
+ struct videobuf_buffer *buf)
+{
+ struct videobuf_dma_contig_memory *mem = buf->priv;
+
+ /* mmapped memory can't be freed here, otherwise mmapped region
+ would be released, while still needed. In this case, the memory
+ release should happen inside videobuf_vm_close().
+ So, it should free memory only if the memory were allocated for
+ read() operation.
+ */
+ if ((buf->memory != V4L2_MEMORY_USERPTR) || !buf->baddr)
+ return;
+
+ if (!mem)
+ return;
+
+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
+
+ dma_free_coherent(q->dev, mem->size, mem->vaddr, mem->dma_handle);
+ mem->vaddr = NULL;
+}
+EXPORT_SYMBOL_GPL(videobuf_dma_contig_free);
+
+MODULE_DESCRIPTION("helper module to manage video4linux dma contig buffers");
+MODULE_AUTHOR("Magnus Damm");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ work/include/media/videobuf-dma-contig.h 2008-07-05 09:47:22.000000000 +0900
@@ -0,0 +1,32 @@
+/*
+ * helper functions for physically contiguous capture buffers
+ *
+ * The functions support hardware lacking scatter gatter support
+ * (i.e. the buffers must be linear in physical memory)
+ *
+ * Copyright (c) 2008 Magnus Damm
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2
+ */
+#ifndef _VIDEOBUF_DMA_CONTIG_H
+#define _VIDEOBUF_DMA_CONTIG_H
+
+#include <linux/dma-mapping.h>
+#include <media/videobuf-core.h>
+
+void videobuf_queue_dma_contig_init(struct videobuf_queue *q,
+ struct videobuf_queue_ops *ops,
+ struct device *dev,
+ spinlock_t *irqlock,
+ enum v4l2_buf_type type,
+ enum v4l2_field field,
+ unsigned int msize,
+ void *priv);
+
+dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf);
+void videobuf_dma_contig_free(struct videobuf_queue *q,
+ struct videobuf_buffer *buf);
+
+#endif /* _VIDEOBUF_DMA_CONTIG_H */
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-05 2:54 ` [PATCH 03/04] videobuf: Add physically contiguous queue code V2 Magnus Damm
@ 2008-07-08 14:33 ` Paulius Zaleckas
2008-07-08 14:42 ` Laurent Pinchart
2008-07-11 21:33 ` Guennadi Liakhovetski
2008-07-11 13:38 ` Karicheri, Muralidharan
1 sibling, 2 replies; 15+ messages in thread
From: Paulius Zaleckas @ 2008-07-08 14:33 UTC (permalink / raw)
To: video4linux-list; +Cc: video4linux-list, linux-sh
Magnus Damm wrote:
> This is V2 of the physically contiguous videobuf queues patch.
> Useful for hardware such as the SuperH Mobile CEU which doesn't
> support scatter gatter bus mastering.
spelling gatther :)
> +static int __videobuf_mmap_mapper(struct videobuf_queue *q,
> + struct vm_area_struct *vma)
> +{
> + struct videobuf_dma_contig_memory *mem;
> + struct videobuf_mapping *map;
> + unsigned int first;
> + int retval;
> + unsigned long size, offset = vma->vm_pgoff << PAGE_SHIFT;
> +
> + dev_dbg(q->dev, "%s\n", __func__);
> + if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
> + return -EINVAL;
> +
> + /* look for first buffer to map */
> + for (first = 0; first < VIDEO_MAX_FRAME; first++) {
> + if (!q->bufs[first])
> + continue;
> +
> + if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
> + continue;
> + if (q->bufs[first]->boff == offset)
> + break;
> + }
> + if (VIDEO_MAX_FRAME == first) {
> + dev_dbg(q->dev, "invalid user space offset [offset=0x%lx]\n",
> + offset);
> + return -EINVAL;
> + }
> +
> + /* create mapping + update buffer list */
> + map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
> + if (!map)
> + return -ENOMEM;
> +
> + q->bufs[first]->map = map;
> + map->start = vma->vm_start;
> + map->end = vma->vm_end;
> + map->q = q;
> +
> + q->bufs[first]->baddr = vma->vm_start;
> +
> + mem = q->bufs[first]->priv;
> + BUG_ON(!mem);
> + MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
> +
> + mem->size = PAGE_ALIGN(q->bufs[first]->bsize);
> + mem->vaddr = dma_alloc_coherent(q->dev, mem->size,
> + &mem->dma_handle, GFP_KERNEL);
> + if (!mem->vaddr) {
> + dev_err(q->dev, "dma_alloc_coherent size %ld failed\n",
> + mem->size);
> + goto error;
> + }
> + dev_dbg(q->dev, "dma_alloc_coherent data is at addr %p (size %ld)\n",
> + mem->vaddr, mem->size);
> +
> + /* Try to remap memory */
> +
> + size = vma->vm_end - vma->vm_start;
> + size = (size < mem->size) ? size : mem->size;
> +
> + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> + retval = remap_pfn_range(vma, vma->vm_start,
> + __pa(mem->vaddr) >> PAGE_SHIFT,
__pa(mem->vaddr) doesn't work on ARM architecture... It is a long story
about handling memory allocations and mapping for ARM (there is
dma_mmap_coherent to deal with this), but there is a workaround:
mem->dma_handle >> PAGE_SHIFT,
It is safe to do it this way and also saves some CPU instructions :)
> + size, vma->vm_page_prot);
> + if (retval) {
> + dev_err(q->dev, "mmap: remap failed with error %d. ", retval);
> + dma_free_coherent(q->dev, mem->size,
> + mem->vaddr, mem->dma_handle);
> + goto error;
> + }
> +
> + vma->vm_ops = &videobuf_vm_ops;
> + vma->vm_flags |= VM_DONTEXPAND;
> + vma->vm_private_data = map;
> +
> + dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
> + map, q, vma->vm_start, vma->vm_end,
> + (long int) q->bufs[first]->bsize,
> + vma->vm_pgoff, first);
> +
> + videobuf_vm_open(vma);
> +
> + return 0;
> +
> +error:
> + kfree(map);
> + return -ENOMEM;
> +}
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-08 14:33 ` Paulius Zaleckas
@ 2008-07-08 14:42 ` Laurent Pinchart
2008-07-09 8:33 ` Magnus Damm
2008-07-11 21:33 ` Guennadi Liakhovetski
1 sibling, 1 reply; 15+ messages in thread
From: Laurent Pinchart @ 2008-07-08 14:42 UTC (permalink / raw)
To: video4linux-list; +Cc: Paulius Zaleckas, linux-sh
On Tuesday 08 July 2008, Paulius Zaleckas wrote:
> Magnus Damm wrote:
> > This is V2 of the physically contiguous videobuf queues patch.
> > Useful for hardware such as the SuperH Mobile CEU which doesn't
> > support scatter gatter bus mastering.
>
> spelling gatther :)
gather would be even better :-)
Laurent Pinchart
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-08 14:42 ` Laurent Pinchart
@ 2008-07-09 8:33 ` Magnus Damm
0 siblings, 0 replies; 15+ messages in thread
From: Magnus Damm @ 2008-07-09 8:33 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: video4linux-list, Paulius Zaleckas, linux-sh
On Tue, Jul 8, 2008 at 11:42 PM, Laurent Pinchart
<laurent.pinchart@skynet.be> wrote:
> On Tuesday 08 July 2008, Paulius Zaleckas wrote:
>> Magnus Damm wrote:
>> > This is V2 of the physically contiguous videobuf queues patch.
>> > Useful for hardware such as the SuperH Mobile CEU which doesn't
>> > support scatter gatter bus mastering.
>>
>> spelling gatther :)
>
> gather would be even better :-)
Heh, maybe so, but even better would be if videobuf-dma-sg.c and
videobuf-vmalloc.c used the same spelling... =)
/ magnus
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-08 14:33 ` Paulius Zaleckas
2008-07-08 14:42 ` Laurent Pinchart
@ 2008-07-11 21:33 ` Guennadi Liakhovetski
2008-07-14 3:51 ` Magnus Damm
1 sibling, 1 reply; 15+ messages in thread
From: Guennadi Liakhovetski @ 2008-07-11 21:33 UTC (permalink / raw)
To: Paulius Zaleckas; +Cc: video4linux-list, linux-sh
On Tue, 8 Jul 2008, Paulius Zaleckas wrote:
> Magnus Damm wrote:
> > This is V2 of the physically contiguous videobuf queues patch.
> > Useful for hardware such as the SuperH Mobile CEU which doesn't
> > support scatter gatter bus mastering.
[snip]
> > + /* Try to remap memory */
> > +
> > + size = vma->vm_end - vma->vm_start;
> > + size = (size < mem->size) ? size : mem->size;
> > +
> > + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> > + retval = remap_pfn_range(vma, vma->vm_start,
> > + __pa(mem->vaddr) >> PAGE_SHIFT,
>
> __pa(mem->vaddr) doesn't work on ARM architecture... It is a long story
> about handling memory allocations and mapping for ARM (there is
> dma_mmap_coherent to deal with this), but there is a workaround:
>
> mem->dma_handle >> PAGE_SHIFT,
>
> It is safe to do it this way and also saves some CPU instructions :)
Paulius, even if the story is so long, could you perhaps point us to some
ML-threads or elaborate a bit? I did find one example in
drivers/media/video/atmel-isi.c (not in mainline), just would be
interesting to find out more.
Magnus, have you investigated this further?
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-11 21:33 ` Guennadi Liakhovetski
@ 2008-07-14 3:51 ` Magnus Damm
2008-07-14 9:25 ` Paulius Zaleckas
[not found] ` <20080715034850.GA3722@linux-sh.org>
0 siblings, 2 replies; 15+ messages in thread
From: Magnus Damm @ 2008-07-14 3:51 UTC (permalink / raw)
To: Guennadi Liakhovetski; +Cc: video4linux-list, Paulius Zaleckas, linux-sh
On Sat, Jul 12, 2008 at 6:33 AM, Guennadi Liakhovetski
<g.liakhovetski@gmx.de> wrote:
> On Tue, 8 Jul 2008, Paulius Zaleckas wrote:
>
>> Magnus Damm wrote:
>> > This is V2 of the physically contiguous videobuf queues patch.
>> > Useful for hardware such as the SuperH Mobile CEU which doesn't
>> > support scatter gatter bus mastering.
>
> [snip]
>
>> > + /* Try to remap memory */
>> > +
>> > + size = vma->vm_end - vma->vm_start;
>> > + size = (size < mem->size) ? size : mem->size;
>> > +
>> > + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>> > + retval = remap_pfn_range(vma, vma->vm_start,
>> > + __pa(mem->vaddr) >> PAGE_SHIFT,
>>
>> __pa(mem->vaddr) doesn't work on ARM architecture... It is a long story
>> about handling memory allocations and mapping for ARM (there is
>> dma_mmap_coherent to deal with this), but there is a workaround:
>>
>> mem->dma_handle >> PAGE_SHIFT,
>>
>> It is safe to do it this way and also saves some CPU instructions :)
>
> Paulius, even if the story is so long, could you perhaps point us to some
> ML-threads or elaborate a bit? I did find one example in
> drivers/media/video/atmel-isi.c (not in mainline), just would be
> interesting to find out more.
>
> Magnus, have you investigated this further?
Both (__pa(mem->vaddr) >> PAGE_SHIFT) and (mem->dma_handle >>
PAGE_SHIFT) work well with the current dma_alloc_coherent()
implementation on SuperH. I do however lean towards using
__pa(mem->vaddr) over mem->dma_handle, since I suspect that
mem->dma_handle doesn't have to be a physical address.
Paul, any thoughts about this? Can we assume that the dma_handle
returned from dma_alloc_coherent() is a physical address, or is it
better to use __pa() on the virtual address to get the pfn?
Thanks,
/ magnus
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-14 3:51 ` Magnus Damm
@ 2008-07-14 9:25 ` Paulius Zaleckas
[not found] ` <20080715034850.GA3722@linux-sh.org>
1 sibling, 0 replies; 15+ messages in thread
From: Paulius Zaleckas @ 2008-07-14 9:25 UTC (permalink / raw)
To: video4linux-list; +Cc: video4linux-list, linux-sh
Magnus Damm wrote:
> On Sat, Jul 12, 2008 at 6:33 AM, Guennadi Liakhovetski
> <g.liakhovetski@gmx.de> wrote:
>> On Tue, 8 Jul 2008, Paulius Zaleckas wrote:
>>
>>> Magnus Damm wrote:
>>>> This is V2 of the physically contiguous videobuf queues patch.
>>>> Useful for hardware such as the SuperH Mobile CEU which doesn't
>>>> support scatter gatter bus mastering.
>> [snip]
>>
>>>> + /* Try to remap memory */
>>>> +
>>>> + size = vma->vm_end - vma->vm_start;
>>>> + size = (size < mem->size) ? size : mem->size;
>>>> +
>>>> + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>>>> + retval = remap_pfn_range(vma, vma->vm_start,
>>>> + __pa(mem->vaddr) >> PAGE_SHIFT,
>>> __pa(mem->vaddr) doesn't work on ARM architecture... It is a long story
>>> about handling memory allocations and mapping for ARM (there is
>>> dma_mmap_coherent to deal with this), but there is a workaround:
>>>
>>> mem->dma_handle >> PAGE_SHIFT,
>>>
>>> It is safe to do it this way and also saves some CPU instructions :)
>> Paulius, even if the story is so long, could you perhaps point us to some
>> ML-threads or elaborate a bit? I did find one example in
>> drivers/media/video/atmel-isi.c (not in mainline), just would be
>> interesting to find out more.
>>
>> Magnus, have you investigated this further?
>
> Both (__pa(mem->vaddr) >> PAGE_SHIFT) and (mem->dma_handle >>
> PAGE_SHIFT) work well with the current dma_alloc_coherent()
> implementation on SuperH. I do however lean towards using
> __pa(mem->vaddr) over mem->dma_handle, since I suspect that
> mem->dma_handle doesn't have to be a physical address.
>
> Paul, any thoughts about this? Can we assume that the dma_handle
> returned from dma_alloc_coherent() is a physical address, or is it
> better to use __pa() on the virtual address to get the pfn?
Well dma_alloc_coherent() is supposed to return physically contiguous
memory physical address in dma_handle... Quick look at LXR didn't show
any architecture where it shouldn't work... but it showed that ARM and
possibly FRV(?) won't work with __pa() since these architectures are
allocating from different memory pool than kmalloc()
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread[parent not found: <20080715034850.GA3722@linux-sh.org>]
* Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
[not found] ` <20080715034850.GA3722@linux-sh.org>
@ 2008-07-15 8:28 ` Magnus Damm
0 siblings, 0 replies; 15+ messages in thread
From: Magnus Damm @ 2008-07-15 8:28 UTC (permalink / raw)
To: Paul Mundt, Magnus Damm, Guennadi Liakhovetski, Paulius Zaleckas,
video4linux-list, linux-sh
On Tue, Jul 15, 2008 at 12:48 PM, Paul Mundt <lethal@linux-sh.org> wrote:
> On Mon, Jul 14, 2008 at 12:51:55PM +0900, Magnus Damm wrote:
>> Both (__pa(mem->vaddr) >> PAGE_SHIFT) and (mem->dma_handle >>
>> PAGE_SHIFT) work well with the current dma_alloc_coherent()
>> implementation on SuperH. I do however lean towards using
>> __pa(mem->vaddr) over mem->dma_handle, since I suspect that
>> mem->dma_handle doesn't have to be a physical address.
>>
>> Paul, any thoughts about this? Can we assume that the dma_handle
>> returned from dma_alloc_coherent() is a physical address, or is it
>> better to use __pa() on the virtual address to get the pfn?
>>
> It's a physical address as far as the dma_handle users are concerned, how
> that actually translates across the bus is another matter. (The corner
> cases end up being things like Cell that DMA in to virtual addresses via
> IOMMU translations).
>
> Documentation/DMA-API.txt simply states:
>
> This routine allocates a region of <size> bytes of consistent memory.
> It also returns a <dma_handle> which may be cast to an unsigned
> integer the same width as the bus and used as the physical address
> base of the region.
>
> so as far as we are concerned, using dma_handle is saner than going the __pa()
> route.
Ok, thanks for the clarification. V3 should be correct already then. I
guess I mixed up the regular dma handle with the bus address of
dma_declare_coherent_memory(). =)
/ magnus
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
2008-07-05 2:54 ` [PATCH 03/04] videobuf: Add physically contiguous queue code V2 Magnus Damm
2008-07-08 14:33 ` Paulius Zaleckas
@ 2008-07-11 13:38 ` Karicheri, Muralidharan
1 sibling, 0 replies; 15+ messages in thread
From: Karicheri, Muralidharan @ 2008-07-11 13:38 UTC (permalink / raw)
To: Magnus Damm, video4linux-list
Cc: paulius.zaleckas, linux-sh, mchehab, lethal, akpm, g.liakhovetski
Magnus,
Thanks for adding support for contiguous buffer in v4l2. I am in
the process of up porting our video drivers to open source and
would require this support in the v4l2 framework. Could you share
with me the related code, makefile and kconfig changes etc ?
Thanks
Murali Karicheri
email: m-karicheri2@ti.com
>>>-----Original Message-----
>>>From: Magnus Damm [mailto:magnus.damm@gmail.com]
>>>Sent: Friday, July 04, 2008 10:54 PM
>>>To: video4linux-list@redhat.com
>>>Cc: paulius.zaleckas@teltonika.lt; linux-sh@vger.kernel.org;
>>>mchehab@infradead.org; lethal@linux-sh.org;
akpm@linux-foundation.org;
>>>g.liakhovetski@gmx.de
>>>Subject: [PATCH 03/04] videobuf: Add physically contiguous queue code
V2
>>>
>>>This is V2 of the physically contiguous videobuf queues patch.
>>>Useful for hardware such as the SuperH Mobile CEU which doesn't
>>>support scatter gatter bus mastering.
>>>
>>>Since it may be difficult to allocate large chunks of physically
>>>contiguous memory after some uptime due to fragmentation, this code
>>>allocates memory using dma_alloc_coherent(). Architectures supporting
>>>dma_declare_coherent_memory() can easily avoid fragmentation issues
>>>by using dma_declare_coherent_memory() to force dma_alloc_coherent()
>>>to allocate from a certain pre-allocated memory area.
>>>
>>>Signed-off-by: Magnus Damm <damm@igel.co.jp>
>>>---
>>>
>>> Changes since V1:
>>> - use dev_err() instead of pr_err()
>>> - remember size in struct videobuf_dma_contig_memory
>>> - keep struct videobuf_dma_contig_memory in .c file
>>> - let videobuf_to_dma_contig() return dma_addr_t
>>> - implement __videobuf_sync()
>>> - return statements, white space and other minor fixes
>>>
>>> drivers/media/video/Kconfig | 5
>>> drivers/media/video/Makefile | 1
>>> drivers/media/video/videobuf-dma-contig.c | 417
>>>+++++++++++++++++++++++++++++
>>> include/media/videobuf-dma-contig.h | 32 ++
>>> 4 files changed, 455 insertions(+)
>>>
>>>--- 0002/drivers/media/video/Kconfig
>>>+++ work/drivers/media/video/Kconfig 2008-07-05 09:47:22.000000000
>>>+0900
>>>@@ -24,6 +24,11 @@ config VIDEOBUF_VMALLOC
>>> select VIDEOBUF_GEN
>>> tristate
>>>
>>>+config VIDEOBUF_DMA_CONTIG
>>>+ depends on HAS_DMA
>>>+ select VIDEOBUF_GEN
>>>+ tristate
>>>+
>>> config VIDEOBUF_DVB
>>> tristate
>>> select VIDEOBUF_GEN
>>>--- 0001/drivers/media/video/Makefile
>>>+++ work/drivers/media/video/Makefile 2008-07-05
09:47:22.000000000
>>>+0900
>>>@@ -88,6 +88,7 @@ obj-$(CONFIG_VIDEO_TUNER) += tuner.o
>>>
>>> obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
>>> obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
>>>+obj-$(CONFIG_VIDEOBUF_DMA_CONTIG) += videobuf-dma-contig.o
>>> obj-$(CONFIG_VIDEOBUF_VMALLOC) += videobuf-vmalloc.o
>>> obj-$(CONFIG_VIDEOBUF_DVB) += videobuf-dvb.o
>>> obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o
>>>--- /dev/null
>>>+++ work/drivers/media/video/videobuf-dma-contig.c 2008-07-05
>>>10:09:12.000000000 +0900
>>>@@ -0,0 +1,417 @@
>>>+/*
>>>+ * helper functions for physically contiguous capture buffers
>>>+ *
>>>+ * The functions support hardware lacking scatter gatter support
>>>+ * (i.e. the buffers must be linear in physical memory)
>>>+ *
>>>+ * Copyright (c) 2008 Magnus Damm
>>>+ *
>>>+ * Based on videobuf-vmalloc.c,
>>>+ * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
>>>+ *
>>>+ * This program is free software; you can redistribute it and/or
modify
>>>+ * it under the terms of the GNU General Public License as published
by
>>>+ * the Free Software Foundation; either version 2
>>>+ */
>>>+
>>>+#include <linux/init.h>
>>>+#include <linux/module.h>
>>>+#include <linux/dma-mapping.h>
>>>+#include <media/videobuf-dma-contig.h>
>>>+
>>>+struct videobuf_dma_contig_memory {
>>>+ u32 magic;
>>>+ void *vaddr;
>>>+ dma_addr_t dma_handle;
>>>+ unsigned long size;
>>>+};
>>>+
>>>+#define MAGIC_DC_MEM 0x0733ac61
>>>+#define MAGIC_CHECK(is, should)
\
>>>+ if (unlikely((is) != (should))) {
\
>>>+ pr_err("magic mismatch: %x expected %x\n", is, should);
\
>>>+ BUG();
\
>>>+ }
>>>+
>>>+static void
>>>+videobuf_vm_open(struct vm_area_struct *vma)
>>>+{
>>>+ struct videobuf_mapping *map = vma->vm_private_data;
>>>+
>>>+ dev_dbg(map->q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n",
>>>+ map, map->count, vma->vm_start, vma->vm_end);
>>>+
>>>+ map->count++;
>>>+}
>>>+
>>>+static void videobuf_vm_close(struct vm_area_struct *vma)
>>>+{
>>>+ struct videobuf_mapping *map = vma->vm_private_data;
>>>+ struct videobuf_queue *q = map->q;
>>>+ int i;
>>>+
>>>+ dev_dbg(map->q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
>>>+ map, map->count, vma->vm_start, vma->vm_end);
>>>+
>>>+ map->count--;
>>>+ if (0 == map->count) {
>>>+ struct videobuf_dma_contig_memory *mem;
>>>+
>>>+ dev_dbg(map->q->dev, "munmap %p q=%p\n", map, q);
>>>+ mutex_lock(&q->vb_lock);
>>>+
>>>+ /* We need first to cancel streams, before unmapping */
>>>+ if (q->streaming)
>>>+ videobuf_queue_cancel(q);
>>>+
>>>+ for (i = 0; i < VIDEO_MAX_FRAME; i++) {
>>>+ if (NULL == q->bufs[i])
>>>+ continue;
>>>+
>>>+ if (q->bufs[i]->map != map)
>>>+ continue;
>>>+
>>>+ mem = q->bufs[i]->priv;
>>>+ if (mem) {
>>>+ /* This callback is called only if
kernel has
>>>+ allocated memory and this memory is
mmapped.
>>>+ In this case, memory should be freed,
>>>+ in order to do memory unmap.
>>>+ */
>>>+
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ /* vfree is not atomic - can't be
>>>+ called with IRQ's disabled
>>>+ */
>>>+ dev_dbg(map->q->dev, "buf[%d] freeing
%p\n",
>>>+ i, mem->vaddr);
>>>+
>>>+ dma_free_coherent(q->dev, mem->size,
>>>+ mem->vaddr,
mem->dma_handle);
>>>+ mem->vaddr = NULL;
>>>+ }
>>>+
>>>+ q->bufs[i]->map = NULL;
>>>+ q->bufs[i]->baddr = 0;
>>>+ }
>>>+
>>>+ kfree(map);
>>>+
>>>+ mutex_unlock(&q->vb_lock);
>>>+ }
>>>+}
>>>+
>>>+static struct vm_operations_struct videobuf_vm_ops = {
>>>+ .open = videobuf_vm_open,
>>>+ .close = videobuf_vm_close,
>>>+};
>>>+
>>>+static void *__videobuf_alloc(size_t size)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem;
>>>+ struct videobuf_buffer *vb;
>>>+
>>>+ vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
>>>+ if (vb) {
>>>+ mem = vb->priv = ((char *)vb) + size;
>>>+ mem->magic = MAGIC_DC_MEM;
>>>+ }
>>>+
>>>+ return vb;
>>>+}
>>>+
>>>+static void *__videobuf_to_vmalloc(struct videobuf_buffer *buf)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem = buf->priv;
>>>+
>>>+ BUG_ON(!mem);
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ return mem->vaddr;
>>>+}
>>>+
>>>+static int __videobuf_iolock(struct videobuf_queue *q,
>>>+ struct videobuf_buffer *vb,
>>>+ struct v4l2_framebuffer *fbuf)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem = vb->priv;
>>>+
>>>+ BUG_ON(!mem);
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ switch (vb->memory) {
>>>+ case V4L2_MEMORY_MMAP:
>>>+ dev_dbg(q->dev, "%s memory method MMAP\n", __func__);
>>>+
>>>+ /* All handling should be done by
__videobuf_mmap_mapper() */
>>>+ if (!mem->vaddr) {
>>>+ dev_err(q->dev, "memory is not
alloced/mmapped.\n");
>>>+ return -EINVAL;
>>>+ }
>>>+ break;
>>>+ case V4L2_MEMORY_USERPTR:
>>>+ dev_dbg(q->dev, "%s memory method USERPTR\n", __func__);
>>>+
>>>+ /* The only USERPTR currently supported is the one
needed for
>>>+ read() method.
>>>+ */
>>>+ if (vb->baddr)
>>>+ return -EINVAL;
>>>+
>>>+ mem->size = PAGE_ALIGN(vb->size);
>>>+ mem->vaddr = dma_alloc_coherent(q->dev, mem->size,
>>>+ &mem->dma_handle,
GFP_KERNEL);
>>>+ if (!mem->vaddr) {
>>>+ dev_err(q->dev, "dma_alloc_coherent %ld
failed\n",
>>>+ mem->size);
>>>+ return -ENOMEM;
>>>+ }
>>>+
>>>+ dev_dbg(q->dev, "dma_alloc_coherent data is at %p
(%ld)\n",
>>>+ mem->vaddr, mem->size);
>>>+ break;
>>>+ case V4L2_MEMORY_OVERLAY:
>>>+ default:
>>>+ dev_dbg(q->dev, "%s memory method OVERLAY/unknown\n",
>>>+ __func__);
>>>+ return -EINVAL;
>>>+ }
>>>+
>>>+ return 0;
>>>+}
>>>+
>>>+static int __videobuf_sync(struct videobuf_queue *q,
>>>+ struct videobuf_buffer *buf)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem = buf->priv;
>>>+
>>>+ BUG_ON(!mem);
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ dma_sync_single_for_cpu(q->dev, mem->dma_handle, mem->size,
>>>+ DMA_FROM_DEVICE);
>>>+ return 0;
>>>+}
>>>+
>>>+static int __videobuf_mmap_free(struct videobuf_queue *q)
>>>+{
>>>+ unsigned int i;
>>>+
>>>+ dev_dbg(q->dev, "%s\n", __func__);
>>>+ for (i = 0; i < VIDEO_MAX_FRAME; i++) {
>>>+ if (q->bufs[i] && q->bufs[i]->map)
>>>+ return -EBUSY;
>>>+ }
>>>+
>>>+ return 0;
>>>+}
>>>+
>>>+static int __videobuf_mmap_mapper(struct videobuf_queue *q,
>>>+ struct vm_area_struct *vma)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem;
>>>+ struct videobuf_mapping *map;
>>>+ unsigned int first;
>>>+ int retval;
>>>+ unsigned long size, offset = vma->vm_pgoff << PAGE_SHIFT;
>>>+
>>>+ dev_dbg(q->dev, "%s\n", __func__);
>>>+ if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
>>>+ return -EINVAL;
>>>+
>>>+ /* look for first buffer to map */
>>>+ for (first = 0; first < VIDEO_MAX_FRAME; first++) {
>>>+ if (!q->bufs[first])
>>>+ continue;
>>>+
>>>+ if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
>>>+ continue;
>>>+ if (q->bufs[first]->boff == offset)
>>>+ break;
>>>+ }
>>>+ if (VIDEO_MAX_FRAME == first) {
>>>+ dev_dbg(q->dev, "invalid user space offset
[offset=0x%lx]\n",
>>>+ offset);
>>>+ return -EINVAL;
>>>+ }
>>>+
>>>+ /* create mapping + update buffer list */
>>>+ map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
>>>+ if (!map)
>>>+ return -ENOMEM;
>>>+
>>>+ q->bufs[first]->map = map;
>>>+ map->start = vma->vm_start;
>>>+ map->end = vma->vm_end;
>>>+ map->q = q;
>>>+
>>>+ q->bufs[first]->baddr = vma->vm_start;
>>>+
>>>+ mem = q->bufs[first]->priv;
>>>+ BUG_ON(!mem);
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ mem->size = PAGE_ALIGN(q->bufs[first]->bsize);
>>>+ mem->vaddr = dma_alloc_coherent(q->dev, mem->size,
>>>+ &mem->dma_handle, GFP_KERNEL);
>>>+ if (!mem->vaddr) {
>>>+ dev_err(q->dev, "dma_alloc_coherent size %ld failed\n",
>>>+ mem->size);
>>>+ goto error;
>>>+ }
>>>+ dev_dbg(q->dev, "dma_alloc_coherent data is at addr %p
>>>(size %ld)\n",
>>>+ mem->vaddr, mem->size);
>>>+
>>>+ /* Try to remap memory */
>>>+
>>>+ size = vma->vm_end - vma->vm_start;
>>>+ size = (size < mem->size) ? size : mem->size;
>>>+
>>>+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>>>+ retval = remap_pfn_range(vma, vma->vm_start,
>>>+ __pa(mem->vaddr) >> PAGE_SHIFT,
>>>+ size, vma->vm_page_prot);
>>>+ if (retval) {
>>>+ dev_err(q->dev, "mmap: remap failed with error %d. ",
>>>retval);
>>>+ dma_free_coherent(q->dev, mem->size,
>>>+ mem->vaddr, mem->dma_handle);
>>>+ goto error;
>>>+ }
>>>+
>>>+ vma->vm_ops = &videobuf_vm_ops;
>>>+ vma->vm_flags |= VM_DONTEXPAND;
>>>+ vma->vm_private_data = map;
>>>+
>>>+ dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx
>>>buf %d\n",
>>>+ map, q, vma->vm_start, vma->vm_end,
>>>+ (long int) q->bufs[first]->bsize,
>>>+ vma->vm_pgoff, first);
>>>+
>>>+ videobuf_vm_open(vma);
>>>+
>>>+ return 0;
>>>+
>>>+error:
>>>+ kfree(map);
>>>+ return -ENOMEM;
>>>+}
>>>+
>>>+static int __videobuf_copy_to_user(struct videobuf_queue *q,
>>>+ char __user *data, size_t count,
>>>+ int nonblocking)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
>>>+ void *vaddr;
>>>+
>>>+ BUG_ON(!mem);
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+ BUG_ON(!mem->vaddr);
>>>+
>>>+ /* copy to userspace */
>>>+ if (count > q->read_buf->size - q->read_off)
>>>+ count = q->read_buf->size - q->read_off;
>>>+
>>>+ vaddr = mem->vaddr;
>>>+
>>>+ if (copy_to_user(data, vaddr + q->read_off, count))
>>>+ return -EFAULT;
>>>+
>>>+ return count;
>>>+}
>>>+
>>>+static int __videobuf_copy_stream(struct videobuf_queue *q,
>>>+ char __user *data, size_t count,
size_t pos,
>>>+ int vbihack, int nonblocking)
>>>+{
>>>+ unsigned int *fc;
>>>+ struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
>>>+
>>>+ BUG_ON(!mem);
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ if (vbihack) {
>>>+ /* dirty, undocumented hack -- pass the frame counter
>>>+ * within the last four bytes of each vbi data
block.
>>>+ * We need that one to maintain backward
compatibility
>>>+ * to all vbi decoding software out there ... */
>>>+ fc = (unsigned int *)mem->vaddr;
>>>+ fc += (q->read_buf->size >> 2) - 1;
>>>+ *fc = q->read_buf->field_count >> 1;
>>>+ dev_dbg(q->dev, "vbihack: %d\n", *fc);
>>>+ }
>>>+
>>>+ /* copy stuff using the common method */
>>>+ count = __videobuf_copy_to_user(q, data, count, nonblocking);
>>>+
>>>+ if ((count == -EFAULT) && (pos == 0))
>>>+ return -EFAULT;
>>>+
>>>+ return count;
>>>+}
>>>+
>>>+static struct videobuf_qtype_ops qops = {
>>>+ .magic = MAGIC_QTYPE_OPS,
>>>+
>>>+ .alloc = __videobuf_alloc,
>>>+ .iolock = __videobuf_iolock,
>>>+ .sync = __videobuf_sync,
>>>+ .mmap_free = __videobuf_mmap_free,
>>>+ .mmap_mapper = __videobuf_mmap_mapper,
>>>+ .video_copy_to_user = __videobuf_copy_to_user,
>>>+ .copy_stream = __videobuf_copy_stream,
>>>+ .vmalloc = __videobuf_to_vmalloc,
>>>+};
>>>+
>>>+void videobuf_queue_dma_contig_init(struct videobuf_queue *q,
>>>+ struct videobuf_queue_ops *ops,
>>>+ struct device *dev,
>>>+ spinlock_t *irqlock,
>>>+ enum v4l2_buf_type type,
>>>+ enum v4l2_field field,
>>>+ unsigned int msize,
>>>+ void *priv)
>>>+{
>>>+ videobuf_queue_core_init(q, ops, dev, irqlock, type, field,
msize,
>>>+ priv, &qops);
>>>+}
>>>+EXPORT_SYMBOL_GPL(videobuf_queue_dma_contig_init);
>>>+
>>>+dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem = buf->priv;
>>>+
>>>+ BUG_ON(!mem);
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ return mem->dma_handle;
>>>+}
>>>+EXPORT_SYMBOL_GPL(videobuf_to_dma_contig);
>>>+
>>>+void videobuf_dma_contig_free(struct videobuf_queue *q,
>>>+ struct videobuf_buffer *buf)
>>>+{
>>>+ struct videobuf_dma_contig_memory *mem = buf->priv;
>>>+
>>>+ /* mmapped memory can't be freed here, otherwise mmapped region
>>>+ would be released, while still needed. In this case, the
memory
>>>+ release should happen inside videobuf_vm_close().
>>>+ So, it should free memory only if the memory were allocated
for
>>>+ read() operation.
>>>+ */
>>>+ if ((buf->memory != V4L2_MEMORY_USERPTR) || !buf->baddr)
>>>+ return;
>>>+
>>>+ if (!mem)
>>>+ return;
>>>+
>>>+ MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
>>>+
>>>+ dma_free_coherent(q->dev, mem->size, mem->vaddr,
mem->dma_handle);
>>>+ mem->vaddr = NULL;
>>>+}
>>>+EXPORT_SYMBOL_GPL(videobuf_dma_contig_free);
>>>+
>>>+MODULE_DESCRIPTION("helper module to manage video4linux dma contig
>>>buffers");
>>>+MODULE_AUTHOR("Magnus Damm");
>>>+MODULE_LICENSE("GPL");
>>>--- /dev/null
>>>+++ work/include/media/videobuf-dma-contig.h 2008-07-05
>>>09:47:22.000000000 +0900
>>>@@ -0,0 +1,32 @@
>>>+/*
>>>+ * helper functions for physically contiguous capture buffers
>>>+ *
>>>+ * The functions support hardware lacking scatter gatter support
>>>+ * (i.e. the buffers must be linear in physical memory)
>>>+ *
>>>+ * Copyright (c) 2008 Magnus Damm
>>>+ *
>>>+ * This program is free software; you can redistribute it and/or
modify
>>>+ * it under the terms of the GNU General Public License as published
by
>>>+ * the Free Software Foundation; either version 2
>>>+ */
>>>+#ifndef _VIDEOBUF_DMA_CONTIG_H
>>>+#define _VIDEOBUF_DMA_CONTIG_H
>>>+
>>>+#include <linux/dma-mapping.h>
>>>+#include <media/videobuf-core.h>
>>>+
>>>+void videobuf_queue_dma_contig_init(struct videobuf_queue *q,
>>>+ struct videobuf_queue_ops *ops,
>>>+ struct device *dev,
>>>+ spinlock_t *irqlock,
>>>+ enum v4l2_buf_type type,
>>>+ enum v4l2_field field,
>>>+ unsigned int msize,
>>>+ void *priv);
>>>+
>>>+dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf);
>>>+void videobuf_dma_contig_free(struct videobuf_queue *q,
>>>+ struct videobuf_buffer *buf);
>>>+
>>>+#endif /* _VIDEOBUF_DMA_CONTIG_H */
>>>
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 04/04] sh_mobile_ceu_camera: Add SuperH Mobile CEU driver V2
2008-07-05 2:53 [PATCH 00/04] soc_camera: SuperH Mobile CEU support V2 Magnus Damm
` (2 preceding siblings ...)
2008-07-05 2:54 ` [PATCH 03/04] videobuf: Add physically contiguous queue code V2 Magnus Damm
@ 2008-07-05 2:54 ` Magnus Damm
3 siblings, 0 replies; 15+ messages in thread
From: Magnus Damm @ 2008-07-05 2:54 UTC (permalink / raw)
To: video4linux-list
Cc: paulius.zaleckas, linux-sh, mchehab, lethal, akpm, g.liakhovetski
This is V2 of the SuperH Mobile CEU soc_camera driver.
The CEU hardware block is configured in a transparent data fetch
mode, frames are captured from the attached camera and written to
physically contiguous memory buffers provided by the newly added
videobuf-dma-contig queue. Tested on sh7722 and sh7723 processors.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
---
drivers/media/video/Kconfig | 8
drivers/media/video/Makefile | 1
drivers/media/video/sh_mobile_ceu_camera.c | 623 ++++++++++++++++++++++++++++
include/asm-sh/sh_mobile_ceu.h | 10
4 files changed, 642 insertions(+)
--- 0009/drivers/media/video/Kconfig
+++ work/drivers/media/video/Kconfig 2008-07-05 09:50:22.000000000 +0900
@@ -969,4 +969,12 @@ config VIDEO_PXA27x
---help---
This is a v4l2 driver for the PXA27x Quick Capture Interface
+config VIDEO_SH_MOBILE_CEU
+ tristate "SuperH Mobile CEU Interface driver"
+ depends on VIDEO_DEV && SUPERH
+ select SOC_CAMERA
+ select VIDEOBUF_DMA_CONTIG
+ ---help---
+ This is a v4l2 driver for the SuperH Mobile CEU Interface
+
endif # VIDEO_CAPTURE_DRIVERS
--- 0009/drivers/media/video/Makefile
+++ work/drivers/media/video/Makefile 2008-07-05 09:50:22.000000000 +0900
@@ -133,6 +133,7 @@ obj-$(CONFIG_VIDEO_VIVI) += vivi.o
obj-$(CONFIG_VIDEO_CX23885) += cx23885/
obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
+obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
obj-$(CONFIG_SOC_CAMERA) += soc_camera.o
obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o
obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o
--- /dev/null
+++ work/drivers/media/video/sh_mobile_ceu_camera.c 2008-07-05 09:50:58.000000000 +0900
@@ -0,0 +1,623 @@
+/*
+ * V4L2 Driver for SuperH Mobile CEU interface
+ *
+ * Copyright (C) 2008 Magnus Damm
+ *
+ * Based on V4L2 Driver for PXA camera host - "pxa_camera.c",
+ *
+ * Copyright (C) 2006, Sascha Hauer, Pengutronix
+ * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/moduleparam.h>
+#include <linux/time.h>
+#include <linux/version.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/mutex.h>
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-dev.h>
+#include <media/soc_camera.h>
+#include <media/videobuf-dma-contig.h>
+
+#include <linux/videodev2.h>
+
+#include <asm/sh_mobile_ceu.h>
+
+/* register offsets for sh7722 / sh7723 */
+
+#define CAPSR 0x00
+#define CAPCR 0x04
+#define CAMCR 0x08
+#define CMCYR 0x0c
+#define CAMOR 0x10
+#define CAPWR 0x14
+#define CAIFR 0x18
+#define CSTCR 0x20 /* not on sh7723 */
+#define CSECR 0x24 /* not on sh7723 */
+#define CRCNTR 0x28
+#define CRCMPR 0x2c
+#define CFLCR 0x30
+#define CFSZR 0x34
+#define CDWDR 0x38
+#define CDAYR 0x3c
+#define CDACR 0x40
+#define CDBYR 0x44
+#define CDBCR 0x48
+#define CBDSR 0x4c
+#define CFWCR 0x5c
+#define CLFCR 0x60
+#define CDOCR 0x64
+#define CDDCR 0x68
+#define CDDAR 0x6c
+#define CEIER 0x70
+#define CETCR 0x74
+#define CSTSR 0x7c
+#define CSRTR 0x80
+#define CDSSR 0x84
+#define CDAYR2 0x90
+#define CDACR2 0x94
+#define CDBYR2 0x98
+#define CDBCR2 0x9c
+
+static DEFINE_MUTEX(camera_lock);
+
+/* per video frame buffer */
+struct sh_mobile_ceu_buffer {
+ struct videobuf_buffer vb; /* v4l buffer must be first */
+ const struct soc_camera_data_format *fmt;
+};
+
+struct sh_mobile_ceu_dev {
+ struct device *dev;
+ struct soc_camera_host ici;
+ struct soc_camera_device *icd;
+
+ unsigned int irq;
+ void __iomem *base;
+
+ spinlock_t lock;
+ struct list_head capture;
+ struct videobuf_buffer *active;
+
+ struct sh_mobile_ceu_info *pdata;
+};
+
+static unsigned int vid_limit = 4; /* Video memory limit, in Mb */
+
+static void ceu_write(struct sh_mobile_ceu_dev *priv,
+ unsigned long reg_offs, unsigned long data)
+{
+ iowrite32(data, priv->base + reg_offs);
+}
+
+static unsigned long ceu_read(struct sh_mobile_ceu_dev *priv,
+ unsigned long reg_offs)
+{
+ return ioread32(priv->base + reg_offs);
+}
+
+/*
+ * Videobuf operations
+ */
+static int sh_mobile_ceu_videobuf_setup(struct videobuf_queue *vq,
+ unsigned int *count,
+ unsigned int *size)
+{
+ struct soc_camera_device *icd = vq->priv_data;
+ int bytes_per_pixel = (icd->current_fmt->depth + 7) >> 3;
+
+ *size = PAGE_ALIGN(icd->width * icd->height * bytes_per_pixel);
+
+ if (0 == *count)
+ *count = 2;
+ while (*size * *count > vid_limit * 1024 * 1024)
+ (*count)--;
+
+ dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
+
+ return 0;
+}
+
+static void free_buffer(struct videobuf_queue *vq,
+ struct sh_mobile_ceu_buffer *buf)
+{
+ struct soc_camera_device *icd = vq->priv_data;
+
+ dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+ &buf->vb, buf->vb.baddr, buf->vb.bsize);
+
+ if (in_interrupt())
+ BUG();
+
+ videobuf_dma_contig_free(vq, &buf->vb);
+ dev_dbg(&icd->dev, "%s freed\n", __func__);
+ buf->vb.state = VIDEOBUF_NEEDS_INIT;
+}
+
+static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
+{
+ ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~1);
+ ceu_write(pcdev, CETCR, ~ceu_read(pcdev, CETCR) & 0x0317f313);
+ ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | 1);
+
+ ceu_write(pcdev, CAPCR, ceu_read(pcdev, CAPCR) & ~0x10000);
+
+ ceu_write(pcdev, CETCR, 0x0317f313 ^ 0x10);
+
+ if (pcdev->active) {
+ ceu_write(pcdev, CDAYR, videobuf_to_dma_contig(pcdev->active));
+ ceu_write(pcdev, CAPSR, 0x1); /* start capture */
+ }
+}
+
+static int sh_mobile_ceu_videobuf_prepare(struct videobuf_queue *vq,
+ struct videobuf_buffer *vb,
+ enum v4l2_field field)
+{
+ struct soc_camera_device *icd = vq->priv_data;
+ struct sh_mobile_ceu_buffer *buf;
+ int ret;
+
+ buf = container_of(vb, struct sh_mobile_ceu_buffer, vb);
+
+ dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+ vb, vb->baddr, vb->bsize);
+
+ /* Added list head initialization on alloc */
+ WARN_ON(!list_empty(&vb->queue));
+
+#ifdef DEBUG
+ /* This can be useful if you want to see if we actually fill
+ * the buffer with something */
+ memset((void *)vb->baddr, 0xaa, vb->bsize);
+#endif
+
+ BUG_ON(NULL == icd->current_fmt);
+
+ if (buf->fmt != icd->current_fmt ||
+ vb->width != icd->width ||
+ vb->height != icd->height ||
+ vb->field != field) {
+ buf->fmt = icd->current_fmt;
+ vb->width = icd->width;
+ vb->height = icd->height;
+ vb->field = field;
+ vb->state = VIDEOBUF_NEEDS_INIT;
+ }
+
+ vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3);
+ if (0 != vb->baddr && vb->bsize < vb->size) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (vb->state == VIDEOBUF_NEEDS_INIT) {
+ ret = videobuf_iolock(vq, vb, NULL);
+ if (ret)
+ goto fail;
+ vb->state = VIDEOBUF_PREPARED;
+ }
+
+ return 0;
+fail:
+ free_buffer(vq, buf);
+out:
+ return ret;
+}
+
+static void sh_mobile_ceu_videobuf_queue(struct videobuf_queue *vq,
+ struct videobuf_buffer *vb)
+{
+ struct soc_camera_device *icd = vq->priv_data;
+ struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
+ unsigned long flags;
+
+ dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+ vb, vb->baddr, vb->bsize);
+
+ vb->state = VIDEOBUF_ACTIVE;
+ spin_lock_irqsave(&pcdev->lock, flags);
+ list_add_tail(&vb->queue, &pcdev->capture);
+
+ if (!pcdev->active) {
+ pcdev->active = vb;
+ sh_mobile_ceu_capture(pcdev);
+ }
+
+ spin_unlock_irqrestore(&pcdev->lock, flags);
+}
+
+static void sh_mobile_ceu_videobuf_release(struct videobuf_queue *vq,
+ struct videobuf_buffer *vb)
+{
+ free_buffer(vq, container_of(vb, struct sh_mobile_ceu_buffer, vb));
+}
+
+static struct videobuf_queue_ops sh_mobile_ceu_videobuf_ops = {
+ .buf_setup = sh_mobile_ceu_videobuf_setup,
+ .buf_prepare = sh_mobile_ceu_videobuf_prepare,
+ .buf_queue = sh_mobile_ceu_videobuf_queue,
+ .buf_release = sh_mobile_ceu_videobuf_release,
+};
+
+static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
+{
+ struct sh_mobile_ceu_dev *pcdev = data;
+ struct videobuf_buffer *vb;
+ unsigned long flags;
+
+ spin_lock_irqsave(&pcdev->lock, flags);
+
+ vb = pcdev->active;
+ list_del_init(&vb->queue);
+
+ if (!list_empty(&pcdev->capture))
+ pcdev->active = list_entry(pcdev->capture.next,
+ struct videobuf_buffer, queue);
+ else
+ pcdev->active = NULL;
+
+ sh_mobile_ceu_capture(pcdev);
+
+ vb->state = VIDEOBUF_DONE;
+ do_gettimeofday(&vb->ts);
+ vb->field_count++;
+ wake_up(&vb->done);
+ spin_unlock_irqrestore(&pcdev->lock, flags);
+
+ return IRQ_HANDLED;
+}
+
+static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
+{
+ struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
+ int ret = -EBUSY;
+
+ mutex_lock(&camera_lock);
+
+ if (pcdev->icd)
+ goto err;
+
+ dev_info(&icd->dev,
+ "SuperH Mobile CEU driver attached to camera %d\n",
+ icd->devnum);
+
+ ret = icd->ops->init(icd);
+ if (ret)
+ goto err;
+
+ ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
+ while (ceu_read(pcdev, CSTSR) & 1)
+ msleep(1);
+
+ pcdev->icd = icd;
+err:
+ mutex_unlock(&camera_lock);
+
+ return ret;
+}
+
+static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
+{
+ struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
+
+ BUG_ON(icd != pcdev->icd);
+
+ dev_info(&icd->dev,
+ "SuperH Mobile CEU driver detached from camera %d\n",
+ icd->devnum);
+
+ /* disable capture, disable interrupts */
+ ceu_write(pcdev, CEIER, 0);
+ ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
+ icd->ops->release(icd);
+ pcdev->icd = NULL;
+}
+
+static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
+ __u32 pixfmt)
+{
+ struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
+ int ret, buswidth, width, cfszr_width, cdwdr_width;
+ unsigned long camera_flags, common_flags, value;
+
+ camera_flags = icd->ops->query_bus_param(icd);
+ common_flags = soc_camera_bus_param_compatible(camera_flags,
+ pcdev->pdata->flags);
+ if (!common_flags)
+ return -EINVAL;
+
+ ret = icd->ops->set_bus_param(icd, common_flags);
+ if (ret < 0)
+ return ret;
+
+ switch (common_flags & SOCAM_DATAWIDTH_MASK) {
+ case SOCAM_DATAWIDTH_8:
+ buswidth = 8;
+ break;
+ case SOCAM_DATAWIDTH_16:
+ buswidth = 16;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ ceu_write(pcdev, CRCNTR, 0);
+ ceu_write(pcdev, CRCMPR, 0);
+
+ value = 0x00000010;
+ value |= (common_flags & SOCAM_VSYNC_ACTIVE_LOW) ? (1 << 1) : 0;
+ value |= (common_flags & SOCAM_HSYNC_ACTIVE_LOW) ? (1 << 0) : 0;
+ value |= (buswidth == 16) ? (1 << 12) : 0;
+ ceu_write(pcdev, CAMCR, value);
+
+ ceu_write(pcdev, CAPCR, 0x00300000);
+ ceu_write(pcdev, CAIFR, 0);
+
+ mdelay(1);
+
+ width = icd->width * (icd->current_fmt->depth / 8);
+ width = (buswidth == 16) ? width / 2 : width;
+ cfszr_width = (buswidth == 8) ? width / 2 : width;
+ cdwdr_width = (buswidth == 16) ? width * 2 : width;
+
+ ceu_write(pcdev, CAMOR, 0);
+ ceu_write(pcdev, CAPWR, (icd->height << 16) | width);
+ ceu_write(pcdev, CFLCR, 0); /* data fetch mode - no scaling */
+ ceu_write(pcdev, CFSZR, (icd->height << 16) | cfszr_width);
+ ceu_write(pcdev, CLFCR, 0); /* data fetch mode - no lowpass filter */
+ ceu_write(pcdev, CDOCR, 0x00000016);
+
+ ceu_write(pcdev, CDWDR, cdwdr_width);
+ ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */
+
+ /* not in bundle mode: skip CBDSR, CDAYR2, CDACR2, CDBYR2, CDBCR2 */
+ /* in data fetch mode: no need for CDACR, CDBYR, CDBCR */
+
+ return 0;
+}
+
+static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd,
+ __u32 pixfmt)
+{
+ struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
+ unsigned long camera_flags, common_flags;
+
+ camera_flags = icd->ops->query_bus_param(icd);
+ common_flags = soc_camera_bus_param_compatible(camera_flags,
+ pcdev->pdata->flags);
+ if (!common_flags)
+ return -EINVAL;
+
+ return 0;
+}
+
+static int sh_mobile_ceu_set_fmt_cap(struct soc_camera_device *icd,
+ __u32 pixfmt, struct v4l2_rect *rect)
+{
+ return icd->ops->set_fmt_cap(icd, pixfmt, rect);
+}
+
+static int sh_mobile_ceu_try_fmt_cap(struct soc_camera_device *icd,
+ struct v4l2_format *f)
+{
+ /* FIXME: calculate using depth and bus width */
+
+ if (f->fmt.pix.height < 4)
+ f->fmt.pix.height = 4;
+ if (f->fmt.pix.height > 1920)
+ f->fmt.pix.height = 1920;
+ if (f->fmt.pix.width < 2)
+ f->fmt.pix.width = 2;
+ if (f->fmt.pix.width > 2560)
+ f->fmt.pix.width = 2560;
+ f->fmt.pix.width &= ~0x01;
+ f->fmt.pix.height &= ~0x03;
+
+ /* limit to sensor capabilities */
+ return icd->ops->try_fmt_cap(icd, f);
+}
+
+static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf,
+ struct v4l2_requestbuffers *p)
+{
+ int i;
+
+ /* This is for locking debugging only. I removed spinlocks and now I
+ * check whether .prepare is ever called on a linked buffer, or whether
+ * a dma IRQ can occur for an in-work or unlinked buffer. Until now
+ * it hadn't triggered */
+ for (i = 0; i < p->count; i++) {
+ struct sh_mobile_ceu_buffer *buf;
+
+ buf = container_of(icf->vb_vidq.bufs[i],
+ struct sh_mobile_ceu_buffer, vb);
+ INIT_LIST_HEAD(&buf->vb.queue);
+ }
+
+ return 0;
+}
+
+static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt)
+{
+ struct soc_camera_file *icf = file->private_data;
+ struct sh_mobile_ceu_buffer *buf;
+
+ buf = list_entry(icf->vb_vidq.stream.next,
+ struct sh_mobile_ceu_buffer, vb.stream);
+
+ poll_wait(file, &buf->vb.done, pt);
+
+ if (buf->vb.state == VIDEOBUF_DONE ||
+ buf->vb.state == VIDEOBUF_ERROR)
+ return POLLIN|POLLRDNORM;
+
+ return 0;
+}
+
+static int sh_mobile_ceu_querycap(struct soc_camera_host *ici,
+ struct v4l2_capability *cap)
+{
+ strlcpy(cap->card, "SuperH_Mobile_CEU", sizeof(cap->card));
+ cap->version = KERNEL_VERSION(0, 0, 5);
+ cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
+ return 0;
+}
+
+static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
+ struct soc_camera_device *icd)
+{
+ struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+ struct sh_mobile_ceu_dev *pcdev = ici->priv;
+
+ videobuf_queue_dma_contig_init(q,
+ &sh_mobile_ceu_videobuf_ops,
+ &ici->dev, &pcdev->lock,
+ V4L2_BUF_TYPE_VIDEO_CAPTURE,
+ V4L2_FIELD_NONE,
+ sizeof(struct sh_mobile_ceu_buffer),
+ icd);
+}
+
+static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
+ .owner = THIS_MODULE,
+ .add = sh_mobile_ceu_add_device,
+ .remove = sh_mobile_ceu_remove_device,
+ .set_fmt_cap = sh_mobile_ceu_set_fmt_cap,
+ .try_fmt_cap = sh_mobile_ceu_try_fmt_cap,
+ .reqbufs = sh_mobile_ceu_reqbufs,
+ .poll = sh_mobile_ceu_poll,
+ .querycap = sh_mobile_ceu_querycap,
+ .try_bus_param = sh_mobile_ceu_try_bus_param,
+ .set_bus_param = sh_mobile_ceu_set_bus_param,
+ .init_videobuf = sh_mobile_ceu_init_videobuf,
+};
+
+static int sh_mobile_ceu_probe(struct platform_device *pdev)
+{
+ struct sh_mobile_ceu_dev *pcdev;
+ struct resource *res;
+ void __iomem *base;
+ unsigned int irq;
+ int err = 0;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ irq = platform_get_irq(pdev, 0);
+ if (!res || !irq) {
+ err = -ENODEV;
+ goto exit;
+ }
+
+ pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
+ if (!pcdev) {
+ dev_err(&pdev->dev, "Could not allocate pcdev\n");
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ platform_set_drvdata(pdev, pcdev);
+ INIT_LIST_HEAD(&pcdev->capture);
+ spin_lock_init(&pcdev->lock);
+
+ pcdev->pdata = pdev->dev.platform_data;
+ if (!pcdev->pdata) {
+ err = -EINVAL;
+ goto exit_kfree;
+ }
+
+ base = ioremap_nocache(res->start, res->end - res->start + 1);
+ if (!base) {
+ err = -ENXIO;
+ goto exit_kfree;
+ }
+ pcdev->irq = irq;
+ pcdev->base = base;
+ pcdev->dev = &pdev->dev;
+
+ /* request irq */
+ err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED,
+ pdev->dev.bus_id, pcdev);
+ if (err) {
+ dev_err(pcdev->dev, "Camera interrupt register failed \n");
+ goto exit_iounmap;
+ }
+
+ pcdev->ici.priv = pcdev;
+ pcdev->ici.dev.parent = &pdev->dev;
+ pcdev->ici.nr = pdev->id;
+ pcdev->ici.drv_name = pdev->dev.bus_id,
+ pcdev->ici.ops = &sh_mobile_ceu_host_ops,
+
+ err = soc_camera_host_register(&pcdev->ici);
+ if (err)
+ goto exit_free_irq;
+
+ return 0;
+
+exit_free_irq:
+ free_irq(pcdev->irq, pcdev);
+exit_iounmap:
+ iounmap(base);
+exit_kfree:
+ kfree(pcdev);
+exit:
+ return err;
+}
+
+static int sh_mobile_ceu_remove(struct platform_device *pdev)
+{
+ struct sh_mobile_ceu_dev *pcdev = platform_get_drvdata(pdev);
+
+ soc_camera_host_unregister(&pcdev->ici);
+ free_irq(pcdev->irq, pcdev);
+ iounmap(pcdev->base);
+ kfree(pcdev);
+ return 0;
+}
+
+static struct platform_driver sh_mobile_ceu_driver = {
+ .driver = {
+ .name = "sh_mobile_ceu",
+ },
+ .probe = sh_mobile_ceu_probe,
+ .remove = sh_mobile_ceu_remove,
+};
+
+static int __init sh_mobile_ceu_init(void)
+{
+ return platform_driver_register(&sh_mobile_ceu_driver);
+}
+
+static void __exit sh_mobile_ceu_exit(void)
+{
+ return platform_driver_unregister(&sh_mobile_ceu_driver);
+}
+
+module_init(sh_mobile_ceu_init);
+module_exit(sh_mobile_ceu_exit);
+
+MODULE_DESCRIPTION("SuperH Mobile CEU driver");
+MODULE_AUTHOR("Magnus Damm");
+MODULE_LICENSE("GPL");
--- /dev/null
+++ work/include/asm-sh/sh_mobile_ceu.h 2008-07-05 09:50:22.000000000 +0900
@@ -0,0 +1,10 @@
+#ifndef __ASM_SH_MOBILE_CEU_H__
+#define __ASM_SH_MOBILE_CEU_H__
+
+#include <media/soc_camera.h>
+
+struct sh_mobile_ceu_info {
+ unsigned long flags; /* SOCAM_... */
+};
+
+#endif /* __ASM_SH_MOBILE_CEU_H__ */
--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
^ permalink raw reply [flat|nested] 15+ messages in thread