RE: [PATCH 8/8] v4l: videobuf2: add CMA allocator
Hello Marek Szyprowski Wrote: > Sent: Monday, December 06, 2010 7:53 PM > To: linux-media@vger.kernel.org > Cc: m.szyprow...@samsung.com; pa...@osciak.com; kyungmin.p...@samsung.com; > andrze...@samsung.com > Subject: [PATCH 8/8] v4l: videobuf2: add CMA allocator > +struct vb2_cma_buf { > + struct vb2_cma_conf *conf; > + dma_addr_t paddr; > + unsigned long size; > + struct vm_area_struct *vma; > + atomic_trefcount; > + struct vb2_vmarea_handler handler; > +}; > + > +static void vb2_cma_put(void *buf_priv); > + > +static void *vb2_cma_alloc(void *alloc_ctx, unsigned long size) > +{ > + struct vb2_cma_conf *conf = alloc_ctx; I wonder that how to acquire vb2_cma_cont value without container_of() or explicit type conversion? Does not conversion from alloc_ctx type to vb2_cma_conf type when caller is called. > + struct vb2_cma_buf *buf; > + > + buf = kzalloc(sizeof *buf, GFP_KERNEL); > + if (!buf) > + return ERR_PTR(-ENOMEM); > + > + buf->paddr = cma_alloc(conf->dev, conf->type, size, conf- > >alignment); > + if (IS_ERR((void *)buf->paddr)) { > + printk(KERN_ERR "cma_alloc of size %ld failed\n", size); > + kfree(buf); > + return ERR_PTR(-ENOMEM); > + } > + > + buf->conf = conf; > + buf->size = size; > + > + buf->handler.refcount = &buf->refcount; > + buf->handler.put = vb2_cma_put; > + buf->handler.arg = buf; > + > + atomic_inc(&buf->refcount); > + > + return buf; > +} > + > +struct vb2_alloc_ctx *vb2_cma_init(struct device *dev, const char *type, > + unsigned long alignment); > +void vb2_cma_cleanup(struct vb2_alloc_ctx *alloc_ctx); > + > +struct vb2_alloc_ctx **vb2_cma_init_multi(struct device *dev, > + unsigned int num_planes, const char *types[], > + unsigned long alignments[]); > +void vb2_cma_cleanup_multi(struct vb2_alloc_ctx **alloc_ctxes); > + > +struct vb2_alloc_ctx *vb2_cma_init(struct device *dev, const char *type, > + unsigned long alignment); This function already exist. > +void vb2_cma_cleanup(struct vb2_alloc_ctx *alloc_ctx); Same > + > +extern const struct vb2_mem_ops vb2_cma_memops; > + > +#endif > -- > 1.7.1.569.g6f426 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-media" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 2/8] v4l: videobuf2: add generic memory handling routines
Hello~ There are a lot of code changes compared with version5 patch. Some minor comments below. Marek Szyprowski Wrote : > Sent: Monday, December 06, 2010 7:53 PM > To: linux-media@vger.kernel.org > Cc: m.szyprow...@samsung.com; pa...@osciak.com; kyungmin.p...@samsung.com; > andrze...@samsung.com > Subject: [PATCH 2/8] v4l: videobuf2: add generic memory handling routines > > From: Pawel Osciak > > Add generic memory handling routines for userspace pointer handling, > contiguous memory verification and mapping. > + > +#include Same include file is existed. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include The " media/videobuf2-memops.h" file already include "videobuf2-core.h" Why don't you remove it? > +#include > + > +/** > + * vb2_get_vma() - acquire and lock the memory area > + * @vaddr: virtual userspace address to the given area outdated comment > + * > + * This function attempts to acquire an area mapped in the userspace for > + * the duration of a hardware operation. > + * > + * Returns a virtual memory region associated with the given vaddr on > success > + * or NULL. > + */ > +struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma) > +{ > + struct vm_area_struct *vma_copy; > + > + vma_copy = kmalloc(sizeof(*vma_copy), GFP_KERNEL); > + if (vma_copy == NULL) > + return NULL; > + > + if (vma->vm_ops && vma->vm_ops->open) > + vma->vm_ops->open(vma); > + > + if (vma->vm_file) > + get_file(vma->vm_file); > + > + memcpy(vma_copy, vma, sizeof(*vma)); > + > + vma_copy->vm_mm = NULL; > + vma_copy->vm_next = NULL; > + vma_copy->vm_prev = NULL; > + > + return vma_copy; > +} > + > +/** > + * vb2_put_userptr() - release a userspace memory area outdated comment > + * @vma: virtual memory region associated with the area to be > released > + * > + * This function releases the previously acquired memory area after a > hardware > + * operation. > + */ > +void vb2_put_vma(struct vm_area_struct *vma) > +{ > + if (!vma) > + return; > + > + if (vma->vm_file) > + fput(vma->vm_file); > + > + if (vma->vm_ops && vma->vm_ops->close) > + vma->vm_ops->close(vma); > + > + kfree(vma); > +} > + > +/** > + * vb2_contig_verify_userptr() - verify contiguity of a userspace-mapped > memory outdated comment > + * @vma: virtual memory region which maps the physical memory > + * to be verified outdated comment > + * @vaddr: starting virtual address of the area to be verified > + * @size:size of the area to be verified > + * @paddr: will return physical address for the given vaddr outdated comment > + * > + * This function will go through memory area of size size mapped at vaddr > and > + * verify that the underlying physical pages are contiguous. > + * > + * Returns 0 on success and a physical address to the memory pointed > + * to by vaddr in paddr. > + */ > +int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size, > +struct vm_area_struct **res_vma, dma_addr_t *res_pa) > +{ You mentioned that dma-sg and iommu allocators will definitely call get_user_pages(). There are dms-sg allocator in v6 patch. How to apply it? -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 7/7] v4l: videobuf2: add CMA allocator
Hi~ Simply comments below Marek Szyprowski Saturday, November 20, 2010 12:56 AM Wrote: snip > +/* > + * videobuf2-cma.h - CMA memory allocator for videobuf2 > + * > + * Copyright (C) 2010 Samsung Electronics > + * > + * Author: Pawel Osciak > + * > + * 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. > + */ > + > +static inline unsigned long vb2_cma_plane_paddr(struct vb2_buffer *vb, > + unsigned int plane_no) > +{ > + return (unsigned long)vb2_plane_cookie(vb, plane_no); vb2_plane_cookie() function is in the videobuf2-core. So, this header file should include "" > +} > + > +struct vb2_alloc_ctx *vb2_cma_init(struct device *dev, const char *type, > + unsigned long alignment); > +void vb2_cma_cleanup(struct vb2_alloc_ctx *alloc_ctx); > + > +struct vb2_alloc_ctx **vb2_cma_init_multi(struct device *dev, > + unsigned int num_planes, const char *types[], > + unsigned long alignments[]); > +void vb2_cma_cleanup_multi(struct vb2_alloc_ctx **alloc_ctxes); > + > +struct vb2_alloc_ctx *vb2_cma_init(struct device *dev, const char *type, > + unsigned long alignment); > +void vb2_cma_cleanup(struct vb2_alloc_ctx *alloc_ctx); > + > -- > 1.7.1.569.g6f426 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-media" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 1/7] v4l: add videobuf2 Video for Linux 2 driver framework
Hi~ Marek. Some comments in here. Saturday, November 20, 2010 12:56 AM Marek Szyprowski wrote : > To: linux-media@vger.kernel.org > Cc: m.szyprow...@samsung.com; pa...@osciak.com; kyungmin.p...@samsung.com > Subject: [PATCH 1/7] v4l: add videobuf2 Video for Linux 2 driver framework > > From: Pawel Osciak > > Videobuf2 is a Video for Linux 2 API-compatible driver framework for > multimedia devices. It acts as an intermediate layer between userspace > applications and device drivers. It also provides low-level, modular > memory management functions for drivers. > > Videobuf2 eases driver development, reduces drivers' code size and aids in > proper and consistent implementation of V4L2 API in drivers. > > Videobuf2 memory management backend is fully modular. This allows custom > memory management routines for devices and platforms with non-standard > memory management requirements to be plugged in, without changing the > high-level buffer management functions and API. > > The framework provides: > - implementations of streaming I/O V4L2 ioctls and file operations > - high-level video buffer, video queue and state management functions > - video buffer memory allocation and management > > Signed-off-by: Pawel Osciak > Signed-off-by: Marek Szyprowski > Signed-off-by: Kyungmin Park > CC: Pawel Osciak > --- > drivers/media/video/Kconfig |3 + > drivers/media/video/Makefile |2 + > drivers/media/video/videobuf2-core.c | 1435 > ++ > include/media/videobuf2-core.h | 376 + > 4 files changed, 1816 insertions(+), 0 deletions(-) > create mode 100644 drivers/media/video/videobuf2-core.c > create mode 100644 include/media/videobuf2-core.h > > diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig > index ac16e81..fef6a14 100644 > --- a/drivers/media/video/Kconfig > +++ b/drivers/media/video/Kconfig > @@ -49,6 +49,9 @@ config V4L2_MEM2MEM_DEV > tristate > depends on VIDEOBUF_GEN > > +config VIDEOBUF2_CORE > + tristate > + > # > # Multimedia Video device configuration > # > diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile > index af79d47..77c4f85 100644 > --- a/drivers/media/video/Makefile > +++ b/drivers/media/video/Makefile > @@ -114,6 +114,8 @@ obj-$(CONFIG_VIDEOBUF_VMALLOC) += videobuf-vmalloc.o > obj-$(CONFIG_VIDEOBUF_DVB) += videobuf-dvb.o > obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o > > +obj-$(CONFIG_VIDEOBUF2_CORE) += videobuf2-core.o > + > obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o > > obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o > diff --git a/drivers/media/video/videobuf2-core.c > b/drivers/media/video/videobuf2-core.c > new file mode 100644 > index 000..828803f > --- /dev/null > +++ b/drivers/media/video/videobuf2-core.c > @@ -0,0 +1,1435 @@ > +/* > + * videobuf2-core.c - V4L2 driver helper framework > + * > + * Copyright (C) 2010 Samsung Electronics > + * > + * Author: Pawel Osciak > + * Marek Szyprowski > + * > + * 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. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +static int debug; > +module_param(debug, int, 0644); > + > +#define dprintk(level, fmt, arg...) \ > + do {\ > + if (debug >= level) \ > + printk(KERN_DEBUG "vb2: " fmt, ## arg); \ > + } while (0) > + > +#define mem_ops(q, plane) ((q)->alloc_ctx[plane]->mem_ops) > + > +#define call_memop(q, plane, op, args...)\ > + ((mem_ops(q, plane)->op) ? \ > + (mem_ops(q, plane)->op(args)) : 0) > + > +#define call_qop(q, op, args...) \ > + (((q)->ops->op) ? ((q)->ops->op(args)) : 0) > + snip > +/** > + * __vb2_wait_for_done_vb() - wait for a buffer to become available > + * for dequeuing > + * > + * Will sleep if required for nonblocking == false. > + */ > +static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking) > +{ > +checks: > + if (!q->streaming) { > + dprintk(1, "Streaming off, will not wait for buffers\n"); > + return -EINVAL; > + } > + > + /* > + * Buffers may be added to vb_done_list without holding the > driver's > + * lock, but removal is performed only while holding both driver's > + * lock and the vb_done_lock spinlock. Thus we can be sure that as > + * long as we hold lock, the list will remain not empty if this > + * check succeeds. > + */ > + if (list_empty(&q->done_list)) { > + int retval; > + if (nonblocking) { > +
RE: [PATCH 4/7] v4l: videobuf2: add DMA coherent allocator
Hi Marek~ Marek Szyprowski wrote: > Sent: Wednesday, November 17, 2010 5:40 PM > To: linux-media@vger.kernel.org > Cc: m.szyprow...@samsung.com; pa...@osciak.com; kyungmin.p...@samsung.com > Subject: [PATCH 4/7] v4l: videobuf2: add DMA coherent allocator > > From: Pawel Osciak > > Add an implementation of DMA coherent memory allocator and handling > routines for videobuf2, implemented on top of dma_alloc_coherent() call. > > Signed-off-by: Pawel Osciak > Signed-off-by: Kyungmin Park > Signed-off-by: Marek Szyprowski > CC: Pawel Osciak > --- > drivers/media/video/Kconfig |5 + > drivers/media/video/Makefile |1 + > drivers/media/video/videobuf2-dma-coherent.c | 208 > ++ > include/media/videobuf2-dma-coherent.h | 27 > 4 files changed, 241 insertions(+), 0 deletions(-) > create mode 100644 drivers/media/video/videobuf2-dma-coherent.c > create mode 100644 include/media/videobuf2-dma-coherent.h > > diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig > index 9351423..e7752ee1 100644 > --- a/drivers/media/video/Kconfig > +++ b/drivers/media/video/Kconfig > @@ -55,6 +55,11 @@ config VIDEOBUF2_CORE > config VIDEOBUF2_MEMOPS > tristate > > +config VIDEOBUF2_DMA_COHERENT > + select VIDEOBUF2_CORE > + select VIDEOBUF2_MEMOPS > + tristate > + > config VIDEOBUF2_VMALLOC > select VIDEOBUF2_CORE > select VIDEOBUF2_MEMOPS > diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile > index 538bee9..baa74e7 100644 > --- a/drivers/media/video/Makefile > +++ b/drivers/media/video/Makefile > @@ -117,6 +117,7 @@ obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o > obj-$(CONFIG_VIDEOBUF2_CORE) += videobuf2-core.o > obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o > obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o > +obj-$(CONFIG_VIDEOBUF2_DMA_COHERENT) += videobuf2-dma_coherent.o > > obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o > > diff --git a/drivers/media/video/videobuf2-dma-coherent.c > b/drivers/media/video/videobuf2-dma-coherent.c > new file mode 100644 > index 000..761f366 > --- /dev/null > +++ b/drivers/media/video/videobuf2-dma-coherent.c > @@ -0,0 +1,208 @@ > +/* > + * videobuf2-dma-coherent.c - DMA coherent memory allocator for videobuf2 > + * > + * Copyright (C) 2010 Samsung Electronics > + * > + * Author: Pawel Osciak > + * > + * 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. > + */ > + > +#include > +#include > + > +#include > +#include > + > +struct vb2_dc_conf { > + struct vb2_alloc_ctxalloc_ctx; > + struct device *dev; > +}; (snip) > +static void vb2_dma_coherent_put_userptr(void *mem_priv) > +{ > + struct vb2_dc_buf *buf = mem_priv; > + > + if (!buf) > + return; > + > + vb2_put_userptr(buf->vma); > + kfree(buf); > +} > + > +const struct vb2_mem_ops vb2_dma_coherent_ops = { > + .alloc = vb2_dma_coherent_alloc, > + .put= vb2_dma_coherent_put, > + .paddr = vb2_dma_coherent_paddr, The "paddr" is not exist in vb2_mem_ops after [PATCH v4 xxx] lists. I think you should fix from paddr to cookie like CMA allocator. > + .mmap = vb2_dma_coherent_mmap, > + .get_userptr= vb2_dma_coherent_get_userptr, > + .put_userptr= vb2_dma_coherent_put_userptr, > + .num_users = vb2_dma_coherent_num_users, > +}; > + (snip) > -- > 1.7.1.569.g6f426 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-media" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 5/6 v5] V4L/DVB: s5p-fimc: Add camera capture support
Latest your reply is easy to understand. And I send you another parts review comments. Tuesday, October 12, 2010 2:27, Sylwester Nawrocki wrote : > > Add a video device driver per each FIMC entity to support > the camera capture input mode. Video capture node is registered > only if CCD sensor data is provided through driver's platfrom data > and board setup code. > > Signed-off-by: Sylwester Nawrocki > Signed-off-by: Kyungmin Park > Reviewed-by: Marek Szyprowski > --- > drivers/media/video/s5p-fimc/Makefile |2 +- > drivers/media/video/s5p-fimc/fimc-capture.c | 819 > +++ > drivers/media/video/s5p-fimc/fimc-core.c| 563 +-- > drivers/media/video/s5p-fimc/fimc-core.h| 205 +++- > drivers/media/video/s5p-fimc/fimc-reg.c | 173 +- > include/media/s3c_fimc.h| 60 ++ > 6 files changed, 1630 insertions(+), 192 deletions(-) > create mode 100644 drivers/media/video/s5p-fimc/fimc-capture.c > create mode 100644 include/media/s3c_fimc.h > > diff --git a/drivers/media/video/s5p-fimc/Makefile > b/drivers/media/video/s5p-fimc/Makefile > index 0d9d541..7ea1b14 100644 > --- a/drivers/media/video/s5p-fimc/Makefile > +++ b/drivers/media/video/s5p-fimc/Makefile > @@ -1,3 +1,3 @@ > > obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) := s5p-fimc.o > -s5p-fimc-y := fimc-core.o fimc-reg.o > +s5p-fimc-y := fimc-core.o fimc-reg.o fimc-capture.o > diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c > b/drivers/media/video/s5p-fimc/fimc-capture.c > new file mode 100644 > index 000..e8f13d3 > --- /dev/null > +++ b/drivers/media/video/s5p-fimc/fimc-capture.c > @@ -0,0 +1,819 @@ > +/* > + * Samsung S5P SoC series camera interface (camera capture) driver > + * > + * Copyright (c) 2010 Samsung Electronics Co., Ltd > + * Author: Sylwester Nawrocki, > + * > + * 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 > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "fimc-core.h" > + > +static struct v4l2_subdev *fimc_subdev_register(struct fimc_dev *fimc, > + struct s3c_fimc_isp_info *isp_info) > +{ > + struct i2c_adapter *i2c_adap; > + struct fimc_vid_cap *vid_cap = &fimc->vid_cap; > + struct v4l2_subdev *sd = NULL; > + > + i2c_adap = i2c_get_adapter(isp_info->i2c_bus_num); > + if (!i2c_adap) > + return ERR_PTR(-ENOMEM); > + > + sd = v4l2_i2c_new_subdev_board(&vid_cap->v4l2_dev, i2c_adap, > +MODULE_NAME, isp_info->board_info, NULL); > + if (!sd) { > + v4l2_err(&vid_cap->v4l2_dev, "failed to acquire subdev\n"); > + return NULL; > + } > + > + v4l2_info(&vid_cap->v4l2_dev, "subdevice %s registered > successfuly\n", > + isp_info->board_info->type); > + > + return sd; > +} > + > +static void fimc_subdev_unregister(struct fimc_dev *fimc) > +{ > + struct fimc_vid_cap *vid_cap = &fimc->vid_cap; > + struct i2c_client *client; > + > + if (vid_cap->input_index < 0) > + return; /* Subdevice already released or not registered. > */ > + > + if (vid_cap->sd) { > + v4l2_device_unregister_subdev(vid_cap->sd); > + client = v4l2_get_subdevdata(vid_cap->sd); > + i2c_unregister_device(client); > + i2c_put_adapter(client->adapter); > + vid_cap->sd = NULL; > + } > + > + vid_cap->input_index = -1; > +} (snip) > +static int fimc_cap_s_fmt(struct file *file, void *priv, > + struct v4l2_format *f) > +{ > + struct fimc_ctx *ctx = priv; > + struct fimc_dev *fimc = ctx->fimc_dev; > + struct fimc_frame *frame; > + struct v4l2_pix_format *pix; > + int ret; > + > + if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) > + return -EINVAL; > + > + ret = fimc_vidioc_try_fmt(file, priv, f); > + if (ret) > + return ret; > + > + if (mutex_lock_interruptible(&fimc->lock)) > + return -ERESTARTSYS; > + > + if (fimc_capture_active(fimc)) { > + ret = -EBUSY; > + goto sf_unlock; > + } I suggest to use vb_lock on here. You already use vb_lock "fimc_m2m_s_fmt" function in fimc-core.c code -- sample -- struct fimc_capture_device *cap = &ctx->fimc_dev->vid_cap; mutex_lock(&cap->vbq->vb->lock); > + > + frame = &ctx->d_frame; > + > + pix = &f->fmt.pix; > + frame->fmt = find_format(f, FMT_FLAGS_M2M | FMT_FLAGS_CAM); > + if (!frame->fmt) { > + err("fimc target format not found\n"); > + ret = -EINVAL; > +