Re: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
> You can take the patch which adds prepare/finish methods to memory > allocators. It should not have any dependency on the other stuff from > that thread. I'm fine with merging it either together with Your patch > or via Tomasz's patchset, whatever comes first. Thank you. I'll do the job -- Federico Vaga -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
RE: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
Hello, On Friday, August 24, 2012 3:23 PM Federico Vaga wrote: > > Getting back to your patch - in your approach cpu cache handling is > > missing. I suspect that it worked fine only because it has been > > tested on some simple platform without any cpu caches (or with very > > small ones). > > Is missing from the memory allocator because I do it on the device > driver. The current operations don't allow me to do that in the memory > allocator. Memory allocator module is much more appropriate place for it. dma-sg allocator also needs a huge cleanup in this area... > > Please check the following thread: > > http://www.spinics.net/lists/linux-media/msg51768.html where Tomasz > > has posted his ongoing effort on updating and extending videobuf2 and > > dma-contig allocator. Especially the patch > > http://www.spinics.net/lists/linux-media/msg51776.html will be > > interesting for you, because cpu cache synchronization > > (dma_sync_single_for_device / dma_sync_single_for_cpu) should be > > called from prepare/finish callbacks. > > You are right, it is interesting because avoid me to use cache sync in > my driver. Can I work on these patches? > > From this page I understand that these patches are not approved yet > https://patchwork.kernel.org/project/linux-media/list/?page=2 You can take the patch which adds prepare/finish methods to memory allocators. It should not have any dependency on the other stuff from that thread. I'm fine with merging it either together with Your patch or via Tomasz's patchset, whatever comes first. Best regards -- Marek Szyprowski Samsung Poland R Center -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
> Getting back to your patch - in your approach cpu cache handling is > missing. I suspect that it worked fine only because it has been > tested on some simple platform without any cpu caches (or with very > small ones). Is missing from the memory allocator because I do it on the device driver. The current operations don't allow me to do that in the memory allocator. > Please check the following thread: > http://www.spinics.net/lists/linux-media/msg51768.html where Tomasz > has posted his ongoing effort on updating and extending videobuf2 and > dma-contig allocator. Especially the patch > http://www.spinics.net/lists/linux-media/msg51776.html will be > interesting for you, because cpu cache synchronization > (dma_sync_single_for_device / dma_sync_single_for_cpu) should be > called from prepare/finish callbacks. You are right, it is interesting because avoid me to use cache sync in my driver. Can I work on these patches? >From this page I understand that these patches are not approved yet https://patchwork.kernel.org/project/linux-media/list/?page=2 -- Federico Vaga -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
Getting back to your patch - in your approach cpu cache handling is missing. I suspect that it worked fine only because it has been tested on some simple platform without any cpu caches (or with very small ones). Is missing from the memory allocator because I do it on the device driver. The current operations don't allow me to do that in the memory allocator. Please check the following thread: http://www.spinics.net/lists/linux-media/msg51768.html where Tomasz has posted his ongoing effort on updating and extending videobuf2 and dma-contig allocator. Especially the patch http://www.spinics.net/lists/linux-media/msg51776.html will be interesting for you, because cpu cache synchronization (dma_sync_single_for_device / dma_sync_single_for_cpu) should be called from prepare/finish callbacks. You are right, it is interesting because avoid me to use cache sync in my driver. Can I work on these patches? From this page I understand that these patches are not approved yet https://patchwork.kernel.org/project/linux-media/list/?page=2 -- Federico Vaga -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
RE: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
Hello, On Friday, August 24, 2012 3:23 PM Federico Vaga wrote: Getting back to your patch - in your approach cpu cache handling is missing. I suspect that it worked fine only because it has been tested on some simple platform without any cpu caches (or with very small ones). Is missing from the memory allocator because I do it on the device driver. The current operations don't allow me to do that in the memory allocator. Memory allocator module is much more appropriate place for it. dma-sg allocator also needs a huge cleanup in this area... Please check the following thread: http://www.spinics.net/lists/linux-media/msg51768.html where Tomasz has posted his ongoing effort on updating and extending videobuf2 and dma-contig allocator. Especially the patch http://www.spinics.net/lists/linux-media/msg51776.html will be interesting for you, because cpu cache synchronization (dma_sync_single_for_device / dma_sync_single_for_cpu) should be called from prepare/finish callbacks. You are right, it is interesting because avoid me to use cache sync in my driver. Can I work on these patches? From this page I understand that these patches are not approved yet https://patchwork.kernel.org/project/linux-media/list/?page=2 You can take the patch which adds prepare/finish methods to memory allocators. It should not have any dependency on the other stuff from that thread. I'm fine with merging it either together with Your patch or via Tomasz's patchset, whatever comes first. Best regards -- Marek Szyprowski Samsung Poland RD Center -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
You can take the patch which adds prepare/finish methods to memory allocators. It should not have any dependency on the other stuff from that thread. I'm fine with merging it either together with Your patch or via Tomasz's patchset, whatever comes first. Thank you. I'll do the job -- Federico Vaga -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
RE: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
Hello, I'm really sorry for a late reply, but I was a bit busy with other stuff. On Tuesday, July 31, 2012 10:17 PM Federico Vaga wrote: > Signed-off-by: Federico Vaga > --- > drivers/media/video/Kconfig | 6 +- > drivers/media/video/Makefile | 1 + > drivers/media/video/videobuf2-dma-streaming.c | 187 > ++ > include/media/videobuf2-dma-streaming.h | 24 > 4 file modificati, 217 inserzioni(+). 1 rimozione(-) > create mode 100644 drivers/media/video/videobuf2-dma-streaming.c > create mode 100644 include/media/videobuf2-dma-streaming.h > > diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig > index be6d718..6c60b59 100644 > --- a/drivers/media/video/Kconfig > +++ b/drivers/media/video/Kconfig > @@ -59,6 +59,10 @@ config VIDEOBUF2_DMA_NC > select VIDEOBUF2_CORE > select VIDEOBUF2_MEMOPS > tristate > +config VIDEOBUF2_DMA_STREAMING > + select VIDEOBUF2_CORE > + select VIDEOBUF2_MEMOPS > + tristate > > config VIDEOBUF2_VMALLOC > select VIDEOBUF2_CORE > @@ -844,7 +848,7 @@ config STA2X11_VIP > tristate "STA2X11 VIP Video For Linux" > depends on STA2X11 > select VIDEO_ADV7180 if VIDEO_HELPER_CHIPS_AUTO > - select VIDEOBUF_DMA_CONTIG > + select VIDEOBUF2_DMA_STREAMING This doesn't look like a part of this part. > depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS > help > Say Y for support for STA2X11 VIP (Video Input Port) capture > diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile > index 30234af..c1a08b9e 100644 > --- a/drivers/media/video/Makefile > +++ b/drivers/media/video/Makefile > @@ -140,6 +140,7 @@ obj-$(CONFIG_VIDEOBUF2_VMALLOC) += > videobuf2-vmalloc.o > obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o > obj-$(CONFIG_VIDEOBUF2_DMA_SG) += videobuf2-dma-sg.o > obj-$(CONFIG_VIDEOBUF2_DMA_NC) += videobuf2-dma-nc.o > +obj-$(CONFIG_VIDEOBUF2_DMA_STREAMING)+= videobuf2-dma-streaming.o > > obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o > > diff --git a/drivers/media/video/videobuf2-dma-streaming.c > b/drivers/media/video/videobuf2- > dma-streaming.c > new file mode 100644 > index 000..d96d3d9 > --- /dev/null > +++ b/drivers/media/video/videobuf2-dma-streaming.c > @@ -0,0 +1,187 @@ > +/* > + * videobuf2-dma-streaming.c - DMA streaming memory allocator for videobuf2 > + * > + * Copyright (C) 2012 Federico Vaga > + * * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + */ > + > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +struct vb2_streaming_conf { > + struct device *dev; > +}; > +struct vb2_streaming_buf { > + struct vb2_streaming_conf *conf; > + void*vaddr; > + > + dma_addr_t dma_handle; > + > + unsigned long size; > + struct vm_area_struct *vma; > + > + atomic_trefcount; > + struct vb2_vmarea_handler handler; > +}; > + > +static void vb2_dma_streaming_put(void *buf_priv) > +{ > + struct vb2_streaming_buf *buf = buf_priv; > + > + if (atomic_dec_and_test(>refcount)) { > + dma_unmap_single(buf->conf->dev, buf->dma_handle, buf->size, > + DMA_FROM_DEVICE); > + free_pages_exact(buf->vaddr, buf->size); > + kfree(buf); > + } > + > +} > + > +static void *vb2_dma_streaming_alloc(void *alloc_ctx, unsigned long size) > +{ > + struct vb2_streaming_conf *conf = alloc_ctx; > + struct vb2_streaming_buf *buf; > + int err; > + > + buf = kzalloc(sizeof *buf, GFP_KERNEL); > + if (!buf) > + return ERR_PTR(-ENOMEM); > + buf->vaddr = alloc_pages_exact(size, GFP_KERNEL | GFP_DMA); > + if (!buf->vaddr) { > + err = -ENOMEM; > + goto out; > + } > + buf->dma_handle = dma_map_single(conf->dev, buf->vaddr, size, > + DMA_FROM_DEVICE); > + err = dma_mapping_error(conf->dev, buf->dma_handle); > + if (err) { > + dev_err(conf->dev, "dma_map_single failed\n"); > + > + free_pages_exact(buf->vaddr, size); > + buf->vaddr = NULL; > + goto out_pages; > + } > + buf->conf = conf; > + buf->size = size; > + buf->handler.refcount = >refcount; > + buf->handler.put = vb2_dma_streaming_put; > + buf->handler.arg = buf; > + > + atomic_inc(>refcount); > + return buf; > + > +out_pages: > + free_pages_exact(buf->vaddr, buf->size); > +out: > + kfree(buf); > + return ERR_PTR(err); > +} > + > +static void *vb2_dma_streaming_cookie(void *buf_priv)
RE: [PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
Hello, I'm really sorry for a late reply, but I was a bit busy with other stuff. On Tuesday, July 31, 2012 10:17 PM Federico Vaga wrote: Signed-off-by: Federico Vaga federico.v...@gmail.com --- drivers/media/video/Kconfig | 6 +- drivers/media/video/Makefile | 1 + drivers/media/video/videobuf2-dma-streaming.c | 187 ++ include/media/videobuf2-dma-streaming.h | 24 4 file modificati, 217 inserzioni(+). 1 rimozione(-) create mode 100644 drivers/media/video/videobuf2-dma-streaming.c create mode 100644 include/media/videobuf2-dma-streaming.h diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index be6d718..6c60b59 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -59,6 +59,10 @@ config VIDEOBUF2_DMA_NC select VIDEOBUF2_CORE select VIDEOBUF2_MEMOPS tristate +config VIDEOBUF2_DMA_STREAMING + select VIDEOBUF2_CORE + select VIDEOBUF2_MEMOPS + tristate config VIDEOBUF2_VMALLOC select VIDEOBUF2_CORE @@ -844,7 +848,7 @@ config STA2X11_VIP tristate STA2X11 VIP Video For Linux depends on STA2X11 select VIDEO_ADV7180 if VIDEO_HELPER_CHIPS_AUTO - select VIDEOBUF_DMA_CONTIG + select VIDEOBUF2_DMA_STREAMING This doesn't look like a part of this part. depends on PCI VIDEO_V4L2 VIRT_TO_BUS help Say Y for support for STA2X11 VIP (Video Input Port) capture diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 30234af..c1a08b9e 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -140,6 +140,7 @@ obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o obj-$(CONFIG_VIDEOBUF2_DMA_SG) += videobuf2-dma-sg.o obj-$(CONFIG_VIDEOBUF2_DMA_NC) += videobuf2-dma-nc.o +obj-$(CONFIG_VIDEOBUF2_DMA_STREAMING)+= videobuf2-dma-streaming.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o diff --git a/drivers/media/video/videobuf2-dma-streaming.c b/drivers/media/video/videobuf2- dma-streaming.c new file mode 100644 index 000..d96d3d9 --- /dev/null +++ b/drivers/media/video/videobuf2-dma-streaming.c @@ -0,0 +1,187 @@ +/* + * videobuf2-dma-streaming.c - DMA streaming memory allocator for videobuf2 + * + * Copyright (C) 2012 Federico Vaga federico.v...@gmail.com + * * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include linux/module.h +#include linux/slab.h +#include linux/pagemap.h +#include linux/dma-mapping.h + +#include media/videobuf2-core.h +#include media/videobuf2-dma-streaming.h +#include media/videobuf2-memops.h + +struct vb2_streaming_conf { + struct device *dev; +}; +struct vb2_streaming_buf { + struct vb2_streaming_conf *conf; + void*vaddr; + + dma_addr_t dma_handle; + + unsigned long size; + struct vm_area_struct *vma; + + atomic_trefcount; + struct vb2_vmarea_handler handler; +}; + +static void vb2_dma_streaming_put(void *buf_priv) +{ + struct vb2_streaming_buf *buf = buf_priv; + + if (atomic_dec_and_test(buf-refcount)) { + dma_unmap_single(buf-conf-dev, buf-dma_handle, buf-size, + DMA_FROM_DEVICE); + free_pages_exact(buf-vaddr, buf-size); + kfree(buf); + } + +} + +static void *vb2_dma_streaming_alloc(void *alloc_ctx, unsigned long size) +{ + struct vb2_streaming_conf *conf = alloc_ctx; + struct vb2_streaming_buf *buf; + int err; + + buf = kzalloc(sizeof *buf, GFP_KERNEL); + if (!buf) + return ERR_PTR(-ENOMEM); + buf-vaddr = alloc_pages_exact(size, GFP_KERNEL | GFP_DMA); + if (!buf-vaddr) { + err = -ENOMEM; + goto out; + } + buf-dma_handle = dma_map_single(conf-dev, buf-vaddr, size, + DMA_FROM_DEVICE); + err = dma_mapping_error(conf-dev, buf-dma_handle); + if (err) { + dev_err(conf-dev, dma_map_single failed\n); + + free_pages_exact(buf-vaddr, size); + buf-vaddr = NULL; + goto out_pages; + } + buf-conf = conf; + buf-size = size; + buf-handler.refcount = buf-refcount; + buf-handler.put = vb2_dma_streaming_put; + buf-handler.arg = buf; + + atomic_inc(buf-refcount); + return buf; + +out_pages: + free_pages_exact(buf-vaddr, buf-size); +out: + kfree(buf); + return ERR_PTR(err); +} + +static void
[PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
Signed-off-by: Federico Vaga --- drivers/media/video/Kconfig | 6 +- drivers/media/video/Makefile | 1 + drivers/media/video/videobuf2-dma-streaming.c | 187 ++ include/media/videobuf2-dma-streaming.h | 24 4 file modificati, 217 inserzioni(+). 1 rimozione(-) create mode 100644 drivers/media/video/videobuf2-dma-streaming.c create mode 100644 include/media/videobuf2-dma-streaming.h diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index be6d718..6c60b59 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -59,6 +59,10 @@ config VIDEOBUF2_DMA_NC select VIDEOBUF2_CORE select VIDEOBUF2_MEMOPS tristate +config VIDEOBUF2_DMA_STREAMING + select VIDEOBUF2_CORE + select VIDEOBUF2_MEMOPS + tristate config VIDEOBUF2_VMALLOC select VIDEOBUF2_CORE @@ -844,7 +848,7 @@ config STA2X11_VIP tristate "STA2X11 VIP Video For Linux" depends on STA2X11 select VIDEO_ADV7180 if VIDEO_HELPER_CHIPS_AUTO - select VIDEOBUF_DMA_CONTIG + select VIDEOBUF2_DMA_STREAMING depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS help Say Y for support for STA2X11 VIP (Video Input Port) capture diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 30234af..c1a08b9e 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -140,6 +140,7 @@ obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o obj-$(CONFIG_VIDEOBUF2_DMA_SG) += videobuf2-dma-sg.o obj-$(CONFIG_VIDEOBUF2_DMA_NC) += videobuf2-dma-nc.o +obj-$(CONFIG_VIDEOBUF2_DMA_STREAMING) += videobuf2-dma-streaming.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o diff --git a/drivers/media/video/videobuf2-dma-streaming.c b/drivers/media/video/videobuf2-dma-streaming.c new file mode 100644 index 000..d96d3d9 --- /dev/null +++ b/drivers/media/video/videobuf2-dma-streaming.c @@ -0,0 +1,187 @@ +/* + * videobuf2-dma-streaming.c - DMA streaming memory allocator for videobuf2 + * + * Copyright (C) 2012 Federico Vaga + * * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +#include +#include +#include + +struct vb2_streaming_conf { + struct device *dev; +}; +struct vb2_streaming_buf { + struct vb2_streaming_conf *conf; + void*vaddr; + + dma_addr_t dma_handle; + + unsigned long size; + struct vm_area_struct *vma; + + atomic_trefcount; + struct vb2_vmarea_handler handler; +}; + +static void vb2_dma_streaming_put(void *buf_priv) +{ + struct vb2_streaming_buf *buf = buf_priv; + + if (atomic_dec_and_test(>refcount)) { + dma_unmap_single(buf->conf->dev, buf->dma_handle, buf->size, +DMA_FROM_DEVICE); + free_pages_exact(buf->vaddr, buf->size); + kfree(buf); + } + +} + +static void *vb2_dma_streaming_alloc(void *alloc_ctx, unsigned long size) +{ + struct vb2_streaming_conf *conf = alloc_ctx; + struct vb2_streaming_buf *buf; + int err; + + buf = kzalloc(sizeof *buf, GFP_KERNEL); + if (!buf) + return ERR_PTR(-ENOMEM); + buf->vaddr = alloc_pages_exact(size, GFP_KERNEL | GFP_DMA); + if (!buf->vaddr) { + err = -ENOMEM; + goto out; + } + buf->dma_handle = dma_map_single(conf->dev, buf->vaddr, size, +DMA_FROM_DEVICE); + err = dma_mapping_error(conf->dev, buf->dma_handle); + if (err) { + dev_err(conf->dev, "dma_map_single failed\n"); + + free_pages_exact(buf->vaddr, size); + buf->vaddr = NULL; + goto out_pages; + } + buf->conf = conf; + buf->size = size; + buf->handler.refcount = >refcount; + buf->handler.put = vb2_dma_streaming_put; + buf->handler.arg = buf; + + atomic_inc(>refcount); + return buf; + +out_pages: + free_pages_exact(buf->vaddr, buf->size); +out: + kfree(buf); + return ERR_PTR(err); +} + +static void *vb2_dma_streaming_cookie(void *buf_priv) +{ + struct vb2_streaming_buf *buf = buf_priv; + + return (void *)buf->dma_handle; +} + +static void *vb2_dma_streaming_vaddr(void *buf_priv) +{ + struct vb2_streaming_buf *buf = buf_priv; + + if (!buf) + return NULL; + return buf->vaddr; +} + +static unsigned int vb2_dma_streaming_num_users(void *buf_priv) +{ +
[PATCH 2/3] [media] videobuf2-dma-streaming: new videobuf2 memory allocator
Signed-off-by: Federico Vaga federico.v...@gmail.com --- drivers/media/video/Kconfig | 6 +- drivers/media/video/Makefile | 1 + drivers/media/video/videobuf2-dma-streaming.c | 187 ++ include/media/videobuf2-dma-streaming.h | 24 4 file modificati, 217 inserzioni(+). 1 rimozione(-) create mode 100644 drivers/media/video/videobuf2-dma-streaming.c create mode 100644 include/media/videobuf2-dma-streaming.h diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index be6d718..6c60b59 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -59,6 +59,10 @@ config VIDEOBUF2_DMA_NC select VIDEOBUF2_CORE select VIDEOBUF2_MEMOPS tristate +config VIDEOBUF2_DMA_STREAMING + select VIDEOBUF2_CORE + select VIDEOBUF2_MEMOPS + tristate config VIDEOBUF2_VMALLOC select VIDEOBUF2_CORE @@ -844,7 +848,7 @@ config STA2X11_VIP tristate STA2X11 VIP Video For Linux depends on STA2X11 select VIDEO_ADV7180 if VIDEO_HELPER_CHIPS_AUTO - select VIDEOBUF_DMA_CONTIG + select VIDEOBUF2_DMA_STREAMING depends on PCI VIDEO_V4L2 VIRT_TO_BUS help Say Y for support for STA2X11 VIP (Video Input Port) capture diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 30234af..c1a08b9e 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -140,6 +140,7 @@ obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o obj-$(CONFIG_VIDEOBUF2_DMA_SG) += videobuf2-dma-sg.o obj-$(CONFIG_VIDEOBUF2_DMA_NC) += videobuf2-dma-nc.o +obj-$(CONFIG_VIDEOBUF2_DMA_STREAMING) += videobuf2-dma-streaming.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o diff --git a/drivers/media/video/videobuf2-dma-streaming.c b/drivers/media/video/videobuf2-dma-streaming.c new file mode 100644 index 000..d96d3d9 --- /dev/null +++ b/drivers/media/video/videobuf2-dma-streaming.c @@ -0,0 +1,187 @@ +/* + * videobuf2-dma-streaming.c - DMA streaming memory allocator for videobuf2 + * + * Copyright (C) 2012 Federico Vaga federico.v...@gmail.com + * * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include linux/module.h +#include linux/slab.h +#include linux/pagemap.h +#include linux/dma-mapping.h + +#include media/videobuf2-core.h +#include media/videobuf2-dma-streaming.h +#include media/videobuf2-memops.h + +struct vb2_streaming_conf { + struct device *dev; +}; +struct vb2_streaming_buf { + struct vb2_streaming_conf *conf; + void*vaddr; + + dma_addr_t dma_handle; + + unsigned long size; + struct vm_area_struct *vma; + + atomic_trefcount; + struct vb2_vmarea_handler handler; +}; + +static void vb2_dma_streaming_put(void *buf_priv) +{ + struct vb2_streaming_buf *buf = buf_priv; + + if (atomic_dec_and_test(buf-refcount)) { + dma_unmap_single(buf-conf-dev, buf-dma_handle, buf-size, +DMA_FROM_DEVICE); + free_pages_exact(buf-vaddr, buf-size); + kfree(buf); + } + +} + +static void *vb2_dma_streaming_alloc(void *alloc_ctx, unsigned long size) +{ + struct vb2_streaming_conf *conf = alloc_ctx; + struct vb2_streaming_buf *buf; + int err; + + buf = kzalloc(sizeof *buf, GFP_KERNEL); + if (!buf) + return ERR_PTR(-ENOMEM); + buf-vaddr = alloc_pages_exact(size, GFP_KERNEL | GFP_DMA); + if (!buf-vaddr) { + err = -ENOMEM; + goto out; + } + buf-dma_handle = dma_map_single(conf-dev, buf-vaddr, size, +DMA_FROM_DEVICE); + err = dma_mapping_error(conf-dev, buf-dma_handle); + if (err) { + dev_err(conf-dev, dma_map_single failed\n); + + free_pages_exact(buf-vaddr, size); + buf-vaddr = NULL; + goto out_pages; + } + buf-conf = conf; + buf-size = size; + buf-handler.refcount = buf-refcount; + buf-handler.put = vb2_dma_streaming_put; + buf-handler.arg = buf; + + atomic_inc(buf-refcount); + return buf; + +out_pages: + free_pages_exact(buf-vaddr, buf-size); +out: + kfree(buf); + return ERR_PTR(err); +} + +static void *vb2_dma_streaming_cookie(void *buf_priv) +{ + struct vb2_streaming_buf *buf = buf_priv; + + return (void *)buf-dma_handle; +} + +static void *vb2_dma_streaming_vaddr(void *buf_priv) +{ + struct vb2_streaming_buf *buf = buf_priv; +