soc_camera: SuperH Mobile CEU support V2
Subsystems (2)
cover soc_camera: SuperH Mobile CEU support V2
This is V2 of the SuperH Mobile CEU interface patches.
[PATCH 01/04] soc_camera: Move spinlocks
[PATCH 02/04] soc_camera: Add 16-bit bus width support [PATCH 03/04] videobuf: Add physically contiguous queue code V2 [PATCH 04/04] sh_mobile_ceu_camera: Add SuperH Mobile CEU driver V2
Changes since V1:
- dropped former V1 patches [01/07]->[04/07]
- rebased on top of [PATCH] soc_camera: make videobuf independent
- rewrote spinlock changes into the new [01/04] patch
- updated the videobuf-dma-contig code with feeback from Paulius Zaleckas
- fixed the CEU driver to work with the newly updated patches
---
Applies on top of 2.6.26-rc8-next-20080703 together with "[PATCH] soc_camera: make videobuf independent".
drivers/media/video/Kconfig | 13 drivers/media/video/Makefile | 2 drivers/media/video/pxa_camera.c | 17 drivers/media/video/sh_mobile_ceu_camera.c | 623 ++++++++++++++++++++++++++++ drivers/media/video/soc_camera.c | 39 - drivers/media/video/videobuf-dma-contig.c | 417 ++++++++++++++++++ include/asm-sh/sh_mobile_ceu.h | 10 include/media/soc_camera.h | 12 include/media/videobuf-dma-contig.h | 32 + 9 files changed, 1108 insertions(+), 57 deletions(-)
PATCH 1/4 soc_camera: Move spinlocks
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().
---
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(-)
drivers/media/video/pxa_camera.c +5 -12
@@ -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 soreturn 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. */
drivers/media/video/soc_camera.c +1 -38
@@ -183,7 +183,6 @@ static int soc_camera_open(struct inodestruct 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 inodestruct 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 ;
include/media/soc_camera.h +1 -4
@@ -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:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 2/4 soc_camera: Add 16-bit bus width support
In reply to Magnus DammThe SuperH Mobile CEU hardware supports 16-bit width bus, so extend the soc_camera code with SOCAM_DATAWIDTH_16.
---
include/media/soc_camera.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/media/soc_camera.h +4 -3
@@ -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:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 3/4 videobuf: Add physically contiguous queue code V2
In reply to Magnus DammThis 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.
---
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(+)
drivers/media/video/Kconfig +5 -0
@@ -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
drivers/media/video/Makefile +1 -0
@@ -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
drivers/media/video/videobuf-dma-contig.c new file +417 -0
417 lines not on this page · raw message
include/media/videobuf-dma-contig.h new file +32 -0
@@ -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:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list
PATCH 4/4 sh_mobile_ceu_camera: Add SuperH Mobile CEU driver V2
In reply to Magnus DammThis 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.
---
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(+)
drivers/media/video/Kconfig +8 -0
@@ -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
drivers/media/video/Makefile +1 -0
@@ -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
drivers/media/video/sh_mobile_ceu_camera.c new file +623 -0
623 lines not on this page · raw message
include/asm-sh/sh_mobile_ceu.h new file +10 -0
@@ -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__ */
Re: [PATCH 01/04] soc_camera: Move spinlocks
In reply to Magnus DammQuoted 3 lines · Magnus Damm
This patch moves the spinlock handling from
soc_camera.cto the actual camera host driver. The spinlock alloc/free callbacks are replaced with code ininit_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
Quoted 163 lines
Signed-off-by Magnus Damm <[email protected]>---
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(-)drivers/media/video/pxa_camera.c +5
-11@@ -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 soreturn 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. */ drivers/media/video/soc_camera.c +1
-38@@ -183,7 +183,6 @@ static int soc_camera_open(struct inodestruct 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 inodestruct 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 ;include/media/soc_camera.h +1
-2@@ -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 *);
include/media/soc_camera.h struct soc_camera_host_ops { · line 78
Quoted 10 lines
include/media/soc_camera.h +0
-2int (*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
Re: [PATCH 01/04] soc_camera: Move spinlocks
Quoted 6 lines · Guennadi Liakhovetski
Quoted 3 lines · Magnus Damm
This patch moves the spinlock handling from
soc_camera.cto the actual camera host driver. The spinlock alloc/free callbacks are replaced with code ininit_videobuf().
Quoted 6 lines
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
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
In reply to Magnus DammQuoted 3 lines · Magnus Damm
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 :)
Quoted 54 lines
drivers/media/video/videobuf-dma-contig.c new file +54
-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",
drivers/media/video/videobuf-dma-contig.c line 273
Quoted 10 lines
drivers/media/video/videobuf-dma-contig.c new file +10
-0+ 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 :)
Quoted 25 lines
drivers/media/video/videobuf-dma-contig.c new file +25
-0+ 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 ; +}
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
Quoted 6 lines · Paulius Zaleckas
Quoted 3 lines · Magnus Damm
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
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
Quoted 9 lines · Laurent Pinchart
Quoted 6 lines · Paulius Zaleckas
Quoted 3 lines · Magnus Damm
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
RE: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
In reply to Magnus DammMagnus,
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: [email protected]
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
-----Original Message-----
From: Magnus Damm [mailto:[email protected]]
Sent: Friday, July 04, 2008 10:54 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected];
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
[email protected]
Subject: [PATCH 03/04] videobuf: Add physically contiguous queue code
V2
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
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 supportingdma_declare_coherent_memory()can easily avoid fragmentation issues by usingdma_declare_coherent_memory()to forcedma_alloc_coherent()to allocate from a certain pre-allocated memory area.Signed-off-by Magnus Damm <[email protected]>---
Changes since V1:
- usedev_err()instead ofpr_err()
- remember size in structvideobuf_dma_contig_memory
- keep structvideobuf_dma_contig_memoryin .c file
- letvideobuf_to_dma_contig()returndma_addr_t
- implement__videobuf_sync()
- return statements, white space and other minor fixesdrivers/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(+)drivers/media/video/Kconfig +1
-0+0900@@ -24,6 +24,11 @@ config VIDEOBUF_VMALLOC select VIDEOBUF_GEN tristate
Quoted 10 lines
Quoted 10 lines
drivers/media/video/Makefile
Quoted 10 lines
drivers/media/video/Kconfig +5
-0+config VIDEOBUF_DMA_CONTIG + depends on HAS_DMA + select VIDEOBUF_GEN + tristate +config
VIDEOBUF_DVB
tristate
selectVIDEOBUF_GENdrivers/media/video/Makefile +0
-0
09:47:22.000000000
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
+0900
drivers/media/video/Makefile +0
-0@@ -88,6 +88,7 @@ obj-$(CONFIG_VIDEO_TUNER) += tuner.oobj-$(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
drivers/media/video/videobuf-dma-contig.c new file +0
-010:09:12.000000000 +0900
drivers/media/video/videobuf-dma-contig.c new file +4
-0@@ -0,0 +1,417 @@ +/* +* helper functions for physically contiguous capture buffers +* +* The functions support hardware lacking scatter gatter support
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+* (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, <[email protected]> +* +* This program is free software; you can redistribute it and/or
modify
Quoted 1 line
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c line 13
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c new file +1
-0+* it under the terms of the GNU General Public License as published
by
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/video/videobuf-dma-contig.c new file +9
-0+* 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 {
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+u32 magic; +void *vaddr; +dma_addr_t dma_handle; +unsigned long size; +}; + +#define MAGIC_DC_MEM 0x0733ac61 +#define MAGIC_CHECK (is, should)
\
Quoted 1 line
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c line 31
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c new file +1
-0+if (unlikely ((is) != (should))) {
\
Quoted 1 line
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c line 32
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c new file +1
-0+pr_err ("magic mismatch: %x expected %x\n" , is, should);
\
Quoted 1 line
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c line 33
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c new file +1
-0+BUG ();
\
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
drivers/media/video/videobuf-dma-contig.c new file +35
-0+ } + +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])
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+continue ; + +if (q->bufs[i]->map != map) +continue ; + + mem = q->bufs[i]->priv; +if (mem) { +/* This callback is called only if
kernel has
Quoted 1 line
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c line 77
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c new file +1
-0+ allocated memory and this memory is
mmapped.
Quoted 10 lines
Quoted 10 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 10 lines
drivers/media/video/videobuf-dma-contig.c new file +10
-0+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",
Quoted 4 lines
Quoted 4 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 4 lines
drivers/media/video/videobuf-dma-contig.c new file +4
-0+ i, mem->vaddr); + + dma_free_coherent(q->dev, mem->size, + mem->vaddr,
mem->dma_handle);
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
drivers/media/video/videobuf-dma-contig.c new file +48
-0+ 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; +
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+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() */
Quoted 2 lines
Quoted 2 lines
drivers/media/video/videobuf-dma-contig.c line 149
Quoted 2 lines
drivers/media/video/videobuf-dma-contig.c new file +2
-0+if (!mem->vaddr) { + dev_err(q->dev, "memory is not
alloced/mmapped.\n");
Quoted 7 lines
Quoted 7 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 7 lines
drivers/media/video/videobuf-dma-contig.c new file +7
-0+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
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+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);
Quoted 2 lines
Quoted 2 lines
drivers/media/video/videobuf-dma-contig.c line 166
Quoted 2 lines
drivers/media/video/videobuf-dma-contig.c new file +2
-0+if (!mem->vaddr) { + dev_err(q->dev, "dma_alloc_coherent %ld
failed\n",
Quoted 5 lines
Quoted 5 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 5 lines
drivers/media/video/videobuf-dma-contig.c new file +5
-0+ mem->size); +return -ENOMEM ; + } + + dev_dbg(q->dev, "dma_alloc_coherent data is at %p
(%ld)\n",
Quoted 55 lines
Quoted 55 lines
Quoted 55 lines
drivers/media/video/videobuf-dma-contig.c new file +55
-0+ 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 ;
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+ +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",
Quoted 85 lines
Quoted 85 lines
Quoted 85 lines
drivers/media/video/videobuf-dma-contig.c new file +29
-0+ 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",
drivers/media/video/videobuf-dma-contig.c new file +13
-0+ 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);
drivers/media/video/videobuf-dma-contig.c new file +10
-0+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 %08lxbuf %d\n",
drivers/media/video/videobuf-dma-contig.c new file +30
-0+ 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; +
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+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,
Quoted 11 lines
Quoted 11 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 11 lines
drivers/media/video/videobuf-dma-contig.c new file +11
-0+ 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.
Quoted 1 line
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c
Quoted 1 line
drivers/media/video/videobuf-dma-contig.c new file +1
-0+* We need that one to maintain backward
compatibility
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
drivers/media/video/videobuf-dma-contig.c new file +31
-0+* 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,
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+ 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,
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
drivers/media/video/videobuf-dma-contig.c new file +14
-0+ 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);
Quoted 8 lines
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+ +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
Quoted 2 lines
Quoted 2 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 2 lines
drivers/media/video/videobuf-dma-contig.c new file +2
-0+ release should happen inside videobuf_vm_close(). + So, it should free memory only if the memory were allocated
for
Quoted 11 lines
Quoted 11 lines
drivers/media/video/videobuf-dma-contig.c
Quoted 11 lines
drivers/media/video/videobuf-dma-contig.c new file +11
-0+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);
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/media/video/videobuf-dma-contig.c new file +5
-0+ mem->vaddr =NULL ; +} +EXPORT_SYMBOL_GPL (videobuf_dma_contig_free); + +MODULE_DESCRIPTION("helper module to manage video4linux dma contigbuffers");
drivers/media/video/videobuf-dma-contig.c new file +2
-0+MODULE_AUTHOR ("Magnus Damm" ); +MODULE_LICENSE ("GPL" );include/media/videobuf-dma-contig.h new file +0
-009:47:22.000000000 +0900
include/media/videobuf-dma-contig.h new file +1
-0@@ -0,0 +1,32 @@ +/*
Quoted 8 lines
Quoted 8 lines
include/media/videobuf-dma-contig.h line 9
Quoted 8 lines
include/media/videobuf-dma-contig.h new file +8
-0+* 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
Quoted 1 line
Quoted 1 line
include/media/videobuf-dma-contig.h line 10
Quoted 1 line
include/media/videobuf-dma-contig.h new file +1
-0+* it under the terms of the GNU General Public License as published
by
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
include/media/videobuf-dma-contig.h new file +22
-0+* 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 */
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
In reply to Paulius ZaleckasQuoted 4 lines · Paulius Zaleckas
Quoted 3 lines · Magnus Damm
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]
Quoted 13 lines
drivers/media/video/videobuf-dma-contig.c line 273
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+/* 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 isdma_mmap_coherentto deal with this), but there is a workaround:
Quoted 3 lines
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
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
Quoted 24 lines · Guennadi Liakhovetski
Quoted 4 lines · Paulius Zaleckas
Quoted 3 lines · Magnus Damm
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]
Quoted 15 lines
drivers/media/video/videobuf-dma-contig.c line 273
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+/* 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 isdma_mmap_coherentto deal with this), but there is a workaround:
mem->dma_handle>>PAGE_SHIFT,
Quoted 8 lines
Quoted 1 line
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
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
Quoted 38 lines · Magnus Damm
Quoted 22 lines · Guennadi Liakhovetski
Quoted 4 lines · Paulius Zaleckas
Quoted 3 lines · Magnus Damm
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]
Quoted 14 lines
drivers/media/video/videobuf-dma-contig.c line 273
Quoted 8 lines
drivers/media/video/videobuf-dma-contig.c new file +8
-0+/* 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 isdma_mmap_coherentto deal with this), but there is a workaround:
mem->dma_handle>>PAGE_SHIFT,Quoted 7 lines
Quoted 1 line
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 currentdma_alloc_coherent()implementation on SuperH. I do however lean towards using__pa(mem->vaddr)overmem->dma_handle, since I suspect thatmem->dma_handledoesn't have to be a physical address.
Quoted 3 lines
Paul, any thoughts about this? Can we assume that the
dma_handlereturned fromdma_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()
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
In reply to Magnus DammQuoted 10 lines · Magnus Damm
Both (
__pa(mem->vaddr)>>PAGE_SHIFT) and (mem->dma_handle>>PAGE_SHIFT) work well with the currentdma_alloc_coherent()implementation on SuperH. I do however lean towards using__pa(mem->vaddr)overmem->dma_handle, since I suspect thatmem->dma_handledoesn't have to be a physical address.Paul, any thoughts about this? Can we assume that the
dma_handlereturned fromdma_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.
Re: [PATCH 03/04] videobuf: Add physically contiguous queue code V2
Quoted 18 lines · Paul Mundt
Quoted 10 lines · Magnus Damm
Both (
__pa(mem->vaddr)>>PAGE_SHIFT) and (mem->dma_handle>>PAGE_SHIFT) work well with the currentdma_alloc_coherent()implementation on SuperH. I do however lean towards using__pa(mem->vaddr)overmem->dma_handle, since I suspect thatmem->dma_handledoesn't have to be a physical address.Paul, any thoughts about this? Can we assume that the
dma_handlereturned fromdma_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_handleusers 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.txtsimply states:
Quoted 7 lines
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_handleis 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