All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] Refactoring Videobuf2 for common use
@ 2015-06-08 13:35 Junghak Sung
  2015-06-08 13:35 ` [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer Junghak Sung
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Junghak Sung @ 2015-06-08 13:35 UTC (permalink / raw)
  To: linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim, jh1009.sung

Hello everybody,

This patch series refactories exsiting Videobuf2, so that not only V4L2
but also other frameworks can use it to manage buffer and utilize
queue.

I would separate existing Videobuf2-core framework into two parts - common
and v4l2-specific part. This work is as follows :

1. Separate existing vb2_buffer structure into common buffer and
   v4l2-specific parts by removing v4l2-specific members and
   embedding it into vb2_v4l2_buffer structure like this:

    struct vb2_v4l2_buffer {
        struct vb2_buffer    vb2;
        struct v4l2_buffer   v4l2_buf;
        struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
    };

2. Abstract the v4l2-specific elements, and specify them when the device
   drives use them. For example, vb2_v4l2_buffer structure can be abstracted
   by vb2_buffer structure, and device drivers can get framework-specific
   object such as vb2_v4l2_buffer by using container_of().

3. Separate VB2-core framework into real VB2-core and v4l2-specific part.
   This means that it moves V4L2-specific parts of VB2-core to v4l2-specific
   part because current VB2-core framework has some codes dependent of V4L2.
   As a result, we will have two VB2 files - videobuf2-core.c and
   videobuf2-v4l2.c.

Why do we try to make the VB2 framework to be common?

As you may know, current DVB framework uses ringbuffer mechanism to demux
MPEG-2 TS data and pass it to userspace. However, this mechanism requires
extra memory copy because DVB framework provides only read() system call for
application - read() system call copies the kernel data to user-space buffer.

So if we can use VB2 framework which supports streaming I/O and buffer
sharing mechanism, then we could enhance existing DVB framework by removing
the extra memory copy - with VB2 framework, application can access the kernel
data directly through mmap system call.

This patch series is the first step for it.

We have a plan for this work as follows:

1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2,
   and VB2-dvb. Of course, this change should not affect other v4l2-based
   device drivers. This patch series includes some parts of this step.

2. Add new APIs for DVB streaming I/O. These APIs will be implemented
   in VB2-dvb framework. So, we can remove unnecessary memory copy between
   kernel-space and user-space by using these new APIs.
   However, we leaves legacy interfaces as-is for backward compatibility.

We are working on this project with Mauro and have a discussion with him
on IRC channel weekly. Nowaday, we are discussing more detailed DVB user
scenario for streaming I/O.

The final goal of this project is to enhance current DVB framework.
The first mission is to achieve zero-copy functionality between kernel-space
and user-space with mmap system call. More missions are under consideration:
i.e., we could share the buffer not only between kernel-space and user-space
but also between devices - demux, hw video codec - by exporting a buffer
to dmabuf fd with VB2 framework.

Any suggestions and comments are welcome.

Best regards,
Junghak

Junghak Sung (3):
  modify the vb2_buffer structure for common video buffer     and make
    struct vb2_v4l2_buffer
  move struct vb2_queue to common and apply the changes related with
    that     Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
  make vb2-core part with not v4l2-specific elements

 Documentation/video4linux/v4l2-pci-skeleton.c      |   16 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |   13 +-
 drivers/media/pci/cx23885/cx23885-417.c            |   13 +-
 drivers/media/pci/cx23885/cx23885-core.c           |    4 +-
 drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |   17 +-
 drivers/media/pci/cx23885/cx23885-video.c          |   19 +-
 drivers/media/pci/cx23885/cx23885.h                |    2 +-
 drivers/media/pci/cx25821/cx25821-video.c          |   20 +-
 drivers/media/pci/cx25821/cx25821.h                |    2 +-
 drivers/media/pci/cx88/cx88-blackbird.c            |   15 +-
 drivers/media/pci/cx88/cx88-core.c                 |    2 +-
 drivers/media/pci/cx88/cx88-dvb.c                  |   13 +-
 drivers/media/pci/cx88/cx88-mpeg.c                 |    2 +-
 drivers/media/pci/cx88/cx88-vbi.c                  |   17 +-
 drivers/media/pci/cx88/cx88-video.c                |   17 +-
 drivers/media/pci/cx88/cx88.h                      |    2 +-
 drivers/media/pci/saa7134/saa7134-core.c           |    4 +-
 drivers/media/pci/saa7134/saa7134-ts.c             |   28 +-
 drivers/media/pci/saa7134/saa7134-vbi.c            |   22 +-
 drivers/media/pci/saa7134/saa7134-video.c          |   17 +-
 drivers/media/pci/saa7134/saa7134.h                |    8 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   19 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   11 +-
 drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c            |   24 +-
 drivers/media/pci/tw68/tw68-video.c                |   20 +-
 drivers/media/pci/tw68/tw68.h                      |    2 +-
 drivers/media/platform/am437x/am437x-vpfe.c        |   33 +-
 drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
 drivers/media/platform/blackfin/bfin_capture.c     |   30 +-
 drivers/media/platform/coda/coda-bit.c             |   20 +-
 drivers/media/platform/coda/coda-common.c          |   28 +-
 drivers/media/platform/coda/coda-jpeg.c            |    2 +-
 drivers/media/platform/coda/coda.h                 |    6 +-
 drivers/media/platform/davinci/vpbe_display.c      |   25 +-
 drivers/media/platform/davinci/vpif_capture.c      |   30 +-
 drivers/media/platform/davinci/vpif_capture.h      |    2 +-
 drivers/media/platform/davinci/vpif_display.c      |   34 +-
 drivers/media/platform/davinci/vpif_display.h      |    6 +-
 drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
 drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
 drivers/media/platform/exynos-gsc/gsc-m2m.c        |   12 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   23 +-
 drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
 drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
 drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   25 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
 drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |   25 +-
 drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c       |   14 +-
 drivers/media/platform/m2m-deinterlace.c           |   16 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |   26 +-
 drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
 drivers/media/platform/mx2_emmaprp.c               |   16 +-
 drivers/media/platform/omap3isp/ispvideo.c         |   24 +-
 drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   23 +-
 drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
 drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
 drivers/media/platform/s5p-g2d/g2d.c               |   14 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |   34 +-
 drivers/media/platform/s5p-mfc/s5p_mfc.c           |   14 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   36 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   57 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    4 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    4 +-
 drivers/media/platform/s5p-tv/mixer.h              |    4 +-
 drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
 drivers/media/platform/s5p-tv/mixer_video.c        |   11 +-
 drivers/media/platform/sh_veu.c                    |   25 +-
 drivers/media/platform/soc_camera/atmel-isi.c      |   26 +-
 drivers/media/platform/soc_camera/mx2_camera.c     |   41 +-
 drivers/media/platform/soc_camera/mx3_camera.c     |   34 +-
 drivers/media/platform/soc_camera/rcar_vin.c       |   30 +-
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |   47 +-
 drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
 drivers/media/platform/ti-vpe/vpe.c                |   30 +-
 drivers/media/platform/vim2m.c                     |   28 +-
 drivers/media/platform/vivid/vivid-core.h          |    4 +-
 drivers/media/platform/vivid/vivid-kthread-cap.c   |    8 +-
 drivers/media/platform/vivid/vivid-kthread-out.c   |    8 +-
 drivers/media/platform/vivid/vivid-sdr-cap.c       |   18 +-
 drivers/media/platform/vivid/vivid-vbi-cap.c       |   14 +-
 drivers/media/platform/vivid/vivid-vbi-out.c       |   14 +-
 drivers/media/platform/vivid/vivid-vid-cap.c       |   24 +-
 drivers/media/platform/vivid/vivid-vid-out.c       |   21 +-
 drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
 drivers/media/platform/vsp1/vsp1_video.c           |   20 +-
 drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
 drivers/media/usb/airspy/airspy.c                  |   15 +-
 drivers/media/usb/au0828/au0828-vbi.c              |   17 +-
 drivers/media/usb/au0828/au0828-video.c            |   29 +-
 drivers/media/usb/au0828/au0828.h                  |    2 +-
 drivers/media/usb/em28xx/em28xx-vbi.c              |   15 +-
 drivers/media/usb/em28xx/em28xx-video.c            |   30 +-
 drivers/media/usb/em28xx/em28xx.h                  |    2 +-
 drivers/media/usb/go7007/go7007-driver.c           |    2 +-
 drivers/media/usb/go7007/go7007-priv.h             |    4 +-
 drivers/media/usb/go7007/go7007-v4l2.c             |   15 +-
 drivers/media/usb/hackrf/hackrf.c                  |   13 +-
 drivers/media/usb/msi2500/msi2500.c                |   13 +-
 drivers/media/usb/pwc/pwc-if.c                     |   26 +-
 drivers/media/usb/pwc/pwc.h                        |    2 +-
 drivers/media/usb/s2255/s2255drv.c                 |   16 +-
 drivers/media/usb/stk1160/stk1160-v4l.c            |   15 +-
 drivers/media/usb/stk1160/stk1160-video.c          |    2 +-
 drivers/media/usb/stk1160/stk1160.h                |    4 +-
 drivers/media/usb/usbtv/usbtv-video.c              |   11 +-
 drivers/media/usb/usbtv/usbtv.h                    |    2 +-
 drivers/media/usb/uvc/uvc_queue.c                  |   32 +-
 drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
 drivers/media/v4l2-core/Makefile                   |    2 +-
 drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
 drivers/media/v4l2-core/v4l2-mem2mem.c             |    8 +-
 drivers/media/v4l2-core/videobuf2-core.c           | 1888 ++------------------
 drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
 drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
 drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
 drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
 drivers/media/v4l2-core/videobuf2-v4l2.c           | 1878 +++++++++++++++++++
 drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
 drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
 drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
 drivers/staging/media/omap4iss/iss_video.c         |   16 +-
 drivers/staging/media/omap4iss/iss_video.h         |    4 +-
 drivers/usb/gadget/function/uvc_queue.c            |   14 +-
 drivers/usb/gadget/function/uvc_queue.h            |    4 +-
 include/media/davinci/vpbe_display.h               |    2 +-
 include/media/soc_camera.h                         |    2 +-
 include/media/v4l2-mem2mem.h                       |   10 +-
 include/media/videobuf2-core.h                     |  235 ++-
 include/media/videobuf2-dma-contig.h               |    6 +-
 include/media/videobuf2-dma-sg.h                   |    6 +-
 include/media/videobuf2-dvb.h                      |    2 +-
 include/media/videobuf2-memops.h                   |    2 +-
 include/media/videobuf2-v4l2.h                     |  139 ++
 include/media/videobuf2-vmalloc.h                  |    2 +-
 144 files changed, 3290 insertions(+), 2662 deletions(-)
 create mode 100644 drivers/media/v4l2-core/videobuf2-v4l2.c
 create mode 100644 include/media/videobuf2-v4l2.h

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer
  2015-06-08 13:35 [RFC PATCH 0/3] Refactoring Videobuf2 for common use Junghak Sung
@ 2015-06-08 13:35 ` Junghak Sung
  2015-06-12  9:58   ` Hans Verkuil
  2015-06-17 12:27   ` Mauro Carvalho Chehab
  2015-06-08 13:35 ` [RFC PATCH 3/3] make vb2-core part with not v4l2-specific elements Junghak Sung
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 15+ messages in thread
From: Junghak Sung @ 2015-06-08 13:35 UTC (permalink / raw)
  To: linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim, jh1009.sung

Make the struct vb2_buffer to common buffer by removing v4l2-specific members.
And common video buffer is embedded into v4l2-specific video buffer like:
struct vb2_v4l2_buffer {
    struct vb2_buffer    vb2;
    struct v4l2_buffer    v4l2_buf;
    struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
};
This changes require the modifications of all device drivers that use this structure.

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
---
 Documentation/video4linux/v4l2-pci-skeleton.c      |   12 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |   10 +-
 drivers/media/pci/cx23885/cx23885-417.c            |   12 +-
 drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |   12 +-
 drivers/media/pci/cx23885/cx23885-video.c          |   12 +-
 drivers/media/pci/cx23885/cx23885.h                |    2 +-
 drivers/media/pci/cx25821/cx25821-video.c          |   12 +-
 drivers/media/pci/cx25821/cx25821.h                |    2 +-
 drivers/media/pci/cx88/cx88-blackbird.c            |   14 +-
 drivers/media/pci/cx88/cx88-dvb.c                  |   14 +-
 drivers/media/pci/cx88/cx88-vbi.c                  |   12 +-
 drivers/media/pci/cx88/cx88-video.c                |   12 +-
 drivers/media/pci/cx88/cx88.h                      |    2 +-
 drivers/media/pci/saa7134/saa7134-empress.c        |    2 +-
 drivers/media/pci/saa7134/saa7134-ts.c             |   10 +-
 drivers/media/pci/saa7134/saa7134-vbi.c            |   12 +-
 drivers/media/pci/saa7134/saa7134-video.c          |   18 +-
 drivers/media/pci/saa7134/saa7134.h                |    8 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   14 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    6 +-
 drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c            |   20 +-
 drivers/media/pci/tw68/tw68-video.c                |   12 +-
 drivers/media/pci/tw68/tw68.h                      |    2 +-
 drivers/media/platform/am437x/am437x-vpfe.c        |   16 +-
 drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
 drivers/media/platform/blackfin/bfin_capture.c     |   20 +-
 drivers/media/platform/coda/coda-bit.c             |   20 +-
 drivers/media/platform/coda/coda-common.c          |   24 +-
 drivers/media/platform/coda/coda-jpeg.c            |    2 +-
 drivers/media/platform/coda/coda.h                 |    6 +-
 drivers/media/platform/davinci/vpbe_display.c      |    8 +-
 drivers/media/platform/davinci/vpif_capture.c      |   16 +-
 drivers/media/platform/davinci/vpif_capture.h      |    2 +-
 drivers/media/platform/davinci/vpif_display.c      |   18 +-
 drivers/media/platform/davinci/vpif_display.h      |    6 +-
 drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
 drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
 drivers/media/platform/exynos-gsc/gsc-m2m.c        |   16 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   12 +-
 drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
 drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
 drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   14 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
 drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |   10 +-
 drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c       |   16 +-
 drivers/media/platform/m2m-deinterlace.c           |   16 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |   24 +-
 drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
 drivers/media/platform/mx2_emmaprp.c               |   16 +-
 drivers/media/platform/omap3isp/ispvideo.c         |    8 +-
 drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   12 +-
 drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
 drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
 drivers/media/platform/s5p-g2d/g2d.c               |   16 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |   30 +-
 drivers/media/platform/s5p-mfc/s5p_mfc.c           |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   10 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   18 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    2 +-
 drivers/media/platform/s5p-tv/mixer.h              |    4 +-
 drivers/media/platform/s5p-tv/mixer_video.c        |    4 +-
 drivers/media/platform/sh_veu.c                    |   20 +-
 drivers/media/platform/soc_camera/atmel-isi.c      |   20 +-
 drivers/media/platform/soc_camera/mx2_camera.c     |   14 +-
 drivers/media/platform/soc_camera/mx3_camera.c     |   18 +-
 drivers/media/platform/soc_camera/rcar_vin.c       |   14 +-
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |   22 +-
 drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
 drivers/media/platform/ti-vpe/vpe.c                |   26 +-
 drivers/media/platform/vim2m.c                     |   24 +-
 drivers/media/platform/vivid/vivid-core.h          |    4 +-
 drivers/media/platform/vivid/vivid-sdr-cap.c       |    8 +-
 drivers/media/platform/vivid/vivid-vbi-cap.c       |   10 +-
 drivers/media/platform/vivid/vivid-vbi-out.c       |   10 +-
 drivers/media/platform/vivid/vivid-vid-cap.c       |   12 +-
 drivers/media/platform/vivid/vivid-vid-out.c       |    8 +-
 drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
 drivers/media/platform/vsp1/vsp1_video.c           |   16 +-
 drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
 drivers/media/usb/airspy/airspy.c                  |    6 +-
 drivers/media/usb/au0828/au0828-vbi.c              |    8 +-
 drivers/media/usb/au0828/au0828-video.c            |    8 +-
 drivers/media/usb/au0828/au0828.h                  |    2 +-
 drivers/media/usb/em28xx/em28xx-vbi.c              |    8 +-
 drivers/media/usb/em28xx/em28xx-video.c            |    8 +-
 drivers/media/usb/em28xx/em28xx.h                  |    2 +-
 drivers/media/usb/go7007/go7007-priv.h             |    4 +-
 drivers/media/usb/go7007/go7007-v4l2.c             |   10 +-
 drivers/media/usb/hackrf/hackrf.c                  |    6 +-
 drivers/media/usb/msi2500/msi2500.c                |    6 +-
 drivers/media/usb/pwc/pwc-if.c                     |   18 +-
 drivers/media/usb/pwc/pwc.h                        |    2 +-
 drivers/media/usb/s2255/s2255drv.c                 |   10 +-
 drivers/media/usb/stk1160/stk1160-v4l.c            |    4 +-
 drivers/media/usb/stk1160/stk1160.h                |    4 +-
 drivers/media/usb/usbtv/usbtv-video.c              |    6 +-
 drivers/media/usb/usbtv/usbtv.h                    |    2 +-
 drivers/media/usb/uvc/uvc_queue.c                  |   14 +-
 drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
 drivers/media/v4l2-core/Makefile                   |    2 +-
 drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
 drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
 drivers/media/v4l2-core/videobuf2-core.c           |  398 +++++++++----------
 drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
 drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
 drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
 drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
 .../{videobuf2-core.c => videobuf2-v4l2.c}         |  400 ++++++++++----------
 drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
 drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
 drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
 drivers/staging/media/omap4iss/iss_video.c         |   16 +-
 drivers/staging/media/omap4iss/iss_video.h         |    4 +-
 drivers/usb/gadget/function/uvc_queue.c            |   14 +-
 drivers/usb/gadget/function/uvc_queue.h            |    4 +-
 include/media/davinci/vpbe_display.h               |    2 +-
 include/media/soc_camera.h                         |    2 +-
 include/media/v4l2-mem2mem.h                       |    8 +-
 include/media/videobuf2-core.h                     |   76 ++--
 include/media/videobuf2-dma-contig.h               |    4 +-
 include/media/videobuf2-dma-sg.h                   |    4 +-
 include/media/videobuf2-dvb.h                      |    2 +-
 include/media/videobuf2-memops.h                   |    2 +-
 .../media/{videobuf2-core.h => videobuf2-v4l2.h}   |   80 ++--
 include/media/videobuf2-vmalloc.h                  |    2 +-
 136 files changed, 1081 insertions(+), 1045 deletions(-)
 copy drivers/media/v4l2-core/{videobuf2-core.c => videobuf2-v4l2.c} (89%)
 copy include/media/{videobuf2-core.h => videobuf2-v4l2.h} (94%)

diff --git a/Documentation/video4linux/v4l2-pci-skeleton.c b/Documentation/video4linux/v4l2-pci-skeleton.c
index 7bd1b97..b1142c2 100644
--- a/Documentation/video4linux/v4l2-pci-skeleton.c
+++ b/Documentation/video4linux/v4l2-pci-skeleton.c
@@ -81,11 +81,11 @@ struct skeleton {
 };
 
 struct skel_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
-static inline struct skel_buffer *to_skel_buffer(struct vb2_buffer *vb2)
+static inline struct skel_buffer *to_skel_buffer(struct vb2_v4l2_buffer *vb2)
 {
 	return container_of(vb2, struct skel_buffer, vb);
 }
@@ -194,9 +194,9 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  * Prepare the buffer for queueing to the DMA engine: check and set the
  * payload size.
  */
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue);
+	struct skeleton *skel = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	unsigned long size = skel->format.sizeimage;
 
 	if (vb2_plane_size(vb, 0) < size) {
@@ -212,9 +212,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 /*
  * Queue this buffer to the DMA engine.
  */
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct skeleton *skel = vb2_get_drv_priv(vb->vb2_queue);
+	struct skeleton *skel = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct skel_buffer *buf = to_skel_buffer(vb);
 	unsigned long flags;
 
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 3ff8806..3ef60ba 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -103,7 +103,7 @@ static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
 
 /* intermediate buffers with raw data from the USB device */
 struct rtl2832_sdr_frame_buf {
-	struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
+	struct vb2_v4l2_buffer vb;   /* common v4l buffer stuff -- must be first */
 	struct list_head list;
 };
 
@@ -500,9 +500,9 @@ static int rtl2832_sdr_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int rtl2832_sdr_buf_prepare(struct vb2_buffer *vb)
+static int rtl2832_sdr_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	/* Don't allow queing new buffers after device disconnection */
 	if (!dev->udev)
@@ -511,9 +511,9 @@ static int rtl2832_sdr_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void rtl2832_sdr_buf_queue(struct vb2_buffer *vb)
+static void rtl2832_sdr_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct rtl2832_sdr_frame_buf *buf =
 			container_of(vb, struct rtl2832_sdr_frame_buf, vb);
 	unsigned long flags;
diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c
index 63c0ee5..89d5009 100644
--- a/drivers/media/pci/cx23885/cx23885-417.c
+++ b/drivers/media/pci/cx23885/cx23885-417.c
@@ -1153,27 +1153,27 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx23885_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer *buf =
 		container_of(vb, struct cx23885_buffer, vb);
 
 	return cx23885_buf_prepare(buf, &dev->ts1);
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx23885_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer *buf = container_of(vb,
 		struct cx23885_buffer, vb);
 
 	cx23885_free_buffer(dev, buf);
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx23885_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer   *buf = container_of(vb,
 		struct cx23885_buffer, vb);
 
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index 45fbe1e..a4af6c8 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -109,18 +109,18 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 }
 
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
+	struct cx23885_tsport *port = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer *buf =
 		container_of(vb, struct cx23885_buffer, vb);
 
 	return cx23885_buf_prepare(buf, port);
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
+	struct cx23885_tsport *port = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_dev *dev = port->dev;
 	struct cx23885_buffer *buf = container_of(vb,
 		struct cx23885_buffer, vb);
@@ -128,9 +128,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 	cx23885_free_buffer(dev, buf);
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
+	struct cx23885_tsport *port = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer   *buf = container_of(vb,
 		struct cx23885_buffer, vb);
 
diff --git a/drivers/media/pci/cx23885/cx23885-vbi.c b/drivers/media/pci/cx23885/cx23885-vbi.c
index d362d38..4c6b19e 100644
--- a/drivers/media/pci/cx23885/cx23885-vbi.c
+++ b/drivers/media/pci/cx23885/cx23885-vbi.c
@@ -136,9 +136,9 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx23885_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer *buf = container_of(vb,
 		struct cx23885_buffer, vb);
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
@@ -159,12 +159,12 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
 	struct cx23885_buffer *buf = container_of(vb,
 		struct cx23885_buffer, vb);
 
-	cx23885_free_buffer(vb->vb2_queue->drv_priv, buf);
+	cx23885_free_buffer(vb->vb2.vb2_queue->drv_priv, buf);
 }
 
 /*
@@ -188,9 +188,9 @@ static void buffer_finish(struct vb2_buffer *vb)
  * The end-result of all this that you only get an interrupt when a buffer
  * is ready, so the control flow is very easy.
  */
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx23885_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb);
 	struct cx23885_buffer *prev;
 	struct cx23885_dmaqueue *q = &dev->vbiq;
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index 5e93c68..ebec673 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -327,9 +327,9 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx23885_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer *buf =
 		container_of(vb, struct cx23885_buffer, vb);
 	u32 line0_offset, line1_offset;
@@ -407,12 +407,12 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
 	struct cx23885_buffer *buf = container_of(vb,
 		struct cx23885_buffer, vb);
 
-	cx23885_free_buffer(vb->vb2_queue->drv_priv, buf);
+	cx23885_free_buffer(vb->vb2.vb2_queue->drv_priv, buf);
 }
 
 /*
@@ -436,9 +436,9 @@ static void buffer_finish(struct vb2_buffer *vb)
  * The end-result of all this that you only get an interrupt when a buffer
  * is ready, so the control flow is very easy.
  */
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx23885_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx23885_buffer   *buf = container_of(vb,
 		struct cx23885_buffer, vb);
 	struct cx23885_buffer   *prev;
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h
index aeda8d3..bfd24f0 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -170,7 +170,7 @@ struct cx23885_riscmem {
 /* buffer for one video frame */
 struct cx23885_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head queue;
 
 	/* cx23885 specific */
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c
index 7bc495e..bb0c663 100644
--- a/drivers/media/pci/cx25821/cx25821-video.c
+++ b/drivers/media/pci/cx25821/cx25821-video.c
@@ -157,9 +157,9 @@ static int cx25821_queue_setup(struct vb2_queue *q, const struct v4l2_format *fm
 	return 0;
 }
 
-static int cx25821_buffer_prepare(struct vb2_buffer *vb)
+static int cx25821_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
+	struct cx25821_channel *chan = vb->vb2.vb2_queue->drv_priv;
 	struct cx25821_dev *dev = chan->dev;
 	struct cx25821_buffer *buf =
 		container_of(vb, struct cx25821_buffer, vb);
@@ -238,21 +238,21 @@ static int cx25821_buffer_prepare(struct vb2_buffer *vb)
 	return ret;
 }
 
-static void cx25821_buffer_finish(struct vb2_buffer *vb)
+static void cx25821_buffer_finish(struct vb2_v4l2_buffer *vb)
 {
 	struct cx25821_buffer *buf =
 		container_of(vb, struct cx25821_buffer, vb);
-	struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
+	struct cx25821_channel *chan = vb->vb2.vb2_queue->drv_priv;
 	struct cx25821_dev *dev = chan->dev;
 
 	cx25821_free_buffer(dev, buf);
 }
 
-static void cx25821_buffer_queue(struct vb2_buffer *vb)
+static void cx25821_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct cx25821_buffer *buf =
 		container_of(vb, struct cx25821_buffer, vb);
-	struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
+	struct cx25821_channel *chan = vb->vb2.vb2_queue->drv_priv;
 	struct cx25821_dev *dev = chan->dev;
 	struct cx25821_buffer *prev;
 	struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq;
diff --git a/drivers/media/pci/cx25821/cx25821.h b/drivers/media/pci/cx25821/cx25821.h
index d81a08a..fb2920c 100644
--- a/drivers/media/pci/cx25821/cx25821.h
+++ b/drivers/media/pci/cx25821/cx25821.h
@@ -127,7 +127,7 @@ struct cx25821_riscmem {
 /* buffer for one video frame */
 struct cx25821_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head queue;
 
 	/* cx25821 specific */
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index b6be46e..87cef1a 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -651,17 +651,17 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8802_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 
-	return cx8802_buf_prepare(vb->vb2_queue, dev, buf);
+	return cx8802_buf_prepare(vb->vb2.vb2_queue, dev, buf);
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8802_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
@@ -670,9 +670,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 	memset(risc, 0, sizeof(*risc));
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8802_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
 
 	cx8802_buf_queue(dev, buf);
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index 1b2ed23..f9959a4 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -97,17 +97,17 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8802_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 
-	return cx8802_buf_prepare(vb->vb2_queue, dev, buf);
+	return cx8802_buf_prepare(vb->vb2.vb2_queue, dev, buf);
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8802_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
@@ -116,9 +116,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 	memset(risc, 0, sizeof(*risc));
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8802_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
 
 	cx8802_buf_queue(dev, buf);
diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c
index 32eb7fd..b40c2a0 100644
--- a/drivers/media/pci/cx88/cx88-vbi.c
+++ b/drivers/media/pci/cx88/cx88-vbi.c
@@ -125,9 +125,9 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 }
 
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8800_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
 	unsigned int lines;
@@ -149,9 +149,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8800_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
@@ -160,9 +160,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 	memset(risc, 0, sizeof(*risc));
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8800_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
 	struct cx88_buffer    *prev;
 	struct cx88_dmaqueue  *q    = &dev->vbiq;
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index 860c98fc..5090346 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -444,9 +444,9 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8800_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_core *core = dev->core;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
@@ -497,9 +497,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8800_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
@@ -508,9 +508,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 	memset(risc, 0, sizeof(*risc));
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
+	struct cx8800_dev *dev = vb->vb2.vb2_queue->drv_priv;
 	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
 	struct cx88_buffer    *prev;
 	struct cx88_core      *core = dev->core;
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index 7748ca9..9a351fd 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h
@@ -321,7 +321,7 @@ struct cx88_riscmem {
 /* buffer for one video frame */
 struct cx88_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head       list;
 
 	/* cx88 specific */
diff --git a/drivers/media/pci/saa7134/saa7134-empress.c b/drivers/media/pci/saa7134/saa7134-empress.c
index 594dc3a..618f8412 100644
--- a/drivers/media/pci/saa7134/saa7134-empress.c
+++ b/drivers/media/pci/saa7134/saa7134-empress.c
@@ -96,7 +96,7 @@ static struct vb2_ops saa7134_empress_qops = {
 	.queue_setup	= saa7134_ts_queue_setup,
 	.buf_init	= saa7134_ts_buffer_init,
 	.buf_prepare	= saa7134_ts_buffer_prepare,
-	.buf_queue	= saa7134_vb2_buffer_queue,
+	.buf_queue	= saa7134_vb2_v4l2_buffer_queue,
 	.wait_prepare	= vb2_ops_wait_prepare,
 	.wait_finish	= vb2_ops_wait_finish,
 	.start_streaming = start_streaming,
diff --git a/drivers/media/pci/saa7134/saa7134-ts.c b/drivers/media/pci/saa7134/saa7134-ts.c
index 2709b83..e197a67 100644
--- a/drivers/media/pci/saa7134/saa7134-ts.c
+++ b/drivers/media/pci/saa7134/saa7134-ts.c
@@ -75,9 +75,9 @@ static int buffer_activate(struct saa7134_dev *dev,
 	return 0;
 }
 
-int saa7134_ts_buffer_init(struct vb2_buffer *vb2)
+int saa7134_ts_buffer_init(struct vb2_v4l2_buffer *vb2)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = vb2->vb2.vb2_queue->drv_priv;
 	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
 
 	dmaq->curr = NULL;
@@ -87,9 +87,9 @@ int saa7134_ts_buffer_init(struct vb2_buffer *vb2)
 }
 EXPORT_SYMBOL_GPL(saa7134_ts_buffer_init);
 
-int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2)
+int saa7134_ts_buffer_prepare(struct vb2_v4l2_buffer *vb2)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = vb2->vb2.vb2_queue->drv_priv;
 	struct saa7134_dev *dev = dmaq->dev;
 	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
 	struct sg_table *dma = vb2_dma_sg_plane_desc(vb2, 0);
@@ -173,7 +173,7 @@ struct vb2_ops saa7134_ts_qops = {
 	.queue_setup	= saa7134_ts_queue_setup,
 	.buf_init	= saa7134_ts_buffer_init,
 	.buf_prepare	= saa7134_ts_buffer_prepare,
-	.buf_queue	= saa7134_vb2_buffer_queue,
+	.buf_queue	= saa7134_vb2_v4l2_buffer_queue,
 	.wait_prepare	= vb2_ops_wait_prepare,
 	.wait_finish	= vb2_ops_wait_finish,
 	.stop_streaming = saa7134_ts_stop_streaming,
diff --git a/drivers/media/pci/saa7134/saa7134-vbi.c b/drivers/media/pci/saa7134/saa7134-vbi.c
index 5306e54..b26a6c3 100644
--- a/drivers/media/pci/saa7134/saa7134-vbi.c
+++ b/drivers/media/pci/saa7134/saa7134-vbi.c
@@ -81,7 +81,7 @@ static int buffer_activate(struct saa7134_dev *dev,
 			   struct saa7134_buf *buf,
 			   struct saa7134_buf *next)
 {
-	struct saa7134_dmaqueue *dmaq = buf->vb2.vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = buf->vb2.vb2.vb2_queue->drv_priv;
 	unsigned long control, base;
 
 	dprintk("buffer_activate [%p]\n", buf);
@@ -113,9 +113,9 @@ static int buffer_activate(struct saa7134_dev *dev,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb2)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb2)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = vb2->vb2.vb2_queue->drv_priv;
 	struct saa7134_dev *dev = dmaq->dev;
 	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
 	struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0);
@@ -156,9 +156,9 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_init(struct vb2_buffer *vb2)
+static int buffer_init(struct vb2_v4l2_buffer *vb2)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = vb2->vb2.vb2_queue->drv_priv;
 	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
 
 	dmaq->curr = NULL;
@@ -170,7 +170,7 @@ struct vb2_ops saa7134_vbi_qops = {
 	.queue_setup	= queue_setup,
 	.buf_init	= buffer_init,
 	.buf_prepare	= buffer_prepare,
-	.buf_queue	= saa7134_vb2_buffer_queue,
+	.buf_queue	= saa7134_vb2_v4l2_buffer_queue,
 	.wait_prepare	= vb2_ops_wait_prepare,
 	.wait_finish	= vb2_ops_wait_finish,
 	.start_streaming = saa7134_vb2_start_streaming,
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 99d09a7..2545418 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -788,7 +788,7 @@ static int buffer_activate(struct saa7134_dev *dev,
 			   struct saa7134_buf *buf,
 			   struct saa7134_buf *next)
 {
-	struct saa7134_dmaqueue *dmaq = buf->vb2.vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = buf->vb2.vb2.vb2_queue->drv_priv;
 	unsigned long base,control,bpl;
 	unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
 
@@ -866,9 +866,9 @@ static int buffer_activate(struct saa7134_dev *dev,
 	return 0;
 }
 
-static int buffer_init(struct vb2_buffer *vb2)
+static int buffer_init(struct vb2_v4l2_buffer *vb2)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = vb2->vb2.vb2_queue->drv_priv;
 	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
 
 	dmaq->curr = NULL;
@@ -876,9 +876,9 @@ static int buffer_init(struct vb2_buffer *vb2)
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb2)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb2)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = vb2->vb2.vb2_queue->drv_priv;
 	struct saa7134_dev *dev = dmaq->dev;
 	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
 	struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0);
@@ -925,15 +925,15 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 /*
  * move buffer to hardware queue
  */
-void saa7134_vb2_buffer_queue(struct vb2_buffer *vb)
+void saa7134_vb2_v4l2_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct saa7134_dmaqueue *dmaq = vb->vb2_queue->drv_priv;
+	struct saa7134_dmaqueue *dmaq = vb->vb2.vb2_queue->drv_priv;
 	struct saa7134_dev *dev = dmaq->dev;
 	struct saa7134_buf *buf = container_of(vb, struct saa7134_buf, vb2);
 
 	saa7134_buffer_queue(dev, dmaq, buf);
 }
-EXPORT_SYMBOL_GPL(saa7134_vb2_buffer_queue);
+EXPORT_SYMBOL_GPL(saa7134_vb2_v4l2_buffer_queue);
 
 int saa7134_vb2_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
@@ -991,7 +991,7 @@ static struct vb2_ops vb2_qops = {
 	.queue_setup	= queue_setup,
 	.buf_init	= buffer_init,
 	.buf_prepare	= buffer_prepare,
-	.buf_queue	= saa7134_vb2_buffer_queue,
+	.buf_queue	= saa7134_vb2_v4l2_buffer_queue,
 	.wait_prepare	= vb2_ops_wait_prepare,
 	.wait_finish	= vb2_ops_wait_finish,
 	.start_streaming = saa7134_vb2_start_streaming,
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
index 8bf0553..00f5e8f 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -456,7 +456,7 @@ struct saa7134_thread {
 /* buffer for one video/vbi/ts frame */
 struct saa7134_buf {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb2;
+	struct vb2_v4l2_buffer vb2;
 
 	/* saa7134 specific */
 	unsigned int            top_seen;
@@ -777,7 +777,7 @@ extern unsigned int video_debug;
 extern struct video_device saa7134_video_template;
 extern struct video_device saa7134_radio_template;
 
-void saa7134_vb2_buffer_queue(struct vb2_buffer *vb);
+void saa7134_vb2_v4l2_buffer_queue(struct vb2_v4l2_buffer *vb);
 int saa7134_vb2_start_streaming(struct vb2_queue *vq, unsigned int count);
 void saa7134_vb2_stop_streaming(struct vb2_queue *vq);
 
@@ -813,8 +813,8 @@ void saa7134_video_fini(struct saa7134_dev *dev);
 
 #define TS_PACKET_SIZE 188 /* TS packets 188 bytes */
 
-int saa7134_ts_buffer_init(struct vb2_buffer *vb2);
-int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2);
+int saa7134_ts_buffer_init(struct vb2_v4l2_buffer *vb2);
+int saa7134_ts_buffer_prepare(struct vb2_v4l2_buffer *vb2);
 int saa7134_ts_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[]);
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
index 53fff54..e4bd59f 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
@@ -456,7 +456,7 @@ static inline u32 vop_usec(const vop_header *vh)
 }
 
 static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
-			  struct vb2_buffer *vb, const vop_header *vh)
+			  struct vb2_v4l2_buffer *vb, const vop_header *vh)
 {
 	struct solo_dev *solo_dev = solo_enc->solo_dev;
 	struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
@@ -477,7 +477,7 @@ static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
 }
 
 static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
-		struct vb2_buffer *vb, const vop_header *vh)
+		struct vb2_v4l2_buffer *vb, const vop_header *vh)
 {
 	struct solo_dev *solo_dev = solo_enc->solo_dev;
 	struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
@@ -511,7 +511,7 @@ static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
 }
 
 static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
-			    struct vb2_buffer *vb, struct solo_enc_buf *enc_buf)
+			    struct vb2_v4l2_buffer *vb, struct solo_enc_buf *enc_buf)
 {
 	const vop_header *vh = enc_buf->vh;
 	int ret;
@@ -676,9 +676,9 @@ static int solo_enc_queue_setup(struct vb2_queue *q,
 	return 0;
 }
 
-static void solo_enc_buf_queue(struct vb2_buffer *vb)
+static void solo_enc_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vq);
 	struct solo_vb2_buf *solo_vb =
 		container_of(vb, struct solo_vb2_buf, vb);
@@ -739,9 +739,9 @@ static void solo_enc_stop_streaming(struct vb2_queue *q)
 	spin_unlock_irqrestore(&solo_enc->av_lock, flags);
 }
 
-static void solo_enc_buf_finish(struct vb2_buffer *vb)
+static void solo_enc_buf_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vb->vb2_queue);
+	struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
 
 	switch (solo_enc->fmt) {
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2.c b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
index 63ae8a6..fbf5468 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
@@ -189,7 +189,7 @@ static int solo_v4l2_set_ch(struct solo_dev *solo_dev, u8 ch)
 }
 
 static void solo_fillbuf(struct solo_dev *solo_dev,
-			 struct vb2_buffer *vb)
+			 struct vb2_v4l2_buffer *vb)
 {
 	dma_addr_t vbuf;
 	unsigned int fdma_addr;
@@ -343,9 +343,9 @@ static void solo_stop_streaming(struct vb2_queue *q)
 	INIT_LIST_HEAD(&solo_dev->vidq_active);
 }
 
-static void solo_buf_queue(struct vb2_buffer *vb)
+static void solo_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct solo_dev *solo_dev = vb2_get_drv_priv(vq);
 	struct solo_vb2_buf *solo_vb =
 		container_of(vb, struct solo_vb2_buf, vb);
diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
index 1ca54b0..516d723 100644
--- a/drivers/media/pci/solo6x10/solo6x10.h
+++ b/drivers/media/pci/solo6x10/solo6x10.h
@@ -35,7 +35,7 @@
 #include <media/v4l2-dev.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ctrls.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 #include "solo6x10-regs.h"
 
@@ -135,7 +135,7 @@ struct solo_p2m_dev {
 #define OSD_TEXT_MAX		44
 
 struct solo_vb2_buf {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 22450f5..bd1aaab 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -88,11 +88,11 @@
 
 
 struct vip_buffer {
-	struct vb2_buffer	vb;
+	struct vb2_v4l2_buffer	vb;
 	struct list_head	list;
 	dma_addr_t		dma;
 };
-static inline struct vip_buffer *to_vip_buffer(struct vb2_buffer *vb2)
+static inline struct vip_buffer *to_vip_buffer(struct vb2_v4l2_buffer *vb2)
 {
 	return container_of(vb2, struct vip_buffer, vb);
 }
@@ -285,7 +285,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 	return 0;
 };
-static int buffer_init(struct vb2_buffer *vb)
+static int buffer_init(struct vb2_v4l2_buffer *vb)
 {
 	struct vip_buffer *vip_buf = to_vip_buffer(vb);
 
@@ -294,9 +294,9 @@ static int buffer_init(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
+	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vip_buffer *vip_buf = to_vip_buffer(vb);
 	unsigned long size;
 
@@ -311,9 +311,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 	return 0;
 }
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
+	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vip_buffer *vip_buf = to_vip_buffer(vb);
 
 	spin_lock(&vip->lock);
@@ -327,9 +327,9 @@ static void buffer_queue(struct vb2_buffer *vb)
 	}
 	spin_unlock(&vip->lock);
 }
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
+	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vip_buffer *vip_buf = to_vip_buffer(vb);
 
 	/* Buffer handled, remove it from the list */
@@ -337,7 +337,7 @@ static void buffer_finish(struct vb2_buffer *vb)
 	list_del_init(&vip_buf->list);
 	spin_unlock(&vip->lock);
 
-	if (vb2_is_streaming(vb->vb2_queue))
+	if (vb2_is_streaming(vb->vb2.vb2_queue))
 		vip_active_buf_next(vip);
 }
 
diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c
index 8355e55..887bbdf 100644
--- a/drivers/media/pci/tw68/tw68-video.c
+++ b/drivers/media/pci/tw68/tw68-video.c
@@ -421,9 +421,9 @@ static int tw68_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
  * The end-result of all this that you only get an interrupt when a buffer
  * is ready, so the control flow is very easy.
  */
-static void tw68_buf_queue(struct vb2_buffer *vb)
+static void tw68_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct tw68_dev *dev = vb2_get_drv_priv(vq);
 	struct tw68_buf *buf = container_of(vb, struct tw68_buf, vb);
 	struct tw68_buf *prev;
@@ -455,9 +455,9 @@ static void tw68_buf_queue(struct vb2_buffer *vb)
  * last format set for the current buffer.  If they differ, the risc
  * code (which controls the filling of the buffer) is (re-)generated.
  */
-static int tw68_buf_prepare(struct vb2_buffer *vb)
+static int tw68_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct tw68_dev *dev = vb2_get_drv_priv(vq);
 	struct tw68_buf *buf = container_of(vb, struct tw68_buf, vb);
 	struct sg_table *dma = vb2_dma_sg_plane_desc(vb, 0);
@@ -497,9 +497,9 @@ static int tw68_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void tw68_buf_finish(struct vb2_buffer *vb)
+static void tw68_buf_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct tw68_dev *dev = vb2_get_drv_priv(vq);
 	struct tw68_buf *buf = container_of(vb, struct tw68_buf, vb);
 
diff --git a/drivers/media/pci/tw68/tw68.h b/drivers/media/pci/tw68/tw68.h
index 93f2335..e23c77c 100644
--- a/drivers/media/pci/tw68/tw68.h
+++ b/drivers/media/pci/tw68/tw68.h
@@ -134,7 +134,7 @@ struct tw68_dev;	/* forward delclaration */
 
 /* buffer for one video/vbi/ts frame */
 struct tw68_buf {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 
 	unsigned int   size;
diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
index 56a5cb0..7bdb1a4 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -306,7 +306,7 @@ static inline struct vpfe_device *to_vpfe(struct vpfe_ccdc *ccdc)
 	return container_of(ccdc, struct vpfe_device, ccdc);
 }
 
-static inline struct vpfe_cap_buffer *to_vpfe_buffer(struct vb2_buffer *vb)
+static inline struct vpfe_cap_buffer *to_vpfe_buffer(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct vpfe_cap_buffer, vb);
 }
@@ -1933,15 +1933,15 @@ static int vpfe_queue_setup(struct vb2_queue *vq,
 
 /*
  * vpfe_buffer_prepare :  callback function for buffer prepare
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  *
  * This is the callback function for buffer prepare when vb2_qbuf()
  * function is called. The buffer is prepared and user space virtual address
  * or user address is converted into  physical address
  */
-static int vpfe_buffer_prepare(struct vb2_buffer *vb)
+static int vpfe_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	vb2_set_plane_payload(vb, 0, vpfe->fmt.fmt.pix.sizeimage);
 
@@ -1955,11 +1955,11 @@ static int vpfe_buffer_prepare(struct vb2_buffer *vb)
 
 /*
  * vpfe_buffer_queue : Callback function to add buffer to DMA queue
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  */
-static void vpfe_buffer_queue(struct vb2_buffer *vb)
+static void vpfe_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vpfe_cap_buffer *buf = to_vpfe_buffer(vb);
 	unsigned long flags = 0;
 
@@ -1971,7 +1971,7 @@ static void vpfe_buffer_queue(struct vb2_buffer *vb)
 
 /*
  * vpfe_start_streaming : Starts the DMA engine for streaming
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  * @count: number of buffers
  */
 static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
diff --git a/drivers/media/platform/am437x/am437x-vpfe.h b/drivers/media/platform/am437x/am437x-vpfe.h
index 0f55735..a2cd259 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.h
+++ b/drivers/media/platform/am437x/am437x-vpfe.h
@@ -105,7 +105,7 @@ struct vpfe_config {
 };
 
 struct vpfe_cap_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index 8f66986..db9f6bb 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -55,7 +55,7 @@ struct bcap_format {
 };
 
 struct bcap_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
@@ -154,7 +154,7 @@ static const struct bcap_format bcap_formats[] = {
 
 static irqreturn_t bcap_isr(int irq, void *dev_id);
 
-static struct bcap_buffer *to_bcap_vb(struct vb2_buffer *vb)
+static struct bcap_buffer *to_bcap_vb(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct bcap_buffer, vb);
 }
@@ -302,7 +302,7 @@ static int bcap_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int bcap_buffer_init(struct vb2_buffer *vb)
+static int bcap_buffer_init(struct vb2_v4l2_buffer *vb)
 {
 	struct bcap_buffer *buf = to_bcap_vb(vb);
 
@@ -310,9 +310,9 @@ static int bcap_buffer_init(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int bcap_buffer_prepare(struct vb2_buffer *vb)
+static int bcap_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct bcap_buffer *buf = to_bcap_vb(vb);
 	unsigned long size;
 
@@ -327,9 +327,9 @@ static int bcap_buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void bcap_buffer_queue(struct vb2_buffer *vb)
+static void bcap_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct bcap_buffer *buf = to_bcap_vb(vb);
 	unsigned long flags;
 
@@ -338,9 +338,9 @@ static void bcap_buffer_queue(struct vb2_buffer *vb)
 	spin_unlock_irqrestore(&bcap_dev->lock, flags);
 }
 
-static void bcap_buffer_cleanup(struct vb2_buffer *vb)
+static void bcap_buffer_cleanup(struct vb2_v4l2_buffer *vb)
 {
-	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct bcap_buffer *buf = to_bcap_vb(vb);
 	unsigned long flags;
 
@@ -506,7 +506,7 @@ static irqreturn_t bcap_isr(int irq, void *dev_id)
 {
 	struct ppi_if *ppi = dev_id;
 	struct bcap_device *bcap_dev = ppi->priv;
-	struct vb2_buffer *vb = &bcap_dev->cur_frm->vb;
+	struct vb2_v4l2_buffer *vb = &bcap_dev->cur_frm->vb;
 	dma_addr_t addr;
 
 	spin_lock(&bcap_dev->lock);
diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 856b542..31d5286 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -24,7 +24,7 @@
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mem2mem.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 #include <media/videobuf2-vmalloc.h>
 
@@ -167,7 +167,7 @@ static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx)
 }
 
 static int coda_bitstream_queue(struct coda_ctx *ctx,
-				struct vb2_buffer *src_buf)
+				struct vb2_v4l2_buffer *src_buf)
 {
 	u32 src_size = vb2_get_plane_payload(src_buf, 0);
 	u32 n;
@@ -187,7 +187,7 @@ static int coda_bitstream_queue(struct coda_ctx *ctx,
 }
 
 static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
-				     struct vb2_buffer *src_buf)
+				     struct vb2_v4l2_buffer *src_buf)
 {
 	int ret;
 
@@ -216,7 +216,7 @@ static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
 
 void coda_fill_bitstream(struct coda_ctx *ctx)
 {
-	struct vb2_buffer *src_buf;
+	struct vb2_v4l2_buffer *src_buf;
 	struct coda_buffer_meta *meta;
 	u32 start;
 
@@ -446,7 +446,7 @@ err:
 	return ret;
 }
 
-static int coda_encode_header(struct coda_ctx *ctx, struct vb2_buffer *buf,
+static int coda_encode_header(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
 			      int header_code, u8 *header, int *size)
 {
 	struct coda_dev *dev = ctx->dev;
@@ -715,7 +715,7 @@ static int coda_start_encoding(struct coda_ctx *ctx)
 	struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
 	struct coda_q_data *q_data_src, *q_data_dst;
 	u32 bitstream_buf, bitstream_size;
-	struct vb2_buffer *buf;
+	struct vb2_v4l2_buffer *buf;
 	int gamma, ret, value;
 	u32 dst_fourcc;
 	int num_fb;
@@ -1097,7 +1097,7 @@ out:
 static int coda_prepare_encode(struct coda_ctx *ctx)
 {
 	struct coda_q_data *q_data_src, *q_data_dst;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	struct coda_dev *dev = ctx->dev;
 	int force_ipicture;
 	int quant_param = 0;
@@ -1234,7 +1234,7 @@ static int coda_prepare_encode(struct coda_ctx *ctx)
 
 static void coda_finish_encode(struct coda_ctx *ctx)
 {
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	struct coda_dev *dev = ctx->dev;
 	u32 wr_ptr, start_ptr;
 
@@ -1568,7 +1568,7 @@ static int coda_start_decoding(struct coda_ctx *ctx)
 
 static int coda_prepare_decode(struct coda_ctx *ctx)
 {
-	struct vb2_buffer *dst_buf;
+	struct vb2_v4l2_buffer *dst_buf;
 	struct coda_dev *dev = ctx->dev;
 	struct coda_q_data *q_data_dst;
 	struct coda_buffer_meta *meta;
@@ -1685,7 +1685,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 	struct coda_dev *dev = ctx->dev;
 	struct coda_q_data *q_data_src;
 	struct coda_q_data *q_data_dst;
-	struct vb2_buffer *dst_buf;
+	struct vb2_v4l2_buffer *dst_buf;
 	struct coda_buffer_meta *meta;
 	unsigned long payload;
 	int width, height;
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 6f32e6d..8983c32 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -35,7 +35,7 @@
 #include <media/v4l2-event.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mem2mem.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 #include <media/videobuf2-vmalloc.h>
 
@@ -85,7 +85,7 @@ unsigned int coda_read(struct coda_dev *dev, u32 reg)
 }
 
 void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
-		     struct vb2_buffer *buf, unsigned int reg_y)
+		     struct vb2_v4l2_buffer *buf, unsigned int reg_y)
 {
 	u32 base_y = vb2_dma_contig_plane_dma_addr(buf, 0);
 	u32 base_cb, base_cr;
@@ -1133,12 +1133,12 @@ static int coda_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int coda_buf_prepare(struct vb2_buffer *vb)
+static int coda_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct coda_q_data *q_data;
 
-	q_data = get_q_data(ctx, vb->vb2_queue->type);
+	q_data = get_q_data(ctx, vb->vb2.vb2_queue->type);
 
 	if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
 		v4l2_warn(&ctx->dev->v4l2_dev,
@@ -1151,13 +1151,13 @@ static int coda_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void coda_buf_queue(struct vb2_buffer *vb)
+static void coda_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct coda_q_data *q_data;
 
-	q_data = get_q_data(ctx, vb->vb2_queue->type);
+	q_data = get_q_data(ctx, vb->vb2.vb2_queue->type);
 
 	/*
 	 * In the decoder case, immediately try to copy the buffer into the
@@ -1172,7 +1172,7 @@ static void coda_buf_queue(struct vb2_buffer *vb)
 			coda_bit_stream_end_flag(ctx);
 		mutex_lock(&ctx->bitstream_mutex);
 		v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
-		if (vb2_is_streaming(vb->vb2_queue))
+		if (vb2_is_streaming(vb->vb2.vb2_queue))
 			coda_fill_bitstream(ctx);
 		mutex_unlock(&ctx->bitstream_mutex);
 	} else {
@@ -1224,7 +1224,7 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct coda_ctx *ctx = vb2_get_drv_priv(q);
 	struct v4l2_device *v4l2_dev = &ctx->dev->v4l2_dev;
 	struct coda_q_data *q_data_src, *q_data_dst;
-	struct vb2_buffer *buf;
+	struct vb2_v4l2_buffer *buf;
 	int ret = 0;
 
 	q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
@@ -1307,7 +1307,7 @@ static void coda_stop_streaming(struct vb2_queue *q)
 {
 	struct coda_ctx *ctx = vb2_get_drv_priv(q);
 	struct coda_dev *dev = ctx->dev;
-	struct vb2_buffer *buf;
+	struct vb2_v4l2_buffer *buf;
 
 	if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
 		v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
diff --git a/drivers/media/platform/coda/coda-jpeg.c b/drivers/media/platform/coda/coda-jpeg.c
index 8fa3e35..a065b80 100644
--- a/drivers/media/platform/coda/coda-jpeg.c
+++ b/drivers/media/platform/coda/coda-jpeg.c
@@ -177,7 +177,7 @@ int coda_jpeg_write_tables(struct coda_ctx *ctx)
 	return 0;
 }
 
-bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb)
+bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_v4l2_buffer *vb)
 {
 	void *vaddr = vb2_plane_vaddr(vb, 0);
 	u16 soi = be16_to_cpup((__be16 *)vaddr);
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index 0c35cd5..872d3ac 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -21,7 +21,7 @@
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-fh.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 #include "coda_regs.h"
 
@@ -243,7 +243,7 @@ extern int coda_debug;
 void coda_write(struct coda_dev *dev, u32 data, u32 reg);
 unsigned int coda_read(struct coda_dev *dev, u32 reg);
 void coda_write_base(struct coda_ctx *ctx, struct coda_q_data *q_data,
-		     struct vb2_buffer *buf, unsigned int reg_y);
+		     struct vb2_v4l2_buffer *buf, unsigned int reg_y);
 
 int coda_alloc_aux_buf(struct coda_dev *dev, struct coda_aux_buf *buf,
 		       size_t size, const char *name, struct dentry *parent);
@@ -293,7 +293,7 @@ void coda_bit_stream_end_flag(struct coda_ctx *ctx);
 
 int coda_h264_padding(int size, char *p);
 
-bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb);
+bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_v4l2_buffer *vb);
 int coda_jpeg_write_tables(struct coda_ctx *ctx);
 void coda_set_jpeg_compression_quality(struct coda_ctx *ctx, int quality);
 
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index c4ab46f..b4f2782 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -205,9 +205,9 @@ static irqreturn_t venc_isr(int irq, void *arg)
  * the buffer is prepared and user space virtual address is converted into
  * physical address
  */
-static int vpbe_buffer_prepare(struct vb2_buffer *vb)
+static int vpbe_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	struct vpbe_layer *layer = vb2_get_drv_priv(q);
 	struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
 	unsigned long addr;
@@ -262,12 +262,12 @@ vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  * vpbe_buffer_queue()
  * This function adds the buffer to DMA queue
  */
-static void vpbe_buffer_queue(struct vb2_buffer *vb)
+static void vpbe_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	/* Get the file handle object and layer object */
 	struct vpbe_disp_buffer *buf = container_of(vb,
 				struct vpbe_disp_buffer, vb);
-	struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vpbe_display *disp = layer->disp_dev;
 	struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
 	unsigned long flags;
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index fa0a515..1936c76 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -57,22 +57,22 @@ static u8 channel_first_int[VPIF_NUMBER_OF_OBJECTS][2] = { {1, 1} };
 /* Is set to 1 in case of SDTV formats, 2 in case of HDTV formats. */
 static int ycmux_mode;
 
-static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_buffer *vb)
+static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct vpif_cap_buffer, vb);
 }
 
 /**
  * vpif_buffer_prepare :  callback function for buffer prepare
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  *
  * This is the callback function for buffer prepare when vb2_qbuf()
  * function is called. The buffer is prepared and user space virtual address
  * or user address is converted into  physical address
  */
-static int vpif_buffer_prepare(struct vb2_buffer *vb)
+static int vpif_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	struct channel_obj *ch = vb2_get_drv_priv(q);
 	struct common_obj *common;
 	unsigned long addr;
@@ -141,11 +141,11 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq,
 
 /**
  * vpif_buffer_queue : Callback function to add buffer to DMA queue
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  */
-static void vpif_buffer_queue(struct vb2_buffer *vb)
+static void vpif_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
+	struct channel_obj *ch = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vpif_cap_buffer *buf = to_vpif_buffer(vb);
 	struct common_obj *common;
 	unsigned long flags;
@@ -162,7 +162,7 @@ static void vpif_buffer_queue(struct vb2_buffer *vb)
 
 /**
  * vpif_start_streaming : Starts the DMA engine for streaming
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  * @count: number of buffers
  */
 static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
diff --git a/drivers/media/platform/davinci/vpif_capture.h b/drivers/media/platform/davinci/vpif_capture.h
index f65d28d..6e6a659 100644
--- a/drivers/media/platform/davinci/vpif_capture.h
+++ b/drivers/media/platform/davinci/vpif_capture.h
@@ -52,7 +52,7 @@ struct video_obj {
 };
 
 struct vpif_cap_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 839c24d..830d36f 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -53,22 +53,22 @@ static struct device *vpif_dev;
 static void vpif_calculate_offsets(struct channel_obj *ch);
 static void vpif_config_addr(struct channel_obj *ch, int muxmode);
 
-static inline struct vpif_disp_buffer *to_vpif_buffer(struct vb2_buffer *vb)
+static inline struct vpif_disp_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct vpif_disp_buffer, vb);
 }
 
 /**
  * vpif_buffer_prepare :  callback function for buffer prepare
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  *
  * This is the callback function for buffer prepare when vb2_qbuf()
  * function is called. The buffer is prepared and user space virtual address
  * or user address is converted into  physical address
  */
-static int vpif_buffer_prepare(struct vb2_buffer *vb)
+static int vpif_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
+	struct channel_obj *ch = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct common_obj *common;
 
 	common = &ch->common[VPIF_VIDEO_INDEX];
@@ -79,7 +79,7 @@ static int vpif_buffer_prepare(struct vb2_buffer *vb)
 
 	vb->v4l2_buf.field = common->fmt.fmt.pix.field;
 
-	if (vb->vb2_queue->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
+	if (vb->vb2.vb2_queue->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
 		unsigned long addr = vb2_dma_contig_plane_dma_addr(vb, 0);
 
 		if (!ISALIGNED(addr + common->ytop_off) ||
@@ -132,14 +132,14 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq,
 
 /**
  * vpif_buffer_queue : Callback function to add buffer to DMA queue
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  *
  * This callback fucntion queues the buffer to DMA engine
  */
-static void vpif_buffer_queue(struct vb2_buffer *vb)
+static void vpif_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct vpif_disp_buffer *buf = to_vpif_buffer(vb);
-	struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
+	struct channel_obj *ch = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct common_obj *common;
 	unsigned long flags;
 
@@ -153,7 +153,7 @@ static void vpif_buffer_queue(struct vb2_buffer *vb)
 
 /**
  * vpif_start_streaming : Starts the DMA engine for streaming
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  * @count: number of buffers
  */
 static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
diff --git a/drivers/media/platform/davinci/vpif_display.h b/drivers/media/platform/davinci/vpif_display.h
index 7b21a76..fd1df8f 100644
--- a/drivers/media/platform/davinci/vpif_display.h
+++ b/drivers/media/platform/davinci/vpif_display.h
@@ -62,15 +62,15 @@ struct video_obj {
 };
 
 struct vpif_disp_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
 struct common_obj {
 	struct vpif_disp_buffer *cur_frm;	/* Pointer pointing to current
-						 * vb2_buffer */
+						 * vb2_v4l2_buffer */
 	struct vpif_disp_buffer *next_frm;	/* Pointer pointing to next
-						 * vb2_buffer */
+						 * vb2_v4l2_buffer */
 	struct v4l2_format fmt;			/* Used to store the format */
 	struct vb2_queue buffer_queue;		/* Buffer queue used in
 						 * video-buf */
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 2edc40b..63279a3 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -798,7 +798,7 @@ void gsc_ctrls_delete(struct gsc_ctx *ctx)
 }
 
 /* The color format (num_comp, num_planes) must be already configured. */
-int gsc_prepare_addr(struct gsc_ctx *ctx, struct vb2_buffer *vb,
+int gsc_prepare_addr(struct gsc_ctx *ctx, struct vb2_v4l2_buffer *vb,
 			struct gsc_frame *frame, struct gsc_addr *addr)
 {
 	int ret = 0;
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.h b/drivers/media/platform/exynos-gsc/gsc-core.h
index fa572aa..7dd6aef 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.h
+++ b/drivers/media/platform/exynos-gsc/gsc-core.h
@@ -19,7 +19,7 @@
 #include <linux/videodev2.h>
 #include <linux/io.h>
 #include <linux/pm_runtime.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-mem2mem.h>
@@ -136,7 +136,7 @@ struct gsc_fmt {
  * @idx : index of G-Scaler input buffer
  */
 struct gsc_input_buf {
-	struct vb2_buffer	vb;
+	struct vb2_v4l2_buffer	vb;
 	struct list_head	list;
 	int			idx;
 };
@@ -408,7 +408,7 @@ int gsc_check_scaler_ratio(struct gsc_variant *var, int sw, int sh, int dw,
 int gsc_set_scaler_info(struct gsc_ctx *ctx);
 int gsc_ctrls_create(struct gsc_ctx *ctx);
 void gsc_ctrls_delete(struct gsc_ctx *ctx);
-int gsc_prepare_addr(struct gsc_ctx *ctx, struct vb2_buffer *vb,
+int gsc_prepare_addr(struct gsc_ctx *ctx, struct vb2_v4l2_buffer *vb,
 		     struct gsc_frame *frame, struct gsc_addr *addr);
 
 static inline void gsc_ctx_state_lock_set(u32 state, struct gsc_ctx *ctx)
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index d5cffef..7f13def 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -77,7 +77,7 @@ static void gsc_m2m_stop_streaming(struct vb2_queue *q)
 
 void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state)
 {
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 
 	if (!ctx || !ctx->m2m_ctx)
 		return;
@@ -109,7 +109,7 @@ static void gsc_m2m_job_abort(void *priv)
 static int gsc_get_bufs(struct gsc_ctx *ctx)
 {
 	struct gsc_frame *s_frame, *d_frame;
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 	int ret;
 
 	s_frame = &ctx->s_frame;
@@ -235,17 +235,17 @@ static int gsc_m2m_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int gsc_m2m_buf_prepare(struct vb2_buffer *vb)
+static int gsc_m2m_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct gsc_frame *frame;
 	int i;
 
-	frame = ctx_get_frame(ctx, vb->vb2_queue->type);
+	frame = ctx_get_frame(ctx, vb->vb2.vb2_queue->type);
 	if (IS_ERR(frame))
 		return PTR_ERR(frame);
 
-	if (!V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
+	if (!V4L2_TYPE_IS_OUTPUT(vb->vb2.vb2_queue->type)) {
 		for (i = 0; i < frame->fmt->num_planes; i++)
 			vb2_set_plane_payload(vb, i, frame->payload[i]);
 	}
@@ -253,9 +253,9 @@ static int gsc_m2m_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void gsc_m2m_buf_queue(struct vb2_buffer *vb)
+static void gsc_m2m_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	pr_debug("ctx: %p, ctx->state: 0x%x", ctx, ctx->state);
 
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 8a2fd8c..24a24c5 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -24,7 +24,7 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mem2mem.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "common.h"
@@ -315,7 +315,7 @@ int fimc_capture_suspend(struct fimc_dev *fimc)
 	return fimc_pipeline_call(&fimc->vid_cap.ve, close);
 }
 
-static void buffer_queue(struct vb2_buffer *vb);
+static void buffer_queue(struct vb2_v4l2_buffer *vb);
 
 int fimc_capture_resume(struct fimc_dev *fimc)
 {
@@ -384,9 +384,9 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct fimc_ctx *ctx = vq->drv_priv;
 	int i;
 
@@ -408,11 +408,11 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct fimc_vid_buffer *buf
 		= container_of(vb, struct fimc_vid_buffer, vb);
-	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct fimc_dev *fimc = ctx->fimc_dev;
 	struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
 	struct exynos_video_entity *ve = &vid_cap->ve;
diff --git a/drivers/media/platform/exynos4-is/fimc-core.c b/drivers/media/platform/exynos4-is/fimc-core.c
index 1101c41..4dfd3ac 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.c
+++ b/drivers/media/platform/exynos4-is/fimc-core.c
@@ -27,7 +27,7 @@
 #include <linux/slab.h>
 #include <linux/clk.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "fimc-core.h"
@@ -348,7 +348,7 @@ out:
 }
 
 /* The color format (colplanes, memplanes) must be already configured. */
-int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
+int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_v4l2_buffer *vb,
 		      struct fimc_frame *frame, struct fimc_addr *paddr)
 {
 	int ret = 0;
diff --git a/drivers/media/platform/exynos4-is/fimc-core.h b/drivers/media/platform/exynos4-is/fimc-core.h
index 7328f08..042276c 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.h
+++ b/drivers/media/platform/exynos4-is/fimc-core.h
@@ -22,7 +22,7 @@
 #include <linux/sizes.h>
 
 #include <media/media-entity.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-mem2mem.h>
@@ -224,7 +224,7 @@ struct fimc_addr {
  * @index: buffer index for the output DMA engine
  */
 struct fimc_vid_buffer {
-	struct vb2_buffer	vb;
+	struct vb2_v4l2_buffer	vb;
 	struct list_head	list;
 	struct fimc_addr	paddr;
 	int			index;
@@ -634,7 +634,7 @@ int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
 			    int dw, int dh, int rotation);
 int fimc_set_scaler_info(struct fimc_ctx *ctx);
 int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags);
-int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
+int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_v4l2_buffer *vb,
 		      struct fimc_frame *frame, struct fimc_addr *paddr);
 void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f);
 void fimc_set_yuv_order(struct fimc_ctx *ctx);
diff --git a/drivers/media/platform/exynos4-is/fimc-is.h b/drivers/media/platform/exynos4-is/fimc-is.h
index e0be691..386eb49 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.h
+++ b/drivers/media/platform/exynos4-is/fimc-is.h
@@ -22,7 +22,7 @@
 #include <linux/sizes.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-ctrls.h>
 
 #include "fimc-isp.h"
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 76b6b4d..3964e27 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -28,7 +28,7 @@
 
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 #include <media/exynos-fimc.h>
 
@@ -157,9 +157,9 @@ static void isp_video_capture_stop_streaming(struct vb2_queue *q)
 	isp->video_capture.buf_count = 0;
 }
 
-static int isp_video_capture_buffer_prepare(struct vb2_buffer *vb)
+static int isp_video_capture_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2_queue);
+	struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct fimc_is_video *video = &isp->video_capture;
 	int i;
 
@@ -192,9 +192,9 @@ static int isp_video_capture_buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void isp_video_capture_buffer_queue(struct vb2_buffer *vb)
+static void isp_video_capture_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2_queue);
+	struct fimc_isp *isp = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct fimc_is_video *video = &isp->video_capture;
 	struct fimc_is *is = fimc_isp_to_is(isp);
 	struct isp_video_buf *ivb = to_isp_video_buf(vb);
@@ -232,7 +232,7 @@ static void isp_video_capture_buffer_queue(struct vb2_buffer *vb)
 	}
 
 	if (!test_bit(ST_ISP_VID_CAP_STREAMING, &isp->state))
-		isp_video_capture_start_streaming(vb->vb2_queue, 0);
+		isp_video_capture_start_streaming(vb->vb2.vb2_queue, 0);
 }
 
 /*
@@ -242,7 +242,7 @@ static void isp_video_capture_buffer_queue(struct vb2_buffer *vb)
 void fimc_isp_video_irq_handler(struct fimc_is *is)
 {
 	struct fimc_is_video *video = &is->isp.video_capture;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int buf_index;
 
 	/* TODO: Ensure the DMA is really stopped in stop_streaming callback */
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.h b/drivers/media/platform/exynos4-is/fimc-isp-video.h
index 98c6626..f79a1b3 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.h
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.h
@@ -11,7 +11,7 @@
 #ifndef FIMC_ISP_VIDEO__
 #define FIMC_ISP_VIDEO__
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include "fimc-isp.h"
 
 #ifdef CONFIG_VIDEO_EXYNOS4_ISP_DMA_CAPTURE
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.h b/drivers/media/platform/exynos4-is/fimc-isp.h
index b99be09..c2d25df 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.h
+++ b/drivers/media/platform/exynos4-is/fimc-isp.h
@@ -21,7 +21,7 @@
 #include <linux/videodev2.h>
 
 #include <media/media-entity.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-mediabus.h>
 #include <media/exynos-fimc.h>
@@ -102,7 +102,7 @@ struct fimc_isp_ctrls {
 };
 
 struct isp_video_buf {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	dma_addr_t dma_addr[FIMC_ISP_MAX_PLANES];
 	unsigned int index;
 };
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index 2510f18..32e400e 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -28,7 +28,7 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mem2mem.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 #include <media/exynos-fimc.h>
 
@@ -396,9 +396,9 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct fimc_lite *fimc = vq->drv_priv;
 	int i;
 
@@ -420,11 +420,11 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct flite_buffer *buf
 		= container_of(vb, struct flite_buffer, vb);
-	struct fimc_lite *fimc = vb2_get_drv_priv(vb->vb2_queue);
+	struct fimc_lite *fimc = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	unsigned long flags;
 
 	spin_lock_irqsave(&fimc->slock, flags);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.h b/drivers/media/platform/exynos4-is/fimc-lite.h
index ea19dc7..b302305 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.h
+++ b/drivers/media/platform/exynos4-is/fimc-lite.h
@@ -19,7 +19,7 @@
 #include <linux/videodev2.h>
 
 #include <media/media-entity.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-mediabus.h>
@@ -100,7 +100,7 @@ struct flite_frame {
  * @index: DMA start address register's index
  */
 struct flite_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 	dma_addr_t paddr;
 	unsigned short index;
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index 0ad1b6f..b876d25 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -24,7 +24,7 @@
 #include <linux/slab.h>
 #include <linux/clk.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "common.h"
@@ -42,7 +42,7 @@ static unsigned int get_m2m_fmt_flags(unsigned int stream_type)
 
 void fimc_m2m_job_finish(struct fimc_ctx *ctx, int vb_state)
 {
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 
 	if (!ctx || !ctx->fh.m2m_ctx)
 		return;
@@ -99,7 +99,7 @@ static void stop_streaming(struct vb2_queue *q)
 
 static void fimc_device_run(void *priv)
 {
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 	struct fimc_ctx *ctx = priv;
 	struct fimc_frame *sf, *df;
 	struct fimc_dev *fimc;
@@ -202,13 +202,13 @@ static int fimc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int fimc_buf_prepare(struct vb2_buffer *vb)
+static int fimc_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct fimc_frame *frame;
 	int i;
 
-	frame = ctx_get_frame(ctx, vb->vb2_queue->type);
+	frame = ctx_get_frame(ctx, vb->vb2.vb2_queue->type);
 	if (IS_ERR(frame))
 		return PTR_ERR(frame);
 
@@ -218,9 +218,9 @@ static int fimc_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void fimc_buf_queue(struct vb2_buffer *vb)
+static void fimc_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
 }
 
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index b70c1ae..5ebcf56 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -200,7 +200,7 @@ static void dma_callback(void *data)
 {
 	struct deinterlace_ctx *curr_ctx = data;
 	struct deinterlace_dev *pcdev = curr_ctx->dev;
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 
 	atomic_set(&pcdev->busy, 0);
 
@@ -225,7 +225,7 @@ static void deinterlace_issue_dma(struct deinterlace_ctx *ctx, int op,
 				  int do_callback)
 {
 	struct deinterlace_q_data *s_q_data;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	struct deinterlace_dev *pcdev = ctx->dev;
 	struct dma_chan *chan = pcdev->dma_chan;
 	struct dma_device *dmadev = chan->device;
@@ -827,14 +827,14 @@ static int deinterlace_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int deinterlace_buf_prepare(struct vb2_buffer *vb)
+static int deinterlace_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct deinterlace_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct deinterlace_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct deinterlace_q_data *q_data;
 
-	dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type);
+	dprintk(ctx->dev, "type: %d\n", vb->vb2.vb2_queue->type);
 
-	q_data = get_q_data(vb->vb2_queue->type);
+	q_data = get_q_data(vb->vb2.vb2_queue->type);
 
 	if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
 		dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n",
@@ -847,9 +847,9 @@ static int deinterlace_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void deinterlace_buf_queue(struct vb2_buffer *vb)
+static void deinterlace_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct deinterlace_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct deinterlace_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
 }
 
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index dd5b141..7ca83ba 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -212,11 +212,11 @@ struct yuv_pointer_t {
 
 /*
  * Our buffer type for working with videobuf2.  Note that the vb2
- * developers have decreed that struct vb2_buffer must be at the
+ * developers have decreed that struct vb2_v4l2_buffer must be at the
  * beginning of this structure.
  */
 struct mcam_vb_buffer {
-	struct vb2_buffer vb_buf;
+	struct vb2_v4l2_buffer vb_buf;
 	struct list_head queue;
 	struct mcam_dma_desc *dma_desc;	/* Descriptor virtual address */
 	dma_addr_t dma_desc_pa;		/* Descriptor physical address */
@@ -224,7 +224,7 @@ struct mcam_vb_buffer {
 	struct yuv_pointer_t yuv_p;
 };
 
-static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_buffer *vb)
+static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct mcam_vb_buffer, vb_buf);
 }
@@ -233,7 +233,7 @@ static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_buffer *vb)
  * Hand a completed buffer back to user space.
  */
 static void mcam_buffer_done(struct mcam_camera *cam, int frame,
-		struct vb2_buffer *vbuf)
+		struct vb2_v4l2_buffer *vbuf)
 {
 	vbuf->v4l2_buf.bytesused = cam->pix_format.sizeimage;
 	vbuf->v4l2_buf.sequence = cam->buf_seq[frame];
@@ -532,7 +532,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 	struct v4l2_pix_format *fmt = &cam->pix_format;
 	dma_addr_t dma_handle;
 	u32 pixel_count = fmt->width * fmt->height;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * If there are no available buffers, go into single mode
@@ -1085,10 +1085,10 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
 }
 
 
-static void mcam_vb_buf_queue(struct vb2_buffer *vb)
+static void mcam_vb_buf_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
-	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
+	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	unsigned long flags;
 	int start;
 
@@ -1181,10 +1181,10 @@ static const struct vb2_ops mcam_vb2_ops = {
  * Scatter/gather mode uses all of the above functions plus a
  * few extras to deal with DMA mapping.
  */
-static int mcam_vb_sg_buf_init(struct vb2_buffer *vb)
+static int mcam_vb_sg_buf_init(struct vb2_v4l2_buffer *vb)
 {
 	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
-	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
+	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	int ndesc = cam->pix_format.sizeimage/PAGE_SIZE + 1;
 
 	mvb->dma_desc = dma_alloc_coherent(cam->dev,
@@ -1197,7 +1197,7 @@ static int mcam_vb_sg_buf_init(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
+static int mcam_vb_sg_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
 	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
 	struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
@@ -1213,9 +1213,9 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void mcam_vb_sg_buf_cleanup(struct vb2_buffer *vb)
+static void mcam_vb_sg_buf_cleanup(struct vb2_v4l2_buffer *vb)
 {
-	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
+	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
 	int ndesc = cam->pix_format.sizeimage/PAGE_SIZE + 1;
 
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h
index aa0c6ea..81e0b5f 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.h
+++ b/drivers/media/platform/marvell-ccic/mcam-core.h
@@ -10,7 +10,7 @@
 #include <media/v4l2-common.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-dev.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 /*
  * Create our own symbols for the supported buffer modes, but, for now,
diff --git a/drivers/media/platform/mx2_emmaprp.c b/drivers/media/platform/mx2_emmaprp.c
index 87314b7..8e52a0d 100644
--- a/drivers/media/platform/mx2_emmaprp.c
+++ b/drivers/media/platform/mx2_emmaprp.c
@@ -289,7 +289,7 @@ static void emmaprp_device_run(void *priv)
 {
 	struct emmaprp_ctx *ctx = priv;
 	struct emmaprp_q_data *s_q_data, *d_q_data;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	struct emmaprp_dev *pcdev = ctx->dev;
 	unsigned int s_width, s_height;
 	unsigned int d_width, d_height;
@@ -351,7 +351,7 @@ static irqreturn_t emmaprp_irq(int irq_emma, void *data)
 {
 	struct emmaprp_dev *pcdev = data;
 	struct emmaprp_ctx *curr_ctx;
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 	unsigned long flags;
 	u32 irqst;
 
@@ -718,14 +718,14 @@ static int emmaprp_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int emmaprp_buf_prepare(struct vb2_buffer *vb)
+static int emmaprp_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct emmaprp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct emmaprp_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct emmaprp_q_data *q_data;
 
-	dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type);
+	dprintk(ctx->dev, "type: %d\n", vb->vb2.vb2_queue->type);
 
-	q_data = get_q_data(ctx, vb->vb2_queue->type);
+	q_data = get_q_data(ctx, vb->vb2.vb2_queue->type);
 
 	if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
 		dprintk(ctx->dev, "%s data will not fit into plane"
@@ -740,9 +740,9 @@ static int emmaprp_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void emmaprp_buf_queue(struct vb2_buffer *vb)
+static void emmaprp_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct emmaprp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct emmaprp_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
 }
 
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 3fe9047..31fc539 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -340,9 +340,9 @@ static int isp_video_queue_setup(struct vb2_queue *queue,
 	return 0;
 }
 
-static int isp_video_buffer_prepare(struct vb2_buffer *buf)
+static int isp_video_buffer_prepare(struct vb2_v4l2_buffer *buf)
 {
-	struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
+	struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2.vb2_queue);
 	struct isp_buffer *buffer = to_isp_buffer(buf);
 	struct isp_video *video = vfh->video;
 	dma_addr_t addr;
@@ -378,9 +378,9 @@ static int isp_video_buffer_prepare(struct vb2_buffer *buf)
  * If the pipeline is busy, it will be restarted in the output module interrupt
  * handler.
  */
-static void isp_video_buffer_queue(struct vb2_buffer *buf)
+static void isp_video_buffer_queue(struct vb2_v4l2_buffer *buf)
 {
-	struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
+	struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2.vb2_queue);
 	struct isp_buffer *buffer = to_isp_buffer(buf);
 	struct isp_video *video = vfh->video;
 	struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
diff --git a/drivers/media/platform/omap3isp/ispvideo.h b/drivers/media/platform/omap3isp/ispvideo.h
index 4071dd7..bcf0e0a 100644
--- a/drivers/media/platform/omap3isp/ispvideo.h
+++ b/drivers/media/platform/omap3isp/ispvideo.h
@@ -20,7 +20,7 @@
 #include <media/media-entity.h>
 #include <media/v4l2-dev.h>
 #include <media/v4l2-fh.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 #define ISP_VIDEO_DRIVER_NAME		"ispvideo"
 #define ISP_VIDEO_DRIVER_VERSION	"0.0.2"
@@ -122,7 +122,7 @@ static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
  * @dma: DMA address
  */
 struct isp_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head irqlist;
 	dma_addr_t dma;
 };
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index 54479d6..defbd8d 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -34,7 +34,7 @@
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "camif-core.h"
@@ -239,7 +239,7 @@ static int camif_stop_capture(struct camif_vp *vp)
 	return camif_reinitialize(vp);
 }
 
-static int camif_prepare_addr(struct camif_vp *vp, struct vb2_buffer *vb,
+static int camif_prepare_addr(struct camif_vp *vp, struct vb2_v4l2_buffer *vb,
 			      struct camif_addr *paddr)
 {
 	struct camif_frame *frame = &vp->out_frame;
@@ -474,9 +474,9 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct camif_vp *vp = vb2_get_drv_priv(vb->vb2_queue);
+	struct camif_vp *vp = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	if (vp->out_fmt == NULL)
 		return -EINVAL;
@@ -491,10 +491,10 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct camif_buffer *buf = container_of(vb, struct camif_buffer, vb);
-	struct camif_vp *vp = vb2_get_drv_priv(vb->vb2_queue);
+	struct camif_vp *vp = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct camif_dev *camif = vp->camif;
 	unsigned long flags;
 
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index 2d5bd3a..47f6653 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -32,7 +32,7 @@
 #include <media/media-device.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "camif-core.h"
diff --git a/drivers/media/platform/s3c-camif/camif-core.h b/drivers/media/platform/s3c-camif/camif-core.h
index 35d2fcd..adaf196 100644
--- a/drivers/media/platform/s3c-camif/camif-core.h
+++ b/drivers/media/platform/s3c-camif/camif-core.h
@@ -25,7 +25,7 @@
 #include <media/v4l2-dev.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-mediabus.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/s3c_camif.h>
 
 #define S3C_CAMIF_DRIVER_NAME	"s3c-camif"
@@ -322,7 +322,7 @@ struct camif_addr {
  * @index: an identifier of this buffer at the DMA engine
  */
 struct camif_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 	struct camif_addr paddr;
 	unsigned int index;
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index ec3e124..d9f2351 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -23,7 +23,7 @@
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "g2d.h"
@@ -121,10 +121,10 @@ static int g2d_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int g2d_buf_prepare(struct vb2_buffer *vb)
+static int g2d_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
-	struct g2d_frame *f = get_frame(ctx, vb->vb2_queue->type);
+	struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
+	struct g2d_frame *f = get_frame(ctx, vb->vb2.vb2_queue->type);
 
 	if (IS_ERR(f))
 		return PTR_ERR(f);
@@ -132,9 +132,9 @@ static int g2d_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void g2d_buf_queue(struct vb2_buffer *vb)
+static void g2d_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
 }
 
@@ -496,7 +496,7 @@ static void device_run(void *prv)
 {
 	struct g2d_ctx *ctx = prv;
 	struct g2d_dev *dev = ctx->dev;
-	struct vb2_buffer *src, *dst;
+	struct vb2_v4l2_buffer *src, *dst;
 	unsigned long flags;
 	u32 cmd = 0;
 
@@ -537,7 +537,7 @@ static irqreturn_t g2d_isr(int irq, void *prv)
 {
 	struct g2d_dev *dev = prv;
 	struct g2d_ctx *ctx = dev->curr;
-	struct vb2_buffer *src, *dst;
+	struct vb2_v4l2_buffer *src, *dst;
 
 	g2d_clear_int(dev);
 	clk_disable(dev->gate);
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index a1fb7e6..d8cb918 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -26,7 +26,7 @@
 #include <linux/string.h>
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "jpeg-core.h"
@@ -1763,7 +1763,7 @@ static void s5p_jpeg_device_run(void *priv)
 {
 	struct s5p_jpeg_ctx *ctx = priv;
 	struct s5p_jpeg *jpeg = ctx->jpeg;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	unsigned long src_addr, dst_addr, flags;
 
 	spin_lock_irqsave(&ctx->jpeg->slock, flags);
@@ -1844,7 +1844,7 @@ static void exynos4_jpeg_set_img_addr(struct s5p_jpeg_ctx *ctx)
 {
 	struct s5p_jpeg *jpeg = ctx->jpeg;
 	struct s5p_jpeg_fmt *fmt;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	struct s5p_jpeg_addr jpeg_addr;
 	u32 pix_size, padding_bytes = 0;
 
@@ -1881,7 +1881,7 @@ static void exynos4_jpeg_set_img_addr(struct s5p_jpeg_ctx *ctx)
 static void exynos4_jpeg_set_jpeg_addr(struct s5p_jpeg_ctx *ctx)
 {
 	struct s5p_jpeg *jpeg = ctx->jpeg;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int jpeg_addr = 0;
 
 	if (ctx->mode == S5P_JPEG_ENCODE)
@@ -1948,7 +1948,7 @@ static void exynos3250_jpeg_set_img_addr(struct s5p_jpeg_ctx *ctx)
 {
 	struct s5p_jpeg *jpeg = ctx->jpeg;
 	struct s5p_jpeg_fmt *fmt;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	struct s5p_jpeg_addr jpeg_addr;
 	u32 pix_size;
 
@@ -1980,7 +1980,7 @@ static void exynos3250_jpeg_set_img_addr(struct s5p_jpeg_ctx *ctx)
 static void exynos3250_jpeg_set_jpeg_addr(struct s5p_jpeg_ctx *ctx)
 {
 	struct s5p_jpeg *jpeg = ctx->jpeg;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int jpeg_addr = 0;
 
 	if (ctx->mode == S5P_JPEG_ENCODE)
@@ -2149,12 +2149,12 @@ static int s5p_jpeg_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int s5p_jpeg_buf_prepare(struct vb2_buffer *vb)
+static int s5p_jpeg_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct s5p_jpeg_q_data *q_data = NULL;
 
-	q_data = get_q_data(ctx, vb->vb2_queue->type);
+	q_data = get_q_data(ctx, vb->vb2.vb2_queue->type);
 	BUG_ON(q_data == NULL);
 
 	if (vb2_plane_size(vb, 0) < q_data->size) {
@@ -2169,12 +2169,12 @@ static int s5p_jpeg_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
+static void s5p_jpeg_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	if (ctx->mode == S5P_JPEG_DECODE &&
-	    vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
+	    vb->vb2.vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
 		struct s5p_jpeg_q_data tmp, *q_data;
 		ctx->hdr_parsed = s5p_jpeg_parse_hdr(&tmp,
 		     (unsigned long)vb2_plane_vaddr(vb, 0),
@@ -2265,7 +2265,7 @@ static irqreturn_t s5p_jpeg_irq(int irq, void *dev_id)
 {
 	struct s5p_jpeg *jpeg = dev_id;
 	struct s5p_jpeg_ctx *curr_ctx;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	unsigned long payload_size = 0;
 	enum vb2_buffer_state state = VB2_BUF_STATE_DONE;
 	bool enc_jpeg_too_large = false;
@@ -2322,7 +2322,7 @@ static irqreturn_t s5p_jpeg_irq(int irq, void *dev_id)
 static irqreturn_t exynos4_jpeg_irq(int irq, void *priv)
 {
 	unsigned int int_status;
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 	struct s5p_jpeg *jpeg = priv;
 	struct s5p_jpeg_ctx *curr_ctx;
 	unsigned long payload_size = 0;
@@ -2384,7 +2384,7 @@ static irqreturn_t exynos3250_jpeg_irq(int irq, void *dev_id)
 {
 	struct s5p_jpeg *jpeg = dev_id;
 	struct s5p_jpeg_ctx *curr_ctx;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 	unsigned long payload_size = 0;
 	enum vb2_buffer_state state = VB2_BUF_STATE_DONE;
 	bool interrupt_timeout = false;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 61e4540..5600dcd 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -22,7 +22,7 @@
 #include <media/v4l2-event.h>
 #include <linux/workqueue.h>
 #include <linux/of.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include "s5p_mfc_common.h"
 #include "s5p_mfc_ctrl.h"
 #include "s5p_mfc_debug.h"
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 24262bb..e8740fa 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -21,7 +21,7 @@
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include "regs-mfc.h"
 #include "regs-mfc-v8.h"
 
@@ -180,7 +180,7 @@ struct s5p_mfc_ctx;
  */
 struct s5p_mfc_buf {
 	struct list_head list;
-	struct vb2_buffer *b;
+	struct vb2_v4l2_buffer *b;
 	union {
 		struct {
 			size_t luma;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index aebe4fd..ff8567f 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -22,7 +22,7 @@
 #include <linux/workqueue.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-event.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include "s5p_mfc_common.h"
 #include "s5p_mfc_ctrl.h"
 #include "s5p_mfc_debug.h"
@@ -943,9 +943,9 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int s5p_mfc_buf_init(struct vb2_buffer *vb)
+static int s5p_mfc_buf_init(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	unsigned int i;
 
@@ -1056,9 +1056,9 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q)
 }
 
 
-static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
+static void s5p_mfc_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	struct s5p_mfc_dev *dev = ctx->dev;
 	unsigned long flags;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index e65993f..c2aab57 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -23,7 +23,7 @@
 #include <media/v4l2-event.h>
 #include <linux/workqueue.h>
 #include <media/v4l2-ctrls.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include "s5p_mfc_common.h"
 #include "s5p_mfc_ctrl.h"
 #include "s5p_mfc_debug.h"
@@ -1789,13 +1789,13 @@ static const struct v4l2_ioctl_ops s5p_mfc_enc_ioctl_ops = {
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
 
-static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
+static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_v4l2_buffer *vb)
 {
 	int i;
 
 	if (!fmt)
 		return -EINVAL;
-	if (fmt->num_planes != vb->num_planes) {
+	if (fmt->num_planes != vb->vb2.num_planes) {
 		mfc_err("invalid plane number for the format\n");
 		return -EINVAL;
 	}
@@ -1866,9 +1866,9 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int s5p_mfc_buf_init(struct vb2_buffer *vb)
+static int s5p_mfc_buf_init(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	unsigned int i;
 	int ret;
@@ -1900,9 +1900,9 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int s5p_mfc_buf_prepare(struct vb2_buffer *vb)
+static int s5p_mfc_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	int ret;
 
@@ -1997,9 +1997,9 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q)
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 }
 
-static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
+static void s5p_mfc_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	struct s5p_mfc_dev *dev = ctx->dev;
 	unsigned long flags;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
index b09bcd1..c64ff34 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -1476,7 +1476,7 @@ static void s5p_mfc_cleanup_queue_v5(struct list_head *lh, struct vb2_queue *vq)
 
 	while (!list_empty(lh)) {
 		b = list_entry(lh->next, struct s5p_mfc_buf, list);
-		for (i = 0; i < b->b->num_planes; i++)
+		for (i = 0; i < b->b->vb2.num_planes; i++)
 			vb2_set_plane_payload(b->b, i, 0);
 		vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
 		list_del(&b->list);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index cefad18..75e875f 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1834,7 +1834,7 @@ static void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
 
 	while (!list_empty(lh)) {
 		b = list_entry(lh->next, struct s5p_mfc_buf, list);
-		for (i = 0; i < b->b->num_planes; i++)
+		for (i = 0; i < b->b->vb2.num_planes; i++)
 			vb2_set_plane_payload(b->b, i, 0);
 		vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
 		list_del(&b->list);
diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
index fb2acc5..be7ed5f 100644
--- a/drivers/media/platform/s5p-tv/mixer.h
+++ b/drivers/media/platform/s5p-tv/mixer.h
@@ -24,7 +24,7 @@
 #include <linux/spinlock.h>
 #include <linux/wait.h>
 #include <media/v4l2-device.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 #include "regs-mixer.h"
 
@@ -113,7 +113,7 @@ struct mxr_geometry {
 /** instance of a buffer */
 struct mxr_buffer {
 	/** common v4l buffer stuff -- must be first */
-	struct vb2_buffer	vb;
+	struct vb2_v4l2_buffer	vb;
 	/** node for layer's lists */
 	struct list_head	list;
 };
diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
index 72d4f2e..e7ca9cd 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -912,10 +912,10 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
 	return 0;
 }
 
-static void buf_queue(struct vb2_buffer *vb)
+static void buf_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct mxr_buffer *buffer = container_of(vb, struct mxr_buffer, vb);
-	struct mxr_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
+	struct mxr_layer *layer = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct mxr_device *mdev = layer->mdev;
 	unsigned long flags;
 
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
index 2554f37..1c9028c 100644
--- a/drivers/media/platform/sh_veu.c
+++ b/drivers/media/platform/sh_veu.c
@@ -243,8 +243,8 @@ static void sh_veu_job_abort(void *priv)
 }
 
 static void sh_veu_process(struct sh_veu_dev *veu,
-			   struct vb2_buffer *src_buf,
-			   struct vb2_buffer *dst_buf)
+			   struct vb2_v4l2_buffer *src_buf,
+			   struct vb2_v4l2_buffer *dst_buf)
 {
 	dma_addr_t addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0);
 
@@ -277,7 +277,7 @@ static void sh_veu_process(struct sh_veu_dev *veu,
 static void sh_veu_device_run(void *priv)
 {
 	struct sh_veu_dev *veu = priv;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 
 	src_buf = v4l2_m2m_next_src_buf(veu->m2m_ctx);
 	dst_buf = v4l2_m2m_next_dst_buf(veu->m2m_ctx);
@@ -908,13 +908,13 @@ static int sh_veu_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int sh_veu_buf_prepare(struct vb2_buffer *vb)
+static int sh_veu_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct sh_veu_dev *veu = vb2_get_drv_priv(vb->vb2_queue);
+	struct sh_veu_dev *veu = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct sh_veu_vfmt *vfmt;
 	unsigned int sizeimage;
 
-	vfmt = sh_veu_get_vfmt(veu, vb->vb2_queue->type);
+	vfmt = sh_veu_get_vfmt(veu, vb->vb2.vb2_queue->type);
 	sizeimage = vfmt->bytesperline * vfmt->frame.height *
 		vfmt->fmt->depth / vfmt->fmt->ydepth;
 
@@ -929,9 +929,9 @@ static int sh_veu_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void sh_veu_buf_queue(struct vb2_buffer *vb)
+static void sh_veu_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct sh_veu_dev *veu = vb2_get_drv_priv(vb->vb2_queue);
+	struct sh_veu_dev *veu = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	dev_dbg(veu->dev, "%s(%d)\n", __func__, vb->v4l2_buf.type);
 	v4l2_m2m_buf_queue(veu->m2m_ctx, vb);
 }
@@ -1082,8 +1082,8 @@ static irqreturn_t sh_veu_bh(int irq, void *dev_id)
 static irqreturn_t sh_veu_isr(int irq, void *dev_id)
 {
 	struct sh_veu_dev *veu = dev_id;
-	struct vb2_buffer *dst;
-	struct vb2_buffer *src;
+	struct vb2_v4l2_buffer *dst;
+	struct vb2_v4l2_buffer *src;
 	u32 status = sh_veu_reg_read(veu, VEU_EVTR);
 
 	/* bundle read mode not used */
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index c835beb..bb66058 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -59,7 +59,7 @@ struct isi_dma_desc {
 
 /* Frame buffer data */
 struct frame_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct isi_dma_desc *p_dma_desc;
 	struct list_head list;
 };
@@ -153,7 +153,7 @@ static int configure_geometry(struct atmel_isi *isi, u32 width,
 static irqreturn_t atmel_isi_handle_streaming(struct atmel_isi *isi)
 {
 	if (isi->active) {
-		struct vb2_buffer *vb = &isi->active->vb;
+		struct vb2_v4l2_buffer *vb = &isi->active->vb;
 		struct frame_buffer *buf = isi->active;
 
 		list_del_init(&buf->list);
@@ -267,7 +267,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_init(struct vb2_buffer *vb)
+static int buffer_init(struct vb2_v4l2_buffer *vb)
 {
 	struct frame_buffer *buf = container_of(vb, struct frame_buffer, vb);
 
@@ -277,9 +277,9 @@ static int buffer_init(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	struct frame_buffer *buf = container_of(vb, struct frame_buffer, vb);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct atmel_isi *isi = ici->priv;
@@ -319,9 +319,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_cleanup(struct vb2_buffer *vb)
+static void buffer_cleanup(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct atmel_isi *isi = ici->priv;
 	struct frame_buffer *buf = container_of(vb, struct frame_buffer, vb);
@@ -360,9 +360,9 @@ static void start_dma(struct atmel_isi *isi, struct frame_buffer *buffer)
 	isi_writel(isi, ISI_CFG1, cfg1);
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct atmel_isi *isi = ici->priv;
 	struct frame_buffer *buf = container_of(vb, struct frame_buffer, vb);
@@ -373,7 +373,7 @@ static void buffer_queue(struct vb2_buffer *vb)
 
 	if (isi->active == NULL) {
 		isi->active = buf;
-		if (vb2_is_streaming(vb->vb2_queue))
+		if (vb2_is_streaming(vb->vb2.vb2_queue))
 			start_dma(isi, buf);
 	}
 	spin_unlock_irqrestore(&isi->lock, flags);
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index 192377f..4022aeb 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -32,7 +32,7 @@
 
 #include <media/v4l2-common.h>
 #include <media/v4l2-dev.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 #include <media/soc_camera.h>
 #include <media/soc_mediabus.h>
@@ -225,7 +225,7 @@ struct mx2_buf_internal {
 /* buffer for one video frame */
 struct mx2_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer		vb;
+	struct vb2_v4l2_buffer		vb;
 	struct mx2_buf_internal		internal;
 };
 
@@ -498,9 +498,9 @@ static int mx2_videobuf_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int mx2_videobuf_prepare(struct vb2_buffer *vb)
+static int mx2_videobuf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	int ret = 0;
 
 	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
@@ -528,7 +528,7 @@ out:
 	return ret;
 }
 
-static void mx2_videobuf_queue(struct vb2_buffer *vb)
+static void mx2_videobuf_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
 	struct soc_camera_host *ici =
@@ -650,7 +650,7 @@ static int mx2_start_streaming(struct vb2_queue *q, unsigned int count)
 		to_soc_camera_host(icd->parent);
 	struct mx2_camera_dev *pcdev = ici->priv;
 	struct mx2_fmt_cfg *prp = pcdev->emma_prp;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	struct mx2_buffer *buf;
 	unsigned long phys;
 	int bytesperline;
@@ -1293,7 +1293,7 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
 #endif
 	struct mx2_buf_internal *ibuf;
 	struct mx2_buffer *buf;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned long phys;
 
 	ibuf = list_first_entry(&pcdev->active_bufs, struct mx2_buf_internal,
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index 3435fd2..e747440 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -63,7 +63,7 @@
 
 struct mx3_camera_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer			vb;
+	struct vb2_v4l2_buffer			vb;
 	struct list_head			queue;
 
 	/* One descriptot per scatterlist (per frame) */
@@ -133,7 +133,7 @@ static void csi_reg_write(struct mx3_camera_dev *mx3, u32 value, off_t reg)
 	__raw_writel(value, mx3->base + reg);
 }
 
-static struct mx3_camera_buffer *to_mx3_vb(struct vb2_buffer *vb)
+static struct mx3_camera_buffer *to_mx3_vb(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct mx3_camera_buffer, vb);
 }
@@ -151,7 +151,7 @@ static void mx3_cam_dma_done(void *arg)
 
 	spin_lock(&mx3_cam->lock);
 	if (mx3_cam->active) {
-		struct vb2_buffer *vb = &mx3_cam->active->vb;
+		struct vb2_v4l2_buffer *vb = &mx3_cam->active->vb;
 		struct mx3_camera_buffer *buf = to_mx3_vb(vb);
 
 		list_del_init(&buf->queue);
@@ -255,9 +255,9 @@ static enum pixel_fmt fourcc_to_ipu_pix(__u32 fourcc)
 	}
 }
 
-static void mx3_videobuf_queue(struct vb2_buffer *vb)
+static void mx3_videobuf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct mx3_camera_dev *mx3_cam = ici->priv;
 	struct mx3_camera_buffer *buf = to_mx3_vb(vb);
@@ -355,9 +355,9 @@ error:
 	vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 }
 
-static void mx3_videobuf_release(struct vb2_buffer *vb)
+static void mx3_videobuf_release(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct mx3_camera_dev *mx3_cam = ici->priv;
 	struct mx3_camera_buffer *buf = to_mx3_vb(vb);
@@ -388,9 +388,9 @@ static void mx3_videobuf_release(struct vb2_buffer *vb)
 	mx3_cam->buf_total -= vb2_plane_size(vb, 0);
 }
 
-static int mx3_videobuf_init(struct vb2_buffer *vb)
+static int mx3_videobuf_init(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct mx3_camera_dev *mx3_cam = ici->priv;
 	struct mx3_camera_buffer *buf = to_mx3_vb(vb);
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index 279ab9f..7a4c3c6 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -475,7 +475,7 @@ struct rcar_vin_priv {
 	struct soc_camera_host		ici;
 	struct list_head		capture;
 #define MAX_BUFFER_NUM			3
-	struct vb2_buffer		*queue_buf[MAX_BUFFER_NUM];
+	struct vb2_v4l2_buffer		*queue_buf[MAX_BUFFER_NUM];
 	struct vb2_alloc_ctx		*alloc_ctx;
 	enum v4l2_field			field;
 	unsigned int			pdata_flags;
@@ -489,11 +489,11 @@ struct rcar_vin_priv {
 #define is_continuous_transfer(priv)	(priv->vb_count > MAX_BUFFER_NUM)
 
 struct rcar_vin_buffer {
-	struct vb2_buffer		vb;
+	struct vb2_v4l2_buffer		vb;
 	struct list_head		list;
 };
 
-#define to_buf_list(vb2_buffer)	(&container_of(vb2_buffer, \
+#define to_buf_list(vb2_v4l2_buffer)	(&container_of(vb2_v4l2_buffer, \
 						       struct rcar_vin_buffer, \
 						       vb)->list)
 
@@ -736,7 +736,7 @@ static int rcar_vin_hw_ready(struct rcar_vin_priv *priv)
 /* Moves a buffer from the queue to the HW slots */
 static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv)
 {
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	dma_addr_t phys_addr_top;
 	int slot;
 
@@ -757,9 +757,9 @@ static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv)
 	return 1;
 }
 
-static void rcar_vin_videobuf_queue(struct vb2_buffer *vb)
+static void rcar_vin_videobuf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
+	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2.vb2_queue);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct rcar_vin_priv *priv = ici->priv;
 	unsigned long size;
@@ -949,7 +949,7 @@ static void rcar_vin_remove_device(struct soc_camera_device *icd)
 {
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct rcar_vin_priv *priv = ici->priv;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int i;
 
 	/* disable capture, disable interrupts */
diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
index 9ce202f..7c05ab1 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -93,7 +93,7 @@
 
 /* per video frame buffer */
 struct sh_mobile_ceu_buffer {
-	struct vb2_buffer vb; /* v4l buffer must be first */
+	struct vb2_v4l2_buffer vb; /* v4l buffer must be first */
 	struct list_head queue;
 };
 
@@ -112,7 +112,7 @@ struct sh_mobile_ceu_dev {
 
 	spinlock_t lock;		/* Protects video buffer lists */
 	struct list_head capture;
-	struct vb2_buffer *active;
+	struct vb2_v4l2_buffer *active;
 	struct vb2_alloc_ctx *alloc_ctx;
 
 	struct sh_mobile_ceu_info *pdata;
@@ -152,7 +152,7 @@ struct sh_mobile_ceu_cam {
 	u32 code;
 };
 
-static struct sh_mobile_ceu_buffer *to_ceu_vb(struct vb2_buffer *vb)
+static struct sh_mobile_ceu_buffer *to_ceu_vb(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct sh_mobile_ceu_buffer, vb);
 }
@@ -367,7 +367,7 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
 	return ret;
 }
 
-static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
+static int sh_mobile_ceu_videobuf_prepare(struct vb2_v4l2_buffer *vb)
 {
 	struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
 
@@ -377,9 +377,9 @@ static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
+static void sh_mobile_ceu_videobuf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
+	struct soc_camera_device *icd = container_of(vb->vb2.vb2_queue, struct soc_camera_device, vb2_vidq);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct sh_mobile_ceu_dev *pcdev = ici->priv;
 	struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
@@ -427,9 +427,9 @@ error:
 	vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 }
 
-static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
+static void sh_mobile_ceu_videobuf_release(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
+	struct soc_camera_device *icd = container_of(vb->vb2.vb2_queue, struct soc_camera_device, vb2_vidq);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
 	struct sh_mobile_ceu_dev *pcdev = ici->priv;
@@ -456,9 +456,9 @@ static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
 	spin_unlock_irq(&pcdev->lock);
 }
 
-static int sh_mobile_ceu_videobuf_init(struct vb2_buffer *vb)
+static int sh_mobile_ceu_videobuf_init(struct vb2_v4l2_buffer *vb)
 {
-	struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
+	struct soc_camera_device *icd = container_of(vb->vb2.vb2_queue, struct soc_camera_device, vb2_vidq);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct sh_mobile_ceu_dev *pcdev = ici->priv;
 
@@ -504,7 +504,7 @@ static struct vb2_ops sh_mobile_ceu_videobuf_ops = {
 static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
 {
 	struct sh_mobile_ceu_dev *pcdev = data;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int ret;
 
 	spin_lock(&pcdev->lock);
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index 66634b4..5f2db3d 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -38,7 +38,7 @@
 #include <media/v4l2-dev.h>
 #include <media/v4l2-of.h>
 #include <media/videobuf-core.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 /* Default to VGA resolution */
 #define DEFAULT_WIDTH	640
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index c44760b..568c716 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -40,7 +40,7 @@
 #include <media/v4l2-event.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-mem2mem.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "vpdma.h"
@@ -384,8 +384,8 @@ struct vpe_ctx {
 	unsigned int		bufs_completed;		/* bufs done in this batch */
 
 	struct vpe_q_data	q_data[2];		/* src & dst queue data */
-	struct vb2_buffer	*src_vbs[VPE_MAX_SRC_BUFS];
-	struct vb2_buffer	*dst_vb;
+	struct vb2_v4l2_buffer	*src_vbs[VPE_MAX_SRC_BUFS];
+	struct vb2_v4l2_buffer	*dst_vb;
 
 	dma_addr_t		mv_buf_dma[2];		/* dma addrs of motion vector in/out bufs */
 	void			*mv_buf[2];		/* virtual addrs of motion vector bufs */
@@ -988,7 +988,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
 {
 	struct vpe_q_data *q_data = &ctx->q_data[Q_DATA_DST];
 	const struct vpe_port_data *p_data = &port_data[port];
-	struct vb2_buffer *vb = ctx->dst_vb;
+	struct vb2_v4l2_buffer *vb = ctx->dst_vb;
 	struct vpe_fmt *fmt = q_data->fmt;
 	const struct vpdma_data_format *vpdma_fmt;
 	int mv_buf_selector = !ctx->src_mv_buf_selector;
@@ -1025,7 +1025,7 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
 {
 	struct vpe_q_data *q_data = &ctx->q_data[Q_DATA_SRC];
 	const struct vpe_port_data *p_data = &port_data[port];
-	struct vb2_buffer *vb = ctx->src_vbs[p_data->vb_index];
+	struct vb2_v4l2_buffer *vb = ctx->src_vbs[p_data->vb_index];
 	struct vpe_fmt *fmt = q_data->fmt;
 	const struct vpdma_data_format *vpdma_fmt;
 	int mv_buf_selector = ctx->src_mv_buf_selector;
@@ -1222,7 +1222,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
 	struct vpe_dev *dev = (struct vpe_dev *)data;
 	struct vpe_ctx *ctx;
 	struct vpe_q_data *d_q_data;
-	struct vb2_buffer *s_vb, *d_vb;
+	struct vb2_v4l2_buffer *s_vb, *d_vb;
 	struct v4l2_buffer *s_buf, *d_buf;
 	unsigned long flags;
 	u32 irqst0, irqst1;
@@ -1823,18 +1823,18 @@ static int vpe_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int vpe_buf_prepare(struct vb2_buffer *vb)
+static int vpe_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vpe_q_data *q_data;
 	int i, num_planes;
 
-	vpe_dbg(ctx->dev, "type: %d\n", vb->vb2_queue->type);
+	vpe_dbg(ctx->dev, "type: %d\n", vb->vb2.vb2_queue->type);
 
-	q_data = get_q_data(ctx, vb->vb2_queue->type);
+	q_data = get_q_data(ctx, vb->vb2.vb2_queue->type);
 	num_planes = q_data->fmt->coplanar ? 2 : 1;
 
-	if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+	if (vb->vb2.vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
 		if (!(q_data->flags & Q_DATA_INTERLACED)) {
 			vb->v4l2_buf.field = V4L2_FIELD_NONE;
 		} else {
@@ -1860,9 +1860,9 @@ static int vpe_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vpe_buf_queue(struct vb2_buffer *vb)
+static void vpe_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
 }
diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
index d9d844a..6e0560d 100644
--- a/drivers/media/platform/vim2m.c
+++ b/drivers/media/platform/vim2m.c
@@ -200,8 +200,8 @@ static struct vim2m_q_data *get_q_data(struct vim2m_ctx *ctx,
 
 
 static int device_process(struct vim2m_ctx *ctx,
-			  struct vb2_buffer *in_vb,
-			  struct vb2_buffer *out_vb)
+			  struct vb2_v4l2_buffer *in_vb,
+			  struct vb2_v4l2_buffer *out_vb)
 {
 	struct vim2m_dev *dev = ctx->dev;
 	struct vim2m_q_data *q_data;
@@ -377,7 +377,7 @@ static void device_run(void *priv)
 {
 	struct vim2m_ctx *ctx = priv;
 	struct vim2m_dev *dev = ctx->dev;
-	struct vb2_buffer *src_buf, *dst_buf;
+	struct vb2_v4l2_buffer *src_buf, *dst_buf;
 
 	src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
@@ -392,7 +392,7 @@ static void device_isr(unsigned long priv)
 {
 	struct vim2m_dev *vim2m_dev = (struct vim2m_dev *)priv;
 	struct vim2m_ctx *curr_ctx;
-	struct vb2_buffer *src_vb, *dst_vb;
+	struct vb2_v4l2_buffer *src_vb, *dst_vb;
 	unsigned long flags;
 
 	curr_ctx = v4l2_m2m_get_curr_priv(vim2m_dev->m2m_dev);
@@ -741,15 +741,15 @@ static int vim2m_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static int vim2m_buf_prepare(struct vb2_buffer *vb)
+static int vim2m_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vim2m_q_data *q_data;
 
-	dprintk(ctx->dev, "type: %d\n", vb->vb2_queue->type);
+	dprintk(ctx->dev, "type: %d\n", vb->vb2.vb2_queue->type);
 
-	q_data = get_q_data(ctx, vb->vb2_queue->type);
-	if (V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
+	q_data = get_q_data(ctx, vb->vb2.vb2_queue->type);
+	if (V4L2_TYPE_IS_OUTPUT(vb->vb2.vb2_queue->type)) {
 		if (vb->v4l2_buf.field == V4L2_FIELD_ANY)
 			vb->v4l2_buf.field = V4L2_FIELD_NONE;
 		if (vb->v4l2_buf.field != V4L2_FIELD_NONE) {
@@ -770,9 +770,9 @@ static int vim2m_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vim2m_buf_queue(struct vb2_buffer *vb)
+static void vim2m_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
 }
@@ -789,7 +789,7 @@ static int vim2m_start_streaming(struct vb2_queue *q, unsigned count)
 static void vim2m_stop_streaming(struct vb2_queue *q)
 {
 	struct vim2m_ctx *ctx = vb2_get_drv_priv(q);
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned long flags;
 
 	for (;;) {
diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h
index 4b497df..4c31d84 100644
--- a/drivers/media/platform/vivid/vivid-core.h
+++ b/drivers/media/platform/vivid/vivid-core.h
@@ -21,7 +21,7 @@
 #define _VIVID_CORE_H_
 
 #include <linux/fb.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-dev.h>
 #include <media/v4l2-ctrls.h>
@@ -92,7 +92,7 @@ extern struct vivid_fmt vivid_formats[];
 /* buffer for one video frame */
 struct vivid_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer	vb;
+	struct vb2_v4l2_buffer	vb;
 	struct list_head	list;
 };
 
diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.c b/drivers/media/platform/vivid/vivid-sdr-cap.c
index 4af55f1..af9de57 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
@@ -200,9 +200,9 @@ static int sdr_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *f
 	return 0;
 }
 
-static int sdr_cap_buf_prepare(struct vb2_buffer *vb)
+static int sdr_cap_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	unsigned size = SDR_CAP_SAMPLES_PER_BUF * 2;
 
 	dprintk(dev, 1, "%s\n", __func__);
@@ -225,9 +225,9 @@ static int sdr_cap_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void sdr_cap_buf_queue(struct vb2_buffer *vb)
+static void sdr_cap_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
diff --git a/drivers/media/platform/vivid/vivid-vbi-cap.c b/drivers/media/platform/vivid/vivid-vbi-cap.c
index ef81b01..a994484 100644
--- a/drivers/media/platform/vivid/vivid-vbi-cap.c
+++ b/drivers/media/platform/vivid/vivid-vbi-cap.c
@@ -157,11 +157,11 @@ static int vbi_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *f
 	return 0;
 }
 
-static int vbi_cap_buf_prepare(struct vb2_buffer *vb)
+static int vbi_cap_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	bool is_60hz = dev->std_cap & V4L2_STD_525_60;
-	unsigned size = vb->vb2_queue->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE ?
+	unsigned size = vb->vb2.vb2_queue->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE ?
 		36 * sizeof(struct v4l2_sliced_vbi_data) :
 		1440 * 2 * (is_60hz ? 12 : 18);
 
@@ -185,9 +185,9 @@ static int vbi_cap_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vbi_cap_buf_queue(struct vb2_buffer *vb)
+static void vbi_cap_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
diff --git a/drivers/media/platform/vivid/vivid-vbi-out.c b/drivers/media/platform/vivid/vivid-vbi-out.c
index 4e4c70e..6d41855 100644
--- a/drivers/media/platform/vivid/vivid-vbi-out.c
+++ b/drivers/media/platform/vivid/vivid-vbi-out.c
@@ -49,11 +49,11 @@ static int vbi_out_queue_setup(struct vb2_queue *vq, const struct v4l2_format *f
 	return 0;
 }
 
-static int vbi_out_buf_prepare(struct vb2_buffer *vb)
+static int vbi_out_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	bool is_60hz = dev->std_out & V4L2_STD_525_60;
-	unsigned size = vb->vb2_queue->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT ?
+	unsigned size = vb->vb2.vb2_queue->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT ?
 		36 * sizeof(struct v4l2_sliced_vbi_data) :
 		1440 * 2 * (is_60hz ? 12 : 18);
 
@@ -77,9 +77,9 @@ static int vbi_out_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vbi_out_buf_queue(struct vb2_buffer *vb)
+static void vbi_out_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index 867a29a..8dba4b5 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -164,9 +164,9 @@ static int vid_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *f
 	return 0;
 }
 
-static int vid_cap_buf_prepare(struct vb2_buffer *vb)
+static int vid_cap_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	unsigned long size;
 	unsigned planes = tpg_g_planes(&dev->tpg);
 	unsigned p;
@@ -201,9 +201,9 @@ static int vid_cap_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vid_cap_buf_finish(struct vb2_buffer *vb)
+static void vid_cap_buf_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct v4l2_timecode *tc = &vb->v4l2_buf.timecode;
 	unsigned fps = 25;
 	unsigned seq = vb->v4l2_buf.sequence;
@@ -226,9 +226,9 @@ static void vid_cap_buf_finish(struct vb2_buffer *vb)
 	tc->hours = (seq / (60 * 60 * fps)) % 24;
 }
 
-static void vid_cap_buf_queue(struct vb2_buffer *vb)
+static void vid_cap_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index 39ff79f..251d02b 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -110,9 +110,9 @@ static int vid_out_queue_setup(struct vb2_queue *vq, const struct v4l2_format *f
 	return 0;
 }
 
-static int vid_out_buf_prepare(struct vb2_buffer *vb)
+static int vid_out_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	unsigned long size;
 	unsigned planes = dev->fmt_out->planes;
 	unsigned p;
@@ -151,9 +151,9 @@ static int vid_out_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vid_out_buf_queue(struct vb2_buffer *vb)
+static void vid_out_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529..a6344df 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -200,10 +200,10 @@ static void rpf_vdev_queue(struct vsp1_video *video,
 
 	vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_Y,
 		       buf->addr[0] + rpf->offsets[0]);
-	if (buf->buf.num_planes > 1)
+	if (buf->buf.vb2.num_planes > 1)
 		vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C0,
 			       buf->addr[1] + rpf->offsets[1]);
-	if (buf->buf.num_planes > 2)
+	if (buf->buf.vb2.num_planes > 2)
 		vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C1,
 			       buf->addr[2] + rpf->offsets[1]);
 }
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index d91f19a..0983ea6 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -24,7 +24,7 @@
 #include <media/v4l2-fh.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-subdev.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "vsp1.h"
@@ -600,7 +600,7 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
 
 	done->buf.v4l2_buf.sequence = video->sequence++;
 	v4l2_get_timestamp(&done->buf.v4l2_buf.timestamp);
-	for (i = 0; i < done->buf.num_planes; ++i)
+	for (i = 0; i < done->buf.vb2.num_planes; ++i)
 		vb2_set_plane_payload(&done->buf, i, done->length[i]);
 	vb2_buffer_done(&done->buf, VB2_BUF_STATE_DONE);
 
@@ -739,17 +739,17 @@ vsp1_video_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int vsp1_video_buffer_prepare(struct vb2_buffer *vb)
+static int vsp1_video_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue);
+	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vsp1_video_buffer *buf = to_vsp1_video_buffer(vb);
 	const struct v4l2_pix_format_mplane *format = &video->format;
 	unsigned int i;
 
-	if (vb->num_planes < format->num_planes)
+	if (vb->vb2.num_planes < format->num_planes)
 		return -EINVAL;
 
-	for (i = 0; i < vb->num_planes; ++i) {
+	for (i = 0; i < vb->vb2.num_planes; ++i) {
 		buf->addr[i] = vb2_dma_contig_plane_dma_addr(vb, i);
 		buf->length[i] = vb2_plane_size(vb, i);
 
@@ -760,9 +760,9 @@ static int vsp1_video_buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
+static void vsp1_video_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue);
+	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct vsp1_pipeline *pipe = to_vsp1_pipeline(&video->video.entity);
 	struct vsp1_video_buffer *buf = to_vsp1_video_buffer(vb);
 	unsigned long flags;
diff --git a/drivers/media/platform/vsp1/vsp1_video.h b/drivers/media/platform/vsp1/vsp1_video.h
index fd2851a..199c289 100644
--- a/drivers/media/platform/vsp1/vsp1_video.h
+++ b/drivers/media/platform/vsp1/vsp1_video.h
@@ -18,7 +18,7 @@
 #include <linux/wait.h>
 
 #include <media/media-entity.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 struct vsp1_video;
 
@@ -94,7 +94,7 @@ static inline struct vsp1_pipeline *to_vsp1_pipeline(struct media_entity *e)
 }
 
 struct vsp1_video_buffer {
-	struct vb2_buffer buf;
+	struct vb2_v4l2_buffer buf;
 	struct list_head queue;
 
 	dma_addr_t addr[3];
@@ -102,7 +102,7 @@ struct vsp1_video_buffer {
 };
 
 static inline struct vsp1_video_buffer *
-to_vsp1_video_buffer(struct vb2_buffer *vb)
+to_vsp1_video_buffer(struct vb2_v4l2_buffer *vb)
 {
 	return container_of(vb, struct vsp1_video_buffer, buf);
 }
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2..84ddefd 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -201,9 +201,9 @@ static void wpf_vdev_queue(struct vsp1_video *video,
 	struct vsp1_rwpf *wpf = container_of(video, struct vsp1_rwpf, video);
 
 	vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_Y, buf->addr[0]);
-	if (buf->buf.num_planes > 1)
+	if (buf->buf.vb2.num_planes > 1)
 		vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C0, buf->addr[1]);
-	if (buf->buf.num_planes > 2)
+	if (buf->buf.vb2.num_planes > 2)
 		vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C1, buf->addr[2]);
 }
 
diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c
index 4069234..d5b9f0d 100644
--- a/drivers/media/usb/airspy/airspy.c
+++ b/drivers/media/usb/airspy/airspy.c
@@ -97,7 +97,7 @@ static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
 
 /* intermediate buffers with raw data from the USB device */
 struct airspy_frame_buf {
-	struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
+	struct vb2_v4l2_buffer vb;   /* common v4l buffer stuff -- must be first */
 	struct list_head list;
 };
 
@@ -503,9 +503,9 @@ static int airspy_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static void airspy_buf_queue(struct vb2_buffer *vb)
+static void airspy_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct airspy *s = vb2_get_drv_priv(vb->vb2_queue);
+	struct airspy *s = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct airspy_frame_buf *buf =
 			container_of(vb, struct airspy_frame_buf, vb);
 	unsigned long flags;
diff --git a/drivers/media/usb/au0828/au0828-vbi.c b/drivers/media/usb/au0828/au0828-vbi.c
index f67247c..2225e8a 100644
--- a/drivers/media/usb/au0828/au0828-vbi.c
+++ b/drivers/media/usb/au0828/au0828-vbi.c
@@ -49,9 +49,9 @@ static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int vbi_buffer_prepare(struct vb2_buffer *vb)
+static int vbi_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
 	unsigned long size;
 
@@ -68,9 +68,9 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 }
 
 static void
-vbi_buffer_queue(struct vb2_buffer *vb)
+vbi_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
 	struct au0828_dmaqueue *vbiq = &dev->vbiq;
 	unsigned long flags = 0;
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index a27cb5f..c5aea1f 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -664,10 +664,10 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 }
 
 static int
-buffer_prepare(struct vb2_buffer *vb)
+buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
 	struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
-	struct au0828_dev    *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct au0828_dev    *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	buf->length = dev->height * dev->bytesperline;
 
@@ -681,12 +681,12 @@ buffer_prepare(struct vb2_buffer *vb)
 }
 
 static void
-buffer_queue(struct vb2_buffer *vb)
+buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct au0828_buffer    *buf     = container_of(vb,
 							struct au0828_buffer,
 							vb);
-	struct au0828_dev       *dev     = vb2_get_drv_priv(vb->vb2_queue);
+	struct au0828_dev       *dev     = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct au0828_dmaqueue  *vidq    = &dev->vidq;
 	unsigned long flags = 0;
 
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index eb15187..8b9df1c 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -167,7 +167,7 @@ struct au0828_usb_isoc_ctl {
 /* buffer for one video frame */
 struct au0828_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 
 	void *mem;
diff --git a/drivers/media/usb/em28xx/em28xx-vbi.c b/drivers/media/usb/em28xx/em28xx-vbi.c
index 744e7ed..e73cea8 100644
--- a/drivers/media/usb/em28xx/em28xx-vbi.c
+++ b/drivers/media/usb/em28xx/em28xx-vbi.c
@@ -57,9 +57,9 @@ static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int vbi_buffer_prepare(struct vb2_buffer *vb)
+static int vbi_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct em28xx        *dev  = vb2_get_drv_priv(vb->vb2_queue);
+	struct em28xx        *dev  = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct em28xx_v4l2   *v4l2 = dev->v4l2;
 	struct em28xx_buffer *buf  = container_of(vb, struct em28xx_buffer, vb);
 	unsigned long        size;
@@ -77,9 +77,9 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 }
 
 static void
-vbi_buffer_queue(struct vb2_buffer *vb)
+vbi_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct em28xx *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
 	struct em28xx_dmaqueue *vbiq = &dev->vbiq;
 	unsigned long flags = 0;
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 9ecf656..907272f 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -899,9 +899,9 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 }
 
 static int
-buffer_prepare(struct vb2_buffer *vb)
+buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct em28xx        *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct em28xx        *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct em28xx_v4l2   *v4l2 = dev->v4l2;
 	struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
 	unsigned long size;
@@ -1041,9 +1041,9 @@ void em28xx_stop_vbi_streaming(struct vb2_queue *vq)
 }
 
 static void
-buffer_queue(struct vb2_buffer *vb)
+buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct em28xx *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
 	struct em28xx_dmaqueue *vidq = &dev->vidq;
 	unsigned long flags = 0;
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index 9c70753..251d050 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -263,7 +263,7 @@ struct em28xx_fmt {
 /* buffer for one video frame */
 struct em28xx_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 
 	void *mem;
diff --git a/drivers/media/usb/go7007/go7007-priv.h b/drivers/media/usb/go7007/go7007-priv.h
index 2251c3f..745185e 100644
--- a/drivers/media/usb/go7007/go7007-priv.h
+++ b/drivers/media/usb/go7007/go7007-priv.h
@@ -20,7 +20,7 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 struct go7007;
 
@@ -136,7 +136,7 @@ struct go7007_hpi_ops {
 #define	GO7007_BUF_SIZE		(GO7007_BUF_PAGES << PAGE_SHIFT)
 
 struct go7007_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 	unsigned int frame_offset;
 	u32 modet_active;
diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c
index d6bf982..c16ff31 100644
--- a/drivers/media/usb/go7007/go7007-v4l2.c
+++ b/drivers/media/usb/go7007/go7007-v4l2.c
@@ -380,9 +380,9 @@ static int go7007_queue_setup(struct vb2_queue *q,
 	return 0;
 }
 
-static void go7007_buf_queue(struct vb2_buffer *vb)
+static void go7007_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct go7007 *go = vb2_get_drv_priv(vq);
 	struct go7007_buffer *go7007_vb =
 		container_of(vb, struct go7007_buffer, vb);
@@ -393,7 +393,7 @@ static void go7007_buf_queue(struct vb2_buffer *vb)
 	spin_unlock_irqrestore(&go->spinlock, flags);
 }
 
-static int go7007_buf_prepare(struct vb2_buffer *vb)
+static int go7007_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
 	struct go7007_buffer *go7007_vb =
 		container_of(vb, struct go7007_buffer, vb);
@@ -404,9 +404,9 @@ static int go7007_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void go7007_buf_finish(struct vb2_buffer *vb)
+static void go7007_buf_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *vq = vb->vb2_queue;
+	struct vb2_queue *vq = vb->vb2.vb2_queue;
 	struct go7007 *go = vb2_get_drv_priv(vq);
 	struct go7007_buffer *go7007_vb =
 		container_of(vb, struct go7007_buffer, vb);
diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c
index fd1fa41..6037040 100644
--- a/drivers/media/usb/hackrf/hackrf.c
+++ b/drivers/media/usb/hackrf/hackrf.c
@@ -85,7 +85,7 @@ static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
 
 /* intermediate buffers with raw data from the USB device */
 struct hackrf_frame_buf {
-	struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
+	struct vb2_v4l2_buffer vb;   /* common v4l buffer stuff -- must be first */
 	struct list_head list;
 };
 
@@ -481,9 +481,9 @@ static int hackrf_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static void hackrf_buf_queue(struct vb2_buffer *vb)
+static void hackrf_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct hackrf_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct hackrf_dev *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct hackrf_frame_buf *buf =
 			container_of(vb, struct hackrf_frame_buf, vb);
 	unsigned long flags;
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index efc761c..4ed8675 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -115,7 +115,7 @@ static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
 
 /* intermediate buffers with raw data from the USB device */
 struct msi2500_frame_buf {
-	struct vb2_buffer vb;   /* common v4l buffer stuff -- must be first */
+	struct vb2_v4l2_buffer vb;   /* common v4l buffer stuff -- must be first */
 	struct list_head list;
 };
 
@@ -629,9 +629,9 @@ static int msi2500_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static void msi2500_buf_queue(struct vb2_buffer *vb)
+static void msi2500_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct msi2500_state *s = vb2_get_drv_priv(vb->vb2_queue);
+	struct msi2500_state *s = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct msi2500_frame_buf *buf =
 			container_of(vb, struct msi2500_frame_buf, vb);
 	unsigned long flags;
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 702267e..5ef46a0 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -592,7 +592,7 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_init(struct vb2_buffer *vb)
+static int buffer_init(struct vb2_v4l2_buffer *vb)
 {
 	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
 
@@ -604,9 +604,9 @@ static int buffer_init(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
+	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 
 	/* Don't allow queing new buffers after device disconnection */
 	if (!pdev->udev)
@@ -615,9 +615,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
+	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
 
 	if (vb->state == VB2_BUF_STATE_DONE) {
@@ -625,22 +625,22 @@ static void buffer_finish(struct vb2_buffer *vb)
 		 * Application has called dqbuf and is getting back a buffer
 		 * we've filled, take the pwc data we've stored in buf->data
 		 * and decompress it into a usable format, storing the result
-		 * in the vb2_buffer.
+		 * in the vb2_v4l2_buffer.
 		 */
 		pwc_decompress(pdev, buf);
 	}
 }
 
-static void buffer_cleanup(struct vb2_buffer *vb)
+static void buffer_cleanup(struct vb2_v4l2_buffer *vb)
 {
 	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
 
 	vfree(buf->data);
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
+	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
 	unsigned long flags = 0;
 
diff --git a/drivers/media/usb/pwc/pwc.h b/drivers/media/usb/pwc/pwc.h
index 81b017a..e2c12dc 100644
--- a/drivers/media/usb/pwc/pwc.h
+++ b/drivers/media/usb/pwc/pwc.h
@@ -210,7 +210,7 @@ struct pwc_raw_frame {
 /* intermediate buffers with raw data from the USB cam */
 struct pwc_frame_buf
 {
-	struct vb2_buffer vb;	/* common v4l buffer stuff -- must be first */
+	struct vb2_v4l2_buffer vb;	/* common v4l buffer stuff -- must be first */
 	struct list_head list;
 	void *data;
 	int filled;		/* number of bytes filled */
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 0f3c34d..110c932 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -293,7 +293,7 @@ struct s2255_fmt {
 /* buffer for one video frame */
 struct s2255_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
@@ -671,9 +671,9 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb)
+static int buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2_queue);
+	struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb);
 	int w = vc->width;
 	int h = vc->height;
@@ -700,10 +700,10 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb);
-	struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2_queue);
+	struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	unsigned long flags = 0;
 	dprintk(vc->dev, 1, "%s\n", __func__);
 	spin_lock_irqsave(&vc->qlock, flags);
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index 65a326c..3ee5cd9 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -538,10 +538,10 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *v4l_fmt,
 	return 0;
 }
 
-static void buffer_queue(struct vb2_buffer *vb)
+static void buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	unsigned long flags;
-	struct stk1160 *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct stk1160 *dev = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct stk1160_buffer *buf =
 		container_of(vb, struct stk1160_buffer, vb);
 
diff --git a/drivers/media/usb/stk1160/stk1160.h b/drivers/media/usb/stk1160/stk1160.h
index abdea48..11c8239 100644
--- a/drivers/media/usb/stk1160/stk1160.h
+++ b/drivers/media/usb/stk1160/stk1160.h
@@ -23,7 +23,7 @@
 #include <linux/i2c.h>
 #include <sound/core.h>
 #include <sound/ac97_codec.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ctrls.h>
 
@@ -78,7 +78,7 @@
 /* Buffer for one video frame */
 struct stk1160_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 
 	void *mem;
diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c
index 9d3525f..51d9437 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -29,7 +29,7 @@
  */
 
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 #include "usbtv.h"
 
@@ -612,9 +612,9 @@ static int usbtv_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static void usbtv_buf_queue(struct vb2_buffer *vb)
+static void usbtv_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct usbtv *usbtv = vb2_get_drv_priv(vb->vb2_queue);
+	struct usbtv *usbtv = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct usbtv_buf *buf = container_of(vb, struct usbtv_buf, vb);
 	unsigned long flags;
 
diff --git a/drivers/media/usb/usbtv/usbtv.h b/drivers/media/usb/usbtv/usbtv.h
index 9681195..a1a4d95 100644
--- a/drivers/media/usb/usbtv/usbtv.h
+++ b/drivers/media/usb/usbtv/usbtv.h
@@ -61,7 +61,7 @@ struct usbtv_norm_params {
 
 /* A single videobuf2 frame buffer. */
 struct usbtv_buf {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 10c554e..8b52fd2 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -87,9 +87,9 @@ static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int uvc_buffer_prepare(struct vb2_buffer *vb)
+static int uvc_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
+	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
 
 	if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
@@ -113,9 +113,9 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void uvc_buffer_queue(struct vb2_buffer *vb)
+static void uvc_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
+	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
 	unsigned long flags;
 
@@ -133,13 +133,13 @@ static void uvc_buffer_queue(struct vb2_buffer *vb)
 	spin_unlock_irqrestore(&queue->irqlock, flags);
 }
 
-static void uvc_buffer_finish(struct vb2_buffer *vb)
+static void uvc_buffer_finish(struct vb2_v4l2_buffer *vb)
 {
-	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
+	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2.vb2_queue);
 	struct uvc_streaming *stream = uvc_queue_to_stream(queue);
 	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
 
-	if (vb->state == VB2_BUF_STATE_DONE)
+	if (vb->vb2.state == VB2_BUF_STATE_DONE)
 		uvc_video_clock_update(stream, &vb->v4l2_buf, buf);
 }
 
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index c63e5b5..e4525bf 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -15,7 +15,7 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-fh.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 /* --------------------------------------------------------------------------
  * UVC constants
@@ -354,7 +354,7 @@ enum uvc_buffer_state {
 };
 
 struct uvc_buffer {
-	struct vb2_buffer buf;
+	struct vb2_v4l2_buffer buf;
 	struct list_head queue;
 
 	enum uvc_buffer_state state;
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 63d29f2..bd9a6ef 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -28,7 +28,7 @@ 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_VIDEOBUF2_CORE) += videobuf2-core.o
+obj-$(CONFIG_VIDEOBUF2_CORE) += videobuf2-v4l2.o
 obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o
 obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o
 obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index b084072..1bab53e 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -26,7 +26,7 @@
 #include <media/v4l2-fh.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-device.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/v4l2.h>
diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 80c588f..3392a58 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -17,7 +17,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-dev.h>
 #include <media/v4l2-fh.h>
@@ -739,13 +739,13 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_release);
  *
  * Call from buf_queue(), videobuf_queue_ops callback.
  */
-void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_buffer *vb)
+void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_v4l2_buffer *vb)
 {
 	struct v4l2_m2m_buffer *b = container_of(vb, struct v4l2_m2m_buffer, vb);
 	struct v4l2_m2m_queue_ctx *q_ctx;
 	unsigned long flags;
 
-	q_ctx = get_queue_ctx(m2m_ctx, vb->vb2_queue->type);
+	q_ctx = get_queue_ctx(m2m_ctx, vb->vb2.vb2_queue->type);
 	if (!q_ctx)
 		return;
 
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index cc16e76..0d8bd9a 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -51,12 +51,12 @@ module_param(debug, int, 0644);
 
 #define log_memop(vb, op)						\
 	dprintk(2, "call_memop(%p, %d, %s)%s\n",			\
-		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
-		(vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
+		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
+		(vb)->vb2.vb2_queue->mem_ops->op ? "" : " (nop)")
 
 #define call_memop(vb, op, args...)					\
 ({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
 	int err;							\
 									\
 	log_memop(vb, op);						\
@@ -68,7 +68,7 @@ module_param(debug, int, 0644);
 
 #define call_ptr_memop(vb, op, args...)					\
 ({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
 	void *ptr;							\
 									\
 	log_memop(vb, op);						\
@@ -80,7 +80,7 @@ module_param(debug, int, 0644);
 
 #define call_void_memop(vb, op, args...)				\
 ({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
 									\
 	log_memop(vb, op);						\
 	if (_q->mem_ops->op)						\
@@ -113,16 +113,16 @@ module_param(debug, int, 0644);
 
 #define log_vb_qop(vb, op, args...)					\
 	dprintk(2, "call_vb_qop(%p, %d, %s)%s\n",			\
-		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
-		(vb)->vb2_queue->ops->op ? "" : " (nop)")
+		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
+		(vb)->vb2.vb2_queue->ops->op ? "" : " (nop)")
 
 #define call_vb_qop(vb, op, args...)					\
 ({									\
 	int err;							\
 									\
 	log_vb_qop(vb, op);						\
-	err = (vb)->vb2_queue->ops->op ?				\
-		(vb)->vb2_queue->ops->op(args) : 0;			\
+	err = (vb)->vb2.vb2_queue->ops->op ?				\
+		(vb)->vb2.vb2_queue->ops->op(args) : 0;			\
 	if (!err)							\
 		(vb)->cnt_ ## op++;					\
 	err;								\
@@ -131,25 +131,25 @@ module_param(debug, int, 0644);
 #define call_void_vb_qop(vb, op, args...)				\
 ({									\
 	log_vb_qop(vb, op);						\
-	if ((vb)->vb2_queue->ops->op)					\
-		(vb)->vb2_queue->ops->op(args);				\
+	if ((vb)->vb2.vb2_queue->ops->op)					\
+		(vb)->vb2.vb2_queue->ops->op(args);				\
 	(vb)->cnt_ ## op++;						\
 })
 
 #else
 
 #define call_memop(vb, op, args...)					\
-	((vb)->vb2_queue->mem_ops->op ?					\
-		(vb)->vb2_queue->mem_ops->op(args) : 0)
+	((vb)->vb2.vb2_queue->mem_ops->op ?					\
+		(vb)->vb2.vb2_queue->mem_ops->op(args) : 0)
 
 #define call_ptr_memop(vb, op, args...)					\
-	((vb)->vb2_queue->mem_ops->op ?					\
-		(vb)->vb2_queue->mem_ops->op(args) : NULL)
+	((vb)->vb2.vb2_queue->mem_ops->op ?					\
+		(vb)->vb2.vb2_queue->mem_ops->op(args) : NULL)
 
 #define call_void_memop(vb, op, args...)				\
 	do {								\
-		if ((vb)->vb2_queue->mem_ops->op)			\
-			(vb)->vb2_queue->mem_ops->op(args);		\
+		if ((vb)->vb2.vb2_queue->mem_ops->op)			\
+			(vb)->vb2.vb2_queue->mem_ops->op(args);		\
 	} while (0)
 
 #define call_qop(q, op, args...)					\
@@ -162,12 +162,12 @@ module_param(debug, int, 0644);
 	} while (0)
 
 #define call_vb_qop(vb, op, args...)					\
-	((vb)->vb2_queue->ops->op ? (vb)->vb2_queue->ops->op(args) : 0)
+	((vb)->vb2.vb2_queue->ops->op ? (vb)->vb2.vb2_queue->ops->op(args) : 0)
 
 #define call_void_vb_qop(vb, op, args...)				\
 	do {								\
-		if ((vb)->vb2_queue->ops->op)				\
-			(vb)->vb2_queue->ops->op(args);			\
+		if ((vb)->vb2.vb2_queue->ops->op)				\
+			(vb)->vb2.vb2_queue->ops->op(args);			\
 	} while (0)
 
 #endif
@@ -186,9 +186,9 @@ static void __vb2_queue_cancel(struct vb2_queue *q);
 /**
  * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
  */
-static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
+static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	enum dma_data_direction dma_dir =
 		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
 	void *mem_priv;
@@ -198,7 +198,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 	 * Allocate memory for all planes in this buffer
 	 * NOTE: mmapped areas should be page aligned
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 		unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
 
 		mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
@@ -207,7 +207,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 			goto free;
 
 		/* Associate allocator private data with this plane */
-		vb->planes[plane].mem_priv = mem_priv;
+		vb->vb2.planes[plane].mem_priv = mem_priv;
 		vb->v4l2_planes[plane].length = q->plane_sizes[plane];
 	}
 
@@ -215,8 +215,8 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 free:
 	/* Free already allocated memory if one of the allocations failed */
 	for (; plane > 0; --plane) {
-		call_void_memop(vb, put, vb->planes[plane - 1].mem_priv);
-		vb->planes[plane - 1].mem_priv = NULL;
+		call_void_memop(vb, put, vb->vb2.planes[plane - 1].mem_priv);
+		vb->vb2.planes[plane - 1].mem_priv = NULL;
 	}
 
 	return -ENOMEM;
@@ -225,13 +225,13 @@ free:
 /**
  * __vb2_buf_mem_free() - free memory of the given buffer
  */
-static void __vb2_buf_mem_free(struct vb2_buffer *vb)
+static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		call_void_memop(vb, put, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		call_void_memop(vb, put, vb->vb2.planes[plane].mem_priv);
+		vb->vb2.planes[plane].mem_priv = NULL;
 		dprintk(3, "freed plane %d of buffer %d\n", plane,
 			vb->v4l2_buf.index);
 	}
@@ -241,14 +241,14 @@ static void __vb2_buf_mem_free(struct vb2_buffer *vb)
  * __vb2_buf_userptr_put() - release userspace memory associated with
  * a USERPTR buffer
  */
-static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
+static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		if (vb->planes[plane].mem_priv)
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		if (vb->vb2.planes[plane].mem_priv)
+			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
+		vb->vb2.planes[plane].mem_priv = NULL;
 	}
 }
 
@@ -256,7 +256,7 @@ static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
  * __vb2_plane_dmabuf_put() - release memory associated with
  * a DMABUF shared plane
  */
-static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
+static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane *p)
 {
 	if (!p->mem_priv)
 		return;
@@ -273,12 +273,12 @@ static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
  * __vb2_buf_dmabuf_put() - release memory associated with
  * a DMABUF shared buffer
  */
-static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
+static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
 
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
+		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
 }
 
 /**
@@ -288,14 +288,14 @@ static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
 static void __setup_lengths(struct vb2_queue *q, unsigned int n)
 {
 	unsigned int buffer, plane;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
 		vb = q->bufs[buffer];
 		if (!vb)
 			continue;
 
-		for (plane = 0; plane < vb->num_planes; ++plane)
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane)
 			vb->v4l2_planes[plane].length = q->plane_sizes[plane];
 	}
 }
@@ -307,13 +307,13 @@ static void __setup_lengths(struct vb2_queue *q, unsigned int n)
 static void __setup_offsets(struct vb2_queue *q, unsigned int n)
 {
 	unsigned int buffer, plane;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned long off;
 
 	if (q->num_buffers) {
 		struct v4l2_plane *p;
 		vb = q->bufs[q->num_buffers - 1];
-		p = &vb->v4l2_planes[vb->num_planes - 1];
+		p = &vb->v4l2_planes[vb->vb2.num_planes - 1];
 		off = PAGE_ALIGN(p->m.mem_offset + p->length);
 	} else {
 		off = 0;
@@ -324,7 +324,7 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
 		if (!vb)
 			continue;
 
-		for (plane = 0; plane < vb->num_planes; ++plane) {
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 			vb->v4l2_planes[plane].m.mem_offset = off;
 
 			dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
@@ -347,7 +347,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 			     unsigned int num_buffers, unsigned int num_planes)
 {
 	unsigned int buffer;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int ret;
 
 	for (buffer = 0; buffer < num_buffers; ++buffer) {
@@ -362,9 +362,9 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 		if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
 			vb->v4l2_buf.length = num_planes;
 
-		vb->state = VB2_BUF_STATE_DEQUEUED;
-		vb->vb2_queue = q;
-		vb->num_planes = num_planes;
+		vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
+		vb->vb2.vb2_queue = q;
+		vb->vb2.num_planes = num_planes;
 		vb->v4l2_buf.index = q->num_buffers + buffer;
 		vb->v4l2_buf.type = q->type;
 		vb->v4l2_buf.memory = memory;
@@ -412,7 +412,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
 {
 	unsigned int buffer;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
 	     ++buffer) {
@@ -438,6 +438,7 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
 static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 {
 	unsigned int buffer;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * Sanity check: when preparing a buffer the queue lock is released for
@@ -449,9 +450,11 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 	 */
 	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
 	     ++buffer) {
-		if (q->bufs[buffer] == NULL)
+		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
+
+		if (vb == NULL)
 			continue;
-		if (q->bufs[buffer]->state == VB2_BUF_STATE_PREPARING) {
+		if (vb->vb2.state == VB2_BUF_STATE_PREPARING) {
 			dprintk(1, "preparing buffers, cannot free\n");
 			return -EAGAIN;
 		}
@@ -460,9 +463,9 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 	/* Call driver-provided cleanup function for each buffer, if provided */
 	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
 	     ++buffer) {
-		struct vb2_buffer *vb = q->bufs[buffer];
+		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
 
-		if (vb && vb->planes[0].mem_priv)
+		if (vb && vb->vb2.planes[0].mem_priv)
 			call_void_vb_qop(vb, buf_cleanup, vb);
 	}
 
@@ -495,38 +498,38 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 		q->cnt_stop_streaming = 0;
 	}
 	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
-		struct vb2_buffer *vb = q->bufs[buffer];
-		bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put ||
-				  vb->cnt_mem_prepare != vb->cnt_mem_finish ||
-				  vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr ||
-				  vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf ||
-				  vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf ||
-				  vb->cnt_buf_queue != vb->cnt_buf_done ||
-				  vb->cnt_buf_prepare != vb->cnt_buf_finish ||
-				  vb->cnt_buf_init != vb->cnt_buf_cleanup;
+		struct vb2_v4l2_buffer *vb = q->bufs[buffer];
+		bool unbalanced = vb->vb2.cnt_mem_alloc != vb->vb2.cnt_mem_put ||
+				  vb->vb2.cnt_mem_prepare != vb->vb2.cnt_mem_finish ||
+				  vb->vb2.cnt_mem_get_userptr != vb->vb2.cnt_mem_put_userptr ||
+				  vb->vb2.cnt_mem_attach_dmabuf != vb->vb2.cnt_mem_detach_dmabuf ||
+				  vb->vb2.cnt_mem_map_dmabuf != vb->vb2.cnt_mem_unmap_dmabuf ||
+				  vb->vb2.cnt_buf_queue != vb->vb2.cnt_buf_done ||
+				  vb->vb2.cnt_buf_prepare != vb->vb2.cnt_buf_finish ||
+				  vb->vb2.cnt_buf_init != vb->vb2.cnt_buf_cleanup;
 
 		if (unbalanced || debug) {
 			pr_info("vb2:   counters for queue %p, buffer %d:%s\n",
 				q, buffer, unbalanced ? " UNBALANCED!" : "");
 			pr_info("vb2:     buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n",
-				vb->cnt_buf_init, vb->cnt_buf_cleanup,
-				vb->cnt_buf_prepare, vb->cnt_buf_finish);
+				vb->vb2.cnt_buf_init, vb->vb2.cnt_buf_cleanup,
+				vb->vb2.cnt_buf_prepare, vb->vb2.cnt_buf_finish);
 			pr_info("vb2:     buf_queue: %u buf_done: %u\n",
-				vb->cnt_buf_queue, vb->cnt_buf_done);
+				vb->vb2.cnt_buf_queue, vb->vb2.cnt_buf_done);
 			pr_info("vb2:     alloc: %u put: %u prepare: %u finish: %u mmap: %u\n",
-				vb->cnt_mem_alloc, vb->cnt_mem_put,
-				vb->cnt_mem_prepare, vb->cnt_mem_finish,
-				vb->cnt_mem_mmap);
+				vb->vb2.cnt_mem_alloc, vb->vb2.cnt_mem_put,
+				vb->vb2.cnt_mem_prepare, vb->vb2.cnt_mem_finish,
+				vb->vb2.cnt_mem_mmap);
 			pr_info("vb2:     get_userptr: %u put_userptr: %u\n",
-				vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr);
+				vb->vb2.cnt_mem_get_userptr, vb->vb2.cnt_mem_put_userptr);
 			pr_info("vb2:     attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n",
-				vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf,
-				vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf);
+				vb->vb2.cnt_mem_attach_dmabuf, vb->vb2.cnt_mem_detach_dmabuf,
+				vb->vb2.cnt_mem_map_dmabuf, vb->vb2.cnt_mem_unmap_dmabuf);
 			pr_info("vb2:     get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n",
-				vb->cnt_mem_get_dmabuf,
-				vb->cnt_mem_num_users,
-				vb->cnt_mem_vaddr,
-				vb->cnt_mem_cookie);
+				vb->vb2.cnt_mem_get_dmabuf,
+				vb->vb2.cnt_mem_num_users,
+				vb->vb2.cnt_mem_vaddr,
+				vb->vb2.cnt_mem_cookie);
 		}
 	}
 #endif
@@ -550,7 +553,7 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
  * __verify_planes_array() - verify that the planes array passed in struct
  * v4l2_buffer from userspace can be safely used
  */
-static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
 		return 0;
@@ -562,9 +565,9 @@ static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer
 		return -EINVAL;
 	}
 
-	if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
+	if (b->length < vb->vb2.num_planes || b->length > VIDEO_MAX_PLANES) {
 		dprintk(1, "incorrect planes array length, "
-			   "expected %d, got %d\n", vb->num_planes, b->length);
+			   "expected %d, got %d\n", vb->vb2.num_planes, b->length);
 		return -EINVAL;
 	}
 
@@ -575,7 +578,7 @@ static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer
  * __verify_length() - Verify that the bytesused value for each plane fits in
  * the plane length and that the data offset doesn't exceed the bytesused value.
  */
-static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	unsigned int length;
 	unsigned int bytesused;
@@ -585,7 +588,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		return 0;
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
-		for (plane = 0; plane < vb->num_planes; ++plane) {
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 			length = (b->memory == V4L2_MEMORY_USERPTR ||
 				  b->memory == V4L2_MEMORY_DMABUF)
 			       ? b->m.planes[plane].length
@@ -616,11 +619,11 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
  * __buffer_in_use() - return true if the buffer is in use and
  * the queue cannot be freed (by the means of REQBUFS(0)) call
  */
-static bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
+static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		void *mem_priv = vb->planes[plane].mem_priv;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		void *mem_priv = vb->vb2.planes[plane].mem_priv;
 		/*
 		 * If num_users() has not been provided, call_memop
 		 * will return 0, apparently nobody cares about this
@@ -651,9 +654,9 @@ static bool __buffers_in_use(struct vb2_queue *q)
  * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
  * returned to userspace
  */
-static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
+static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 
 	/* Copy back data such as timestamp, flags, etc. */
 	memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
@@ -665,7 +668,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 		 * Fill in plane-related data if userspace provided an array
 		 * for it. The caller has already verified memory and size.
 		 */
-		b->length = vb->num_planes;
+		b->length = vb->vb2.num_planes;
 		memcpy(b->m.planes, vb->v4l2_planes,
 			b->length * sizeof(struct v4l2_plane));
 	} else {
@@ -698,7 +701,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 	}
 
-	switch (vb->state) {
+	switch (vb->vb2.state) {
 	case VB2_BUF_STATE_QUEUED:
 	case VB2_BUF_STATE_ACTIVE:
 		b->flags |= V4L2_BUF_FLAG_QUEUED;
@@ -737,7 +740,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
  */
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int ret;
 
 	if (b->type != q->type) {
@@ -857,7 +860,7 @@ static int __verify_memory_type(struct vb2_queue *q,
  * 2) sets up the queue,
  * 3) negotiates number of buffers and planes per buffer with the driver
  *    to be used during streaming,
- * 4) allocates internal buffer structures (struct vb2_buffer), according to
+ * 4) allocates internal buffer structures (struct vb2_v4l2_buffer), according to
  *    the agreed parameters,
  * 5) for MMAP memory type, allocates actual video memory, using the
  *    memory handling/allocation routines provided during queue initialization
@@ -1114,45 +1117,45 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
 /**
  * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
- * @vb:		vb2_buffer to which the plane in question belongs to
+ * @vb:		vb2_v4l2_buffer to which the plane in question belongs to
  * @plane_no:	plane number for which the address is to be returned
  *
  * This function returns a kernel virtual address of a given plane if
  * such a mapping exist, NULL otherwise.
  */
-void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no)
+void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
-	if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
+	if (plane_no > vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
 		return NULL;
 
-	return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
+	return call_ptr_memop(vb, vaddr, vb->vb2.planes[plane_no].mem_priv);
 
 }
 EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
 
 /**
  * vb2_plane_cookie() - Return allocator specific cookie for the given plane
- * @vb:		vb2_buffer to which the plane in question belongs to
+ * @vb:		vb2_v4l2_buffer to which the plane in question belongs to
  * @plane_no:	plane number for which the cookie is to be returned
  *
  * This function returns an allocator specific cookie for a given plane if
  * available, NULL otherwise. The allocator should provide some simple static
- * inline function, which would convert this cookie to the allocator specific
+ * inline funaction, which would convert this cookie to the allocator specific
  * type that can be used directly by the driver to access the buffer. This can
  * be for example physical address, pointer to scatter list or IOMMU mapping.
  */
-void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no)
+void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
-	if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
+	if (plane_no >= vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
 		return NULL;
 
-	return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
+	return call_ptr_memop(vb, cookie, vb->vb2.planes[plane_no].mem_priv);
 }
 EXPORT_SYMBOL_GPL(vb2_plane_cookie);
 
 /**
  * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished
- * @vb:		vb2_buffer returned from the driver
+ * @vb:		vb2_v4l2_buffer returned from the driver
  * @state:	either VB2_BUF_STATE_DONE if the operation finished successfully
  *		or VB2_BUF_STATE_ERROR if the operation finished with an error.
  *		If start_streaming fails then it should return buffers with state
@@ -1169,13 +1172,13 @@ EXPORT_SYMBOL_GPL(vb2_plane_cookie);
  * be started for some reason. In that case the buffers should be returned with
  * state QUEUED.
  */
-void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
+void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	unsigned long flags;
 	unsigned int plane;
 
-	if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
+	if (WARN_ON(vb->vb2.state != VB2_BUF_STATE_ACTIVE))
 		return;
 
 	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
@@ -1188,20 +1191,20 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 	 * Although this is not a callback, it still does have to balance
 	 * with the buf_queue op. So update this counter manually.
 	 */
-	vb->cnt_buf_done++;
+	vb->vb2.cnt_buf_done++;
 #endif
 	dprintk(4, "done processing on buffer %d, state: %d\n",
 			vb->v4l2_buf.index, state);
 
 	/* sync buffers */
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
+		call_void_memop(vb, finish, vb->vb2.planes[plane].mem_priv);
 
 	/* Add the buffer to the done buffers list */
 	spin_lock_irqsave(&q->done_lock, flags);
-	vb->state = state;
+	vb->vb2.state = state;
 	if (state != VB2_BUF_STATE_QUEUED)
-		list_add_tail(&vb->done_entry, &q->done_list);
+		list_add_tail(&vb->vb2.done_entry, &q->done_list);
 	atomic_dec(&q->owned_by_drv_count);
 	spin_unlock_irqrestore(&q->done_lock, flags);
 
@@ -1238,18 +1241,18 @@ void vb2_discard_done(struct vb2_queue *q)
 EXPORT_SYMBOL_GPL(vb2_discard_done);
 
 /**
- * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a
+ * __fill_vb2_buffer() - fill a vb2_v4l2_buffer with information provided in a
  * v4l2_buffer by the userspace. The caller has already verified that struct
  * v4l2_buffer has a valid number of planes.
  */
-static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b,
+static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b,
 				struct v4l2_plane *v4l2_planes)
 {
 	unsigned int plane;
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
 		if (b->memory == V4L2_MEMORY_USERPTR) {
-			for (plane = 0; plane < vb->num_planes; ++plane) {
+			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 				v4l2_planes[plane].m.userptr =
 					b->m.planes[plane].m.userptr;
 				v4l2_planes[plane].length =
@@ -1257,7 +1260,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 			}
 		}
 		if (b->memory == V4L2_MEMORY_DMABUF) {
-			for (plane = 0; plane < vb->num_planes; ++plane) {
+			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 				v4l2_planes[plane].m.fd =
 					b->m.planes[plane].m.fd;
 				v4l2_planes[plane].length =
@@ -1277,7 +1280,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 			 * it's a safe assumption that they really meant to
 			 * use the full plane sizes.
 			 */
-			for (plane = 0; plane < vb->num_planes; ++plane) {
+			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 				struct v4l2_plane *pdst = &v4l2_planes[plane];
 				struct v4l2_plane *psrc = &b->m.planes[plane];
 
@@ -1316,7 +1319,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 
 	/* Zero flags that the vb2 core handles */
 	vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
-	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
+	if ((vb->vb2.vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
 	    V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
 		/*
 		 * Non-COPY timestamps and non-OUTPUT queues will get
@@ -1344,7 +1347,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 /**
  * __qbuf_mmap() - handle qbuf of an MMAP buffer
  */
-static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_mmap(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	__fill_vb2_buffer(vb, b, vb->v4l2_planes);
 	return call_vb_qop(vb, buf_prepare, vb);
@@ -1353,22 +1356,22 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 /**
  * __qbuf_userptr() - handle qbuf of a USERPTR buffer
  */
-static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct v4l2_plane planes[VIDEO_MAX_PLANES];
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	void *mem_priv;
 	unsigned int plane;
 	int ret;
 	enum dma_data_direction dma_dir =
 		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-	bool reacquired = vb->planes[0].mem_priv == NULL;
+	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
 
-	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
+	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
 	/* Copy relevant information provided by the userspace */
 	__fill_vb2_buffer(vb, b, planes);
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 		/* Skip the plane if already verified */
 		if (vb->v4l2_planes[plane].m.userptr &&
 		    vb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
@@ -1389,15 +1392,15 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 
 		/* Release previously acquired memory if present */
-		if (vb->planes[plane].mem_priv) {
+		if (vb->vb2.planes[plane].mem_priv) {
 			if (!reacquired) {
 				reacquired = true;
 				call_void_vb_qop(vb, buf_cleanup, vb);
 			}
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
+			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
 		}
 
-		vb->planes[plane].mem_priv = NULL;
+		vb->vb2.planes[plane].mem_priv = NULL;
 		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
 
 		/* Acquire each plane's memory */
@@ -1410,14 +1413,14 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 			ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
 			goto err;
 		}
-		vb->planes[plane].mem_priv = mem_priv;
+		vb->vb2.planes[plane].mem_priv = mem_priv;
 	}
 
 	/*
 	 * Now that everything is in order, copy relevant information
 	 * provided by userspace.
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane)
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
 		vb->v4l2_planes[plane] = planes[plane];
 
 	if (reacquired) {
@@ -1443,10 +1446,10 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	return 0;
 err:
 	/* In case of errors, release planes that were already acquired */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		if (vb->planes[plane].mem_priv)
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		if (vb->vb2.planes[plane].mem_priv)
+			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
+		vb->vb2.planes[plane].mem_priv = NULL;
 		vb->v4l2_planes[plane].m.userptr = 0;
 		vb->v4l2_planes[plane].length = 0;
 	}
@@ -1457,22 +1460,22 @@ err:
 /**
  * __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
  */
-static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct v4l2_plane planes[VIDEO_MAX_PLANES];
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	void *mem_priv;
 	unsigned int plane;
 	int ret;
 	enum dma_data_direction dma_dir =
 		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-	bool reacquired = vb->planes[0].mem_priv == NULL;
+	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
 
-	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
+	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
 	/* Copy relevant information provided by the userspace */
 	__fill_vb2_buffer(vb, b, planes);
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 		struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
 
 		if (IS_ERR_OR_NULL(dbuf)) {
@@ -1494,7 +1497,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 
 		/* Skip the plane if already verified */
-		if (dbuf == vb->planes[plane].dbuf &&
+		if (dbuf == vb->vb2.planes[plane].dbuf &&
 		    vb->v4l2_planes[plane].length == planes[plane].length) {
 			dma_buf_put(dbuf);
 			continue;
@@ -1508,7 +1511,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 
 		/* Release previously acquired memory if present */
-		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
+		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
 		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
 
 		/* Acquire each plane's memory */
@@ -1521,29 +1524,29 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 			goto err;
 		}
 
-		vb->planes[plane].dbuf = dbuf;
-		vb->planes[plane].mem_priv = mem_priv;
+		vb->vb2.planes[plane].dbuf = dbuf;
+		vb->vb2.planes[plane].mem_priv = mem_priv;
 	}
 
 	/* TODO: This pins the buffer(s) with  dma_buf_map_attachment()).. but
 	 * really we want to do this just before the DMA, not while queueing
 	 * the buffer(s)..
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		ret = call_memop(vb, map_dmabuf, vb->vb2.planes[plane].mem_priv);
 		if (ret) {
 			dprintk(1, "failed to map dmabuf for plane %d\n",
 				plane);
 			goto err;
 		}
-		vb->planes[plane].dbuf_mapped = 1;
+		vb->vb2.planes[plane].dbuf_mapped = 1;
 	}
 
 	/*
 	 * Now that everything is in order, copy relevant information
 	 * provided by userspace.
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane)
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
 		vb->v4l2_planes[plane] = planes[plane];
 
 	if (reacquired) {
@@ -1574,10 +1577,11 @@ err:
 }
 
 /**
- * __enqueue_in_driver() - enqueue a vb2_buffer in driver for processing
+ * __enqueue_in_driver() - enqueue a vb2_v4l2_buffer in driver for processing
  */
 static void __enqueue_in_driver(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *pb = container_of(vb, struct vb2_v4l2_buffer, vb2);
 	struct vb2_queue *q = vb->vb2_queue;
 	unsigned int plane;
 
@@ -1586,14 +1590,14 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
 
 	/* sync buffers */
 	for (plane = 0; plane < vb->num_planes; ++plane)
-		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
+		call_void_memop(pb, prepare, vb->planes[plane].mem_priv);
 
-	call_void_vb_qop(vb, buf_queue, vb);
+	call_void_vb_qop(pb, buf_queue, pb);
 }
 
-static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	int ret;
 
 	ret = __verify_length(vb, b);
@@ -1620,7 +1624,7 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		return -EIO;
 	}
 
-	vb->state = VB2_BUF_STATE_PREPARING;
+	vb->vb2.state = VB2_BUF_STATE_PREPARING;
 	vb->v4l2_buf.timestamp.tv_sec = 0;
 	vb->v4l2_buf.timestamp.tv_usec = 0;
 	vb->v4l2_buf.sequence = 0;
@@ -1644,7 +1648,7 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 
 	if (ret)
 		dprintk(1, "buffer preparation failed: %d\n", ret);
-	vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
+	vb->vb2.state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
 
 	return ret;
 }
@@ -1693,7 +1697,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
  */
 int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int ret;
 
 	if (vb2_fileio_is_active(q)) {
@@ -1706,9 +1710,9 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 		return ret;
 
 	vb = q->bufs[b->index];
-	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
+	if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
 		dprintk(1, "invalid buffer state %d\n",
-			vb->state);
+			vb->vb2.state);
 		return -EINVAL;
 	}
 
@@ -1737,6 +1741,7 @@ EXPORT_SYMBOL_GPL(vb2_prepare_buf);
 static int vb2_start_streaming(struct vb2_queue *q)
 {
 	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *pb;
 	int ret;
 
 	/*
@@ -1770,9 +1775,9 @@ static int vb2_start_streaming(struct vb2_queue *q)
 		 * correctly return them to vb2.
 		 */
 		for (i = 0; i < q->num_buffers; ++i) {
-			vb = q->bufs[i];
-			if (vb->state == VB2_BUF_STATE_ACTIVE)
-				vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED);
+			pb = q->bufs[i];
+			if (pb->vb2.state == VB2_BUF_STATE_ACTIVE)
+				vb2_buffer_done(pb, VB2_BUF_STATE_QUEUED);
 		}
 		/* Must be zero now */
 		WARN_ON(atomic_read(&q->owned_by_drv_count));
@@ -1789,14 +1794,14 @@ static int vb2_start_streaming(struct vb2_queue *q)
 static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
 	int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	if (ret)
 		return ret;
 
 	vb = q->bufs[b->index];
 
-	switch (vb->state) {
+	switch (vb->vb2.state) {
 	case VB2_BUF_STATE_DEQUEUED:
 		ret = __buf_prepare(vb, b);
 		if (ret)
@@ -1808,7 +1813,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 		dprintk(1, "buffer still being prepared\n");
 		return -EINVAL;
 	default:
-		dprintk(1, "invalid buffer state %d\n", vb->state);
+		dprintk(1, "invalid buffer state %d\n", vb->vb2.state);
 		return -EINVAL;
 	}
 
@@ -1816,10 +1821,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 	 * Add to the queued buffers list, a buffer will stay on it until
 	 * dequeued in dqbuf.
 	 */
-	list_add_tail(&vb->queued_entry, &q->queued_list);
+	list_add_tail(&vb->vb2.queued_entry, &q->queued_list);
 	q->queued_count++;
 	q->waiting_for_buffers = false;
-	vb->state = VB2_BUF_STATE_QUEUED;
+	vb->vb2.state = VB2_BUF_STATE_QUEUED;
 	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
 		/*
 		 * For output buffers copy the timestamp if needed,
@@ -1838,7 +1843,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 	 * If not, the buffer will be given to driver on next streamon.
 	 */
 	if (q->start_streaming_called)
-		__enqueue_in_driver(vb);
+		__enqueue_in_driver(&vb->vb2);
 
 	/* Fill buffer information for the userspace */
 	__fill_v4l2_buffer(vb, b);
@@ -1964,11 +1969,12 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
  *
  * Will sleep if required for nonblocking == false.
  */
-static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
+static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
 				struct v4l2_buffer *b, int nonblocking)
 {
 	unsigned long flags;
 	int ret;
+	struct vb2_buffer *vb2 = NULL;
 
 	/*
 	 * Wait for at least one buffer to become available on the done_list.
@@ -1982,14 +1988,15 @@ static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
 	 * is not empty, so no need for another list_empty(done_list) check.
 	 */
 	spin_lock_irqsave(&q->done_lock, flags);
-	*vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
+	vb2 = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
+	*vb = container_of(vb2, struct vb2_v4l2_buffer, vb2); 
 	/*
 	 * Only remove the buffer from done_list if v4l2_buffer can handle all
 	 * the planes.
 	 */
 	ret = __verify_planes_array(*vb, b);
 	if (!ret)
-		list_del(&(*vb)->done_entry);
+		list_del(&(*vb)->vb2.done_entry);
 	spin_unlock_irqrestore(&q->done_lock, flags);
 
 	return ret;
@@ -2020,30 +2027,30 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
 /**
  * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
  */
-static void __vb2_dqbuf(struct vb2_buffer *vb)
+static void __vb2_dqbuf(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	unsigned int i;
 
 	/* nothing to do if the buffer is already dequeued */
-	if (vb->state == VB2_BUF_STATE_DEQUEUED)
+	if (vb->vb2.state == VB2_BUF_STATE_DEQUEUED)
 		return;
 
-	vb->state = VB2_BUF_STATE_DEQUEUED;
+	vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
 
 	/* unmap DMABUF buffer */
 	if (q->memory == V4L2_MEMORY_DMABUF)
-		for (i = 0; i < vb->num_planes; ++i) {
-			if (!vb->planes[i].dbuf_mapped)
+		for (i = 0; i < vb->vb2.num_planes; ++i) {
+			if (!vb->vb2.planes[i].dbuf_mapped)
 				continue;
-			call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
-			vb->planes[i].dbuf_mapped = 0;
+			call_void_memop(vb, unmap_dmabuf, vb->vb2.planes[i].mem_priv);
+			vb->vb2.planes[i].dbuf_mapped = 0;
 		}
 }
 
 static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
-	struct vb2_buffer *vb = NULL;
+	struct vb2_v4l2_buffer *vb = NULL;
 	int ret;
 
 	if (b->type != q->type) {
@@ -2054,7 +2061,7 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
 	if (ret < 0)
 		return ret;
 
-	switch (vb->state) {
+	switch (vb->vb2.state) {
 	case VB2_BUF_STATE_DONE:
 		dprintk(3, "returning done buffer\n");
 		break;
@@ -2071,13 +2078,13 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
 	/* Fill buffer information for the userspace */
 	__fill_v4l2_buffer(vb, b);
 	/* Remove from videobuf queue */
-	list_del(&vb->queued_entry);
+	list_del(&vb->vb2.queued_entry);
 	q->queued_count--;
 	/* go back to dequeued state */
 	__vb2_dqbuf(vb);
 
 	dprintk(1, "dqbuf of buffer %d, with state %d\n",
-			vb->v4l2_buf.index, vb->state);
+			vb->v4l2_buf.index, vb->vb2.state);
 
 	return 0;
 }
@@ -2122,6 +2129,7 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
 static void __vb2_queue_cancel(struct vb2_queue *q)
 {
 	unsigned int i;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * Tell driver to stop all transactions and release all queued
@@ -2138,8 +2146,11 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 	 */
 	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
 		for (i = 0; i < q->num_buffers; ++i)
-			if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE)
-				vb2_buffer_done(q->bufs[i], VB2_BUF_STATE_ERROR);
+		{
+			vb = (struct vb2_v4l2_buffer *)q->bufs[i];
+			if (vb->vb2.state == VB2_BUF_STATE_ACTIVE)
+				vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+		}
 		/* Must be zero now */
 		WARN_ON(atomic_read(&q->owned_by_drv_count));
 	}
@@ -2171,10 +2182,10 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 	 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
 	 */
 	for (i = 0; i < q->num_buffers; ++i) {
-		struct vb2_buffer *vb = q->bufs[i];
+		struct vb2_v4l2_buffer *vb = q->bufs[i];
 
-		if (vb->state != VB2_BUF_STATE_DEQUEUED) {
-			vb->state = VB2_BUF_STATE_PREPARED;
+		if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
+			vb->vb2.state = VB2_BUF_STATE_PREPARED;
 			call_void_vb_qop(vb, buf_finish, vb);
 		}
 		__vb2_dqbuf(vb);
@@ -2322,7 +2333,7 @@ EXPORT_SYMBOL_GPL(vb2_streamoff);
 static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
 			unsigned int *_buffer, unsigned int *_plane)
 {
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int buffer, plane;
 
 	/*
@@ -2333,7 +2344,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
 	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
 		vb = q->bufs[buffer];
 
-		for (plane = 0; plane < vb->num_planes; ++plane) {
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 			if (vb->v4l2_planes[plane].m.mem_offset == off) {
 				*_buffer = buffer;
 				*_plane = plane;
@@ -2356,7 +2367,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
  */
 int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 {
-	struct vb2_buffer *vb = NULL;
+	struct vb2_v4l2_buffer *vb = NULL;
 	struct vb2_plane *vb_plane;
 	int ret;
 	struct dma_buf *dbuf;
@@ -2388,7 +2399,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 
 	vb = q->bufs[eb->index];
 
-	if (eb->plane >= vb->num_planes) {
+	if (eb->plane >= vb->vb2.num_planes) {
 		dprintk(1, "buffer plane out of range\n");
 		return -EINVAL;
 	}
@@ -2398,7 +2409,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 		return -EBUSY;
 	}
 
-	vb_plane = &vb->planes[eb->plane];
+	vb_plane = &vb->vb2.planes[eb->plane];
 
 	dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE);
 	if (IS_ERR_OR_NULL(dbuf)) {
@@ -2445,7 +2456,7 @@ EXPORT_SYMBOL_GPL(vb2_expbuf);
 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 {
 	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int buffer = 0, plane = 0;
 	int ret;
 	unsigned long length;
@@ -2500,7 +2511,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 	}
 
 	mutex_lock(&q->mmap_lock);
-	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
+	ret = call_memop(vb, mmap, vb->vb2.planes[plane].mem_priv, vma);
 	mutex_unlock(&q->mmap_lock);
 	if (ret)
 		return ret;
@@ -2518,7 +2529,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
 				    unsigned long flags)
 {
 	unsigned long off = pgoff << PAGE_SHIFT;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int buffer, plane;
 	void *vaddr;
 	int ret;
@@ -2658,7 +2669,7 @@ EXPORT_SYMBOL_GPL(vb2_poll);
  * responsible of clearing it's content and setting initial values for some
  * required entries before calling this function.
  * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer
- * to the struct vb2_queue description in include/media/videobuf2-core.h
+ * to the struct vb2_queue description in include/media/videobuf2-v4l2.h
  * for more information.
  */
 int vb2_queue_init(struct vb2_queue *q)
@@ -2689,7 +2700,7 @@ int vb2_queue_init(struct vb2_queue *q)
 	init_waitqueue_head(&q->done_wq);
 
 	if (q->buf_struct_size == 0)
-		q->buf_struct_size = sizeof(struct vb2_buffer);
+		q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
 
 	return 0;
 }
@@ -2773,6 +2784,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	struct vb2_fileio_data *fileio;
 	int i, ret;
 	unsigned int count = 0;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * Sanity check
@@ -2823,7 +2835,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	 * Check if plane_count is correct
 	 * (multiplane buffers are not supported).
 	 */
-	if (q->bufs[0]->num_planes != 1) {
+	vb = (struct vb2_v4l2_buffer *)q->bufs[0];
+	if (vb->vb2.num_planes != 1) {
 		ret = -EBUSY;
 		goto err_reqbufs;
 	}
@@ -3133,7 +3146,7 @@ static int vb2_thread(void *data)
 	set_freezable();
 
 	for (;;) {
-		struct vb2_buffer *vb;
+		struct vb2_v4l2_buffer *vb;
 
 		/*
 		 * Call vb2_dqbuf to get buffer back.
@@ -3225,7 +3238,6 @@ EXPORT_SYMBOL_GPL(vb2_thread_start);
 int vb2_thread_stop(struct vb2_queue *q)
 {
 	struct vb2_threadio_data *threadio = q->threadio;
-	struct vb2_fileio_data *fileio = q->fileio;
 	int err;
 
 	if (threadio == NULL)
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 852a952..f578775 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -17,7 +17,7 @@
 #include <linux/slab.h>
 #include <linux/dma-mapping.h>
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 #include <media/videobuf2-memops.h>
 
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index b1838ab..3e3a3cc 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -17,7 +17,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-memops.h>
 #include <media/videobuf2-dma-sg.h>
 
diff --git a/drivers/media/v4l2-core/videobuf2-dvb.c b/drivers/media/v4l2-core/videobuf2-dvb.c
index d092698..21e6858 100644
--- a/drivers/media/v4l2-core/videobuf2-dvb.c
+++ b/drivers/media/v4l2-core/videobuf2-dvb.c
@@ -27,7 +27,7 @@ MODULE_LICENSE("GPL");
 
 /* ------------------------------------------------------------------ */
 
-static int dvb_fnc(struct vb2_buffer *vb, void *priv)
+static int dvb_fnc(struct vb2_v4l2_buffer *vb, void *priv)
 {
 	struct vb2_dvb *dvb = priv;
 
diff --git a/drivers/media/v4l2-core/videobuf2-memops.c b/drivers/media/v4l2-core/videobuf2-memops.c
index 81c1ad8..e5da47a 100644
--- a/drivers/media/v4l2-core/videobuf2-memops.c
+++ b/drivers/media/v4l2-core/videobuf2-memops.c
@@ -19,7 +19,7 @@
 #include <linux/sched.h>
 #include <linux/file.h>
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-memops.h>
 
 /**
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
similarity index 89%
copy from drivers/media/v4l2-core/videobuf2-core.c
copy to drivers/media/v4l2-core/videobuf2-v4l2.c
index cc16e76..cd28b4807f 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -28,7 +28,7 @@
 #include <media/v4l2-fh.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-common.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 static int debug;
 module_param(debug, int, 0644);
@@ -51,12 +51,12 @@ module_param(debug, int, 0644);
 
 #define log_memop(vb, op)						\
 	dprintk(2, "call_memop(%p, %d, %s)%s\n",			\
-		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
-		(vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
+		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
+		(vb)->vb2.vb2_queue->mem_ops->op ? "" : " (nop)")
 
 #define call_memop(vb, op, args...)					\
 ({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
 	int err;							\
 									\
 	log_memop(vb, op);						\
@@ -68,7 +68,7 @@ module_param(debug, int, 0644);
 
 #define call_ptr_memop(vb, op, args...)					\
 ({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
 	void *ptr;							\
 									\
 	log_memop(vb, op);						\
@@ -80,7 +80,7 @@ module_param(debug, int, 0644);
 
 #define call_void_memop(vb, op, args...)				\
 ({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
 									\
 	log_memop(vb, op);						\
 	if (_q->mem_ops->op)						\
@@ -113,16 +113,16 @@ module_param(debug, int, 0644);
 
 #define log_vb_qop(vb, op, args...)					\
 	dprintk(2, "call_vb_qop(%p, %d, %s)%s\n",			\
-		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
-		(vb)->vb2_queue->ops->op ? "" : " (nop)")
+		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
+		(vb)->vb2.vb2_queue->ops->op ? "" : " (nop)")
 
 #define call_vb_qop(vb, op, args...)					\
 ({									\
 	int err;							\
 									\
 	log_vb_qop(vb, op);						\
-	err = (vb)->vb2_queue->ops->op ?				\
-		(vb)->vb2_queue->ops->op(args) : 0;			\
+	err = (vb)->vb2.vb2_queue->ops->op ?				\
+		(vb)->vb2.vb2_queue->ops->op(args) : 0;			\
 	if (!err)							\
 		(vb)->cnt_ ## op++;					\
 	err;								\
@@ -131,25 +131,25 @@ module_param(debug, int, 0644);
 #define call_void_vb_qop(vb, op, args...)				\
 ({									\
 	log_vb_qop(vb, op);						\
-	if ((vb)->vb2_queue->ops->op)					\
-		(vb)->vb2_queue->ops->op(args);				\
+	if ((vb)->vb2.vb2_queue->ops->op)					\
+		(vb)->vb2.vb2_queue->ops->op(args);				\
 	(vb)->cnt_ ## op++;						\
 })
 
 #else
 
 #define call_memop(vb, op, args...)					\
-	((vb)->vb2_queue->mem_ops->op ?					\
-		(vb)->vb2_queue->mem_ops->op(args) : 0)
+	((vb)->vb2.vb2_queue->mem_ops->op ?					\
+		(vb)->vb2.vb2_queue->mem_ops->op(args) : 0)
 
 #define call_ptr_memop(vb, op, args...)					\
-	((vb)->vb2_queue->mem_ops->op ?					\
-		(vb)->vb2_queue->mem_ops->op(args) : NULL)
+	((vb)->vb2.vb2_queue->mem_ops->op ?					\
+		(vb)->vb2.vb2_queue->mem_ops->op(args) : NULL)
 
 #define call_void_memop(vb, op, args...)				\
 	do {								\
-		if ((vb)->vb2_queue->mem_ops->op)			\
-			(vb)->vb2_queue->mem_ops->op(args);		\
+		if ((vb)->vb2.vb2_queue->mem_ops->op)			\
+			(vb)->vb2.vb2_queue->mem_ops->op(args);		\
 	} while (0)
 
 #define call_qop(q, op, args...)					\
@@ -162,12 +162,12 @@ module_param(debug, int, 0644);
 	} while (0)
 
 #define call_vb_qop(vb, op, args...)					\
-	((vb)->vb2_queue->ops->op ? (vb)->vb2_queue->ops->op(args) : 0)
+	((vb)->vb2.vb2_queue->ops->op ? (vb)->vb2.vb2_queue->ops->op(args) : 0)
 
 #define call_void_vb_qop(vb, op, args...)				\
 	do {								\
-		if ((vb)->vb2_queue->ops->op)				\
-			(vb)->vb2_queue->ops->op(args);			\
+		if ((vb)->vb2.vb2_queue->ops->op)				\
+			(vb)->vb2.vb2_queue->ops->op(args);			\
 	} while (0)
 
 #endif
@@ -186,9 +186,9 @@ static void __vb2_queue_cancel(struct vb2_queue *q);
 /**
  * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
  */
-static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
+static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	enum dma_data_direction dma_dir =
 		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
 	void *mem_priv;
@@ -198,7 +198,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 	 * Allocate memory for all planes in this buffer
 	 * NOTE: mmapped areas should be page aligned
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 		unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
 
 		mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
@@ -207,7 +207,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 			goto free;
 
 		/* Associate allocator private data with this plane */
-		vb->planes[plane].mem_priv = mem_priv;
+		vb->vb2.planes[plane].mem_priv = mem_priv;
 		vb->v4l2_planes[plane].length = q->plane_sizes[plane];
 	}
 
@@ -215,8 +215,8 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 free:
 	/* Free already allocated memory if one of the allocations failed */
 	for (; plane > 0; --plane) {
-		call_void_memop(vb, put, vb->planes[plane - 1].mem_priv);
-		vb->planes[plane - 1].mem_priv = NULL;
+		call_void_memop(vb, put, vb->vb2.planes[plane - 1].mem_priv);
+		vb->vb2.planes[plane - 1].mem_priv = NULL;
 	}
 
 	return -ENOMEM;
@@ -225,13 +225,13 @@ free:
 /**
  * __vb2_buf_mem_free() - free memory of the given buffer
  */
-static void __vb2_buf_mem_free(struct vb2_buffer *vb)
+static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		call_void_memop(vb, put, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		call_void_memop(vb, put, vb->vb2.planes[plane].mem_priv);
+		vb->vb2.planes[plane].mem_priv = NULL;
 		dprintk(3, "freed plane %d of buffer %d\n", plane,
 			vb->v4l2_buf.index);
 	}
@@ -241,14 +241,14 @@ static void __vb2_buf_mem_free(struct vb2_buffer *vb)
  * __vb2_buf_userptr_put() - release userspace memory associated with
  * a USERPTR buffer
  */
-static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
+static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		if (vb->planes[plane].mem_priv)
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		if (vb->vb2.planes[plane].mem_priv)
+			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
+		vb->vb2.planes[plane].mem_priv = NULL;
 	}
 }
 
@@ -256,7 +256,7 @@ static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
  * __vb2_plane_dmabuf_put() - release memory associated with
  * a DMABUF shared plane
  */
-static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
+static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane *p)
 {
 	if (!p->mem_priv)
 		return;
@@ -273,12 +273,12 @@ static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
  * __vb2_buf_dmabuf_put() - release memory associated with
  * a DMABUF shared buffer
  */
-static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
+static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
 
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
+		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
 }
 
 /**
@@ -288,14 +288,14 @@ static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
 static void __setup_lengths(struct vb2_queue *q, unsigned int n)
 {
 	unsigned int buffer, plane;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
 		vb = q->bufs[buffer];
 		if (!vb)
 			continue;
 
-		for (plane = 0; plane < vb->num_planes; ++plane)
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane)
 			vb->v4l2_planes[plane].length = q->plane_sizes[plane];
 	}
 }
@@ -307,13 +307,13 @@ static void __setup_lengths(struct vb2_queue *q, unsigned int n)
 static void __setup_offsets(struct vb2_queue *q, unsigned int n)
 {
 	unsigned int buffer, plane;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned long off;
 
 	if (q->num_buffers) {
 		struct v4l2_plane *p;
 		vb = q->bufs[q->num_buffers - 1];
-		p = &vb->v4l2_planes[vb->num_planes - 1];
+		p = &vb->v4l2_planes[vb->vb2.num_planes - 1];
 		off = PAGE_ALIGN(p->m.mem_offset + p->length);
 	} else {
 		off = 0;
@@ -324,7 +324,7 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
 		if (!vb)
 			continue;
 
-		for (plane = 0; plane < vb->num_planes; ++plane) {
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 			vb->v4l2_planes[plane].m.mem_offset = off;
 
 			dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
@@ -347,7 +347,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 			     unsigned int num_buffers, unsigned int num_planes)
 {
 	unsigned int buffer;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int ret;
 
 	for (buffer = 0; buffer < num_buffers; ++buffer) {
@@ -362,9 +362,9 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 		if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
 			vb->v4l2_buf.length = num_planes;
 
-		vb->state = VB2_BUF_STATE_DEQUEUED;
-		vb->vb2_queue = q;
-		vb->num_planes = num_planes;
+		vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
+		vb->vb2.vb2_queue = q;
+		vb->vb2.num_planes = num_planes;
 		vb->v4l2_buf.index = q->num_buffers + buffer;
 		vb->v4l2_buf.type = q->type;
 		vb->v4l2_buf.memory = memory;
@@ -412,7 +412,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
 {
 	unsigned int buffer;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
 	     ++buffer) {
@@ -438,6 +438,7 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
 static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 {
 	unsigned int buffer;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * Sanity check: when preparing a buffer the queue lock is released for
@@ -449,9 +450,11 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 	 */
 	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
 	     ++buffer) {
-		if (q->bufs[buffer] == NULL)
+		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
+
+		if (vb == NULL)
 			continue;
-		if (q->bufs[buffer]->state == VB2_BUF_STATE_PREPARING) {
+		if (vb->vb2.state == VB2_BUF_STATE_PREPARING) {
 			dprintk(1, "preparing buffers, cannot free\n");
 			return -EAGAIN;
 		}
@@ -460,9 +463,9 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 	/* Call driver-provided cleanup function for each buffer, if provided */
 	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
 	     ++buffer) {
-		struct vb2_buffer *vb = q->bufs[buffer];
+		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
 
-		if (vb && vb->planes[0].mem_priv)
+		if (vb && vb->vb2.planes[0].mem_priv)
 			call_void_vb_qop(vb, buf_cleanup, vb);
 	}
 
@@ -495,38 +498,38 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 		q->cnt_stop_streaming = 0;
 	}
 	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
-		struct vb2_buffer *vb = q->bufs[buffer];
-		bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put ||
-				  vb->cnt_mem_prepare != vb->cnt_mem_finish ||
-				  vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr ||
-				  vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf ||
-				  vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf ||
-				  vb->cnt_buf_queue != vb->cnt_buf_done ||
-				  vb->cnt_buf_prepare != vb->cnt_buf_finish ||
-				  vb->cnt_buf_init != vb->cnt_buf_cleanup;
+		struct vb2_v4l2_buffer *vb = q->bufs[buffer];
+		bool unbalanced = vb->vb2.cnt_mem_alloc != vb->vb2.cnt_mem_put ||
+				  vb->vb2.cnt_mem_prepare != vb->vb2.cnt_mem_finish ||
+				  vb->vb2.cnt_mem_get_userptr != vb->vb2.cnt_mem_put_userptr ||
+				  vb->vb2.cnt_mem_attach_dmabuf != vb->vb2.cnt_mem_detach_dmabuf ||
+				  vb->vb2.cnt_mem_map_dmabuf != vb->vb2.cnt_mem_unmap_dmabuf ||
+				  vb->vb2.cnt_buf_queue != vb->vb2.cnt_buf_done ||
+				  vb->vb2.cnt_buf_prepare != vb->vb2.cnt_buf_finish ||
+				  vb->vb2.cnt_buf_init != vb->vb2.cnt_buf_cleanup;
 
 		if (unbalanced || debug) {
 			pr_info("vb2:   counters for queue %p, buffer %d:%s\n",
 				q, buffer, unbalanced ? " UNBALANCED!" : "");
 			pr_info("vb2:     buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n",
-				vb->cnt_buf_init, vb->cnt_buf_cleanup,
-				vb->cnt_buf_prepare, vb->cnt_buf_finish);
+				vb->vb2.cnt_buf_init, vb->vb2.cnt_buf_cleanup,
+				vb->vb2.cnt_buf_prepare, vb->vb2.cnt_buf_finish);
 			pr_info("vb2:     buf_queue: %u buf_done: %u\n",
-				vb->cnt_buf_queue, vb->cnt_buf_done);
+				vb->vb2.cnt_buf_queue, vb->vb2.cnt_buf_done);
 			pr_info("vb2:     alloc: %u put: %u prepare: %u finish: %u mmap: %u\n",
-				vb->cnt_mem_alloc, vb->cnt_mem_put,
-				vb->cnt_mem_prepare, vb->cnt_mem_finish,
-				vb->cnt_mem_mmap);
+				vb->vb2.cnt_mem_alloc, vb->vb2.cnt_mem_put,
+				vb->vb2.cnt_mem_prepare, vb->vb2.cnt_mem_finish,
+				vb->vb2.cnt_mem_mmap);
 			pr_info("vb2:     get_userptr: %u put_userptr: %u\n",
-				vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr);
+				vb->vb2.cnt_mem_get_userptr, vb->vb2.cnt_mem_put_userptr);
 			pr_info("vb2:     attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n",
-				vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf,
-				vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf);
+				vb->vb2.cnt_mem_attach_dmabuf, vb->vb2.cnt_mem_detach_dmabuf,
+				vb->vb2.cnt_mem_map_dmabuf, vb->vb2.cnt_mem_unmap_dmabuf);
 			pr_info("vb2:     get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n",
-				vb->cnt_mem_get_dmabuf,
-				vb->cnt_mem_num_users,
-				vb->cnt_mem_vaddr,
-				vb->cnt_mem_cookie);
+				vb->vb2.cnt_mem_get_dmabuf,
+				vb->vb2.cnt_mem_num_users,
+				vb->vb2.cnt_mem_vaddr,
+				vb->vb2.cnt_mem_cookie);
 		}
 	}
 #endif
@@ -550,7 +553,7 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
  * __verify_planes_array() - verify that the planes array passed in struct
  * v4l2_buffer from userspace can be safely used
  */
-static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
 		return 0;
@@ -562,9 +565,9 @@ static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer
 		return -EINVAL;
 	}
 
-	if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
+	if (b->length < vb->vb2.num_planes || b->length > VIDEO_MAX_PLANES) {
 		dprintk(1, "incorrect planes array length, "
-			   "expected %d, got %d\n", vb->num_planes, b->length);
+			   "expected %d, got %d\n", vb->vb2.num_planes, b->length);
 		return -EINVAL;
 	}
 
@@ -575,7 +578,7 @@ static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer
  * __verify_length() - Verify that the bytesused value for each plane fits in
  * the plane length and that the data offset doesn't exceed the bytesused value.
  */
-static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	unsigned int length;
 	unsigned int bytesused;
@@ -585,7 +588,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		return 0;
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
-		for (plane = 0; plane < vb->num_planes; ++plane) {
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 			length = (b->memory == V4L2_MEMORY_USERPTR ||
 				  b->memory == V4L2_MEMORY_DMABUF)
 			       ? b->m.planes[plane].length
@@ -616,11 +619,11 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
  * __buffer_in_use() - return true if the buffer is in use and
  * the queue cannot be freed (by the means of REQBUFS(0)) call
  */
-static bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
+static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
 {
 	unsigned int plane;
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		void *mem_priv = vb->planes[plane].mem_priv;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		void *mem_priv = vb->vb2.planes[plane].mem_priv;
 		/*
 		 * If num_users() has not been provided, call_memop
 		 * will return 0, apparently nobody cares about this
@@ -651,9 +654,9 @@ static bool __buffers_in_use(struct vb2_queue *q)
  * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
  * returned to userspace
  */
-static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
+static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 
 	/* Copy back data such as timestamp, flags, etc. */
 	memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
@@ -665,7 +668,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 		 * Fill in plane-related data if userspace provided an array
 		 * for it. The caller has already verified memory and size.
 		 */
-		b->length = vb->num_planes;
+		b->length = vb->vb2.num_planes;
 		memcpy(b->m.planes, vb->v4l2_planes,
 			b->length * sizeof(struct v4l2_plane));
 	} else {
@@ -698,7 +701,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 	}
 
-	switch (vb->state) {
+	switch (vb->vb2.state) {
 	case VB2_BUF_STATE_QUEUED:
 	case VB2_BUF_STATE_ACTIVE:
 		b->flags |= V4L2_BUF_FLAG_QUEUED;
@@ -737,7 +740,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
  */
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int ret;
 
 	if (b->type != q->type) {
@@ -857,7 +860,7 @@ static int __verify_memory_type(struct vb2_queue *q,
  * 2) sets up the queue,
  * 3) negotiates number of buffers and planes per buffer with the driver
  *    to be used during streaming,
- * 4) allocates internal buffer structures (struct vb2_buffer), according to
+ * 4) allocates internal buffer structures (struct vb2_v4l2_buffer), according to
  *    the agreed parameters,
  * 5) for MMAP memory type, allocates actual video memory, using the
  *    memory handling/allocation routines provided during queue initialization
@@ -1114,45 +1117,45 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
 /**
  * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
- * @vb:		vb2_buffer to which the plane in question belongs to
+ * @vb:		vb2_v4l2_buffer to which the plane in question belongs to
  * @plane_no:	plane number for which the address is to be returned
  *
  * This function returns a kernel virtual address of a given plane if
  * such a mapping exist, NULL otherwise.
  */
-void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no)
+void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
-	if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
+	if (plane_no > vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
 		return NULL;
 
-	return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
+	return call_ptr_memop(vb, vaddr, vb->vb2.planes[plane_no].mem_priv);
 
 }
 EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
 
 /**
  * vb2_plane_cookie() - Return allocator specific cookie for the given plane
- * @vb:		vb2_buffer to which the plane in question belongs to
+ * @vb:		vb2_v4l2_buffer to which the plane in question belongs to
  * @plane_no:	plane number for which the cookie is to be returned
  *
  * This function returns an allocator specific cookie for a given plane if
  * available, NULL otherwise. The allocator should provide some simple static
- * inline function, which would convert this cookie to the allocator specific
+ * inline funaction, which would convert this cookie to the allocator specific
  * type that can be used directly by the driver to access the buffer. This can
  * be for example physical address, pointer to scatter list or IOMMU mapping.
  */
-void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no)
+void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
-	if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
+	if (plane_no >= vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
 		return NULL;
 
-	return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
+	return call_ptr_memop(vb, cookie, vb->vb2.planes[plane_no].mem_priv);
 }
 EXPORT_SYMBOL_GPL(vb2_plane_cookie);
 
 /**
  * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished
- * @vb:		vb2_buffer returned from the driver
+ * @vb:		vb2_v4l2_buffer returned from the driver
  * @state:	either VB2_BUF_STATE_DONE if the operation finished successfully
  *		or VB2_BUF_STATE_ERROR if the operation finished with an error.
  *		If start_streaming fails then it should return buffers with state
@@ -1169,13 +1172,13 @@ EXPORT_SYMBOL_GPL(vb2_plane_cookie);
  * be started for some reason. In that case the buffers should be returned with
  * state QUEUED.
  */
-void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
+void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	unsigned long flags;
 	unsigned int plane;
 
-	if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
+	if (WARN_ON(vb->vb2.state != VB2_BUF_STATE_ACTIVE))
 		return;
 
 	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
@@ -1188,20 +1191,20 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 	 * Although this is not a callback, it still does have to balance
 	 * with the buf_queue op. So update this counter manually.
 	 */
-	vb->cnt_buf_done++;
+	vb->vb2.cnt_buf_done++;
 #endif
 	dprintk(4, "done processing on buffer %d, state: %d\n",
 			vb->v4l2_buf.index, state);
 
 	/* sync buffers */
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
+		call_void_memop(vb, finish, vb->vb2.planes[plane].mem_priv);
 
 	/* Add the buffer to the done buffers list */
 	spin_lock_irqsave(&q->done_lock, flags);
-	vb->state = state;
+	vb->vb2.state = state;
 	if (state != VB2_BUF_STATE_QUEUED)
-		list_add_tail(&vb->done_entry, &q->done_list);
+		list_add_tail(&vb->vb2.done_entry, &q->done_list);
 	atomic_dec(&q->owned_by_drv_count);
 	spin_unlock_irqrestore(&q->done_lock, flags);
 
@@ -1238,18 +1241,18 @@ void vb2_discard_done(struct vb2_queue *q)
 EXPORT_SYMBOL_GPL(vb2_discard_done);
 
 /**
- * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a
+ * __fill_vb2_buffer() - fill a vb2_v4l2_buffer with information provided in a
  * v4l2_buffer by the userspace. The caller has already verified that struct
  * v4l2_buffer has a valid number of planes.
  */
-static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b,
+static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b,
 				struct v4l2_plane *v4l2_planes)
 {
 	unsigned int plane;
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
 		if (b->memory == V4L2_MEMORY_USERPTR) {
-			for (plane = 0; plane < vb->num_planes; ++plane) {
+			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 				v4l2_planes[plane].m.userptr =
 					b->m.planes[plane].m.userptr;
 				v4l2_planes[plane].length =
@@ -1257,7 +1260,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 			}
 		}
 		if (b->memory == V4L2_MEMORY_DMABUF) {
-			for (plane = 0; plane < vb->num_planes; ++plane) {
+			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 				v4l2_planes[plane].m.fd =
 					b->m.planes[plane].m.fd;
 				v4l2_planes[plane].length =
@@ -1277,7 +1280,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 			 * it's a safe assumption that they really meant to
 			 * use the full plane sizes.
 			 */
-			for (plane = 0; plane < vb->num_planes; ++plane) {
+			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 				struct v4l2_plane *pdst = &v4l2_planes[plane];
 				struct v4l2_plane *psrc = &b->m.planes[plane];
 
@@ -1316,7 +1319,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 
 	/* Zero flags that the vb2 core handles */
 	vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
-	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
+	if ((vb->vb2.vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
 	    V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
 		/*
 		 * Non-COPY timestamps and non-OUTPUT queues will get
@@ -1344,7 +1347,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 /**
  * __qbuf_mmap() - handle qbuf of an MMAP buffer
  */
-static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_mmap(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	__fill_vb2_buffer(vb, b, vb->v4l2_planes);
 	return call_vb_qop(vb, buf_prepare, vb);
@@ -1353,22 +1356,22 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 /**
  * __qbuf_userptr() - handle qbuf of a USERPTR buffer
  */
-static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct v4l2_plane planes[VIDEO_MAX_PLANES];
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	void *mem_priv;
 	unsigned int plane;
 	int ret;
 	enum dma_data_direction dma_dir =
 		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-	bool reacquired = vb->planes[0].mem_priv == NULL;
+	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
 
-	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
+	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
 	/* Copy relevant information provided by the userspace */
 	__fill_vb2_buffer(vb, b, planes);
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 		/* Skip the plane if already verified */
 		if (vb->v4l2_planes[plane].m.userptr &&
 		    vb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
@@ -1389,15 +1392,15 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 
 		/* Release previously acquired memory if present */
-		if (vb->planes[plane].mem_priv) {
+		if (vb->vb2.planes[plane].mem_priv) {
 			if (!reacquired) {
 				reacquired = true;
 				call_void_vb_qop(vb, buf_cleanup, vb);
 			}
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
+			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
 		}
 
-		vb->planes[plane].mem_priv = NULL;
+		vb->vb2.planes[plane].mem_priv = NULL;
 		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
 
 		/* Acquire each plane's memory */
@@ -1410,14 +1413,14 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 			ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
 			goto err;
 		}
-		vb->planes[plane].mem_priv = mem_priv;
+		vb->vb2.planes[plane].mem_priv = mem_priv;
 	}
 
 	/*
 	 * Now that everything is in order, copy relevant information
 	 * provided by userspace.
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane)
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
 		vb->v4l2_planes[plane] = planes[plane];
 
 	if (reacquired) {
@@ -1443,10 +1446,10 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	return 0;
 err:
 	/* In case of errors, release planes that were already acquired */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		if (vb->planes[plane].mem_priv)
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		if (vb->vb2.planes[plane].mem_priv)
+			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
+		vb->vb2.planes[plane].mem_priv = NULL;
 		vb->v4l2_planes[plane].m.userptr = 0;
 		vb->v4l2_planes[plane].length = 0;
 	}
@@ -1457,22 +1460,22 @@ err:
 /**
  * __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
  */
-static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct v4l2_plane planes[VIDEO_MAX_PLANES];
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	void *mem_priv;
 	unsigned int plane;
 	int ret;
 	enum dma_data_direction dma_dir =
 		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-	bool reacquired = vb->planes[0].mem_priv == NULL;
+	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
 
-	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
+	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
 	/* Copy relevant information provided by the userspace */
 	__fill_vb2_buffer(vb, b, planes);
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 		struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
 
 		if (IS_ERR_OR_NULL(dbuf)) {
@@ -1494,7 +1497,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 
 		/* Skip the plane if already verified */
-		if (dbuf == vb->planes[plane].dbuf &&
+		if (dbuf == vb->vb2.planes[plane].dbuf &&
 		    vb->v4l2_planes[plane].length == planes[plane].length) {
 			dma_buf_put(dbuf);
 			continue;
@@ -1508,7 +1511,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 
 		/* Release previously acquired memory if present */
-		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
+		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
 		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
 
 		/* Acquire each plane's memory */
@@ -1521,29 +1524,29 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 			goto err;
 		}
 
-		vb->planes[plane].dbuf = dbuf;
-		vb->planes[plane].mem_priv = mem_priv;
+		vb->vb2.planes[plane].dbuf = dbuf;
+		vb->vb2.planes[plane].mem_priv = mem_priv;
 	}
 
 	/* TODO: This pins the buffer(s) with  dma_buf_map_attachment()).. but
 	 * really we want to do this just before the DMA, not while queueing
 	 * the buffer(s)..
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
+		ret = call_memop(vb, map_dmabuf, vb->vb2.planes[plane].mem_priv);
 		if (ret) {
 			dprintk(1, "failed to map dmabuf for plane %d\n",
 				plane);
 			goto err;
 		}
-		vb->planes[plane].dbuf_mapped = 1;
+		vb->vb2.planes[plane].dbuf_mapped = 1;
 	}
 
 	/*
 	 * Now that everything is in order, copy relevant information
 	 * provided by userspace.
 	 */
-	for (plane = 0; plane < vb->num_planes; ++plane)
+	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
 		vb->v4l2_planes[plane] = planes[plane];
 
 	if (reacquired) {
@@ -1574,10 +1577,11 @@ err:
 }
 
 /**
- * __enqueue_in_driver() - enqueue a vb2_buffer in driver for processing
+ * __enqueue_in_driver() - enqueue a vb2_v4l2_buffer in driver for processing
  */
 static void __enqueue_in_driver(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *pb = container_of(vb, struct vb2_v4l2_buffer, vb2);
 	struct vb2_queue *q = vb->vb2_queue;
 	unsigned int plane;
 
@@ -1586,14 +1590,14 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
 
 	/* sync buffers */
 	for (plane = 0; plane < vb->num_planes; ++plane)
-		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
+		call_void_memop(pb, prepare, vb->planes[plane].mem_priv);
 
-	call_void_vb_qop(vb, buf_queue, vb);
+	call_void_vb_qop(pb, buf_queue, pb);
 }
 
-static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	int ret;
 
 	ret = __verify_length(vb, b);
@@ -1620,7 +1624,7 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		return -EIO;
 	}
 
-	vb->state = VB2_BUF_STATE_PREPARING;
+	vb->vb2.state = VB2_BUF_STATE_PREPARING;
 	vb->v4l2_buf.timestamp.tv_sec = 0;
 	vb->v4l2_buf.timestamp.tv_usec = 0;
 	vb->v4l2_buf.sequence = 0;
@@ -1644,7 +1648,7 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 
 	if (ret)
 		dprintk(1, "buffer preparation failed: %d\n", ret);
-	vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
+	vb->vb2.state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
 
 	return ret;
 }
@@ -1693,7 +1697,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
  */
 int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	int ret;
 
 	if (vb2_fileio_is_active(q)) {
@@ -1706,9 +1710,9 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 		return ret;
 
 	vb = q->bufs[b->index];
-	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
+	if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
 		dprintk(1, "invalid buffer state %d\n",
-			vb->state);
+			vb->vb2.state);
 		return -EINVAL;
 	}
 
@@ -1737,6 +1741,7 @@ EXPORT_SYMBOL_GPL(vb2_prepare_buf);
 static int vb2_start_streaming(struct vb2_queue *q)
 {
 	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *pb;
 	int ret;
 
 	/*
@@ -1770,9 +1775,9 @@ static int vb2_start_streaming(struct vb2_queue *q)
 		 * correctly return them to vb2.
 		 */
 		for (i = 0; i < q->num_buffers; ++i) {
-			vb = q->bufs[i];
-			if (vb->state == VB2_BUF_STATE_ACTIVE)
-				vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED);
+			pb = q->bufs[i];
+			if (pb->vb2.state == VB2_BUF_STATE_ACTIVE)
+				vb2_buffer_done(pb, VB2_BUF_STATE_QUEUED);
 		}
 		/* Must be zero now */
 		WARN_ON(atomic_read(&q->owned_by_drv_count));
@@ -1789,14 +1794,14 @@ static int vb2_start_streaming(struct vb2_queue *q)
 static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
 	int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	if (ret)
 		return ret;
 
 	vb = q->bufs[b->index];
 
-	switch (vb->state) {
+	switch (vb->vb2.state) {
 	case VB2_BUF_STATE_DEQUEUED:
 		ret = __buf_prepare(vb, b);
 		if (ret)
@@ -1808,7 +1813,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 		dprintk(1, "buffer still being prepared\n");
 		return -EINVAL;
 	default:
-		dprintk(1, "invalid buffer state %d\n", vb->state);
+		dprintk(1, "invalid buffer state %d\n", vb->vb2.state);
 		return -EINVAL;
 	}
 
@@ -1816,10 +1821,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 	 * Add to the queued buffers list, a buffer will stay on it until
 	 * dequeued in dqbuf.
 	 */
-	list_add_tail(&vb->queued_entry, &q->queued_list);
+	list_add_tail(&vb->vb2.queued_entry, &q->queued_list);
 	q->queued_count++;
 	q->waiting_for_buffers = false;
-	vb->state = VB2_BUF_STATE_QUEUED;
+	vb->vb2.state = VB2_BUF_STATE_QUEUED;
 	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
 		/*
 		 * For output buffers copy the timestamp if needed,
@@ -1838,7 +1843,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 	 * If not, the buffer will be given to driver on next streamon.
 	 */
 	if (q->start_streaming_called)
-		__enqueue_in_driver(vb);
+		__enqueue_in_driver(&vb->vb2);
 
 	/* Fill buffer information for the userspace */
 	__fill_v4l2_buffer(vb, b);
@@ -1964,11 +1969,12 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
  *
  * Will sleep if required for nonblocking == false.
  */
-static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
+static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
 				struct v4l2_buffer *b, int nonblocking)
 {
 	unsigned long flags;
 	int ret;
+	struct vb2_buffer *vb2 = NULL;
 
 	/*
 	 * Wait for at least one buffer to become available on the done_list.
@@ -1982,14 +1988,15 @@ static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
 	 * is not empty, so no need for another list_empty(done_list) check.
 	 */
 	spin_lock_irqsave(&q->done_lock, flags);
-	*vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
+	vb2 = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
+	*vb = container_of(vb2, struct vb2_v4l2_buffer, vb2); 
 	/*
 	 * Only remove the buffer from done_list if v4l2_buffer can handle all
 	 * the planes.
 	 */
 	ret = __verify_planes_array(*vb, b);
 	if (!ret)
-		list_del(&(*vb)->done_entry);
+		list_del(&(*vb)->vb2.done_entry);
 	spin_unlock_irqrestore(&q->done_lock, flags);
 
 	return ret;
@@ -2020,30 +2027,30 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
 /**
  * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
  */
-static void __vb2_dqbuf(struct vb2_buffer *vb)
+static void __vb2_dqbuf(struct vb2_v4l2_buffer *vb)
 {
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_queue *q = vb->vb2.vb2_queue;
 	unsigned int i;
 
 	/* nothing to do if the buffer is already dequeued */
-	if (vb->state == VB2_BUF_STATE_DEQUEUED)
+	if (vb->vb2.state == VB2_BUF_STATE_DEQUEUED)
 		return;
 
-	vb->state = VB2_BUF_STATE_DEQUEUED;
+	vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
 
 	/* unmap DMABUF buffer */
 	if (q->memory == V4L2_MEMORY_DMABUF)
-		for (i = 0; i < vb->num_planes; ++i) {
-			if (!vb->planes[i].dbuf_mapped)
+		for (i = 0; i < vb->vb2.num_planes; ++i) {
+			if (!vb->vb2.planes[i].dbuf_mapped)
 				continue;
-			call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
-			vb->planes[i].dbuf_mapped = 0;
+			call_void_memop(vb, unmap_dmabuf, vb->vb2.planes[i].mem_priv);
+			vb->vb2.planes[i].dbuf_mapped = 0;
 		}
 }
 
 static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
-	struct vb2_buffer *vb = NULL;
+	struct vb2_v4l2_buffer *vb = NULL;
 	int ret;
 
 	if (b->type != q->type) {
@@ -2054,7 +2061,7 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
 	if (ret < 0)
 		return ret;
 
-	switch (vb->state) {
+	switch (vb->vb2.state) {
 	case VB2_BUF_STATE_DONE:
 		dprintk(3, "returning done buffer\n");
 		break;
@@ -2071,13 +2078,13 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
 	/* Fill buffer information for the userspace */
 	__fill_v4l2_buffer(vb, b);
 	/* Remove from videobuf queue */
-	list_del(&vb->queued_entry);
+	list_del(&vb->vb2.queued_entry);
 	q->queued_count--;
 	/* go back to dequeued state */
 	__vb2_dqbuf(vb);
 
 	dprintk(1, "dqbuf of buffer %d, with state %d\n",
-			vb->v4l2_buf.index, vb->state);
+			vb->v4l2_buf.index, vb->vb2.state);
 
 	return 0;
 }
@@ -2122,6 +2129,7 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
 static void __vb2_queue_cancel(struct vb2_queue *q)
 {
 	unsigned int i;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * Tell driver to stop all transactions and release all queued
@@ -2138,8 +2146,11 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 	 */
 	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
 		for (i = 0; i < q->num_buffers; ++i)
-			if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE)
-				vb2_buffer_done(q->bufs[i], VB2_BUF_STATE_ERROR);
+		{
+			vb = (struct vb2_v4l2_buffer *)q->bufs[i];
+			if (vb->vb2.state == VB2_BUF_STATE_ACTIVE)
+				vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+		}
 		/* Must be zero now */
 		WARN_ON(atomic_read(&q->owned_by_drv_count));
 	}
@@ -2171,10 +2182,10 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 	 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
 	 */
 	for (i = 0; i < q->num_buffers; ++i) {
-		struct vb2_buffer *vb = q->bufs[i];
+		struct vb2_v4l2_buffer *vb = q->bufs[i];
 
-		if (vb->state != VB2_BUF_STATE_DEQUEUED) {
-			vb->state = VB2_BUF_STATE_PREPARED;
+		if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
+			vb->vb2.state = VB2_BUF_STATE_PREPARED;
 			call_void_vb_qop(vb, buf_finish, vb);
 		}
 		__vb2_dqbuf(vb);
@@ -2322,7 +2333,7 @@ EXPORT_SYMBOL_GPL(vb2_streamoff);
 static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
 			unsigned int *_buffer, unsigned int *_plane)
 {
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int buffer, plane;
 
 	/*
@@ -2333,7 +2344,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
 	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
 		vb = q->bufs[buffer];
 
-		for (plane = 0; plane < vb->num_planes; ++plane) {
+		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
 			if (vb->v4l2_planes[plane].m.mem_offset == off) {
 				*_buffer = buffer;
 				*_plane = plane;
@@ -2356,7 +2367,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
  */
 int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 {
-	struct vb2_buffer *vb = NULL;
+	struct vb2_v4l2_buffer *vb = NULL;
 	struct vb2_plane *vb_plane;
 	int ret;
 	struct dma_buf *dbuf;
@@ -2388,7 +2399,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 
 	vb = q->bufs[eb->index];
 
-	if (eb->plane >= vb->num_planes) {
+	if (eb->plane >= vb->vb2.num_planes) {
 		dprintk(1, "buffer plane out of range\n");
 		return -EINVAL;
 	}
@@ -2398,7 +2409,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 		return -EBUSY;
 	}
 
-	vb_plane = &vb->planes[eb->plane];
+	vb_plane = &vb->vb2.planes[eb->plane];
 
 	dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE);
 	if (IS_ERR_OR_NULL(dbuf)) {
@@ -2445,7 +2456,7 @@ EXPORT_SYMBOL_GPL(vb2_expbuf);
 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 {
 	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int buffer = 0, plane = 0;
 	int ret;
 	unsigned long length;
@@ -2500,7 +2511,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 	}
 
 	mutex_lock(&q->mmap_lock);
-	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
+	ret = call_memop(vb, mmap, vb->vb2.planes[plane].mem_priv, vma);
 	mutex_unlock(&q->mmap_lock);
 	if (ret)
 		return ret;
@@ -2518,7 +2529,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
 				    unsigned long flags)
 {
 	unsigned long off = pgoff << PAGE_SHIFT;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 	unsigned int buffer, plane;
 	void *vaddr;
 	int ret;
@@ -2658,7 +2669,7 @@ EXPORT_SYMBOL_GPL(vb2_poll);
  * responsible of clearing it's content and setting initial values for some
  * required entries before calling this function.
  * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer
- * to the struct vb2_queue description in include/media/videobuf2-core.h
+ * to the struct vb2_queue description in include/media/videobuf2-v4l2.h
  * for more information.
  */
 int vb2_queue_init(struct vb2_queue *q)
@@ -2689,7 +2700,7 @@ int vb2_queue_init(struct vb2_queue *q)
 	init_waitqueue_head(&q->done_wq);
 
 	if (q->buf_struct_size == 0)
-		q->buf_struct_size = sizeof(struct vb2_buffer);
+		q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
 
 	return 0;
 }
@@ -2773,6 +2784,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	struct vb2_fileio_data *fileio;
 	int i, ret;
 	unsigned int count = 0;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * Sanity check
@@ -2823,7 +2835,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	 * Check if plane_count is correct
 	 * (multiplane buffers are not supported).
 	 */
-	if (q->bufs[0]->num_planes != 1) {
+	vb = (struct vb2_v4l2_buffer *)q->bufs[0];
+	if (vb->vb2.num_planes != 1) {
 		ret = -EBUSY;
 		goto err_reqbufs;
 	}
@@ -3133,7 +3146,7 @@ static int vb2_thread(void *data)
 	set_freezable();
 
 	for (;;) {
-		struct vb2_buffer *vb;
+		struct vb2_v4l2_buffer *vb;
 
 		/*
 		 * Call vb2_dqbuf to get buffer back.
@@ -3225,7 +3238,6 @@ EXPORT_SYMBOL_GPL(vb2_thread_start);
 int vb2_thread_stop(struct vb2_queue *q)
 {
 	struct vb2_threadio_data *threadio = q->threadio;
-	struct vb2_fileio_data *fileio = q->fileio;
 	int err;
 
 	if (threadio == NULL)
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index bcde885..386064c 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -17,7 +17,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-vmalloc.h>
 #include <media/videobuf2-memops.h>
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 06d48d5..3a61e7d 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -474,7 +474,7 @@ void vpfe_video_process_buffer_complete(struct vpfe_video_device *video)
 	struct vpfe_pipeline *pipe = &video->pipe;
 
 	do_gettimeofday(&video->cur_frm->vb.v4l2_buf.timestamp);
-	vb2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_DONE);
+	vb2_v4l2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_DONE);
 	if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS)
 		video->cur_frm = video->next_frm;
 }
@@ -1112,15 +1112,15 @@ vpfe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 /*
  * vpfe_buffer_prepare : callback function for buffer prepare
- * @vb: ptr to vb2_buffer
+ * @vb: ptr to vb2_v4l2_buffer
  *
  * This is the callback function for buffer prepare when vb2_qbuf()
  * function is called. The buffer is prepared and user space virtual address
  * or user address is converted into  physical address
  */
-static int vpfe_buffer_prepare(struct vb2_buffer *vb)
+static int vpfe_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 	struct vpfe_video_device *video = fh->video;
 	struct vpfe_device *vpfe_dev = video->vpfe_dev;
 	unsigned long addr;
@@ -1145,10 +1145,10 @@ static int vpfe_buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void vpfe_buffer_queue(struct vb2_buffer *vb)
+static void vpfe_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
 	/* Get the file handle object and device object */
-	struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 	struct vpfe_video_device *video = fh->video;
 	struct vpfe_device *vpfe_dev = video->vpfe_dev;
 	struct vpfe_pipeline *pipe = &video->pipe;
@@ -1223,10 +1223,10 @@ static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
 	if (ret) {
 		struct vpfe_cap_buffer *buf, *tmp;
 
-		vb2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_QUEUED);
+		vb2_v4l2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_QUEUED);
 		list_for_each_entry_safe(buf, tmp, &video->dma_queue, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_v4l2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
 		}
 		goto unlock_out;
 	}
@@ -1241,7 +1241,7 @@ streamoff:
 	return 0;
 }
 
-static int vpfe_buffer_init(struct vb2_buffer *vb)
+static int vpfe_buffer_init(struct vb2_v4l2_buffer *vb)
 {
 	struct vpfe_cap_buffer *buf = container_of(vb,
 						   struct vpfe_cap_buffer, vb);
@@ -1258,13 +1258,13 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
 
 	/* release all active buffers */
 	if (video->cur_frm == video->next_frm) {
-		vb2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_v4l2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_ERROR);
 	} else {
 		if (video->cur_frm != NULL)
-			vb2_buffer_done(&video->cur_frm->vb,
+			vb2_v4l2_buffer_done(&video->cur_frm->vb,
 					VB2_BUF_STATE_ERROR);
 		if (video->next_frm != NULL)
-			vb2_buffer_done(&video->next_frm->vb,
+			vb2_v4l2_buffer_done(&video->next_frm->vb,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -1272,13 +1272,13 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
 		video->next_frm = list_entry(video->dma_queue.next,
 						struct vpfe_cap_buffer, list);
 		list_del(&video->next_frm->list);
-		vb2_buffer_done(&video->next_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_v4l2_buffer_done(&video->next_frm->vb, VB2_BUF_STATE_ERROR);
 	}
 }
 
-static void vpfe_buf_cleanup(struct vb2_buffer *vb)
+static void vpfe_buf_cleanup(struct vb2_v4l2_buffer *vb)
 {
-	struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
+	struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 	struct vpfe_video_device *video = fh->video;
 	struct vpfe_device *vpfe_dev = video->vpfe_dev;
 	struct vpfe_cap_buffer *buf = container_of(vb,
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.h b/drivers/staging/media/davinci_vpfe/vpfe_video.h
index 1b1b6c4..6a82257 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.h
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.h
@@ -72,7 +72,7 @@ struct vpfe_pipeline {
 	container_of(vdev, struct vpfe_video_device, video_dev)
 
 struct vpfe_cap_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.c b/drivers/staging/media/dt3155v4l/dt3155v4l.c
index 293ffda..fa995bc 100644
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c
@@ -190,7 +190,7 @@ static int wait_i2c_reg(void __iomem *addr)
 static int
 dt3155_start_acq(struct dt3155_priv *pd)
 {
-	struct vb2_buffer *vb = pd->curr_buf;
+	struct vb2_v4l2_buffer *vb = pd->curr_buf;
 	dma_addr_t dma_addr;
 
 	dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
@@ -256,7 +256,7 @@ dt3155_wait_finish(struct vb2_queue *q)
 }
 
 static int
-dt3155_buf_prepare(struct vb2_buffer *vb)
+dt3155_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
 	vb2_set_plane_payload(vb, 0, img_width * img_height);
 	return 0;
@@ -272,21 +272,21 @@ dt3155_stop_streaming(struct vb2_queue *q)
 	while (!list_empty(&pd->dmaq)) {
 		vb = list_first_entry(&pd->dmaq, typeof(*vb), done_entry);
 		list_del(&vb->done_entry);
-		vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+		vb2_v4l2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irq(&pd->lock);
 	msleep(45); /* irq hendler will stop the hardware */
 }
 
 static void
-dt3155_buf_queue(struct vb2_buffer *vb)
+dt3155_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue);
+	struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 
 	/*  pd->q->streaming = 1 when dt3155_buf_queue() is invoked  */
 	spin_lock_irq(&pd->lock);
 	if (pd->curr_buf)
-		list_add_tail(&vb->done_entry, &pd->dmaq);
+		list_add_tail(&vb->vb2_buf.done_entry, &pd->dmaq);
 	else {
 		pd->curr_buf = vb;
 		dt3155_start_acq(pd);
@@ -342,7 +342,7 @@ dt3155_irq_handler_even(int irq, void *dev_id)
 	if (ipd->curr_buf) {
 		v4l2_get_timestamp(&ipd->curr_buf->v4l2_buf.timestamp);
 		ipd->curr_buf->v4l2_buf.sequence = (ipd->field_count) >> 1;
-		vb2_buffer_done(ipd->curr_buf, VB2_BUF_STATE_DONE);
+		vb2_v4l2_buffer_done(ipd->curr_buf, VB2_BUF_STATE_DONE);
 	}
 
 	if (!ipd->q->streaming || list_empty(&ipd->dmaq))
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.h b/drivers/staging/media/dt3155v4l/dt3155v4l.h
index 2e4f89d..5e4fa61 100644
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.h
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.h
@@ -196,7 +196,7 @@ struct dt3155_priv {
 	struct video_device *vdev;
 	struct pci_dev *pdev;
 	struct vb2_queue *q;
-	struct vb2_buffer *curr_buf;
+	struct vb2_v4l2_buffer *curr_buf;
 	struct mutex mux;
 	struct list_head dmaq;
 	spinlock_t lock;
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 6955044..8df1b10 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -309,7 +309,7 @@ static int iss_video_queue_setup(struct vb2_queue *vq,
 	return 0;
 }
 
-static void iss_video_buf_cleanup(struct vb2_buffer *vb)
+static void iss_video_buf_cleanup(struct vb2_v4l2_buffer *vb)
 {
 	struct iss_buffer *buffer = container_of(vb, struct iss_buffer, vb);
 
@@ -317,9 +317,9 @@ static void iss_video_buf_cleanup(struct vb2_buffer *vb)
 		buffer->iss_addr = 0;
 }
 
-static int iss_video_buf_prepare(struct vb2_buffer *vb)
+static int iss_video_buf_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct iss_video_fh *vfh = vb2_get_drv_priv(vb->vb2_queue);
+	struct iss_video_fh *vfh = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 	struct iss_buffer *buffer = container_of(vb, struct iss_buffer, vb);
 	struct iss_video *video = vfh->video;
 	unsigned long size = vfh->format.fmt.pix.sizeimage;
@@ -340,9 +340,9 @@ static int iss_video_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void iss_video_buf_queue(struct vb2_buffer *vb)
+static void iss_video_buf_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct iss_video_fh *vfh = vb2_get_drv_priv(vb->vb2_queue);
+	struct iss_video_fh *vfh = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 	struct iss_video *video = vfh->video;
 	struct iss_buffer *buffer = container_of(vb, struct iss_buffer, vb);
 	struct iss_pipeline *pipe = to_iss_pipeline(&video->video.entity);
@@ -357,7 +357,7 @@ static void iss_video_buf_queue(struct vb2_buffer *vb)
 	 * need to handle the race condition with an authoritative check here.
 	 */
 	if (unlikely(video->error)) {
-		vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+		vb2_v4l2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 		spin_unlock_irqrestore(&video->qlock, flags);
 		return;
 	}
@@ -449,7 +449,7 @@ struct iss_buffer *omap4iss_video_buffer_next(struct iss_video *video)
 	else
 		buf->vb.v4l2_buf.sequence = atomic_read(&pipe->frame_number);
 
-	vb2_buffer_done(&buf->vb, pipe->error ?
+	vb2_v4l2_buffer_done(&buf->vb, pipe->error ?
 			VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 	pipe->error = false;
 
@@ -503,7 +503,7 @@ void omap4iss_video_cancel_stream(struct iss_video *video)
 		buf = list_first_entry(&video->dmaqueue, struct iss_buffer,
 				       list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_v4l2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
 	}
 
 	vb2_queue_error(video->queue);
diff --git a/drivers/staging/media/omap4iss/iss_video.h b/drivers/staging/media/omap4iss/iss_video.h
index f11fce2..cf30642 100644
--- a/drivers/staging/media/omap4iss/iss_video.h
+++ b/drivers/staging/media/omap4iss/iss_video.h
@@ -18,7 +18,7 @@
 #include <media/media-entity.h>
 #include <media/v4l2-dev.h>
 #include <media/v4l2-fh.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #define ISS_VIDEO_DRIVER_NAME		"issvideo"
@@ -117,7 +117,7 @@ static inline int iss_pipeline_ready(struct iss_pipeline *pipe)
  */
 struct iss_buffer {
 	/* common v4l buffer stuff -- must be first */
-	struct vb2_buffer	vb;
+	struct vb2_v4l2_buffer	vb;
 	struct list_head	list;
 	dma_addr_t iss_addr;
 };
diff --git a/drivers/usb/gadget/function/uvc_queue.c b/drivers/usb/gadget/function/uvc_queue.c
index 8ea8b3b..ccf1be7 100644
--- a/drivers/usb/gadget/function/uvc_queue.c
+++ b/drivers/usb/gadget/function/uvc_queue.c
@@ -58,9 +58,9 @@ static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int uvc_buffer_prepare(struct vb2_buffer *vb)
+static int uvc_buffer_prepare(struct vb2_v4l2_buffer *vb)
 {
-	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
+	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
 
 	if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
@@ -83,9 +83,9 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static void uvc_buffer_queue(struct vb2_buffer *vb)
+static void uvc_buffer_queue(struct vb2_v4l2_buffer *vb)
 {
-	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
+	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_buf.vb2_queue);
 	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
 	unsigned long flags;
 
@@ -98,7 +98,7 @@ static void uvc_buffer_queue(struct vb2_buffer *vb)
 		 * directly. The next QBUF call will fail with -ENODEV.
 		 */
 		buf->state = UVC_BUF_STATE_ERROR;
-		vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
+		vb2_v4l2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&queue->irqlock, flags);
@@ -292,7 +292,7 @@ void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect)
 				       queue);
 		list_del(&buf->queue);
 		buf->state = UVC_BUF_STATE_ERROR;
-		vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
+		vb2_v4l2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
 	}
 	/* This must be protected by the irqlock spinlock to avoid race
 	 * conditions between uvc_queue_buffer and the disconnection event that
@@ -383,7 +383,7 @@ struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
 	v4l2_get_timestamp(&buf->buf.v4l2_buf.timestamp);
 
 	vb2_set_plane_payload(&buf->buf, 0, buf->bytesused);
-	vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE);
+	vb2_v4l2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE);
 
 	return nextbuf;
 }
diff --git a/drivers/usb/gadget/function/uvc_queue.h b/drivers/usb/gadget/function/uvc_queue.h
index 03919c7..2f0ef74 100644
--- a/drivers/usb/gadget/function/uvc_queue.h
+++ b/drivers/usb/gadget/function/uvc_queue.h
@@ -6,7 +6,7 @@
 #include <linux/kernel.h>
 #include <linux/poll.h>
 #include <linux/videodev2.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 /* Maximum frame size in bytes, for sanity checking. */
 #define UVC_MAX_FRAME_SIZE	(16*1024*1024)
@@ -26,7 +26,7 @@ enum uvc_buffer_state {
 };
 
 struct uvc_buffer {
-	struct vb2_buffer buf;
+	struct vb2_v4l2_buffer buf;
 	struct list_head queue;
 
 	enum uvc_buffer_state state;
diff --git a/include/media/davinci/vpbe_display.h b/include/media/davinci/vpbe_display.h
index fa0247a..63c16ed 100644
--- a/include/media/davinci/vpbe_display.h
+++ b/include/media/davinci/vpbe_display.h
@@ -64,7 +64,7 @@ struct display_layer_info {
 };
 
 struct vpbe_disp_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index 2f6261f..97aa133 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -18,7 +18,7 @@
 #include <linux/pm.h>
 #include <linux/videodev2.h>
 #include <media/videobuf-core.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-async.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index c5f3914..225c2a6 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -17,7 +17,7 @@
 #ifndef _MEDIA_V4L2_MEM2MEM_H
 #define _MEDIA_V4L2_MEM2MEM_H
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 /**
  * struct v4l2_m2m_ops - mem-to-mem device driver callbacks
@@ -86,7 +86,7 @@ struct v4l2_m2m_ctx {
 };
 
 struct v4l2_m2m_buffer {
-	struct vb2_buffer	vb;
+	struct vb2_v4l2_buffer	vb;
 	struct list_head	list;
 };
 
@@ -101,7 +101,7 @@ void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
 			 struct v4l2_m2m_ctx *m2m_ctx);
 
 static inline void
-v4l2_m2m_buf_done(struct vb2_buffer *buf, enum vb2_buffer_state state)
+v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state)
 {
 	vb2_buffer_done(buf, state);
 }
@@ -154,7 +154,7 @@ static inline void v4l2_m2m_set_dst_buffered(struct v4l2_m2m_ctx *m2m_ctx,
 
 void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx);
 
-void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_buffer *vb);
+void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_v4l2_buffer *vb);
 
 /**
  * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index bd2cec2..3b5df66 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -1,5 +1,5 @@
 /*
- * videobuf2-core.h - V4L2 driver helper framework
+ * videobuf2-core.h - Video Buffer 2 framework
  *
  * Copyright (C) 2010 Samsung Electronics
  *
@@ -171,18 +171,7 @@ enum vb2_buffer_state {
 struct vb2_queue;
 
 /**
- * struct vb2_buffer - represents a video buffer
- * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
- *			be read by the driver and relevant entries can be
- *			changed by the driver in case of CAPTURE types
- *			(such as timestamp)
- * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
- *			be read by the driver and relevant entries can be
- *			changed by the driver in case of CAPTURE types
- *			(such as bytesused); NOTE that even for single-planar
- *			types, the v4l2_planes[0] struct should be used
- *			instead of v4l2_buf for filling bytesused - drivers
- *			should use the vb2_set_plane_payload() function for that
+ * struct vb2_buffer - represents a common video buffer
  * @vb2_queue:		the queue to which this driver belongs
  * @num_planes:		number of planes in the buffer
  *			on an internal driver queue
@@ -194,11 +183,7 @@ struct vb2_queue;
  * @planes:		private per-plane information; do not change
  */
 struct vb2_buffer {
-	struct v4l2_buffer	v4l2_buf;
-	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
-
 	struct vb2_queue	*vb2_queue;
-
 	unsigned int		num_planes;
 
 /* Private: internal use only */
@@ -242,6 +227,27 @@ struct vb2_buffer {
 };
 
 /**
+ * struct vb2_v4l2_buffer - represents a video buffer for v4l2
+ * @vb2_buf:		common video buffer
+ * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
+ *			be read by the driver and relevant entries can be
+ *			changed by the driver in case of CAPTURE types
+ *			(such as timestamp)
+ * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
+ *			be read by the driver and relevant entries can be
+ *			changed by the driver in case of CAPTURE types
+ *			(such as bytesused); NOTE that even for single-planar
+ *			types, the v4l2_planes[0] struct should be used
+ *			instead of v4l2_buf for filling bytesused - drivers
+ *			should use the vb2_set_plane_payload() function for that
+ */
+struct vb2_v4l2_buffer {
+	struct vb2_buffer	vb2;
+	struct v4l2_buffer	v4l2_buf;
+	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
+};
+
+/**
  * struct vb2_ops - driver-specific callbacks
  *
  * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
@@ -328,15 +334,15 @@ struct vb2_ops {
 	void (*wait_prepare)(struct vb2_queue *q);
 	void (*wait_finish)(struct vb2_queue *q);
 
-	int (*buf_init)(struct vb2_buffer *vb);
-	int (*buf_prepare)(struct vb2_buffer *vb);
-	void (*buf_finish)(struct vb2_buffer *vb);
-	void (*buf_cleanup)(struct vb2_buffer *vb);
+	int (*buf_init)(struct vb2_v4l2_buffer *vb);
+	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
+	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
+	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
 
 	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
 	void (*stop_streaming)(struct vb2_queue *q);
 
-	void (*buf_queue)(struct vb2_buffer *vb);
+	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
 };
 
 struct v4l2_fh;
@@ -361,7 +367,7 @@ struct v4l2_fh;
  * @drv_priv:	driver private data
  * @buf_struct_size: size of the driver-specific buffer structure;
  *		"0" indicates the driver doesn't want to use a custom buffer
- *		structure type, so sizeof(struct vb2_buffer) will is used
+ *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
  * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
  *		V4L2_BUF_FLAG_TSTAMP_SRC_*
  * @gfp_flags:	additional gfp flags used when allocating the buffers.
@@ -398,7 +404,7 @@ struct vb2_queue {
 	unsigned int			io_modes;
 	unsigned int			io_flags;
 	struct mutex			*lock;
-	struct v4l2_fh			*owner;
+	void					*owner;
 
 	const struct vb2_ops		*ops;
 	const struct vb2_mem_ops	*mem_ops;
@@ -411,7 +417,7 @@ struct vb2_queue {
 /* private: internal use only */
 	struct mutex			mmap_lock;
 	enum v4l2_memory		memory;
-	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
+	void					*bufs[VIDEO_MAX_FRAME];
 	unsigned int			num_buffers;
 
 	struct list_head		queued_list;
@@ -446,10 +452,10 @@ struct vb2_queue {
 #endif
 };
 
-void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
-void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
+void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
+void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
 
-void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
+void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
 void vb2_discard_done(struct vb2_queue *q);
 int vb2_wait_for_all_buffers(struct vb2_queue *q);
 
@@ -489,7 +495,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
  *
  * This is called whenever a buffer is dequeued in the thread.
  */
-typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
+typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
 
 /**
  * vb2_thread_start() - start a thread for the given queue.
@@ -566,10 +572,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
  * @plane_no:	plane number for which payload should be set
  * @size:	payload in bytes
  */
-static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
+static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
 				 unsigned int plane_no, unsigned long size)
 {
-	if (plane_no < vb->num_planes)
+	if (plane_no < vb->vb2.num_planes)
 		vb->v4l2_planes[plane_no].bytesused = size;
 }
 
@@ -579,10 +585,10 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
  * @plane_no:	plane number for which payload should be set
  * @size:	payload in bytes
  */
-static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
+static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
 				 unsigned int plane_no)
 {
-	if (plane_no < vb->num_planes)
+	if (plane_no < vb->vb2.num_planes)
 		return vb->v4l2_planes[plane_no].bytesused;
 	return 0;
 }
@@ -593,9 +599,9 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
  * @plane_no:	plane number for which size should be returned
  */
 static inline unsigned long
-vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
+vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
-	if (plane_no < vb->num_planes)
+	if (plane_no < vb->vb2.num_planes)
 		return vb->v4l2_planes[plane_no].length;
 	return 0;
 }
diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h
index 8197f87..3de9111 100644
--- a/include/media/videobuf2-dma-contig.h
+++ b/include/media/videobuf2-dma-contig.h
@@ -13,11 +13,11 @@
 #ifndef _MEDIA_VIDEOBUF2_DMA_CONTIG_H
 #define _MEDIA_VIDEOBUF2_DMA_CONTIG_H
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <linux/dma-mapping.h>
 
 static inline dma_addr_t
-vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no)
+vb2_dma_contig_plane_dma_addr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
 	dma_addr_t *addr = vb2_plane_cookie(vb, plane_no);
 
diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h
index 14ce306..36f7ea3 100644
--- a/include/media/videobuf2-dma-sg.h
+++ b/include/media/videobuf2-dma-sg.h
@@ -13,10 +13,10 @@
 #ifndef _MEDIA_VIDEOBUF2_DMA_SG_H
 #define _MEDIA_VIDEOBUF2_DMA_SG_H
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 static inline struct sg_table *vb2_dma_sg_plane_desc(
-		struct vb2_buffer *vb, unsigned int plane_no)
+		struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
 	return (struct sg_table *)vb2_plane_cookie(vb, plane_no);
 }
diff --git a/include/media/videobuf2-dvb.h b/include/media/videobuf2-dvb.h
index 8f61456..bef9127 100644
--- a/include/media/videobuf2-dvb.h
+++ b/include/media/videobuf2-dvb.h
@@ -6,7 +6,7 @@
 #include <dvb_demux.h>
 #include <dvb_net.h>
 #include <dvb_frontend.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 struct vb2_dvb {
 	/* filling that the job of the driver */
diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
index f05444c..7b6d475 100644
--- a/include/media/videobuf2-memops.h
+++ b/include/media/videobuf2-memops.h
@@ -14,7 +14,7 @@
 #ifndef _MEDIA_VIDEOBUF2_MEMOPS_H
 #define _MEDIA_VIDEOBUF2_MEMOPS_H
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 /**
  * vb2_vmarea_handler - common vma refcount tracking handler
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-v4l2.h
similarity index 94%
copy from include/media/videobuf2-core.h
copy to include/media/videobuf2-v4l2.h
index bd2cec2..80b08cb 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-v4l2.h
@@ -9,8 +9,8 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation.
  */
-#ifndef _MEDIA_VIDEOBUF2_CORE_H
-#define _MEDIA_VIDEOBUF2_CORE_H
+#ifndef _MEDIA_VIDEOBUF2_V4L2_H
+#define _MEDIA_VIDEOBUF2_V4L2_H
 
 #include <linux/mm_types.h>
 #include <linux/mutex.h>
@@ -171,18 +171,7 @@ enum vb2_buffer_state {
 struct vb2_queue;
 
 /**
- * struct vb2_buffer - represents a video buffer
- * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
- *			be read by the driver and relevant entries can be
- *			changed by the driver in case of CAPTURE types
- *			(such as timestamp)
- * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
- *			be read by the driver and relevant entries can be
- *			changed by the driver in case of CAPTURE types
- *			(such as bytesused); NOTE that even for single-planar
- *			types, the v4l2_planes[0] struct should be used
- *			instead of v4l2_buf for filling bytesused - drivers
- *			should use the vb2_set_plane_payload() function for that
+ * struct vb2_buffer - represents a common video buffer
  * @vb2_queue:		the queue to which this driver belongs
  * @num_planes:		number of planes in the buffer
  *			on an internal driver queue
@@ -194,11 +183,7 @@ struct vb2_queue;
  * @planes:		private per-plane information; do not change
  */
 struct vb2_buffer {
-	struct v4l2_buffer	v4l2_buf;
-	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
-
 	struct vb2_queue	*vb2_queue;
-
 	unsigned int		num_planes;
 
 /* Private: internal use only */
@@ -242,6 +227,27 @@ struct vb2_buffer {
 };
 
 /**
+ * struct vb2_v4l2_buffer - represents a video buffer for v4l2
+ * @vb2_buf:		common video buffer
+ * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
+ *			be read by the driver and relevant entries can be
+ *			changed by the driver in case of CAPTURE types
+ *			(such as timestamp)
+ * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
+ *			be read by the driver and relevant entries can be
+ *			changed by the driver in case of CAPTURE types
+ *			(such as bytesused); NOTE that even for single-planar
+ *			types, the v4l2_planes[0] struct should be used
+ *			instead of v4l2_buf for filling bytesused - drivers
+ *			should use the vb2_set_plane_payload() function for that
+ */
+struct vb2_v4l2_buffer {
+	struct vb2_buffer	vb2;
+	struct v4l2_buffer	v4l2_buf;
+	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
+};
+
+/**
  * struct vb2_ops - driver-specific callbacks
  *
  * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
@@ -328,15 +334,15 @@ struct vb2_ops {
 	void (*wait_prepare)(struct vb2_queue *q);
 	void (*wait_finish)(struct vb2_queue *q);
 
-	int (*buf_init)(struct vb2_buffer *vb);
-	int (*buf_prepare)(struct vb2_buffer *vb);
-	void (*buf_finish)(struct vb2_buffer *vb);
-	void (*buf_cleanup)(struct vb2_buffer *vb);
+	int (*buf_init)(struct vb2_v4l2_buffer *vb);
+	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
+	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
+	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
 
 	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
 	void (*stop_streaming)(struct vb2_queue *q);
 
-	void (*buf_queue)(struct vb2_buffer *vb);
+	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
 };
 
 struct v4l2_fh;
@@ -361,7 +367,7 @@ struct v4l2_fh;
  * @drv_priv:	driver private data
  * @buf_struct_size: size of the driver-specific buffer structure;
  *		"0" indicates the driver doesn't want to use a custom buffer
- *		structure type, so sizeof(struct vb2_buffer) will is used
+ *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
  * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
  *		V4L2_BUF_FLAG_TSTAMP_SRC_*
  * @gfp_flags:	additional gfp flags used when allocating the buffers.
@@ -398,7 +404,7 @@ struct vb2_queue {
 	unsigned int			io_modes;
 	unsigned int			io_flags;
 	struct mutex			*lock;
-	struct v4l2_fh			*owner;
+	void					*owner;
 
 	const struct vb2_ops		*ops;
 	const struct vb2_mem_ops	*mem_ops;
@@ -411,7 +417,7 @@ struct vb2_queue {
 /* private: internal use only */
 	struct mutex			mmap_lock;
 	enum v4l2_memory		memory;
-	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
+	void					*bufs[VIDEO_MAX_FRAME];
 	unsigned int			num_buffers;
 
 	struct list_head		queued_list;
@@ -446,10 +452,10 @@ struct vb2_queue {
 #endif
 };
 
-void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
-void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
+void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
+void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
 
-void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
+void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
 void vb2_discard_done(struct vb2_queue *q);
 int vb2_wait_for_all_buffers(struct vb2_queue *q);
 
@@ -489,7 +495,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
  *
  * This is called whenever a buffer is dequeued in the thread.
  */
-typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
+typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
 
 /**
  * vb2_thread_start() - start a thread for the given queue.
@@ -566,10 +572,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
  * @plane_no:	plane number for which payload should be set
  * @size:	payload in bytes
  */
-static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
+static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
 				 unsigned int plane_no, unsigned long size)
 {
-	if (plane_no < vb->num_planes)
+	if (plane_no < vb->vb2.num_planes)
 		vb->v4l2_planes[plane_no].bytesused = size;
 }
 
@@ -579,10 +585,10 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
  * @plane_no:	plane number for which payload should be set
  * @size:	payload in bytes
  */
-static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
+static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
 				 unsigned int plane_no)
 {
-	if (plane_no < vb->num_planes)
+	if (plane_no < vb->vb2.num_planes)
 		return vb->v4l2_planes[plane_no].bytesused;
 	return 0;
 }
@@ -593,9 +599,9 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
  * @plane_no:	plane number for which size should be returned
  */
 static inline unsigned long
-vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
+vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
 {
-	if (plane_no < vb->num_planes)
+	if (plane_no < vb->vb2.num_planes)
 		return vb->v4l2_planes[plane_no].length;
 	return 0;
 }
@@ -653,4 +659,4 @@ unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
 void vb2_ops_wait_prepare(struct vb2_queue *vq);
 void vb2_ops_wait_finish(struct vb2_queue *vq);
 
-#endif /* _MEDIA_VIDEOBUF2_CORE_H */
+#endif /* _MEDIA_VIDEOBUF2_V4L2_H */
diff --git a/include/media/videobuf2-vmalloc.h b/include/media/videobuf2-vmalloc.h
index 93a76b4..a63fe66 100644
--- a/include/media/videobuf2-vmalloc.h
+++ b/include/media/videobuf2-vmalloc.h
@@ -13,7 +13,7 @@
 #ifndef _MEDIA_VIDEOBUF2_VMALLOC_H
 #define _MEDIA_VIDEOBUF2_VMALLOC_H
 
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 extern const struct vb2_mem_ops vb2_vmalloc_memops;
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [RFC PATCH 3/3] make vb2-core part with not v4l2-specific elements
  2015-06-08 13:35 [RFC PATCH 0/3] Refactoring Videobuf2 for common use Junghak Sung
  2015-06-08 13:35 ` [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer Junghak Sung
@ 2015-06-08 13:35 ` Junghak Sung
  2015-06-08 14:42 ` [RFC PATCH 0/3] Refactoring Videobuf2 for common use Hans Verkuil
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 15+ messages in thread
From: Junghak Sung @ 2015-06-08 13:35 UTC (permalink / raw)
  To: linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim, jh1009.sung

It is temporary work to divide the vb2-core into two part, real vb2-core and
v4l2-specific part.

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
---
 Documentation/video4linux/v4l2-pci-skeleton.c      |    4 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |    6 +-
 drivers/media/pci/cx23885/cx23885-417.c            |    2 +-
 drivers/media/pci/cx23885/cx23885-core.c           |    4 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |    2 +-
 drivers/media/pci/cx23885/cx23885-video.c          |    4 +-
 drivers/media/pci/cx25821/cx25821-video.c          |    4 +-
 drivers/media/pci/cx88/cx88-blackbird.c            |    4 +-
 drivers/media/pci/cx88/cx88-core.c                 |    2 +-
 drivers/media/pci/cx88/cx88-dvb.c                  |    2 +-
 drivers/media/pci/cx88/cx88-mpeg.c                 |    2 +-
 drivers/media/pci/cx88/cx88-vbi.c                  |    2 +-
 drivers/media/pci/cx88/cx88-video.c                |    2 +-
 drivers/media/pci/saa7134/saa7134-core.c           |    4 +-
 drivers/media/pci/saa7134/saa7134-ts.c             |    4 +-
 drivers/media/pci/saa7134/saa7134-video.c          |    4 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |    4 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    2 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c            |    4 +-
 drivers/media/pci/tw68/tw68-video.c                |    4 +-
 drivers/media/platform/am437x/am437x-vpfe.c        |   12 +-
 drivers/media/platform/blackfin/bfin_capture.c     |    6 +-
 drivers/media/platform/davinci/vpbe_display.c      |   14 +-
 drivers/media/platform/davinci/vpif_capture.c      |   12 +-
 drivers/media/platform/davinci/vpif_display.c      |   14 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |    6 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |    2 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |    6 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |    2 +-
 drivers/media/platform/omap3isp/ispvideo.c         |    6 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |    6 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc.c           |   12 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   10 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    2 +-
 drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
 drivers/media/platform/s5p-tv/mixer_video.c        |    6 +-
 drivers/media/platform/soc_camera/atmel-isi.c      |    4 +-
 drivers/media/platform/soc_camera/mx2_camera.c     |    4 +-
 drivers/media/platform/soc_camera/mx3_camera.c     |    4 +-
 drivers/media/platform/soc_camera/rcar_vin.c       |    8 +-
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |    4 +-
 drivers/media/platform/vivid/vivid-kthread-cap.c   |    8 +-
 drivers/media/platform/vivid/vivid-kthread-out.c   |    8 +-
 drivers/media/platform/vivid/vivid-sdr-cap.c       |    6 +-
 drivers/media/platform/vivid/vivid-vbi-cap.c       |    2 +-
 drivers/media/platform/vivid/vivid-vbi-out.c       |    2 +-
 drivers/media/platform/vivid/vivid-vid-cap.c       |    2 +-
 drivers/media/platform/vivid/vivid-vid-out.c       |    2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |    4 +-
 drivers/media/usb/airspy/airspy.c                  |    8 +-
 drivers/media/usb/au0828/au0828-video.c            |   12 +-
 drivers/media/usb/em28xx/em28xx-video.c            |   10 +-
 drivers/media/usb/go7007/go7007-driver.c           |    2 +-
 drivers/media/usb/hackrf/hackrf.c                  |    6 +-
 drivers/media/usb/msi2500/msi2500.c                |    6 +-
 drivers/media/usb/pwc/pwc-if.c                     |   10 +-
 drivers/media/usb/s2255/s2255drv.c                 |    4 +-
 drivers/media/usb/stk1160/stk1160-v4l.c            |    6 +-
 drivers/media/usb/stk1160/stk1160-video.c          |    2 +-
 drivers/media/usb/usbtv/usbtv-video.c              |    4 +-
 drivers/media/usb/uvc/uvc_queue.c                  |    6 +-
 drivers/media/v4l2-core/videobuf2-core.c           | 1930 ++++++++-
 drivers/media/v4l2-core/videobuf2-v4l2.c           | 4429 ++++++--------------
 include/media/v4l2-mem2mem.h                       |    2 +-
 include/media/videobuf2-core.h                     |  226 +-
 include/media/videobuf2-dma-sg.h                   |    4 +-
 include/media/videobuf2-v4l2.h                     |  121 +-
 69 files changed, 3683 insertions(+), 3351 deletions(-)

diff --git a/Documentation/video4linux/v4l2-pci-skeleton.c b/Documentation/video4linux/v4l2-pci-skeleton.c
index b1142c2..e5f4c42 100644
--- a/Documentation/video4linux/v4l2-pci-skeleton.c
+++ b/Documentation/video4linux/v4l2-pci-skeleton.c
@@ -149,7 +149,7 @@ static irqreturn_t skeleton_irq(int irq, void *dev_id)
 			else if (skel->field == V4L2_FIELD_TOP)
 				skel->field = V4L2_FIELD_BOTTOM;
 		}
-		vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&new_buf->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 #endif
 	return IRQ_HANDLED;
@@ -234,7 +234,7 @@ static void return_all_buffers(struct skeleton *skel,
 
 	spin_lock_irqsave(&skel->qlock, flags);
 	list_for_each_entry_safe(buf, node, &skel->buf_list, list) {
-		vb2_buffer_done(&buf->vb, state);
+		vb2_buffer_done(&buf->vb.vb2, state);
 		list_del(&buf->list);
 	}
 	spin_unlock_irqrestore(&skel->qlock, flags);
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 2353b63..b24ccac 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -305,7 +305,7 @@ static void rtl2832_sdr_urb_complete(struct urb *urb)
 		vb2_set_plane_payload(&fbuf->vb, 0, len);
 		v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
 		fbuf->vb.v4l2_buf.sequence = dev->sequence++;
-		vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&fbuf->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 skip:
 	usb_submit_urb(urb, GFP_ATOMIC);
@@ -459,7 +459,7 @@ static void rtl2832_sdr_cleanup_queued_bufs(struct rtl2832_sdr_dev *dev)
 		buf = list_entry(dev->queued_bufs.next,
 				struct rtl2832_sdr_frame_buf, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
 }
@@ -521,7 +521,7 @@ static void rtl2832_sdr_buf_queue(struct vb2_buffer *vb)
 
 	/* Check the device has not disconnected between prep and queuing */
 	if (!dev->udev) {
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 		return;
 	}
 
diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c
index 4e74f71..67329e4 100644
--- a/drivers/media/pci/cx23885/cx23885-417.c
+++ b/drivers/media/pci/cx23885/cx23885-417.c
@@ -1204,7 +1204,7 @@ static int cx23885_start_streaming(struct vb2_queue *q, unsigned int count)
 			struct cx23885_buffer, queue);
 
 		list_del(&buf->queue);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 	return ret;
diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
index 1ad4994..3dd63d4 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -432,7 +432,7 @@ static void cx23885_wakeup(struct cx23885_tsport *port,
 	dprintk(1, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.v4l2_buf.index,
 		count, q->count);
 	list_del(&buf->queue);
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 }
 
 int cx23885_sram_channel_setup(struct cx23885_dev *dev,
@@ -1529,7 +1529,7 @@ static void do_cancel_buffers(struct cx23885_tsport *port, char *reason)
 		buf = list_entry(q->active.next, struct cx23885_buffer,
 				 queue);
 		list_del(&buf->queue);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		dprintk(1, "[%p/%d] %s - dma=0x%08lx\n",
 			buf, buf->vb.v4l2_buf.index, reason, (unsigned long)buf->risc.dma);
 	}
diff --git a/drivers/media/pci/cx23885/cx23885-vbi.c b/drivers/media/pci/cx23885/cx23885-vbi.c
index ba0360b..08c2b0e 100644
--- a/drivers/media/pci/cx23885/cx23885-vbi.c
+++ b/drivers/media/pci/cx23885/cx23885-vbi.c
@@ -248,7 +248,7 @@ static void cx23885_stop_streaming(struct vb2_queue *q)
 			struct cx23885_buffer, queue);
 
 		list_del(&buf->queue);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index 79983f9..bee4946 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -109,7 +109,7 @@ void cx23885_video_wakeup(struct cx23885_dev *dev,
 	dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.v4l2_buf.index,
 			count, q->count);
 	list_del(&buf->queue);
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 }
 
 int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
@@ -495,7 +495,7 @@ static void cx23885_stop_streaming(struct vb2_queue *q)
 			struct cx23885_buffer, queue);
 
 		list_del(&buf->queue);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c
index 12894be..2854ad1 100644
--- a/drivers/media/pci/cx25821/cx25821-video.c
+++ b/drivers/media/pci/cx25821/cx25821-video.c
@@ -133,7 +133,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
 			v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
 			buf->vb.v4l2_buf.sequence = dmaq->count++;
 			list_del(&buf->queue);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 		}
 		spin_unlock(&dev->slock);
 		handled++;
@@ -304,7 +304,7 @@ static void cx25821_stop_streaming(struct vb2_queue *q)
 			struct cx25821_buffer, queue);
 
 		list_del(&buf->queue);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index 5bfdaaf..da006ff 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -724,7 +724,7 @@ fail:
 			struct cx88_buffer, list);
 
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 	return err;
@@ -752,7 +752,7 @@ static void stop_streaming(struct vb2_queue *q)
 			struct cx88_buffer, list);
 
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c
index c38d5a1..fb47821 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -520,7 +520,7 @@ void cx88_wakeup(struct cx88_core *core,
 			 struct cx88_buffer, list);
 	v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
 	list_del(&buf->list);
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 }
 
 void cx88_shutdown(struct cx88_core *core)
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index a13de6f..886a0c4 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -152,7 +152,7 @@ static void stop_streaming(struct vb2_queue *q)
 			struct cx88_buffer, list);
 
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index a369b08..561d81e 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -288,7 +288,7 @@ static void do_cancel_buffers(struct cx8802_dev *dev)
 	while (!list_empty(&q->active)) {
 		buf = list_entry(q->active.next, struct cx88_buffer, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock,flags);
 }
diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c
index ca23fae..a6d2db0 100644
--- a/drivers/media/pci/cx88/cx88-vbi.c
+++ b/drivers/media/pci/cx88/cx88-vbi.c
@@ -220,7 +220,7 @@ static void stop_streaming(struct vb2_queue *q)
 			struct cx88_buffer, list);
 
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index f0c486e..6eb0490 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -567,7 +567,7 @@ static void stop_streaming(struct vb2_queue *q)
 			struct cx88_buffer, list);
 
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index a349e96..cdee1a6 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -303,7 +303,7 @@ void saa7134_buffer_finish(struct saa7134_dev *dev,
 	/* finish current buffer */
 	v4l2_get_timestamp(&q->curr->vb2.v4l2_buf.timestamp);
 	q->curr->vb2.v4l2_buf.sequence = q->seq_nr++;
-	vb2_buffer_done(&q->curr->vb2, state);
+	vb2_buffer_done(&q->curr->vb2.vb2, state);
 	q->curr = NULL;
 }
 
@@ -368,7 +368,7 @@ void saa7134_stop_streaming(struct saa7134_dev *dev, struct saa7134_dmaqueue *q)
 	if (!list_empty(&q->queue)) {
 		list_for_each_safe(pos, n, &q->queue) {
 			 tmp = list_entry(pos, struct saa7134_buf, entry);
-			 vb2_buffer_done(&tmp->vb2, VB2_BUF_STATE_ERROR);
+			 vb2_buffer_done(&tmp->vb2.vb2, VB2_BUF_STATE_ERROR);
 			 list_del(pos);
 			 tmp = NULL;
 		}
diff --git a/drivers/media/pci/saa7134/saa7134-ts.c b/drivers/media/pci/saa7134/saa7134-ts.c
index dbab598..0bcd4f3 100644
--- a/drivers/media/pci/saa7134/saa7134-ts.c
+++ b/drivers/media/pci/saa7134/saa7134-ts.c
@@ -148,10 +148,10 @@ int saa7134_ts_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 		list_for_each_entry_safe(buf, tmp, &dmaq->queue, entry) {
 			list_del(&buf->entry);
-			vb2_buffer_done(&buf->vb2, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb2.vb2, VB2_BUF_STATE_QUEUED);
 		}
 		if (dmaq->curr) {
-			vb2_buffer_done(&dmaq->curr->vb2, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&dmaq->curr->vb2.vb2, VB2_BUF_STATE_QUEUED);
 			dmaq->curr = NULL;
 		}
 		return -EBUSY;
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 208f313..4d53dc2 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -951,10 +951,10 @@ int saa7134_vb2_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 		list_for_each_entry_safe(buf, tmp, &dmaq->queue, entry) {
 			list_del(&buf->entry);
-			vb2_buffer_done(&buf->vb2, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb2.vb2, VB2_BUF_STATE_QUEUED);
 		}
 		if (dmaq->curr) {
-			vb2_buffer_done(&dmaq->curr->vb2, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&dmaq->curr->vb2.vb2, VB2_BUF_STATE_QUEUED);
 			dmaq->curr = NULL;
 		}
 		return -EBUSY;
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
index 0b71219..d5ebdf6 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
@@ -546,7 +546,7 @@ static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
 		}
 	}
 
-	vb2_buffer_done(vb, ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vb->vb2, ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 
 	return ret;
 }
@@ -735,7 +735,7 @@ static void solo_enc_stop_streaming(struct vb2_queue *q)
 				struct solo_vb2_buf, list);
 
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&solo_enc->av_lock, flags);
 }
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2.c b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
index 129b53f..525f01a 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
@@ -226,7 +226,7 @@ finish_buf:
 		v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
 	}
 
-	vb2_buffer_done(vb, error ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vb->vb2, error ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 }
 
 static void solo_thread_try(struct solo_dev *solo_dev)
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 674e9fd..8d9971a 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -374,7 +374,7 @@ static void stop_streaming(struct vb2_queue *vq)
 	/* Release all active buffers */
 	spin_lock(&vip->lock);
 	list_for_each_entry_safe(vip_buf, node, &vip->buffer_list, list) {
-		vb2_buffer_done(&vip_buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&vip_buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		list_del(&vip_buf->list);
 	}
 	spin_unlock(&vip->lock);
@@ -819,7 +819,7 @@ static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip)
 		/* Remove the active buffer from the list */
 		do_gettimeofday(&vip->active->vb.v4l2_buf.timestamp);
 		vip->active->vb.v4l2_buf.sequence = vip->sequence++;
-		vb2_buffer_done(&vip->active->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vip->active->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 
 	return IRQ_HANDLED;
diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c
index f94bd23..15cbf60 100644
--- a/drivers/media/pci/tw68/tw68-video.c
+++ b/drivers/media/pci/tw68/tw68-video.c
@@ -532,7 +532,7 @@ static void tw68_stop_streaming(struct vb2_queue *q)
 			container_of(dev->active.next, struct tw68_buf, list);
 
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 }
 
@@ -1019,7 +1019,7 @@ void tw68_irq_video_done(struct tw68_dev *dev, unsigned long status)
 		v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
 		buf->vb.v4l2_buf.field = dev->field;
 		buf->vb.v4l2_buf.sequence = dev->seqnr++;
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 		status &= ~(TW68_DMAPI);
 		if (0 == status)
 			return;
diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
index 75f6d3f..feaae29 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -1272,7 +1272,7 @@ static inline void vpfe_process_buffer_complete(struct vpfe_device *vpfe)
 	v4l2_get_timestamp(&vpfe->cur_frm->vb.v4l2_buf.timestamp);
 	vpfe->cur_frm->vb.v4l2_buf.field = vpfe->fmt.fmt.pix.field;
 	vpfe->cur_frm->vb.v4l2_buf.sequence = vpfe->sequence++;
-	vb2_buffer_done(&vpfe->cur_frm->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vpfe->cur_frm->vb.vb2, VB2_BUF_STATE_DONE);
 	vpfe->cur_frm = vpfe->next_frm;
 }
 
@@ -2025,7 +2025,7 @@ static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
 err:
 	list_for_each_entry_safe(buf, tmp, &vpfe->dma_queue, list) {
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 	}
 
 	return ret;
@@ -2057,13 +2057,13 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
 	/* release all active buffers */
 	spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
 	if (vpfe->cur_frm == vpfe->next_frm) {
-		vb2_buffer_done(&vpfe->cur_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&vpfe->cur_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	} else {
 		if (vpfe->cur_frm != NULL)
-			vb2_buffer_done(&vpfe->cur_frm->vb,
+			vb2_buffer_done(&vpfe->cur_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 		if (vpfe->next_frm != NULL)
-			vb2_buffer_done(&vpfe->next_frm->vb,
+			vb2_buffer_done(&vpfe->next_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -2071,7 +2071,7 @@ static void vpfe_stop_streaming(struct vb2_queue *vq)
 		vpfe->next_frm = list_entry(vpfe->dma_queue.next,
 						struct vpfe_cap_buffer, list);
 		list_del(&vpfe->next_frm->list);
-		vb2_buffer_done(&vpfe->next_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&vpfe->next_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
 }
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index d742b51..eb17142 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -439,7 +439,7 @@ static void bcap_stop_streaming(struct vb2_queue *vq)
 		bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
 						struct bcap_buffer, list);
 		list_del_init(&bcap_dev->cur_frm->list);
-		vb2_buffer_done(&bcap_dev->cur_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&bcap_dev->cur_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 }
 
@@ -518,10 +518,10 @@ static irqreturn_t bcap_isr(int irq, void *dev_id)
 	if (!list_empty(&bcap_dev->dma_queue)) {
 		v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
 		if (ppi->err) {
-			vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_ERROR);
 			ppi->err = false;
 		} else {
-			vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_DONE);
 		}
 		bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
 				struct bcap_buffer, list);
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index 418a140..f810820 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -80,7 +80,7 @@ static void vpbe_isr_even_field(struct vpbe_display *disp_obj,
 		timevalue.tv_sec;
 	layer->cur_frm->vb.v4l2_buf.timestamp.tv_usec =
 		timevalue.tv_nsec / NSEC_PER_USEC;
-	vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&layer->cur_frm->vb.vb2, VB2_BUF_STATE_DONE);
 	/* Make cur_frm pointing to next_frm */
 	layer->cur_frm = layer->next_frm;
 }
@@ -307,10 +307,10 @@ static int vpbe_start_streaming(struct vb2_queue *vq, unsigned int count)
 	if (ret < 0) {
 		struct vpbe_disp_buffer *buf, *tmp;
 
-		vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_QUEUED);
+		vb2_buffer_done(&layer->cur_frm->vb.vb2, VB2_BUF_STATE_QUEUED);
 		list_for_each_entry_safe(buf, tmp, &layer->dma_queue, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 
 		return ret;
@@ -340,13 +340,13 @@ static void vpbe_stop_streaming(struct vb2_queue *vq)
 	/* release all active buffers */
 	spin_lock_irqsave(&disp->dma_queue_lock, flags);
 	if (layer->cur_frm == layer->next_frm) {
-		vb2_buffer_done(&layer->cur_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&layer->cur_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	} else {
 		if (layer->cur_frm != NULL)
-			vb2_buffer_done(&layer->cur_frm->vb,
+			vb2_buffer_done(&layer->cur_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 		if (layer->next_frm != NULL)
-			vb2_buffer_done(&layer->next_frm->vb,
+			vb2_buffer_done(&layer->next_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -354,7 +354,7 @@ static void vpbe_stop_streaming(struct vb2_queue *vq)
 		layer->next_frm = list_entry(layer->dma_queue.next,
 						struct vpbe_disp_buffer, list);
 		list_del(&layer->next_frm->list);
-		vb2_buffer_done(&layer->next_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&layer->next_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&disp->dma_queue_lock, flags);
 }
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index e4912c0..dbe9f97 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -245,7 +245,7 @@ static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
 err:
 	list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 
@@ -288,13 +288,13 @@ static void vpif_stop_streaming(struct vb2_queue *vq)
 	/* release all active buffers */
 	spin_lock_irqsave(&common->irqlock, flags);
 	if (common->cur_frm == common->next_frm) {
-		vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&common->cur_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	} else {
 		if (common->cur_frm != NULL)
-			vb2_buffer_done(&common->cur_frm->vb,
+			vb2_buffer_done(&common->cur_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 		if (common->next_frm != NULL)
-			vb2_buffer_done(&common->next_frm->vb,
+			vb2_buffer_done(&common->next_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -302,7 +302,7 @@ static void vpif_stop_streaming(struct vb2_queue *vq)
 		common->next_frm = list_entry(common->dma_queue.next,
 						struct vpif_cap_buffer, list);
 		list_del(&common->next_frm->list);
-		vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&common->next_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 }
@@ -328,7 +328,7 @@ static struct vb2_ops video_qops = {
 static void vpif_process_buffer_complete(struct common_obj *common)
 {
 	v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
-	vb2_buffer_done(&common->cur_frm->vb,
+	vb2_buffer_done(&common->cur_frm->vb.vb2,
 					    VB2_BUF_STATE_DONE);
 	/* Make curFrm pointing to nextFrm */
 	common->cur_frm = common->next_frm;
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 97cb223..0229e2a 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -231,7 +231,7 @@ static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
 err:
 	list_for_each_entry_safe(buf, tmp, &common->dma_queue, list) {
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 
@@ -266,13 +266,13 @@ static void vpif_stop_streaming(struct vb2_queue *vq)
 	/* release all active buffers */
 	spin_lock_irqsave(&common->irqlock, flags);
 	if (common->cur_frm == common->next_frm) {
-		vb2_buffer_done(&common->cur_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&common->cur_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	} else {
 		if (common->cur_frm != NULL)
-			vb2_buffer_done(&common->cur_frm->vb,
+			vb2_buffer_done(&common->cur_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 		if (common->next_frm != NULL)
-			vb2_buffer_done(&common->next_frm->vb,
+			vb2_buffer_done(&common->next_frm->vb.vb2,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -280,7 +280,7 @@ static void vpif_stop_streaming(struct vb2_queue *vq)
 		common->next_frm = list_entry(common->dma_queue.next,
 						struct vpif_disp_buffer, list);
 		list_del(&common->next_frm->list);
-		vb2_buffer_done(&common->next_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&common->next_frm->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 }
@@ -328,7 +328,7 @@ static void process_interlaced_mode(int fid, struct common_obj *common)
 		/* Copy frame display time */
 		v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
 		/* Change status of the cur_frm */
-		vb2_buffer_done(&common->cur_frm->vb,
+		vb2_buffer_done(&common->cur_frm->vb.vb2,
 					    VB2_BUF_STATE_DONE);
 		/* Make cur_frm pointing to next_frm */
 		common->cur_frm = common->next_frm;
@@ -384,7 +384,7 @@ static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
 				 * done and unlock semaphore on it */
 				v4l2_get_timestamp(&common->cur_frm->vb.
 						   v4l2_buf.timestamp);
-				vb2_buffer_done(&common->cur_frm->vb,
+				vb2_buffer_done(&common->cur_frm->vb.vb2,
 					    VB2_BUF_STATE_DONE);
 				/* Make cur_frm pointing to next_frm */
 				common->cur_frm = common->next_frm;
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 40db7ac..775d33a 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -103,7 +103,7 @@ static int fimc_capture_state_cleanup(struct fimc_dev *fimc, bool suspend)
 	/* Release unused buffers */
 	while (!suspend && !list_empty(&cap->pending_buf_q)) {
 		buf = fimc_pending_queue_pop(cap);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	/* If suspending put unused buffers onto pending queue */
 	while (!list_empty(&cap->active_buf_q)) {
@@ -111,7 +111,7 @@ static int fimc_capture_state_cleanup(struct fimc_dev *fimc, bool suspend)
 		if (suspend)
 			fimc_pending_queue_add(cap, buf);
 		else
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	fimc_hw_reset(fimc);
@@ -202,7 +202,7 @@ void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf)
 		tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
 		v_buf->vb.v4l2_buf.sequence = cap->frame_count++;
 
-		vb2_buffer_done(&v_buf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&v_buf->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 
 	if (!list_empty(&cap->pending_buf_q)) {
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 833a238..2443ec0 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -256,7 +256,7 @@ void fimc_isp_video_irq_handler(struct fimc_is *is)
 	vb = &video->buffers[buf_index]->vb;
 
 	v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
-	vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_DONE);
 
 	video->buf_mask &= ~BIT(buf_index);
 	fimc_is_hw_set_isp_buf_mask(is, video->buf_mask);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index ec8bbf1..8d5bdc9 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -200,7 +200,7 @@ static int fimc_lite_reinit(struct fimc_lite *fimc, bool suspend)
 	/* Release unused buffers */
 	while (!suspend && !list_empty(&fimc->pending_buf_q)) {
 		buf = fimc_lite_pending_queue_pop(fimc);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	/* If suspending put unused buffers onto pending queue */
 	while (!list_empty(&fimc->active_buf_q)) {
@@ -208,7 +208,7 @@ static int fimc_lite_reinit(struct fimc_lite *fimc, bool suspend)
 		if (suspend)
 			fimc_lite_pending_queue_add(fimc, buf);
 		else
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&fimc->slock, flags);
@@ -300,7 +300,7 @@ static irqreturn_t flite_irq_handler(int irq, void *priv)
 		tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
 		vbuf->vb.v4l2_buf.sequence = fimc->frame_count++;
 		flite_hw_mask_dma_buffer(fimc, vbuf->index);
-		vb2_buffer_done(&vbuf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vbuf->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 
 	if (test_bit(ST_FLITE_CONFIG, &fimc->state))
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 50b23af..e7aea8a 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -238,7 +238,7 @@ static void mcam_buffer_done(struct mcam_camera *cam, int frame,
 	vbuf->v4l2_buf.bytesused = cam->pix_format.sizeimage;
 	vbuf->v4l2_buf.sequence = cam->buf_seq[frame];
 	vb2_set_plane_payload(vbuf, 0, cam->pix_format.sizeimage);
-	vb2_buffer_done(vbuf, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vbuf->vb2, VB2_BUF_STATE_DONE);
 }
 
 
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 5d390e7..861e790 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -394,7 +394,7 @@ static void isp_video_buffer_queue(struct vb2_buffer *vb)
 	spin_lock_irqsave(&video->irqlock, flags);
 
 	if (unlikely(video->error)) {
-		vb2_buffer_done(&buffer->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buffer->vb.vb2, VB2_BUF_STATE_ERROR);
 		spin_unlock_irqrestore(&video->irqlock, flags);
 		return;
 	}
@@ -496,7 +496,7 @@ struct isp_buffer *omap3isp_video_buffer_next(struct isp_video *video)
 		state = VB2_BUF_STATE_DONE;
 	}
 
-	vb2_buffer_done(&buf->vb, state);
+	vb2_buffer_done(&buf->vb.vb2, state);
 
 	spin_lock_irqsave(&video->irqlock, flags);
 
@@ -552,7 +552,7 @@ void omap3isp_video_cancel_stream(struct isp_video *video)
 		buf = list_first_entry(&video->dmaqueue,
 				       struct isp_buffer, irqlist);
 		list_del(&buf->irqlist);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	video->error = true;
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index a1f982f..def396f 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -164,12 +164,12 @@ static int camif_reinitialize(struct camif_vp *vp)
 	/* Release unused buffers */
 	while (!list_empty(&vp->pending_buf_q)) {
 		buf = camif_pending_queue_pop(vp);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	while (!list_empty(&vp->active_buf_q)) {
 		buf = camif_active_queue_pop(vp);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&camif->slock, flags);
@@ -346,7 +346,7 @@ irqreturn_t s3c_camif_irq_handler(int irq, void *priv)
 			tv->tv_sec = ts.tv_sec;
 			tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
 			vbuf->vb.v4l2_buf.sequence = vp->frame_sequence++;
-			vb2_buffer_done(&vbuf->vb, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&vbuf->vb.vb2, VB2_BUF_STATE_DONE);
 
 			/* Set up an empty buffer at the DMA engine */
 			vbuf = camif_pending_queue_pop(vp);
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 93f3e13..8ac79a2 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -2183,7 +2183,7 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
 		     min((unsigned long)ctx->out_q.size,
 			 vb2_get_plane_payload(cb, 0)), ctx);
 		if (!ctx->hdr_parsed) {
-			vb2_buffer_done(cb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 			return;
 		}
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 5600dcd..fc00580 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -213,7 +213,7 @@ static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
 			dst_buf->b->v4l2_buf.field = V4L2_FIELD_INTERLACED;
 
 		ctx->dec_dst_flag &= ~(1 << dst_buf->b->v4l2_buf.index);
-		vb2_buffer_done(dst_buf->b, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&dst_buf->b->vb2, VB2_BUF_STATE_DONE);
 	}
 }
 
@@ -312,7 +312,7 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
 			clear_bit(dst_buf->b->v4l2_buf.index,
 							&ctx->dec_dst_flag);
 
-			vb2_buffer_done(dst_buf->b,
+			vb2_buffer_done(&dst_buf->b->vb2,
 				err ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 
 			break;
@@ -406,9 +406,9 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
 			list_del(&src_buf->list);
 			ctx->src_queue_cnt--;
 			if (s5p_mfc_hw_call(dev->mfc_ops, err_dec, err) > 0)
-				vb2_buffer_done(src_buf->b, VB2_BUF_STATE_ERROR);
+				vb2_buffer_done(&src_buf->b->vb2, VB2_BUF_STATE_ERROR);
 			else
-				vb2_buffer_done(src_buf->b, VB2_BUF_STATE_DONE);
+				vb2_buffer_done(&src_buf->b->vb2, VB2_BUF_STATE_DONE);
 		}
 	}
 leave_handle_frame:
@@ -550,7 +550,7 @@ static void s5p_mfc_handle_init_buffers(struct s5p_mfc_ctx *ctx,
 					     struct s5p_mfc_buf, list);
 				list_del(&src_buf->list);
 				ctx->src_queue_cnt--;
-				vb2_buffer_done(src_buf->b,
+				vb2_buffer_done(&src_buf->b->vb2,
 						VB2_BUF_STATE_DONE);
 			}
 			spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -592,7 +592,7 @@ static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx,
 		list_del(&mb_entry->list);
 		ctx->dst_queue_cnt--;
 		vb2_set_plane_payload(mb_entry->b, 0, 0);
-		vb2_buffer_done(mb_entry->b, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&mb_entry->b->vb2, VB2_BUF_STATE_DONE);
 	}
 	spin_unlock(&dev->irqlock);
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 062a087..2a1e7fc 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -799,7 +799,7 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
 			vb2_set_plane_payload(dst_mb->b, 0,
 				s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size,
 						dev));
-			vb2_buffer_done(dst_mb->b, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&dst_mb->b->vb2, VB2_BUF_STATE_DONE);
 		}
 		spin_unlock_irqrestore(&dev->irqlock, flags);
 	}
@@ -875,7 +875,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
 						(enc_c_addr == mb_c_addr)) {
 				list_del(&mb_entry->list);
 				ctx->src_queue_cnt--;
-				vb2_buffer_done(mb_entry->b,
+				vb2_buffer_done(&mb_entry->b->vb2,
 							VB2_BUF_STATE_DONE);
 				break;
 			}
@@ -887,7 +887,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
 						(enc_c_addr == mb_c_addr)) {
 				list_del(&mb_entry->list);
 				ctx->ref_queue_cnt--;
-				vb2_buffer_done(mb_entry->b,
+				vb2_buffer_done(&mb_entry->b->vb2,
 							VB2_BUF_STATE_DONE);
 				break;
 			}
@@ -922,7 +922,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
 			break;
 		}
 		vb2_set_plane_payload(mb_entry->b, 0, strm_size);
-		vb2_buffer_done(mb_entry->b, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&mb_entry->b->vb2, VB2_BUF_STATE_DONE);
 	}
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0))
@@ -2009,7 +2009,7 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
 	struct s5p_mfc_buf *mfc_buf;
 
 	if (ctx->state == MFCINST_ERROR) {
-		vb2_buffer_done(cb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 		cleanup_ref_queue(ctx);
 		return;
 	}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
index c64ff34..e36b6c5 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -1478,7 +1478,7 @@ static void s5p_mfc_cleanup_queue_v5(struct list_head *lh, struct vb2_queue *vq)
 		b = list_entry(lh->next, struct s5p_mfc_buf, list);
 		for (i = 0; i < b->b->vb2.num_planes; i++)
 			vb2_set_plane_payload(b->b, i, 0);
-		vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&b->b->vb2, VB2_BUF_STATE_ERROR);
 		list_del(&b->list);
 	}
 }
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 75e875f..a68dd3a 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1836,7 +1836,7 @@ static void s5p_mfc_cleanup_queue_v6(struct list_head *lh, struct vb2_queue *vq)
 		b = list_entry(lh->next, struct s5p_mfc_buf, list);
 		for (i = 0; i < b->b->vb2.num_planes; i++)
 			vb2_set_plane_payload(b->b, i, 0);
-		vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&b->b->vb2, VB2_BUF_STATE_ERROR);
 		list_del(&b->list);
 	}
 }
diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
index b713403..72d367c 100644
--- a/drivers/media/platform/s5p-tv/mixer_reg.c
+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
@@ -279,7 +279,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
 	layer->ops.buffer_set(layer, layer->update_buf);
 
 	if (done && done != layer->shadow_buf)
-		vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&done->vb.vb2, VB2_BUF_STATE_DONE);
 
 done:
 	spin_unlock(&layer->enq_slock);
diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
index 47309f0..ab30d46 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -964,11 +964,11 @@ static void mxr_watchdog(unsigned long arg)
 	if (layer->update_buf == layer->shadow_buf)
 		layer->update_buf = NULL;
 	if (layer->update_buf) {
-		vb2_buffer_done(&layer->update_buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&layer->update_buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		layer->update_buf = NULL;
 	}
 	if (layer->shadow_buf) {
-		vb2_buffer_done(&layer->shadow_buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&layer->shadow_buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		layer->shadow_buf = NULL;
 	}
 	spin_unlock_irqrestore(&layer->enq_slock, flags);
@@ -992,7 +992,7 @@ static void stop_streaming(struct vb2_queue *vq)
 	/* set all buffer to be done */
 	list_for_each_entry_safe(buf, buf_tmp, &layer->enq_list, list) {
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&layer->enq_slock, flags);
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index b3e9315..9c592e3 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -159,7 +159,7 @@ static irqreturn_t atmel_isi_handle_streaming(struct atmel_isi *isi)
 		list_del_init(&buf->list);
 		v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
 		vb->v4l2_buf.sequence = isi->sequence++;
-		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_DONE);
 	}
 
 	if (list_empty(&isi->video_buffer_list)) {
@@ -425,7 +425,7 @@ static void stop_streaming(struct vb2_queue *vq)
 	/* Release all active buffers */
 	list_for_each_entry_safe(buf, node, &isi->video_buffer_list, list) {
 		list_del_init(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irq(&isi->lock);
 
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index 45e956a..2cfd4d1 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -1340,9 +1340,9 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
 		v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
 		vb->v4l2_buf.sequence = pcdev->frame_count;
 		if (err)
-			vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_ERROR);
 		else
-			vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_DONE);
 	}
 
 	pcdev->frame_count++;
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index e431b7c..cd7ba2a 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -158,7 +158,7 @@ static void mx3_cam_dma_done(void *arg)
 		v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
 		vb->v4l2_buf.field = mx3_cam->field;
 		vb->v4l2_buf.sequence = mx3_cam->sequence++;
-		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_DONE);
 	}
 
 	if (list_empty(&mx3_cam->capture)) {
@@ -428,7 +428,7 @@ static void mx3_stop_streaming(struct vb2_queue *q)
 
 	list_for_each_entry_safe(buf, tmp, &mx3_cam->capture, queue) {
 		list_del_init(&buf->queue);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&mx3_cam->lock, flags);
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index 1f84155..24ef71a 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -841,7 +841,7 @@ static void rcar_vin_stop_streaming(struct vb2_queue *vq)
 
 	for (i = 0; i < MAX_BUFFER_NUM; i++) {
 		if (priv->queue_buf[i]) {
-			vb2_buffer_done(priv->queue_buf[i],
+			vb2_buffer_done(&priv->queue_buf[i]->vb2,
 					VB2_BUF_STATE_ERROR);
 			priv->queue_buf[i] = NULL;
 		}
@@ -849,7 +849,7 @@ static void rcar_vin_stop_streaming(struct vb2_queue *vq)
 
 	list_for_each_safe(buf_head, tmp, &priv->capture) {
 		vb2_buffer_done(&list_entry(buf_head,
-					struct rcar_vin_buffer, list)->vb,
+					struct rcar_vin_buffer, list)->vb.vb2,
 				VB2_BUF_STATE_ERROR);
 		list_del_init(buf_head);
 	}
@@ -897,7 +897,7 @@ static irqreturn_t rcar_vin_irq(int irq, void *data)
 		priv->queue_buf[slot]->v4l2_buf.field = priv->field;
 		priv->queue_buf[slot]->v4l2_buf.sequence = priv->sequence++;
 		do_gettimeofday(&priv->queue_buf[slot]->v4l2_buf.timestamp);
-		vb2_buffer_done(priv->queue_buf[slot], VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&priv->queue_buf[slot]->vb2, VB2_BUF_STATE_DONE);
 		priv->queue_buf[slot] = NULL;
 
 		if (priv->state != STOPPING)
@@ -968,7 +968,7 @@ static void rcar_vin_remove_device(struct soc_camera_device *icd)
 		vb = priv->queue_buf[i];
 		if (vb) {
 			list_del_init(to_buf_list(vb));
-			vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&vb->vb2, VB2_BUF_STATE_ERROR);
 		}
 	}
 	spin_unlock_irq(&priv->lock);
diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
index 5713920..14a22da 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -533,7 +533,7 @@ static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
 		vb->v4l2_buf.field = pcdev->field;
 		vb->v4l2_buf.sequence = pcdev->sequence++;
 	}
-	vb2_buffer_done(vb, ret < 0 ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vb->vb2, ret < 0 ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 
 out:
 	spin_unlock(&pcdev->lock);
@@ -638,7 +638,7 @@ static void sh_mobile_ceu_clock_stop(struct soc_camera_host *ici)
 	spin_lock_irq(&pcdev->lock);
 	if (pcdev->active) {
 		list_del_init(&to_ceu_vb(pcdev->active)->queue);
-		vb2_buffer_done(pcdev->active, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&pcdev->active->vb2, VB2_BUF_STATE_ERROR);
 		pcdev->active = NULL;
 	}
 	spin_unlock_irq(&pcdev->lock);
diff --git a/drivers/media/platform/vivid/vivid-kthread-cap.c b/drivers/media/platform/vivid/vivid-kthread-cap.c
index 39a67cf..0fbd564 100644
--- a/drivers/media/platform/vivid/vivid-kthread-cap.c
+++ b/drivers/media/platform/vivid/vivid-kthread-cap.c
@@ -677,7 +677,7 @@ static void vivid_thread_vid_cap_tick(struct vivid_dev *dev, int dropped_bufs)
 				dev->fb_cap.fmt.pixelformat == dev->fmt_cap->fourcc)
 			vivid_overlay(dev, vid_cap_buf);
 
-		vb2_buffer_done(&vid_cap_buf->vb, dev->dqbuf_error ?
+		vb2_buffer_done(&vid_cap_buf->vb.vb2, dev->dqbuf_error ?
 				VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 		dprintk(dev, 2, "vid_cap buffer %d done\n",
 				vid_cap_buf->vb.v4l2_buf.index);
@@ -688,7 +688,7 @@ static void vivid_thread_vid_cap_tick(struct vivid_dev *dev, int dropped_bufs)
 			vivid_sliced_vbi_cap_process(dev, vbi_cap_buf);
 		else
 			vivid_raw_vbi_cap_process(dev, vbi_cap_buf);
-		vb2_buffer_done(&vbi_cap_buf->vb, dev->dqbuf_error ?
+		vb2_buffer_done(&vbi_cap_buf->vb.vb2, dev->dqbuf_error ?
 				VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 		dprintk(dev, 2, "vbi_cap %d done\n",
 				vbi_cap_buf->vb.v4l2_buf.index);
@@ -855,7 +855,7 @@ void vivid_stop_generating_vid_cap(struct vivid_dev *dev, bool *pstreaming)
 			buf = list_entry(dev->vid_cap_active.next,
 					 struct vivid_buffer, list);
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 			dprintk(dev, 2, "vid_cap buffer %d done\n",
 				buf->vb.v4l2_buf.index);
 		}
@@ -868,7 +868,7 @@ void vivid_stop_generating_vid_cap(struct vivid_dev *dev, bool *pstreaming)
 			buf = list_entry(dev->vbi_cap_active.next,
 					 struct vivid_buffer, list);
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 			dprintk(dev, 2, "vbi_cap buffer %d done\n",
 				buf->vb.v4l2_buf.index);
 		}
diff --git a/drivers/media/platform/vivid/vivid-kthread-out.c b/drivers/media/platform/vivid/vivid-kthread-out.c
index d9f36cc..551d306 100644
--- a/drivers/media/platform/vivid/vivid-kthread-out.c
+++ b/drivers/media/platform/vivid/vivid-kthread-out.c
@@ -97,7 +97,7 @@ static void vivid_thread_vid_out_tick(struct vivid_dev *dev)
 		}
 		v4l2_get_timestamp(&vid_out_buf->vb.v4l2_buf.timestamp);
 		vid_out_buf->vb.v4l2_buf.timestamp.tv_sec += dev->time_wrap_offset;
-		vb2_buffer_done(&vid_out_buf->vb, dev->dqbuf_error ?
+		vb2_buffer_done(&vid_out_buf->vb.vb2, dev->dqbuf_error ?
 				VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 		dprintk(dev, 2, "vid_out buffer %d done\n",
 			vid_out_buf->vb.v4l2_buf.index);
@@ -110,7 +110,7 @@ static void vivid_thread_vid_out_tick(struct vivid_dev *dev)
 		vbi_out_buf->vb.v4l2_buf.sequence = dev->vbi_out_seq_count;
 		v4l2_get_timestamp(&vbi_out_buf->vb.v4l2_buf.timestamp);
 		vbi_out_buf->vb.v4l2_buf.timestamp.tv_sec += dev->time_wrap_offset;
-		vb2_buffer_done(&vbi_out_buf->vb, dev->dqbuf_error ?
+		vb2_buffer_done(&vbi_out_buf->vb.vb2, dev->dqbuf_error ?
 				VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 		dprintk(dev, 2, "vbi_out buffer %d done\n",
 			vbi_out_buf->vb.v4l2_buf.index);
@@ -274,7 +274,7 @@ void vivid_stop_generating_vid_out(struct vivid_dev *dev, bool *pstreaming)
 			buf = list_entry(dev->vid_out_active.next,
 					 struct vivid_buffer, list);
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 			dprintk(dev, 2, "vid_out buffer %d done\n",
 				buf->vb.v4l2_buf.index);
 		}
@@ -287,7 +287,7 @@ void vivid_stop_generating_vid_out(struct vivid_dev *dev, bool *pstreaming)
 			buf = list_entry(dev->vbi_out_active.next,
 					 struct vivid_buffer, list);
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 			dprintk(dev, 2, "vbi_out buffer %d done\n",
 				buf->vb.v4l2_buf.index);
 		}
diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.c b/drivers/media/platform/vivid/vivid-sdr-cap.c
index f17dc18..e7f9c7b 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
@@ -98,7 +98,7 @@ static void vivid_thread_sdr_cap_tick(struct vivid_dev *dev)
 		vivid_sdr_cap_process(dev, sdr_cap_buf);
 		v4l2_get_timestamp(&sdr_cap_buf->vb.v4l2_buf.timestamp);
 		sdr_cap_buf->vb.v4l2_buf.timestamp.tv_sec += dev->time_wrap_offset;
-		vb2_buffer_done(&sdr_cap_buf->vb, dev->dqbuf_error ?
+		vb2_buffer_done(&sdr_cap_buf->vb.vb2, dev->dqbuf_error ?
 				VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 		dev->dqbuf_error = false;
 	}
@@ -264,7 +264,7 @@ static int sdr_cap_start_streaming(struct vb2_queue *vq, unsigned count)
 
 		list_for_each_entry_safe(buf, tmp, &dev->sdr_cap_active, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 	}
 	return err;
@@ -283,7 +283,7 @@ static void sdr_cap_stop_streaming(struct vb2_queue *vq)
 
 		buf = list_entry(dev->sdr_cap_active.next, struct vivid_buffer, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	/* shutdown control thread */
diff --git a/drivers/media/platform/vivid/vivid-vbi-cap.c b/drivers/media/platform/vivid/vivid-vbi-cap.c
index 5758beb..3f63dff 100644
--- a/drivers/media/platform/vivid/vivid-vbi-cap.c
+++ b/drivers/media/platform/vivid/vivid-vbi-cap.c
@@ -217,7 +217,7 @@ static int vbi_cap_start_streaming(struct vb2_queue *vq, unsigned count)
 
 		list_for_each_entry_safe(buf, tmp, &dev->vbi_cap_active, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 	}
 	return err;
diff --git a/drivers/media/platform/vivid/vivid-vbi-out.c b/drivers/media/platform/vivid/vivid-vbi-out.c
index 181fea0..582c0b4 100644
--- a/drivers/media/platform/vivid/vivid-vbi-out.c
+++ b/drivers/media/platform/vivid/vivid-vbi-out.c
@@ -109,7 +109,7 @@ static int vbi_out_start_streaming(struct vb2_queue *vq, unsigned count)
 
 		list_for_each_entry_safe(buf, tmp, &dev->vbi_out_active, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 	}
 	return err;
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index 8427b16..4708d48 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -269,7 +269,7 @@ static int vid_cap_start_streaming(struct vb2_queue *vq, unsigned count)
 
 		list_for_each_entry_safe(buf, tmp, &dev->vid_cap_active, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 	}
 	return err;
diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index 5427ded..8b97ef9 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -190,7 +190,7 @@ static int vid_out_start_streaming(struct vb2_queue *vq, unsigned count)
 
 		list_for_each_entry_safe(buf, tmp, &dev->vid_out_active, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 	}
 	return err;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 0983ea6..2abcc20 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -602,7 +602,7 @@ vsp1_video_complete_buffer(struct vsp1_video *video)
 	v4l2_get_timestamp(&done->buf.v4l2_buf.timestamp);
 	for (i = 0; i < done->buf.vb2.num_planes; ++i)
 		vb2_set_plane_payload(&done->buf, i, done->length[i]);
-	vb2_buffer_done(&done->buf, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&done->buf.vb2, VB2_BUF_STATE_DONE);
 
 	return next;
 }
@@ -875,7 +875,7 @@ static void vsp1_video_stop_streaming(struct vb2_queue *vq)
 	/* Remove all buffers from the IRQ queue. */
 	spin_lock_irqsave(&video->irqlock, flags);
 	list_for_each_entry(buffer, &video->irqqueue, queue)
-		vb2_buffer_done(&buffer->buf, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buffer->buf.vb2, VB2_BUF_STATE_ERROR);
 	INIT_LIST_HEAD(&video->irqqueue);
 	spin_unlock_irqrestore(&video->irqlock, flags);
 }
diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c
index 637a75e..c18424b 100644
--- a/drivers/media/usb/airspy/airspy.c
+++ b/drivers/media/usb/airspy/airspy.c
@@ -316,7 +316,7 @@ static void airspy_urb_complete(struct urb *urb)
 		vb2_set_plane_payload(&fbuf->vb, 0, len);
 		v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
 		fbuf->vb.v4l2_buf.sequence = s->sequence++;
-		vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&fbuf->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 skip:
 	usb_submit_urb(urb, GFP_ATOMIC);
@@ -459,7 +459,7 @@ static void airspy_cleanup_queued_bufs(struct airspy *s)
 		buf = list_entry(s->queued_bufs.next,
 				struct airspy_frame_buf, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&s->queued_bufs_lock, flags);
 }
@@ -513,7 +513,7 @@ static void airspy_buf_queue(struct vb2_buffer *vb)
 
 	/* Check the device has not disconnected between prep and queuing */
 	if (unlikely(!s->udev)) {
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		return;
 	}
 
@@ -572,7 +572,7 @@ err_clear_bit:
 
 		list_for_each_entry_safe(buf, tmp, &s->queued_bufs, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 	}
 
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 2a25401..6e03417 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -308,7 +308,7 @@ static inline void buffer_filled(struct au0828_dev *dev,
 	buf->vb.v4l2_buf.sequence = dev->frame_count++;
 	buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
 	v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 }
 
 static inline void vbi_buffer_filled(struct au0828_dev *dev,
@@ -321,7 +321,7 @@ static inline void vbi_buffer_filled(struct au0828_dev *dev,
 	buf->vb.v4l2_buf.sequence = dev->vbi_frame_count++;
 	buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
 	v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 }
 
 /*
@@ -837,14 +837,14 @@ static void au0828_stop_streaming(struct vb2_queue *vq)
 
 	spin_lock_irqsave(&dev->slock, flags);
 	if (dev->isoc_ctl.buf != NULL) {
-		vb2_buffer_done(&dev->isoc_ctl.buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&dev->isoc_ctl.buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		dev->isoc_ctl.buf = NULL;
 	}
 	while (!list_empty(&vidq->active)) {
 		struct au0828_buffer *buf;
 
 		buf = list_entry(vidq->active.next, struct au0828_buffer, list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		list_del(&buf->list);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
@@ -864,7 +864,7 @@ void au0828_stop_vbi_streaming(struct vb2_queue *vq)
 
 	spin_lock_irqsave(&dev->slock, flags);
 	if (dev->isoc_ctl.vbi_buf != NULL) {
-		vb2_buffer_done(&dev->isoc_ctl.vbi_buf->vb,
+		vb2_buffer_done(&dev->isoc_ctl.vbi_buf->vb.vb2,
 				VB2_BUF_STATE_ERROR);
 		dev->isoc_ctl.vbi_buf = NULL;
 	}
@@ -873,7 +873,7 @@ void au0828_stop_vbi_streaming(struct vb2_queue *vq)
 
 		buf = list_entry(vbiq->active.next, struct au0828_buffer, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 50f7859..39d765f 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -440,7 +440,7 @@ static inline void finish_buffer(struct em28xx *dev,
 		buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
 	v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
 
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 }
 
 /*
@@ -999,7 +999,7 @@ static void em28xx_stop_streaming(struct vb2_queue *vq)
 
 	spin_lock_irqsave(&dev->slock, flags);
 	if (dev->usb_ctl.vid_buf != NULL) {
-		vb2_buffer_done(&dev->usb_ctl.vid_buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&dev->usb_ctl.vid_buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		dev->usb_ctl.vid_buf = NULL;
 	}
 	while (!list_empty(&vidq->active)) {
@@ -1007,7 +1007,7 @@ static void em28xx_stop_streaming(struct vb2_queue *vq)
 
 		buf = list_entry(vidq->active.next, struct em28xx_buffer, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
@@ -1030,7 +1030,7 @@ void em28xx_stop_vbi_streaming(struct vb2_queue *vq)
 
 	spin_lock_irqsave(&dev->slock, flags);
 	if (dev->usb_ctl.vbi_buf != NULL) {
-		vb2_buffer_done(&dev->usb_ctl.vbi_buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&dev->usb_ctl.vbi_buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		dev->usb_ctl.vbi_buf = NULL;
 	}
 	while (!list_empty(&vbiq->active)) {
@@ -1038,7 +1038,7 @@ void em28xx_stop_vbi_streaming(struct vb2_queue *vq)
 
 		buf = list_entry(vbiq->active.next, struct em28xx_buffer, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/usb/go7007/go7007-driver.c b/drivers/media/usb/go7007/go7007-driver.c
index 95cffb7..2c9f056 100644
--- a/drivers/media/usb/go7007/go7007-driver.c
+++ b/drivers/media/usb/go7007/go7007-driver.c
@@ -475,7 +475,7 @@ static struct go7007_buffer *frame_boundary(struct go7007 *go, struct go7007_buf
 		vb = list_first_entry(&go->vidq_active, struct go7007_buffer, list);
 	go->active_buf = vb;
 	spin_unlock(&go->spinlock);
-	vb2_buffer_done(&vb_tmp->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vb_tmp->vb.vb2, VB2_BUF_STATE_DONE);
 	return vb;
 }
 
diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c
index 46fc79d..5a173a8 100644
--- a/drivers/media/usb/hackrf/hackrf.c
+++ b/drivers/media/usb/hackrf/hackrf.c
@@ -293,7 +293,7 @@ static void hackrf_urb_complete(struct urb *urb)
 		vb2_set_plane_payload(&fbuf->vb, 0, len);
 		v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
 		fbuf->vb.v4l2_buf.sequence = dev->sequence++;
-		vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&fbuf->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 skip:
 	usb_submit_urb(urb, GFP_ATOMIC);
@@ -437,7 +437,7 @@ static void hackrf_cleanup_queued_bufs(struct hackrf_dev *dev)
 		buf = list_entry(dev->queued_bufs.next,
 				struct hackrf_frame_buf, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
 }
@@ -540,7 +540,7 @@ err:
 
 		list_for_each_entry_safe(buf, tmp, &dev->queued_bufs, list) {
 			list_del(&buf->list);
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_QUEUED);
 		}
 	}
 
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index 14777b5..771eb08e 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -435,7 +435,7 @@ static void msi2500_isoc_handler(struct urb *urb)
 		ptr = vb2_plane_vaddr(&fbuf->vb, 0);
 		flen = msi2500_convert_stream(s, ptr, iso_buf, flen);
 		vb2_set_plane_payload(&fbuf->vb, 0, flen);
-		vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&fbuf->vb.vb2, VB2_BUF_STATE_DONE);
 	}
 
 handler_end:
@@ -569,7 +569,7 @@ static void msi2500_cleanup_queued_bufs(struct msi2500_state *s)
 		buf = list_entry(s->queued_bufs.next, struct msi2500_frame_buf,
 				 list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&s->queued_bufs_lock, flags);
 }
@@ -639,7 +639,7 @@ static void msi2500_buf_queue(struct vb2_buffer *vb)
 
 	/* Check the device has not disconnected between prep and queuing */
 	if (unlikely(!s->udev)) {
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		return;
 	}
 
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 87fc603..1f1c558 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -242,7 +242,7 @@ static void pwc_frame_complete(struct pwc_device *pdev)
 		} else {
 			fbuf->vb.v4l2_buf.field = V4L2_FIELD_NONE;
 			fbuf->vb.v4l2_buf.sequence = pdev->vframe_count;
-			vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&fbuf->vb.vb2, VB2_BUF_STATE_DONE);
 			pdev->fill_buf = NULL;
 			pdev->vsync = 0;
 		}
@@ -287,7 +287,7 @@ static void pwc_isoc_handler(struct urb *urb)
 		{
 			PWC_ERROR("Too many ISOC errors, bailing out.\n");
 			if (pdev->fill_buf) {
-				vb2_buffer_done(&pdev->fill_buf->vb,
+				vb2_buffer_done(&pdev->fill_buf->vb.vb2,
 						VB2_BUF_STATE_ERROR);
 				pdev->fill_buf = NULL;
 			}
@@ -520,7 +520,7 @@ static void pwc_cleanup_queued_bufs(struct pwc_device *pdev,
 		buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf,
 				 list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, state);
+		vb2_buffer_done(&buf->vb.vb2, state);
 	}
 	spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
 }
@@ -650,7 +650,7 @@ static void buffer_queue(struct vb2_buffer *vb)
 
 	/* Check the device has not disconnected between prep and queuing */
 	if (!pdev->udev) {
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		return;
 	}
 
@@ -699,7 +699,7 @@ static void stop_streaming(struct vb2_queue *vq)
 
 	pwc_cleanup_queued_bufs(pdev, VB2_BUF_STATE_ERROR);
 	if (pdev->fill_buf)
-		vb2_buffer_done(&pdev->fill_buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&pdev->fill_buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	mutex_unlock(&pdev->v4l2_lock);
 }
 
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 0bebb53..ebb408c 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -580,7 +580,7 @@ static void s2255_got_frame(struct s2255_vc *vc, int jpgsize)
 
 	s2255_fillbuff(vc, buf, jpgsize);
 	/* tell v4l buffer was filled */
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 	dprintk(dev, 2, "%s: [buf] [%p]\n", __func__, buf);
 }
 
@@ -1118,7 +1118,7 @@ static void stop_streaming(struct vb2_queue *vq)
 	spin_lock_irqsave(&vc->qlock, flags);
 	list_for_each_entry_safe(buf, node, &vc->buf_list, list) {
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		dprintk(vc->dev, 2, "[%p/%d] done\n",
 			buf, buf->vb.v4l2_buf.index);
 	}
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index b865ca6..bdb0690 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -552,7 +552,7 @@ static void buffer_queue(struct vb2_buffer *vb)
 		 * If the device is disconnected return the buffer to userspace
 		 * directly. The next QBUF call will fail with -ENODEV.
 		 */
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 	} else {
 
 		buf->mem = vb2_plane_vaddr(cb, 0);
@@ -565,7 +565,7 @@ static void buffer_queue(struct vb2_buffer *vb)
 		 * the buffer to userspace directly.
 		 */
 		if (buf->length < dev->width * dev->height * 2)
-			vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+			vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		else
 			list_add_tail(&buf->list, &dev->avail_bufs);
 
@@ -617,7 +617,7 @@ void stk1160_clear_queue(struct stk1160 *dev)
 		buf = list_first_entry(&dev->avail_bufs,
 			struct stk1160_buffer, list);
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		stk1160_info("buffer [%p/%d] aborted\n",
 				buf, buf->vb.v4l2_buf.index);
 	}
diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c
index 39f1aae..af7975b 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -104,7 +104,7 @@ void stk1160_buffer_done(struct stk1160 *dev)
 	v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
 
 	vb2_set_plane_payload(&buf->vb, 0, buf->bytesused);
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_DONE);
 
 	dev->isoc_ctl.buf = NULL;
 }
diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c
index 82d1dc0..ac9a34f 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -324,7 +324,7 @@ static void usbtv_image_chunk(struct usbtv *usbtv, __be32 *chunk)
 		buf->vb.v4l2_buf.sequence = usbtv->sequence++;
 		v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
 		vb2_set_plane_payload(&buf->vb, 0, size);
-		vb2_buffer_done(&buf->vb, state);
+		vb2_buffer_done(&buf->vb.vb2, state);
 		list_del(&buf->list);
 	}
 
@@ -422,7 +422,7 @@ static void usbtv_stop(struct usbtv *usbtv)
 	while (!list_empty(&usbtv->bufs)) {
 		struct usbtv_buf *buf = list_first_entry(&usbtv->bufs,
 						struct usbtv_buf, list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2, VB2_BUF_STATE_ERROR);
 		list_del(&buf->list);
 	}
 	spin_unlock_irqrestore(&usbtv->buflock, flags);
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index faa0105..a366fe1 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -60,7 +60,7 @@ static void uvc_queue_return_buffers(struct uvc_video_queue *queue,
 							  queue);
 		list_del(&buf->queue);
 		buf->state = state;
-		vb2_buffer_done(&buf->buf, vb2_state);
+		vb2_buffer_done(&buf->buf.vb2, vb2_state);
 	}
 }
 
@@ -130,7 +130,7 @@ static void uvc_buffer_queue(struct vb2_buffer *vb)
 		 * directly. The next QBUF call will fail with -ENODEV.
 		 */
 		buf->state = UVC_BUF_STATE_ERROR;
-		vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->buf.vb2, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&queue->irqlock, flags);
@@ -416,7 +416,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
 
 	buf->state = buf->error ? VB2_BUF_STATE_ERROR : UVC_BUF_STATE_DONE;
 	vb2_set_plane_payload(&buf->buf, 0, buf->bytesused);
-	vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->buf.vb2, VB2_BUF_STATE_DONE);
 
 	return nextbuf;
 }
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 5f75937..222aa65 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -28,8 +28,1936 @@
 #include <media/v4l2-fh.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-common.h>
-#include <media/videobuf2-v4l2.h>
+#include <media/videobuf2-core.h>
 
+static int vb2_debug;
+module_param(vb2_debug, int, 0644);
+
+int get_vb2_debug(void)
+{
+	return vb2_debug;
+}
+
+#define dprintk(level, fmt, arg...)					      \
+	do {								      \
+		if (get_vb2_debug() >= level)					      \
+			pr_info("vb2: %s: " fmt, __func__, ## arg); \
+	} while (0)
+
+#define call_priv_op(q, op, args...)				\
+({ \
+	int ret = 0;									\
+	if((q) && (q)->priv_ops && (q)->priv_ops->op)	\
+		ret = (q)->priv_ops->op(args);			\
+	ret;										\
+})
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+
+/*
+ * If advanced debugging is on, then count how often each op is called
+ * successfully, which can either be per-buffer or per-queue.
+ *
+ * This makes it easy to check that the 'init' and 'cleanup'
+ * (and variations thereof) stay balanced.
+ */
+
+#define log_memop(vb, op)						\
+	dprintk(2, "call_memop(%p, %d, %s)%s\n",			\
+		(vb)->vb2_queue, call_priv_op(vb->vb2_queue, get_buffer_index, vb), #op,	\
+		(vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
+
+#define call_memop(vb, op, args...)					\
+({									\
+	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	int err;							\
+									\
+	log_memop(vb, op);						\
+	err = _q->mem_ops->op ? _q->mem_ops->op(args) : 0;		\
+	if (!err)							\
+		(vb)->cnt_mem_ ## op++;					\
+	err;								\
+})
+
+#define call_ptr_memop(vb, op, args...)					\
+({									\
+	struct vb2_queue *_q = (vb)->vb2_queue;				\
+	void *ptr;							\
+									\
+	log_memop(vb, op);						\
+	ptr = _q->mem_ops->op ? _q->mem_ops->op(args) : NULL;		\
+	if (!IS_ERR_OR_NULL(ptr))					\
+		(vb)->cnt_mem_ ## op++;					\
+	ptr;								\
+})
+
+#define call_void_memop(vb, op, args...)				\
+({									\
+	struct vb2_queue *_q = (vb)->vb2_queue;				\
+									\
+	log_memop(vb, op);						\
+	if (_q->mem_ops->op)						\
+		_q->mem_ops->op(args);					\
+	(vb)->cnt_mem_ ## op++;						\
+})
+
+#define log_qop(q, op)							\
+	dprintk(2, "call_qop(%p, %s)%s\n", q, #op,			\
+		(q)->ops->op ? "" : " (nop)")
+
+#define call_qop(q, op, args...)					\
+({									\
+	int err;							\
+									\
+	log_qop(q, op);							\
+	err = (q)->ops->op ? (q)->ops->op(args) : 0;			\
+	if (!err)							\
+		(q)->cnt_ ## op++;					\
+	err;								\
+})
+
+#define call_void_qop(q, op, args...)					\
+({									\
+	log_qop(q, op);							\
+	if ((q)->ops->op)						\
+		(q)->ops->op(args);					\
+	(q)->cnt_ ## op++;						\
+})
+
+#define log_vb_qop(vb, op, args...)					\
+	dprintk(2, "call_vb_qop(%p, %d, %s)%s\n",			\
+		(vb)->vb2_queue, call_priv_op(vb->vb2_queue, get_buffer_index, vb), #op,	\
+		(vb)->vb2_queue->ops->op ? "" : " (nop)")
+
+#define call_vb_qop(vb, op, args...)					\
+({									\
+	int err;							\
+									\
+	log_vb_qop(vb, op);						\
+	err = (vb)->vb2_queue->ops->op ?				\
+		(vb)->vb2_queue->ops->op(args) : 0;			\
+	if (!err)							\
+		(vb)->cnt_ ## op++;					\
+	err;								\
+})
+
+#define call_void_vb_qop(vb, op, args...)				\
+({									\
+	log_vb_qop(vb, op);						\
+	if ((vb)->vb2_queue->ops->op)					\
+		(vb)->vb2_queue->ops->op(args);				\
+	(vb)->cnt_ ## op++;						\
+})
+
+#else
+
+#define call_memop(vb, op, args...)					\
+	((vb)->vb2_queue->mem_ops->op ?					\
+		(vb)->vb2_queue->mem_ops->op(args) : 0)
+
+#define call_ptr_memop(vb, op, args...)					\
+	((vb)->vb2_queue->mem_ops->op ?					\
+		(vb)->vb2_queue->mem_ops->op(args) : NULL)
+
+#define call_void_memop(vb, op, args...)				\
+	do {								\
+		if ((vb)->vb2_queue->mem_ops->op)			\
+			(vb)->vb2_queue->mem_ops->op(args);		\
+	} while (0)
+
+#define call_qop(q, op, args...)					\
+	((q)->ops->op ? (q)->ops->op(args) : 0)
+
+#define call_void_qop(q, op, args...)					\
+	do {								\
+		if ((q)->ops->op)					\
+			(q)->ops->op(args);				\
+	} while (0)
+
+#define call_vb_qop(vb, op, args...)					\
+	((vb)->vb2_queue->ops->op ? (vb)->vb2_queue->ops->op(args) : 0)
+
+#define call_void_vb_qop(vb, op, args...)				\
+	do {								\
+		if ((vb)->vb2_queue->ops->op)				\
+			(vb)->vb2_queue->ops->op(args);			\
+	} while (0)
+
+#endif
+
+
+void __vb2_queue_cancel(struct vb2_queue *q);
+
+/**
+ * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
+ */
+static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	enum dma_data_direction dma_dir =
+		MEDIA_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
+	void *mem_priv;
+	int plane;
+
+	/*
+	 * Allocate memory for all planes in this buffer
+	 * NOTE: mmapped areas should be page aligned
+	 */
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
+
+		mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
+				      size, dma_dir, q->gfp_flags);
+		if (IS_ERR_OR_NULL(mem_priv))
+			goto free;
+
+		/* Associate allocator private data with this plane */
+		vb->planes[plane].mem_priv = mem_priv;
+		call_priv_op(q, set_plane_length, vb, plane, q->plane_sizes[plane]);
+	}
+
+	return 0;
+free:
+	/* Free already allocated memory if one of the allocations failed */
+	for (; plane > 0; --plane) {
+		call_void_memop(vb, put, vb->planes[plane - 1].mem_priv);
+		vb->planes[plane - 1].mem_priv = NULL;
+	}
+
+	return -ENOMEM;
+}
+
+/**
+ * __vb2_buf_mem_free() - free memory of the given buffer
+ */
+static void __vb2_buf_mem_free(struct vb2_buffer *vb)
+{
+	unsigned int plane;
+
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		call_void_memop(vb, put, vb->planes[plane].mem_priv);
+		vb->planes[plane].mem_priv = NULL;
+		dprintk(3, "freed plane %d of buffer %d\n", plane,
+			call_priv_op(vb->vb2_queue, get_buffer_index, vb));
+	}
+}
+
+/**
+ * __vb2_buf_userptr_put() - release userspace memory associated with
+ * a USERPTR buffer
+ */
+static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
+{
+	unsigned int plane;
+
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		if (vb->planes[plane].mem_priv)
+			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
+		vb->planes[plane].mem_priv = NULL;
+	}
+}
+
+/**
+ * __vb2_plane_dmabuf_put() - release memory associated with
+ * a DMABUF shared plane
+ */
+void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
+{
+	if (!p->mem_priv)
+		return;
+
+	if (p->dbuf_mapped)
+		call_void_memop(vb, unmap_dmabuf, p->mem_priv);
+
+	call_void_memop(vb, detach_dmabuf, p->mem_priv);
+	dma_buf_put(p->dbuf);
+	memset(p, 0, sizeof(*p));
+}
+
+/**
+ * __vb2_buf_dmabuf_put() - release memory associated with
+ * a DMABUF shared buffer
+ */
+void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
+{
+	unsigned int plane;
+
+	for (plane = 0; plane < vb->num_planes; ++plane)
+		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
+}
+
+/**
+ * __setup_lengths() - setup initial lengths for every plane in
+ * every buffer on the queue
+ */
+static void __setup_lengths(struct vb2_queue *q, unsigned int n)
+{
+	unsigned int buffer, plane;
+	struct vb2_buffer *vb;
+
+	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
+		vb = q->bufs[buffer];
+		if (!vb)
+			continue;
+
+		for (plane = 0; plane < vb->num_planes; ++plane)
+			call_priv_op(q, set_plane_length, vb, plane, q->plane_sizes[plane]);
+	}
+}
+
+/**
+ * __vb2_queue_alloc() - allocate videobuf buffer structures and (for MMAP type)
+ * video buffer memory for all buffers/planes on the queue and initializes the
+ * queue
+ *
+ * Returns the number of buffers successfully allocated.
+ */
+static int __vb2_queue_alloc(struct vb2_queue *q, enum media_memory memory,
+			     unsigned int num_buffers, unsigned int num_planes)
+{
+	unsigned int buffer;
+	struct vb2_buffer *vb;
+	int ret;
+
+	for (buffer = 0; buffer < num_buffers; ++buffer) {
+		/* Allocate videobuf buffer structures */
+		vb = kzalloc(q->buf_struct_size, GFP_KERNEL);
+		if (!vb) {
+			dprintk(1, "memory alloc for buffer struct failed\n");
+			break;
+		}
+
+		vb->state = VB2_BUF_STATE_DEQUEUED;
+		vb->vb2_queue = q;
+		vb->num_planes = num_planes;
+		call_priv_op(q, init_priv_buffer, vb, q, buffer, memory, num_planes);
+
+		/* Allocate video buffer memory for the MMAP type */
+		if (memory == MEDIA_MEMORY_MMAP) {
+			ret = __vb2_buf_mem_alloc(vb);
+			if (ret) {
+				dprintk(1, "failed allocating memory for "
+						"buffer %d\n", buffer);
+				kfree(vb);
+				break;
+			}
+			/*
+			 * Call the driver-provided buffer initialization
+			 * callback, if given. An error in initialization
+			 * results in queue setup failure.
+			 */
+			ret = call_vb_qop(vb, buf_init, vb);
+			if (ret) {
+				dprintk(1, "buffer %d %p initialization"
+					" failed\n", buffer, vb);
+				__vb2_buf_mem_free(vb);
+				kfree(vb);
+				break;
+			}
+		}
+
+		q->bufs[q->num_buffers + buffer] = vb;
+	}
+
+	__setup_lengths(q, buffer);
+	if (memory == MEDIA_MEMORY_MMAP)
+		call_priv_op(q, setup_offsets, q, buffer);
+
+	dprintk(1, "allocated %d buffers, %d plane(s) each\n",
+			buffer, num_planes);
+
+	return buffer;
+}
+
+/**
+ * __vb2_free_mem() - release all video buffer memory for a given queue
+ */
+static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
+{
+	unsigned int buffer;
+	struct vb2_buffer *vb;
+
+	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
+	     ++buffer) {
+		vb = q->bufs[buffer];
+		if (!vb)
+			continue;
+
+		/* Free MMAP buffers or release USERPTR buffers */
+		if (q->memory == MEDIA_MEMORY_MMAP)
+			__vb2_buf_mem_free(vb);
+		else if (q->memory == MEDIA_MEMORY_DMABUF)
+			__vb2_buf_dmabuf_put(vb);
+		else
+			__vb2_buf_userptr_put(vb);
+	}
+}
+
+/**
+ * __vb2_queue_free() - free buffers at the end of the queue - video memory and
+ * related information, if no buffers are left return the queue to an
+ * uninitialized state. Might be called even if the queue has already been freed.
+ */
+int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
+{
+	unsigned int buffer;
+
+	/*
+	 * Sanity check: when preparing a buffer the queue lock is released for
+	 * a short while (see __buf_prepare for the details), which would allow
+	 * a race with a reqbufs which can call this function. Removing the
+	 * buffers from underneath __buf_prepare is obviously a bad idea, so we
+	 * check if any of the buffers is in the state PREPARING, and if so we
+	 * just return -EAGAIN.
+	 */
+	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
+	     ++buffer) {
+		if (q->bufs[buffer] == NULL)
+			continue;
+		if (q->bufs[buffer]->state == VB2_BUF_STATE_PREPARING) {
+			dprintk(1, "preparing buffers, cannot free\n");
+			return -EAGAIN;
+		}
+	}
+
+	/* Call driver-provided cleanup function for each buffer, if provided */
+	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
+	     ++buffer) {
+		struct vb2_buffer *vb = q->bufs[buffer];
+
+		if (vb && vb->planes[0].mem_priv)
+			call_void_vb_qop(vb, buf_cleanup, vb);
+	}
+
+	/* Release video buffer memory */
+	__vb2_free_mem(q, buffers);
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	/*
+	 * Check that all the calls were balances during the life-time of this
+	 * queue. If not (or if the debug level is 1 or up), then dump the
+	 * counters to the kernel log.
+	 */
+	if (q->num_buffers) {
+		bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming ||
+				  q->cnt_wait_prepare != q->cnt_wait_finish;
+
+		if (unbalanced || vb2_debug) {
+			pr_info("vb2: counters for queue %p:%s\n", q,
+				unbalanced ? " UNBALANCED!" : "");
+			pr_info("vb2:     setup: %u start_streaming: %u stop_streaming: %u\n",
+				q->cnt_queue_setup, q->cnt_start_streaming,
+				q->cnt_stop_streaming);
+			pr_info("vb2:     wait_prepare: %u wait_finish: %u\n",
+				q->cnt_wait_prepare, q->cnt_wait_finish);
+		}
+		q->cnt_queue_setup = 0;
+		q->cnt_wait_prepare = 0;
+		q->cnt_wait_finish = 0;
+		q->cnt_start_streaming = 0;
+		q->cnt_stop_streaming = 0;
+	}
+	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
+		struct vb2_buffer *vb = q->bufs[buffer];
+		bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put ||
+				  vb->cnt_mem_prepare != vb->cnt_mem_finish ||
+				  vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr ||
+				  vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf ||
+				  vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf ||
+				  vb->cnt_buf_queue != vb->cnt_buf_done ||
+				  vb->cnt_buf_prepare != vb->cnt_buf_finish ||
+				  vb->cnt_buf_init != vb->cnt_buf_cleanup;
+
+		if (unbalanced || vb2_debug) {
+			pr_info("vb2:   counters for queue %p, buffer %d:%s\n",
+				q, buffer, unbalanced ? " UNBALANCED!" : "");
+			pr_info("vb2:     buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n",
+				vb->cnt_buf_init, vb->cnt_buf_cleanup,
+				vb->cnt_buf_prepare, vb->cnt_buf_finish);
+			pr_info("vb2:     buf_queue: %u buf_done: %u\n",
+				vb->cnt_buf_queue, vb->cnt_buf_done);
+			pr_info("vb2:     alloc: %u put: %u prepare: %u finish: %u mmap: %u\n",
+				vb->cnt_mem_alloc, vb->cnt_mem_put,
+				vb->cnt_mem_prepare, vb->cnt_mem_finish,
+				vb->cnt_mem_mmap);
+			pr_info("vb2:     get_userptr: %u put_userptr: %u\n",
+				vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr);
+			pr_info("vb2:     attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n",
+				vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf,
+				vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf);
+			pr_info("vb2:     get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n",
+				vb->cnt_mem_get_dmabuf,
+				vb->cnt_mem_num_users,
+				vb->cnt_mem_vaddr,
+				vb->cnt_mem_cookie);
+		}
+	}
+#endif
+
+	/* Free videobuf buffers */
+	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
+	     ++buffer) {
+		kfree(q->bufs[buffer]);
+		q->bufs[buffer] = NULL;
+	}
+
+	q->num_buffers -= buffers;
+	if (!q->num_buffers) {
+		q->memory = 0;
+		INIT_LIST_HEAD(&q->queued_list);
+	}
+	return 0;
+}
+
+/**
+ * __buffer_in_use() - return true if the buffer is in use and
+ * the queue cannot be freed (by the means of REQBUFS(0)) call
+ */
+bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
+{
+	unsigned int plane;
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		void *mem_priv = vb->planes[plane].mem_priv;
+		/*
+		 * If num_users() has not been provided, call_memop
+		 * will return 0, apparently nobody cares about this
+		 * case anyway. If num_users() returns more than 1,
+		 * we are not the only user of the plane's memory.
+		 */
+		if (mem_priv && call_memop(vb, num_users, mem_priv) > 1)
+			return true;
+	}
+	return false;
+}
+
+/**
+ * __buffers_in_use() - return true if any buffers on the queue are in use and
+ * the queue cannot be freed (by the means of REQBUFS(0)) call
+ */
+static bool __buffers_in_use(struct vb2_queue *q)
+{
+	unsigned int buffer;
+	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
+		if (__buffer_in_use(q, q->bufs[buffer]))
+			return true;
+	}
+	return false;
+}
+
+/**
+ * vb2_core_querybuf() - query video buffer information
+ * @q:		videobuf queue
+ * @type:	enum media_buf_type; buffer type (type == *_MPLANE for
+ *		multiplanar buffers);
+ * @index:	id number of the buffer
+ * @pb:		private buffer struct passed from userspace to vidioc_querybuf handler
+ *		in driver
+ *
+ * Should be called from vidioc_querybuf ioctl handler in driver.
+ * This function will verify the passed v4l2_buffer structure and fill the
+ * relevant information for the userspace.
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_querybuf handler in driver.
+ */
+int vb2_core_querybuf(struct vb2_queue *q, unsigned int type,
+		unsigned int index, void *pb)
+{
+	struct vb2_buffer *vb;
+	int ret;
+
+	if (type != q->type) {
+		dprintk(1, "wrong buffer type\n");
+		return -EINVAL;
+	}
+
+	if (index >= q->num_buffers) {
+		dprintk(1, "buffer index out of range\n");
+		return -EINVAL;
+	}
+	vb = q->bufs[index];
+	ret = call_priv_op(q, verify_planes_array, vb, pb);
+	if (!ret)
+		ret = call_priv_op(q, fill_priv_buffer, vb, pb);
+	
+	return ret;
+}
+
+/**
+ * __verify_userptr_ops() - verify that all memory operations required for
+ * USERPTR queue type have been provided
+ */
+static int __verify_userptr_ops(struct vb2_queue *q)
+{
+	if (!(q->io_modes & VB2_USERPTR) || !q->mem_ops->get_userptr ||
+	    !q->mem_ops->put_userptr)
+		return -EINVAL;
+
+	return 0;
+}
+
+/**
+ * __verify_mmap_ops() - verify that all memory operations required for
+ * MMAP queue type have been provided
+ */
+static int __verify_mmap_ops(struct vb2_queue *q)
+{
+	if (!(q->io_modes & VB2_MMAP) || !q->mem_ops->alloc ||
+	    !q->mem_ops->put || !q->mem_ops->mmap)
+		return -EINVAL;
+
+	return 0;
+}
+
+/**
+ * __verify_dmabuf_ops() - verify that all memory operations required for
+ * DMABUF queue type have been provided
+ */
+static int __verify_dmabuf_ops(struct vb2_queue *q)
+{
+	if (!(q->io_modes & VB2_DMABUF) || !q->mem_ops->attach_dmabuf ||
+	    !q->mem_ops->detach_dmabuf  || !q->mem_ops->map_dmabuf ||
+	    !q->mem_ops->unmap_dmabuf)
+		return -EINVAL;
+
+	return 0;
+}
+
+/**
+ * __verify_memory_type() - Check whether the memory type and buffer type
+ * passed to a buffer operation are compatible with the queue.
+ */
+int __verify_memory_type(struct vb2_queue *q,
+		enum media_memory memory, enum media_buf_type type)
+{
+	if (memory != MEDIA_MEMORY_MMAP && memory != MEDIA_MEMORY_USERPTR &&
+	    memory != MEDIA_MEMORY_DMABUF) {
+		dprintk(1, "unsupported memory type\n");
+		return -EINVAL;
+	}
+
+	if (type != q->type) {
+		dprintk(1, "requested type is incorrect\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Make sure all the required memory ops for given memory type
+	 * are available.
+	 */
+	if (memory == MEDIA_MEMORY_MMAP && __verify_mmap_ops(q)) {
+		dprintk(1, "MMAP for current setup unsupported\n");
+		return -EINVAL;
+	}
+
+	if (memory == MEDIA_MEMORY_USERPTR && __verify_userptr_ops(q)) {
+		dprintk(1, "USERPTR for current setup unsupported\n");
+		return -EINVAL;
+	}
+
+	if (memory == MEDIA_MEMORY_DMABUF && __verify_dmabuf_ops(q)) {
+		dprintk(1, "DMABUF for current setup unsupported\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Place the busy tests at the end: -EBUSY can be ignored when
+	 * create_bufs is called with count == 0, but count == 0 should still
+	 * do the memory and type validation.
+	 */
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "file io in progress\n");
+		return -EBUSY;
+	}
+	return 0;
+}
+
+/**
+ * __reqbufs() - Initiate streaming
+ * @q:		videobuf2 queue
+ * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
+ *
+ * Should be called from vidioc_reqbufs ioctl handler of a driver.
+ * This function:
+ * 1) verifies streaming parameters passed from the userspace,
+ * 2) sets up the queue,
+ * 3) negotiates number of buffers and planes per buffer with the driver
+ *    to be used during streaming,
+ * 4) allocates internal buffer structures (struct vb2_buffer), according to
+ *    the agreed parameters,
+ * 5) for MMAP memory type, allocates actual video memory, using the
+ *    memory handling/allocation routines provided during queue initialization
+ *
+ * If req->count is 0, all the memory will be freed instead.
+ * If the queue has been allocated previously (by a previous vb2_reqbufs) call
+ * and the queue is not busy, memory will be reallocated.
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_reqbufs handler in driver.
+ */
+int __reqbufs(struct vb2_queue *q, unsigned int count,
+		unsigned int type, unsigned int memory)
+{
+	unsigned int num_buffers, allocated_buffers, num_planes = 0;
+	int ret;
+
+	if (q->streaming) {
+		dprintk(1, "streaming active\n");
+		return -EBUSY;
+	}
+
+	if (count == 0 || q->num_buffers != 0 || q->memory != memory) {
+		/*
+		 * We already have buffers allocated, so first check if they
+		 * are not in use and can be freed.
+		 */
+		mutex_lock(&q->mmap_lock);
+		if (q->memory == MEDIA_MEMORY_MMAP && __buffers_in_use(q)) {
+			mutex_unlock(&q->mmap_lock);
+			dprintk(1, "memory in use, cannot free\n");
+			return -EBUSY;
+		}
+
+		/*
+		 * Call queue_cancel to clean up any buffers in the PREPARED or
+		 * QUEUED state which is possible if buffers were prepared or
+		 * queued without ever calling STREAMON.
+		 */
+		__vb2_queue_cancel(q);
+		ret = __vb2_queue_free(q, q->num_buffers);
+		mutex_unlock(&q->mmap_lock);
+		if (ret)
+			return ret;
+
+		/*
+		 * In case of REQBUFS(0) return immediately without calling
+		 * driver's queue_setup() callback and allocating resources.
+		 */
+		if (count == 0)
+			return 0;
+	}
+
+	/*
+	 * Make sure the requested values and current defaults are sane.
+	 */
+	num_buffers = min_t(unsigned int, count, MEDIA_MAX_FRAME);
+	num_buffers = max_t(unsigned int, num_buffers, q->min_buffers_needed);
+	memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
+	memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
+	q->memory = memory;
+
+	/*
+	 * Ask the driver how many buffers and planes per buffer it requires.
+	 * Driver also sets the size and allocator context for each plane.
+	 */
+	ret = call_qop(q, queue_setup, q, NULL, &num_buffers, &num_planes,
+		       q->plane_sizes, q->alloc_ctx);
+	if (ret)
+		return ret;
+
+	/* Finally, allocate buffers and video memory */
+	allocated_buffers = __vb2_queue_alloc(q, memory, num_buffers, num_planes);
+	if (allocated_buffers == 0) {
+		dprintk(1, "memory allocation failed\n");
+		return -ENOMEM;
+	}
+
+	/*
+	 * There is no point in continuing if we can't allocate the minimum
+	 * number of buffers needed by this vb2_queue.
+	 */
+	if (allocated_buffers < q->min_buffers_needed)
+		ret = -ENOMEM;
+
+	/*
+	 * Check if driver can handle the allocated number of buffers.
+	 */
+	if (!ret && allocated_buffers < num_buffers) {
+		num_buffers = allocated_buffers;
+
+		ret = call_qop(q, queue_setup, q, NULL, &num_buffers,
+			       &num_planes, q->plane_sizes, q->alloc_ctx);
+
+		if (!ret && allocated_buffers < num_buffers)
+			ret = -ENOMEM;
+
+		/*
+		 * Either the driver has accepted a smaller number of buffers,
+		 * or .queue_setup() returned an error
+		 */
+	}
+
+	mutex_lock(&q->mmap_lock);
+	q->num_buffers = allocated_buffers;
+
+	if (ret < 0) {
+		/*
+		 * Note: __vb2_queue_free() will subtract 'allocated_buffers'
+		 * from q->num_buffers.
+		 */
+		__vb2_queue_free(q, allocated_buffers);
+		mutex_unlock(&q->mmap_lock);
+		return ret;
+	}
+	mutex_unlock(&q->mmap_lock);
+
+	q->waiting_for_buffers = !MEDIA_TYPE_IS_OUTPUT(q->type);
+
+	/*
+	 * Return the number of successfully allocated buffers
+	 * to the userspace.
+	 */
+	return allocated_buffers;
+}
+
+/**
+ * vb2_core_reqbufs() - Wrapper for __reqbufs() that also verifies the memory and
+ * type values.
+ * @q:		videobuf2 queue
+ * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
+ */
+int vb2_core_reqbufs(struct vb2_queue *q, unsigned int count, 
+		unsigned int type, unsigned int memory)
+{
+	int ret = __verify_memory_type(q, memory, type);
+	return ret ? ret : __reqbufs(q, count, type, memory);
+}
+
+/**
+ * __create_bufs() - Allocate buffers and any required auxiliary structs
+ * @q:		videobuf2 queue
+ * @create:	creation parameters, passed from userspace to vidioc_create_bufs
+ *		handler in driver
+ *
+ * Should be called from vidioc_create_bufs ioctl handler of a driver.
+ * This function:
+ * 1) verifies parameter sanity
+ * 2) calls the .queue_setup() queue operation
+ * 3) performs any necessary memory allocations
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_create_bufs handler in driver.
+ */
+int __create_bufs(struct vb2_queue *q,  unsigned int count,
+		unsigned int type, unsigned int memory, void *format)
+{
+	unsigned int num_planes = 0, num_buffers, allocated_buffers;
+	int ret;
+
+	if (q->num_buffers == MEDIA_MAX_FRAME) {
+		dprintk(1, "maximum number of buffers already allocated\n");
+		return -ENOBUFS;
+	}
+
+	if (!q->num_buffers) {
+		memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
+		memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
+		q->memory = memory;
+		q->waiting_for_buffers = !MEDIA_TYPE_IS_OUTPUT(q->type);
+	}
+
+	num_buffers = min(count, MEDIA_MAX_FRAME - q->num_buffers);
+
+	/*
+	 * Ask the driver, whether the requested number of buffers, planes per
+	 * buffer and their sizes are acceptable
+	 */
+	ret = call_qop(q, queue_setup, q, format, &num_buffers,
+		       &num_planes, q->plane_sizes, q->alloc_ctx);
+	if (ret)
+		return ret;
+
+	/* Finally, allocate buffers and video memory */
+	allocated_buffers = __vb2_queue_alloc(q, memory, num_buffers,
+				num_planes);
+	if (allocated_buffers == 0) {
+		dprintk(1, "memory allocation failed\n");
+		return -ENOMEM;
+	}
+
+	/*
+	 * Check if driver can handle the so far allocated number of buffers.
+	 */
+	if (allocated_buffers < num_buffers) {
+		num_buffers = allocated_buffers;
+
+		/*
+		 * q->num_buffers contains the total number of buffers, that the
+		 * queue driver has set up
+		 */
+		ret = call_qop(q, queue_setup, q, format, &num_buffers,
+			       &num_planes, q->plane_sizes, q->alloc_ctx);
+
+		if (!ret && allocated_buffers < num_buffers)
+			ret = -ENOMEM;
+
+		/*
+		 * Either the driver has accepted a smaller number of buffers,
+		 * or .queue_setup() returned an error
+		 */
+	}
+
+	mutex_lock(&q->mmap_lock);
+	q->num_buffers += allocated_buffers;
+
+	if (ret < 0) {
+		/*
+		 * Note: __vb2_queue_free() will subtract 'allocated_buffers'
+		 * from q->num_buffers.
+		 */
+		__vb2_queue_free(q, allocated_buffers);
+		mutex_unlock(&q->mmap_lock);
+		return -ENOMEM;
+	}
+	mutex_unlock(&q->mmap_lock);
+
+	/*
+	 * Return the number of successfully allocated buffers
+	 * to the userspace.
+	 */
+	return allocated_buffers;
+}
+
+/**
+ * vb2_create_bufs() - Wrapper for __create_bufs() that also verifies the
+ * memory and type values.
+ * @q:		videobuf2 queue
+ * @create:	creation parameters, passed from userspace to vidioc_create_bufs
+ *		handler in driver
+ */
+int vb2_core_create_bufs(struct vb2_queue *q, unsigned int count,
+		unsigned int type, unsigned int memory, void *format)
+{
+	int ret = __verify_memory_type(q, memory, type);
+	if (count == 0)
+		return ret != -EBUSY ? ret : 0;
+	return ret ? ret : __create_bufs(q, count, type, memory, format);
+}
+
+/**
+ * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished
+ * @vb:		vb2_buffer returned from the driver
+ * @state:	either VB2_BUF_STATE_DONE if the operation finished successfully
+ *		or VB2_BUF_STATE_ERROR if the operation finished with an error.
+ *		If start_streaming fails then it should return buffers with state
+ *		VB2_BUF_STATE_QUEUED to put them back into the queue.
+ *
+ * This function should be called by the driver after a hardware operation on
+ * a buffer is finished and the buffer may be returned to userspace. The driver
+ * cannot use this buffer anymore until it is queued back to it by videobuf
+ * by the means of buf_queue callback. Only buffers previously queued to the
+ * driver by buf_queue can be passed to this function.
+ *
+ * While streaming a buffer can only be returned in state DONE or ERROR.
+ * The start_streaming op can also return them in case the DMA engine cannot
+ * be started for some reason. In that case the buffers should be returned with
+ * state QUEUED.
+ */
+void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	unsigned long flags;
+	unsigned int plane;
+
+	if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
+		return;
+
+	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
+		    state != VB2_BUF_STATE_ERROR &&
+		    state != VB2_BUF_STATE_QUEUED))
+		state = VB2_BUF_STATE_ERROR;
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	/*
+	 * Although this is not a callback, it still does have to balance
+	 * with the buf_queue op. So update this counter manually.
+	 */
+	vb->cnt_buf_done++;
+#endif
+	dprintk(4, "done processing on buffer %d, state: %d\n",
+			call_priv_op(q, get_buffer_index, vb), state);
+
+	/* sync buffers */
+	for (plane = 0; plane < vb->num_planes; ++plane)
+		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
+
+	/* Add the buffer to the done buffers list */
+	spin_lock_irqsave(&q->done_lock, flags);
+	vb->state = state;
+	if (state != VB2_BUF_STATE_QUEUED)
+		list_add_tail(&vb->done_entry, &q->done_list);
+	atomic_dec(&q->owned_by_drv_count);
+	spin_unlock_irqrestore(&q->done_lock, flags);
+
+	if (state == VB2_BUF_STATE_QUEUED)
+		return;
+
+	/* Inform any processes that may be waiting for buffers */
+	wake_up(&q->done_wq);
+}
+EXPORT_SYMBOL_GPL(vb2_buffer_done);
+
+/**
+ * vb2_discard_done() - discard all buffers marked as DONE
+ * @q:		videobuf2 queue
+ *
+ * This function is intended to be used with suspend/resume operations. It
+ * discards all 'done' buffers as they would be too old to be requested after
+ * resume.
+ *
+ * Drivers must stop the hardware and synchronize with interrupt handlers and/or
+ * delayed works before calling this function to make sure no buffer will be
+ * touched by the driver and/or hardware.
+ */
+void vb2_discard_done(struct vb2_queue *q)
+{
+	struct vb2_buffer *vb;
+	unsigned long flags;
+
+	spin_lock_irqsave(&q->done_lock, flags);
+	list_for_each_entry(vb, &q->done_list, done_entry)
+		vb->state = VB2_BUF_STATE_ERROR;
+	spin_unlock_irqrestore(&q->done_lock, flags);
+}
+EXPORT_SYMBOL_GPL(vb2_discard_done);
+
+
+/**
+ * __enqueue_in_driver() - enqueue a vb2_buffer in driver for processing
+ */
+static void __enqueue_in_driver(struct vb2_buffer *vb)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	unsigned int plane;
+
+	vb->state = VB2_BUF_STATE_ACTIVE;
+	atomic_inc(&q->owned_by_drv_count);
+
+	/* sync buffers */
+	for (plane = 0; plane < vb->num_planes; ++plane)
+		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
+
+	call_void_vb_qop(vb, buf_queue, vb);
+}
+
+static int __buf_prepare(struct vb2_buffer *vb, void *pb)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	int ret;
+
+	ret = call_priv_op(q, verify_length, vb, pb);
+	if (ret < 0) {
+		dprintk(1, "plane parameters verification failed: %d\n", ret);
+		return ret;
+	}
+	if (call_priv_op(q, is_alternate, pb) && MEDIA_TYPE_IS_OUTPUT(q->type)) {
+		/*
+		 * If the format's field is ALTERNATE, then the buffer's field
+		 * should be either TOP or BOTTOM, not ALTERNATE since that
+		 * makes no sense. The driver has to know whether the
+		 * buffer represents a top or a bottom field in order to
+		 * program any DMA correctly. Using ALTERNATE is wrong, since
+		 * that just says that it is either a top or a bottom field,
+		 * but not which of the two it is.
+		 */
+		dprintk(1, "the field is incorrectly set to ALTERNATE for an output buffer\n");
+		return -EINVAL;
+	}
+
+	if (q->error) {
+		dprintk(1, "fatal error occurred on queue\n");
+		return -EIO;
+	}
+
+	vb->state = VB2_BUF_STATE_PREPARING;
+	call_priv_op(q, init_timestamp, vb);
+
+	switch (q->memory) {
+	case V4L2_MEMORY_MMAP:
+		ret = call_priv_op(q, qbuf_mmap, vb, pb);
+		break;
+	case V4L2_MEMORY_USERPTR:
+		down_read(&current->mm->mmap_sem);
+		ret = call_priv_op(q, qbuf_userptr, vb, pb);
+		up_read(&current->mm->mmap_sem);
+		break;
+	case V4L2_MEMORY_DMABUF:
+		ret = call_priv_op(q, qbuf_dmabuf, vb, pb);
+		break;
+	default:
+		WARN(1, "Invalid queue type\n");
+		ret = -EINVAL;
+	}
+
+	if (ret)
+		dprintk(1, "buffer preparation failed: %d\n", ret);
+	vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
+
+	return ret;
+}
+
+static int vb2_queue_or_prepare_buf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, unsigned int memory, void *pb, const char *opname)
+{
+	int ret;
+
+	if (type != q->type) {
+		dprintk(1, "%s: invalid buffer type\n", opname);
+		return -EINVAL;
+	}
+
+	if (index >= q->num_buffers) {
+		dprintk(1, "%s: buffer index out of range\n", opname);
+		return -EINVAL;
+	}
+
+	if (q->bufs[index] == NULL) {
+		/* Should never happen */
+		dprintk(1, "%s: buffer is NULL\n", opname);
+		return -EINVAL;
+	}
+
+	if (memory != q->memory) {
+		dprintk(1, "%s: invalid memory type\n", opname);
+		return -EINVAL;
+	}
+
+	ret = call_priv_op(q, verify_planes_array, q->bufs[index], pb);
+	return ret;
+}
+
+/**
+ * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace to the kernel
+ * @q:		videobuf2 queue
+ * @b:		buffer structure passed from userspace to vidioc_prepare_buf
+ *		handler in driver
+ *
+ * Should be called from vidioc_prepare_buf ioctl handler of a driver.
+ * This function:
+ * 1) verifies the passed buffer,
+ * 2) calls buf_prepare callback in the driver (if provided), in which
+ *    driver-specific buffer initialization can be performed,
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_prepare_buf handler in driver.
+ */
+int vb2_core_prepare_buf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, unsigned int memory, void *pb)
+{
+	struct vb2_buffer *vb;
+	int ret;
+
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "file io in progress\n");
+		return -EBUSY;
+	}
+
+	ret = vb2_queue_or_prepare_buf(q, type, index, memory, pb, "prepare_buf");
+	if (ret)
+		return ret;
+
+	vb = q->bufs[index];
+	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
+		dprintk(1, "invalid buffer state %d\n",
+			vb->state);
+		return -EINVAL;
+	}
+
+	ret = __buf_prepare(vb, pb);
+	if (!ret) {
+		/* Fill buffer information for the userspace */
+		call_priv_op(q, fill_priv_buffer, vb, pb);
+
+		dprintk(1, "prepare of buffer %d succeeded\n",
+				call_priv_op(q, get_buffer_index, vb));
+	}
+	return ret;
+}
+
+/**
+ * vb2_start_streaming() - Attempt to start streaming.
+ * @q:		videobuf2 queue
+ *
+ * Attempt to start streaming. When this function is called there must be
+ * at least q->min_buffers_needed buffers queued up (i.e. the minimum
+ * number of buffers required for the DMA engine to function). If the
+ * @start_streaming op fails it is supposed to return all the driver-owned
+ * buffers back to vb2 in state QUEUED. Check if that happened and if
+ * not warn and reclaim them forcefully.
+ */
+static int vb2_start_streaming(struct vb2_queue *q)
+{
+	struct vb2_buffer *vb;
+	int ret;
+
+	/*
+	 * If any buffers were queued before streamon,
+	 * we can now pass them to driver for processing.
+	 */
+	list_for_each_entry(vb, &q->queued_list, queued_entry)
+		__enqueue_in_driver(vb);
+
+	/* Tell the driver to start streaming */
+	q->start_streaming_called = 1;
+	ret = call_qop(q, start_streaming, q,
+		       atomic_read(&q->owned_by_drv_count));
+	if (!ret)
+		return 0;
+
+	q->start_streaming_called = 0;
+
+	dprintk(1, "driver refused to start streaming\n");
+	/*
+	 * If you see this warning, then the driver isn't cleaning up properly
+	 * after a failed start_streaming(). See the start_streaming()
+	 * documentation in videobuf2-core.h for more information how buffers
+	 * should be returned to vb2 in start_streaming().
+	 */
+	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
+		unsigned i;
+
+		/*
+		 * Forcefully reclaim buffers if the driver did not
+		 * correctly return them to vb2.
+		 */
+		for (i = 0; i < q->num_buffers; ++i) {
+			vb = q->bufs[i];
+			if (vb->state == VB2_BUF_STATE_ACTIVE)
+				vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED);
+		}
+		/* Must be zero now */
+		WARN_ON(atomic_read(&q->owned_by_drv_count));
+	}
+	/*
+	 * If done_list is not empty, then start_streaming() didn't call
+	 * vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED) but STATE_ERROR or
+	 * STATE_DONE.
+	 */
+	WARN_ON(!list_empty(&q->done_list));
+	return ret;
+}
+
+int vb2_internal_qbuf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, unsigned int memory, void *pb)
+{
+	int ret = vb2_queue_or_prepare_buf(q, type, index, memory, pb, "qbuf");
+	struct vb2_buffer *vb;
+
+	if (ret)
+		return ret;
+
+	vb = q->bufs[index];
+
+	switch (vb->state) {
+	case VB2_BUF_STATE_DEQUEUED:
+		ret = __buf_prepare(vb, pb);
+		if (ret)
+			return ret;
+		break;
+	case VB2_BUF_STATE_PREPARED:
+		break;
+	case VB2_BUF_STATE_PREPARING:
+		dprintk(1, "buffer still being prepared\n");
+		return -EINVAL;
+	default:
+		dprintk(1, "invalid buffer state %d\n", vb->state);
+		return -EINVAL;
+	}
+
+	/*
+	 * Add to the queued buffers list, a buffer will stay on it until
+	 * dequeued in dqbuf.
+	 */
+	list_add_tail(&vb->queued_entry, &q->queued_list);
+	q->queued_count++;
+	q->waiting_for_buffers = false;
+	vb->state = VB2_BUF_STATE_QUEUED;
+	if (MEDIA_TYPE_IS_OUTPUT(q->type)) {
+		/*
+		 * For output buffers copy the timestamp if needed,
+		 * and the timecode field and flag if needed.
+		 */
+		call_priv_op(q, set_timestamp, vb, pb);
+	}
+
+	/*
+	 * If already streaming, give the buffer to driver for processing.
+	 * If not, the buffer will be given to driver on next streamon.
+	 */
+	if (q->start_streaming_called)
+		__enqueue_in_driver(vb);
+
+	/* Fill buffer information for the userspace */
+	call_priv_op(q, fill_priv_buffer, vb, pb);
+
+	/*
+	 * If streamon has been called, and we haven't yet called
+	 * start_streaming() since not enough buffers were queued, and
+	 * we now have reached the minimum number of queued buffers,
+	 * then we can finally call start_streaming().
+	 */
+	if (q->streaming && !q->start_streaming_called &&
+	    q->queued_count >= q->min_buffers_needed) {
+		ret = vb2_start_streaming(q);
+		if (ret)
+			return ret;
+	}
+
+	dprintk(1, "qbuf of buffer %d succeeded\n", call_priv_op(q, get_buffer_index, vb));
+	return 0;
+}
+
+/**
+ * vb2_core_qbuf() - Queue a buffer from userspace
+ * @q:		videobuf2 queue
+ * @b:		buffer structure passed from userspace to vidioc_qbuf handler
+ *		in driver
+ *
+ * Should be called from vidioc_qbuf ioctl handler of a driver.
+ * This function:
+ * 1) verifies the passed buffer,
+ * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
+ *    which driver-specific buffer initialization can be performed,
+ * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
+ *    callback for processing.
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_qbuf handler in driver.
+ */
+int vb2_core_qbuf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, unsigned int memory, void *pb)
+{
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "file io in progress\n");
+		return -EBUSY;
+	}
+
+	return vb2_internal_qbuf(q, type, index, memory, pb);
+}
+
+/**
+ * __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)
+{
+	/*
+	 * All operations on vb_done_list are performed under done_lock
+	 * spinlock protection. However, buffers may be removed from
+	 * it and returned to userspace only while holding both driver's
+	 * lock and the done_lock spinlock. Thus we can be sure that as
+	 * long as we hold the driver's lock, the list will remain not
+	 * empty if list_empty() check succeeds.
+	 */
+
+	for (;;) {
+		int ret;
+
+		if (!q->streaming) {
+			dprintk(1, "streaming off, will not wait for buffers\n");
+			return -EINVAL;
+		}
+
+		if (q->error) {
+			dprintk(1, "Queue in error state, will not wait for buffers\n");
+			return -EIO;
+		}
+
+		if (!list_empty(&q->done_list)) {
+			/*
+			 * Found a buffer that we were waiting for.
+			 */
+			break;
+		}
+
+		if (nonblocking) {
+			dprintk(1, "nonblocking and no buffers to dequeue, "
+								"will not wait\n");
+			return -EAGAIN;
+		}
+
+		/*
+		 * We are streaming and blocking, wait for another buffer to
+		 * become ready or for streamoff. Driver's lock is released to
+		 * allow streamoff or qbuf to be called while waiting.
+		 */
+		call_void_qop(q, wait_prepare, q);
+
+		/*
+		 * All locks have been released, it is safe to sleep now.
+		 */
+		dprintk(3, "will sleep waiting for buffers\n");
+		ret = wait_event_interruptible(q->done_wq,
+				!list_empty(&q->done_list) || !q->streaming ||
+				q->error);
+
+		/*
+		 * We need to reevaluate both conditions again after reacquiring
+		 * the locks or return an error if one occurred.
+		 */
+		call_void_qop(q, wait_finish, q);
+		if (ret) {
+			dprintk(1, "sleep was interrupted\n");
+			return ret;
+		}
+	}
+	return 0;
+}
+
+/**
+ * __vb2_get_done_vb() - get a buffer ready for dequeuing
+ *
+ * Will sleep if required for nonblocking == false.
+ */
+static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
+				void *pb, int nonblocking)
+{
+	unsigned long flags;
+	int ret;
+
+	/*
+	 * Wait for at least one buffer to become available on the done_list.
+	 */
+	ret = __vb2_wait_for_done_vb(q, nonblocking);
+	if (ret)
+		return ret;
+
+	/*
+	 * Driver's lock has been held since we last verified that done_list
+	 * is not empty, so no need for another list_empty(done_list) check.
+	 */
+	spin_lock_irqsave(&q->done_lock, flags);
+	*vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
+	/*
+	 * Only remove the buffer from done_list if v4l2_buffer can handle all
+	 * the planes.
+	 */
+	call_priv_op(q, verify_planes_array, *vb, pb);
+	if (!ret)
+		list_del(&(*vb)->done_entry);
+	spin_unlock_irqrestore(&q->done_lock, flags);
+
+	return ret;
+}
+
+/**
+ * vb2_wait_for_all_buffers() - wait until all buffers are given back to vb2
+ * @q:		videobuf2 queue
+ *
+ * This function will wait until all buffers that have been given to the driver
+ * by buf_queue() are given back to vb2 with vb2_buffer_done(). It doesn't call
+ * wait_prepare, wait_finish pair. It is intended to be called with all locks
+ * taken, for example from stop_streaming() callback.
+ */
+int vb2_wait_for_all_buffers(struct vb2_queue *q)
+{
+	if (!q->streaming) {
+		dprintk(1, "streaming off, will not wait for buffers\n");
+		return -EINVAL;
+	}
+
+	if (q->start_streaming_called)
+		wait_event(q->done_wq, !atomic_read(&q->owned_by_drv_count));
+	return 0;
+}
+EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
+
+/**
+ * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
+ */
+static void __vb2_dqbuf(struct vb2_buffer *vb)
+{
+	struct vb2_queue *q = vb->vb2_queue;
+	unsigned int i;
+
+	/* nothing to do if the buffer is already dequeued */
+	if (vb->state == VB2_BUF_STATE_DEQUEUED)
+		return;
+
+	vb->state = VB2_BUF_STATE_DEQUEUED;
+
+	/* unmap DMABUF buffer */
+	if (q->memory == MEDIA_MEMORY_DMABUF)
+		for (i = 0; i < vb->num_planes; ++i) {
+			if (!vb->planes[i].dbuf_mapped)
+				continue;
+			call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
+			vb->planes[i].dbuf_mapped = 0;
+		}
+}
+
+int vb2_internal_dqbuf(struct vb2_queue *q, enum media_buf_type type, void *pb,
+		bool nonblocking)
+{
+	struct vb2_buffer *vb = NULL;
+	int ret;
+
+	if (type != q->type) {
+		dprintk(1, "invalid buffer type\n");
+		return -EINVAL;
+	}
+	ret = __vb2_get_done_vb(q, &vb, pb, nonblocking);
+	if (ret < 0)
+		return ret;
+
+	switch (vb->state) {
+	case VB2_BUF_STATE_DONE:
+		dprintk(3, "returning done buffer\n");
+		break;
+	case VB2_BUF_STATE_ERROR:
+		dprintk(3, "returning done buffer with errors\n");
+		break;
+	default:
+		dprintk(1, "invalid buffer state\n");
+		return -EINVAL;
+	}
+
+	call_void_vb_qop(vb, buf_finish, vb);
+
+	/* Fill buffer information for the userspace */
+	call_priv_op(q, fill_priv_buffer, vb, pb);
+	/* Remove from videobuf queue */
+	list_del(&vb->queued_entry);
+	q->queued_count--;
+	/* go back to dequeued state */
+	__vb2_dqbuf(vb);
+
+	dprintk(1, "dqbuf of buffer %d, with state %d\n",
+			call_priv_op(q, get_buffer_index, vb), vb->state);
+
+	return 0;
+}
+
+/**
+ * vb2_dqbuf() - Dequeue a buffer to the userspace
+ * @q:		videobuf2 queue
+ * @b:		buffer structure passed from userspace to vidioc_dqbuf handler
+ *		in driver
+ * @nonblocking: if true, this call will not sleep waiting for a buffer if no
+ *		 buffers ready for dequeuing are present. Normally the driver
+ *		 would be passing (file->f_flags & O_NONBLOCK) here
+ *
+ * Should be called from vidioc_dqbuf ioctl handler of a driver.
+ * This function:
+ * 1) verifies the passed buffer,
+ * 2) calls buf_finish callback in the driver (if provided), in which
+ *    driver can perform any additional operations that may be required before
+ *    returning the buffer to userspace, such as cache sync,
+ * 3) the buffer struct members are filled with relevant information for
+ *    the userspace.
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_dqbuf handler in driver.
+ */
+int vb2_core_dqbuf(struct vb2_queue *q, enum media_buf_type type, void *pb,
+		bool nonblocking)
+{
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "file io in progress\n");
+		return -EBUSY;
+	}
+	return vb2_internal_dqbuf(q, type, pb, nonblocking);
+}
+
+/**
+ * __vb2_queue_cancel() - cancel and stop (pause) streaming
+ *
+ * Removes all queued buffers from driver's queue and all buffers queued by
+ * userspace from videobuf's queue. Returns to state after reqbufs.
+ */
+void __vb2_queue_cancel(struct vb2_queue *q)
+{
+	unsigned int i;
+
+	/*
+	 * Tell driver to stop all transactions and release all queued
+	 * buffers.
+	 */
+	if (q->start_streaming_called)
+		call_void_qop(q, stop_streaming, q);
+
+	/*
+	 * If you see this warning, then the driver isn't cleaning up properly
+	 * in stop_streaming(). See the stop_streaming() documentation in
+	 * videobuf2-core.h for more information how buffers should be returned
+	 * to vb2 in stop_streaming().
+	 */
+	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
+		for (i = 0; i < q->num_buffers; ++i)
+			if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE)
+				vb2_buffer_done(q->bufs[i], VB2_BUF_STATE_ERROR);
+		/* Must be zero now */
+		WARN_ON(atomic_read(&q->owned_by_drv_count));
+	}
+
+	q->streaming = 0;
+	q->start_streaming_called = 0;
+	q->queued_count = 0;
+	q->error = 0;
+
+	/*
+	 * Remove all buffers from videobuf's list...
+	 */
+	INIT_LIST_HEAD(&q->queued_list);
+	/*
+	 * ...and done list; userspace will not receive any buffers it
+	 * has not already dequeued before initiating cancel.
+	 */
+	INIT_LIST_HEAD(&q->done_list);
+	atomic_set(&q->owned_by_drv_count, 0);
+	wake_up_all(&q->done_wq);
+
+	/*
+	 * Reinitialize all buffers for next use.
+	 * Make sure to call buf_finish for any queued buffers. Normally
+	 * that's done in dqbuf, but that's not going to happen when we
+	 * cancel the whole queue. Note: this code belongs here, not in
+	 * __vb2_dqbuf() since in vb2_internal_dqbuf() there is a critical
+	 * call to __fill_v4l2_buffer() after buf_finish(). That order can't
+	 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
+	 */
+	for (i = 0; i < q->num_buffers; ++i) {
+		struct vb2_buffer *vb = q->bufs[i];
+
+		if (vb->state != VB2_BUF_STATE_DEQUEUED) {
+			vb->state = VB2_BUF_STATE_PREPARED;
+			call_void_vb_qop(vb, buf_finish, vb);
+		}
+		__vb2_dqbuf(vb);
+	}
+}
+
+int vb2_internal_streamon(struct vb2_queue *q, enum media_buf_type type)
+{
+	int ret;
+
+	if (type != q->type) {
+		dprintk(1, "invalid stream type\n");
+		return -EINVAL;
+	}
+
+	if (q->streaming) {
+		dprintk(3, "already streaming\n");
+		return 0;
+	}
+
+	if (!q->num_buffers) {
+		dprintk(1, "no buffers have been allocated\n");
+		return -EINVAL;
+	}
+
+	if (q->num_buffers < q->min_buffers_needed) {
+		dprintk(1, "need at least %u allocated buffers\n",
+				q->min_buffers_needed);
+		return -EINVAL;
+	}
+
+	/*
+	 * Tell driver to start streaming provided sufficient buffers
+	 * are available.
+	 */
+	if (q->queued_count >= q->min_buffers_needed) {
+		ret = vb2_start_streaming(q);
+		if (ret) {
+			__vb2_queue_cancel(q);
+			return ret;
+		}
+	}
+
+	q->streaming = 1;
+
+	dprintk(3, "successful\n");
+	return 0;
+}
+
+/**
+ * vb2_queue_error() - signal a fatal error on the queue
+ * @q:		videobuf2 queue
+ *
+ * Flag that a fatal unrecoverable error has occurred and wake up all processes
+ * waiting on the queue. Polling will now set POLLERR and queuing and dequeuing
+ * buffers will return -EIO.
+ *
+ * The error flag will be cleared when cancelling the queue, either from
+ * vb2_streamoff or vb2_queue_release. Drivers should thus not call this
+ * function before starting the stream, otherwise the error flag will remain set
+ * until the queue is released when closing the device node.
+ */
+void vb2_queue_error(struct vb2_queue *q)
+{
+	q->error = 1;
+
+	wake_up_all(&q->done_wq);
+}
+EXPORT_SYMBOL_GPL(vb2_queue_error);
+
+/**
+ * vb2_core_streamon - start streaming
+ * @q:		videobuf2 queue
+ * @type:	type argument passed from userspace to vidioc_streamon handler
+ *
+ * Should be called from vidioc_streamon handler of a driver.
+ * This function:
+ * 1) verifies current state
+ * 2) passes any previously queued buffers to the driver and starts streaming
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_streamon handler in the driver.
+ */
+int vb2_core_streamon(struct vb2_queue *q, enum media_buf_type type)
+{
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "file io in progress\n");
+		return -EBUSY;
+	}
+	return vb2_internal_streamon(q, type);
+}
+
+int vb2_internal_streamoff(struct vb2_queue *q, enum media_buf_type type)
+{
+	if (type != q->type) {
+		dprintk(1, "invalid stream type\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Cancel will pause streaming and remove all buffers from the driver
+	 * and videobuf, effectively returning control over them to userspace.
+	 *
+	 * Note that we do this even if q->streaming == 0: if you prepare or
+	 * queue buffers, and then call streamoff without ever having called
+	 * streamon, you would still expect those buffers to be returned to
+	 * their normal dequeued state.
+	 */
+	__vb2_queue_cancel(q);
+	q->waiting_for_buffers = !MEDIA_TYPE_IS_OUTPUT(q->type);
+
+	dprintk(3, "successful\n");
+	return 0;
+}
+
+/**
+ * vb2_streamoff - stop streaming
+ * @q:		videobuf2 queue
+ * @type:	type argument passed from userspace to vidioc_streamoff handler
+ *
+ * Should be called from vidioc_streamoff handler of a driver.
+ * This function:
+ * 1) verifies current state,
+ * 2) stop streaming and dequeues any queued buffers, including those previously
+ *    passed to the driver (after waiting for the driver to finish).
+ *
+ * This call can be used for pausing playback.
+ * The return values from this function are intended to be directly returned
+ * from vidioc_streamoff handler in the driver
+ */
+int vb2_core_streamoff(struct vb2_queue *q, enum media_buf_type type)
+{
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "file io in progress\n");
+		return -EBUSY;
+	}
+	return vb2_internal_streamoff(q, type);
+}
+
+/**
+ * vb2_core_expbuf() - Export a buffer as a file descriptor
+ * @q:		videobuf2 queue
+ * @eb:		export buffer structure passed from userspace to vidioc_expbuf
+ *		handler in driver
+ *
+ * The return values from this function are intended to be directly returned
+ * from vidioc_expbuf handler in driver.
+ */
+int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
+		unsigned int plane, unsigned int flags)
+{
+	struct vb2_buffer *vb = NULL;
+	struct vb2_plane *vb_plane;
+	int ret;
+	struct dma_buf *dbuf;
+
+	if (q->memory != MEDIA_MEMORY_MMAP) {
+		dprintk(1, "queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	if (!q->mem_ops->get_dmabuf) {
+		dprintk(1, "queue does not support DMA buffer exporting\n");
+		return -EINVAL;
+	}
+
+	if (flags & ~(O_CLOEXEC | O_ACCMODE)) {
+		dprintk(1, "queue does support only O_CLOEXEC and access mode flags\n");
+		return -EINVAL;
+	}
+
+	if (type != q->type) {
+		dprintk(1, "invalid buffer type\n");
+		return -EINVAL;
+	}
+
+	if (index >= q->num_buffers) {
+		dprintk(1, "buffer index out of range\n");
+		return -EINVAL;
+	}
+
+	vb = q->bufs[index];
+
+	if (plane >= vb->num_planes) {
+		dprintk(1, "buffer plane out of range\n");
+		return -EINVAL;
+	}
+
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "expbuf: file io in progress\n");
+		return -EBUSY;
+	}
+
+	vb_plane = &vb->planes[plane];
+
+	dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, flags & O_ACCMODE);
+	if (IS_ERR_OR_NULL(dbuf)) {
+		dprintk(1, "failed to export buffer %d, plane %d\n", index, plane);
+		return -EINVAL;
+	}
+
+	ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
+	if (ret < 0) {
+		dprintk(3, "buffer %d, plane %d failed to export (%d)\n",
+			index, plane, ret);
+		dma_buf_put(dbuf);
+		return ret;
+	}
+
+	dprintk(3, "buffer %d, plane %d exported as %d descriptor\n",
+		index, plane, ret);
+
+	return ret;
+}
+
+/**
+ * vb2_mmap() - map video buffers into application address space
+ * @q:		videobuf2 queue
+ * @vma:	vma passed to the mmap file operation handler in the driver
+ *
+ * Should be called from mmap file operation handler of a driver.
+ * This function maps one plane of one of the available video buffers to
+ * userspace. To map whole video memory allocated on reqbufs, this function
+ * has to be called once per each plane per each buffer previously allocated.
+ *
+ * When the userspace application calls mmap, it passes to it an offset returned
+ * to it earlier by the means of vidioc_querybuf handler. That offset acts as
+ * a "cookie", which is then used to identify the plane to be mapped.
+ * This function finds a plane with a matching offset and a mapping is performed
+ * by the means of a provided memory operation.
+ *
+ * The return values from this function are intended to be directly returned
+ * from the mmap handler in driver.
+ */
+int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
+{
+	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
+	struct vb2_buffer *vb;
+	unsigned int buffer = 0, plane = 0;
+	int ret;
+	unsigned long length;
+
+	if (q->memory != MEDIA_MEMORY_MMAP) {
+		dprintk(1, "queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Check memory area access mode.
+	 */
+	if (!(vma->vm_flags & VM_SHARED)) {
+		dprintk(1, "invalid vma flags, VM_SHARED needed\n");
+		return -EINVAL;
+	}
+	if (MEDIA_TYPE_IS_OUTPUT(q->type)) {
+		if (!(vma->vm_flags & VM_WRITE)) {
+			dprintk(1, "invalid vma flags, VM_WRITE needed\n");
+			return -EINVAL;
+		}
+	} else {
+		if (!(vma->vm_flags & VM_READ)) {
+			dprintk(1, "invalid vma flags, VM_READ needed\n");
+			return -EINVAL;
+		}
+	}
+	if (vb2_fileio_is_active(q)) {
+		dprintk(1, "mmap: file io in progress\n");
+		return -EBUSY;
+	}
+
+	/*
+	 * Find the plane corresponding to the offset passed by userspace.
+	 */
+	ret = call_priv_op(q, find_plane_by_offset, q, off, &buffer, &plane);
+	if (ret)
+		return ret;
+
+	vb = q->bufs[buffer];
+
+	/*
+	 * MMAP requires page_aligned buffers.
+	 * The buffer length was page_aligned at __vb2_buf_mem_alloc(),
+	 * so, we need to do the same here.
+	 */
+	length = call_priv_op(q, get_plane_length, vb, plane);
+	length = PAGE_ALIGN(length);
+	if (length < (vma->vm_end - vma->vm_start)) {
+		dprintk(1,
+			"MMAP invalid, as it would overflow buffer length\n");
+		return -EINVAL;
+	}
+
+	mutex_lock(&q->mmap_lock);
+	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
+	mutex_unlock(&q->mmap_lock);
+	if (ret)
+		return ret;
+
+	dprintk(3, "buffer %d, plane %d successfully mapped\n", buffer, plane);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(vb2_mmap);
+
+#ifndef CONFIG_MMU
+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
+				    unsigned long addr,
+				    unsigned long len,
+				    unsigned long pgoff,
+				    unsigned long flags)
+{
+	unsigned long off = pgoff << PAGE_SHIFT;
+	struct vb2_buffer *vb;
+	unsigned int buffer, plane;
+	void *vaddr;
+	int ret;
+
+	if (q->memory != MEDIA_MEMORY_MMAP) {
+		dprintk(1, "queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Find the plane corresponding to the offset passed by userspace.
+	 */
+	ret = call_priv_op(q, find_plane_by_offset, q, off, &buffer, &plane);
+	if (ret)
+		return ret;
+
+	vb = q->bufs[buffer];
+
+	vaddr = vb2_plane_vaddr(vb, plane);
+	return vaddr ? (unsigned long)vaddr : -EINVAL;
+}
+EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
+#endif
 
 MODULE_DESCRIPTION("Driver helper framework for Video for Linux 2");
 MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>, Marek Szyprowski");
diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index fe07a2b..62fb5ae 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -30,113 +30,12 @@
 #include <media/v4l2-common.h>
 #include <media/videobuf2-v4l2.h>
 
-static int debug;
-module_param(debug, int, 0644);
-
-#define dprintk(level, fmt, arg...)					      \
-	do {								      \
-		if (debug >= level)					      \
-			pr_info("vb2: %s: " fmt, __func__, ## arg); \
+#define dprintk(level, fmt, arg...)						\
+	do {												\
+		if (get_vb2_debug() >= level)					\
+		pr_info("vb2: %s: " fmt, __func__, ## arg);		\
 	} while (0)
 
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-
-/*
- * If advanced debugging is on, then count how often each op is called
- * successfully, which can either be per-buffer or per-queue.
- *
- * This makes it easy to check that the 'init' and 'cleanup'
- * (and variations thereof) stay balanced.
- */
-
-#define log_memop(vb, op)						\
-	dprintk(2, "call_memop(%p, %d, %s)%s\n",			\
-		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
-		(vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
-
-#define call_memop(vb, op, args...)					\
-({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
-	int err;							\
-									\
-	log_memop(vb, op);						\
-	err = _q->mem_ops->op ? _q->mem_ops->op(args) : 0;		\
-	if (!err)							\
-		(vb)->cnt_mem_ ## op++;					\
-	err;								\
-})
-
-#define call_ptr_memop(vb, op, args...)					\
-({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
-	void *ptr;							\
-									\
-	log_memop(vb, op);						\
-	ptr = _q->mem_ops->op ? _q->mem_ops->op(args) : NULL;		\
-	if (!IS_ERR_OR_NULL(ptr))					\
-		(vb)->cnt_mem_ ## op++;					\
-	ptr;								\
-})
-
-#define call_void_memop(vb, op, args...)				\
-({									\
-	struct vb2_queue *_q = (vb)->vb2_queue;				\
-									\
-	log_memop(vb, op);						\
-	if (_q->mem_ops->op)						\
-		_q->mem_ops->op(args);					\
-	(vb)->cnt_mem_ ## op++;						\
-})
-
-#define log_qop(q, op)							\
-	dprintk(2, "call_qop(%p, %s)%s\n", q, #op,			\
-		(q)->ops->op ? "" : " (nop)")
-
-#define call_qop(q, op, args...)					\
-({									\
-	int err;							\
-									\
-	log_qop(q, op);							\
-	err = (q)->ops->op ? (q)->ops->op(args) : 0;			\
-	if (!err)							\
-		(q)->cnt_ ## op++;					\
-	err;								\
-})
-
-#define call_void_qop(q, op, args...)					\
-({									\
-	log_qop(q, op);							\
-	if ((q)->ops->op)						\
-		(q)->ops->op(args);					\
-	(q)->cnt_ ## op++;						\
-})
-
-#define log_vb_qop(vb, op, args...)					\
-	dprintk(2, "call_vb_qop(%p, %d, %s)%s\n",			\
-		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
-		(vb)->vb2_queue->ops->op ? "" : " (nop)")
-
-#define call_vb_qop(vb, op, args...)					\
-({									\
-	int err;							\
-									\
-	log_vb_qop(vb, op);						\
-	err = (vb)->vb2_queue->ops->op ?				\
-		(vb)->vb2_queue->ops->op(args) : 0;			\
-	if (!err)							\
-		(vb)->cnt_ ## op++;					\
-	err;								\
-})
-
-#define call_void_vb_qop(vb, op, args...)				\
-({									\
-	log_vb_qop(vb, op);						\
-	if ((vb)->vb2_queue->ops->op)					\
-		(vb)->vb2_queue->ops->op(args);				\
-	(vb)->cnt_ ## op++;						\
-})
-
-#else
 
 #define call_memop(vb, op, args...)					\
 	((vb)->vb2_queue->mem_ops->op ?					\
@@ -170,7 +69,6 @@ module_param(debug, int, 0644);
 			(vb)->vb2_queue->ops->op(args);			\
 	} while (0)
 
-#endif
 
 /* Flags that are set by the vb2 core */
 #define V4L2_BUFFER_MASK_FLAGS	(V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
@@ -181,3398 +79,1799 @@ module_param(debug, int, 0644);
 #define V4L2_BUFFER_OUT_FLAGS	(V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME | \
 				 V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_TIMECODE)
 
-static void __vb2_queue_cancel(struct vb2_queue *q);
-
 /**
- * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
+ * vb2_querybuf() - Wrapper for vb2_core_querybuf()
  */
-static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *cb)
+int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *pb)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	struct vb2_queue *q = vb->vb2_queue;
-	enum dma_data_direction dma_dir =
-		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-	void *mem_priv;
-	int plane;
-
-	/*
-	 * Allocate memory for all planes in this buffer
-	 * NOTE: mmapped areas should be page aligned
-	 */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
-
-		mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
-				      size, dma_dir, q->gfp_flags);
-		if (IS_ERR_OR_NULL(mem_priv))
-			goto free;
-
-		/* Associate allocator private data with this plane */
-		vb->planes[plane].mem_priv = mem_priv;
-		cb->v4l2_planes[plane].length = q->plane_sizes[plane];
-	}
-
-	return 0;
-free:
-	/* Free already allocated memory if one of the allocations failed */
-	for (; plane > 0; --plane) {
-		call_void_memop(vb, put, vb->planes[plane - 1].mem_priv);
-		vb->planes[plane - 1].mem_priv = NULL;
-	}
-
-	return -ENOMEM;
+	int ret = vb2_core_querybuf(q, pb->type, pb->index, (void *)pb);
+	return ret;
 }
+EXPORT_SYMBOL(vb2_querybuf);
 
 /**
- * __vb2_buf_mem_free() - free memory of the given buffer
+ * vb2_reqbufs() - Wrapper for vb2_core_reqbufs()
  */
-static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *cb)
+int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	unsigned int plane;
+	int ret = vb2_core_reqbufs(q, req->count, req->type, req->memory);
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		call_void_memop(vb, put, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
-		dprintk(3, "freed plane %d of buffer %d\n", plane,
-			cb->v4l2_buf.index);
+	if(ret>0)
+	{
+		req->count = ret;
+		return 0;
 	}
+	else req->count = 0;
+
+	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_reqbufs);
 
 /**
- * __vb2_buf_userptr_put() - release userspace memory associated with
- * a USERPTR buffer
+ * vb2_create_bufs() - Wrapper for vb2_core_create_bufs()
  */
-static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *cb)
+int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	unsigned int plane;
+	int ret;
 
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		if (vb->planes[plane].mem_priv)
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
+	create->index = q->num_buffers;
+	ret = vb2_core_create_bufs(q, create->count, create->format.type,
+			create->memory, (void *)&create->format);
+	if(ret>0)
+	{
+		create->count = ret;
+		return 0;
 	}
+	else create->count = 0;
+
+	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
 /**
- * __vb2_plane_dmabuf_put() - release memory associated with
- * a DMABUF shared plane
+ * vb2_prepare_buf() - Wrapper for vb2_core_prepare_buf()
  */
-static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *cb, struct vb2_plane *p)
+int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	if (!p->mem_priv)
-		return;
-
-	if (p->dbuf_mapped)
-		call_void_memop(vb, unmap_dmabuf, p->mem_priv);
-
-	call_void_memop(vb, detach_dmabuf, p->mem_priv);
-	dma_buf_put(p->dbuf);
-	memset(p, 0, sizeof(*p));
+	int ret = vb2_core_prepare_buf(q, b->type, b->index, b->memory, (void *)b);
+	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_prepare_buf);
 
 /**
- * __vb2_buf_dmabuf_put() - release memory associated with
- * a DMABUF shared buffer
+ * vb2_qbuf() - Wrapper for vb2_core_qbuf()
  */
-static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *cb)
+int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	unsigned int plane;
-
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		__vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
+	int ret = vb2_core_qbuf(q, b->type, b->index, b->memory, (void *)b);
+	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_qbuf);
 
 /**
- * __setup_lengths() - setup initial lengths for every plane in
- * every buffer on the queue
+ * vb2_dqbuf() - Wrapper for vb2_core_dqbuf()
  */
-static void __setup_lengths(struct vb2_queue *q, unsigned int n)
+int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
-	unsigned int buffer, plane;
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-
-	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
-		vb = q->bufs[buffer];
-		if (!vb)
-			continue;
-
-		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-		for (plane = 0; plane < vb->num_planes; ++plane)
-			cb->v4l2_planes[plane].length = q->plane_sizes[plane];
-	}
+	int ret = vb2_core_dqbuf(q, b->type, (void *)b, nonblocking);
+	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
 /**
- * __setup_offsets() - setup unique offsets ("cookies") for every plane in
- * every buffer on the queue
+ * vb2_streamon - Wrapper for vb2_core_streamon()
  */
-static void __setup_offsets(struct vb2_queue *q, unsigned int n)
+int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
 {
-	unsigned int buffer, plane;
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	unsigned long off;
-
-	if (q->num_buffers) {
-		struct v4l2_plane *p;
-		vb = q->bufs[q->num_buffers - 1];
-		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-		p = &cb->v4l2_planes[vb->num_planes - 1];
-		off = PAGE_ALIGN(p->m.mem_offset + p->length);
-	} else {
-		off = 0;
-	}
-
-	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
-		vb = q->bufs[buffer];
-		if (!vb)
-			continue;
-
-		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-		for (plane = 0; plane < vb->num_planes; ++plane) {
-			cb->v4l2_planes[plane].m.mem_offset = off;
-
-			dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
-					buffer, plane, off);
-
-			off += cb->v4l2_planes[plane].length;
-			off = PAGE_ALIGN(off);
-		}
-	}
+	return vb2_core_streamon(q, type);
 }
+EXPORT_SYMBOL_GPL(vb2_streamon);
 
 /**
- * __vb2_queue_alloc() - allocate videobuf buffer structures and (for MMAP type)
- * video buffer memory for all buffers/planes on the queue and initializes the
- * queue
- *
- * Returns the number of buffers successfully allocated.
+ * vb2_streamoff - Wrapper for vb2_streamoff()
  */
-static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
-			     unsigned int num_buffers, unsigned int num_planes)
+int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
 {
-	unsigned int buffer;
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	int ret;
-
-	for (buffer = 0; buffer < num_buffers; ++buffer) {
-		/* Allocate videobuf buffer structures */
-		cb = kzalloc(q->buf_struct_size, GFP_KERNEL);
-		if (!cb) {
-			dprintk(1, "memory alloc for buffer struct failed\n");
-			break;
-		}
-
-		vb = &cb->vb2;
-		/* Length stores number of planes for multiplanar buffers */
-		if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
-			cb->v4l2_buf.length = num_planes;
-
-		vb->state = VB2_BUF_STATE_DEQUEUED;
-		vb->vb2_queue = q;
-		vb->num_planes = num_planes;
-		cb->v4l2_buf.index = q->num_buffers + buffer;
-		cb->v4l2_buf.type = q->type;
-		cb->v4l2_buf.memory = memory;
-
-		/* Allocate video buffer memory for the MMAP type */
-		if (memory == V4L2_MEMORY_MMAP) {
-			ret = __vb2_buf_mem_alloc(cb);
-			if (ret) {
-				dprintk(1, "failed allocating memory for "
-						"buffer %d\n", buffer);
-				kfree(cb);
-				break;
-			}
-			/*
-			 * Call the driver-provided buffer initialization
-			 * callback, if given. An error in initialization
-			 * results in queue setup failure.
-			 */
-			ret = call_vb_qop(vb, buf_init, vb);
-			if (ret) {
-				dprintk(1, "buffer %d %p initialization"
-					" failed\n", buffer, vb);
-				__vb2_buf_mem_free(cb);
-				kfree(cb);
-				break;
-			}
-		}
-
-		q->bufs[q->num_buffers + buffer] = vb;
-	}
-
-	__setup_lengths(q, buffer);
-	if (memory == V4L2_MEMORY_MMAP)
-		__setup_offsets(q, buffer);
-
-	dprintk(1, "allocated %d buffers, %d plane(s) each\n",
-			buffer, num_planes);
-
-	return buffer;
+	return vb2_core_streamoff(q, type);
 }
+EXPORT_SYMBOL_GPL(vb2_streamoff);
 
 /**
- * __vb2_free_mem() - release all video buffer memory for a given queue
+ * vb2_expbuf() - Wrapper for vb2_core_expbuf()
  */
-static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
+int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 {
-	unsigned int buffer;
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-
-	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
-	     ++buffer) {
-		vb = q->bufs[buffer];
-		if (!vb)
-			continue;
-		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	int ret = vb2_core_expbuf(q, eb->type, eb->index, eb->plane, eb->flags);
 
-		/* Free MMAP buffers or release USERPTR buffers */
-		if (q->memory == V4L2_MEMORY_MMAP)
-			__vb2_buf_mem_free(cb);
-		else if (q->memory == V4L2_MEMORY_DMABUF)
-			__vb2_buf_dmabuf_put(cb);
-		else
-			__vb2_buf_userptr_put(cb);
+	if(ret>0)
+	{
+		eb->fd = ret;
+		return 0;
 	}
+	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_expbuf);
+
+static int __vb2_init_fileio(struct vb2_queue *q, int read);
+static int __vb2_cleanup_fileio(struct vb2_queue *q);
 
 /**
- * __vb2_queue_free() - free buffers at the end of the queue - video memory and
- * related information, if no buffers are left return the queue to an
- * uninitialized state. Might be called even if the queue has already been freed.
+ * vb2_poll() - implements poll userspace operation
+ * @q:		videobuf2 queue
+ * @file:	file argument passed to the poll file operation handler
+ * @wait:	wait argument passed to the poll file operation handler
+ *
+ * This function implements poll file operation handler for a driver.
+ * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will
+ * be informed that the file descriptor of a video device is available for
+ * reading.
+ * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
+ * will be reported as available for writing.
+ *
+ * If the driver uses struct v4l2_fh, then vb2_poll() will also check for any
+ * pending events.
+ *
+ * The return values from this function are intended to be directly returned
+ * from poll handler in driver.
  */
-static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
+unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 {
-	unsigned int buffer;
-	struct vb2_buffer *vb;
-
-	/*
-	 * Sanity check: when preparing a buffer the queue lock is released for
-	 * a short while (see __buf_prepare for the details), which would allow
-	 * a race with a reqbufs which can call this function. Removing the
-	 * buffers from underneath __buf_prepare is obviously a bad idea, so we
-	 * check if any of the buffers is in the state PREPARING, and if so we
-	 * just return -EAGAIN.
-	 */
-	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
-	     ++buffer) {
-		vb = q->bufs[buffer];
-
-		if (vb == NULL)
-			continue;
-		if (vb->state == VB2_BUF_STATE_PREPARING) {
-			dprintk(1, "preparing buffers, cannot free\n");
-			return -EAGAIN;
-		}
-	}
+	struct video_device *vfd = video_devdata(file);
+	unsigned long req_events = poll_requested_events(wait);
+	struct vb2_buffer *vb = NULL;
+	unsigned int res = 0;
+	unsigned long flags;
 
-	/* Call driver-provided cleanup function for each buffer, if provided */
-	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
-	     ++buffer) {
-		vb = q->bufs[buffer];
+	if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
+		struct v4l2_fh *fh = file->private_data;
 
-		if (vb && vb->planes[0].mem_priv)
-			call_void_vb_qop(vb, buf_cleanup, vb);
+		if (v4l2_event_pending(fh))
+			res = POLLPRI;
+		else if (req_events & POLLPRI)
+			poll_wait(file, &fh->wait, wait);
 	}
 
-	/* Release video buffer memory */
-	__vb2_free_mem(q, buffers);
+	if (!V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLIN | POLLRDNORM)))
+		return res;
+	if (V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLOUT | POLLWRNORM)))
+		return res;
 
-#ifdef CONFIG_VIDEO_ADV_DEBUG
 	/*
-	 * Check that all the calls were balances during the life-time of this
-	 * queue. If not (or if the debug level is 1 or up), then dump the
-	 * counters to the kernel log.
+	 * Start file I/O emulator only if streaming API has not been used yet.
 	 */
-	if (q->num_buffers) {
-		bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming ||
-				  q->cnt_wait_prepare != q->cnt_wait_finish;
-
-		if (unbalanced || debug) {
-			pr_info("vb2: counters for queue %p:%s\n", q,
-				unbalanced ? " UNBALANCED!" : "");
-			pr_info("vb2:     setup: %u start_streaming: %u stop_streaming: %u\n",
-				q->cnt_queue_setup, q->cnt_start_streaming,
-				q->cnt_stop_streaming);
-			pr_info("vb2:     wait_prepare: %u wait_finish: %u\n",
-				q->cnt_wait_prepare, q->cnt_wait_finish);
+	if (q->num_buffers == 0 && !vb2_fileio_is_active(q)) {
+		if (!V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_READ) &&
+				(req_events & (POLLIN | POLLRDNORM))) {
+			if (__vb2_init_fileio(q, 1))
+				return res | POLLERR;
 		}
-		q->cnt_queue_setup = 0;
-		q->cnt_wait_prepare = 0;
-		q->cnt_wait_finish = 0;
-		q->cnt_start_streaming = 0;
-		q->cnt_stop_streaming = 0;
-	}
-	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
-		struct vb2_buffer *vb = q->bufs[buffer];
-		bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put ||
-				  vb->cnt_mem_prepare != vb->cnt_mem_finish ||
-				  vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr ||
-				  vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf ||
-				  vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf ||
-				  vb->cnt_buf_queue != vb->cnt_buf_done ||
-				  vb->cnt_buf_prepare != vb->cnt_buf_finish ||
-				  vb->cnt_buf_init != vb->cnt_buf_cleanup;
-
-		if (unbalanced || debug) {
-			pr_info("vb2:   counters for queue %p, buffer %d:%s\n",
-				q, buffer, unbalanced ? " UNBALANCED!" : "");
-			pr_info("vb2:     buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n",
-				vb->cnt_buf_init, vb->cnt_buf_cleanup,
-				vb->cnt_buf_prepare, vb->cnt_buf_finish);
-			pr_info("vb2:     buf_queue: %u buf_done: %u\n",
-				vb->cnt_buf_queue, vb->cnt_buf_done);
-			pr_info("vb2:     alloc: %u put: %u prepare: %u finish: %u mmap: %u\n",
-				vb->cnt_mem_alloc, vb->cnt_mem_put,
-				vb->cnt_mem_prepare, vb->cnt_mem_finish,
-				vb->cnt_mem_mmap);
-			pr_info("vb2:     get_userptr: %u put_userptr: %u\n",
-				vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr);
-			pr_info("vb2:     attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n",
-				vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf,
-				vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf);
-			pr_info("vb2:     get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n",
-				vb->cnt_mem_get_dmabuf,
-				vb->cnt_mem_num_users,
-				vb->cnt_mem_vaddr,
-				vb->cnt_mem_cookie);
+		if (V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_WRITE) &&
+				(req_events & (POLLOUT | POLLWRNORM))) {
+			if (__vb2_init_fileio(q, 0))
+				return res | POLLERR;
+			/*
+			 * Write to OUTPUT queue can be done immediately.
+			 */
+			return res | POLLOUT | POLLWRNORM;
 		}
 	}
-#endif
-
-	/* Free videobuf buffers */
-	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
-	     ++buffer) {
-		kfree(q->bufs[buffer]);
-		q->bufs[buffer] = NULL;
-	}
 
-	q->num_buffers -= buffers;
-	if (!q->num_buffers) {
-		q->memory = 0;
-		INIT_LIST_HEAD(&q->queued_list);
-	}
-	return 0;
-}
+	/*
+	 * There is nothing to wait for if the queue isn't streaming, or if the
+	 * error flag is set.
+	 */
+	if (!vb2_is_streaming(q) || q->error)
+		return res | POLLERR;
+	/*
+	 * For compatibility with vb1: if QBUF hasn't been called yet, then
+	 * return POLLERR as well. This only affects capture queues, output
+	 * queues will always initialize waiting_for_buffers to false.
+	 */
+	if (q->waiting_for_buffers)
+		return res | POLLERR;
 
-/**
- * __verify_planes_array() - verify that the planes array passed in struct
- * v4l2_buffer from userspace can be safely used
- */
-static int __verify_planes_array(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
-{
-	struct vb2_buffer *vb = &cb->vb2;
+	/*
+	 * For output streams you can write as long as there are fewer buffers
+	 * queued than there are buffers available.
+	 */
+	if (V4L2_TYPE_IS_OUTPUT(q->type) && q->queued_count < q->num_buffers)
+		return res | POLLOUT | POLLWRNORM;
 
-	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
-		return 0;
+	if (list_empty(&q->done_list))
+		poll_wait(file, &q->done_wq, wait);
 
-	/* Is memory for copying plane information present? */
-	if (NULL == b->m.planes) {
-		dprintk(1, "multi-planar buffer passed but "
-			   "planes array not provided\n");
-		return -EINVAL;
-	}
+	/*
+	 * Take first buffer available for dequeuing.
+	 */
+	spin_lock_irqsave(&q->done_lock, flags);
+	if (!list_empty(&q->done_list))
+		vb = list_first_entry(&q->done_list, struct vb2_buffer,
+					done_entry);
+	spin_unlock_irqrestore(&q->done_lock, flags);
 
-	if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
-		dprintk(1, "incorrect planes array length, "
-			   "expected %d, got %d\n", vb->num_planes, b->length);
-		return -EINVAL;
+	if (vb && (vb->state == VB2_BUF_STATE_DONE
+			|| vb->state == VB2_BUF_STATE_ERROR)) {
+		return (V4L2_TYPE_IS_OUTPUT(q->type)) ?
+				res | POLLOUT | POLLWRNORM :
+				res | POLLIN | POLLRDNORM;
 	}
-
-	return 0;
+	return res;
 }
+EXPORT_SYMBOL_GPL(vb2_poll);
 
+const struct vb2_priv_ops vb2_v4l2_operations;
 /**
- * __verify_length() - Verify that the bytesused value for each plane fits in
- * the plane length and that the data offset doesn't exceed the bytesused value.
+ * vb2_queue_init() - initialize a videobuf2 queue
+ * @q:		videobuf2 queue; this structure should be allocated in driver
+ *
+ * The vb2_queue structure should be allocated by the driver. The driver is
+ * responsible of clearing it's content and setting initial values for some
+ * required entries before calling this function.
+ * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer
+ * to the struct vb2_queue description in include/media/videobuf2-core.h
+ * for more information.
  */
-static int __verify_length(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
+int vb2_queue_init(struct vb2_queue *q)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	unsigned int length;
-	unsigned int bytesused;
-	unsigned int plane;
+	/*
+	 * Sanity check
+	 */
+	if (WARN_ON(!q)			  ||
+	    WARN_ON(!q->ops)		  ||
+	    WARN_ON(!q->mem_ops)	  ||
+	    WARN_ON(!q->type)		  ||
+	    WARN_ON(!q->io_modes)	  ||
+	    WARN_ON(!q->ops->queue_setup) ||
+	    WARN_ON(!q->ops->buf_queue)   ||
+	    WARN_ON(q->timestamp_flags &
+		    ~(V4L2_BUF_FLAG_TIMESTAMP_MASK |
+		      V4L2_BUF_FLAG_TSTAMP_SRC_MASK)))
+		return -EINVAL;
 
-	if (!V4L2_TYPE_IS_OUTPUT(b->type))
-		return 0;
+	/* Warn that the driver should choose an appropriate timestamp type */
+	WARN_ON((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
+		V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN);
 
-	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
-		for (plane = 0; plane < vb->num_planes; ++plane) {
-			length = (b->memory == V4L2_MEMORY_USERPTR ||
-				  b->memory == V4L2_MEMORY_DMABUF)
-			       ? b->m.planes[plane].length
-			       : cb->v4l2_planes[plane].length;
-			bytesused = b->m.planes[plane].bytesused
-				  ? b->m.planes[plane].bytesused : length;
+	INIT_LIST_HEAD(&q->queued_list);
+	INIT_LIST_HEAD(&q->done_list);
+	spin_lock_init(&q->done_lock);
+	mutex_init(&q->mmap_lock);
+	init_waitqueue_head(&q->done_wq);
 
-			if (b->m.planes[plane].bytesused > length)
-				return -EINVAL;
 
-			if (b->m.planes[plane].data_offset > 0 &&
-			    b->m.planes[plane].data_offset >= bytesused)
-				return -EINVAL;
-		}
-	} else {
-		length = (b->memory == V4L2_MEMORY_USERPTR)
-		       ? b->length : cb->v4l2_planes[0].length;
-		bytesused = b->bytesused ? b->bytesused : length;
+	q->priv_ops = &vb2_v4l2_operations;
 
-		if (b->bytesused > length)
-			return -EINVAL;
-	}
+	if (q->buf_struct_size == 0)
+		q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_queue_init);
 
 /**
- * __buffer_in_use() - return true if the buffer is in use and
- * the queue cannot be freed (by the means of REQBUFS(0)) call
+ * vb2_queue_release() - stop streaming, release the queue and free memory
+ * @q:		videobuf2 queue
+ *
+ * This function stops streaming and performs necessary clean ups, including
+ * freeing video buffer memory. The driver is responsible for freeing
+ * the vb2_queue structure itself.
  */
-static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *cb)
+void vb2_queue_release(struct vb2_queue *q)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	unsigned int plane;
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		void *mem_priv = vb->planes[plane].mem_priv;
-		/*
-		 * If num_users() has not been provided, call_memop
-		 * will return 0, apparently nobody cares about this
-		 * case anyway. If num_users() returns more than 1,
-		 * we are not the only user of the plane's memory.
-		 */
-		if (mem_priv && call_memop(vb, num_users, mem_priv) > 1)
-			return true;
-	}
-	return false;
+	__vb2_cleanup_fileio(q);
+	__vb2_queue_cancel(q);
+	mutex_lock(&q->mmap_lock);
+	__vb2_queue_free(q, q->num_buffers);
+	mutex_unlock(&q->mmap_lock);
 }
+EXPORT_SYMBOL_GPL(vb2_queue_release);
 
 /**
- * __buffers_in_use() - return true if any buffers on the queue are in use and
- * the queue cannot be freed (by the means of REQBUFS(0)) call
+ * struct vb2_fileio_buf - buffer context used by file io emulator
+ *
+ * vb2 provides a compatibility layer and emulator of file io (read and
+ * write) calls on top of streaming API. This structure is used for
+ * tracking context related to the buffers.
  */
-static bool __buffers_in_use(struct vb2_queue *q)
-{
-	struct vb2_v4l2_buffer *cb;
-	unsigned int buffer;
+struct vb2_fileio_buf {
+	void *vaddr;
+	unsigned int size;
+	unsigned int pos;
+	unsigned int queued:1;
+};
 
-	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
-		cb = container_of(q->bufs[buffer], struct vb2_v4l2_buffer, vb2);
-		if (__buffer_in_use(q, cb))
-			return true;
-	}
-	return false;
-}
+/**
+ * struct vb2_fileio_data - queue context used by file io emulator
+ *
+ * @cur_index:	the index of the buffer currently being read from or
+ *		written to. If equal to q->num_buffers then a new buffer
+ *		must be dequeued.
+ * @initial_index: in the read() case all buffers are queued up immediately
+ *		in __vb2_init_fileio() and __vb2_perform_fileio() just cycles
+ *		buffers. However, in the write() case no buffers are initially
+ *		queued, instead whenever a buffer is full it is queued up by
+ *		__vb2_perform_fileio(). Only once all available buffers have
+ *		been queued up will __vb2_perform_fileio() start to dequeue
+ *		buffers. This means that initially __vb2_perform_fileio()
+ *		needs to know what buffer index to use when it is queuing up
+ *		the buffers for the first time. That initial index is stored
+ *		in this field. Once it is equal to q->num_buffers all
+ *		available buffers have been queued and __vb2_perform_fileio()
+ *		should start the normal dequeue/queue cycle.
+ *
+ * vb2 provides a compatibility layer and emulator of file io (read and
+ * write) calls on top of streaming API. For proper operation it required
+ * this structure to save the driver state between each call of the read
+ * or write function.
+ */
+struct vb2_fileio_data {
+	struct v4l2_requestbuffers req;
+	struct v4l2_plane p;
+	struct v4l2_buffer b;
+	struct vb2_fileio_buf bufs[MEDIA_MAX_FRAME];
+	unsigned int cur_index;
+	unsigned int initial_index;
+	unsigned int q_count;
+	unsigned int dq_count;
+	unsigned int flags;
+};
 
 /**
- * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
- * returned to userspace
+ * __vb2_init_fileio() - initialize file io emulator
+ * @q:		videobuf2 queue
+ * @read:	mode selector (1 means read, 0 means write)
  */
-static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *cb, struct v4l2_buffer *b)
+static int __vb2_init_fileio(struct vb2_queue *q, int read)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_fileio_data *fileio;
+	int i, ret;
+	unsigned int count = 0;
 
-	/* Copy back data such as timestamp, flags, etc. */
-	memcpy(b, &cb->v4l2_buf, offsetof(struct v4l2_buffer, m));
-	b->reserved2 = cb->v4l2_buf.reserved2;
-	b->reserved = cb->v4l2_buf.reserved;
+	/*
+	 * Sanity check
+	 */
+	if (WARN_ON((read && !(q->io_modes & VB2_READ)) ||
+		    (!read && !(q->io_modes & VB2_WRITE))))
+		return -EINVAL;
 
-	if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) {
-		/*
-		 * Fill in plane-related data if userspace provided an array
-		 * for it. The caller has already verified memory and size.
-		 */
-		b->length = vb->num_planes;
-		memcpy(b->m.planes, cb->v4l2_planes,
-			b->length * sizeof(struct v4l2_plane));
-	} else {
-		/*
-		 * We use length and offset in v4l2_planes array even for
-		 * single-planar buffers, but userspace does not.
-		 */
-		b->length = cb->v4l2_planes[0].length;
-		b->bytesused = cb->v4l2_planes[0].bytesused;
-		if (q->memory == V4L2_MEMORY_MMAP)
-			b->m.offset = cb->v4l2_planes[0].m.mem_offset;
-		else if (q->memory == V4L2_MEMORY_USERPTR)
-			b->m.userptr = cb->v4l2_planes[0].m.userptr;
-		else if (q->memory == V4L2_MEMORY_DMABUF)
-			b->m.fd = cb->v4l2_planes[0].m.fd;
-	}
+	/*
+	 * Check if device supports mapping buffers to kernel virtual space.
+	 */
+	if (!q->mem_ops->vaddr)
+		return -EBUSY;
 
 	/*
-	 * Clear any buffer state related flags.
+	 * Check if streaming api has not been already activated.
 	 */
-	b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
-	b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
-	if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
-	    V4L2_BUF_FLAG_TIMESTAMP_COPY) {
-		/*
-		 * For non-COPY timestamps, drop timestamp source bits
-		 * and obtain the timestamp source from the queue.
-		 */
-		b->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-	}
+	if (q->streaming || q->num_buffers > 0)
+		return -EBUSY;
 
-	switch (vb->state) {
-	case VB2_BUF_STATE_QUEUED:
-	case VB2_BUF_STATE_ACTIVE:
-		b->flags |= V4L2_BUF_FLAG_QUEUED;
-		break;
-	case VB2_BUF_STATE_ERROR:
-		b->flags |= V4L2_BUF_FLAG_ERROR;
-		/* fall through */
-	case VB2_BUF_STATE_DONE:
-		b->flags |= V4L2_BUF_FLAG_DONE;
-		break;
-	case VB2_BUF_STATE_PREPARED:
-		b->flags |= V4L2_BUF_FLAG_PREPARED;
-		break;
-	case VB2_BUF_STATE_PREPARING:
-	case VB2_BUF_STATE_DEQUEUED:
-		/* nothing */
-		break;
-	}
+	/*
+	 * Start with count 1, driver can increase it in queue_setup()
+	 */
+	count = 1;
 
-	if (__buffer_in_use(q, cb))
-		b->flags |= V4L2_BUF_FLAG_MAPPED;
-}
+	dprintk(3, "setting up file io: mode %s, count %d, flags %08x\n",
+		(read) ? "read" : "write", count, q->io_flags);
 
-/**
- * vb2_querybuf() - query video buffer information
- * @q:		videobuf queue
- * @b:		buffer struct passed from userspace to vidioc_querybuf handler
- *		in driver
- *
- * Should be called from vidioc_querybuf ioctl handler in driver.
- * This function will verify the passed v4l2_buffer structure and fill the
- * relevant information for the userspace.
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_querybuf handler in driver.
- */
-int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
-{
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	int ret;
-
-	if (b->type != q->type) {
-		dprintk(1, "wrong buffer type\n");
-		return -EINVAL;
-	}
-
-	if (b->index >= q->num_buffers) {
-		dprintk(1, "buffer index out of range\n");
-		return -EINVAL;
-	}
-	vb = q->bufs[b->index];
-	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-	ret = __verify_planes_array(cb, b);
-	if (!ret)
-		__fill_v4l2_buffer(cb, b);
-	return ret;
-}
-EXPORT_SYMBOL(vb2_querybuf);
-
-/**
- * __verify_userptr_ops() - verify that all memory operations required for
- * USERPTR queue type have been provided
- */
-static int __verify_userptr_ops(struct vb2_queue *q)
-{
-	if (!(q->io_modes & VB2_USERPTR) || !q->mem_ops->get_userptr ||
-	    !q->mem_ops->put_userptr)
-		return -EINVAL;
-
-	return 0;
-}
-
-/**
- * __verify_mmap_ops() - verify that all memory operations required for
- * MMAP queue type have been provided
- */
-static int __verify_mmap_ops(struct vb2_queue *q)
-{
-	if (!(q->io_modes & VB2_MMAP) || !q->mem_ops->alloc ||
-	    !q->mem_ops->put || !q->mem_ops->mmap)
-		return -EINVAL;
-
-	return 0;
-}
-
-/**
- * __verify_dmabuf_ops() - verify that all memory operations required for
- * DMABUF queue type have been provided
- */
-static int __verify_dmabuf_ops(struct vb2_queue *q)
-{
-	if (!(q->io_modes & VB2_DMABUF) || !q->mem_ops->attach_dmabuf ||
-	    !q->mem_ops->detach_dmabuf  || !q->mem_ops->map_dmabuf ||
-	    !q->mem_ops->unmap_dmabuf)
-		return -EINVAL;
-
-	return 0;
-}
-
-/**
- * __verify_memory_type() - Check whether the memory type and buffer type
- * passed to a buffer operation are compatible with the queue.
- */
-static int __verify_memory_type(struct vb2_queue *q,
-		enum v4l2_memory memory, enum v4l2_buf_type type)
-{
-	if (memory != V4L2_MEMORY_MMAP && memory != V4L2_MEMORY_USERPTR &&
-	    memory != V4L2_MEMORY_DMABUF) {
-		dprintk(1, "unsupported memory type\n");
-		return -EINVAL;
-	}
+	fileio = kzalloc(sizeof(struct vb2_fileio_data), GFP_KERNEL);
+	if (fileio == NULL)
+		return -ENOMEM;
 
-	if (type != q->type) {
-		dprintk(1, "requested type is incorrect\n");
-		return -EINVAL;
-	}
+	fileio->flags = q->io_flags;
 
 	/*
-	 * Make sure all the required memory ops for given memory type
-	 * are available.
+	 * Request buffers and use MMAP type to force driver
+	 * to allocate buffers by itself.
 	 */
-	if (memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
-		dprintk(1, "MMAP for current setup unsupported\n");
-		return -EINVAL;
-	}
-
-	if (memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
-		dprintk(1, "USERPTR for current setup unsupported\n");
-		return -EINVAL;
-	}
-
-	if (memory == V4L2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) {
-		dprintk(1, "DMABUF for current setup unsupported\n");
-		return -EINVAL;
-	}
+	fileio->req.count = count;
+	fileio->req.memory = MEDIA_MEMORY_MMAP;
+	fileio->req.type = q->type;
+	q->fileio = fileio;
+	ret = vb2_core_reqbufs(q, count, q->type, MEDIA_MEMORY_MMAP);
+	if (ret)
+		goto err_kfree;
 
 	/*
-	 * Place the busy tests at the end: -EBUSY can be ignored when
-	 * create_bufs is called with count == 0, but count == 0 should still
-	 * do the memory and type validation.
+	 * Check if plane_count is correct
+	 * (multiplane buffers are not supported).
 	 */
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
-		return -EBUSY;
-	}
-	return 0;
-}
-
-/**
- * __reqbufs() - Initiate streaming
- * @q:		videobuf2 queue
- * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
- *
- * Should be called from vidioc_reqbufs ioctl handler of a driver.
- * This function:
- * 1) verifies streaming parameters passed from the userspace,
- * 2) sets up the queue,
- * 3) negotiates number of buffers and planes per buffer with the driver
- *    to be used during streaming,
- * 4) allocates internal buffer structures (struct vb2_v4l2_buffer), according to
- *    the agreed parameters,
- * 5) for MMAP memory type, allocates actual video memory, using the
- *    memory handling/allocation routines provided during queue initialization
- *
- * If req->count is 0, all the memory will be freed instead.
- * If the queue has been allocated previously (by a previous vb2_reqbufs) call
- * and the queue is not busy, memory will be reallocated.
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_reqbufs handler in driver.
- */
-static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
-{
-	unsigned int num_buffers, allocated_buffers, num_planes = 0;
-	int ret;
-
-	if (q->streaming) {
-		dprintk(1, "streaming active\n");
-		return -EBUSY;
-	}
-
-	if (req->count == 0 || q->num_buffers != 0 || q->memory != req->memory) {
-		/*
-		 * We already have buffers allocated, so first check if they
-		 * are not in use and can be freed.
-		 */
-		mutex_lock(&q->mmap_lock);
-		if (q->memory == V4L2_MEMORY_MMAP && __buffers_in_use(q)) {
-			mutex_unlock(&q->mmap_lock);
-			dprintk(1, "memory in use, cannot free\n");
-			return -EBUSY;
-		}
-
-		/*
-		 * Call queue_cancel to clean up any buffers in the PREPARED or
-		 * QUEUED state which is possible if buffers were prepared or
-		 * queued without ever calling STREAMON.
-		 */
-		__vb2_queue_cancel(q);
-		ret = __vb2_queue_free(q, q->num_buffers);
-		mutex_unlock(&q->mmap_lock);
-		if (ret)
-			return ret;
-
-		/*
-		 * In case of REQBUFS(0) return immediately without calling
-		 * driver's queue_setup() callback and allocating resources.
-		 */
-		if (req->count == 0)
-			return 0;
+	if (q->bufs[0]->num_planes != 1) {
+		ret = -EBUSY;
+		goto err_reqbufs;
 	}
 
 	/*
-	 * Make sure the requested values and current defaults are sane.
-	 */
-	num_buffers = min_t(unsigned int, req->count, VIDEO_MAX_FRAME);
-	num_buffers = max_t(unsigned int, num_buffers, q->min_buffers_needed);
-	memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
-	memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
-	q->memory = req->memory;
-
-	/*
-	 * Ask the driver how many buffers and planes per buffer it requires.
-	 * Driver also sets the size and allocator context for each plane.
+	 * Get kernel address of each buffer.
 	 */
-	ret = call_qop(q, queue_setup, q, NULL, &num_buffers, &num_planes,
-		       q->plane_sizes, q->alloc_ctx);
-	if (ret)
-		return ret;
-
-	/* Finally, allocate buffers and video memory */
-	allocated_buffers = __vb2_queue_alloc(q, req->memory, num_buffers, num_planes);
-	if (allocated_buffers == 0) {
-		dprintk(1, "memory allocation failed\n");
-		return -ENOMEM;
+	for (i = 0; i < q->num_buffers; i++) {
+		struct vb2_v4l2_buffer *cb = container_of(q->bufs[i], struct vb2_v4l2_buffer, vb2);
+		fileio->bufs[i].vaddr = vb2_plane_vaddr(cb, 0);
+		if (fileio->bufs[i].vaddr == NULL) {
+			ret = -EINVAL;
+			goto err_reqbufs;
+		}
+		fileio->bufs[i].size = vb2_plane_size(cb, 0);
 	}
 
 	/*
-	 * There is no point in continuing if we can't allocate the minimum
-	 * number of buffers needed by this vb2_queue.
-	 */
-	if (allocated_buffers < q->min_buffers_needed)
-		ret = -ENOMEM;
-
-	/*
-	 * Check if driver can handle the allocated number of buffers.
+	 * Read mode requires pre queuing of all buffers.
 	 */
-	if (!ret && allocated_buffers < num_buffers) {
-		num_buffers = allocated_buffers;
-
-		ret = call_qop(q, queue_setup, q, NULL, &num_buffers,
-			       &num_planes, q->plane_sizes, q->alloc_ctx);
-
-		if (!ret && allocated_buffers < num_buffers)
-			ret = -ENOMEM;
+	if (read) {
+		bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
 
 		/*
-		 * Either the driver has accepted a smaller number of buffers,
-		 * or .queue_setup() returned an error
+		 * Queue all buffers.
 		 */
-	}
-
-	mutex_lock(&q->mmap_lock);
-	q->num_buffers = allocated_buffers;
+		for (i = 0; i < q->num_buffers; i++) {
+			struct v4l2_buffer *b = &fileio->b;
 
-	if (ret < 0) {
+			memset(b, 0, sizeof(*b));
+			b->type = q->type;
+			if (is_multiplanar) {
+				memset(&fileio->p, 0, sizeof(fileio->p));
+				b->m.planes = &fileio->p;
+				b->length = 1;
+			}
+			b->memory = q->memory;
+			b->index = i;
+			ret = vb2_internal_qbuf(q, q->type, i, q->memory, b);
+			if (ret)
+				goto err_reqbufs;
+			fileio->bufs[i].queued = 1;
+		}
 		/*
-		 * Note: __vb2_queue_free() will subtract 'allocated_buffers'
-		 * from q->num_buffers.
+		 * All buffers have been queued, so mark that by setting
+		 * initial_index to q->num_buffers
 		 */
-		__vb2_queue_free(q, allocated_buffers);
-		mutex_unlock(&q->mmap_lock);
-		return ret;
+		fileio->initial_index = q->num_buffers;
+		fileio->cur_index = q->num_buffers;
 	}
-	mutex_unlock(&q->mmap_lock);
 
 	/*
-	 * Return the number of successfully allocated buffers
-	 * to the userspace.
+	 * Start streaming.
 	 */
-	req->count = allocated_buffers;
-	q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
+	ret = vb2_internal_streamon(q, q->type);
+	if (ret)
+		goto err_reqbufs;
 
-	return 0;
+	return ret;
+
+err_reqbufs:
+	vb2_core_reqbufs(q, 0, q->type, MEDIA_MEMORY_MMAP);
+
+err_kfree:
+	q->fileio = NULL;
+	kfree(fileio);
+	return ret;
 }
 
 /**
- * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory and
- * type values.
+ * __vb2_cleanup_fileio() - free resourced used by file io emulator
  * @q:		videobuf2 queue
- * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
  */
-int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
+static int __vb2_cleanup_fileio(struct vb2_queue *q)
 {
-	int ret = __verify_memory_type(q, req->memory, req->type);
+	struct vb2_fileio_data *fileio = q->fileio;
 
-	return ret ? ret : __reqbufs(q, req);
+	if (fileio) {
+		vb2_internal_streamoff(q, q->type);
+		q->fileio = NULL;
+		fileio->req.count = 0;
+		vb2_reqbufs(q, &fileio->req);
+		kfree(fileio);
+		dprintk(3, "file io emulator closed\n");
+	}
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_reqbufs);
 
 /**
- * __create_bufs() - Allocate buffers and any required auxiliary structs
+ * __vb2_perform_fileio() - perform a single file io (read or write) operation
  * @q:		videobuf2 queue
- * @create:	creation parameters, passed from userspace to vidioc_create_bufs
- *		handler in driver
- *
- * Should be called from vidioc_create_bufs ioctl handler of a driver.
- * This function:
- * 1) verifies parameter sanity
- * 2) calls the .queue_setup() queue operation
- * 3) performs any necessary memory allocations
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_create_bufs handler in driver.
+ * @data:	pointed to target userspace buffer
+ * @count:	number of bytes to read or write
+ * @ppos:	file handle position tracking pointer
+ * @nonblock:	mode selector (1 means blocking calls, 0 means nonblocking)
+ * @read:	access mode selector (1 means read, 0 means write)
  */
-static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
+static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
+		loff_t *ppos, int nonblock, int read)
 {
-	unsigned int num_planes = 0, num_buffers, allocated_buffers;
-	int ret;
+	struct vb2_fileio_data *fileio;
+	struct vb2_fileio_buf *buf;
+	bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
+	struct vb2_v4l2_buffer *cb;
 
-	if (q->num_buffers == VIDEO_MAX_FRAME) {
-		dprintk(1, "maximum number of buffers already allocated\n");
-		return -ENOBUFS;
-	}
+	/*
+	 * When using write() to write data to an output video node the vb2 core
+	 * should set timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody
+	 * else is able to provide this information with the write() operation.
+	 */
+	bool set_timestamp = !read &&
+		(q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
+		V4L2_BUF_FLAG_TIMESTAMP_COPY;
+	int ret, index;
 
-	if (!q->num_buffers) {
-		memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
-		memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
-		q->memory = create->memory;
-		q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
-	}
+	dprintk(3, "mode %s, offset %ld, count %zd, %sblocking\n",
+		read ? "read" : "write", (long)*ppos, count,
+		nonblock ? "non" : "");
 
-	num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers);
+	if (!data)
+		return -EINVAL;
 
 	/*
-	 * Ask the driver, whether the requested number of buffers, planes per
-	 * buffer and their sizes are acceptable
+	 * Initialize emulator on first call.
 	 */
-	ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
-		       &num_planes, q->plane_sizes, q->alloc_ctx);
-	if (ret)
-		return ret;
-
-	/* Finally, allocate buffers and video memory */
-	allocated_buffers = __vb2_queue_alloc(q, create->memory, num_buffers,
-				num_planes);
-	if (allocated_buffers == 0) {
-		dprintk(1, "memory allocation failed\n");
-		return -ENOMEM;
+	if (!vb2_fileio_is_active(q)) {
+		ret = __vb2_init_fileio(q, read);
+		dprintk(3, "vb2_init_fileio result: %d\n", ret);
+		if (ret)
+			return ret;
 	}
+	fileio = q->fileio;
 
 	/*
-	 * Check if driver can handle the so far allocated number of buffers.
+	 * Check if we need to dequeue the buffer.
 	 */
-	if (allocated_buffers < num_buffers) {
-		num_buffers = allocated_buffers;
-
-		/*
-		 * q->num_buffers contains the total number of buffers, that the
-		 * queue driver has set up
-		 */
-		ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
-			       &num_planes, q->plane_sizes, q->alloc_ctx);
-
-		if (!ret && allocated_buffers < num_buffers)
-			ret = -ENOMEM;
-
+	index = fileio->cur_index;
+	if (index >= q->num_buffers) {
 		/*
-		 * Either the driver has accepted a smaller number of buffers,
-		 * or .queue_setup() returned an error
+		 * Call vb2_dqbuf to get buffer back.
 		 */
-	}
+		memset(&fileio->b, 0, sizeof(fileio->b));
+		fileio->b.type = q->type;
+		fileio->b.memory = q->memory;
+		if (is_multiplanar) {
+			memset(&fileio->p, 0, sizeof(fileio->p));
+			fileio->b.m.planes = &fileio->p;
+			fileio->b.length = 1;
+		}
+		ret = vb2_internal_dqbuf(q, q->type, &fileio->b, nonblock);
+		dprintk(5, "vb2_dqbuf result: %d\n", ret);
+		if (ret)
+			return ret;
+		fileio->dq_count += 1;
 
-	mutex_lock(&q->mmap_lock);
-	q->num_buffers += allocated_buffers;
+		fileio->cur_index = index = fileio->b.index;
+		buf = &fileio->bufs[index];
 
-	if (ret < 0) {
 		/*
-		 * Note: __vb2_queue_free() will subtract 'allocated_buffers'
-		 * from q->num_buffers.
+		 * Get number of bytes filled by the driver
 		 */
-		__vb2_queue_free(q, allocated_buffers);
-		mutex_unlock(&q->mmap_lock);
-		return -ENOMEM;
+		buf->pos = 0;
+		buf->queued = 0;
+		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
+		buf->size = read ? vb2_get_plane_payload(cb, 0)
+				 : vb2_plane_size(cb, 0);
+		/* Compensate for data_offset on read in the multiplanar case. */
+		if (is_multiplanar && read &&
+		    fileio->b.m.planes[0].data_offset < buf->size) {
+			buf->pos = fileio->b.m.planes[0].data_offset;
+			buf->size -= buf->pos;
+		}
+	} else {
+		buf = &fileio->bufs[index];
 	}
-	mutex_unlock(&q->mmap_lock);
 
 	/*
-	 * Return the number of successfully allocated buffers
-	 * to the userspace.
+	 * Limit count on last few bytes of the buffer.
 	 */
-	create->count = allocated_buffers;
-
-	return 0;
-}
-
-/**
- * vb2_create_bufs() - Wrapper for __create_bufs() that also verifies the
- * memory and type values.
- * @q:		videobuf2 queue
- * @create:	creation parameters, passed from userspace to vidioc_create_bufs
- *		handler in driver
- */
-int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
-{
-	int ret = __verify_memory_type(q, create->memory, create->format.type);
-
-	create->index = q->num_buffers;
-	if (create->count == 0)
-		return ret != -EBUSY ? ret : 0;
-	return ret ? ret : __create_bufs(q, create);
-}
-EXPORT_SYMBOL_GPL(vb2_create_bufs);
-
-/**
- * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
- * @vb:		vb2_v4l2_buffer to which the plane in question belongs to
- * @plane_no:	plane number for which the address is to be returned
- *
- * This function returns a kernel virtual address of a given plane if
- * such a mapping exist, NULL otherwise.
- */
-void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
-		return NULL;
-
-	return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
-
-}
-EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
-
-/**
- * vb2_plane_cookie() - Return allocator specific cookie for the given plane
- * @vb:		vb2_v4l2_buffer to which the plane in question belongs to
- * @plane_no:	plane number for which the cookie is to be returned
- *
- * This function returns an allocator specific cookie for a given plane if
- * available, NULL otherwise. The allocator should provide some simple static
- * inline function, which would convert this cookie to the allocator specific
- * type that can be used directly by the driver to access the buffer. This can
- * be for example physical address, pointer to scatter list or IOMMU mapping.
- */
-void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
-		return NULL;
-
-	return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
-}
-EXPORT_SYMBOL_GPL(vb2_plane_cookie);
-
-/**
- * vb2_buffer_done() - inform videobuf that an operation on a buffer is finished
- * @vb:		vb2_v4l2_buffer returned from the driver
- * @state:	either VB2_BUF_STATE_DONE if the operation finished successfully
- *		or VB2_BUF_STATE_ERROR if the operation finished with an error.
- *		If start_streaming fails then it should return buffers with state
- *		VB2_BUF_STATE_QUEUED to put them back into the queue.
- *
- * This function should be called by the driver after a hardware operation on
- * a buffer is finished and the buffer may be returned to userspace. The driver
- * cannot use this buffer anymore until it is queued back to it by videobuf
- * by the means of buf_queue callback. Only buffers previously queued to the
- * driver by buf_queue can be passed to this function.
- *
- * While streaming a buffer can only be returned in state DONE or ERROR.
- * The start_streaming op can also return them in case the DMA engine cannot
- * be started for some reason. In that case the buffers should be returned with
- * state QUEUED.
- */
-void vb2_buffer_done(struct vb2_v4l2_buffer *cb, enum vb2_buffer_state state)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	struct vb2_queue *q = vb->vb2_queue;
-	unsigned long flags;
-	unsigned int plane;
-
-	if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
-		return;
-
-	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
-		    state != VB2_BUF_STATE_ERROR &&
-		    state != VB2_BUF_STATE_QUEUED))
-		state = VB2_BUF_STATE_ERROR;
-
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-	/*
-	 * Although this is not a callback, it still does have to balance
-	 * with the buf_queue op. So update this counter manually.
-	 */
-	vb->cnt_buf_done++;
-#endif
-	dprintk(4, "done processing on buffer %d, state: %d\n",
-			cb->v4l2_buf.index, state);
-
-	/* sync buffers */
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
-
-	/* Add the buffer to the done buffers list */
-	spin_lock_irqsave(&q->done_lock, flags);
-	vb->state = state;
-	if (state != VB2_BUF_STATE_QUEUED)
-		list_add_tail(&vb->done_entry, &q->done_list);
-	atomic_dec(&q->owned_by_drv_count);
-	spin_unlock_irqrestore(&q->done_lock, flags);
-
-	if (state == VB2_BUF_STATE_QUEUED)
-		return;
-
-	/* Inform any processes that may be waiting for buffers */
-	wake_up(&q->done_wq);
-}
-EXPORT_SYMBOL_GPL(vb2_buffer_done);
-
-/**
- * vb2_discard_done() - discard all buffers marked as DONE
- * @q:		videobuf2 queue
- *
- * This function is intended to be used with suspend/resume operations. It
- * discards all 'done' buffers as they would be too old to be requested after
- * resume.
- *
- * Drivers must stop the hardware and synchronize with interrupt handlers and/or
- * delayed works before calling this function to make sure no buffer will be
- * touched by the driver and/or hardware.
- */
-void vb2_discard_done(struct vb2_queue *q)
-{
-	struct vb2_buffer *vb;
-	unsigned long flags;
-
-	spin_lock_irqsave(&q->done_lock, flags);
-	list_for_each_entry(vb, &q->done_list, done_entry)
-		vb->state = VB2_BUF_STATE_ERROR;
-	spin_unlock_irqrestore(&q->done_lock, flags);
-}
-EXPORT_SYMBOL_GPL(vb2_discard_done);
-
-/**
- * __fill_vb2_buffer() - fill a vb2_v4l2_buffer with information provided in a
- * v4l2_buffer by the userspace. The caller has already verified that struct
- * v4l2_buffer has a valid number of planes.
- */
-static void __fill_vb2_buffer(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b,
-				struct v4l2_plane *v4l2_planes)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	unsigned int plane;
-
-	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
-		if (b->memory == V4L2_MEMORY_USERPTR) {
-			for (plane = 0; plane < vb->num_planes; ++plane) {
-				v4l2_planes[plane].m.userptr =
-					b->m.planes[plane].m.userptr;
-				v4l2_planes[plane].length =
-					b->m.planes[plane].length;
-			}
-		}
-		if (b->memory == V4L2_MEMORY_DMABUF) {
-			for (plane = 0; plane < vb->num_planes; ++plane) {
-				v4l2_planes[plane].m.fd =
-					b->m.planes[plane].m.fd;
-				v4l2_planes[plane].length =
-					b->m.planes[plane].length;
-			}
-		}
-
-		/* Fill in driver-provided information for OUTPUT types */
-		if (V4L2_TYPE_IS_OUTPUT(b->type)) {
-			/*
-			 * Will have to go up to b->length when API starts
-			 * accepting variable number of planes.
-			 *
-			 * If bytesused == 0 for the output buffer, then fall
-			 * back to the full buffer size. In that case
-			 * userspace clearly never bothered to set it and
-			 * it's a safe assumption that they really meant to
-			 * use the full plane sizes.
-			 */
-			for (plane = 0; plane < vb->num_planes; ++plane) {
-				struct v4l2_plane *pdst = &v4l2_planes[plane];
-				struct v4l2_plane *psrc = &b->m.planes[plane];
-
-				pdst->bytesused = psrc->bytesused ?
-					psrc->bytesused : pdst->length;
-				pdst->data_offset = psrc->data_offset;
-			}
-		}
-	} else {
-		/*
-		 * Single-planar buffers do not use planes array,
-		 * so fill in relevant v4l2_buffer struct fields instead.
-		 * In videobuf we use our internal V4l2_planes struct for
-		 * single-planar buffers as well, for simplicity.
-		 *
-		 * If bytesused == 0 for the output buffer, then fall back
-		 * to the full buffer size as that's a sensible default.
-		 */
-		if (b->memory == V4L2_MEMORY_USERPTR) {
-			v4l2_planes[0].m.userptr = b->m.userptr;
-			v4l2_planes[0].length = b->length;
-		}
-
-		if (b->memory == V4L2_MEMORY_DMABUF) {
-			v4l2_planes[0].m.fd = b->m.fd;
-			v4l2_planes[0].length = b->length;
-		}
-
-		if (V4L2_TYPE_IS_OUTPUT(b->type))
-			v4l2_planes[0].bytesused = b->bytesused ?
-				b->bytesused : v4l2_planes[0].length;
-		else
-			v4l2_planes[0].bytesused = 0;
-
-	}
-
-	/* Zero flags that the vb2 core handles */
-	cb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
-	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
-	    V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
-		/*
-		 * Non-COPY timestamps and non-OUTPUT queues will get
-		 * their timestamp and timestamp source flags from the
-		 * queue.
-		 */
-		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
-	}
-
-	if (V4L2_TYPE_IS_OUTPUT(b->type)) {
-		/*
-		 * For output buffers mask out the timecode flag:
-		 * this will be handled later in vb2_internal_qbuf().
-		 * The 'field' is valid metadata for this output buffer
-		 * and so that needs to be copied here.
-		 */
-		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
-		cb->v4l2_buf.field = b->field;
-	} else {
-		/* Zero any output buffer flags as this is a capture buffer */
-		cb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
-	}
-}
-
-/**
- * __qbuf_mmap() - handle qbuf of an MMAP buffer
- */
-static int __qbuf_mmap(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	__fill_vb2_buffer(cb, b, cb->v4l2_planes);
-	return call_vb_qop(vb, buf_prepare, vb);
-}
-
-/**
- * __qbuf_userptr() - handle qbuf of a USERPTR buffer
- */
-static int __qbuf_userptr(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	struct v4l2_plane planes[VIDEO_MAX_PLANES];
-	struct vb2_queue *q = vb->vb2_queue;
-	void *mem_priv;
-	unsigned int plane;
-	int ret;
-	enum dma_data_direction dma_dir =
-		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-	bool reacquired = vb->planes[0].mem_priv == NULL;
-
-	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
-	/* Copy relevant information provided by the userspace */
-	__fill_vb2_buffer(cb, b, planes);
-
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		/* Skip the plane if already verified */
-		if (cb->v4l2_planes[plane].m.userptr &&
-		    cb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
-		    && cb->v4l2_planes[plane].length == planes[plane].length)
-			continue;
-
-		dprintk(3, "userspace address for plane %d changed, "
-				"reacquiring memory\n", plane);
-
-		/* Check if the provided plane buffer is large enough */
-		if (planes[plane].length < q->plane_sizes[plane]) {
-			dprintk(1, "provided buffer size %u is less than "
-						"setup size %u for plane %d\n",
-						planes[plane].length,
-						q->plane_sizes[plane], plane);
-			ret = -EINVAL;
-			goto err;
-		}
-
-		/* Release previously acquired memory if present */
-		if (vb->planes[plane].mem_priv) {
-			if (!reacquired) {
-				reacquired = true;
-				call_void_vb_qop(vb, buf_cleanup, vb);
-			}
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
-		}
-
-		vb->planes[plane].mem_priv = NULL;
-		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
-
-		/* Acquire each plane's memory */
-		mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane],
-				      planes[plane].m.userptr,
-				      planes[plane].length, dma_dir);
-		if (IS_ERR_OR_NULL(mem_priv)) {
-			dprintk(1, "failed acquiring userspace "
-						"memory for plane %d\n", plane);
-			ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
-			goto err;
-		}
-		vb->planes[plane].mem_priv = mem_priv;
-	}
-
-	/*
-	 * Now that everything is in order, copy relevant information
-	 * provided by userspace.
-	 */
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		cb->v4l2_planes[plane] = planes[plane];
-
-	if (reacquired) {
-		/*
-		 * One or more planes changed, so we must call buf_init to do
-		 * the driver-specific initialization on the newly acquired
-		 * buffer, if provided.
-		 */
-		ret = call_vb_qop(vb, buf_init, vb);
-		if (ret) {
-			dprintk(1, "buffer initialization failed\n");
-			goto err;
-		}
-	}
-
-	ret = call_vb_qop(vb, buf_prepare, vb);
-	if (ret) {
-		dprintk(1, "buffer preparation failed\n");
-		call_void_vb_qop(vb, buf_cleanup, vb);
-		goto err;
-	}
-
-	return 0;
-err:
-	/* In case of errors, release planes that were already acquired */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		if (vb->planes[plane].mem_priv)
-			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
-		vb->planes[plane].mem_priv = NULL;
-		cb->v4l2_planes[plane].m.userptr = 0;
-		cb->v4l2_planes[plane].length = 0;
-	}
-
-	return ret;
-}
-
-/**
- * __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
- */
-static int __qbuf_dmabuf(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	struct v4l2_plane planes[VIDEO_MAX_PLANES];
-	struct vb2_queue *q = vb->vb2_queue;
-	void *mem_priv;
-	unsigned int plane;
-	int ret;
-	enum dma_data_direction dma_dir =
-		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
-	bool reacquired = vb->planes[0].mem_priv == NULL;
-
-	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
-	/* Copy relevant information provided by the userspace */
-	__fill_vb2_buffer(cb, b, planes);
-
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
-
-		if (IS_ERR_OR_NULL(dbuf)) {
-			dprintk(1, "invalid dmabuf fd for plane %d\n",
-				plane);
-			ret = -EINVAL;
-			goto err;
-		}
-
-		/* use DMABUF size if length is not provided */
-		if (planes[plane].length == 0)
-			planes[plane].length = dbuf->size;
-
-		if (planes[plane].length < q->plane_sizes[plane]) {
-			dprintk(1, "invalid dmabuf length for plane %d\n",
-				plane);
-			ret = -EINVAL;
-			goto err;
-		}
-
-		/* Skip the plane if already verified */
-		if (dbuf == vb->planes[plane].dbuf &&
-		    cb->v4l2_planes[plane].length == planes[plane].length) {
-			dma_buf_put(dbuf);
-			continue;
-		}
-
-		dprintk(1, "buffer for plane %d changed\n", plane);
-
-		if (!reacquired) {
-			reacquired = true;
-			call_void_vb_qop(vb, buf_cleanup, vb);
-		}
-
-		/* Release previously acquired memory if present */
-		__vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
-		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
-
-		/* Acquire each plane's memory */
-		mem_priv = call_ptr_memop(vb, attach_dmabuf, q->alloc_ctx[plane],
-			dbuf, planes[plane].length, dma_dir);
-		if (IS_ERR(mem_priv)) {
-			dprintk(1, "failed to attach dmabuf\n");
-			ret = PTR_ERR(mem_priv);
-			dma_buf_put(dbuf);
-			goto err;
-		}
-
-		vb->planes[plane].dbuf = dbuf;
-		vb->planes[plane].mem_priv = mem_priv;
-	}
-
-	/* TODO: This pins the buffer(s) with  dma_buf_map_attachment()).. but
-	 * really we want to do this just before the DMA, not while queueing
-	 * the buffer(s)..
-	 */
-	for (plane = 0; plane < vb->num_planes; ++plane) {
-		ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
-		if (ret) {
-			dprintk(1, "failed to map dmabuf for plane %d\n",
-				plane);
-			goto err;
-		}
-		vb->planes[plane].dbuf_mapped = 1;
-	}
-
-	/*
-	 * Now that everything is in order, copy relevant information
-	 * provided by userspace.
-	 */
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		cb->v4l2_planes[plane] = planes[plane];
-
-	if (reacquired) {
-		/*
-		 * Call driver-specific initialization on the newly acquired buffer,
-		 * if provided.
-		 */
-		ret = call_vb_qop(vb, buf_init, vb);
-		if (ret) {
-			dprintk(1, "buffer initialization failed\n");
-			goto err;
-		}
+	if (buf->pos + count > buf->size) {
+		count = buf->size - buf->pos;
+		dprintk(5, "reducing read count: %zd\n", count);
 	}
 
-	ret = call_vb_qop(vb, buf_prepare, vb);
+	/*
+	 * Transfer data to userspace.
+	 */
+	dprintk(3, "copying %zd bytes - buffer %d, offset %u\n",
+		count, index, buf->pos);
+	if (read)
+		ret = copy_to_user(data, buf->vaddr + buf->pos, count);
+	else
+		ret = copy_from_user(buf->vaddr + buf->pos, data, count);
 	if (ret) {
-		dprintk(1, "buffer preparation failed\n");
-		call_void_vb_qop(vb, buf_cleanup, vb);
-		goto err;
-	}
-
-	return 0;
-err:
-	/* In case of errors, release planes that were already acquired */
-	__vb2_buf_dmabuf_put(cb);
-
-	return ret;
-}
-
-/**
- * __enqueue_in_driver() - enqueue a vb2_v4l2_buffer in driver for processing
- */
-static void __enqueue_in_driver(struct vb2_buffer *vb)
-{
-	struct vb2_queue *q = vb->vb2_queue;
-	unsigned int plane;
-
-	vb->state = VB2_BUF_STATE_ACTIVE;
-	atomic_inc(&q->owned_by_drv_count);
-
-	/* sync buffers */
-	for (plane = 0; plane < vb->num_planes; ++plane)
-		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
-
-	call_void_vb_qop(vb, buf_queue, vb);
-}
-
-static int __buf_prepare(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
-{
-	struct vb2_buffer *vb = &cb->vb2;
-	struct vb2_queue *q = vb->vb2_queue;
-	int ret;
-
-	ret = __verify_length(cb, b);
-	if (ret < 0) {
-		dprintk(1, "plane parameters verification failed: %d\n", ret);
-		return ret;
-	}
-	if (b->field == V4L2_FIELD_ALTERNATE && V4L2_TYPE_IS_OUTPUT(q->type)) {
-		/*
-		 * If the format's field is ALTERNATE, then the buffer's field
-		 * should be either TOP or BOTTOM, not ALTERNATE since that
-		 * makes no sense. The driver has to know whether the
-		 * buffer represents a top or a bottom field in order to
-		 * program any DMA correctly. Using ALTERNATE is wrong, since
-		 * that just says that it is either a top or a bottom field,
-		 * but not which of the two it is.
-		 */
-		dprintk(1, "the field is incorrectly set to ALTERNATE for an output buffer\n");
-		return -EINVAL;
-	}
-
-	if (q->error) {
-		dprintk(1, "fatal error occurred on queue\n");
-		return -EIO;
-	}
-
-	vb->state = VB2_BUF_STATE_PREPARING;
-	cb->v4l2_buf.timestamp.tv_sec = 0;
-	cb->v4l2_buf.timestamp.tv_usec = 0;
-	cb->v4l2_buf.sequence = 0;
-
-	switch (q->memory) {
-	case V4L2_MEMORY_MMAP:
-		ret = __qbuf_mmap(cb, b);
-		break;
-	case V4L2_MEMORY_USERPTR:
-		down_read(&current->mm->mmap_sem);
-		ret = __qbuf_userptr(cb, b);
-		up_read(&current->mm->mmap_sem);
-		break;
-	case V4L2_MEMORY_DMABUF:
-		ret = __qbuf_dmabuf(cb, b);
-		break;
-	default:
-		WARN(1, "Invalid queue type\n");
-		ret = -EINVAL;
-	}
-
-	if (ret)
-		dprintk(1, "buffer preparation failed: %d\n", ret);
-	vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
-
-	return ret;
-}
-
-static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
-				    const char *opname)
-{
-	struct vb2_v4l2_buffer *cb;
-
-	if (b->type != q->type) {
-		dprintk(1, "%s: invalid buffer type\n", opname);
-		return -EINVAL;
-	}
-
-	if (b->index >= q->num_buffers) {
-		dprintk(1, "%s: buffer index out of range\n", opname);
-		return -EINVAL;
-	}
-
-	if (q->bufs[b->index] == NULL) {
-		/* Should never happen */
-		dprintk(1, "%s: buffer is NULL\n", opname);
-		return -EINVAL;
-	}
-
-	if (b->memory != q->memory) {
-		dprintk(1, "%s: invalid memory type\n", opname);
-		return -EINVAL;
-	}
-
-	cb = container_of(q->bufs[b->index], struct vb2_v4l2_buffer, vb2);
-
-	return __verify_planes_array(cb, b);
-}
-
-/**
- * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel
- * @q:		videobuf2 queue
- * @b:		buffer structure passed from userspace to vidioc_prepare_buf
- *		handler in driver
- *
- * Should be called from vidioc_prepare_buf ioctl handler of a driver.
- * This function:
- * 1) verifies the passed buffer,
- * 2) calls buf_prepare callback in the driver (if provided), in which
- *    driver-specific buffer initialization can be performed,
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_prepare_buf handler in driver.
- */
-int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
-{
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	int ret;
-
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
-		return -EBUSY;
-	}
-
-	ret = vb2_queue_or_prepare_buf(q, b, "prepare_buf");
-	if (ret)
-		return ret;
-
-	vb = q->bufs[b->index];
-	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
-		dprintk(1, "invalid buffer state %d\n",
-			vb->state);
-		return -EINVAL;
-	}
-
-	ret = __buf_prepare(cb, b);
-	if (!ret) {
-		/* Fill buffer information for the userspace */
-		__fill_v4l2_buffer(cb, b);
-
-		dprintk(1, "prepare of buffer %d succeeded\n", cb->v4l2_buf.index);
+		dprintk(3, "error copying data\n");
+		return -EFAULT;
 	}
-	return ret;
-}
-EXPORT_SYMBOL_GPL(vb2_prepare_buf);
-
-/**
- * vb2_start_streaming() - Attempt to start streaming.
- * @q:		videobuf2 queue
- *
- * Attempt to start streaming. When this function is called there must be
- * at least q->min_buffers_needed buffers queued up (i.e. the minimum
- * number of buffers required for the DMA engine to function). If the
- * @start_streaming op fails it is supposed to return all the driver-owned
- * buffers back to vb2 in state QUEUED. Check if that happened and if
- * not warn and reclaim them forcefully.
- */
-static int vb2_start_streaming(struct vb2_queue *q)
-{
-	struct vb2_buffer *vb;
-	struct vb2_v4l2_buffer *cb;
-	int ret;
 
 	/*
-	 * If any buffers were queued before streamon,
-	 * we can now pass them to driver for processing.
+	 * Update counters.
 	 */
-	list_for_each_entry(vb, &q->queued_list, queued_entry)
-		__enqueue_in_driver(vb);
-
-	/* Tell the driver to start streaming */
-	q->start_streaming_called = 1;
-	ret = call_qop(q, start_streaming, q,
-		       atomic_read(&q->owned_by_drv_count));
-	if (!ret)
-		return 0;
-
-	q->start_streaming_called = 0;
+	buf->pos += count;
+	*ppos += count;
 
-	dprintk(1, "driver refused to start streaming\n");
 	/*
-	 * If you see this warning, then the driver isn't cleaning up properly
-	 * after a failed start_streaming(). See the start_streaming()
-	 * documentation in videobuf2-core.h for more information how buffers
-	 * should be returned to vb2 in start_streaming().
+	 * Queue next buffer if required.
 	 */
-	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
-		unsigned i;
-
+	if (buf->pos == buf->size ||
+	   (!read && (fileio->flags & VB2_FILEIO_WRITE_IMMEDIATELY))) {
 		/*
-		 * Forcefully reclaim buffers if the driver did not
-		 * correctly return them to vb2.
+		 * Check if this is the last buffer to read.
 		 */
-		for (i = 0; i < q->num_buffers; ++i) {
-			vb = q->bufs[i];
-			cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-			if (vb->state == VB2_BUF_STATE_ACTIVE)
-				vb2_buffer_done(cb, VB2_BUF_STATE_QUEUED);
+		if (read && (fileio->flags & VB2_FILEIO_READ_ONCE) &&
+		    fileio->dq_count == 1) {
+			dprintk(3, "read limit reached\n");
+			return __vb2_cleanup_fileio(q);
 		}
-		/* Must be zero now */
-		WARN_ON(atomic_read(&q->owned_by_drv_count));
-	}
-	/*
-	 * If done_list is not empty, then start_streaming() didn't call
-	 * vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED) but STATE_ERROR or
-	 * STATE_DONE.
-	 */
-	WARN_ON(!list_empty(&q->done_list));
-	return ret;
-}
-
-static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
-{
-	int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-
-	if (ret)
-		return ret;
-
-	vb = q->bufs[b->index];
-	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-
-	switch (vb->state) {
-	case VB2_BUF_STATE_DEQUEUED:
-		ret = __buf_prepare(cb, b);
-		if (ret)
-			return ret;
-		break;
-	case VB2_BUF_STATE_PREPARED:
-		break;
-	case VB2_BUF_STATE_PREPARING:
-		dprintk(1, "buffer still being prepared\n");
-		return -EINVAL;
-	default:
-		dprintk(1, "invalid buffer state %d\n", vb->state);
-		return -EINVAL;
-	}
 
-	/*
-	 * Add to the queued buffers list, a buffer will stay on it until
-	 * dequeued in dqbuf.
-	 */
-	list_add_tail(&vb->queued_entry, &q->queued_list);
-	q->queued_count++;
-	q->waiting_for_buffers = false;
-	vb->state = VB2_BUF_STATE_QUEUED;
-	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
 		/*
-		 * For output buffers copy the timestamp if needed,
-		 * and the timecode field and flag if needed.
+		 * Call vb2_qbuf and give buffer to the driver.
 		 */
-		if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
-		    V4L2_BUF_FLAG_TIMESTAMP_COPY)
-			cb->v4l2_buf.timestamp = b->timestamp;
-		cb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
-		if (b->flags & V4L2_BUF_FLAG_TIMECODE)
-			cb->v4l2_buf.timecode = b->timecode;
-	}
-
-	/*
-	 * If already streaming, give the buffer to driver for processing.
-	 * If not, the buffer will be given to driver on next streamon.
-	 */
-	if (q->start_streaming_called)
-		__enqueue_in_driver(vb);
-
-	/* Fill buffer information for the userspace */
-	__fill_v4l2_buffer(cb, b);
-
-	/*
-	 * If streamon has been called, and we haven't yet called
-	 * start_streaming() since not enough buffers were queued, and
-	 * we now have reached the minimum number of queued buffers,
-	 * then we can finally call start_streaming().
-	 */
-	if (q->streaming && !q->start_streaming_called &&
-	    q->queued_count >= q->min_buffers_needed) {
-		ret = vb2_start_streaming(q);
+		memset(&fileio->b, 0, sizeof(fileio->b));
+		fileio->b.type = q->type;
+		fileio->b.memory = q->memory;
+		fileio->b.index = index;
+		fileio->b.bytesused = buf->pos;
+		if (is_multiplanar) {
+			memset(&fileio->p, 0, sizeof(fileio->p));
+			fileio->p.bytesused = buf->pos;
+			fileio->b.m.planes = &fileio->p;
+			fileio->b.length = 1;
+		}
+		if (set_timestamp)
+			v4l2_get_timestamp(&fileio->b.timestamp);
+		ret = vb2_internal_qbuf(q, q->type, index, q->memory, &fileio->b);
+		dprintk(5, "vb2_dbuf result: %d\n", ret);
 		if (ret)
 			return ret;
-	}
-
-	dprintk(1, "qbuf of buffer %d succeeded\n", cb->v4l2_buf.index);
-	return 0;
-}
-
-/**
- * vb2_qbuf() - Queue a buffer from userspace
- * @q:		videobuf2 queue
- * @b:		buffer structure passed from userspace to vidioc_qbuf handler
- *		in driver
- *
- * Should be called from vidioc_qbuf ioctl handler of a driver.
- * This function:
- * 1) verifies the passed buffer,
- * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
- *    which driver-specific buffer initialization can be performed,
- * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
- *    callback for processing.
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_qbuf handler in driver.
- */
-int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
-{
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
-		return -EBUSY;
-	}
-
-	return vb2_internal_qbuf(q, b);
-}
-EXPORT_SYMBOL_GPL(vb2_qbuf);
-
-/**
- * __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)
-{
-	/*
-	 * All operations on vb_done_list are performed under done_lock
-	 * spinlock protection. However, buffers may be removed from
-	 * it and returned to userspace only while holding both driver's
-	 * lock and the done_lock spinlock. Thus we can be sure that as
-	 * long as we hold the driver's lock, the list will remain not
-	 * empty if list_empty() check succeeds.
-	 */
-
-	for (;;) {
-		int ret;
-
-		if (!q->streaming) {
-			dprintk(1, "streaming off, will not wait for buffers\n");
-			return -EINVAL;
-		}
-
-		if (q->error) {
-			dprintk(1, "Queue in error state, will not wait for buffers\n");
-			return -EIO;
-		}
-
-		if (!list_empty(&q->done_list)) {
-			/*
-			 * Found a buffer that we were waiting for.
-			 */
-			break;
-		}
-
-		if (nonblocking) {
-			dprintk(1, "nonblocking and no buffers to dequeue, "
-								"will not wait\n");
-			return -EAGAIN;
-		}
 
 		/*
-		 * We are streaming and blocking, wait for another buffer to
-		 * become ready or for streamoff. Driver's lock is released to
-		 * allow streamoff or qbuf to be called while waiting.
+		 * Buffer has been queued, update the status
 		 */
-		call_void_qop(q, wait_prepare, q);
-
+		buf->pos = 0;
+		buf->queued = 1;
+		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
+		buf->size = vb2_plane_size(cb, 0);
+		fileio->q_count += 1;
 		/*
-		 * All locks have been released, it is safe to sleep now.
+		 * If we are queuing up buffers for the first time, then
+		 * increase initial_index by one.
 		 */
-		dprintk(3, "will sleep waiting for buffers\n");
-		ret = wait_event_interruptible(q->done_wq,
-				!list_empty(&q->done_list) || !q->streaming ||
-				q->error);
-
+		if (fileio->initial_index < q->num_buffers)
+			fileio->initial_index++;
 		/*
-		 * We need to reevaluate both conditions again after reacquiring
-		 * the locks or return an error if one occurred.
+		 * The next buffer to use is either a buffer that's going to be
+		 * queued for the first time (initial_index < q->num_buffers)
+		 * or it is equal to q->num_buffers, meaning that the next
+		 * time we need to dequeue a buffer since we've now queued up
+		 * all the 'first time' buffers.
 		 */
-		call_void_qop(q, wait_finish, q);
-		if (ret) {
-			dprintk(1, "sleep was interrupted\n");
-			return ret;
-		}
+		fileio->cur_index = fileio->initial_index;
 	}
-	return 0;
-}
-
-/**
- * __vb2_get_done_vb() - get a buffer ready for dequeuing
- *
- * Will sleep if required for nonblocking == false.
- */
-static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **cb,
-				struct v4l2_buffer *b, int nonblocking)
-{
-	unsigned long flags;
-	int ret;
-	struct vb2_buffer *vb = NULL;
-
-	/*
-	 * Wait for at least one buffer to become available on the done_list.
-	 */
-	ret = __vb2_wait_for_done_vb(q, nonblocking);
-	if (ret)
-		return ret;
 
 	/*
-	 * Driver's lock has been held since we last verified that done_list
-	 * is not empty, so no need for another list_empty(done_list) check.
-	 */
-	spin_lock_irqsave(&q->done_lock, flags);
-	vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
-	*cb = container_of(vb, struct vb2_v4l2_buffer, vb2); 
-	/*
-	 * Only remove the buffer from done_list if v4l2_buffer can handle all
-	 * the planes.
+	 * Return proper number of bytes processed.
 	 */
-	ret = __verify_planes_array(*cb, b);
-	if (!ret)
-		list_del(&vb->done_entry);
-	spin_unlock_irqrestore(&q->done_lock, flags);
-
+	if (ret == 0)
+		ret = count;
 	return ret;
 }
 
-/**
- * vb2_wait_for_all_buffers() - wait until all buffers are given back to vb2
- * @q:		videobuf2 queue
- *
- * This function will wait until all buffers that have been given to the driver
- * by buf_queue() are given back to vb2 with vb2_buffer_done(). It doesn't call
- * wait_prepare, wait_finish pair. It is intended to be called with all locks
- * taken, for example from stop_streaming() callback.
- */
-int vb2_wait_for_all_buffers(struct vb2_queue *q)
+size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
+		loff_t *ppos, int nonblocking)
 {
-	if (!q->streaming) {
-		dprintk(1, "streaming off, will not wait for buffers\n");
-		return -EINVAL;
-	}
-
-	if (q->start_streaming_called)
-		wait_event(q->done_wq, !atomic_read(&q->owned_by_drv_count));
-	return 0;
+	return __vb2_perform_fileio(q, data, count, ppos, nonblocking, 1);
 }
-EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
+EXPORT_SYMBOL_GPL(vb2_read);
 
-/**
- * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
- */
-static void __vb2_dqbuf(struct vb2_v4l2_buffer *cb)
+size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
+		loff_t *ppos, int nonblocking)
 {
-	struct vb2_buffer *vb = &cb->vb2;
-	struct vb2_queue *q = vb->vb2_queue;
-	unsigned int i;
-
-	/* nothing to do if the buffer is already dequeued */
-	if (vb->state == VB2_BUF_STATE_DEQUEUED)
-		return;
-
-	vb->state = VB2_BUF_STATE_DEQUEUED;
-
-	/* unmap DMABUF buffer */
-	if (q->memory == V4L2_MEMORY_DMABUF)
-		for (i = 0; i < vb->num_planes; ++i) {
-			if (!vb->planes[i].dbuf_mapped)
-				continue;
-			call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
-			vb->planes[i].dbuf_mapped = 0;
-		}
+	return __vb2_perform_fileio(q, (char __user *) data, count,
+							ppos, nonblocking, 0);
 }
+EXPORT_SYMBOL_GPL(vb2_write);
+
+struct vb2_threadio_data {
+	struct task_struct *thread;
+	vb2_thread_fnc fnc;
+	void *priv;
+	bool stop;
+};
 
-static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
+static int vb2_thread(void *data)
 {
-	struct vb2_v4l2_buffer *cb = NULL;
-	struct vb2_buffer *vb = NULL;
-	int ret;
+	struct vb2_queue *q = data;
+	struct vb2_threadio_data *threadio = q->threadio;
+	struct vb2_fileio_data *fileio = q->fileio;
+	bool set_timestamp = false;
+	int prequeue = 0;
+	int index = 0;
+	int ret = 0;
 
-	if (b->type != q->type) {
-		dprintk(1, "invalid buffer type\n");
-		return -EINVAL;
+	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+		prequeue = q->num_buffers;
+		set_timestamp =
+			(q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
+			V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	}
-	ret = __vb2_get_done_vb(q, &cb, b, nonblocking);
-	if (ret < 0)
-		return ret;
 
-	vb = &cb->vb2;
-
-	switch (vb->state) {
-	case VB2_BUF_STATE_DONE:
-		dprintk(3, "returning done buffer\n");
-		break;
-	case VB2_BUF_STATE_ERROR:
-		dprintk(3, "returning done buffer with errors\n");
-		break;
-	default:
-		dprintk(1, "invalid buffer state\n");
-		return -EINVAL;
-	}
+	set_freezable();
 
-	call_void_vb_qop(vb, buf_finish, vb);
+	for (;;) {
+		struct vb2_buffer *vb;
 
-	/* Fill buffer information for the userspace */
-	__fill_v4l2_buffer(cb, b);
-	/* Remove from videobuf queue */
-	list_del(&vb->queued_entry);
-	q->queued_count--;
-	/* go back to dequeued state */
-	__vb2_dqbuf(cb);
+		/*
+		 * Call vb2_dqbuf to get buffer back.
+		 */
+		memset(&fileio->b, 0, sizeof(fileio->b));
+		fileio->b.type = q->type;
+		fileio->b.memory = q->memory;
+		if (prequeue) {
+			fileio->b.index = index++;
+			prequeue--;
+		} else {
+			call_void_qop(q, wait_finish, q);
+			if (!threadio->stop)
+				ret = vb2_internal_dqbuf(q, q->type, &fileio->b, 0);
+			call_void_qop(q, wait_prepare, q);
+			dprintk(5, "file io: vb2_dqbuf result: %d\n", ret);
+		}
+		if (ret || threadio->stop)
+			break;
+		try_to_freeze();
 
-	dprintk(1, "dqbuf of buffer %d, with state %d\n",
-			cb->v4l2_buf.index, vb->state);
+		vb = q->bufs[fileio->b.index];
+		if (!(fileio->b.flags & V4L2_BUF_FLAG_ERROR))
+			if (threadio->fnc(vb, threadio->priv))
+				break;
+		call_void_qop(q, wait_finish, q);
+		if (set_timestamp)
+			v4l2_get_timestamp(&fileio->b.timestamp);
+		if (!threadio->stop)
+			ret = vb2_internal_qbuf(q, q->type, fileio->b.index, fileio->b.memory, &fileio->b);
+		call_void_qop(q, wait_prepare, q);
+		if (ret || threadio->stop)
+			break;
+	}
 
+	/* Hmm, linux becomes *very* unhappy without this ... */
+	while (!kthread_should_stop()) {
+		set_current_state(TASK_INTERRUPTIBLE);
+		schedule();
+	}
 	return 0;
 }
 
-/**
- * vb2_dqbuf() - Dequeue a buffer to the userspace
- * @q:		videobuf2 queue
- * @b:		buffer structure passed from userspace to vidioc_dqbuf handler
- *		in driver
- * @nonblocking: if true, this call will not sleep waiting for a buffer if no
- *		 buffers ready for dequeuing are present. Normally the driver
- *		 would be passing (file->f_flags & O_NONBLOCK) here
- *
- * Should be called from vidioc_dqbuf ioctl handler of a driver.
- * This function:
- * 1) verifies the passed buffer,
- * 2) calls buf_finish callback in the driver (if provided), in which
- *    driver can perform any additional operations that may be required before
- *    returning the buffer to userspace, such as cache sync,
- * 3) the buffer struct members are filled with relevant information for
- *    the userspace.
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_dqbuf handler in driver.
+/*
+ * This function should not be used for anything else but the videobuf2-dvb
+ * support. If you think you have another good use-case for this, then please
+ * contact the linux-media mailinglist first.
  */
-int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
+int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
+		     const char *thread_name)
 {
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
-		return -EBUSY;
-	}
-	return vb2_internal_dqbuf(q, b, nonblocking);
-}
-EXPORT_SYMBOL_GPL(vb2_dqbuf);
+	struct vb2_threadio_data *threadio;
+	int ret = 0;
 
-/**
- * __vb2_queue_cancel() - cancel and stop (pause) streaming
- *
- * Removes all queued buffers from driver's queue and all buffers queued by
- * userspace from videobuf's queue. Returns to state after reqbufs.
- */
-static void __vb2_queue_cancel(struct vb2_queue *q)
-{
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	unsigned int i;
+	if (q->threadio)
+		return -EBUSY;
+	if (vb2_is_busy(q))
+		return -EBUSY;
+	if (WARN_ON(q->fileio))
+		return -EBUSY;
 
-	/*
-	 * Tell driver to stop all transactions and release all queued
-	 * buffers.
-	 */
-	if (q->start_streaming_called)
-		call_void_qop(q, stop_streaming, q);
+	threadio = kzalloc(sizeof(*threadio), GFP_KERNEL);
+	if (threadio == NULL)
+		return -ENOMEM;
+	threadio->fnc = fnc;
+	threadio->priv = priv;
 
-	/*
-	 * If you see this warning, then the driver isn't cleaning up properly
-	 * in stop_streaming(). See the stop_streaming() documentation in
-	 * videobuf2-core.h for more information how buffers should be returned
-	 * to vb2 in stop_streaming().
-	 */
-	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
-		for (i = 0; i < q->num_buffers; ++i)
-		{
-			vb = q->bufs[i];
-			cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-			if (vb->state == VB2_BUF_STATE_ACTIVE)
-				vb2_buffer_done(cb, VB2_BUF_STATE_ERROR);
-		}
-		/* Must be zero now */
-		WARN_ON(atomic_read(&q->owned_by_drv_count));
+	ret = __vb2_init_fileio(q, !V4L2_TYPE_IS_OUTPUT(q->type));
+	dprintk(3, "file io: vb2_init_fileio result: %d\n", ret);
+	if (ret)
+		goto nomem;
+	q->threadio = threadio;
+	threadio->thread = kthread_run(vb2_thread, q, "vb2-%s", thread_name);
+	if (IS_ERR(threadio->thread)) {
+		ret = PTR_ERR(threadio->thread);
+		threadio->thread = NULL;
+		goto nothread;
 	}
+	return 0;
 
-	q->streaming = 0;
-	q->start_streaming_called = 0;
-	q->queued_count = 0;
-	q->error = 0;
-
-	/*
-	 * Remove all buffers from videobuf's list...
-	 */
-	INIT_LIST_HEAD(&q->queued_list);
-	/*
-	 * ...and done list; userspace will not receive any buffers it
-	 * has not already dequeued before initiating cancel.
-	 */
-	INIT_LIST_HEAD(&q->done_list);
-	atomic_set(&q->owned_by_drv_count, 0);
-	wake_up_all(&q->done_wq);
-
-	/*
-	 * Reinitialize all buffers for next use.
-	 * Make sure to call buf_finish for any queued buffers. Normally
-	 * that's done in dqbuf, but that's not going to happen when we
-	 * cancel the whole queue. Note: this code belongs here, not in
-	 * __vb2_dqbuf() since in vb2_internal_dqbuf() there is a critical
-	 * call to __fill_v4l2_buffer() after buf_finish(). That order can't
-	 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
-	 */
-	for (i = 0; i < q->num_buffers; ++i) {
-		struct vb2_buffer *vb = q->bufs[i];
-		struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-
-		if (vb->state != VB2_BUF_STATE_DEQUEUED) {
-			vb->state = VB2_BUF_STATE_PREPARED;
-			call_void_vb_qop(vb, buf_finish, vb);
-		}
-		__vb2_dqbuf(cb);
-	}
+nothread:
+	__vb2_cleanup_fileio(q);
+nomem:
+	kfree(threadio);
+	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_thread_start);
 
-static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
+int vb2_thread_stop(struct vb2_queue *q)
 {
-	int ret;
-
-	if (type != q->type) {
-		dprintk(1, "invalid stream type\n");
-		return -EINVAL;
-	}
+	struct vb2_threadio_data *threadio = q->threadio;
+	int err;
 
-	if (q->streaming) {
-		dprintk(3, "already streaming\n");
+	if (threadio == NULL)
 		return 0;
-	}
-
-	if (!q->num_buffers) {
-		dprintk(1, "no buffers have been allocated\n");
-		return -EINVAL;
-	}
-
-	if (q->num_buffers < q->min_buffers_needed) {
-		dprintk(1, "need at least %u allocated buffers\n",
-				q->min_buffers_needed);
-		return -EINVAL;
-	}
-
-	/*
-	 * Tell driver to start streaming provided sufficient buffers
-	 * are available.
-	 */
-	if (q->queued_count >= q->min_buffers_needed) {
-		ret = vb2_start_streaming(q);
-		if (ret) {
-			__vb2_queue_cancel(q);
-			return ret;
-		}
-	}
+	threadio->stop = true;
+	/* Wake up all pending sleeps in the thread */
+	vb2_queue_error(q);
+	err = kthread_stop(threadio->thread);
+	__vb2_cleanup_fileio(q);
+	threadio->thread = NULL;
+	kfree(threadio);
+	q->threadio = NULL;
+	return err;
+}
+EXPORT_SYMBOL_GPL(vb2_thread_stop);
 
-	q->streaming = 1;
+/*
+ * The following functions are not part of the vb2 core API, but are helper
+ * functions that plug into struct v4l2_ioctl_ops, struct v4l2_file_operations
+ * and struct vb2_ops.
+ * They contain boilerplate code that most if not all drivers have to do
+ * and so they simplify the driver code.
+ */
 
-	dprintk(3, "successful\n");
-	return 0;
+/* The queue is busy if there is a owner and you are not that owner. */
+static bool vb2_queue_is_busy(struct video_device *vdev, struct file *file)
+{
+	return vdev->queue->owner && vdev->queue->owner != file->private_data;
 }
 
-/**
- * vb2_queue_error() - signal a fatal error on the queue
- * @q:		videobuf2 queue
- *
- * Flag that a fatal unrecoverable error has occurred and wake up all processes
- * waiting on the queue. Polling will now set POLLERR and queuing and dequeuing
- * buffers will return -EIO.
- *
- * The error flag will be cleared when cancelling the queue, either from
- * vb2_streamoff or vb2_queue_release. Drivers should thus not call this
- * function before starting the stream, otherwise the error flag will remain set
- * until the queue is released when closing the device node.
- */
-void vb2_queue_error(struct vb2_queue *q)
+/* vb2 ioctl helpers */
+
+int vb2_ioctl_reqbufs(struct file *file, void *priv,
+			  struct v4l2_requestbuffers *p)
 {
-	q->error = 1;
+	struct video_device *vdev = video_devdata(file);
+	int res = __verify_memory_type(vdev->queue, p->memory, p->type);
 
-	wake_up_all(&q->done_wq);
+	if (res)
+		return res;
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	res = __reqbufs(vdev->queue, p->count, p->type, p->memory);
+	/* If count == 0, then the owner has released all buffers and he
+	   is no longer owner of the queue. Otherwise we have a new owner. */
+	if (res == 0)
+		vdev->queue->owner = p->count ? file->private_data : NULL;
+	return res;
 }
-EXPORT_SYMBOL_GPL(vb2_queue_error);
+EXPORT_SYMBOL_GPL(vb2_ioctl_reqbufs);
 
-/**
- * vb2_streamon - start streaming
- * @q:		videobuf2 queue
- * @type:	type argument passed from userspace to vidioc_streamon handler
- *
- * Should be called from vidioc_streamon handler of a driver.
- * This function:
- * 1) verifies current state
- * 2) passes any previously queued buffers to the driver and starts streaming
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_streamon handler in the driver.
- */
-int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
+int vb2_ioctl_create_bufs(struct file *file, void *priv,
+			  struct v4l2_create_buffers *p)
 {
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
+	struct video_device *vdev = video_devdata(file);
+	int res = __verify_memory_type(vdev->queue, p->memory, p->format.type);
+
+	p->index = vdev->queue->num_buffers;
+	/* If count == 0, then just check if memory and type are valid.
+	   Any -EBUSY result from __verify_memory_type can be mapped to 0. */
+	if (p->count == 0)
+		return res != -EBUSY ? res : 0;
+	if (res)
+		return res;
+	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	}
-	return vb2_internal_streamon(q, type);
+	res = __create_bufs(vdev->queue, p->count, p->format.type, p->memory, &p->format);
+	if (res == 0)
+		vdev->queue->owner = file->private_data;
+	return res;
 }
-EXPORT_SYMBOL_GPL(vb2_streamon);
+EXPORT_SYMBOL_GPL(vb2_ioctl_create_bufs);
 
-static int vb2_internal_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
+int vb2_ioctl_prepare_buf(struct file *file, void *priv,
+			  struct v4l2_buffer *p)
 {
-	if (type != q->type) {
-		dprintk(1, "invalid stream type\n");
-		return -EINVAL;
-	}
-
-	/*
-	 * Cancel will pause streaming and remove all buffers from the driver
-	 * and videobuf, effectively returning control over them to userspace.
-	 *
-	 * Note that we do this even if q->streaming == 0: if you prepare or
-	 * queue buffers, and then call streamoff without ever having called
-	 * streamon, you would still expect those buffers to be returned to
-	 * their normal dequeued state.
-	 */
-	__vb2_queue_cancel(q);
-	q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
-
-	dprintk(3, "successful\n");
-	return 0;
-}
+	struct video_device *vdev = video_devdata(file);
 
-/**
- * vb2_streamoff - stop streaming
- * @q:		videobuf2 queue
- * @type:	type argument passed from userspace to vidioc_streamoff handler
- *
- * Should be called from vidioc_streamoff handler of a driver.
- * This function:
- * 1) verifies current state,
- * 2) stop streaming and dequeues any queued buffers, including those previously
- *    passed to the driver (after waiting for the driver to finish).
- *
- * This call can be used for pausing playback.
- * The return values from this function are intended to be directly returned
- * from vidioc_streamoff handler in the driver
- */
-int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
-{
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
+	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	}
-	return vb2_internal_streamoff(q, type);
+	return vb2_prepare_buf(vdev->queue, p);
 }
-EXPORT_SYMBOL_GPL(vb2_streamoff);
+EXPORT_SYMBOL_GPL(vb2_ioctl_prepare_buf);
 
-/**
- * __find_plane_by_offset() - find plane associated with the given offset off
- */
-static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
-			unsigned int *_buffer, unsigned int *_plane)
+int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
 {
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	unsigned int buffer, plane;
-
-	/*
-	 * Go over all buffers and their planes, comparing the given offset
-	 * with an offset assigned to each plane. If a match is found,
-	 * return its buffer and plane numbers.
-	 */
-	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
-		vb = q->bufs[buffer];
-		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-
-		for (plane = 0; plane < vb->num_planes; ++plane) {
-			if (cb->v4l2_planes[plane].m.mem_offset == off) {
-				*_buffer = buffer;
-				*_plane = plane;
-				return 0;
-			}
-		}
-	}
+	struct video_device *vdev = video_devdata(file);
 
-	return -EINVAL;
+	/* No need to call vb2_queue_is_busy(), anyone can query buffers. */
+	return vb2_querybuf(vdev->queue, p);
 }
+EXPORT_SYMBOL_GPL(vb2_ioctl_querybuf);
 
-/**
- * vb2_expbuf() - Export a buffer as a file descriptor
- * @q:		videobuf2 queue
- * @eb:		export buffer structure passed from userspace to vidioc_expbuf
- *		handler in driver
- *
- * The return values from this function are intended to be directly returned
- * from vidioc_expbuf handler in driver.
- */
-int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
+int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 {
-	struct vb2_buffer *vb = NULL;
-	struct vb2_plane *vb_plane;
-	int ret;
-	struct dma_buf *dbuf;
-
-	if (q->memory != V4L2_MEMORY_MMAP) {
-		dprintk(1, "queue is not currently set up for mmap\n");
-		return -EINVAL;
-	}
-
-	if (!q->mem_ops->get_dmabuf) {
-		dprintk(1, "queue does not support DMA buffer exporting\n");
-		return -EINVAL;
-	}
-
-	if (eb->flags & ~(O_CLOEXEC | O_ACCMODE)) {
-		dprintk(1, "queue does support only O_CLOEXEC and access mode flags\n");
-		return -EINVAL;
-	}
-
-	if (eb->type != q->type) {
-		dprintk(1, "invalid buffer type\n");
-		return -EINVAL;
-	}
-
-	if (eb->index >= q->num_buffers) {
-		dprintk(1, "buffer index out of range\n");
-		return -EINVAL;
-	}
+	struct video_device *vdev = video_devdata(file);
 
-	vb = q->bufs[eb->index];
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_qbuf(vdev->queue, p);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_qbuf);
 
-	if (eb->plane >= vb->num_planes) {
-		dprintk(1, "buffer plane out of range\n");
-		return -EINVAL;
-	}
+int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+{
+	struct video_device *vdev = video_devdata(file);
 
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "expbuf: file io in progress\n");
+	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	}
-
-	vb_plane = &vb->planes[eb->plane];
+	return vb2_dqbuf(vdev->queue, p, file->f_flags & O_NONBLOCK);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_dqbuf);
 
-	dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE);
-	if (IS_ERR_OR_NULL(dbuf)) {
-		dprintk(1, "failed to export buffer %d, plane %d\n",
-			eb->index, eb->plane);
-		return -EINVAL;
-	}
+int vb2_ioctl_streamon(struct file *file, void *priv, unsigned int type)
+{
+	struct video_device *vdev = video_devdata(file);
 
-	ret = dma_buf_fd(dbuf, eb->flags & ~O_ACCMODE);
-	if (ret < 0) {
-		dprintk(3, "buffer %d, plane %d failed to export (%d)\n",
-			eb->index, eb->plane, ret);
-		dma_buf_put(dbuf);
-		return ret;
-	}
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_streamon(vdev->queue, type);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_streamon);
 
-	dprintk(3, "buffer %d, plane %d exported as %d descriptor\n",
-		eb->index, eb->plane, ret);
-	eb->fd = ret;
+int vb2_ioctl_streamoff(struct file *file, void *priv, unsigned int type)
+{
+	struct video_device *vdev = video_devdata(file);
 
-	return 0;
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_streamoff(vdev->queue, type);
 }
-EXPORT_SYMBOL_GPL(vb2_expbuf);
+EXPORT_SYMBOL_GPL(vb2_ioctl_streamoff);
 
-/**
- * vb2_mmap() - map video buffers into application address space
- * @q:		videobuf2 queue
- * @vma:	vma passed to the mmap file operation handler in the driver
- *
- * Should be called from mmap file operation handler of a driver.
- * This function maps one plane of one of the available video buffers to
- * userspace. To map whole video memory allocated on reqbufs, this function
- * has to be called once per each plane per each buffer previously allocated.
- *
- * When the userspace application calls mmap, it passes to it an offset returned
- * to it earlier by the means of vidioc_querybuf handler. That offset acts as
- * a "cookie", which is then used to identify the plane to be mapped.
- * This function finds a plane with a matching offset and a mapping is performed
- * by the means of a provided memory operation.
- *
- * The return values from this function are intended to be directly returned
- * from the mmap handler in driver.
- */
-int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
+int vb2_ioctl_expbuf(struct file *file, void *priv, struct v4l2_exportbuffer *p)
 {
-	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	unsigned int buffer = 0, plane = 0;
-	int ret;
-	unsigned long length;
-
-	if (q->memory != V4L2_MEMORY_MMAP) {
-		dprintk(1, "queue is not currently set up for mmap\n");
-		return -EINVAL;
-	}
+	struct video_device *vdev = video_devdata(file);
 
-	/*
-	 * Check memory area access mode.
-	 */
-	if (!(vma->vm_flags & VM_SHARED)) {
-		dprintk(1, "invalid vma flags, VM_SHARED needed\n");
-		return -EINVAL;
-	}
-	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
-		if (!(vma->vm_flags & VM_WRITE)) {
-			dprintk(1, "invalid vma flags, VM_WRITE needed\n");
-			return -EINVAL;
-		}
-	} else {
-		if (!(vma->vm_flags & VM_READ)) {
-			dprintk(1, "invalid vma flags, VM_READ needed\n");
-			return -EINVAL;
-		}
-	}
-	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "mmap: file io in progress\n");
+	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	}
-
-	/*
-	 * Find the plane corresponding to the offset passed by userspace.
-	 */
-	ret = __find_plane_by_offset(q, off, &buffer, &plane);
-	if (ret)
-		return ret;
+	return vb2_expbuf(vdev->queue, p);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_expbuf);
 
-	vb = q->bufs[buffer];
-	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-	/*
-	 * MMAP requires page_aligned buffers.
-	 * The buffer length was page_aligned at __vb2_buf_mem_alloc(),
-	 * so, we need to do the same here.
-	 */
-	length = PAGE_ALIGN(cb->v4l2_planes[plane].length);
-	if (length < (vma->vm_end - vma->vm_start)) {
-		dprintk(1,
-			"MMAP invalid, as it would overflow buffer length\n");
-		return -EINVAL;
-	}
+/* v4l2_file_operations helpers */
 
-	mutex_lock(&q->mmap_lock);
-	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
-	mutex_unlock(&q->mmap_lock);
-	if (ret)
-		return ret;
+int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	struct video_device *vdev = video_devdata(file);
 
-	dprintk(3, "buffer %d, plane %d successfully mapped\n", buffer, plane);
-	return 0;
+	return vb2_mmap(vdev->queue, vma);
 }
-EXPORT_SYMBOL_GPL(vb2_mmap);
+EXPORT_SYMBOL_GPL(vb2_fop_mmap);
 
-#ifndef CONFIG_MMU
-unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
-				    unsigned long addr,
-				    unsigned long len,
-				    unsigned long pgoff,
-				    unsigned long flags)
+int _vb2_fop_release(struct file *file, struct mutex *lock)
 {
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
-	unsigned long off = pgoff << PAGE_SHIFT;
-	unsigned int buffer, plane;
-	void *vaddr;
-	int ret;
+	struct video_device *vdev = video_devdata(file);
 
-	if (q->memory != V4L2_MEMORY_MMAP) {
-		dprintk(1, "queue is not currently set up for mmap\n");
-		return -EINVAL;
+	if (lock)
+		mutex_lock(lock);
+	if (file->private_data == vdev->queue->owner) {
+		vb2_queue_release(vdev->queue);
+		vdev->queue->owner = NULL;
 	}
+	if (lock)
+		mutex_unlock(lock);
+	return v4l2_fh_release(file);
+}
+EXPORT_SYMBOL_GPL(_vb2_fop_release);
 
-	/*
-	 * Find the plane corresponding to the offset passed by userspace.
-	 */
-	ret = __find_plane_by_offset(q, off, &buffer, &plane);
-	if (ret)
-		return ret;
-
-	vb = q->bufs[buffer];
-	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+int vb2_fop_release(struct file *file)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
 
-	vaddr = vb2_plane_vaddr(cb, plane);
-	return vaddr ? (unsigned long)vaddr : -EINVAL;
+	return _vb2_fop_release(file, lock);
 }
-EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
-#endif
-
-static int __vb2_init_fileio(struct vb2_queue *q, int read);
-static int __vb2_cleanup_fileio(struct vb2_queue *q);
+EXPORT_SYMBOL_GPL(vb2_fop_release);
 
-/**
- * vb2_poll() - implements poll userspace operation
- * @q:		videobuf2 queue
- * @file:	file argument passed to the poll file operation handler
- * @wait:	wait argument passed to the poll file operation handler
- *
- * This function implements poll file operation handler for a driver.
- * For CAPTURE queues, if a buffer is ready to be dequeued, the userspace will
- * be informed that the file descriptor of a video device is available for
- * reading.
- * For OUTPUT queues, if a buffer is ready to be dequeued, the file descriptor
- * will be reported as available for writing.
- *
- * If the driver uses struct v4l2_fh, then vb2_poll() will also check for any
- * pending events.
- *
- * The return values from this function are intended to be directly returned
- * from poll handler in driver.
- */
-unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
+ssize_t vb2_fop_write(struct file *file, const char __user *buf,
+		size_t count, loff_t *ppos)
 {
-	struct video_device *vfd = video_devdata(file);
-	unsigned long req_events = poll_requested_events(wait);
-	struct vb2_buffer *vb = NULL;
-	unsigned int res = 0;
-	unsigned long flags;
+	struct video_device *vdev = video_devdata(file);
+	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
+	int err = -EBUSY;
 
-	if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
-		struct v4l2_fh *fh = file->private_data;
+	if (lock && mutex_lock_interruptible(lock))
+		return -ERESTARTSYS;
+	if (vb2_queue_is_busy(vdev, file))
+		goto exit;
+	err = vb2_write(vdev->queue, buf, count, ppos,
+		       file->f_flags & O_NONBLOCK);
+	if (vdev->queue->fileio)
+		vdev->queue->owner = file->private_data;
+exit:
+	if (lock)
+		mutex_unlock(lock);
+	return err;
+}
+EXPORT_SYMBOL_GPL(vb2_fop_write);
 
-		if (v4l2_event_pending(fh))
-			res = POLLPRI;
-		else if (req_events & POLLPRI)
-			poll_wait(file, &fh->wait, wait);
-	}
+ssize_t vb2_fop_read(struct file *file, char __user *buf,
+		size_t count, loff_t *ppos)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
+	int err = -EBUSY;
 
-	if (!V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLIN | POLLRDNORM)))
-		return res;
-	if (V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLOUT | POLLWRNORM)))
-		return res;
+	if (lock && mutex_lock_interruptible(lock))
+		return -ERESTARTSYS;
+	if (vb2_queue_is_busy(vdev, file))
+		goto exit;
+	err = vb2_read(vdev->queue, buf, count, ppos,
+		       file->f_flags & O_NONBLOCK);
+	if (vdev->queue->fileio)
+		vdev->queue->owner = file->private_data;
+exit:
+	if (lock)
+		mutex_unlock(lock);
+	return err;
+}
+EXPORT_SYMBOL_GPL(vb2_fop_read);
 
-	/*
-	 * Start file I/O emulator only if streaming API has not been used yet.
-	 */
-	if (q->num_buffers == 0 && !vb2_fileio_is_active(q)) {
-		if (!V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_READ) &&
-				(req_events & (POLLIN | POLLRDNORM))) {
-			if (__vb2_init_fileio(q, 1))
-				return res | POLLERR;
-		}
-		if (V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_WRITE) &&
-				(req_events & (POLLOUT | POLLWRNORM))) {
-			if (__vb2_init_fileio(q, 0))
-				return res | POLLERR;
-			/*
-			 * Write to OUTPUT queue can be done immediately.
-			 */
-			return res | POLLOUT | POLLWRNORM;
-		}
-	}
+unsigned int vb2_fop_poll(struct file *file, poll_table *wait)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct vb2_queue *q = vdev->queue;
+	struct mutex *lock = q->lock ? q->lock : vdev->lock;
+	unsigned res;
+	void *fileio;
 
 	/*
-	 * There is nothing to wait for if the queue isn't streaming, or if the
-	 * error flag is set.
-	 */
-	if (!vb2_is_streaming(q) || q->error)
-		return res | POLLERR;
-	/*
-	 * For compatibility with vb1: if QBUF hasn't been called yet, then
-	 * return POLLERR as well. This only affects capture queues, output
-	 * queues will always initialize waiting_for_buffers to false.
+	 * If this helper doesn't know how to lock, then you shouldn't be using
+	 * it but you should write your own.
 	 */
-	if (q->waiting_for_buffers)
-		return res | POLLERR;
+	WARN_ON(!lock);
 
-	/*
-	 * For output streams you can write as long as there are fewer buffers
-	 * queued than there are buffers available.
-	 */
-	if (V4L2_TYPE_IS_OUTPUT(q->type) && q->queued_count < q->num_buffers)
-		return res | POLLOUT | POLLWRNORM;
+	if (lock && mutex_lock_interruptible(lock))
+		return POLLERR;
 
-	if (list_empty(&q->done_list))
-		poll_wait(file, &q->done_wq, wait);
+	fileio = q->fileio;
 
-	/*
-	 * Take first buffer available for dequeuing.
-	 */
-	spin_lock_irqsave(&q->done_lock, flags);
-	if (!list_empty(&q->done_list))
-		vb = list_first_entry(&q->done_list, struct vb2_buffer,
-					done_entry);
-	spin_unlock_irqrestore(&q->done_lock, flags);
+	res = vb2_poll(vdev->queue, file, wait);
 
-	if (vb && (vb->state == VB2_BUF_STATE_DONE
-			|| vb->state == VB2_BUF_STATE_ERROR)) {
-		return (V4L2_TYPE_IS_OUTPUT(q->type)) ?
-				res | POLLOUT | POLLWRNORM :
-				res | POLLIN | POLLRDNORM;
-	}
+	/* If fileio was started, then we have a new queue owner. */
+	if (!fileio && q->fileio)
+		q->owner = file->private_data;
+	if (lock)
+		mutex_unlock(lock);
 	return res;
 }
-EXPORT_SYMBOL_GPL(vb2_poll);
+EXPORT_SYMBOL_GPL(vb2_fop_poll);
 
-/**
- * vb2_queue_init() - initialize a videobuf2 queue
- * @q:		videobuf2 queue; this structure should be allocated in driver
- *
- * The vb2_queue structure should be allocated by the driver. The driver is
- * responsible of clearing it's content and setting initial values for some
- * required entries before calling this function.
- * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer
- * to the struct vb2_queue description in include/media/videobuf2-v4l2.h
- * for more information.
- */
-int vb2_queue_init(struct vb2_queue *q)
+#ifndef CONFIG_MMU
+unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
+		unsigned long len, unsigned long pgoff, unsigned long flags)
 {
-	/*
-	 * Sanity check
-	 */
-	if (WARN_ON(!q)			  ||
-	    WARN_ON(!q->ops)		  ||
-	    WARN_ON(!q->mem_ops)	  ||
-	    WARN_ON(!q->type)		  ||
-	    WARN_ON(!q->io_modes)	  ||
-	    WARN_ON(!q->ops->queue_setup) ||
-	    WARN_ON(!q->ops->buf_queue)   ||
-	    WARN_ON(q->timestamp_flags &
-		    ~(V4L2_BUF_FLAG_TIMESTAMP_MASK |
-		      V4L2_BUF_FLAG_TSTAMP_SRC_MASK)))
-		return -EINVAL;
-
-	/* Warn that the driver should choose an appropriate timestamp type */
-	WARN_ON((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
-		V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN);
+	struct video_device *vdev = video_devdata(file);
 
-	INIT_LIST_HEAD(&q->queued_list);
-	INIT_LIST_HEAD(&q->done_list);
-	spin_lock_init(&q->done_lock);
-	mutex_init(&q->mmap_lock);
-	init_waitqueue_head(&q->done_wq);
+	return vb2_get_unmapped_area(vdev->queue, addr, len, pgoff, flags);
+}
+EXPORT_SYMBOL_GPL(vb2_fop_get_unmapped_area);
+#endif
 
-	if (q->buf_struct_size == 0)
-		q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
+/* vb2_ops helpers. Only use if vq->lock is non-NULL. */
 
-	return 0;
+void vb2_ops_wait_prepare(struct vb2_queue *vq)
+{
+	mutex_unlock(vq->lock);
 }
-EXPORT_SYMBOL_GPL(vb2_queue_init);
+EXPORT_SYMBOL_GPL(vb2_ops_wait_prepare);
 
-/**
- * vb2_queue_release() - stop streaming, release the queue and free memory
- * @q:		videobuf2 queue
- *
- * This function stops streaming and performs necessary clean ups, including
- * freeing video buffer memory. The driver is responsible for freeing
- * the vb2_queue structure itself.
- */
-void vb2_queue_release(struct vb2_queue *q)
+void vb2_ops_wait_finish(struct vb2_queue *vq)
 {
-	__vb2_cleanup_fileio(q);
-	__vb2_queue_cancel(q);
-	mutex_lock(&q->mmap_lock);
-	__vb2_queue_free(q, q->num_buffers);
-	mutex_unlock(&q->mmap_lock);
+	mutex_lock(vq->lock);
 }
-EXPORT_SYMBOL_GPL(vb2_queue_release);
-
-/**
- * struct vb2_fileio_buf - buffer context used by file io emulator
- *
- * vb2 provides a compatibility layer and emulator of file io (read and
- * write) calls on top of streaming API. This structure is used for
- * tracking context related to the buffers.
- */
-struct vb2_fileio_buf {
-	void *vaddr;
-	unsigned int size;
-	unsigned int pos;
-	unsigned int queued:1;
-};
+EXPORT_SYMBOL_GPL(vb2_ops_wait_finish);
 
 /**
- * struct vb2_fileio_data - queue context used by file io emulator
- *
- * @cur_index:	the index of the buffer currently being read from or
- *		written to. If equal to q->num_buffers then a new buffer
- *		must be dequeued.
- * @initial_index: in the read() case all buffers are queued up immediately
- *		in __vb2_init_fileio() and __vb2_perform_fileio() just cycles
- *		buffers. However, in the write() case no buffers are initially
- *		queued, instead whenever a buffer is full it is queued up by
- *		__vb2_perform_fileio(). Only once all available buffers have
- *		been queued up will __vb2_perform_fileio() start to dequeue
- *		buffers. This means that initially __vb2_perform_fileio()
- *		needs to know what buffer index to use when it is queuing up
- *		the buffers for the first time. That initial index is stored
- *		in this field. Once it is equal to q->num_buffers all
- *		available buffers have been queued and __vb2_perform_fileio()
- *		should start the normal dequeue/queue cycle.
+ * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
+ * @vb:		vb2_buffer to which the plane in question belongs to
+ * @plane_no:	plane number for which the address is to be returned
  *
- * vb2 provides a compatibility layer and emulator of file io (read and
- * write) calls on top of streaming API. For proper operation it required
- * this structure to save the driver state between each call of the read
- * or write function.
- */
-struct vb2_fileio_data {
-	struct v4l2_requestbuffers req;
-	struct v4l2_plane p;
-	struct v4l2_buffer b;
-	struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME];
-	unsigned int cur_index;
-	unsigned int initial_index;
-	unsigned int q_count;
-	unsigned int dq_count;
-	unsigned int flags;
-};
-
-/**
- * __vb2_init_fileio() - initialize file io emulator
- * @q:		videobuf2 queue
- * @read:	mode selector (1 means read, 0 means write)
+ * This function returns a kernel virtual address of a given plane if
+ * such a mapping exist, NULL otherwise.
  */
-static int __vb2_init_fileio(struct vb2_queue *q, int read)
+void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
 {
-	struct vb2_fileio_data *fileio;
-	int i, ret;
-	unsigned int count = 0;
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_buffer *vb;
+	struct vb2_buffer *vb = &cb->vb2;
+	if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
+		return NULL;
 
-	/*
-	 * Sanity check
-	 */
-	if (WARN_ON((read && !(q->io_modes & VB2_READ)) ||
-		    (!read && !(q->io_modes & VB2_WRITE))))
-		return -EINVAL;
+	return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
 
-	/*
-	 * Check if device supports mapping buffers to kernel virtual space.
-	 */
-	if (!q->mem_ops->vaddr)
-		return -EBUSY;
+}
+EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
 
-	/*
-	 * Check if streaming api has not been already activated.
-	 */
-	if (q->streaming || q->num_buffers > 0)
-		return -EBUSY;
+/**
+ * vb2_plane_cookie() - Return allocator specific cookie for the given plane
+ * @vb:		vb2_buffer to which the plane in question belongs to
+ * @plane_no:	plane number for which the cookie is to be returned
+ *
+ * This function returns an allocator specific cookie for a given plane if
+ * available, NULL otherwise. The allocator should provide some simple static
+ * inline function, which would convert this cookie to the allocator specific
+ * type that can be used directly by the driver to access the buffer. This can
+ * be for example physical address, pointer to scatter list or IOMMU mapping.
+ */
+void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
+{
+	struct vb2_buffer *vb = &cb->vb2;
+	if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
+		return NULL;
 
-	/*
-	 * Start with count 1, driver can increase it in queue_setup()
-	 */
-	count = 1;
+	return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
+}
+EXPORT_SYMBOL_GPL(vb2_plane_cookie);
 
-	dprintk(3, "setting up file io: mode %s, count %d, flags %08x\n",
-		(read) ? "read" : "write", count, q->io_flags);
+/**
+ *  Belows are private functions for v4l2
+ */
 
-	fileio = kzalloc(sizeof(struct vb2_fileio_data), GFP_KERNEL);
-	if (fileio == NULL)
-		return -ENOMEM;
+/**
+ * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a
+ * v4l2_buffer by the userspace. The caller has already verified that struct
+ * v4l2_buffer has a valid number of planes.
+ */
+static int v4l2_fill_vb2_buffer(struct vb2_buffer *vb, void *pbuffer,
+		void *pplane)
+{
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pbuffer;
+	struct v4l2_plane *v4l2_planes = (struct v4l2_plane *)pplane;
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	unsigned int plane;
 
-	fileio->flags = q->io_flags;
+	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
+		if (b->memory == V4L2_MEMORY_USERPTR) {
+			for (plane = 0; plane < vb->num_planes; ++plane) {
+				v4l2_planes[plane].m.userptr =
+					b->m.planes[plane].m.userptr;
+				v4l2_planes[plane].length =
+					b->m.planes[plane].length;
+			}
+		}
+		if (b->memory == V4L2_MEMORY_DMABUF) {
+			for (plane = 0; plane < vb->num_planes; ++plane) {
+				v4l2_planes[plane].m.fd =
+					b->m.planes[plane].m.fd;
+				v4l2_planes[plane].length =
+					b->m.planes[plane].length;
+			}
+		}
 
-	/*
-	 * Request buffers and use MMAP type to force driver
-	 * to allocate buffers by itself.
-	 */
-	fileio->req.count = count;
-	fileio->req.memory = V4L2_MEMORY_MMAP;
-	fileio->req.type = q->type;
-	q->fileio = fileio;
-	ret = __reqbufs(q, &fileio->req);
-	if (ret)
-		goto err_kfree;
+		/* Fill in driver-provided information for OUTPUT types */
+		if (V4L2_TYPE_IS_OUTPUT(b->type)) {
+			/*
+			 * Will have to go up to b->length when API starts
+			 * accepting variable number of planes.
+			 *
+			 * If bytesused == 0 for the output buffer, then fall
+			 * back to the full buffer size. In that case
+			 * userspace clearly never bothered to set it and
+			 * it's a safe assumption that they really meant to
+			 * use the full plane sizes.
+			 */
+			for (plane = 0; plane < vb->num_planes; ++plane) {
+				struct v4l2_plane *pdst = &v4l2_planes[plane];
+				struct v4l2_plane *psrc = &b->m.planes[plane];
 
-	/*
-	 * Check if plane_count is correct
-	 * (multiplane buffers are not supported).
-	 */
-	vb = q->bufs[0];
-	if (vb->num_planes != 1) {
-		ret = -EBUSY;
-		goto err_reqbufs;
-	}
+				pdst->bytesused = psrc->bytesused ?
+					psrc->bytesused : pdst->length;
+				pdst->data_offset = psrc->data_offset;
+			}
+		}
+	} else {
+		/*
+		 * Single-planar buffers do not use planes array,
+		 * so fill in relevant v4l2_buffer struct fields instead.
+		 * In videobuf we use our internal V4l2_planes struct for
+		 * single-planar buffers as well, for simplicity.
+		 *
+		 * If bytesused == 0 for the output buffer, then fall back
+		 * to the full buffer size as that's a sensible default.
+		 */
+		if (b->memory == V4L2_MEMORY_USERPTR) {
+			v4l2_planes[0].m.userptr = b->m.userptr;
+			v4l2_planes[0].length = b->length;
+		}
 
-	/*
-	 * Get kernel address of each buffer.
-	 */
-	for (i = 0; i < q->num_buffers; i++) {
-		cb = container_of(q->bufs[i], struct vb2_v4l2_buffer, vb2);
-		fileio->bufs[i].vaddr = vb2_plane_vaddr(cb, 0);
-		if (fileio->bufs[i].vaddr == NULL) {
-			ret = -EINVAL;
-			goto err_reqbufs;
+		if (b->memory == V4L2_MEMORY_DMABUF) {
+			v4l2_planes[0].m.fd = b->m.fd;
+			v4l2_planes[0].length = b->length;
 		}
-		fileio->bufs[i].size = vb2_plane_size(cb, 0);
-	}
 
-	/*
-	 * Read mode requires pre queuing of all buffers.
-	 */
-	if (read) {
-		bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
+		if (V4L2_TYPE_IS_OUTPUT(b->type))
+			v4l2_planes[0].bytesused = b->bytesused ?
+				b->bytesused : v4l2_planes[0].length;
+		else
+			v4l2_planes[0].bytesused = 0;
+
+	}
 
+	/* Zero flags that the vb2 core handles */
+	cb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
+	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
+	    V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
 		/*
-		 * Queue all buffers.
+		 * Non-COPY timestamps and non-OUTPUT queues will get
+		 * their timestamp and timestamp source flags from the
+		 * queue.
 		 */
-		for (i = 0; i < q->num_buffers; i++) {
-			struct v4l2_buffer *b = &fileio->b;
+		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+	}
 
-			memset(b, 0, sizeof(*b));
-			b->type = q->type;
-			if (is_multiplanar) {
-				memset(&fileio->p, 0, sizeof(fileio->p));
-				b->m.planes = &fileio->p;
-				b->length = 1;
-			}
-			b->memory = q->memory;
-			b->index = i;
-			ret = vb2_internal_qbuf(q, b);
-			if (ret)
-				goto err_reqbufs;
-			fileio->bufs[i].queued = 1;
-		}
+	if (V4L2_TYPE_IS_OUTPUT(b->type)) {
 		/*
-		 * All buffers have been queued, so mark that by setting
-		 * initial_index to q->num_buffers
+		 * For output buffers mask out the timecode flag:
+		 * this will be handled later in vb2_internal_qbuf().
+		 * The 'field' is valid metadata for this output buffer
+		 * and so that needs to be copied here.
 		 */
-		fileio->initial_index = q->num_buffers;
-		fileio->cur_index = q->num_buffers;
+		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
+		cb->v4l2_buf.field = b->field;
+	} else {
+		/* Zero any output buffer flags as this is a capture buffer */
+		cb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
 	}
 
-	/*
-	 * Start streaming.
-	 */
-	ret = vb2_internal_streamon(q, q->type);
-	if (ret)
-		goto err_reqbufs;
-
-	return ret;
-
-err_reqbufs:
-	fileio->req.count = 0;
-	__reqbufs(q, &fileio->req);
-
-err_kfree:
-	q->fileio = NULL;
-	kfree(fileio);
-	return ret;
+	return 0;
 }
 
 /**
- * __vb2_cleanup_fileio() - free resourced used by file io emulator
- * @q:		videobuf2 queue
+ * v4l2_qbuf_mmap() - handle qbuf of an MMAP buffer
  */
-static int __vb2_cleanup_fileio(struct vb2_queue *q)
+static int v4l2_qbuf_mmap(struct vb2_buffer *vb, void *pb)
 {
-	struct vb2_fileio_data *fileio = q->fileio;
-
-	if (fileio) {
-		vb2_internal_streamoff(q, q->type);
-		q->fileio = NULL;
-		fileio->req.count = 0;
-		vb2_reqbufs(q, &fileio->req);
-		kfree(fileio);
-		dprintk(3, "file io emulator closed\n");
-	}
-	return 0;
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	v4l2_fill_vb2_buffer(vb, b, cb->v4l2_planes);
+	return call_vb_qop(vb, buf_prepare, vb);
 }
 
 /**
- * __vb2_perform_fileio() - perform a single file io (read or write) operation
- * @q:		videobuf2 queue
- * @data:	pointed to target userspace buffer
- * @count:	number of bytes to read or write
- * @ppos:	file handle position tracking pointer
- * @nonblock:	mode selector (1 means blocking calls, 0 means nonblocking)
- * @read:	access mode selector (1 means read, 0 means write)
+ * v4l2_qbuf_userptr() - handle qbuf of a USERPTR buffer
  */
-static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
-		loff_t *ppos, int nonblock, int read)
+static int v4l2_qbuf_userptr(struct vb2_buffer *vb, void *pb)
 {
-	struct vb2_v4l2_buffer *cb;
-	struct vb2_fileio_data *fileio;
-	struct vb2_fileio_buf *buf;
-	bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
-	/*
-	 * When using write() to write data to an output video node the vb2 core
-	 * should set timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody
-	 * else is able to provide this information with the write() operation.
-	 */
-	bool set_timestamp = !read &&
-		(q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
-		V4L2_BUF_FLAG_TIMESTAMP_COPY;
-	int ret, index;
-
-	dprintk(3, "mode %s, offset %ld, count %zd, %sblocking\n",
-		read ? "read" : "write", (long)*ppos, count,
-		nonblock ? "non" : "");
-
-	if (!data)
-		return -EINVAL;
-
-	/*
-	 * Initialize emulator on first call.
-	 */
-	if (!vb2_fileio_is_active(q)) {
-		ret = __vb2_init_fileio(q, read);
-		dprintk(3, "vb2_init_fileio result: %d\n", ret);
-		if (ret)
-			return ret;
-	}
-	fileio = q->fileio;
-
-	/*
-	 * Check if we need to dequeue the buffer.
-	 */
-	index = fileio->cur_index;
-	if (index >= q->num_buffers) {
-		/*
-		 * Call vb2_dqbuf to get buffer back.
-		 */
-		memset(&fileio->b, 0, sizeof(fileio->b));
-		fileio->b.type = q->type;
-		fileio->b.memory = q->memory;
-		if (is_multiplanar) {
-			memset(&fileio->p, 0, sizeof(fileio->p));
-			fileio->b.m.planes = &fileio->p;
-			fileio->b.length = 1;
-		}
-		ret = vb2_internal_dqbuf(q, &fileio->b, nonblock);
-		dprintk(5, "vb2_dqbuf result: %d\n", ret);
-		if (ret)
-			return ret;
-		fileio->dq_count += 1;
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	struct v4l2_plane planes[VIDEO_MAX_PLANES];
+	struct vb2_queue *q = vb->vb2_queue;
+	void *mem_priv;
+	unsigned int plane;
+	int ret;
+	enum dma_data_direction dma_dir =
+		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
+	bool reacquired = vb->planes[0].mem_priv == NULL;
 
-		fileio->cur_index = index = fileio->b.index;
-		buf = &fileio->bufs[index];
+	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
+	/* Copy relevant information provided by the userspace */
+	v4l2_fill_vb2_buffer(vb, pb, planes);
 
-		/*
-		 * Get number of bytes filled by the driver
-		 */
-		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
-		buf->pos = 0;
-		buf->queued = 0;
-		buf->size = read ? vb2_get_plane_payload(cb, 0)
-				 : vb2_plane_size(cb, 0);
-		/* Compensate for data_offset on read in the multiplanar case. */
-		if (is_multiplanar && read &&
-		    fileio->b.m.planes[0].data_offset < buf->size) {
-			buf->pos = fileio->b.m.planes[0].data_offset;
-			buf->size -= buf->pos;
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		/* Skip the plane if already verified */
+		if (cb->v4l2_planes[plane].m.userptr &&
+		    cb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
+		    && cb->v4l2_planes[plane].length == planes[plane].length)
+			continue;
+
+		dprintk(3, "userspace address for plane %d changed, "
+				"reacquiring memory\n", plane);
+
+		/* Check if the provided plane buffer is large enough */
+		if (planes[plane].length < q->plane_sizes[plane]) {
+			dprintk(1, "provided buffer size %u is less than "
+						"setup size %u for plane %d\n",
+						planes[plane].length,
+						q->plane_sizes[plane], plane);
+			ret = -EINVAL;
+			goto err;
 		}
-	} else {
-		buf = &fileio->bufs[index];
-	}
 
-	/*
-	 * Limit count on last few bytes of the buffer.
-	 */
-	if (buf->pos + count > buf->size) {
-		count = buf->size - buf->pos;
-		dprintk(5, "reducing read count: %zd\n", count);
-	}
+		/* Release previously acquired memory if present */
+		if (vb->planes[plane].mem_priv) {
+			if (!reacquired) {
+				reacquired = true;
+				call_void_vb_qop(vb, buf_cleanup, vb);
+			}
+			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
+		}
 
-	/*
-	 * Transfer data to userspace.
-	 */
-	dprintk(3, "copying %zd bytes - buffer %d, offset %u\n",
-		count, index, buf->pos);
-	if (read)
-		ret = copy_to_user(data, buf->vaddr + buf->pos, count);
-	else
-		ret = copy_from_user(buf->vaddr + buf->pos, data, count);
-	if (ret) {
-		dprintk(3, "error copying data\n");
-		return -EFAULT;
+		vb->planes[plane].mem_priv = NULL;
+		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
+
+		/* Acquire each plane's memory */
+		mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane],
+				      planes[plane].m.userptr,
+				      planes[plane].length, dma_dir);
+		if (IS_ERR_OR_NULL(mem_priv)) {
+			dprintk(1, "failed acquiring userspace "
+						"memory for plane %d\n", plane);
+			ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
+			goto err;
+		}
+		vb->planes[plane].mem_priv = mem_priv;
 	}
 
 	/*
-	 * Update counters.
+	 * Now that everything is in order, copy relevant information
+	 * provided by userspace.
 	 */
-	buf->pos += count;
-	*ppos += count;
+	for (plane = 0; plane < vb->num_planes; ++plane)
+		cb->v4l2_planes[plane] = planes[plane];
 
-	/*
-	 * Queue next buffer if required.
-	 */
-	if (buf->pos == buf->size ||
-	   (!read && (fileio->flags & VB2_FILEIO_WRITE_IMMEDIATELY))) {
+	if (reacquired) {
 		/*
-		 * Check if this is the last buffer to read.
+		 * One or more planes changed, so we must call buf_init to do
+		 * the driver-specific initialization on the newly acquired
+		 * buffer, if provided.
 		 */
-		if (read && (fileio->flags & VB2_FILEIO_READ_ONCE) &&
-		    fileio->dq_count == 1) {
-			dprintk(3, "read limit reached\n");
-			return __vb2_cleanup_fileio(q);
+		ret = call_vb_qop(vb, buf_init, vb);
+		if (ret) {
+			dprintk(1, "buffer initialization failed\n");
+			goto err;
 		}
+	}
 
-		/*
-		 * Call vb2_qbuf and give buffer to the driver.
-		 */
-		memset(&fileio->b, 0, sizeof(fileio->b));
-		fileio->b.type = q->type;
-		fileio->b.memory = q->memory;
-		fileio->b.index = index;
-		fileio->b.bytesused = buf->pos;
-		if (is_multiplanar) {
-			memset(&fileio->p, 0, sizeof(fileio->p));
-			fileio->p.bytesused = buf->pos;
-			fileio->b.m.planes = &fileio->p;
-			fileio->b.length = 1;
-		}
-		if (set_timestamp)
-			v4l2_get_timestamp(&fileio->b.timestamp);
-		ret = vb2_internal_qbuf(q, &fileio->b);
-		dprintk(5, "vb2_dbuf result: %d\n", ret);
-		if (ret)
-			return ret;
+	ret = call_vb_qop(vb, buf_prepare, vb);
+	if (ret) {
+		dprintk(1, "buffer preparation failed\n");
+		call_void_vb_qop(vb, buf_cleanup, vb);
+		goto err;
+	}
 
-		/*
-		 * Buffer has been queued, update the status
-		 */
-		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
-		buf->pos = 0;
-		buf->queued = 1;
-		buf->size = vb2_plane_size(cb, 0);
-		fileio->q_count += 1;
-		/*
-		 * If we are queuing up buffers for the first time, then
-		 * increase initial_index by one.
-		 */
-		if (fileio->initial_index < q->num_buffers)
-			fileio->initial_index++;
-		/*
-		 * The next buffer to use is either a buffer that's going to be
-		 * queued for the first time (initial_index < q->num_buffers)
-		 * or it is equal to q->num_buffers, meaning that the next
-		 * time we need to dequeue a buffer since we've now queued up
-		 * all the 'first time' buffers.
-		 */
-		fileio->cur_index = fileio->initial_index;
+	return 0;
+err:
+	/* In case of errors, release planes that were already acquired */
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		if (vb->planes[plane].mem_priv)
+			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
+		vb->planes[plane].mem_priv = NULL;
+		cb->v4l2_planes[plane].m.userptr = 0;
+		cb->v4l2_planes[plane].length = 0;
 	}
 
-	/*
-	 * Return proper number of bytes processed.
-	 */
-	if (ret == 0)
-		ret = count;
 	return ret;
 }
 
-size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
-		loff_t *ppos, int nonblocking)
+/**
+ * v4l2_qbuf_dmabuf() - handle qbuf of a DMABUF buffer
+ */
+static int v4l2_qbuf_dmabuf(struct vb2_buffer *vb, void *pb)
 {
-	return __vb2_perform_fileio(q, data, count, ppos, nonblocking, 1);
-}
-EXPORT_SYMBOL_GPL(vb2_read);
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	struct v4l2_plane planes[VIDEO_MAX_PLANES];
+	struct vb2_queue *q = vb->vb2_queue;
+	void *mem_priv;
+	unsigned int plane;
+	int ret;
+	enum dma_data_direction dma_dir =
+		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
+	bool reacquired = vb->planes[0].mem_priv == NULL;
 
-size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
-		loff_t *ppos, int nonblocking)
-{
-	return __vb2_perform_fileio(q, (char __user *) data, count,
-							ppos, nonblocking, 0);
-}
-EXPORT_SYMBOL_GPL(vb2_write);
+	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
+	/* Copy relevant information provided by the userspace */
+	v4l2_fill_vb2_buffer(vb, b, planes);
 
-struct vb2_threadio_data {
-	struct task_struct *thread;
-	vb2_thread_fnc fnc;
-	void *priv;
-	bool stop;
-};
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
 
-static int vb2_thread(void *data)
-{
-	struct vb2_queue *q = data;
-	struct vb2_threadio_data *threadio = q->threadio;
-	struct vb2_fileio_data *fileio = q->fileio;
-	bool set_timestamp = false;
-	int prequeue = 0;
-	int index = 0;
-	int ret = 0;
+		if (IS_ERR_OR_NULL(dbuf)) {
+			dprintk(1, "invalid dmabuf fd for plane %d\n",
+				plane);
+			ret = -EINVAL;
+			goto err;
+		}
 
-	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
-		prequeue = q->num_buffers;
-		set_timestamp =
-			(q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
-			V4L2_BUF_FLAG_TIMESTAMP_COPY;
+		/* use DMABUF size if length is not provided */
+		if (planes[plane].length == 0)
+			planes[plane].length = dbuf->size;
+
+		if (planes[plane].length < q->plane_sizes[plane]) {
+			dprintk(1, "invalid dmabuf length for plane %d\n",
+				plane);
+			ret = -EINVAL;
+			goto err;
+		}
+
+		/* Skip the plane if already verified */
+		if (dbuf == vb->planes[plane].dbuf &&
+		    cb->v4l2_planes[plane].length == planes[plane].length) {
+			dma_buf_put(dbuf);
+			continue;
+		}
+
+		dprintk(1, "buffer for plane %d changed\n", plane);
+
+		if (!reacquired) {
+			reacquired = true;
+			call_void_vb_qop(vb, buf_cleanup, vb);
+		}
+
+		/* Release previously acquired memory if present */
+		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
+		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
+
+		/* Acquire each plane's memory */
+		mem_priv = call_ptr_memop(vb, attach_dmabuf, q->alloc_ctx[plane],
+			dbuf, planes[plane].length, dma_dir);
+		if (IS_ERR(mem_priv)) {
+			dprintk(1, "failed to attach dmabuf\n");
+			ret = PTR_ERR(mem_priv);
+			dma_buf_put(dbuf);
+			goto err;
+		}
+
+		vb->planes[plane].dbuf = dbuf;
+		vb->planes[plane].mem_priv = mem_priv;
 	}
 
-	set_freezable();
+	/* TODO: This pins the buffer(s) with  dma_buf_map_attachment()).. but
+	 * really we want to do this just before the DMA, not while queueing
+	 * the buffer(s)..
+	 */
+	for (plane = 0; plane < vb->num_planes; ++plane) {
+		ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
+		if (ret) {
+			dprintk(1, "failed to map dmabuf for plane %d\n",
+				plane);
+			goto err;
+		}
+		vb->planes[plane].dbuf_mapped = 1;
+	}
 
-	for (;;) {
-		struct vb2_v4l2_buffer *cb;
-		struct vb2_buffer *vb;
+	/*
+	 * Now that everything is in order, copy relevant information
+	 * provided by userspace.
+	 */
+	for (plane = 0; plane < vb->num_planes; ++plane)
+		cb->v4l2_planes[plane] = planes[plane];
 
+	if (reacquired) {
 		/*
-		 * Call vb2_dqbuf to get buffer back.
+		 * Call driver-specific initialization on the newly acquired buffer,
+		 * if provided.
 		 */
-		memset(&fileio->b, 0, sizeof(fileio->b));
-		fileio->b.type = q->type;
-		fileio->b.memory = q->memory;
-		if (prequeue) {
-			fileio->b.index = index++;
-			prequeue--;
-		} else {
-			call_void_qop(q, wait_finish, q);
-			if (!threadio->stop)
-				ret = vb2_internal_dqbuf(q, &fileio->b, 0);
-			call_void_qop(q, wait_prepare, q);
-			dprintk(5, "file io: vb2_dqbuf result: %d\n", ret);
+		ret = call_vb_qop(vb, buf_init, vb);
+		if (ret) {
+			dprintk(1, "buffer initialization failed\n");
+			goto err;
 		}
-		if (ret || threadio->stop)
-			break;
-		try_to_freeze();
-
-		vb = q->bufs[fileio->b.index];
-		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
-		if (!(fileio->b.flags & V4L2_BUF_FLAG_ERROR))
-			if (threadio->fnc(cb, threadio->priv))
-				break;
-		call_void_qop(q, wait_finish, q);
-		if (set_timestamp)
-			v4l2_get_timestamp(&fileio->b.timestamp);
-		if (!threadio->stop)
-			ret = vb2_internal_qbuf(q, &fileio->b);
-		call_void_qop(q, wait_prepare, q);
-		if (ret || threadio->stop)
-			break;
 	}
 
-	/* Hmm, linux becomes *very* unhappy without this ... */
-	while (!kthread_should_stop()) {
-		set_current_state(TASK_INTERRUPTIBLE);
-		schedule();
+	ret = call_vb_qop(vb, buf_prepare, vb);
+	if (ret) {
+		dprintk(1, "buffer preparation failed\n");
+		call_void_vb_qop(vb, buf_cleanup, vb);
+		goto err;
 	}
-	return 0;
-}
-
-/*
- * This function should not be used for anything else but the videobuf2-dvb
- * support. If you think you have another good use-case for this, then please
- * contact the linux-media mailinglist first.
- */
-int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
-		     const char *thread_name)
-{
-	struct vb2_threadio_data *threadio;
-	int ret = 0;
 
-	if (q->threadio)
-		return -EBUSY;
-	if (vb2_is_busy(q))
-		return -EBUSY;
-	if (WARN_ON(q->fileio))
-		return -EBUSY;
-
-	threadio = kzalloc(sizeof(*threadio), GFP_KERNEL);
-	if (threadio == NULL)
-		return -ENOMEM;
-	threadio->fnc = fnc;
-	threadio->priv = priv;
-
-	ret = __vb2_init_fileio(q, !V4L2_TYPE_IS_OUTPUT(q->type));
-	dprintk(3, "file io: vb2_init_fileio result: %d\n", ret);
-	if (ret)
-		goto nomem;
-	q->threadio = threadio;
-	threadio->thread = kthread_run(vb2_thread, q, "vb2-%s", thread_name);
-	if (IS_ERR(threadio->thread)) {
-		ret = PTR_ERR(threadio->thread);
-		threadio->thread = NULL;
-		goto nothread;
-	}
 	return 0;
+err:
+	/* In case of errors, release planes that were already acquired */
+	__vb2_buf_dmabuf_put(vb);
 
-nothread:
-	__vb2_cleanup_fileio(q);
-nomem:
-	kfree(threadio);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(vb2_thread_start);
 
-int vb2_thread_stop(struct vb2_queue *q)
+static int v4l2_is_alternate(void *pb)
 {
-	struct vb2_threadio_data *threadio = q->threadio;
-	int err;
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
 
-	if (threadio == NULL)
-		return 0;
-	threadio->stop = true;
-	/* Wake up all pending sleeps in the thread */
-	vb2_queue_error(q);
-	err = kthread_stop(threadio->thread);
-	__vb2_cleanup_fileio(q);
-	threadio->thread = NULL;
-	kfree(threadio);
-	q->threadio = NULL;
-	return err;
+	return (b->field == V4L2_FIELD_ALTERNATE);
 }
-EXPORT_SYMBOL_GPL(vb2_thread_stop);
-
-/*
- * The following functions are not part of the vb2 core API, but are helper
- * functions that plug into struct v4l2_ioctl_ops, struct v4l2_file_operations
- * and struct vb2_ops.
- * They contain boilerplate code that most if not all drivers have to do
- * and so they simplify the driver code.
- */
 
-/* The queue is busy if there is a owner and you are not that owner. */
-static inline bool vb2_queue_is_busy(struct video_device *vdev, struct file *file)
+static int v4l2_init_timestamp(struct vb2_buffer *vb)
 {
-	return vdev->queue->owner && vdev->queue->owner != file->private_data;
-}
-
-/* vb2 ioctl helpers */
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
 
-int vb2_ioctl_reqbufs(struct file *file, void *priv,
-			  struct v4l2_requestbuffers *p)
-{
-	struct video_device *vdev = video_devdata(file);
-	int res = __verify_memory_type(vdev->queue, p->memory, p->type);
+	cb->v4l2_buf.timestamp.tv_sec = 0;
+	cb->v4l2_buf.timestamp.tv_usec = 0;
+	cb->v4l2_buf.sequence = 0;
 
-	if (res)
-		return res;
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	res = __reqbufs(vdev->queue, p);
-	/* If count == 0, then the owner has released all buffers and he
-	   is no longer owner of the queue. Otherwise we have a new owner. */
-	if (res == 0)
-		vdev->queue->owner = p->count ? file->private_data : NULL;
-	return res;
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_reqbufs);
 
-int vb2_ioctl_create_bufs(struct file *file, void *priv,
-			  struct v4l2_create_buffers *p)
+static int v4l2_set_timestamp(struct vb2_buffer *vb, void *pb)
 {
-	struct video_device *vdev = video_devdata(file);
-	int res = __verify_memory_type(vdev->queue, p->memory, p->format.type);
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct vb2_queue *q = vb->vb2_queue;
 
-	p->index = vdev->queue->num_buffers;
-	/* If count == 0, then just check if memory and type are valid.
-	   Any -EBUSY result from __verify_memory_type can be mapped to 0. */
-	if (p->count == 0)
-		return res != -EBUSY ? res : 0;
-	if (res)
-		return res;
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	res = __create_bufs(vdev->queue, p);
-	if (res == 0)
-		vdev->queue->owner = file->private_data;
-	return res;
+	if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
+			V4L2_BUF_FLAG_TIMESTAMP_COPY)
+		cb->v4l2_buf.timestamp = b->timestamp;
+	cb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
+	if (b->flags & V4L2_BUF_FLAG_TIMECODE)
+		cb->v4l2_buf.timecode = b->timecode;
+
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_create_bufs);
 
-int vb2_ioctl_prepare_buf(struct file *file, void *priv,
-			  struct v4l2_buffer *p)
+static int v4l2_poll_wait(struct file *file, unsigned long req_events, poll_table *wait)
 {
-	struct video_device *vdev = video_devdata(file);
+	struct video_device *vfd = video_devdata(file);
+	int ret = 0;
 
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	return vb2_prepare_buf(vdev->queue, p);
+	if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
+		struct v4l2_fh *fh = file->private_data;
+
+		if (v4l2_event_pending(fh))
+			ret = POLLPRI;
+		else if (req_events & POLLPRI)
+			poll_wait(file, &fh->wait, wait);
+	}
+	return ret;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_prepare_buf);
 
-int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
+static int v4l2_get_buffer_index(struct vb2_buffer *vb)
 {
-	struct video_device *vdev = video_devdata(file);
-
-	/* No need to call vb2_queue_is_busy(), anyone can query buffers. */
-	return vb2_querybuf(vdev->queue, p);
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	return (int)cb->v4l2_buf.index;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_querybuf);
 
-int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+static int v4l2_set_plane_length(struct vb2_buffer *vb, int plane, unsigned int val)
 {
-	struct video_device *vdev = video_devdata(file);
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	cb->v4l2_planes[plane].length = val;
+	return 0;
+}
 
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	return vb2_qbuf(vdev->queue, p);
+static int v4l2_get_plane_length(struct vb2_buffer *vb, int plane)
+{
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	return cb->v4l2_planes[plane].length;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_qbuf);
 
-int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+static int v4l2_init_buffer(struct vb2_buffer *vb, struct vb2_queue *q,
+		unsigned int buffer, unsigned int memory, unsigned int planes)
 {
-	struct video_device *vdev = video_devdata(file);
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
 
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	return vb2_dqbuf(vdev->queue, p, file->f_flags & O_NONBLOCK);
+	cb->v4l2_buf.index = q->num_buffers + buffer;
+	cb->v4l2_buf.type = q->type;
+	cb->v4l2_buf.memory = memory;
+
+	/* Length stores number of planes for multiplanar buffers */
+	if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
+		cb->v4l2_buf.length = planes;
+
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_dqbuf);
 
-int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
+/**
+ * v4l2_setup_offsets() - setup unique offsets ("cookies") for every plane in
+ * every buffer on the queue
+ */
+static int v4l2_setup_offsets(struct vb2_queue *q, unsigned int n)
 {
-	struct video_device *vdev = video_devdata(file);
+	unsigned int buffer, plane;
+	struct vb2_v4l2_buffer *cb;
+	struct vb2_buffer *vb;
+	unsigned long off;
 
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	return vb2_streamon(vdev->queue, i);
+	if (q->num_buffers) {
+		struct v4l2_plane *p;
+		vb = q->bufs[q->num_buffers - 1];
+		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+		p = &cb->v4l2_planes[vb->num_planes - 1];
+		off = PAGE_ALIGN(p->m.mem_offset + p->length);
+	} else {
+		off = 0;
+	}
+
+	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
+		vb = q->bufs[buffer];
+		if (!vb)
+			continue;
+
+		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+		for (plane = 0; plane < vb->num_planes; ++plane) {
+			cb->v4l2_planes[plane].m.mem_offset = off;
+
+			dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
+					buffer, plane, off);
+
+			off += cb->v4l2_planes[plane].length;
+			off = PAGE_ALIGN(off);
+		}
+	}
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_streamon);
 
-int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
+/**
+ * v4l2_verify_planes_array() - verify that the planes array passed in struct
+ * v4l2_buffer from userspace can be safely used
+ */
+static int v4l2_verify_planes_array(struct vb2_buffer *vb, void *pb)
 {
-	struct video_device *vdev = video_devdata(file);
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
+		return 0;
 
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	return vb2_streamoff(vdev->queue, i);
-}
-EXPORT_SYMBOL_GPL(vb2_ioctl_streamoff);
+	/* Is memory for copying plane information present? */
+	if (NULL == b->m.planes) {
+		dprintk(1, "multi-planar buffer passed but "
+			   "planes array not provided\n");
+		return -EINVAL;
+	}
 
-int vb2_ioctl_expbuf(struct file *file, void *priv, struct v4l2_exportbuffer *p)
-{
-	struct video_device *vdev = video_devdata(file);
+	if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
+		dprintk(1, "incorrect planes array length, "
+			   "expected %d, got %d\n", vb->num_planes, b->length);
+		return -EINVAL;
+	}
 
-	if (vb2_queue_is_busy(vdev, file))
-		return -EBUSY;
-	return vb2_expbuf(vdev->queue, p);
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_ioctl_expbuf);
-
-/* v4l2_file_operations helpers */
 
-int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma)
+/**
+ * v4l2_verify_length() - Verify that the bytesused value for each plane fits in
+ * the plane length and that the data offset doesn't exceed the bytesused value.
+ */
+static int v4l2_verify_length(struct vb2_buffer *vb, void *pb)
 {
-	struct video_device *vdev = video_devdata(file);
-
-	return vb2_mmap(vdev->queue, vma);
-}
-EXPORT_SYMBOL_GPL(vb2_fop_mmap);
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+	unsigned int length;
+	unsigned int bytesused;
+	unsigned int plane;
 
-int _vb2_fop_release(struct file *file, struct mutex *lock)
-{
-	struct video_device *vdev = video_devdata(file);
+	if (!V4L2_TYPE_IS_OUTPUT(b->type))
+		return 0;
 
-	if (lock)
-		mutex_lock(lock);
-	if (file->private_data == vdev->queue->owner) {
-		vb2_queue_release(vdev->queue);
-		vdev->queue->owner = NULL;
-	}
-	if (lock)
-		mutex_unlock(lock);
-	return v4l2_fh_release(file);
-}
-EXPORT_SYMBOL_GPL(_vb2_fop_release);
+	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
+		for (plane = 0; plane < vb->num_planes; ++plane) {
+			length = (b->memory == V4L2_MEMORY_USERPTR ||
+				  b->memory == V4L2_MEMORY_DMABUF)
+			       ? b->m.planes[plane].length
+			       : cb->v4l2_planes[plane].length;
+			bytesused = b->m.planes[plane].bytesused
+				  ? b->m.planes[plane].bytesused : length;
 
-int vb2_fop_release(struct file *file)
-{
-	struct video_device *vdev = video_devdata(file);
-	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
+			if (b->m.planes[plane].bytesused > length)
+				return -EINVAL;
 
-	return _vb2_fop_release(file, lock);
-}
-EXPORT_SYMBOL_GPL(vb2_fop_release);
+			if (b->m.planes[plane].data_offset > 0 &&
+			    b->m.planes[plane].data_offset >= bytesused)
+				return -EINVAL;
+		}
+	} else {
+		length = (b->memory == V4L2_MEMORY_USERPTR)
+		       ? b->length : cb->v4l2_planes[0].length;
+		bytesused = b->bytesused ? b->bytesused : length;
 
-ssize_t vb2_fop_write(struct file *file, const char __user *buf,
-		size_t count, loff_t *ppos)
-{
-	struct video_device *vdev = video_devdata(file);
-	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
-	int err = -EBUSY;
+		if (b->bytesused > length)
+			return -EINVAL;
+	}
 
-	if (lock && mutex_lock_interruptible(lock))
-		return -ERESTARTSYS;
-	if (vb2_queue_is_busy(vdev, file))
-		goto exit;
-	err = vb2_write(vdev->queue, buf, count, ppos,
-		       file->f_flags & O_NONBLOCK);
-	if (vdev->queue->fileio)
-		vdev->queue->owner = file->private_data;
-exit:
-	if (lock)
-		mutex_unlock(lock);
-	return err;
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_fop_write);
 
-ssize_t vb2_fop_read(struct file *file, char __user *buf,
-		size_t count, loff_t *ppos)
+/**
+ * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
+ * returned to userspace
+ */
+static int v4l2_fill_v4l2_buffer(struct vb2_buffer *vb, void *pb)
 {
-	struct video_device *vdev = video_devdata(file);
-	struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
-	int err = -EBUSY;
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
 
-	if (lock && mutex_lock_interruptible(lock))
-		return -ERESTARTSYS;
-	if (vb2_queue_is_busy(vdev, file))
-		goto exit;
-	err = vb2_read(vdev->queue, buf, count, ppos,
-		       file->f_flags & O_NONBLOCK);
-	if (vdev->queue->fileio)
-		vdev->queue->owner = file->private_data;
-exit:
-	if (lock)
-		mutex_unlock(lock);
-	return err;
-}
-EXPORT_SYMBOL_GPL(vb2_fop_read);
+	/* Copy back data such as timestamp, flags, etc. */
+	memcpy(b, &cb->v4l2_buf, offsetof(struct v4l2_buffer, m));
+	b->reserved2 = cb->v4l2_buf.reserved2;
+	b->reserved = cb->v4l2_buf.reserved;
 
-unsigned int vb2_fop_poll(struct file *file, poll_table *wait)
-{
-	struct video_device *vdev = video_devdata(file);
-	struct vb2_queue *q = vdev->queue;
-	struct mutex *lock = q->lock ? q->lock : vdev->lock;
-	unsigned res;
-	void *fileio;
+	if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) {
+		/*
+		 * Fill in plane-related data if userspace provided an array
+		 * for it. The caller has already verified memory and size.
+		 */
+		b->length = vb->num_planes;
+		memcpy(b->m.planes, cb->v4l2_planes,
+			b->length * sizeof(struct v4l2_plane));
+	} else {
+		/*
+		 * We use length and offset in v4l2_planes array even for
+		 * single-planar buffers, but userspace does not.
+		 */
+		b->length = cb->v4l2_planes[0].length;
+		b->bytesused = cb->v4l2_planes[0].bytesused;
+		if (q->memory == V4L2_MEMORY_MMAP)
+			b->m.offset = cb->v4l2_planes[0].m.mem_offset;
+		else if (q->memory == V4L2_MEMORY_USERPTR)
+			b->m.userptr = cb->v4l2_planes[0].m.userptr;
+		else if (q->memory == V4L2_MEMORY_DMABUF)
+			b->m.fd = cb->v4l2_planes[0].m.fd;
+	}
 
 	/*
-	 * If this helper doesn't know how to lock, then you shouldn't be using
-	 * it but you should write your own.
+	 * Clear any buffer state related flags.
 	 */
-	WARN_ON(!lock);
-
-	if (lock && mutex_lock_interruptible(lock))
-		return POLLERR;
+	b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
+	b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
+	if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
+	    V4L2_BUF_FLAG_TIMESTAMP_COPY) {
+		/*
+		 * For non-COPY timestamps, drop timestamp source bits
+		 * and obtain the timestamp source from the queue.
+		 */
+		b->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+	}
 
-	fileio = q->fileio;
+	switch (vb->state) {
+	case VB2_BUF_STATE_QUEUED:
+	case VB2_BUF_STATE_ACTIVE:
+		b->flags |= V4L2_BUF_FLAG_QUEUED;
+		break;
+	case VB2_BUF_STATE_ERROR:
+		b->flags |= V4L2_BUF_FLAG_ERROR;
+		/* fall through */
+	case VB2_BUF_STATE_DONE:
+		b->flags |= V4L2_BUF_FLAG_DONE;
+		break;
+	case VB2_BUF_STATE_PREPARED:
+		b->flags |= V4L2_BUF_FLAG_PREPARED;
+		break;
+	case VB2_BUF_STATE_PREPARING:
+	case VB2_BUF_STATE_DEQUEUED:
+		/* nothing */
+		break;
+	}
 
-	res = vb2_poll(vdev->queue, file, wait);
+	if (__buffer_in_use(q, vb))
+		b->flags |= V4L2_BUF_FLAG_MAPPED;
 
-	/* If fileio was started, then we have a new queue owner. */
-	if (!fileio && q->fileio)
-		q->owner = file->private_data;
-	if (lock)
-		mutex_unlock(lock);
-	return res;
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_fop_poll);
 
-#ifndef CONFIG_MMU
-unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
-		unsigned long len, unsigned long pgoff, unsigned long flags)
+/**
+ * v4l2_find_plane_by_offset() - find plane associated with the given offset off
+ */
+static int v4l2_find_plane_by_offset(struct vb2_queue *q, unsigned long off,
+			unsigned int *_buffer, unsigned int *_plane)
 {
-	struct video_device *vdev = video_devdata(file);
-
-	return vb2_get_unmapped_area(vdev->queue, addr, len, pgoff, flags);
-}
-EXPORT_SYMBOL_GPL(vb2_fop_get_unmapped_area);
-#endif
+	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *cb;
+	unsigned int buffer, plane;
 
-/* vb2_ops helpers. Only use if vq->lock is non-NULL. */
+	/*
+	 * Go over all buffers and their planes, comparing the given offset
+	 * with an offset assigned to each plane. If a match is found,
+	 * return its buffer and plane numbers.
+	 */
+	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
+		vb = q->bufs[buffer];
+		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
+		for (plane = 0; plane < vb->num_planes; ++plane) {
+			if (cb->v4l2_planes[plane].m.mem_offset == off) {
+				*_buffer = buffer;
+				*_plane = plane;
+				return 0;
+			}
+		}
+	}
 
-void vb2_ops_wait_prepare(struct vb2_queue *vq)
-{
-	mutex_unlock(vq->lock);
+	return -EINVAL;
 }
-EXPORT_SYMBOL_GPL(vb2_ops_wait_prepare);
 
-void vb2_ops_wait_finish(struct vb2_queue *vq)
-{
-	mutex_lock(vq->lock);
-}
-EXPORT_SYMBOL_GPL(vb2_ops_wait_finish);
+const struct vb2_priv_ops vb2_v4l2_operations = {
+	.get_buffer_index = v4l2_get_buffer_index,
+	.set_plane_length = v4l2_set_plane_length,
+	.get_plane_length = v4l2_get_plane_length,
+	.init_priv_buffer = v4l2_init_buffer,
+	.setup_offsets = v4l2_setup_offsets,
+	.verify_planes_array = v4l2_verify_planes_array,
+	.verify_length = v4l2_verify_length,
+	.fill_priv_buffer = v4l2_fill_v4l2_buffer,
+	.fill_vb2_buffer = v4l2_fill_vb2_buffer,
+	.qbuf_mmap = v4l2_qbuf_mmap,
+	.qbuf_userptr = v4l2_qbuf_userptr,
+	.qbuf_dmabuf = v4l2_qbuf_dmabuf,
+	.is_alternate = v4l2_is_alternate,
+	.init_timestamp = v4l2_init_timestamp,
+	.set_timestamp = v4l2_set_timestamp,
+	.find_plane_by_offset = v4l2_find_plane_by_offset,
+	.poll_wait = v4l2_poll_wait,
+};
+EXPORT_SYMBOL_GPL(vb2_v4l2_operations);
 
 MODULE_DESCRIPTION("Driver helper framework for Video for Linux 2");
 MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>, Marek Szyprowski");
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index 225c2a6..f4f2e07 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -103,7 +103,7 @@ void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
 static inline void
 v4l2_m2m_buf_done(struct vb2_v4l2_buffer *buf, enum vb2_buffer_state state)
 {
-	vb2_buffer_done(buf, state);
+	vb2_buffer_done(&buf->vb2, state);
 }
 
 int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 24c229d..5e379a4 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -18,6 +18,48 @@
 #include <linux/videodev2.h>
 #include <linux/dma-buf.h>
 
+// redefine enum values and macro function common-used
+#define MEDIA_MAX_FRAME		(VIDEO_MAX_FRAME) //32
+#define MEDIA_MAX_PLANES    (VIDEO_MAX_PLANES) //8
+
+enum media_memory {
+	MEDIA_MEMORY_MMAP		= V4L2_MEMORY_MMAP,
+	MEDIA_MEMORY_USERPTR	= V4L2_MEMORY_USERPTR,
+	MEDIA_MEMORY_OVERLAY	= V4L2_MEMORY_OVERLAY,
+	MEDIA_MEMORY_DMABUF		= V4L2_MEMORY_DMABUF,
+};
+
+enum media_buf_type {
+	MEDIA_BUF_TYPE_VIDEO_CAPTURE		= V4L2_BUF_TYPE_VIDEO_CAPTURE,
+	MEDIA_BUF_TYPE_VIDEO_OUTPUT			= V4L2_BUF_TYPE_VIDEO_OUTPUT,
+	MEDIA_BUF_TYPE_VIDEO_OVERLAY		= V4L2_BUF_TYPE_VIDEO_OVERLAY,
+	MEDIA_BUF_TYPE_VBI_CAPTURE			= V4L2_BUF_TYPE_VBI_CAPTURE,
+	MEDIA_BUF_TYPE_VBI_OUTPUT			= V4L2_BUF_TYPE_VBI_OUTPUT,
+	MEDIA_BUF_TYPE_SLICED_VBI_CAPTURE	= V4L2_BUF_TYPE_SLICED_VBI_CAPTURE,
+	MEDIA_BUF_TYPE_SLICED_VBI_OUTPUT	= V4L2_BUF_TYPE_SLICED_VBI_OUTPUT,
+#if 1
+	/* Experimental */
+	MEDIA_BUF_TYPE_VIDEO_OUTPUT_OVERLAY	= V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY,
+#endif
+	MEDIA_BUF_TYPE_VIDEO_CAPTURE_MPLANE	= V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+	MEDIA_BUF_TYPE_VIDEO_OUTPUT_MPLANE	= V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+	MEDIA_BUF_TYPE_SDR_CAPTURE			= V4L2_BUF_TYPE_SDR_CAPTURE,
+	/* Deprecated, do not use */
+	MEDIA_BUF_TYPE_PRIVATE				= 0x80,
+	MEDIA_BUF_TYPE_DVB_CAPTURE			= 0x81,
+	MEDIA_BUF_TYPE_DVB_OUTPUT			= 0x82,
+};
+
+#define MEDIA_TYPE_IS_MULTIPLANAR(type)		\
+		(V4L2_TYPE_IS_MULTIPLANAR(type))
+
+#define MEDIA_TYPE_IS_OUTPUT(type)			\
+		(V4L2_TYPE_IS_OUTPUT(type) || (type) == MEDIA_BUF_TYPE_DVB_OUTPUT)
+
+#define MEDIA_TYPE_IS_DVB(type)			\
+		((type) == MEDIA_BUF_TYPE_DVB_CAPTURE	\
+		|| (type) == MEDIA_BUF_TYPE_DVB_OUTPUT)
+
 struct vb2_alloc_ctx;
 struct vb2_fileio_data;
 struct vb2_threadio_data;
@@ -192,7 +234,7 @@ struct vb2_buffer {
 	struct list_head	queued_entry;
 	struct list_head	done_entry;
 
-	struct vb2_plane	planes[VIDEO_MAX_PLANES];
+	struct vb2_plane	planes[MEDIA_MAX_PLANES];
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	/*
@@ -324,6 +366,29 @@ struct vb2_ops {
 	void (*buf_queue)(struct vb2_buffer *vb);
 };
 
+struct vb2_priv_ops {
+	int (*get_buffer_index)(struct vb2_buffer *vb);
+	int (*set_plane_length)(struct vb2_buffer *vb, int plane, unsigned int val);
+	int (*get_plane_length)(struct vb2_buffer *vb, int plane);
+	int (*init_priv_buffer)(struct vb2_buffer *vb, struct vb2_queue *q,
+		unsigned int buffer, unsigned int memory, unsigned int planes);
+	int (*setup_offsets)(struct vb2_queue *q, unsigned int n);
+	int (*verify_planes_array)(struct vb2_buffer *vb, void *pb);
+	int (*verify_length)(struct vb2_buffer *vb, void *pb);
+	int (*fill_priv_buffer)(struct vb2_buffer *vb, void *pb);
+	int (*fill_vb2_buffer)(struct vb2_buffer *vb, void *pbuffer, void *pplane);
+	int (*qbuf_mmap)(struct vb2_buffer *vb, void *pb);
+	int (*qbuf_userptr)(struct vb2_buffer *vb, void *pb);
+	int (*qbuf_dmabuf)(struct vb2_buffer *vb, void *pb);
+	int (*is_alternate)(void *pb);
+	int (*init_timestamp)(struct vb2_buffer *vb);
+	int (*set_timestamp)(struct vb2_buffer *vb, void *pb);
+	int (*find_plane_by_offset)(struct vb2_queue *q, unsigned long off,
+			unsigned int *_buffer, unsigned int *_plane);
+	int (*poll_wait)(struct file *file, unsigned long req_events, poll_table *wait);
+	int (*get_buf_siz)(void);
+};
+
 /**
  * struct vb2_queue - a videobuf queue
  *
@@ -331,7 +396,7 @@ struct vb2_ops {
  * @io_modes:	supported io methods (see vb2_io_modes enum)
  * @io_flags:	additional io flags (see vb2_fileio_flags enum)
  * @lock:	pointer to a mutex that protects the vb2_queue struct. The
- *		driver can set this to a mutex to let the v4l2 core serialize
+ *		driver can set this to a mutex to let the core serialize
  *		the queuing ioctls. If the driver wants to handle locking
  *		itself, then this should be set to NULL. This lock is not used
  *		by the videobuf2 core API.
@@ -385,6 +450,8 @@ struct vb2_queue {
 
 	const struct vb2_ops		*ops;
 	const struct vb2_mem_ops	*mem_ops;
+	const struct vb2_priv_ops    *priv_ops;
+	
 	void				*drv_priv;
 	unsigned int			buf_struct_size;
 	u32				timestamp_flags;
@@ -394,7 +461,7 @@ struct vb2_queue {
 /* private: internal use only */
 	struct mutex			mmap_lock;
 	unsigned int			memory;
-	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
+	struct vb2_buffer		*bufs[MEDIA_MAX_FRAME];
 	unsigned int			num_buffers;
 
 	struct list_head		queued_list;
@@ -405,8 +472,8 @@ struct vb2_queue {
 	spinlock_t			done_lock;
 	wait_queue_head_t		done_wq;
 
-	void				*alloc_ctx[VIDEO_MAX_PLANES];
-	unsigned int			plane_sizes[VIDEO_MAX_PLANES];
+	void				*alloc_ctx[MEDIA_MAX_PLANES];
+	unsigned int			plane_sizes[MEDIA_MAX_PLANES];
 
 	unsigned int			streaming:1;
 	unsigned int			start_streaming_called:1;
@@ -428,4 +495,153 @@ struct vb2_queue {
 	u32				cnt_stop_streaming;
 #endif
 };
+
+int get_vb2_debug(void);
+
+void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
+void vb2_discard_done(struct vb2_queue *q);
+
+int vb2_wait_for_all_buffers(struct vb2_queue *q);
+
+int vb2_core_querybuf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, void *ab);
+int vb2_core_reqbufs(struct vb2_queue *q, unsigned int count, 
+		unsigned int type, unsigned int memory);
+
+int vb2_core_create_bufs(struct vb2_queue *q, unsigned int count,
+		unsigned int type, unsigned int memory, void *format);
+int vb2_core_prepare_buf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, unsigned int memory, void *ab);
+
+int __must_check vb2_queue_init(struct vb2_queue *q);
+
+void vb2_queue_release(struct vb2_queue *q);
+void vb2_queue_error(struct vb2_queue *q);
+
+int vb2_core_qbuf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, unsigned int memory, void *ab);
+int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
+		unsigned int plane, unsigned int flags);
+int vb2_core_dqbuf(struct vb2_queue *q, enum media_buf_type type, void *ab, bool nonblocking);
+
+int vb2_core_streamon(struct vb2_queue *q, enum media_buf_type type);
+int vb2_core_streamoff(struct vb2_queue *q, enum media_buf_type type);
+
+int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
+int vb2_internal_dqbuf(struct vb2_queue *q, enum media_buf_type type, void *pb,
+		bool nonblocking);
+int vb2_internal_qbuf(struct vb2_queue *q, enum media_buf_type type,
+		unsigned int index, unsigned int memory, void *pb);
+int vb2_internal_streamoff(struct vb2_queue *q, enum media_buf_type type);
+int vb2_internal_streamon(struct vb2_queue *q, enum media_buf_type type);
+
+#ifndef CONFIG_MMU
+unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
+				    unsigned long addr,
+				    unsigned long len,
+				    unsigned long pgoff,
+				    unsigned long flags);
+#endif
+unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
+size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
+		loff_t *ppos, int nonblock);
+size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
+		loff_t *ppos, int nonblock);
+/**
+ * vb2_thread_fnc - callback function for use with vb2_thread
+ *
+ * This is called whenever a buffer is dequeued in the thread.
+ */
+typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
+
+/**
+ * vb2_thread_start() - start a thread for the given queue.
+ * @q:		videobuf queue
+ * @fnc:	callback function
+ * @priv:	priv pointer passed to the callback function
+ * @thread_name:the name of the thread. This will be prefixed with "vb2-".
+ *
+ * This starts a thread that will queue and dequeue until an error occurs
+ * or @vb2_thread_stop is called.
+ *
+ * This function should not be used for anything else but the videobuf2-dvb
+ * support. If you think you have another good use-case for this, then please
+ * contact the linux-media mailinglist first.
+ */
+int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
+		     const char *thread_name);
+
+/**
+ * vb2_thread_stop() - stop the thread for the given queue.
+ * @q:		videobuf queue
+ */
+int vb2_thread_stop(struct vb2_queue *q);
+
+/**
+ * vb2_is_streaming() - return streaming status of the queue
+ * @q:		videobuf queue
+ */
+static inline bool vb2_is_streaming(struct vb2_queue *q)
+{
+	return q->streaming;
+}
+
+/**
+ * vb2_fileio_is_active() - return true if fileio is active.
+ * @q:		videobuf queue
+ *
+ * This returns true if read() or write() is used to stream the data
+ * as opposed to stream I/O. This is almost never an important distinction,
+ * except in rare cases. One such case is that using read() or write() to
+ * stream a format using V4L2_FIELD_ALTERNATE is not allowed since there
+ * is no way you can pass the field information of each buffer to/from
+ * userspace. A driver that supports this field format should check for
+ * this in the queue_setup op and reject it if this function returns true.
+ */
+static inline bool vb2_fileio_is_active(struct vb2_queue *q)
+{
+	return q->fileio;
+}
+
+/**
+ * vb2_is_busy() - return busy status of the queue
+ * @q:		videobuf queue
+ *
+ * This function checks if queue has any buffers allocated.
+ */
+static inline bool vb2_is_busy(struct vb2_queue *q)
+{
+	return (q->num_buffers > 0);
+}
+
+/**
+ * vb2_get_drv_priv() - return driver private data associated with the queue
+ * @q:		videobuf queue
+ */
+static inline void *vb2_get_drv_priv(struct vb2_queue *q)
+{
+	return q->drv_priv;
+}
+
+/**
+ * vb2_start_streaming_called() - return streaming status of driver
+ * @q:		videobuf queue
+ */
+static inline bool vb2_start_streaming_called(struct vb2_queue *q)
+{
+	return q->start_streaming_called;
+}
+
+bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
+int __verify_memory_type(struct vb2_queue *q,
+		enum media_memory memory, enum media_buf_type type);
+void __vb2_queue_cancel(struct vb2_queue *q);
+int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers);
+int __reqbufs(struct vb2_queue *q, unsigned int count,
+		unsigned int type, unsigned int memory);
+int __create_bufs(struct vb2_queue *q,  unsigned int count,
+		unsigned int type, unsigned int memory, void *format);
+void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p);
+void __vb2_buf_dmabuf_put(struct vb2_buffer *vb);
+
 #endif /* _MEDIA_VIDEOBUF2_CORE_H */
diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h
index 36f7ea3..e054baa 100644
--- a/include/media/videobuf2-dma-sg.h
+++ b/include/media/videobuf2-dma-sg.h
@@ -16,9 +16,9 @@
 #include <media/videobuf2-v4l2.h>
 
 static inline struct sg_table *vb2_dma_sg_plane_desc(
-		struct vb2_v4l2_buffer *vb, unsigned int plane_no)
+		struct vb2_v4l2_buffer *cb, unsigned int plane_no)
 {
-	return (struct sg_table *)vb2_plane_cookie(vb, plane_no);
+	return (struct sg_table *)vb2_plane_cookie(cb, plane_no);
 }
 
 void *vb2_dma_sg_init_ctx(struct device *dev);
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index cd2b6b9..17136f3 100644
--- a/include/media/videobuf2-v4l2.h
+++ b/include/media/videobuf2-v4l2.h
@@ -42,117 +42,15 @@ struct vb2_v4l2_buffer {
 
 void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no);
 void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no);
-
-void vb2_buffer_done(struct vb2_v4l2_buffer *cb, enum vb2_buffer_state state);
-void vb2_discard_done(struct vb2_queue *q);
-int vb2_wait_for_all_buffers(struct vb2_queue *q);
-
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
-
 int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create);
 int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
-
-int __must_check vb2_queue_init(struct vb2_queue *q);
-
-void vb2_queue_release(struct vb2_queue *q);
-void vb2_queue_error(struct vb2_queue *q);
-
 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
-int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
 int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
-
 int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
 int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
-
-int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
-#ifndef CONFIG_MMU
-unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
-				    unsigned long addr,
-				    unsigned long len,
-				    unsigned long pgoff,
-				    unsigned long flags);
-#endif
-unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
-size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
-		loff_t *ppos, int nonblock);
-size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
-		loff_t *ppos, int nonblock);
-/**
- * vb2_thread_fnc - callback function for use with vb2_thread
- *
- * This is called whenever a buffer is dequeued in the thread.
- */
-typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *cb, void *priv);
-
-/**
- * vb2_thread_start() - start a thread for the given queue.
- * @q:		videobuf queue
- * @fnc:	callback function
- * @priv:	priv pointer passed to the callback function
- * @thread_name:the name of the thread. This will be prefixed with "vb2-".
- *
- * This starts a thread that will queue and dequeue until an error occurs
- * or @vb2_thread_stop is called.
- *
- * This function should not be used for anything else but the videobuf2-dvb
- * support. If you think you have another good use-case for this, then please
- * contact the linux-media mailinglist first.
- */
-int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
-		     const char *thread_name);
-
-/**
- * vb2_thread_stop() - stop the thread for the given queue.
- * @q:		videobuf queue
- */
-int vb2_thread_stop(struct vb2_queue *q);
-
-/**
- * vb2_is_streaming() - return streaming status of the queue
- * @q:		videobuf queue
- */
-static inline bool vb2_is_streaming(struct vb2_queue *q)
-{
-	return q->streaming;
-}
-
-/**
- * vb2_fileio_is_active() - return true if fileio is active.
- * @q:		videobuf queue
- *
- * This returns true if read() or write() is used to stream the data
- * as opposed to stream I/O. This is almost never an important distinction,
- * except in rare cases. One such case is that using read() or write() to
- * stream a format using V4L2_FIELD_ALTERNATE is not allowed since there
- * is no way you can pass the field information of each buffer to/from
- * userspace. A driver that supports this field format should check for
- * this in the queue_setup op and reject it if this function returns true.
- */
-static inline bool vb2_fileio_is_active(struct vb2_queue *q)
-{
-	return q->fileio;
-}
-
-/**
- * vb2_is_busy() - return busy status of the queue
- * @q:		videobuf queue
- *
- * This function checks if queue has any buffers allocated.
- */
-static inline bool vb2_is_busy(struct vb2_queue *q)
-{
-	return (q->num_buffers > 0);
-}
-
-/**
- * vb2_get_drv_priv() - return driver private data associated with the queue
- * @q:		videobuf queue
- */
-static inline void *vb2_get_drv_priv(struct vb2_queue *q)
-{
-	return q->drv_priv;
-}
+int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
 
 /**
  * vb2_set_plane_payload() - set bytesused for the plane plane_no
@@ -194,15 +92,6 @@ vb2_plane_size(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
 	return 0;
 }
 
-/**
- * vb2_start_streaming_called() - return streaming status of driver
- * @q:		videobuf queue
- */
-static inline bool vb2_start_streaming_called(struct vb2_queue *q)
-{
-	return q->start_streaming_called;
-}
-
 /*
  * The following functions are not part of the vb2 core API, but are simple
  * helper functions that you can use in your struct v4l2_file_operations,
@@ -222,13 +111,12 @@ int vb2_ioctl_prepare_buf(struct file *file, void *priv,
 int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
 int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
 int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
-int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
-int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
+int vb2_ioctl_streamon(struct file *file, void *priv, unsigned int type);
+int vb2_ioctl_streamoff(struct file *file, void *priv, unsigned int type);
 int vb2_ioctl_expbuf(struct file *file, void *priv,
 	struct v4l2_exportbuffer *p);
 
-/* struct v4l2_file_operations helpers */
-
+/* struct file_operations helpers */
 int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
 int vb2_fop_release(struct file *file);
 int _vb2_fop_release(struct file *file, struct mutex *lock);
@@ -247,4 +135,5 @@ unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
 void vb2_ops_wait_prepare(struct vb2_queue *vq);
 void vb2_ops_wait_finish(struct vb2_queue *vq);
 
+
 #endif /* _MEDIA_VIDEOBUF2_V4L2_H */
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 0/3] Refactoring Videobuf2 for common use
  2015-06-08 13:35 [RFC PATCH 0/3] Refactoring Videobuf2 for common use Junghak Sung
  2015-06-08 13:35 ` [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer Junghak Sung
  2015-06-08 13:35 ` [RFC PATCH 3/3] make vb2-core part with not v4l2-specific elements Junghak Sung
@ 2015-06-08 14:42 ` Hans Verkuil
  2015-06-08 17:39   ` Mauro Carvalho Chehab
  2015-06-12 10:51 ` Hans Verkuil
       [not found] ` <1433770535-21143-3-git-send-email-jh1009.sung@samsung.com>
  4 siblings, 1 reply; 15+ messages in thread
From: Hans Verkuil @ 2015-06-08 14:42 UTC (permalink / raw)
  To: Junghak Sung, linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim

On 06/08/2015 03:35 PM, Junghak Sung wrote:
> Hello everybody,
> 
> This patch series refactories exsiting Videobuf2, so that not only V4L2
> but also other frameworks can use it to manage buffer and utilize
> queue.
> 
> I would separate existing Videobuf2-core framework into two parts - common
> and v4l2-specific part. This work is as follows :
> 
> 1. Separate existing vb2_buffer structure into common buffer and
>    v4l2-specific parts by removing v4l2-specific members and
>    embedding it into vb2_v4l2_buffer structure like this:
> 
>     struct vb2_v4l2_buffer {
>         struct vb2_buffer    vb2;
>         struct v4l2_buffer   v4l2_buf;
>         struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
>     };
> 
> 2. Abstract the v4l2-specific elements, and specify them when the device
>    drives use them. For example, vb2_v4l2_buffer structure can be abstracted
>    by vb2_buffer structure, and device drivers can get framework-specific
>    object such as vb2_v4l2_buffer by using container_of().
> 
> 3. Separate VB2-core framework into real VB2-core and v4l2-specific part.
>    This means that it moves V4L2-specific parts of VB2-core to v4l2-specific
>    part because current VB2-core framework has some codes dependent of V4L2.
>    As a result, we will have two VB2 files - videobuf2-core.c and
>    videobuf2-v4l2.c.
> 
> Why do we try to make the VB2 framework to be common?
> 
> As you may know, current DVB framework uses ringbuffer mechanism to demux
> MPEG-2 TS data and pass it to userspace. However, this mechanism requires
> extra memory copy because DVB framework provides only read() system call for
> application - read() system call copies the kernel data to user-space buffer.
> 
> So if we can use VB2 framework which supports streaming I/O and buffer
> sharing mechanism, then we could enhance existing DVB framework by removing
> the extra memory copy - with VB2 framework, application can access the kernel
> data directly through mmap system call.
> 
> This patch series is the first step for it.
> 
> We have a plan for this work as follows:
> 
> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2,
>    and VB2-dvb. Of course, this change should not affect other v4l2-based
>    device drivers. This patch series includes some parts of this step.
> 
> 2. Add new APIs for DVB streaming I/O. These APIs will be implemented
>    in VB2-dvb framework. So, we can remove unnecessary memory copy between
>    kernel-space and user-space by using these new APIs.
>    However, we leaves legacy interfaces as-is for backward compatibility.
> 
> We are working on this project with Mauro and have a discussion with him
> on IRC channel weekly. Nowaday, we are discussing more detailed DVB user
> scenario for streaming I/O.
> 
> The final goal of this project is to enhance current DVB framework.
> The first mission is to achieve zero-copy functionality between kernel-space
> and user-space with mmap system call. More missions are under consideration:
> i.e., we could share the buffer not only between kernel-space and user-space
> but also between devices - demux, hw video codec - by exporting a buffer
> to dmabuf fd with VB2 framework.
> 
> Any suggestions and comments are welcome.
> 
> Best regards,
> Junghak
> 
> Junghak Sung (3):
>   modify the vb2_buffer structure for common video buffer     and make
>     struct vb2_v4l2_buffer
>   move struct vb2_queue to common and apply the changes related with
>     that     Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>   make vb2-core part with not v4l2-specific elements

Patch 2/3 didn't arrive at linux-media for some reason. Can you post it again?

Thanks!

	Hans

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 0/3] Refactoring Videobuf2 for common use
  2015-06-08 14:42 ` [RFC PATCH 0/3] Refactoring Videobuf2 for common use Hans Verkuil
@ 2015-06-08 17:39   ` Mauro Carvalho Chehab
  2015-06-09  1:41     ` Junghak Sung
  0 siblings, 1 reply; 15+ messages in thread
From: Mauro Carvalho Chehab @ 2015-06-08 17:39 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Junghak Sung, linux-media, sangbae90.lee, inki.dae, nenggun.kim,
	sw0312.kim

Em Mon, 08 Jun 2015 16:42:48 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 06/08/2015 03:35 PM, Junghak Sung wrote:
> > Hello everybody,
> > 
> > This patch series refactories exsiting Videobuf2, so that not only V4L2
> > but also other frameworks can use it to manage buffer and utilize
> > queue.
> > 
> > I would separate existing Videobuf2-core framework into two parts - common
> > and v4l2-specific part. This work is as follows :
> > 
> > 1. Separate existing vb2_buffer structure into common buffer and
> >    v4l2-specific parts by removing v4l2-specific members and
> >    embedding it into vb2_v4l2_buffer structure like this:
> > 
> >     struct vb2_v4l2_buffer {
> >         struct vb2_buffer    vb2;
> >         struct v4l2_buffer   v4l2_buf;
> >         struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
> >     };
> > 
> > 2. Abstract the v4l2-specific elements, and specify them when the device
> >    drives use them. For example, vb2_v4l2_buffer structure can be abstracted
> >    by vb2_buffer structure, and device drivers can get framework-specific
> >    object such as vb2_v4l2_buffer by using container_of().
> > 
> > 3. Separate VB2-core framework into real VB2-core and v4l2-specific part.
> >    This means that it moves V4L2-specific parts of VB2-core to v4l2-specific
> >    part because current VB2-core framework has some codes dependent of V4L2.
> >    As a result, we will have two VB2 files - videobuf2-core.c and
> >    videobuf2-v4l2.c.
> > 
> > Why do we try to make the VB2 framework to be common?
> > 
> > As you may know, current DVB framework uses ringbuffer mechanism to demux
> > MPEG-2 TS data and pass it to userspace. However, this mechanism requires
> > extra memory copy because DVB framework provides only read() system call for
> > application - read() system call copies the kernel data to user-space buffer.
> > 
> > So if we can use VB2 framework which supports streaming I/O and buffer
> > sharing mechanism, then we could enhance existing DVB framework by removing
> > the extra memory copy - with VB2 framework, application can access the kernel
> > data directly through mmap system call.
> > 
> > This patch series is the first step for it.
> > 
> > We have a plan for this work as follows:
> > 
> > 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2,
> >    and VB2-dvb. Of course, this change should not affect other v4l2-based
> >    device drivers. This patch series includes some parts of this step.
> > 
> > 2. Add new APIs for DVB streaming I/O. These APIs will be implemented
> >    in VB2-dvb framework. So, we can remove unnecessary memory copy between
> >    kernel-space and user-space by using these new APIs.
> >    However, we leaves legacy interfaces as-is for backward compatibility.
> > 
> > We are working on this project with Mauro and have a discussion with him
> > on IRC channel weekly. Nowaday, we are discussing more detailed DVB user
> > scenario for streaming I/O.
> > 
> > The final goal of this project is to enhance current DVB framework.
> > The first mission is to achieve zero-copy functionality between kernel-space
> > and user-space with mmap system call. More missions are under consideration:
> > i.e., we could share the buffer not only between kernel-space and user-space
> > but also between devices - demux, hw video codec - by exporting a buffer
> > to dmabuf fd with VB2 framework.
> > 
> > Any suggestions and comments are welcome.
> > 
> > Best regards,
> > Junghak
> > 
> > Junghak Sung (3):
> >   modify the vb2_buffer structure for common video buffer     and make
> >     struct vb2_v4l2_buffer
> >   move struct vb2_queue to common and apply the changes related with
> >     that     Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> >   make vb2-core part with not v4l2-specific elements
> 
> Patch 2/3 didn't arrive at linux-media for some reason. Can you post it again?

Probably, the patch is too big. Vger doesn't accept patches bigger than
a few hundreds of KB. Not sure what's the current limit.

Junghak added the patches on his tree too:
	http://git.linuxtv.org/cgit.cgi/jsung/dvb-vb2.git/log/?h=dvb-vb2

Junghak,

You may try to play with the git options that improve rename/copy files,
like:
	--find-copies-harder
	-M
	-C

The last two options accepts a percentage parameter, like:
  -C60	for detect changes that keep up to 60% of the original content.

and:
	--diff-algorithm=minimal
	--diff-algorithm=patience

Maybe with those options, the email produced by git format-patch will
be small enough to fit at the VGER mailing list limits.

If none of those work, please let us know.

Regards,
Mauro
 

> Thanks!
> 
> 	Hans

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 0/3] Refactoring Videobuf2 for common use
  2015-06-08 17:39   ` Mauro Carvalho Chehab
@ 2015-06-09  1:41     ` Junghak Sung
  0 siblings, 0 replies; 15+ messages in thread
From: Junghak Sung @ 2015-06-09  1:41 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Hans Verkuil
  Cc: linux-media, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim



On 06/09/2015 02:39 AM, Mauro Carvalho Chehab wrote:
> Em Mon, 08 Jun 2015 16:42:48 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
>
>> On 06/08/2015 03:35 PM, Junghak Sung wrote:
>>> Hello everybody,
>>>
>>> This patch series refactories exsiting Videobuf2, so that not only V4L2
>>> but also other frameworks can use it to manage buffer and utilize
>>> queue.
>>>
>>> I would separate existing Videobuf2-core framework into two parts - common
>>> and v4l2-specific part. This work is as follows :
>>>
>>> 1. Separate existing vb2_buffer structure into common buffer and
>>>     v4l2-specific parts by removing v4l2-specific members and
>>>     embedding it into vb2_v4l2_buffer structure like this:
>>>
>>>      struct vb2_v4l2_buffer {
>>>          struct vb2_buffer    vb2;
>>>          struct v4l2_buffer   v4l2_buf;
>>>          struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
>>>      };
>>>
>>> 2. Abstract the v4l2-specific elements, and specify them when the device
>>>     drives use them. For example, vb2_v4l2_buffer structure can be abstracted
>>>     by vb2_buffer structure, and device drivers can get framework-specific
>>>     object such as vb2_v4l2_buffer by using container_of().
>>>
>>> 3. Separate VB2-core framework into real VB2-core and v4l2-specific part.
>>>     This means that it moves V4L2-specific parts of VB2-core to v4l2-specific
>>>     part because current VB2-core framework has some codes dependent of V4L2.
>>>     As a result, we will have two VB2 files - videobuf2-core.c and
>>>     videobuf2-v4l2.c.
>>>
>>> Why do we try to make the VB2 framework to be common?
>>>
>>> As you may know, current DVB framework uses ringbuffer mechanism to demux
>>> MPEG-2 TS data and pass it to userspace. However, this mechanism requires
>>> extra memory copy because DVB framework provides only read() system call for
>>> application - read() system call copies the kernel data to user-space buffer.
>>>
>>> So if we can use VB2 framework which supports streaming I/O and buffer
>>> sharing mechanism, then we could enhance existing DVB framework by removing
>>> the extra memory copy - with VB2 framework, application can access the kernel
>>> data directly through mmap system call.
>>>
>>> This patch series is the first step for it.
>>>
>>> We have a plan for this work as follows:
>>>
>>> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2,
>>>     and VB2-dvb. Of course, this change should not affect other v4l2-based
>>>     device drivers. This patch series includes some parts of this step.
>>>
>>> 2. Add new APIs for DVB streaming I/O. These APIs will be implemented
>>>     in VB2-dvb framework. So, we can remove unnecessary memory copy between
>>>     kernel-space and user-space by using these new APIs.
>>>     However, we leaves legacy interfaces as-is for backward compatibility.
>>>
>>> We are working on this project with Mauro and have a discussion with him
>>> on IRC channel weekly. Nowaday, we are discussing more detailed DVB user
>>> scenario for streaming I/O.
>>>
>>> The final goal of this project is to enhance current DVB framework.
>>> The first mission is to achieve zero-copy functionality between kernel-space
>>> and user-space with mmap system call. More missions are under consideration:
>>> i.e., we could share the buffer not only between kernel-space and user-space
>>> but also between devices - demux, hw video codec - by exporting a buffer
>>> to dmabuf fd with VB2 framework.
>>>
>>> Any suggestions and comments are welcome.
>>>
>>> Best regards,
>>> Junghak
>>>
>>> Junghak Sung (3):
>>>    modify the vb2_buffer structure for common video buffer     and make
>>>      struct vb2_v4l2_buffer
>>>    move struct vb2_queue to common and apply the changes related with
>>>      that     Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>>>    make vb2-core part with not v4l2-specific elements
>> Patch 2/3 didn't arrive at linux-media for some reason. Can you post it again?
> Probably, the patch is too big. Vger doesn't accept patches bigger than
> a few hundreds of KB. Not sure what's the current limit.
>
> Junghak added the patches on his tree too:
> 	http://git.linuxtv.org/cgit.cgi/jsung/dvb-vb2.git/log/?h=dvb-vb2
>
> Junghak,
>
> You may try to play with the git options that improve rename/copy files,
> like:
> 	--find-copies-harder
> 	-M
> 	-C
>
> The last two options accepts a percentage parameter, like:
>    -C60	for detect changes that keep up to 60% of the original content.
>
> and:
> 	--diff-algorithm=minimal
> 	--diff-algorithm=patience
>
> Maybe with those options, the email produced by git format-patch will
> be small enough to fit at the VGER mailing list limits.
>
> If none of those work, please let us know.
I tried to reduce the size of patch 2/3 with the combinations of git 
options you recommended like :
     --minimal, --patience, -M[n], -C[n], --find-copies-harder
I found the patch 3/3 can be optimized with those options.
But, failed to optimize patch 2/3.
Is there any other solutions?

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer
  2015-06-08 13:35 ` [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer Junghak Sung
@ 2015-06-12  9:58   ` Hans Verkuil
  2015-06-12 10:09     ` Hans Verkuil
  2015-06-17 12:27   ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 15+ messages in thread
From: Hans Verkuil @ 2015-06-12  9:58 UTC (permalink / raw)
  To: Junghak Sung, linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim

Hi Junghak,

On 06/08/2015 03:35 PM, Junghak Sung wrote:
> Make the struct vb2_buffer to common buffer by removing v4l2-specific members.
> And common video buffer is embedded into v4l2-specific video buffer like:
> struct vb2_v4l2_buffer {
>     struct vb2_buffer    vb2;
>     struct v4l2_buffer    v4l2_buf;
>     struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
> };
> This changes require the modifications of all device drivers that use this structure.

It's next to impossible to review just large diffs, but it is unavoidable for
changes like this I guess.

I do recommend that you do a 'git grep videobuf2-core' to make sure all usages
of that have been replaced with videobuf2-v4l2. I think I saw videobuf2-core
mentioned in a comment, but it is hard to be sure.

It would also be easier to review if the renaming of core.[ch] to v4l2.[ch] was
done in a separate patch. If it is relatively easy to split it up like that,
then I would appreciate it, but if it takes a lot of time, then leave it as is.

Anyway, assuming that 'git grep videobuf2-core' doesn't find anything:

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans

> 
> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> ---
>  Documentation/video4linux/v4l2-pci-skeleton.c      |   12 +-
>  drivers/media/dvb-frontends/rtl2832_sdr.c          |   10 +-
>  drivers/media/pci/cx23885/cx23885-417.c            |   12 +-
>  drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
>  drivers/media/pci/cx23885/cx23885-vbi.c            |   12 +-
>  drivers/media/pci/cx23885/cx23885-video.c          |   12 +-
>  drivers/media/pci/cx23885/cx23885.h                |    2 +-
>  drivers/media/pci/cx25821/cx25821-video.c          |   12 +-
>  drivers/media/pci/cx25821/cx25821.h                |    2 +-
>  drivers/media/pci/cx88/cx88-blackbird.c            |   14 +-
>  drivers/media/pci/cx88/cx88-dvb.c                  |   14 +-
>  drivers/media/pci/cx88/cx88-vbi.c                  |   12 +-
>  drivers/media/pci/cx88/cx88-video.c                |   12 +-
>  drivers/media/pci/cx88/cx88.h                      |    2 +-
>  drivers/media/pci/saa7134/saa7134-empress.c        |    2 +-
>  drivers/media/pci/saa7134/saa7134-ts.c             |   10 +-
>  drivers/media/pci/saa7134/saa7134-vbi.c            |   12 +-
>  drivers/media/pci/saa7134/saa7134-video.c          |   18 +-
>  drivers/media/pci/saa7134/saa7134.h                |    8 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   14 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    6 +-
>  drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
>  drivers/media/pci/sta2x11/sta2x11_vip.c            |   20 +-
>  drivers/media/pci/tw68/tw68-video.c                |   12 +-
>  drivers/media/pci/tw68/tw68.h                      |    2 +-
>  drivers/media/platform/am437x/am437x-vpfe.c        |   16 +-
>  drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
>  drivers/media/platform/blackfin/bfin_capture.c     |   20 +-
>  drivers/media/platform/coda/coda-bit.c             |   20 +-
>  drivers/media/platform/coda/coda-common.c          |   24 +-
>  drivers/media/platform/coda/coda-jpeg.c            |    2 +-
>  drivers/media/platform/coda/coda.h                 |    6 +-
>  drivers/media/platform/davinci/vpbe_display.c      |    8 +-
>  drivers/media/platform/davinci/vpif_capture.c      |   16 +-
>  drivers/media/platform/davinci/vpif_capture.h      |    2 +-
>  drivers/media/platform/davinci/vpif_display.c      |   18 +-
>  drivers/media/platform/davinci/vpif_display.h      |    6 +-
>  drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
>  drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
>  drivers/media/platform/exynos-gsc/gsc-m2m.c        |   16 +-
>  drivers/media/platform/exynos4-is/fimc-capture.c   |   12 +-
>  drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
>  drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
>  drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
>  drivers/media/platform/exynos4-is/fimc-isp-video.c |   14 +-
>  drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
>  drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
>  drivers/media/platform/exynos4-is/fimc-lite.c      |   10 +-
>  drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
>  drivers/media/platform/exynos4-is/fimc-m2m.c       |   16 +-
>  drivers/media/platform/m2m-deinterlace.c           |   16 +-
>  drivers/media/platform/marvell-ccic/mcam-core.c    |   24 +-
>  drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
>  drivers/media/platform/mx2_emmaprp.c               |   16 +-
>  drivers/media/platform/omap3isp/ispvideo.c         |    8 +-
>  drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
>  drivers/media/platform/s3c-camif/camif-capture.c   |   12 +-
>  drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
>  drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
>  drivers/media/platform/s5p-g2d/g2d.c               |   16 +-
>  drivers/media/platform/s5p-jpeg/jpeg-core.c        |   30 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc.c           |    2 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   10 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   18 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    2 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    2 +-
>  drivers/media/platform/s5p-tv/mixer.h              |    4 +-
>  drivers/media/platform/s5p-tv/mixer_video.c        |    4 +-
>  drivers/media/platform/sh_veu.c                    |   20 +-
>  drivers/media/platform/soc_camera/atmel-isi.c      |   20 +-
>  drivers/media/platform/soc_camera/mx2_camera.c     |   14 +-
>  drivers/media/platform/soc_camera/mx3_camera.c     |   18 +-
>  drivers/media/platform/soc_camera/rcar_vin.c       |   14 +-
>  .../platform/soc_camera/sh_mobile_ceu_camera.c     |   22 +-
>  drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
>  drivers/media/platform/ti-vpe/vpe.c                |   26 +-
>  drivers/media/platform/vim2m.c                     |   24 +-
>  drivers/media/platform/vivid/vivid-core.h          |    4 +-
>  drivers/media/platform/vivid/vivid-sdr-cap.c       |    8 +-
>  drivers/media/platform/vivid/vivid-vbi-cap.c       |   10 +-
>  drivers/media/platform/vivid/vivid-vbi-out.c       |   10 +-
>  drivers/media/platform/vivid/vivid-vid-cap.c       |   12 +-
>  drivers/media/platform/vivid/vivid-vid-out.c       |    8 +-
>  drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
>  drivers/media/platform/vsp1/vsp1_video.c           |   16 +-
>  drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
>  drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
>  drivers/media/usb/airspy/airspy.c                  |    6 +-
>  drivers/media/usb/au0828/au0828-vbi.c              |    8 +-
>  drivers/media/usb/au0828/au0828-video.c            |    8 +-
>  drivers/media/usb/au0828/au0828.h                  |    2 +-
>  drivers/media/usb/em28xx/em28xx-vbi.c              |    8 +-
>  drivers/media/usb/em28xx/em28xx-video.c            |    8 +-
>  drivers/media/usb/em28xx/em28xx.h                  |    2 +-
>  drivers/media/usb/go7007/go7007-priv.h             |    4 +-
>  drivers/media/usb/go7007/go7007-v4l2.c             |   10 +-
>  drivers/media/usb/hackrf/hackrf.c                  |    6 +-
>  drivers/media/usb/msi2500/msi2500.c                |    6 +-
>  drivers/media/usb/pwc/pwc-if.c                     |   18 +-
>  drivers/media/usb/pwc/pwc.h                        |    2 +-
>  drivers/media/usb/s2255/s2255drv.c                 |   10 +-
>  drivers/media/usb/stk1160/stk1160-v4l.c            |    4 +-
>  drivers/media/usb/stk1160/stk1160.h                |    4 +-
>  drivers/media/usb/usbtv/usbtv-video.c              |    6 +-
>  drivers/media/usb/usbtv/usbtv.h                    |    2 +-
>  drivers/media/usb/uvc/uvc_queue.c                  |   14 +-
>  drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
>  drivers/media/v4l2-core/Makefile                   |    2 +-
>  drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
>  drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
>  drivers/media/v4l2-core/videobuf2-core.c           |  398 +++++++++----------
>  drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
>  drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
>  drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
>  drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
>  .../{videobuf2-core.c => videobuf2-v4l2.c}         |  400 ++++++++++----------
>  drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
>  drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
>  drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
>  drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
>  drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
>  drivers/staging/media/omap4iss/iss_video.c         |   16 +-
>  drivers/staging/media/omap4iss/iss_video.h         |    4 +-
>  drivers/usb/gadget/function/uvc_queue.c            |   14 +-
>  drivers/usb/gadget/function/uvc_queue.h            |    4 +-
>  include/media/davinci/vpbe_display.h               |    2 +-
>  include/media/soc_camera.h                         |    2 +-
>  include/media/v4l2-mem2mem.h                       |    8 +-
>  include/media/videobuf2-core.h                     |   76 ++--
>  include/media/videobuf2-dma-contig.h               |    4 +-
>  include/media/videobuf2-dma-sg.h                   |    4 +-
>  include/media/videobuf2-dvb.h                      |    2 +-
>  include/media/videobuf2-memops.h                   |    2 +-
>  .../media/{videobuf2-core.h => videobuf2-v4l2.h}   |   80 ++--
>  include/media/videobuf2-vmalloc.h                  |    2 +-
>  136 files changed, 1081 insertions(+), 1045 deletions(-)
>  copy drivers/media/v4l2-core/{videobuf2-core.c => videobuf2-v4l2.c} (89%)
>  copy include/media/{videobuf2-core.h => videobuf2-v4l2.h} (94%)


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer
  2015-06-12  9:58   ` Hans Verkuil
@ 2015-06-12 10:09     ` Hans Verkuil
  2015-06-17 11:55       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 15+ messages in thread
From: Hans Verkuil @ 2015-06-12 10:09 UTC (permalink / raw)
  To: Junghak Sung, linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim

On 06/12/2015 11:58 AM, Hans Verkuil wrote:
> Hi Junghak,
> 
> On 06/08/2015 03:35 PM, Junghak Sung wrote:
>> Make the struct vb2_buffer to common buffer by removing v4l2-specific members.
>> And common video buffer is embedded into v4l2-specific video buffer like:
>> struct vb2_v4l2_buffer {
>>     struct vb2_buffer    vb2;
>>     struct v4l2_buffer    v4l2_buf;
>>     struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
>> };
>> This changes require the modifications of all device drivers that use this structure.
> 
> It's next to impossible to review just large diffs, but it is unavoidable for
> changes like this I guess.
> 
> I do recommend that you do a 'git grep videobuf2-core' to make sure all usages
> of that have been replaced with videobuf2-v4l2. I think I saw videobuf2-core
> mentioned in a comment, but it is hard to be sure.
> 
> It would also be easier to review if the renaming of core.[ch] to v4l2.[ch] was
> done in a separate patch. If it is relatively easy to split it up like that,
> then I would appreciate it, but if it takes a lot of time, then leave it as is.
> 
> Anyway, assuming that 'git grep videobuf2-core' doesn't find anything:
> 
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Sorry, I'm retracting that Acked-by: I tried to apply it and I saw it was against
an old kernel version, not against the media_tree master branch.

Also, I thought videobuf2-core.[ch] was renamed to videobuf2-v4l2.[ch], but that's
not the case. I think that would make much more sense. Later patches can split up
videobuf2-v4l2.c/h into a videobuf2-core and -v4l2 part.

Regards,

	Hans

> 
> Regards,
> 
> 	Hans
> 
>>
>> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>> ---
>>  Documentation/video4linux/v4l2-pci-skeleton.c      |   12 +-
>>  drivers/media/dvb-frontends/rtl2832_sdr.c          |   10 +-
>>  drivers/media/pci/cx23885/cx23885-417.c            |   12 +-
>>  drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
>>  drivers/media/pci/cx23885/cx23885-vbi.c            |   12 +-
>>  drivers/media/pci/cx23885/cx23885-video.c          |   12 +-
>>  drivers/media/pci/cx23885/cx23885.h                |    2 +-
>>  drivers/media/pci/cx25821/cx25821-video.c          |   12 +-
>>  drivers/media/pci/cx25821/cx25821.h                |    2 +-
>>  drivers/media/pci/cx88/cx88-blackbird.c            |   14 +-
>>  drivers/media/pci/cx88/cx88-dvb.c                  |   14 +-
>>  drivers/media/pci/cx88/cx88-vbi.c                  |   12 +-
>>  drivers/media/pci/cx88/cx88-video.c                |   12 +-
>>  drivers/media/pci/cx88/cx88.h                      |    2 +-
>>  drivers/media/pci/saa7134/saa7134-empress.c        |    2 +-
>>  drivers/media/pci/saa7134/saa7134-ts.c             |   10 +-
>>  drivers/media/pci/saa7134/saa7134-vbi.c            |   12 +-
>>  drivers/media/pci/saa7134/saa7134-video.c          |   18 +-
>>  drivers/media/pci/saa7134/saa7134.h                |    8 +-
>>  drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   14 +-
>>  drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    6 +-
>>  drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
>>  drivers/media/pci/sta2x11/sta2x11_vip.c            |   20 +-
>>  drivers/media/pci/tw68/tw68-video.c                |   12 +-
>>  drivers/media/pci/tw68/tw68.h                      |    2 +-
>>  drivers/media/platform/am437x/am437x-vpfe.c        |   16 +-
>>  drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
>>  drivers/media/platform/blackfin/bfin_capture.c     |   20 +-
>>  drivers/media/platform/coda/coda-bit.c             |   20 +-
>>  drivers/media/platform/coda/coda-common.c          |   24 +-
>>  drivers/media/platform/coda/coda-jpeg.c            |    2 +-
>>  drivers/media/platform/coda/coda.h                 |    6 +-
>>  drivers/media/platform/davinci/vpbe_display.c      |    8 +-
>>  drivers/media/platform/davinci/vpif_capture.c      |   16 +-
>>  drivers/media/platform/davinci/vpif_capture.h      |    2 +-
>>  drivers/media/platform/davinci/vpif_display.c      |   18 +-
>>  drivers/media/platform/davinci/vpif_display.h      |    6 +-
>>  drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
>>  drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
>>  drivers/media/platform/exynos-gsc/gsc-m2m.c        |   16 +-
>>  drivers/media/platform/exynos4-is/fimc-capture.c   |   12 +-
>>  drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
>>  drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
>>  drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
>>  drivers/media/platform/exynos4-is/fimc-isp-video.c |   14 +-
>>  drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
>>  drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
>>  drivers/media/platform/exynos4-is/fimc-lite.c      |   10 +-
>>  drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
>>  drivers/media/platform/exynos4-is/fimc-m2m.c       |   16 +-
>>  drivers/media/platform/m2m-deinterlace.c           |   16 +-
>>  drivers/media/platform/marvell-ccic/mcam-core.c    |   24 +-
>>  drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
>>  drivers/media/platform/mx2_emmaprp.c               |   16 +-
>>  drivers/media/platform/omap3isp/ispvideo.c         |    8 +-
>>  drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
>>  drivers/media/platform/s3c-camif/camif-capture.c   |   12 +-
>>  drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
>>  drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
>>  drivers/media/platform/s5p-g2d/g2d.c               |   16 +-
>>  drivers/media/platform/s5p-jpeg/jpeg-core.c        |   30 +-
>>  drivers/media/platform/s5p-mfc/s5p_mfc.c           |    2 +-
>>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
>>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   10 +-
>>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   18 +-
>>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    2 +-
>>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    2 +-
>>  drivers/media/platform/s5p-tv/mixer.h              |    4 +-
>>  drivers/media/platform/s5p-tv/mixer_video.c        |    4 +-
>>  drivers/media/platform/sh_veu.c                    |   20 +-
>>  drivers/media/platform/soc_camera/atmel-isi.c      |   20 +-
>>  drivers/media/platform/soc_camera/mx2_camera.c     |   14 +-
>>  drivers/media/platform/soc_camera/mx3_camera.c     |   18 +-
>>  drivers/media/platform/soc_camera/rcar_vin.c       |   14 +-
>>  .../platform/soc_camera/sh_mobile_ceu_camera.c     |   22 +-
>>  drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
>>  drivers/media/platform/ti-vpe/vpe.c                |   26 +-
>>  drivers/media/platform/vim2m.c                     |   24 +-
>>  drivers/media/platform/vivid/vivid-core.h          |    4 +-
>>  drivers/media/platform/vivid/vivid-sdr-cap.c       |    8 +-
>>  drivers/media/platform/vivid/vivid-vbi-cap.c       |   10 +-
>>  drivers/media/platform/vivid/vivid-vbi-out.c       |   10 +-
>>  drivers/media/platform/vivid/vivid-vid-cap.c       |   12 +-
>>  drivers/media/platform/vivid/vivid-vid-out.c       |    8 +-
>>  drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
>>  drivers/media/platform/vsp1/vsp1_video.c           |   16 +-
>>  drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
>>  drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
>>  drivers/media/usb/airspy/airspy.c                  |    6 +-
>>  drivers/media/usb/au0828/au0828-vbi.c              |    8 +-
>>  drivers/media/usb/au0828/au0828-video.c            |    8 +-
>>  drivers/media/usb/au0828/au0828.h                  |    2 +-
>>  drivers/media/usb/em28xx/em28xx-vbi.c              |    8 +-
>>  drivers/media/usb/em28xx/em28xx-video.c            |    8 +-
>>  drivers/media/usb/em28xx/em28xx.h                  |    2 +-
>>  drivers/media/usb/go7007/go7007-priv.h             |    4 +-
>>  drivers/media/usb/go7007/go7007-v4l2.c             |   10 +-
>>  drivers/media/usb/hackrf/hackrf.c                  |    6 +-
>>  drivers/media/usb/msi2500/msi2500.c                |    6 +-
>>  drivers/media/usb/pwc/pwc-if.c                     |   18 +-
>>  drivers/media/usb/pwc/pwc.h                        |    2 +-
>>  drivers/media/usb/s2255/s2255drv.c                 |   10 +-
>>  drivers/media/usb/stk1160/stk1160-v4l.c            |    4 +-
>>  drivers/media/usb/stk1160/stk1160.h                |    4 +-
>>  drivers/media/usb/usbtv/usbtv-video.c              |    6 +-
>>  drivers/media/usb/usbtv/usbtv.h                    |    2 +-
>>  drivers/media/usb/uvc/uvc_queue.c                  |   14 +-
>>  drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
>>  drivers/media/v4l2-core/Makefile                   |    2 +-
>>  drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
>>  drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
>>  drivers/media/v4l2-core/videobuf2-core.c           |  398 +++++++++----------
>>  drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
>>  drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
>>  drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
>>  drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
>>  .../{videobuf2-core.c => videobuf2-v4l2.c}         |  400 ++++++++++----------
>>  drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
>>  drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
>>  drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
>>  drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
>>  drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
>>  drivers/staging/media/omap4iss/iss_video.c         |   16 +-
>>  drivers/staging/media/omap4iss/iss_video.h         |    4 +-
>>  drivers/usb/gadget/function/uvc_queue.c            |   14 +-
>>  drivers/usb/gadget/function/uvc_queue.h            |    4 +-
>>  include/media/davinci/vpbe_display.h               |    2 +-
>>  include/media/soc_camera.h                         |    2 +-
>>  include/media/v4l2-mem2mem.h                       |    8 +-
>>  include/media/videobuf2-core.h                     |   76 ++--
>>  include/media/videobuf2-dma-contig.h               |    4 +-
>>  include/media/videobuf2-dma-sg.h                   |    4 +-
>>  include/media/videobuf2-dvb.h                      |    2 +-
>>  include/media/videobuf2-memops.h                   |    2 +-
>>  .../media/{videobuf2-core.h => videobuf2-v4l2.h}   |   80 ++--
>>  include/media/videobuf2-vmalloc.h                  |    2 +-
>>  136 files changed, 1081 insertions(+), 1045 deletions(-)
>>  copy drivers/media/v4l2-core/{videobuf2-core.c => videobuf2-v4l2.c} (89%)
>>  copy include/media/{videobuf2-core.h => videobuf2-v4l2.h} (94%)
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 0/3] Refactoring Videobuf2 for common use
  2015-06-08 13:35 [RFC PATCH 0/3] Refactoring Videobuf2 for common use Junghak Sung
                   ` (2 preceding siblings ...)
  2015-06-08 14:42 ` [RFC PATCH 0/3] Refactoring Videobuf2 for common use Hans Verkuil
@ 2015-06-12 10:51 ` Hans Verkuil
  2015-06-23  0:48   ` Junghak Sung
       [not found] ` <1433770535-21143-3-git-send-email-jh1009.sung@samsung.com>
  4 siblings, 1 reply; 15+ messages in thread
From: Hans Verkuil @ 2015-06-12 10:51 UTC (permalink / raw)
  To: Junghak Sung, linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim

Hi Junghak,

On 06/08/2015 03:35 PM, Junghak Sung wrote:
> Hello everybody,
> 
> This patch series refactories exsiting Videobuf2, so that not only V4L2
> but also other frameworks can use it to manage buffer and utilize
> queue.
> 
> I would separate existing Videobuf2-core framework into two parts - common
> and v4l2-specific part. This work is as follows :
> 
> 1. Separate existing vb2_buffer structure into common buffer and
>    v4l2-specific parts by removing v4l2-specific members and
>    embedding it into vb2_v4l2_buffer structure like this:
> 
>     struct vb2_v4l2_buffer {
>         struct vb2_buffer    vb2;
>         struct v4l2_buffer   v4l2_buf;
>         struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
>     };
> 
> 2. Abstract the v4l2-specific elements, and specify them when the device
>    drives use them. For example, vb2_v4l2_buffer structure can be abstracted
>    by vb2_buffer structure, and device drivers can get framework-specific
>    object such as vb2_v4l2_buffer by using container_of().
> 
> 3. Separate VB2-core framework into real VB2-core and v4l2-specific part.
>    This means that it moves V4L2-specific parts of VB2-core to v4l2-specific
>    part because current VB2-core framework has some codes dependent of V4L2.
>    As a result, we will have two VB2 files - videobuf2-core.c and
>    videobuf2-v4l2.c.
> 
> Why do we try to make the VB2 framework to be common?
> 
> As you may know, current DVB framework uses ringbuffer mechanism to demux
> MPEG-2 TS data and pass it to userspace. However, this mechanism requires
> extra memory copy because DVB framework provides only read() system call for
> application - read() system call copies the kernel data to user-space buffer.
> 
> So if we can use VB2 framework which supports streaming I/O and buffer
> sharing mechanism, then we could enhance existing DVB framework by removing
> the extra memory copy - with VB2 framework, application can access the kernel
> data directly through mmap system call.
> 
> This patch series is the first step for it.
> 
> We have a plan for this work as follows:
> 
> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2,
>    and VB2-dvb. Of course, this change should not affect other v4l2-based
>    device drivers. This patch series includes some parts of this step.
> 
> 2. Add new APIs for DVB streaming I/O. These APIs will be implemented
>    in VB2-dvb framework. So, we can remove unnecessary memory copy between
>    kernel-space and user-space by using these new APIs.
>    However, we leaves legacy interfaces as-is for backward compatibility.
> 
> We are working on this project with Mauro and have a discussion with him
> on IRC channel weekly. Nowaday, we are discussing more detailed DVB user
> scenario for streaming I/O.
> 
> The final goal of this project is to enhance current DVB framework.
> The first mission is to achieve zero-copy functionality between kernel-space
> and user-space with mmap system call. More missions are under consideration:
> i.e., we could share the buffer not only between kernel-space and user-space
> but also between devices - demux, hw video codec - by exporting a buffer
> to dmabuf fd with VB2 framework.
> 
> Any suggestions and comments are welcome.

I've tried to review it, but in the current form it is too hard to do. It's not
helped by the fact that patch 2 didn't make it to the mailinglist. It might
be better to just split up such large patches and make a note that the pull
request will combine the two (or more) patches into one.

BTW, I fully agree with what you want to do, where I am having trouble is
verifying that nothing breaks and in the details of the vb2 API changes.

Can you make a new patch series that only shows the changes to the videobuf2
sources and headers, so without all the driver changes? The driver changes
are automatically checked by the compiler when you build the drivers, so I
believe that that's correct (I hope :-) ).

Also try to split it up in smaller pieces. I had the feeling that you combined
multiple but otherwise independent changes in one patch. The vb2 framework is
an important piece of code, and I want to be confident about the changes made.

Regarding the split into core and v4l2 sources/headers: I've been thinking about
this a bit more, and what would probably make reviewing easiest is if you start
off with making a simple videobuf2-v4l2.h header that just includes core.h and
slowly move the v4l2-specific parts from videobuf2-core.h to videobuf2-v4l2.h.

And do the same with videobuf2-v4l2.c: start off with an empty source and move
code from core.c to v4l2.c whenever a v4l2-specific part migrates.

Another note: I noticed that the queue_setup op was changed so the v4l2_format
argument became a void *. I do not think that that is the right approach since
we lose strong typing.

I wonder if v4l2-specific queue ops should be introduced. I'm not sure how that
would work out, but I think we can look at that for the next round of patches.

Regards,

	Hans

> 
> Best regards,
> Junghak
> 
> Junghak Sung (3):
>   modify the vb2_buffer structure for common video buffer     and make
>     struct vb2_v4l2_buffer
>   move struct vb2_queue to common and apply the changes related with
>     that     Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>   make vb2-core part with not v4l2-specific elements
> 
>  Documentation/video4linux/v4l2-pci-skeleton.c      |   16 +-
>  drivers/media/dvb-frontends/rtl2832_sdr.c          |   13 +-
>  drivers/media/pci/cx23885/cx23885-417.c            |   13 +-
>  drivers/media/pci/cx23885/cx23885-core.c           |    4 +-
>  drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
>  drivers/media/pci/cx23885/cx23885-vbi.c            |   17 +-
>  drivers/media/pci/cx23885/cx23885-video.c          |   19 +-
>  drivers/media/pci/cx23885/cx23885.h                |    2 +-
>  drivers/media/pci/cx25821/cx25821-video.c          |   20 +-
>  drivers/media/pci/cx25821/cx25821.h                |    2 +-
>  drivers/media/pci/cx88/cx88-blackbird.c            |   15 +-
>  drivers/media/pci/cx88/cx88-core.c                 |    2 +-
>  drivers/media/pci/cx88/cx88-dvb.c                  |   13 +-
>  drivers/media/pci/cx88/cx88-mpeg.c                 |    2 +-
>  drivers/media/pci/cx88/cx88-vbi.c                  |   17 +-
>  drivers/media/pci/cx88/cx88-video.c                |   17 +-
>  drivers/media/pci/cx88/cx88.h                      |    2 +-
>  drivers/media/pci/saa7134/saa7134-core.c           |    4 +-
>  drivers/media/pci/saa7134/saa7134-ts.c             |   28 +-
>  drivers/media/pci/saa7134/saa7134-vbi.c            |   22 +-
>  drivers/media/pci/saa7134/saa7134-video.c          |   17 +-
>  drivers/media/pci/saa7134/saa7134.h                |    8 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   19 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   11 +-
>  drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
>  drivers/media/pci/sta2x11/sta2x11_vip.c            |   24 +-
>  drivers/media/pci/tw68/tw68-video.c                |   20 +-
>  drivers/media/pci/tw68/tw68.h                      |    2 +-
>  drivers/media/platform/am437x/am437x-vpfe.c        |   33 +-
>  drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
>  drivers/media/platform/blackfin/bfin_capture.c     |   30 +-
>  drivers/media/platform/coda/coda-bit.c             |   20 +-
>  drivers/media/platform/coda/coda-common.c          |   28 +-
>  drivers/media/platform/coda/coda-jpeg.c            |    2 +-
>  drivers/media/platform/coda/coda.h                 |    6 +-
>  drivers/media/platform/davinci/vpbe_display.c      |   25 +-
>  drivers/media/platform/davinci/vpif_capture.c      |   30 +-
>  drivers/media/platform/davinci/vpif_capture.h      |    2 +-
>  drivers/media/platform/davinci/vpif_display.c      |   34 +-
>  drivers/media/platform/davinci/vpif_display.h      |    6 +-
>  drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
>  drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
>  drivers/media/platform/exynos-gsc/gsc-m2m.c        |   12 +-
>  drivers/media/platform/exynos4-is/fimc-capture.c   |   23 +-
>  drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
>  drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
>  drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
>  drivers/media/platform/exynos4-is/fimc-isp-video.c |   25 +-
>  drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
>  drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
>  drivers/media/platform/exynos4-is/fimc-lite.c      |   25 +-
>  drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
>  drivers/media/platform/exynos4-is/fimc-m2m.c       |   14 +-
>  drivers/media/platform/m2m-deinterlace.c           |   16 +-
>  drivers/media/platform/marvell-ccic/mcam-core.c    |   26 +-
>  drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
>  drivers/media/platform/mx2_emmaprp.c               |   16 +-
>  drivers/media/platform/omap3isp/ispvideo.c         |   24 +-
>  drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
>  drivers/media/platform/s3c-camif/camif-capture.c   |   23 +-
>  drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
>  drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
>  drivers/media/platform/s5p-g2d/g2d.c               |   14 +-
>  drivers/media/platform/s5p-jpeg/jpeg-core.c        |   34 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc.c           |   14 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   36 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   57 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    4 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    4 +-
>  drivers/media/platform/s5p-tv/mixer.h              |    4 +-
>  drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
>  drivers/media/platform/s5p-tv/mixer_video.c        |   11 +-
>  drivers/media/platform/sh_veu.c                    |   25 +-
>  drivers/media/platform/soc_camera/atmel-isi.c      |   26 +-
>  drivers/media/platform/soc_camera/mx2_camera.c     |   41 +-
>  drivers/media/platform/soc_camera/mx3_camera.c     |   34 +-
>  drivers/media/platform/soc_camera/rcar_vin.c       |   30 +-
>  .../platform/soc_camera/sh_mobile_ceu_camera.c     |   47 +-
>  drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
>  drivers/media/platform/ti-vpe/vpe.c                |   30 +-
>  drivers/media/platform/vim2m.c                     |   28 +-
>  drivers/media/platform/vivid/vivid-core.h          |    4 +-
>  drivers/media/platform/vivid/vivid-kthread-cap.c   |    8 +-
>  drivers/media/platform/vivid/vivid-kthread-out.c   |    8 +-
>  drivers/media/platform/vivid/vivid-sdr-cap.c       |   18 +-
>  drivers/media/platform/vivid/vivid-vbi-cap.c       |   14 +-
>  drivers/media/platform/vivid/vivid-vbi-out.c       |   14 +-
>  drivers/media/platform/vivid/vivid-vid-cap.c       |   24 +-
>  drivers/media/platform/vivid/vivid-vid-out.c       |   21 +-
>  drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
>  drivers/media/platform/vsp1/vsp1_video.c           |   20 +-
>  drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
>  drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
>  drivers/media/usb/airspy/airspy.c                  |   15 +-
>  drivers/media/usb/au0828/au0828-vbi.c              |   17 +-
>  drivers/media/usb/au0828/au0828-video.c            |   29 +-
>  drivers/media/usb/au0828/au0828.h                  |    2 +-
>  drivers/media/usb/em28xx/em28xx-vbi.c              |   15 +-
>  drivers/media/usb/em28xx/em28xx-video.c            |   30 +-
>  drivers/media/usb/em28xx/em28xx.h                  |    2 +-
>  drivers/media/usb/go7007/go7007-driver.c           |    2 +-
>  drivers/media/usb/go7007/go7007-priv.h             |    4 +-
>  drivers/media/usb/go7007/go7007-v4l2.c             |   15 +-
>  drivers/media/usb/hackrf/hackrf.c                  |   13 +-
>  drivers/media/usb/msi2500/msi2500.c                |   13 +-
>  drivers/media/usb/pwc/pwc-if.c                     |   26 +-
>  drivers/media/usb/pwc/pwc.h                        |    2 +-
>  drivers/media/usb/s2255/s2255drv.c                 |   16 +-
>  drivers/media/usb/stk1160/stk1160-v4l.c            |   15 +-
>  drivers/media/usb/stk1160/stk1160-video.c          |    2 +-
>  drivers/media/usb/stk1160/stk1160.h                |    4 +-
>  drivers/media/usb/usbtv/usbtv-video.c              |   11 +-
>  drivers/media/usb/usbtv/usbtv.h                    |    2 +-
>  drivers/media/usb/uvc/uvc_queue.c                  |   32 +-
>  drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
>  drivers/media/v4l2-core/Makefile                   |    2 +-
>  drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
>  drivers/media/v4l2-core/v4l2-mem2mem.c             |    8 +-
>  drivers/media/v4l2-core/videobuf2-core.c           | 1888 ++------------------
>  drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
>  drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
>  drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
>  drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
>  drivers/media/v4l2-core/videobuf2-v4l2.c           | 1878 +++++++++++++++++++
>  drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
>  drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
>  drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
>  drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
>  drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
>  drivers/staging/media/omap4iss/iss_video.c         |   16 +-
>  drivers/staging/media/omap4iss/iss_video.h         |    4 +-
>  drivers/usb/gadget/function/uvc_queue.c            |   14 +-
>  drivers/usb/gadget/function/uvc_queue.h            |    4 +-
>  include/media/davinci/vpbe_display.h               |    2 +-
>  include/media/soc_camera.h                         |    2 +-
>  include/media/v4l2-mem2mem.h                       |   10 +-
>  include/media/videobuf2-core.h                     |  235 ++-
>  include/media/videobuf2-dma-contig.h               |    6 +-
>  include/media/videobuf2-dma-sg.h                   |    6 +-
>  include/media/videobuf2-dvb.h                      |    2 +-
>  include/media/videobuf2-memops.h                   |    2 +-
>  include/media/videobuf2-v4l2.h                     |  139 ++
>  include/media/videobuf2-vmalloc.h                  |    2 +-
>  144 files changed, 3290 insertions(+), 2662 deletions(-)
>  create mode 100644 drivers/media/v4l2-core/videobuf2-v4l2.c
>  create mode 100644 include/media/videobuf2-v4l2.h
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer
  2015-06-12 10:09     ` Hans Verkuil
@ 2015-06-17 11:55       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 15+ messages in thread
From: Mauro Carvalho Chehab @ 2015-06-17 11:55 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Junghak Sung, linux-media, sangbae90.lee, inki.dae, nenggun.kim,
	sw0312.kim

Em Fri, 12 Jun 2015 12:09:00 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 06/12/2015 11:58 AM, Hans Verkuil wrote:
> > Hi Junghak,
> > 
> > On 06/08/2015 03:35 PM, Junghak Sung wrote:
> >> Make the struct vb2_buffer to common buffer by removing v4l2-specific members.
> >> And common video buffer is embedded into v4l2-specific video buffer like:
> >> struct vb2_v4l2_buffer {
> >>     struct vb2_buffer    vb2;
> >>     struct v4l2_buffer    v4l2_buf;
> >>     struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
> >> };
> >> This changes require the modifications of all device drivers that use this structure.
> > 
> > It's next to impossible to review just large diffs, but it is unavoidable for
> > changes like this I guess.
> > 
> > I do recommend that you do a 'git grep videobuf2-core' to make sure all usages
> > of that have been replaced with videobuf2-v4l2. I think I saw videobuf2-core
> > mentioned in a comment, but it is hard to be sure.
> > 
> > It would also be easier to review if the renaming of core.[ch] to v4l2.[ch] was
> > done in a separate patch. If it is relatively easy to split it up like that,
> > then I would appreciate it, but if it takes a lot of time, then leave it as is.
> > 
> > Anyway, assuming that 'git grep videobuf2-core' doesn't find anything:
> > 
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Sorry, I'm retracting that Acked-by: I tried to apply it and I saw it was against
> an old kernel version, not against the media_tree master branch.

Well, no matter on what version this patch is produced, it would very
likely cause merge conflicts. The best here would be if you add a
small shell/perl script at the body of the patch that would be doing
the renaming thing at the drivers. This way, the maintainer can run the
script when merging it. That would warrant that this would be changed
everywhere and noting was left behind.

> Also, I thought videobuf2-core.[ch] was renamed to videobuf2-v4l2.[ch], but that's
> not the case. I think that would make much more sense. Later patches can split up
> videobuf2-v4l2.c/h into a videobuf2-core and -v4l2 part.

> >>  copy drivers/media/v4l2-core/{videobuf2-core.c => videobuf2-v4l2.c} (89%)
> >>  copy include/media/{videobuf2-core.h => videobuf2-v4l2.h} (94%)

Actually, it is being copied, with is almost the same.

I agree that this series could be better split into:

1) a patch that would be just doing:
	mv drivers/media/v4l2-core/videobuf2-core.c drivers/media/v4l2-core/videobuf2-v4l2.c 
	mv include/media/videobuf2-core.h include/media/videobuf2-v4l2.h

And changing the includes and Makefile bits to use the new header.

2) this patch (with the script used to produce it);

3) patches that would be gradually moving the common functions from
   videobuf2-v4l2.c into videobuf2-core.c.

Regards,
Mauro


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer
  2015-06-08 13:35 ` [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer Junghak Sung
  2015-06-12  9:58   ` Hans Verkuil
@ 2015-06-17 12:27   ` Mauro Carvalho Chehab
  2015-06-23  1:11     ` Junghak Sung
  1 sibling, 1 reply; 15+ messages in thread
From: Mauro Carvalho Chehab @ 2015-06-17 12:27 UTC (permalink / raw)
  To: Junghak Sung
  Cc: linux-media, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim

Em Mon, 08 Jun 2015 22:35:33 +0900
Junghak Sung <jh1009.sung@samsung.com> escreveu:

> Make the struct vb2_buffer to common buffer by removing v4l2-specific members.
> And common video buffer is embedded into v4l2-specific video buffer like:
> struct vb2_v4l2_buffer {
>     struct vb2_buffer    vb2;
>     struct v4l2_buffer    v4l2_buf;
>     struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
> };
> This changes require the modifications of all device drivers that use this structure.

Thanks for the patch!

In general, it looks fine. Just a few comments. See below.

Regards,
Mauro

> 
> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> ---
>  Documentation/video4linux/v4l2-pci-skeleton.c      |   12 +-
>  drivers/media/dvb-frontends/rtl2832_sdr.c          |   10 +-
>  drivers/media/pci/cx23885/cx23885-417.c            |   12 +-
>  drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
>  drivers/media/pci/cx23885/cx23885-vbi.c            |   12 +-
>  drivers/media/pci/cx23885/cx23885-video.c          |   12 +-
>  drivers/media/pci/cx23885/cx23885.h                |    2 +-
>  drivers/media/pci/cx25821/cx25821-video.c          |   12 +-
>  drivers/media/pci/cx25821/cx25821.h                |    2 +-
>  drivers/media/pci/cx88/cx88-blackbird.c            |   14 +-
>  drivers/media/pci/cx88/cx88-dvb.c                  |   14 +-
>  drivers/media/pci/cx88/cx88-vbi.c                  |   12 +-
>  drivers/media/pci/cx88/cx88-video.c                |   12 +-
>  drivers/media/pci/cx88/cx88.h                      |    2 +-
>  drivers/media/pci/saa7134/saa7134-empress.c        |    2 +-
>  drivers/media/pci/saa7134/saa7134-ts.c             |   10 +-
>  drivers/media/pci/saa7134/saa7134-vbi.c            |   12 +-
>  drivers/media/pci/saa7134/saa7134-video.c          |   18 +-
>  drivers/media/pci/saa7134/saa7134.h                |    8 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   14 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    6 +-
>  drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
>  drivers/media/pci/sta2x11/sta2x11_vip.c            |   20 +-
>  drivers/media/pci/tw68/tw68-video.c                |   12 +-
>  drivers/media/pci/tw68/tw68.h                      |    2 +-
>  drivers/media/platform/am437x/am437x-vpfe.c        |   16 +-
>  drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
>  drivers/media/platform/blackfin/bfin_capture.c     |   20 +-
>  drivers/media/platform/coda/coda-bit.c             |   20 +-
>  drivers/media/platform/coda/coda-common.c          |   24 +-
>  drivers/media/platform/coda/coda-jpeg.c            |    2 +-
>  drivers/media/platform/coda/coda.h                 |    6 +-
>  drivers/media/platform/davinci/vpbe_display.c      |    8 +-
>  drivers/media/platform/davinci/vpif_capture.c      |   16 +-
>  drivers/media/platform/davinci/vpif_capture.h      |    2 +-
>  drivers/media/platform/davinci/vpif_display.c      |   18 +-
>  drivers/media/platform/davinci/vpif_display.h      |    6 +-
>  drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
>  drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
>  drivers/media/platform/exynos-gsc/gsc-m2m.c        |   16 +-
>  drivers/media/platform/exynos4-is/fimc-capture.c   |   12 +-
>  drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
>  drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
>  drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
>  drivers/media/platform/exynos4-is/fimc-isp-video.c |   14 +-
>  drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
>  drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
>  drivers/media/platform/exynos4-is/fimc-lite.c      |   10 +-
>  drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
>  drivers/media/platform/exynos4-is/fimc-m2m.c       |   16 +-
>  drivers/media/platform/m2m-deinterlace.c           |   16 +-
>  drivers/media/platform/marvell-ccic/mcam-core.c    |   24 +-
>  drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
>  drivers/media/platform/mx2_emmaprp.c               |   16 +-
>  drivers/media/platform/omap3isp/ispvideo.c         |    8 +-
>  drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
>  drivers/media/platform/s3c-camif/camif-capture.c   |   12 +-
>  drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
>  drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
>  drivers/media/platform/s5p-g2d/g2d.c               |   16 +-
>  drivers/media/platform/s5p-jpeg/jpeg-core.c        |   30 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc.c           |    2 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   10 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   18 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    2 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    2 +-
>  drivers/media/platform/s5p-tv/mixer.h              |    4 +-
>  drivers/media/platform/s5p-tv/mixer_video.c        |    4 +-
>  drivers/media/platform/sh_veu.c                    |   20 +-
>  drivers/media/platform/soc_camera/atmel-isi.c      |   20 +-
>  drivers/media/platform/soc_camera/mx2_camera.c     |   14 +-
>  drivers/media/platform/soc_camera/mx3_camera.c     |   18 +-
>  drivers/media/platform/soc_camera/rcar_vin.c       |   14 +-
>  .../platform/soc_camera/sh_mobile_ceu_camera.c     |   22 +-
>  drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
>  drivers/media/platform/ti-vpe/vpe.c                |   26 +-
>  drivers/media/platform/vim2m.c                     |   24 +-
>  drivers/media/platform/vivid/vivid-core.h          |    4 +-
>  drivers/media/platform/vivid/vivid-sdr-cap.c       |    8 +-
>  drivers/media/platform/vivid/vivid-vbi-cap.c       |   10 +-
>  drivers/media/platform/vivid/vivid-vbi-out.c       |   10 +-
>  drivers/media/platform/vivid/vivid-vid-cap.c       |   12 +-
>  drivers/media/platform/vivid/vivid-vid-out.c       |    8 +-
>  drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
>  drivers/media/platform/vsp1/vsp1_video.c           |   16 +-
>  drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
>  drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
>  drivers/media/usb/airspy/airspy.c                  |    6 +-
>  drivers/media/usb/au0828/au0828-vbi.c              |    8 +-
>  drivers/media/usb/au0828/au0828-video.c            |    8 +-
>  drivers/media/usb/au0828/au0828.h                  |    2 +-
>  drivers/media/usb/em28xx/em28xx-vbi.c              |    8 +-
>  drivers/media/usb/em28xx/em28xx-video.c            |    8 +-
>  drivers/media/usb/em28xx/em28xx.h                  |    2 +-
>  drivers/media/usb/go7007/go7007-priv.h             |    4 +-
>  drivers/media/usb/go7007/go7007-v4l2.c             |   10 +-
>  drivers/media/usb/hackrf/hackrf.c                  |    6 +-
>  drivers/media/usb/msi2500/msi2500.c                |    6 +-
>  drivers/media/usb/pwc/pwc-if.c                     |   18 +-
>  drivers/media/usb/pwc/pwc.h                        |    2 +-
>  drivers/media/usb/s2255/s2255drv.c                 |   10 +-
>  drivers/media/usb/stk1160/stk1160-v4l.c            |    4 +-
>  drivers/media/usb/stk1160/stk1160.h                |    4 +-
>  drivers/media/usb/usbtv/usbtv-video.c              |    6 +-
>  drivers/media/usb/usbtv/usbtv.h                    |    2 +-
>  drivers/media/usb/uvc/uvc_queue.c                  |   14 +-
>  drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
>  drivers/media/v4l2-core/Makefile                   |    2 +-
>  drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
>  drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
>  drivers/media/v4l2-core/videobuf2-core.c           |  398 +++++++++----------
>  drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
>  drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
>  drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
>  drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
>  .../{videobuf2-core.c => videobuf2-v4l2.c}         |  400 ++++++++++----------
>  drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
>  drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
>  drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
>  drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
>  drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
>  drivers/staging/media/omap4iss/iss_video.c         |   16 +-
>  drivers/staging/media/omap4iss/iss_video.h         |    4 +-
>  drivers/usb/gadget/function/uvc_queue.c            |   14 +-
>  drivers/usb/gadget/function/uvc_queue.h            |    4 +-
>  include/media/davinci/vpbe_display.h               |    2 +-
>  include/media/soc_camera.h                         |    2 +-
>  include/media/v4l2-mem2mem.h                       |    8 +-
>  include/media/videobuf2-core.h                     |   76 ++--
>  include/media/videobuf2-dma-contig.h               |    4 +-
>  include/media/videobuf2-dma-sg.h                   |    4 +-
>  include/media/videobuf2-dvb.h                      |    2 +-
>  include/media/videobuf2-memops.h                   |    2 +-
>  .../media/{videobuf2-core.h => videobuf2-v4l2.h}   |   80 ++--
>  include/media/videobuf2-vmalloc.h                  |    2 +-
>  136 files changed, 1081 insertions(+), 1045 deletions(-)
>  copy drivers/media/v4l2-core/{videobuf2-core.c => videobuf2-v4l2.c} (89%)
>  copy include/media/{videobuf2-core.h => videobuf2-v4l2.h} (94%)
> 

Let me go directly to the header changes. Everything else is consequence
of that. As I said before, the best is to have a script that would do the
renaming changes to fulfill what was changed in the headers.

> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -1,5 +1,5 @@
>  /*
> - * videobuf2-core.h - V4L2 driver helper framework
> + * videobuf2-core.h - Video Buffer 2 framework
>   *
>   * Copyright (C) 2010 Samsung Electronics
>   *
> @@ -171,18 +171,7 @@ enum vb2_buffer_state {
>  struct vb2_queue;
>  
>  /**
> - * struct vb2_buffer - represents a video buffer
> - * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
> - *			be read by the driver and relevant entries can be
> - *			changed by the driver in case of CAPTURE types
> - *			(such as timestamp)
> - * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
> - *			be read by the driver and relevant entries can be
> - *			changed by the driver in case of CAPTURE types
> - *			(such as bytesused); NOTE that even for single-planar
> - *			types, the v4l2_planes[0] struct should be used
> - *			instead of v4l2_buf for filling bytesused - drivers
> - *			should use the vb2_set_plane_payload() function for that
> + * struct vb2_buffer - represents a common video buffer
>   * @vb2_queue:		the queue to which this driver belongs
>   * @num_planes:		number of planes in the buffer
>   *			on an internal driver queue
> @@ -194,11 +183,7 @@ struct vb2_queue;
>   * @planes:		private per-plane information; do not change
>   */
>  struct vb2_buffer {
> -	struct v4l2_buffer	v4l2_buf;
> -	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
> -
>  	struct vb2_queue	*vb2_queue;
> -
>  	unsigned int		num_planes;
>  
>  /* Private: internal use only */
> @@ -242,6 +227,27 @@ struct vb2_buffer {
>  };
>  
>  /**
> + * struct vb2_v4l2_buffer - represents a video buffer for v4l2
> + * @vb2_buf:		common video buffer
> + * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
> + *			be read by the driver and relevant entries can be
> + *			changed by the driver in case of CAPTURE types
> + *			(such as timestamp)
> + * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
> + *			be read by the driver and relevant entries can be
> + *			changed by the driver in case of CAPTURE types
> + *			(such as bytesused); NOTE that even for single-planar
> + *			types, the v4l2_planes[0] struct should be used
> + *			instead of v4l2_buf for filling bytesused - drivers
> + *			should use the vb2_set_plane_payload() function for that
> + */
> +struct vb2_v4l2_buffer {
> +	struct vb2_buffer	vb2;
> +	struct v4l2_buffer	v4l2_buf;
> +	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
> +};
> +
> +/**
>   * struct vb2_ops - driver-specific callbacks
>   *
>   * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
> @@ -328,15 +334,15 @@ struct vb2_ops {
>  	void (*wait_prepare)(struct vb2_queue *q);
>  	void (*wait_finish)(struct vb2_queue *q);
>  
> -	int (*buf_init)(struct vb2_buffer *vb);
> -	int (*buf_prepare)(struct vb2_buffer *vb);
> -	void (*buf_finish)(struct vb2_buffer *vb);
> -	void (*buf_cleanup)(struct vb2_buffer *vb);
> +	int (*buf_init)(struct vb2_v4l2_buffer *vb);
> +	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
> +	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
> +	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
>  
>  	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
>  	void (*stop_streaming)(struct vb2_queue *q);
>  
> -	void (*buf_queue)(struct vb2_buffer *vb);
> +	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
>  };
>  
>  struct v4l2_fh;
> @@ -361,7 +367,7 @@ struct v4l2_fh;
>   * @drv_priv:	driver private data
>   * @buf_struct_size: size of the driver-specific buffer structure;
>   *		"0" indicates the driver doesn't want to use a custom buffer
> - *		structure type, so sizeof(struct vb2_buffer) will is used
> + *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
>   * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
>   *		V4L2_BUF_FLAG_TSTAMP_SRC_*
>   * @gfp_flags:	additional gfp flags used when allocating the buffers.
> @@ -398,7 +404,7 @@ struct vb2_queue {
>  	unsigned int			io_modes;
>  	unsigned int			io_flags;
>  	struct mutex			*lock;
> -	struct v4l2_fh			*owner;
> +	void					*owner;

Looks ok, except for the extra tab that disaligns it. Please notice
that, on Kernel, a tab is 8 spaces.

>  
>  	const struct vb2_ops		*ops;
>  	const struct vb2_mem_ops	*mem_ops;
> @@ -411,7 +417,7 @@ struct vb2_queue {
>  /* private: internal use only */
>  	struct mutex			mmap_lock;
>  	enum v4l2_memory		memory;
> -	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
> +	void					*bufs[VIDEO_MAX_FRAME];

Hmm.. why void? It can be struct vb2_buffer. Of course, in order
to get the buffer, the code would need to do something like:

	struct vb2_v4l2_buffer *vb;

	vb = container_of(bufs[0], struct vb2_v4l2_buffer, vb2);

But this would avoid the typecasts at the VB2 core, and, most importantly,
it would ensure strong type checks by the compiler.

>  	unsigned int			num_buffers;
>  
>  	struct list_head		queued_list;
> @@ -446,10 +452,10 @@ struct vb2_queue {
>  #endif
>  };
>  
> -void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
> -void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>  
> -void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
> +void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
>  void vb2_discard_done(struct vb2_queue *q);
>  int vb2_wait_for_all_buffers(struct vb2_queue *q);
>  
> @@ -489,7 +495,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
>   *
>   * This is called whenever a buffer is dequeued in the thread.
>   */
> -typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
> +typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
>  
>  /**
>   * vb2_thread_start() - start a thread for the given queue.
> @@ -566,10 +572,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
>   * @plane_no:	plane number for which payload should be set
>   * @size:	payload in bytes
>   */
> -static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
> +static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>  				 unsigned int plane_no, unsigned long size)
>  {
> -	if (plane_no < vb->num_planes)
> +	if (plane_no < vb->vb2.num_planes)
>  		vb->v4l2_planes[plane_no].bytesused = size;
>  }
>  
> @@ -579,10 +585,10 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
>   * @plane_no:	plane number for which payload should be set
>   * @size:	payload in bytes
>   */
> -static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
> +static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>  				 unsigned int plane_no)
>  {
> -	if (plane_no < vb->num_planes)
> +	if (plane_no < vb->vb2.num_planes)
>  		return vb->v4l2_planes[plane_no].bytesused;
>  	return 0;
>  }
> @@ -593,9 +599,9 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
>   * @plane_no:	plane number for which size should be returned
>   */
>  static inline unsigned long
> -vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
> +vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>  {
> -	if (plane_no < vb->num_planes)
> +	if (plane_no < vb->vb2.num_planes)
>  		return vb->v4l2_planes[plane_no].length;
>  	return 0;
>  }
> diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h
> index 8197f87..3de9111 100644
> --- a/include/media/videobuf2-dma-contig.h
> +++ b/include/media/videobuf2-dma-contig.h
> @@ -13,11 +13,11 @@
>  #ifndef _MEDIA_VIDEOBUF2_DMA_CONTIG_H
>  #define _MEDIA_VIDEOBUF2_DMA_CONTIG_H
>  
> -#include <media/videobuf2-core.h>
> +#include <media/videobuf2-v4l2.h>
>  #include <linux/dma-mapping.h>
>  
>  static inline dma_addr_t
> -vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no)
> +vb2_dma_contig_plane_dma_addr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>  {
>  	dma_addr_t *addr = vb2_plane_cookie(vb, plane_no);
>  
> diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h
> index 14ce306..36f7ea3 100644
> --- a/include/media/videobuf2-dma-sg.h
> +++ b/include/media/videobuf2-dma-sg.h
> @@ -13,10 +13,10 @@
>  #ifndef _MEDIA_VIDEOBUF2_DMA_SG_H
>  #define _MEDIA_VIDEOBUF2_DMA_SG_H
>  
> -#include <media/videobuf2-core.h>
> +#include <media/videobuf2-v4l2.h>
>  
>  static inline struct sg_table *vb2_dma_sg_plane_desc(
> -		struct vb2_buffer *vb, unsigned int plane_no)
> +		struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>  {
>  	return (struct sg_table *)vb2_plane_cookie(vb, plane_no);
>  }
> diff --git a/include/media/videobuf2-dvb.h b/include/media/videobuf2-dvb.h
> index 8f61456..bef9127 100644
> --- a/include/media/videobuf2-dvb.h
> +++ b/include/media/videobuf2-dvb.h
> @@ -6,7 +6,7 @@
>  #include <dvb_demux.h>
>  #include <dvb_net.h>
>  #include <dvb_frontend.h>
> -#include <media/videobuf2-core.h>
> +#include <media/videobuf2-v4l2.h>
>  
>  struct vb2_dvb {
>  	/* filling that the job of the driver */
> diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
> index f05444c..7b6d475 100644
> --- a/include/media/videobuf2-memops.h
> +++ b/include/media/videobuf2-memops.h
> @@ -14,7 +14,7 @@
>  #ifndef _MEDIA_VIDEOBUF2_MEMOPS_H
>  #define _MEDIA_VIDEOBUF2_MEMOPS_H
>  
> -#include <media/videobuf2-core.h>
> +#include <media/videobuf2-v4l2.h>
>  
>  /**
>   * vb2_vmarea_handler - common vma refcount tracking handler
> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-v4l2.h
> similarity index 94%
> copy from include/media/videobuf2-core.h
> copy to include/media/videobuf2-v4l2.h
> index bd2cec2..80b08cb 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-v4l2.h
> @@ -9,8 +9,8 @@
>   * it under the terms of the GNU General Public License as published by
>   * the Free Software Foundation.
>   */
> -#ifndef _MEDIA_VIDEOBUF2_CORE_H
> -#define _MEDIA_VIDEOBUF2_CORE_H
> +#ifndef _MEDIA_VIDEOBUF2_V4L2_H
> +#define _MEDIA_VIDEOBUF2_V4L2_H
>  
>  #include <linux/mm_types.h>
>  #include <linux/mutex.h>
> @@ -171,18 +171,7 @@ enum vb2_buffer_state {
>  struct vb2_queue;
>  
>  /**
> - * struct vb2_buffer - represents a video buffer
> - * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
> - *			be read by the driver and relevant entries can be
> - *			changed by the driver in case of CAPTURE types
> - *			(such as timestamp)
> - * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
> - *			be read by the driver and relevant entries can be
> - *			changed by the driver in case of CAPTURE types
> - *			(such as bytesused); NOTE that even for single-planar
> - *			types, the v4l2_planes[0] struct should be used
> - *			instead of v4l2_buf for filling bytesused - drivers
> - *			should use the vb2_set_plane_payload() function for that
> + * struct vb2_buffer - represents a common video buffer
>   * @vb2_queue:		the queue to which this driver belongs
>   * @num_planes:		number of planes in the buffer
>   *			on an internal driver queue
> @@ -194,11 +183,7 @@ struct vb2_queue;
>   * @planes:		private per-plane information; do not change
>   */
>  struct vb2_buffer {
> -	struct v4l2_buffer	v4l2_buf;
> -	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
> -
>  	struct vb2_queue	*vb2_queue;
> -
>  	unsigned int		num_planes;
>  
>  /* Private: internal use only */
> @@ -242,6 +227,27 @@ struct vb2_buffer {
>  };

Why are you declaring it again here? Instead, just include
videobuf2-core.h.

>  
>  /**
> + * struct vb2_v4l2_buffer - represents a video buffer for v4l2
> + * @vb2_buf:		common video buffer
> + * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
> + *			be read by the driver and relevant entries can be
> + *			changed by the driver in case of CAPTURE types
> + *			(such as timestamp)
> + * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
> + *			be read by the driver and relevant entries can be
> + *			changed by the driver in case of CAPTURE types
> + *			(such as bytesused); NOTE that even for single-planar
> + *			types, the v4l2_planes[0] struct should be used
> + *			instead of v4l2_buf for filling bytesused - drivers
> + *			should use the vb2_set_plane_payload() function for that
> + */
> +struct vb2_v4l2_buffer {
> +	struct vb2_buffer	vb2;
> +	struct v4l2_buffer	v4l2_buf;
> +	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
> +};
> +

Same here: this got declared twice.

As I explained on my comment 0/3, in order to easy patch review, I would
first rename the header, then do those changes and then move the
non-vb4l2 functions to the new videobuf2-core.h

> +/**
>   * struct vb2_ops - driver-specific callbacks
>   *
>   * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
> @@ -328,15 +334,15 @@ struct vb2_ops {
>  	void (*wait_prepare)(struct vb2_queue *q);
>  	void (*wait_finish)(struct vb2_queue *q);
>  
> -	int (*buf_init)(struct vb2_buffer *vb);
> -	int (*buf_prepare)(struct vb2_buffer *vb);
> -	void (*buf_finish)(struct vb2_buffer *vb);
> -	void (*buf_cleanup)(struct vb2_buffer *vb);
> +	int (*buf_init)(struct vb2_v4l2_buffer *vb);
> +	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
> +	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
> +	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
>  
>  	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
>  	void (*stop_streaming)(struct vb2_queue *q);
>  
> -	void (*buf_queue)(struct vb2_buffer *vb);
> +	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
>  };
>  
>  struct v4l2_fh;
> @@ -361,7 +367,7 @@ struct v4l2_fh;
>   * @drv_priv:	driver private data
>   * @buf_struct_size: size of the driver-specific buffer structure;
>   *		"0" indicates the driver doesn't want to use a custom buffer
> - *		structure type, so sizeof(struct vb2_buffer) will is used
> + *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
>   * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
>   *		V4L2_BUF_FLAG_TSTAMP_SRC_*
>   * @gfp_flags:	additional gfp flags used when allocating the buffers.
> @@ -398,7 +404,7 @@ struct vb2_queue {
>  	unsigned int			io_modes;
>  	unsigned int			io_flags;
>  	struct mutex			*lock;
> -	struct v4l2_fh			*owner;
> +	void					*owner;

Again, there's an extra tab here.

>  
>  	const struct vb2_ops		*ops;
>  	const struct vb2_mem_ops	*mem_ops;
> @@ -411,7 +417,7 @@ struct vb2_queue {
>  /* private: internal use only */
>  	struct mutex			mmap_lock;
>  	enum v4l2_memory		memory;
> -	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
> +	void					*bufs[VIDEO_MAX_FRAME];

Again, there's an extra tab here.

>  	unsigned int			num_buffers;
>  
>  	struct list_head		queued_list;
> @@ -446,10 +452,10 @@ struct vb2_queue {
>  #endif
>  };
>  
> -void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
> -void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>  
> -void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
> +void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
>  void vb2_discard_done(struct vb2_queue *q);
>  int vb2_wait_for_all_buffers(struct vb2_queue *q);
>  
> @@ -489,7 +495,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
>   *
>   * This is called whenever a buffer is dequeued in the thread.
>   */
> -typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
> +typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
>  
>  /**
>   * vb2_thread_start() - start a thread for the given queue.
> @@ -566,10 +572,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
>   * @plane_no:	plane number for which payload should be set
>   * @size:	payload in bytes
>   */
> -static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
> +static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>  				 unsigned int plane_no, unsigned long size)
>  {
> -	if (plane_no < vb->num_planes)
> +	if (plane_no < vb->vb2.num_planes)
>  		vb->v4l2_planes[plane_no].bytesused = size;
>  }
>  
> @@ -579,10 +585,10 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
>   * @plane_no:	plane number for which payload should be set
>   * @size:	payload in bytes
>   */
> -static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
> +static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>  				 unsigned int plane_no)
>  {
> -	if (plane_no < vb->num_planes)
> +	if (plane_no < vb->vb2.num_planes)
>  		return vb->v4l2_planes[plane_no].bytesused;
>  	return 0;
>  }
> @@ -593,9 +599,9 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
>   * @plane_no:	plane number for which size should be returned
>   */
>  static inline unsigned long
> -vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
> +vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>  {
> -	if (plane_no < vb->num_planes)
> +	if (plane_no < vb->vb2.num_planes)
>  		return vb->v4l2_planes[plane_no].length;
>  	return 0;
>  }
> @@ -653,4 +659,4 @@ unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
>  void vb2_ops_wait_prepare(struct vb2_queue *vq);
>  void vb2_ops_wait_finish(struct vb2_queue *vq);
>  
> -#endif /* _MEDIA_VIDEOBUF2_CORE_H */
> +#endif /* _MEDIA_VIDEOBUF2_V4L2_H */
> diff --git a/include/media/videobuf2-vmalloc.h b/include/media/videobuf2-vmalloc.h
> index 93a76b4..a63fe66 100644
> --- a/include/media/videobuf2-vmalloc.h
> +++ b/include/media/videobuf2-vmalloc.h
> @@ -13,7 +13,7 @@
>  #ifndef _MEDIA_VIDEOBUF2_VMALLOC_H
>  #define _MEDIA_VIDEOBUF2_VMALLOC_H
>  
> -#include <media/videobuf2-core.h>
> +#include <media/videobuf2-v4l2.h>
>  
>  extern const struct vb2_mem_ops vb2_vmalloc_memops;
>  


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 2/3] make struct vb2_queue to common and apply the changes related with that.
       [not found] ` <1433770535-21143-3-git-send-email-jh1009.sung@samsung.com>
@ 2015-06-17 13:16   ` Mauro Carvalho Chehab
  2015-06-23  1:33     ` Junghak Sung
  0 siblings, 1 reply; 15+ messages in thread
From: Mauro Carvalho Chehab @ 2015-06-17 13:16 UTC (permalink / raw)
  To: Junghak Sung
  Cc: linux-media, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim

Em Mon, 08 Jun 2015 22:35:34 +0900
Junghak Sung <jh1009.sung@samsung.com> escreveu:

> Abstract the v4l2-specific members of the struct vb2_queue,
> and concrete it in the side of user.
> For example, the struct vb2_v4l2_buffer can be abstracted by using
> struct vb2_buffer, and concrete it by using container_of() in a device driver.
> 
> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> ---
>  drivers/media/dvb-frontends/rtl2832_sdr.c          |   13 +-
>  drivers/media/pci/cx23885/cx23885-417.c            |   23 +-
>  drivers/media/pci/cx23885/cx23885-dvb.c            |   24 +-
>  drivers/media/pci/cx23885/cx23885-vbi.c            |   27 +-
>  drivers/media/pci/cx23885/cx23885-video.c          |   27 +-
>  drivers/media/pci/cx25821/cx25821-video.c          |   28 +-
>  drivers/media/pci/cx88/cx88-blackbird.c            |   25 +-
>  drivers/media/pci/cx88/cx88-dvb.c                  |   25 +-
>  drivers/media/pci/cx88/cx88-vbi.c                  |   27 +-
>  drivers/media/pci/cx88/cx88-video.c                |   27 +-
>  drivers/media/pci/saa7134/saa7134-empress.c        |    2 +-
>  drivers/media/pci/saa7134/saa7134-ts.c             |   26 +-
>  drivers/media/pci/saa7134/saa7134-vbi.c            |   22 +-
>  drivers/media/pci/saa7134/saa7134-video.c          |   11 +-
>  drivers/media/pci/saa7134/saa7134.h                |    2 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   15 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   11 +-
>  drivers/media/pci/sta2x11/sta2x11_vip.c            |   32 +-
>  drivers/media/pci/tw68/tw68-video.c                |   28 +-
>  drivers/media/platform/am437x/am437x-vpfe.c        |   21 +-
>  drivers/media/platform/blackfin/bfin_capture.c     |   32 +-
>  drivers/media/platform/coda/coda-common.c          |   30 +-
>  drivers/media/platform/davinci/vpbe_display.c      |   19 +-
>  drivers/media/platform/davinci/vpif_capture.c      |   10 +-
>  drivers/media/platform/davinci/vpif_display.c      |   10 +-
>  drivers/media/platform/exynos-gsc/gsc-m2m.c        |   20 +-
>  drivers/media/platform/exynos4-is/fimc-capture.c   |   25 +-
>  drivers/media/platform/exynos4-is/fimc-isp-video.c |   29 +-
>  drivers/media/platform/exynos4-is/fimc-lite.c      |   25 +-
>  drivers/media/platform/exynos4-is/fimc-m2m.c       |   18 +-
>  drivers/media/platform/m2m-deinterlace.c           |   24 +-
>  drivers/media/platform/marvell-ccic/mcam-core.c    |   28 +-
>  drivers/media/platform/mx2_emmaprp.c               |   24 +-
>  drivers/media/platform/omap3isp/ispvideo.c         |   18 +-
>  drivers/media/platform/s3c-camif/camif-capture.c   |   21 +-
>  drivers/media/platform/s5p-g2d/g2d.c               |   18 +-
>  drivers/media/platform/s5p-jpeg/jpeg-core.c        |   30 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   42 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   57 +-
>  drivers/media/platform/s5p-tv/mixer_video.c        |    9 +-
>  drivers/media/platform/sh_veu.c                    |   25 +-
>  drivers/media/platform/soc_camera/atmel-isi.c      |   34 +-
>  drivers/media/platform/soc_camera/mx2_camera.c     |   37 +-
>  drivers/media/platform/soc_camera/mx3_camera.c     |   36 +-
>  drivers/media/platform/soc_camera/rcar_vin.c       |   16 +-
>  .../platform/soc_camera/sh_mobile_ceu_camera.c     |   49 +-
>  drivers/media/platform/ti-vpe/vpe.c                |   32 +-
>  drivers/media/platform/vim2m.c                     |   32 +-
>  drivers/media/platform/vivid/vivid-sdr-cap.c       |   20 +-
>  drivers/media/platform/vivid/vivid-vbi-cap.c       |   22 +-
>  drivers/media/platform/vivid/vivid-vbi-out.c       |   22 +-
>  drivers/media/platform/vivid/vivid-vid-cap.c       |   34 +-
>  drivers/media/platform/vivid/vivid-vid-out.c       |   27 +-
>  drivers/media/usb/airspy/airspy.c                  |    9 +-
>  drivers/media/usb/au0828/au0828-vbi.c              |   25 +-
>  drivers/media/usb/au0828/au0828-video.c            |   25 +-
>  drivers/media/usb/em28xx/em28xx-vbi.c              |   23 +-
>  drivers/media/usb/em28xx/em28xx-video.c            |   28 +-
>  drivers/media/usb/go7007/go7007-v4l2.c             |   25 +-
>  drivers/media/usb/hackrf/hackrf.c                  |    9 +-
>  drivers/media/usb/msi2500/msi2500.c                |    9 +-
>  drivers/media/usb/pwc/pwc-if.c                     |   30 +-
>  drivers/media/usb/s2255/s2255drv.c                 |   18 +-
>  drivers/media/usb/stk1160/stk1160-v4l.c            |   13 +-
>  drivers/media/usb/usbtv/usbtv-video.c              |    9 +-
>  drivers/media/usb/uvc/uvc_queue.c                  |   40 +-
>  drivers/media/v4l2-core/Makefile                   |    2 +-
>  drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
>  drivers/media/v4l2-core/videobuf2-core.c           | 3488 +-------------------
>  drivers/media/v4l2-core/videobuf2-v4l2.c           |  615 ++--
>  include/media/videobuf2-core.h                     |  249 +-
>  include/media/videobuf2-dma-contig.h               |    4 +-
>  include/media/videobuf2-v4l2.h                     |  440 +--
>  73 files changed, 1227 insertions(+), 5131 deletions(-)

(driver changes removed - those are consequences of the core changes.
 Again, a script is the best way to do those driver changes, as it can
 be easily reviewed and will be needed anyway when applying the changes, as
 drivers may change or added while this changeset is not merged).

>  static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
> diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
> index bd9a6ef..15789e9 100644
> --- a/drivers/media/v4l2-core/Makefile
> +++ b/drivers/media/v4l2-core/Makefile
> @@ -28,7 +28,7 @@ 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_VIDEOBUF2_CORE) += videobuf2-v4l2.o
> +obj-$(CONFIG_VIDEOBUF2_CORE) += videobuf2-core.o videobuf2-v4l2.o
>  obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o
>  obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o
>  obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o
> diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
> index 3392a58..bce2560 100644
> --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
> +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
> @@ -739,13 +739,13 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_release);
>   *
>   * Call from buf_queue(), videobuf_queue_ops callback.
>   */
> -void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_v4l2_buffer *vb)
> +void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_v4l2_buffer *cb)

Why are you renaming it to "cb"? IMHO, we should standardize the namespace
for those. On the past patch, you were using vb2 and vb.

In any case, this namespace rename could happen on a separate patch, IMHO.
This one is already big enough without namespace renaming.

>  {
> -	struct v4l2_m2m_buffer *b = container_of(vb, struct v4l2_m2m_buffer, vb);
> +	struct v4l2_m2m_buffer *b = container_of(cb, struct v4l2_m2m_buffer, vb);
>  	struct v4l2_m2m_queue_ctx *q_ctx;
>  	unsigned long flags;
>  
> -	q_ctx = get_queue_ctx(m2m_ctx, vb->vb2.vb2_queue->type);
> +	q_ctx = get_queue_ctx(m2m_ctx, cb->vb2.vb2_queue->type);
>  	if (!q_ctx)
>  		return;
>  
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
> index 0d8bd9a..5f75937 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -1,5 +1,5 @@
>  /*
> - * videobuf2-core.c - V4L2 driver helper framework
> + * videobuf2-core.c - Video Buffer 2 framework
>   *
>   * Copyright (C) 2010 Samsung Electronics
>   *
> @@ -28,3492 +28,8 @@
>  #include <media/v4l2-fh.h>
>  #include <media/v4l2-event.h>
>  #include <media/v4l2-common.h>
> -#include <media/videobuf2-core.h>
> +#include <media/videobuf2-v4l2.h>
> -static int debug;
... (lots of lines removed here
> -EXPORT_SYMBOL_GPL(vb2_ops_wait_finish);
>  
>  MODULE_DESCRIPTION("Driver helper framework for Video for Linux 2");
>  MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>, Marek Szyprowski");

Hmm... was most of this file just removed and just the above was
preserved? This enforces the idea of just renaming it on the
previous patch (as proposed on patches 0/3 and 1/3) and then
creating a new one with the new content, moving out the functions
added here from videobuf2-v4l2.c.

> diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
> index cd28b4807f..fe07a2b 100644
> --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
> +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
> @@ -51,12 +51,12 @@ module_param(debug, int, 0644);
>  
>  #define log_memop(vb, op)						\
>  	dprintk(2, "call_memop(%p, %d, %s)%s\n",			\
> -		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
> -		(vb)->vb2.vb2_queue->mem_ops->op ? "" : " (nop)")
> +		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
> +		(vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
>  
>  #define call_memop(vb, op, args...)					\
>  ({									\
> -	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
> +	struct vb2_queue *_q = (vb)->vb2_queue;				\
>  	int err;							\
>  									\
>  	log_memop(vb, op);						\
> @@ -68,7 +68,7 @@ module_param(debug, int, 0644);
>  
>  #define call_ptr_memop(vb, op, args...)					\
>  ({									\
> -	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
> +	struct vb2_queue *_q = (vb)->vb2_queue;				\
>  	void *ptr;							\
>  									\
>  	log_memop(vb, op);						\
> @@ -80,7 +80,7 @@ module_param(debug, int, 0644);
>  
>  #define call_void_memop(vb, op, args...)				\
>  ({									\
> -	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
> +	struct vb2_queue *_q = (vb)->vb2_queue;				\
>  									\
>  	log_memop(vb, op);						\
>  	if (_q->mem_ops->op)						\
> @@ -113,16 +113,16 @@ module_param(debug, int, 0644);
>  
>  #define log_vb_qop(vb, op, args...)					\
>  	dprintk(2, "call_vb_qop(%p, %d, %s)%s\n",			\
> -		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
> -		(vb)->vb2.vb2_queue->ops->op ? "" : " (nop)")
> +		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
> +		(vb)->vb2_queue->ops->op ? "" : " (nop)")
>  
>  #define call_vb_qop(vb, op, args...)					\
>  ({									\
>  	int err;							\
>  									\
>  	log_vb_qop(vb, op);						\
> -	err = (vb)->vb2.vb2_queue->ops->op ?				\
> -		(vb)->vb2.vb2_queue->ops->op(args) : 0;			\
> +	err = (vb)->vb2_queue->ops->op ?				\
> +		(vb)->vb2_queue->ops->op(args) : 0;			\
>  	if (!err)							\
>  		(vb)->cnt_ ## op++;					\
>  	err;								\
> @@ -131,25 +131,25 @@ module_param(debug, int, 0644);
>  #define call_void_vb_qop(vb, op, args...)				\
>  ({									\
>  	log_vb_qop(vb, op);						\
> -	if ((vb)->vb2.vb2_queue->ops->op)					\
> -		(vb)->vb2.vb2_queue->ops->op(args);				\
> +	if ((vb)->vb2_queue->ops->op)					\
> +		(vb)->vb2_queue->ops->op(args);				\
>  	(vb)->cnt_ ## op++;						\
>  })
>  
>  #else
>  
>  #define call_memop(vb, op, args...)					\
> -	((vb)->vb2.vb2_queue->mem_ops->op ?					\
> -		(vb)->vb2.vb2_queue->mem_ops->op(args) : 0)
> +	((vb)->vb2_queue->mem_ops->op ?					\
> +		(vb)->vb2_queue->mem_ops->op(args) : 0)
>  
>  #define call_ptr_memop(vb, op, args...)					\
> -	((vb)->vb2.vb2_queue->mem_ops->op ?					\
> -		(vb)->vb2.vb2_queue->mem_ops->op(args) : NULL)
> +	((vb)->vb2_queue->mem_ops->op ?					\
> +		(vb)->vb2_queue->mem_ops->op(args) : NULL)
>  
>  #define call_void_memop(vb, op, args...)				\
>  	do {								\
> -		if ((vb)->vb2.vb2_queue->mem_ops->op)			\
> -			(vb)->vb2.vb2_queue->mem_ops->op(args);		\
> +		if ((vb)->vb2_queue->mem_ops->op)			\
> +			(vb)->vb2_queue->mem_ops->op(args);		\
>  	} while (0)
>  
>  #define call_qop(q, op, args...)					\
> @@ -162,12 +162,12 @@ module_param(debug, int, 0644);
>  	} while (0)
>  
>  #define call_vb_qop(vb, op, args...)					\
> -	((vb)->vb2.vb2_queue->ops->op ? (vb)->vb2.vb2_queue->ops->op(args) : 0)
> +	((vb)->vb2_queue->ops->op ? (vb)->vb2_queue->ops->op(args) : 0)
>  
>  #define call_void_vb_qop(vb, op, args...)				\
>  	do {								\
> -		if ((vb)->vb2.vb2_queue->ops->op)				\
> -			(vb)->vb2.vb2_queue->ops->op(args);			\
> +		if ((vb)->vb2_queue->ops->op)				\
> +			(vb)->vb2_queue->ops->op(args);			\
>  	} while (0)
>  
>  #endif
> @@ -186,9 +186,10 @@ static void __vb2_queue_cancel(struct vb2_queue *q);
>  /**
>   * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
>   */
> -static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
> +static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *cb)

Why are you called the v4l2 buffer as "cb"? At least for me, "cb" would
be an alias "common buffer". So, I would be expecting just the reverse ;)

>  {
> -	struct vb2_queue *q = vb->vb2.vb2_queue;
> +	struct vb2_buffer *vb = &cb->vb2;
> +	struct vb2_queue *q = vb->vb2_queue;
>  	enum dma_data_direction dma_dir =
>  		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
>  	void *mem_priv;
> @@ -198,7 +199,7 @@ static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
>  	 * Allocate memory for all planes in this buffer
>  	 * NOTE: mmapped areas should be page aligned
>  	 */
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>  		unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
>  
>  		mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
> @@ -207,16 +208,16 @@ static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
>  			goto free;
>  
>  		/* Associate allocator private data with this plane */
> -		vb->vb2.planes[plane].mem_priv = mem_priv;
> -		vb->v4l2_planes[plane].length = q->plane_sizes[plane];
> +		vb->planes[plane].mem_priv = mem_priv;
> +		cb->v4l2_planes[plane].length = q->plane_sizes[plane];
>  	}
>  
>  	return 0;
>  free:
>  	/* Free already allocated memory if one of the allocations failed */
>  	for (; plane > 0; --plane) {
> -		call_void_memop(vb, put, vb->vb2.planes[plane - 1].mem_priv);
> -		vb->vb2.planes[plane - 1].mem_priv = NULL;
> +		call_void_memop(vb, put, vb->planes[plane - 1].mem_priv);
> +		vb->planes[plane - 1].mem_priv = NULL;
>  	}
>  
>  	return -ENOMEM;
> @@ -225,15 +226,16 @@ free:
>  /**
>   * __vb2_buf_mem_free() - free memory of the given buffer
>   */
> -static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
> +static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *cb)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	unsigned int plane;
>  
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> -		call_void_memop(vb, put, vb->vb2.planes[plane].mem_priv);
> -		vb->vb2.planes[plane].mem_priv = NULL;
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
> +		call_void_memop(vb, put, vb->planes[plane].mem_priv);
> +		vb->planes[plane].mem_priv = NULL;
>  		dprintk(3, "freed plane %d of buffer %d\n", plane,
> -			vb->v4l2_buf.index);
> +			cb->v4l2_buf.index);
>  	}
>  }
>  
> @@ -241,14 +243,15 @@ static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
>   * __vb2_buf_userptr_put() - release userspace memory associated with
>   * a USERPTR buffer
>   */
> -static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
> +static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *cb)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	unsigned int plane;
>  
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> -		if (vb->vb2.planes[plane].mem_priv)
> -			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
> -		vb->vb2.planes[plane].mem_priv = NULL;
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
> +		if (vb->planes[plane].mem_priv)
> +			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
> +		vb->planes[plane].mem_priv = NULL;
>  	}
>  }
>  
> @@ -256,8 +259,9 @@ static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
>   * __vb2_plane_dmabuf_put() - release memory associated with
>   * a DMABUF shared plane
>   */
> -static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane *p)
> +static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *cb, struct vb2_plane *p)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	if (!p->mem_priv)
>  		return;
>  
> @@ -273,12 +277,13 @@ static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane
>   * __vb2_buf_dmabuf_put() - release memory associated with
>   * a DMABUF shared buffer
>   */
> -static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
> +static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *cb)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	unsigned int plane;
>  
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
> -		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
> +	for (plane = 0; plane < vb->num_planes; ++plane)
> +		__vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
>  }
>  
>  /**
> @@ -288,15 +293,17 @@ static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
>  static void __setup_lengths(struct vb2_queue *q, unsigned int n)
>  {
>  	unsigned int buffer, plane;
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  
>  	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
>  		vb = q->bufs[buffer];
>  		if (!vb)
>  			continue;
>  
> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane)
> -			vb->v4l2_planes[plane].length = q->plane_sizes[plane];
> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
> +		for (plane = 0; plane < vb->num_planes; ++plane)
> +			cb->v4l2_planes[plane].length = q->plane_sizes[plane];
>  	}
>  }
>  
> @@ -307,13 +314,15 @@ static void __setup_lengths(struct vb2_queue *q, unsigned int n)
>  static void __setup_offsets(struct vb2_queue *q, unsigned int n)
>  {
>  	unsigned int buffer, plane;
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	unsigned long off;
>  
>  	if (q->num_buffers) {
>  		struct v4l2_plane *p;
>  		vb = q->bufs[q->num_buffers - 1];
> -		p = &vb->v4l2_planes[vb->vb2.num_planes - 1];
> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
> +		p = &cb->v4l2_planes[vb->num_planes - 1];
>  		off = PAGE_ALIGN(p->m.mem_offset + p->length);
>  	} else {
>  		off = 0;
> @@ -324,13 +333,14 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
>  		if (!vb)
>  			continue;
>  
> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> -			vb->v4l2_planes[plane].m.mem_offset = off;
> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
> +		for (plane = 0; plane < vb->num_planes; ++plane) {
> +			cb->v4l2_planes[plane].m.mem_offset = off;
>  
>  			dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
>  					buffer, plane, off);
>  
> -			off += vb->v4l2_planes[plane].length;
> +			off += cb->v4l2_planes[plane].length;
>  			off = PAGE_ALIGN(off);
>  		}
>  	}
> @@ -347,35 +357,37 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
>  			     unsigned int num_buffers, unsigned int num_planes)
>  {
>  	unsigned int buffer;
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	int ret;
>  
>  	for (buffer = 0; buffer < num_buffers; ++buffer) {
>  		/* Allocate videobuf buffer structures */
> -		vb = kzalloc(q->buf_struct_size, GFP_KERNEL);
> -		if (!vb) {
> +		cb = kzalloc(q->buf_struct_size, GFP_KERNEL);
> +		if (!cb) {
>  			dprintk(1, "memory alloc for buffer struct failed\n");
>  			break;
>  		}
>  
> +		vb = &cb->vb2;
>  		/* Length stores number of planes for multiplanar buffers */
>  		if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
> -			vb->v4l2_buf.length = num_planes;
> +			cb->v4l2_buf.length = num_planes;
>  
> -		vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
> -		vb->vb2.vb2_queue = q;
> -		vb->vb2.num_planes = num_planes;
> -		vb->v4l2_buf.index = q->num_buffers + buffer;
> -		vb->v4l2_buf.type = q->type;
> -		vb->v4l2_buf.memory = memory;
> +		vb->state = VB2_BUF_STATE_DEQUEUED;
> +		vb->vb2_queue = q;
> +		vb->num_planes = num_planes;
> +		cb->v4l2_buf.index = q->num_buffers + buffer;
> +		cb->v4l2_buf.type = q->type;
> +		cb->v4l2_buf.memory = memory;
>  
>  		/* Allocate video buffer memory for the MMAP type */
>  		if (memory == V4L2_MEMORY_MMAP) {
> -			ret = __vb2_buf_mem_alloc(vb);
> +			ret = __vb2_buf_mem_alloc(cb);
>  			if (ret) {
>  				dprintk(1, "failed allocating memory for "
>  						"buffer %d\n", buffer);
> -				kfree(vb);
> +				kfree(cb);
>  				break;
>  			}
>  			/*
> @@ -387,8 +399,8 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
>  			if (ret) {
>  				dprintk(1, "buffer %d %p initialization"
>  					" failed\n", buffer, vb);
> -				__vb2_buf_mem_free(vb);
> -				kfree(vb);
> +				__vb2_buf_mem_free(cb);
> +				kfree(cb);
>  				break;
>  			}
>  		}
> @@ -412,21 +424,23 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
>  static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
>  {
>  	unsigned int buffer;
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  
>  	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
>  	     ++buffer) {
>  		vb = q->bufs[buffer];
>  		if (!vb)
>  			continue;
> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  
>  		/* Free MMAP buffers or release USERPTR buffers */
>  		if (q->memory == V4L2_MEMORY_MMAP)
> -			__vb2_buf_mem_free(vb);
> +			__vb2_buf_mem_free(cb);
>  		else if (q->memory == V4L2_MEMORY_DMABUF)
> -			__vb2_buf_dmabuf_put(vb);
> +			__vb2_buf_dmabuf_put(cb);
>  		else
> -			__vb2_buf_userptr_put(vb);
> +			__vb2_buf_userptr_put(cb);
>  	}
>  }
>  
> @@ -438,7 +452,7 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
>  static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>  {
>  	unsigned int buffer;
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_buffer *vb;
>  
>  	/*
>  	 * Sanity check: when preparing a buffer the queue lock is released for
> @@ -450,11 +464,11 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>  	 */
>  	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
>  	     ++buffer) {
> -		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
> +		vb = q->bufs[buffer];
>  
>  		if (vb == NULL)
>  			continue;
> -		if (vb->vb2.state == VB2_BUF_STATE_PREPARING) {
> +		if (vb->state == VB2_BUF_STATE_PREPARING) {
>  			dprintk(1, "preparing buffers, cannot free\n");
>  			return -EAGAIN;
>  		}
> @@ -463,9 +477,9 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>  	/* Call driver-provided cleanup function for each buffer, if provided */
>  	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
>  	     ++buffer) {
> -		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
> +		vb = q->bufs[buffer];
>  
> -		if (vb && vb->vb2.planes[0].mem_priv)
> +		if (vb && vb->planes[0].mem_priv)
>  			call_void_vb_qop(vb, buf_cleanup, vb);
>  	}
>  
> @@ -498,38 +512,38 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>  		q->cnt_stop_streaming = 0;
>  	}
>  	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
> -		struct vb2_v4l2_buffer *vb = q->bufs[buffer];
> -		bool unbalanced = vb->vb2.cnt_mem_alloc != vb->vb2.cnt_mem_put ||
> -				  vb->vb2.cnt_mem_prepare != vb->vb2.cnt_mem_finish ||
> -				  vb->vb2.cnt_mem_get_userptr != vb->vb2.cnt_mem_put_userptr ||
> -				  vb->vb2.cnt_mem_attach_dmabuf != vb->vb2.cnt_mem_detach_dmabuf ||
> -				  vb->vb2.cnt_mem_map_dmabuf != vb->vb2.cnt_mem_unmap_dmabuf ||
> -				  vb->vb2.cnt_buf_queue != vb->vb2.cnt_buf_done ||
> -				  vb->vb2.cnt_buf_prepare != vb->vb2.cnt_buf_finish ||
> -				  vb->vb2.cnt_buf_init != vb->vb2.cnt_buf_cleanup;
> +		struct vb2_buffer *vb = q->bufs[buffer];
> +		bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put ||
> +				  vb->cnt_mem_prepare != vb->cnt_mem_finish ||
> +				  vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr ||
> +				  vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf ||
> +				  vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf ||
> +				  vb->cnt_buf_queue != vb->cnt_buf_done ||
> +				  vb->cnt_buf_prepare != vb->cnt_buf_finish ||
> +				  vb->cnt_buf_init != vb->cnt_buf_cleanup;
>  
>  		if (unbalanced || debug) {
>  			pr_info("vb2:   counters for queue %p, buffer %d:%s\n",
>  				q, buffer, unbalanced ? " UNBALANCED!" : "");
>  			pr_info("vb2:     buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n",
> -				vb->vb2.cnt_buf_init, vb->vb2.cnt_buf_cleanup,
> -				vb->vb2.cnt_buf_prepare, vb->vb2.cnt_buf_finish);
> +				vb->cnt_buf_init, vb->cnt_buf_cleanup,
> +				vb->cnt_buf_prepare, vb->cnt_buf_finish);
>  			pr_info("vb2:     buf_queue: %u buf_done: %u\n",
> -				vb->vb2.cnt_buf_queue, vb->vb2.cnt_buf_done);
> +				vb->cnt_buf_queue, vb->cnt_buf_done);
>  			pr_info("vb2:     alloc: %u put: %u prepare: %u finish: %u mmap: %u\n",
> -				vb->vb2.cnt_mem_alloc, vb->vb2.cnt_mem_put,
> -				vb->vb2.cnt_mem_prepare, vb->vb2.cnt_mem_finish,
> -				vb->vb2.cnt_mem_mmap);
> +				vb->cnt_mem_alloc, vb->cnt_mem_put,
> +				vb->cnt_mem_prepare, vb->cnt_mem_finish,
> +				vb->cnt_mem_mmap);
>  			pr_info("vb2:     get_userptr: %u put_userptr: %u\n",
> -				vb->vb2.cnt_mem_get_userptr, vb->vb2.cnt_mem_put_userptr);
> +				vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr);
>  			pr_info("vb2:     attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n",
> -				vb->vb2.cnt_mem_attach_dmabuf, vb->vb2.cnt_mem_detach_dmabuf,
> -				vb->vb2.cnt_mem_map_dmabuf, vb->vb2.cnt_mem_unmap_dmabuf);
> +				vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf,
> +				vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf);
>  			pr_info("vb2:     get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n",
> -				vb->vb2.cnt_mem_get_dmabuf,
> -				vb->vb2.cnt_mem_num_users,
> -				vb->vb2.cnt_mem_vaddr,
> -				vb->vb2.cnt_mem_cookie);
> +				vb->cnt_mem_get_dmabuf,
> +				vb->cnt_mem_num_users,
> +				vb->cnt_mem_vaddr,
> +				vb->cnt_mem_cookie);
>  		}
>  	}
>  #endif
> @@ -553,8 +567,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>   * __verify_planes_array() - verify that the planes array passed in struct
>   * v4l2_buffer from userspace can be safely used
>   */
> -static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
> +static int __verify_planes_array(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
> +
>  	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
>  		return 0;
>  
> @@ -565,9 +581,9 @@ static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_b
>  		return -EINVAL;
>  	}
>  
> -	if (b->length < vb->vb2.num_planes || b->length > VIDEO_MAX_PLANES) {
> +	if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
>  		dprintk(1, "incorrect planes array length, "
> -			   "expected %d, got %d\n", vb->vb2.num_planes, b->length);
> +			   "expected %d, got %d\n", vb->num_planes, b->length);
>  		return -EINVAL;
>  	}
>  
> @@ -578,8 +594,9 @@ static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_b
>   * __verify_length() - Verify that the bytesused value for each plane fits in
>   * the plane length and that the data offset doesn't exceed the bytesused value.
>   */
> -static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
> +static int __verify_length(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	unsigned int length;
>  	unsigned int bytesused;
>  	unsigned int plane;
> @@ -588,11 +605,11 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
>  		return 0;
>  
>  	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> +		for (plane = 0; plane < vb->num_planes; ++plane) {
>  			length = (b->memory == V4L2_MEMORY_USERPTR ||
>  				  b->memory == V4L2_MEMORY_DMABUF)
>  			       ? b->m.planes[plane].length
> -			       : vb->v4l2_planes[plane].length;
> +			       : cb->v4l2_planes[plane].length;
>  			bytesused = b->m.planes[plane].bytesused
>  				  ? b->m.planes[plane].bytesused : length;
>  
> @@ -605,7 +622,7 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
>  		}
>  	} else {
>  		length = (b->memory == V4L2_MEMORY_USERPTR)
> -		       ? b->length : vb->v4l2_planes[0].length;
> +		       ? b->length : cb->v4l2_planes[0].length;
>  		bytesused = b->bytesused ? b->bytesused : length;
>  
>  		if (b->bytesused > length)
> @@ -619,11 +636,12 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
>   * __buffer_in_use() - return true if the buffer is in use and
>   * the queue cannot be freed (by the means of REQBUFS(0)) call
>   */
> -static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
> +static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *cb)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	unsigned int plane;
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> -		void *mem_priv = vb->vb2.planes[plane].mem_priv;
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
> +		void *mem_priv = vb->planes[plane].mem_priv;
>  		/*
>  		 * If num_users() has not been provided, call_memop
>  		 * will return 0, apparently nobody cares about this
> @@ -642,9 +660,12 @@ static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
>   */
>  static bool __buffers_in_use(struct vb2_queue *q)
>  {
> +	struct vb2_v4l2_buffer *cb;
>  	unsigned int buffer;
> +
>  	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
> -		if (__buffer_in_use(q, q->bufs[buffer]))
> +		cb = container_of(q->bufs[buffer], struct vb2_v4l2_buffer, vb2);
> +		if (__buffer_in_use(q, cb))
>  			return true;
>  	}
>  	return false;
> @@ -654,36 +675,37 @@ static bool __buffers_in_use(struct vb2_queue *q)
>   * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
>   * returned to userspace
>   */
> -static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b)
> +static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *cb, struct v4l2_buffer *b)
>  {
> -	struct vb2_queue *q = vb->vb2.vb2_queue;
> +	struct vb2_buffer *vb = &cb->vb2;
> +	struct vb2_queue *q = vb->vb2_queue;
>  
>  	/* Copy back data such as timestamp, flags, etc. */
> -	memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
> -	b->reserved2 = vb->v4l2_buf.reserved2;
> -	b->reserved = vb->v4l2_buf.reserved;
> +	memcpy(b, &cb->v4l2_buf, offsetof(struct v4l2_buffer, m));
> +	b->reserved2 = cb->v4l2_buf.reserved2;
> +	b->reserved = cb->v4l2_buf.reserved;
>  
>  	if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) {
>  		/*
>  		 * Fill in plane-related data if userspace provided an array
>  		 * for it. The caller has already verified memory and size.
>  		 */
> -		b->length = vb->vb2.num_planes;
> -		memcpy(b->m.planes, vb->v4l2_planes,
> +		b->length = vb->num_planes;
> +		memcpy(b->m.planes, cb->v4l2_planes,
>  			b->length * sizeof(struct v4l2_plane));
>  	} else {
>  		/*
>  		 * We use length and offset in v4l2_planes array even for
>  		 * single-planar buffers, but userspace does not.
>  		 */
> -		b->length = vb->v4l2_planes[0].length;
> -		b->bytesused = vb->v4l2_planes[0].bytesused;
> +		b->length = cb->v4l2_planes[0].length;
> +		b->bytesused = cb->v4l2_planes[0].bytesused;
>  		if (q->memory == V4L2_MEMORY_MMAP)
> -			b->m.offset = vb->v4l2_planes[0].m.mem_offset;
> +			b->m.offset = cb->v4l2_planes[0].m.mem_offset;
>  		else if (q->memory == V4L2_MEMORY_USERPTR)
> -			b->m.userptr = vb->v4l2_planes[0].m.userptr;
> +			b->m.userptr = cb->v4l2_planes[0].m.userptr;
>  		else if (q->memory == V4L2_MEMORY_DMABUF)
> -			b->m.fd = vb->v4l2_planes[0].m.fd;
> +			b->m.fd = cb->v4l2_planes[0].m.fd;
>  	}
>  
>  	/*
> @@ -701,7 +723,7 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
>  		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
>  	}
>  
> -	switch (vb->vb2.state) {
> +	switch (vb->state) {
>  	case VB2_BUF_STATE_QUEUED:
>  	case VB2_BUF_STATE_ACTIVE:
>  		b->flags |= V4L2_BUF_FLAG_QUEUED;
> @@ -721,7 +743,7 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
>  		break;
>  	}
>  
> -	if (__buffer_in_use(q, vb))
> +	if (__buffer_in_use(q, cb))
>  		b->flags |= V4L2_BUF_FLAG_MAPPED;
>  }
>  
> @@ -740,7 +762,8 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
>   */
>  int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  {
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	int ret;
>  
>  	if (b->type != q->type) {
> @@ -753,9 +776,10 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  		return -EINVAL;
>  	}
>  	vb = q->bufs[b->index];
> -	ret = __verify_planes_array(vb, b);
> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
> +	ret = __verify_planes_array(cb, b);
>  	if (!ret)
> -		__fill_v4l2_buffer(vb, b);
> +		__fill_v4l2_buffer(cb, b);
>  	return ret;
>  }
>  EXPORT_SYMBOL(vb2_querybuf);
> @@ -1123,12 +1147,13 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs);
>   * This function returns a kernel virtual address of a given plane if
>   * such a mapping exist, NULL otherwise.
>   */
> -void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>  {
> -	if (plane_no > vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
> +	struct vb2_buffer *vb = &cb->vb2;
> +	if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
>  		return NULL;
>  
> -	return call_ptr_memop(vb, vaddr, vb->vb2.planes[plane_no].mem_priv);
> +	return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
>  
>  }
>  EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
> @@ -1140,16 +1165,17 @@ EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
>   *
>   * This function returns an allocator specific cookie for a given plane if
>   * available, NULL otherwise. The allocator should provide some simple static
> - * inline funaction, which would convert this cookie to the allocator specific
> + * inline function, which would convert this cookie to the allocator specific
>   * type that can be used directly by the driver to access the buffer. This can
>   * be for example physical address, pointer to scatter list or IOMMU mapping.
>   */
> -void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>  {
> -	if (plane_no >= vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
> +	struct vb2_buffer *vb = &cb->vb2;
> +	if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
>  		return NULL;
>  
> -	return call_ptr_memop(vb, cookie, vb->vb2.planes[plane_no].mem_priv);
> +	return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
>  }
>  EXPORT_SYMBOL_GPL(vb2_plane_cookie);
>  
> @@ -1172,13 +1198,14 @@ EXPORT_SYMBOL_GPL(vb2_plane_cookie);
>   * be started for some reason. In that case the buffers should be returned with
>   * state QUEUED.
>   */
> -void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
> +void vb2_buffer_done(struct vb2_v4l2_buffer *cb, enum vb2_buffer_state state)
>  {
> -	struct vb2_queue *q = vb->vb2.vb2_queue;
> +	struct vb2_buffer *vb = &cb->vb2;
> +	struct vb2_queue *q = vb->vb2_queue;
>  	unsigned long flags;
>  	unsigned int plane;
>  
> -	if (WARN_ON(vb->vb2.state != VB2_BUF_STATE_ACTIVE))
> +	if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
>  		return;
>  
>  	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
> @@ -1191,20 +1218,20 @@ void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
>  	 * Although this is not a callback, it still does have to balance
>  	 * with the buf_queue op. So update this counter manually.
>  	 */
> -	vb->vb2.cnt_buf_done++;
> +	vb->cnt_buf_done++;
>  #endif
>  	dprintk(4, "done processing on buffer %d, state: %d\n",
> -			vb->v4l2_buf.index, state);
> +			cb->v4l2_buf.index, state);
>  
>  	/* sync buffers */
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
> -		call_void_memop(vb, finish, vb->vb2.planes[plane].mem_priv);
> +	for (plane = 0; plane < vb->num_planes; ++plane)
> +		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
>  
>  	/* Add the buffer to the done buffers list */
>  	spin_lock_irqsave(&q->done_lock, flags);
> -	vb->vb2.state = state;
> +	vb->state = state;
>  	if (state != VB2_BUF_STATE_QUEUED)
> -		list_add_tail(&vb->vb2.done_entry, &q->done_list);
> +		list_add_tail(&vb->done_entry, &q->done_list);
>  	atomic_dec(&q->owned_by_drv_count);
>  	spin_unlock_irqrestore(&q->done_lock, flags);
>  
> @@ -1245,14 +1272,15 @@ EXPORT_SYMBOL_GPL(vb2_discard_done);
>   * v4l2_buffer by the userspace. The caller has already verified that struct
>   * v4l2_buffer has a valid number of planes.
>   */
> -static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b,
> +static void __fill_vb2_buffer(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b,
>  				struct v4l2_plane *v4l2_planes)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	unsigned int plane;
>  
>  	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
>  		if (b->memory == V4L2_MEMORY_USERPTR) {
> -			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> +			for (plane = 0; plane < vb->num_planes; ++plane) {
>  				v4l2_planes[plane].m.userptr =
>  					b->m.planes[plane].m.userptr;
>  				v4l2_planes[plane].length =
> @@ -1260,7 +1288,7 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>  			}
>  		}
>  		if (b->memory == V4L2_MEMORY_DMABUF) {
> -			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> +			for (plane = 0; plane < vb->num_planes; ++plane) {
>  				v4l2_planes[plane].m.fd =
>  					b->m.planes[plane].m.fd;
>  				v4l2_planes[plane].length =
> @@ -1280,7 +1308,7 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>  			 * it's a safe assumption that they really meant to
>  			 * use the full plane sizes.
>  			 */
> -			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> +			for (plane = 0; plane < vb->num_planes; ++plane) {
>  				struct v4l2_plane *pdst = &v4l2_planes[plane];
>  				struct v4l2_plane *psrc = &b->m.planes[plane];
>  
> @@ -1318,15 +1346,15 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>  	}
>  
>  	/* Zero flags that the vb2 core handles */
> -	vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
> -	if ((vb->vb2.vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
> +	cb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
> +	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
>  	    V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
>  		/*
>  		 * Non-COPY timestamps and non-OUTPUT queues will get
>  		 * their timestamp and timestamp source flags from the
>  		 * queue.
>  		 */
> -		vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
> +		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
>  	}
>  
>  	if (V4L2_TYPE_IS_OUTPUT(b->type)) {
> @@ -1336,46 +1364,48 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>  		 * The 'field' is valid metadata for this output buffer
>  		 * and so that needs to be copied here.
>  		 */
> -		vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
> -		vb->v4l2_buf.field = b->field;
> +		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
> +		cb->v4l2_buf.field = b->field;
>  	} else {
>  		/* Zero any output buffer flags as this is a capture buffer */
> -		vb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
> +		cb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
>  	}
>  }
>  
>  /**
>   * __qbuf_mmap() - handle qbuf of an MMAP buffer
>   */
> -static int __qbuf_mmap(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
> +static int __qbuf_mmap(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>  {
> -	__fill_vb2_buffer(vb, b, vb->v4l2_planes);
> +	struct vb2_buffer *vb = &cb->vb2;
> +	__fill_vb2_buffer(cb, b, cb->v4l2_planes);
>  	return call_vb_qop(vb, buf_prepare, vb);
>  }
>  
>  /**
>   * __qbuf_userptr() - handle qbuf of a USERPTR buffer
>   */
> -static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
> +static int __qbuf_userptr(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	struct v4l2_plane planes[VIDEO_MAX_PLANES];
> -	struct vb2_queue *q = vb->vb2.vb2_queue;
> +	struct vb2_queue *q = vb->vb2_queue;
>  	void *mem_priv;
>  	unsigned int plane;
>  	int ret;
>  	enum dma_data_direction dma_dir =
>  		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
> -	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
> +	bool reacquired = vb->planes[0].mem_priv == NULL;
>  
> -	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
> +	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
>  	/* Copy relevant information provided by the userspace */
> -	__fill_vb2_buffer(vb, b, planes);
> +	__fill_vb2_buffer(cb, b, planes);
>  
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>  		/* Skip the plane if already verified */
> -		if (vb->v4l2_planes[plane].m.userptr &&
> -		    vb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
> -		    && vb->v4l2_planes[plane].length == planes[plane].length)
> +		if (cb->v4l2_planes[plane].m.userptr &&
> +		    cb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
> +		    && cb->v4l2_planes[plane].length == planes[plane].length)
>  			continue;
>  
>  		dprintk(3, "userspace address for plane %d changed, "
> @@ -1392,16 +1422,16 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
>  		}
>  
>  		/* Release previously acquired memory if present */
> -		if (vb->vb2.planes[plane].mem_priv) {
> +		if (vb->planes[plane].mem_priv) {
>  			if (!reacquired) {
>  				reacquired = true;
>  				call_void_vb_qop(vb, buf_cleanup, vb);
>  			}
> -			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
> +			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
>  		}
>  
> -		vb->vb2.planes[plane].mem_priv = NULL;
> -		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
> +		vb->planes[plane].mem_priv = NULL;
> +		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
>  
>  		/* Acquire each plane's memory */
>  		mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane],
> @@ -1413,15 +1443,15 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
>  			ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
>  			goto err;
>  		}
> -		vb->vb2.planes[plane].mem_priv = mem_priv;
> +		vb->planes[plane].mem_priv = mem_priv;
>  	}
>  
>  	/*
>  	 * Now that everything is in order, copy relevant information
>  	 * provided by userspace.
>  	 */
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
> -		vb->v4l2_planes[plane] = planes[plane];
> +	for (plane = 0; plane < vb->num_planes; ++plane)
> +		cb->v4l2_planes[plane] = planes[plane];
>  
>  	if (reacquired) {
>  		/*
> @@ -1446,12 +1476,12 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
>  	return 0;
>  err:
>  	/* In case of errors, release planes that were already acquired */
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> -		if (vb->vb2.planes[plane].mem_priv)
> -			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
> -		vb->vb2.planes[plane].mem_priv = NULL;
> -		vb->v4l2_planes[plane].m.userptr = 0;
> -		vb->v4l2_planes[plane].length = 0;
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
> +		if (vb->planes[plane].mem_priv)
> +			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
> +		vb->planes[plane].mem_priv = NULL;
> +		cb->v4l2_planes[plane].m.userptr = 0;
> +		cb->v4l2_planes[plane].length = 0;
>  	}
>  
>  	return ret;
> @@ -1460,22 +1490,23 @@ err:
>  /**
>   * __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
>   */
> -static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
> +static int __qbuf_dmabuf(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>  {
> +	struct vb2_buffer *vb = &cb->vb2;
>  	struct v4l2_plane planes[VIDEO_MAX_PLANES];
> -	struct vb2_queue *q = vb->vb2.vb2_queue;
> +	struct vb2_queue *q = vb->vb2_queue;
>  	void *mem_priv;
>  	unsigned int plane;
>  	int ret;
>  	enum dma_data_direction dma_dir =
>  		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
> -	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
> +	bool reacquired = vb->planes[0].mem_priv == NULL;
>  
> -	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
> +	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
>  	/* Copy relevant information provided by the userspace */
> -	__fill_vb2_buffer(vb, b, planes);
> +	__fill_vb2_buffer(cb, b, planes);
>  
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>  		struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
>  
>  		if (IS_ERR_OR_NULL(dbuf)) {
> @@ -1497,8 +1528,8 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>  		}
>  
>  		/* Skip the plane if already verified */
> -		if (dbuf == vb->vb2.planes[plane].dbuf &&
> -		    vb->v4l2_planes[plane].length == planes[plane].length) {
> +		if (dbuf == vb->planes[plane].dbuf &&
> +		    cb->v4l2_planes[plane].length == planes[plane].length) {
>  			dma_buf_put(dbuf);
>  			continue;
>  		}
> @@ -1511,8 +1542,8 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>  		}
>  
>  		/* Release previously acquired memory if present */
> -		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
> -		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
> +		__vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
> +		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
>  
>  		/* Acquire each plane's memory */
>  		mem_priv = call_ptr_memop(vb, attach_dmabuf, q->alloc_ctx[plane],
> @@ -1524,30 +1555,30 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>  			goto err;
>  		}
>  
> -		vb->vb2.planes[plane].dbuf = dbuf;
> -		vb->vb2.planes[plane].mem_priv = mem_priv;
> +		vb->planes[plane].dbuf = dbuf;
> +		vb->planes[plane].mem_priv = mem_priv;
>  	}
>  
>  	/* TODO: This pins the buffer(s) with  dma_buf_map_attachment()).. but
>  	 * really we want to do this just before the DMA, not while queueing
>  	 * the buffer(s)..
>  	 */
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> -		ret = call_memop(vb, map_dmabuf, vb->vb2.planes[plane].mem_priv);
> +	for (plane = 0; plane < vb->num_planes; ++plane) {
> +		ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
>  		if (ret) {
>  			dprintk(1, "failed to map dmabuf for plane %d\n",
>  				plane);
>  			goto err;
>  		}
> -		vb->vb2.planes[plane].dbuf_mapped = 1;
> +		vb->planes[plane].dbuf_mapped = 1;
>  	}
>  
>  	/*
>  	 * Now that everything is in order, copy relevant information
>  	 * provided by userspace.
>  	 */
> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
> -		vb->v4l2_planes[plane] = planes[plane];
> +	for (plane = 0; plane < vb->num_planes; ++plane)
> +		cb->v4l2_planes[plane] = planes[plane];
>  
>  	if (reacquired) {
>  		/*
> @@ -1571,7 +1602,7 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>  	return 0;
>  err:
>  	/* In case of errors, release planes that were already acquired */
> -	__vb2_buf_dmabuf_put(vb);
> +	__vb2_buf_dmabuf_put(cb);
>  
>  	return ret;
>  }
> @@ -1581,7 +1612,6 @@ err:
>   */
>  static void __enqueue_in_driver(struct vb2_buffer *vb)
>  {
> -	struct vb2_v4l2_buffer *pb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  	struct vb2_queue *q = vb->vb2_queue;
>  	unsigned int plane;
>  
> @@ -1590,17 +1620,18 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
>  
>  	/* sync buffers */
>  	for (plane = 0; plane < vb->num_planes; ++plane)
> -		call_void_memop(pb, prepare, vb->planes[plane].mem_priv);
> +		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
>  
> -	call_void_vb_qop(pb, buf_queue, pb);
> +	call_void_vb_qop(vb, buf_queue, vb);
>  }
>  
> -static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
> +static int __buf_prepare(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>  {
> -	struct vb2_queue *q = vb->vb2.vb2_queue;
> +	struct vb2_buffer *vb = &cb->vb2;
> +	struct vb2_queue *q = vb->vb2_queue;
>  	int ret;
>  
> -	ret = __verify_length(vb, b);
> +	ret = __verify_length(cb, b);
>  	if (ret < 0) {
>  		dprintk(1, "plane parameters verification failed: %d\n", ret);
>  		return ret;
> @@ -1624,22 +1655,22 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>  		return -EIO;
>  	}
>  
> -	vb->vb2.state = VB2_BUF_STATE_PREPARING;
> -	vb->v4l2_buf.timestamp.tv_sec = 0;
> -	vb->v4l2_buf.timestamp.tv_usec = 0;
> -	vb->v4l2_buf.sequence = 0;
> +	vb->state = VB2_BUF_STATE_PREPARING;
> +	cb->v4l2_buf.timestamp.tv_sec = 0;
> +	cb->v4l2_buf.timestamp.tv_usec = 0;
> +	cb->v4l2_buf.sequence = 0;
>  
>  	switch (q->memory) {
>  	case V4L2_MEMORY_MMAP:
> -		ret = __qbuf_mmap(vb, b);
> +		ret = __qbuf_mmap(cb, b);
>  		break;
>  	case V4L2_MEMORY_USERPTR:
>  		down_read(&current->mm->mmap_sem);
> -		ret = __qbuf_userptr(vb, b);
> +		ret = __qbuf_userptr(cb, b);
>  		up_read(&current->mm->mmap_sem);
>  		break;
>  	case V4L2_MEMORY_DMABUF:
> -		ret = __qbuf_dmabuf(vb, b);
> +		ret = __qbuf_dmabuf(cb, b);
>  		break;
>  	default:
>  		WARN(1, "Invalid queue type\n");
> @@ -1648,7 +1679,7 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>  
>  	if (ret)
>  		dprintk(1, "buffer preparation failed: %d\n", ret);
> -	vb->vb2.state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
> +	vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
>  
>  	return ret;
>  }
> @@ -1656,6 +1687,8 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>  static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
>  				    const char *opname)
>  {
> +	struct vb2_v4l2_buffer *cb;
> +
>  	if (b->type != q->type) {
>  		dprintk(1, "%s: invalid buffer type\n", opname);
>  		return -EINVAL;
> @@ -1677,7 +1710,9 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
>  		return -EINVAL;
>  	}
>  
> -	return __verify_planes_array(q->bufs[b->index], b);
> +	cb = container_of(q->bufs[b->index], struct vb2_v4l2_buffer, vb2);
> +
> +	return __verify_planes_array(cb, b);
>  }
>  
>  /**
> @@ -1697,7 +1732,8 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
>   */
>  int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
>  {
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	int ret;
>  
>  	if (vb2_fileio_is_active(q)) {
> @@ -1710,18 +1746,19 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
>  		return ret;
>  
>  	vb = q->bufs[b->index];
> -	if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
> +	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
>  		dprintk(1, "invalid buffer state %d\n",
> -			vb->vb2.state);
> +			vb->state);
>  		return -EINVAL;
>  	}
>  
> -	ret = __buf_prepare(vb, b);
> +	ret = __buf_prepare(cb, b);
>  	if (!ret) {
>  		/* Fill buffer information for the userspace */
> -		__fill_v4l2_buffer(vb, b);
> +		__fill_v4l2_buffer(cb, b);
>  
> -		dprintk(1, "prepare of buffer %d succeeded\n", vb->v4l2_buf.index);
> +		dprintk(1, "prepare of buffer %d succeeded\n", cb->v4l2_buf.index);
>  	}
>  	return ret;
>  }
> @@ -1741,7 +1778,7 @@ EXPORT_SYMBOL_GPL(vb2_prepare_buf);
>  static int vb2_start_streaming(struct vb2_queue *q)
>  {
>  	struct vb2_buffer *vb;
> -	struct vb2_v4l2_buffer *pb;
> +	struct vb2_v4l2_buffer *cb;
>  	int ret;
>  
>  	/*
> @@ -1775,9 +1812,10 @@ static int vb2_start_streaming(struct vb2_queue *q)
>  		 * correctly return them to vb2.
>  		 */
>  		for (i = 0; i < q->num_buffers; ++i) {
> -			pb = q->bufs[i];
> -			if (pb->vb2.state == VB2_BUF_STATE_ACTIVE)
> -				vb2_buffer_done(pb, VB2_BUF_STATE_QUEUED);
> +			vb = q->bufs[i];
> +			cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
> +			if (vb->state == VB2_BUF_STATE_ACTIVE)
> +				vb2_buffer_done(cb, VB2_BUF_STATE_QUEUED);
>  		}
>  		/* Must be zero now */
>  		WARN_ON(atomic_read(&q->owned_by_drv_count));
> @@ -1794,16 +1832,18 @@ static int vb2_start_streaming(struct vb2_queue *q)
>  static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  {
>  	int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  
>  	if (ret)
>  		return ret;
>  
>  	vb = q->bufs[b->index];
> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  
> -	switch (vb->vb2.state) {
> +	switch (vb->state) {
>  	case VB2_BUF_STATE_DEQUEUED:
> -		ret = __buf_prepare(vb, b);
> +		ret = __buf_prepare(cb, b);
>  		if (ret)
>  			return ret;
>  		break;
> @@ -1813,7 +1853,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  		dprintk(1, "buffer still being prepared\n");
>  		return -EINVAL;
>  	default:
> -		dprintk(1, "invalid buffer state %d\n", vb->vb2.state);
> +		dprintk(1, "invalid buffer state %d\n", vb->state);
>  		return -EINVAL;
>  	}
>  
> @@ -1821,10 +1861,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  	 * Add to the queued buffers list, a buffer will stay on it until
>  	 * dequeued in dqbuf.
>  	 */
> -	list_add_tail(&vb->vb2.queued_entry, &q->queued_list);
> +	list_add_tail(&vb->queued_entry, &q->queued_list);
>  	q->queued_count++;
>  	q->waiting_for_buffers = false;
> -	vb->vb2.state = VB2_BUF_STATE_QUEUED;
> +	vb->state = VB2_BUF_STATE_QUEUED;
>  	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
>  		/*
>  		 * For output buffers copy the timestamp if needed,
> @@ -1832,10 +1872,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  		 */
>  		if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
>  		    V4L2_BUF_FLAG_TIMESTAMP_COPY)
> -			vb->v4l2_buf.timestamp = b->timestamp;
> -		vb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
> +			cb->v4l2_buf.timestamp = b->timestamp;
> +		cb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
>  		if (b->flags & V4L2_BUF_FLAG_TIMECODE)
> -			vb->v4l2_buf.timecode = b->timecode;
> +			cb->v4l2_buf.timecode = b->timecode;
>  	}
>  
>  	/*
> @@ -1843,10 +1883,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  	 * If not, the buffer will be given to driver on next streamon.
>  	 */
>  	if (q->start_streaming_called)
> -		__enqueue_in_driver(&vb->vb2);
> +		__enqueue_in_driver(vb);
>  
>  	/* Fill buffer information for the userspace */
> -	__fill_v4l2_buffer(vb, b);
> +	__fill_v4l2_buffer(cb, b);
>  
>  	/*
>  	 * If streamon has been called, and we haven't yet called
> @@ -1861,7 +1901,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>  			return ret;
>  	}
>  
> -	dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index);
> +	dprintk(1, "qbuf of buffer %d succeeded\n", cb->v4l2_buf.index);
>  	return 0;
>  }
>  
> @@ -1969,12 +2009,12 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
>   *
>   * Will sleep if required for nonblocking == false.
>   */
> -static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
> +static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **cb,
>  				struct v4l2_buffer *b, int nonblocking)
>  {
>  	unsigned long flags;
>  	int ret;
> -	struct vb2_buffer *vb2 = NULL;
> +	struct vb2_buffer *vb = NULL;
>  
>  	/*
>  	 * Wait for at least one buffer to become available on the done_list.
> @@ -1988,15 +2028,15 @@ static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
>  	 * is not empty, so no need for another list_empty(done_list) check.
>  	 */
>  	spin_lock_irqsave(&q->done_lock, flags);
> -	vb2 = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
> -	*vb = container_of(vb2, struct vb2_v4l2_buffer, vb2); 
> +	vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
> +	*cb = container_of(vb, struct vb2_v4l2_buffer, vb2); 
>  	/*
>  	 * Only remove the buffer from done_list if v4l2_buffer can handle all
>  	 * the planes.
>  	 */
> -	ret = __verify_planes_array(*vb, b);
> +	ret = __verify_planes_array(*cb, b);
>  	if (!ret)
> -		list_del(&(*vb)->vb2.done_entry);
> +		list_del(&vb->done_entry);
>  	spin_unlock_irqrestore(&q->done_lock, flags);
>  
>  	return ret;
> @@ -2027,41 +2067,45 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
>  /**
>   * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
>   */
> -static void __vb2_dqbuf(struct vb2_v4l2_buffer *vb)
> +static void __vb2_dqbuf(struct vb2_v4l2_buffer *cb)
>  {
> -	struct vb2_queue *q = vb->vb2.vb2_queue;
> +	struct vb2_buffer *vb = &cb->vb2;
> +	struct vb2_queue *q = vb->vb2_queue;
>  	unsigned int i;
>  
>  	/* nothing to do if the buffer is already dequeued */
> -	if (vb->vb2.state == VB2_BUF_STATE_DEQUEUED)
> +	if (vb->state == VB2_BUF_STATE_DEQUEUED)
>  		return;
>  
> -	vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
> +	vb->state = VB2_BUF_STATE_DEQUEUED;
>  
>  	/* unmap DMABUF buffer */
>  	if (q->memory == V4L2_MEMORY_DMABUF)
> -		for (i = 0; i < vb->vb2.num_planes; ++i) {
> -			if (!vb->vb2.planes[i].dbuf_mapped)
> +		for (i = 0; i < vb->num_planes; ++i) {
> +			if (!vb->planes[i].dbuf_mapped)
>  				continue;
> -			call_void_memop(vb, unmap_dmabuf, vb->vb2.planes[i].mem_priv);
> -			vb->vb2.planes[i].dbuf_mapped = 0;
> +			call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
> +			vb->planes[i].dbuf_mapped = 0;
>  		}
>  }
>  
>  static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
>  {
> -	struct vb2_v4l2_buffer *vb = NULL;
> +	struct vb2_v4l2_buffer *cb = NULL;
> +	struct vb2_buffer *vb = NULL;
>  	int ret;
>  
>  	if (b->type != q->type) {
>  		dprintk(1, "invalid buffer type\n");
>  		return -EINVAL;
>  	}
> -	ret = __vb2_get_done_vb(q, &vb, b, nonblocking);
> +	ret = __vb2_get_done_vb(q, &cb, b, nonblocking);
>  	if (ret < 0)
>  		return ret;
>  
> -	switch (vb->vb2.state) {
> +	vb = &cb->vb2;
> +
> +	switch (vb->state) {
>  	case VB2_BUF_STATE_DONE:
>  		dprintk(3, "returning done buffer\n");
>  		break;
> @@ -2076,15 +2120,15 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
>  	call_void_vb_qop(vb, buf_finish, vb);
>  
>  	/* Fill buffer information for the userspace */
> -	__fill_v4l2_buffer(vb, b);
> +	__fill_v4l2_buffer(cb, b);
>  	/* Remove from videobuf queue */
> -	list_del(&vb->vb2.queued_entry);
> +	list_del(&vb->queued_entry);
>  	q->queued_count--;
>  	/* go back to dequeued state */
> -	__vb2_dqbuf(vb);
> +	__vb2_dqbuf(cb);
>  
>  	dprintk(1, "dqbuf of buffer %d, with state %d\n",
> -			vb->v4l2_buf.index, vb->vb2.state);
> +			cb->v4l2_buf.index, vb->state);
>  
>  	return 0;
>  }
> @@ -2128,8 +2172,9 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
>   */
>  static void __vb2_queue_cancel(struct vb2_queue *q)
>  {
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	unsigned int i;
> -	struct vb2_v4l2_buffer *vb;
>  
>  	/*
>  	 * Tell driver to stop all transactions and release all queued
> @@ -2147,9 +2192,10 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
>  	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
>  		for (i = 0; i < q->num_buffers; ++i)
>  		{
> -			vb = (struct vb2_v4l2_buffer *)q->bufs[i];
> -			if (vb->vb2.state == VB2_BUF_STATE_ACTIVE)
> -				vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
> +			vb = q->bufs[i];
> +			cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
> +			if (vb->state == VB2_BUF_STATE_ACTIVE)
> +				vb2_buffer_done(cb, VB2_BUF_STATE_ERROR);
>  		}
>  		/* Must be zero now */
>  		WARN_ON(atomic_read(&q->owned_by_drv_count));
> @@ -2182,13 +2228,14 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
>  	 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
>  	 */
>  	for (i = 0; i < q->num_buffers; ++i) {
> -		struct vb2_v4l2_buffer *vb = q->bufs[i];
> +		struct vb2_buffer *vb = q->bufs[i];
> +		struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  
> -		if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
> -			vb->vb2.state = VB2_BUF_STATE_PREPARED;
> +		if (vb->state != VB2_BUF_STATE_DEQUEUED) {
> +			vb->state = VB2_BUF_STATE_PREPARED;
>  			call_void_vb_qop(vb, buf_finish, vb);
>  		}
> -		__vb2_dqbuf(vb);
> +		__vb2_dqbuf(cb);
>  	}
>  }
>  
> @@ -2333,7 +2380,8 @@ EXPORT_SYMBOL_GPL(vb2_streamoff);
>  static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
>  			unsigned int *_buffer, unsigned int *_plane)
>  {
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	unsigned int buffer, plane;
>  
>  	/*
> @@ -2343,9 +2391,10 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
>  	 */
>  	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
>  		vb = q->bufs[buffer];
> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  
> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
> -			if (vb->v4l2_planes[plane].m.mem_offset == off) {
> +		for (plane = 0; plane < vb->num_planes; ++plane) {
> +			if (cb->v4l2_planes[plane].m.mem_offset == off) {
>  				*_buffer = buffer;
>  				*_plane = plane;
>  				return 0;
> @@ -2367,7 +2416,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
>   */
>  int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
>  {
> -	struct vb2_v4l2_buffer *vb = NULL;
> +	struct vb2_buffer *vb = NULL;
>  	struct vb2_plane *vb_plane;
>  	int ret;
>  	struct dma_buf *dbuf;
> @@ -2399,7 +2448,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
>  
>  	vb = q->bufs[eb->index];
>  
> -	if (eb->plane >= vb->vb2.num_planes) {
> +	if (eb->plane >= vb->num_planes) {
>  		dprintk(1, "buffer plane out of range\n");
>  		return -EINVAL;
>  	}
> @@ -2409,7 +2458,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
>  		return -EBUSY;
>  	}
>  
> -	vb_plane = &vb->vb2.planes[eb->plane];
> +	vb_plane = &vb->planes[eb->plane];
>  
>  	dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE);
>  	if (IS_ERR_OR_NULL(dbuf)) {
> @@ -2456,7 +2505,8 @@ EXPORT_SYMBOL_GPL(vb2_expbuf);
>  int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>  {
>  	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	unsigned int buffer = 0, plane = 0;
>  	int ret;
>  	unsigned long length;
> @@ -2497,13 +2547,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>  		return ret;
>  
>  	vb = q->bufs[buffer];
> -
> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  	/*
>  	 * MMAP requires page_aligned buffers.
>  	 * The buffer length was page_aligned at __vb2_buf_mem_alloc(),
>  	 * so, we need to do the same here.
>  	 */
> -	length = PAGE_ALIGN(vb->v4l2_planes[plane].length);
> +	length = PAGE_ALIGN(cb->v4l2_planes[plane].length);
>  	if (length < (vma->vm_end - vma->vm_start)) {
>  		dprintk(1,
>  			"MMAP invalid, as it would overflow buffer length\n");
> @@ -2511,7 +2561,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>  	}
>  
>  	mutex_lock(&q->mmap_lock);
> -	ret = call_memop(vb, mmap, vb->vb2.planes[plane].mem_priv, vma);
> +	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
>  	mutex_unlock(&q->mmap_lock);
>  	if (ret)
>  		return ret;
> @@ -2528,8 +2578,9 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
>  				    unsigned long pgoff,
>  				    unsigned long flags)
>  {
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  	unsigned long off = pgoff << PAGE_SHIFT;
> -	struct vb2_v4l2_buffer *vb;
>  	unsigned int buffer, plane;
>  	void *vaddr;
>  	int ret;
> @@ -2547,8 +2598,9 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
>  		return ret;
>  
>  	vb = q->bufs[buffer];
> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  
> -	vaddr = vb2_plane_vaddr(vb, plane);
> +	vaddr = vb2_plane_vaddr(cb, plane);
>  	return vaddr ? (unsigned long)vaddr : -EINVAL;
>  }
>  EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
> @@ -2784,7 +2836,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>  	struct vb2_fileio_data *fileio;
>  	int i, ret;
>  	unsigned int count = 0;
> -	struct vb2_v4l2_buffer *vb;
> +	struct vb2_v4l2_buffer *cb;
> +	struct vb2_buffer *vb;
>  
>  	/*
>  	 * Sanity check
> @@ -2835,8 +2888,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>  	 * Check if plane_count is correct
>  	 * (multiplane buffers are not supported).
>  	 */
> -	vb = (struct vb2_v4l2_buffer *)q->bufs[0];
> -	if (vb->vb2.num_planes != 1) {
> +	vb = q->bufs[0];
> +	if (vb->num_planes != 1) {
>  		ret = -EBUSY;
>  		goto err_reqbufs;
>  	}
> @@ -2845,12 +2898,13 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>  	 * Get kernel address of each buffer.
>  	 */
>  	for (i = 0; i < q->num_buffers; i++) {
> -		fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
> +		cb = container_of(q->bufs[i], struct vb2_v4l2_buffer, vb2);
> +		fileio->bufs[i].vaddr = vb2_plane_vaddr(cb, 0);
>  		if (fileio->bufs[i].vaddr == NULL) {
>  			ret = -EINVAL;
>  			goto err_reqbufs;
>  		}
> -		fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
> +		fileio->bufs[i].size = vb2_plane_size(cb, 0);
>  	}
>  
>  	/*
> @@ -2937,6 +2991,7 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
>  static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
>  		loff_t *ppos, int nonblock, int read)
>  {
> +	struct vb2_v4l2_buffer *cb;
>  	struct vb2_fileio_data *fileio;
>  	struct vb2_fileio_buf *buf;
>  	bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
> @@ -2996,10 +3051,11 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
>  		/*
>  		 * Get number of bytes filled by the driver
>  		 */
> +		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
>  		buf->pos = 0;
>  		buf->queued = 0;
> -		buf->size = read ? vb2_get_plane_payload(q->bufs[index], 0)
> -				 : vb2_plane_size(q->bufs[index], 0);
> +		buf->size = read ? vb2_get_plane_payload(cb, 0)
> +				 : vb2_plane_size(cb, 0);
>  		/* Compensate for data_offset on read in the multiplanar case. */
>  		if (is_multiplanar && read &&
>  		    fileio->b.m.planes[0].data_offset < buf->size) {
> @@ -3076,9 +3132,10 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
>  		/*
>  		 * Buffer has been queued, update the status
>  		 */
> +		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
>  		buf->pos = 0;
>  		buf->queued = 1;
> -		buf->size = vb2_plane_size(q->bufs[index], 0);
> +		buf->size = vb2_plane_size(cb, 0);
>  		fileio->q_count += 1;
>  		/*
>  		 * If we are queuing up buffers for the first time, then
> @@ -3146,7 +3203,8 @@ static int vb2_thread(void *data)
>  	set_freezable();
>  
>  	for (;;) {
> -		struct vb2_v4l2_buffer *vb;
> +		struct vb2_v4l2_buffer *cb;
> +		struct vb2_buffer *vb;
>  
>  		/*
>  		 * Call vb2_dqbuf to get buffer back.
> @@ -3169,8 +3227,9 @@ static int vb2_thread(void *data)
>  		try_to_freeze();
>  
>  		vb = q->bufs[fileio->b.index];
> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>  		if (!(fileio->b.flags & V4L2_BUF_FLAG_ERROR))
> -			if (threadio->fnc(vb, threadio->priv))
> +			if (threadio->fnc(cb, threadio->priv))
>  				break;
>  		call_void_qop(q, wait_finish, q);
>  		if (set_timestamp)

> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index 3b5df66..24c229d 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -227,27 +227,6 @@ struct vb2_buffer {
>  };
>  
>  /**
> - * struct vb2_v4l2_buffer - represents a video buffer for v4l2
> - * @vb2_buf:		common video buffer
> - * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
> - *			be read by the driver and relevant entries can be
> - *			changed by the driver in case of CAPTURE types
> - *			(such as timestamp)
> - * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
> - *			be read by the driver and relevant entries can be
> - *			changed by the driver in case of CAPTURE types
> - *			(such as bytesused); NOTE that even for single-planar
> - *			types, the v4l2_planes[0] struct should be used
> - *			instead of v4l2_buf for filling bytesused - drivers
> - *			should use the vb2_set_plane_payload() function for that
> - */
> -struct vb2_v4l2_buffer {
> -	struct vb2_buffer	vb2;
> -	struct v4l2_buffer	v4l2_buf;
> -	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
> -};
> -
> -/**
>   * struct vb2_ops - driver-specific callbacks
>   *
>   * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
> @@ -327,26 +306,24 @@ struct vb2_v4l2_buffer {
>   *			pre-queued buffers before calling STREAMON.
>   */
>  struct vb2_ops {
> -	int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
> +	int (*queue_setup)(struct vb2_queue *q, void *fmt,
>  			   unsigned int *num_buffers, unsigned int *num_planes,
>  			   unsigned int sizes[], void *alloc_ctxs[]);

Better to rename "fmt" here to "priv", to indicate that the usage of
this field is specific to the VB2-variant.

>  
>  	void (*wait_prepare)(struct vb2_queue *q);
>  	void (*wait_finish)(struct vb2_queue *q);
>  
> -	int (*buf_init)(struct vb2_v4l2_buffer *vb);
> -	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
> -	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
> -	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
> +	int (*buf_init)(struct vb2_buffer *vb);
> +	int (*buf_prepare)(struct vb2_buffer *vb);
> +	void (*buf_finish)(struct vb2_buffer *vb);
> +	void (*buf_cleanup)(struct vb2_buffer *vb);
>  
>  	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
>  	void (*stop_streaming)(struct vb2_queue *q);
>  
> -	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
> +	void (*buf_queue)(struct vb2_buffer *vb);
>  };
>  
> -struct v4l2_fh;
> -
>  /**
>   * struct vb2_queue - a videobuf queue
>   *
> @@ -400,7 +377,7 @@ struct v4l2_fh;
>   * @threadio:	thread io internal data, used only if thread is active
>   */
>  struct vb2_queue {
> -	enum v4l2_buf_type		type;
> +	unsigned int			type;
>  	unsigned int			io_modes;
>  	unsigned int			io_flags;
>  	struct mutex			*lock;
> @@ -416,8 +393,8 @@ struct vb2_queue {
>  
>  /* private: internal use only */
>  	struct mutex			mmap_lock;
> -	enum v4l2_memory		memory;
> -	void					*bufs[VIDEO_MAX_FRAME];
> +	unsigned int			memory;

> +	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];

OK. IMHO, this change (struct vb2_buffer) should be part of
the first patch.

>  	unsigned int			num_buffers;
>  
>  	struct list_head		queued_list;
> @@ -451,212 +428,4 @@ struct vb2_queue {
>  	u32				cnt_stop_streaming;
>  #endif
>  };
> -
> -void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
> -void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
> -
> -void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
> -void vb2_discard_done(struct vb2_queue *q);
> -int vb2_wait_for_all_buffers(struct vb2_queue *q);
> -
> -int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
> -int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
> -
> -int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create);
> -int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
> -
> -int __must_check vb2_queue_init(struct vb2_queue *q);
> -
> -void vb2_queue_release(struct vb2_queue *q);
> -void vb2_queue_error(struct vb2_queue *q);
> -
> -int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
> -int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
> -int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
> -
> -int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
> -int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
> -
> -int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
> -#ifndef CONFIG_MMU
> -unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
> -				    unsigned long addr,
> -				    unsigned long len,
> -				    unsigned long pgoff,
> -				    unsigned long flags);
> -#endif
> -unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
> -size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
> -		loff_t *ppos, int nonblock);
> -size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
> -		loff_t *ppos, int nonblock);
> -/**
> - * vb2_thread_fnc - callback function for use with vb2_thread
> - *
> - * This is called whenever a buffer is dequeued in the thread.
> - */
> -typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
> -
> -/**
> - * vb2_thread_start() - start a thread for the given queue.
> - * @q:		videobuf queue
> - * @fnc:	callback function
> - * @priv:	priv pointer passed to the callback function
> - * @thread_name:the name of the thread. This will be prefixed with "vb2-".
> - *
> - * This starts a thread that will queue and dequeue until an error occurs
> - * or @vb2_thread_stop is called.
> - *
> - * This function should not be used for anything else but the videobuf2-dvb
> - * support. If you think you have another good use-case for this, then please
> - * contact the linux-media mailinglist first.
> - */
> -int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
> -		     const char *thread_name);
> -
> -/**
> - * vb2_thread_stop() - stop the thread for the given queue.
> - * @q:		videobuf queue
> - */
> -int vb2_thread_stop(struct vb2_queue *q);
> -
> -/**
> - * vb2_is_streaming() - return streaming status of the queue
> - * @q:		videobuf queue
> - */
> -static inline bool vb2_is_streaming(struct vb2_queue *q)
> -{
> -	return q->streaming;
> -}
> -
> -/**
> - * vb2_fileio_is_active() - return true if fileio is active.
> - * @q:		videobuf queue
> - *
> - * This returns true if read() or write() is used to stream the data
> - * as opposed to stream I/O. This is almost never an important distinction,
> - * except in rare cases. One such case is that using read() or write() to
> - * stream a format using V4L2_FIELD_ALTERNATE is not allowed since there
> - * is no way you can pass the field information of each buffer to/from
> - * userspace. A driver that supports this field format should check for
> - * this in the queue_setup op and reject it if this function returns true.
> - */
> -static inline bool vb2_fileio_is_active(struct vb2_queue *q)
> -{
> -	return q->fileio;
> -}
> -
> -/**
> - * vb2_is_busy() - return busy status of the queue
> - * @q:		videobuf queue
> - *
> - * This function checks if queue has any buffers allocated.
> - */
> -static inline bool vb2_is_busy(struct vb2_queue *q)
> -{
> -	return (q->num_buffers > 0);
> -}
> -
> -/**
> - * vb2_get_drv_priv() - return driver private data associated with the queue
> - * @q:		videobuf queue
> - */
> -static inline void *vb2_get_drv_priv(struct vb2_queue *q)
> -{
> -	return q->drv_priv;
> -}
> -
> -/**
> - * vb2_set_plane_payload() - set bytesused for the plane plane_no
> - * @vb:		buffer for which plane payload should be set
> - * @plane_no:	plane number for which payload should be set
> - * @size:	payload in bytes
> - */
> -static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
> -				 unsigned int plane_no, unsigned long size)
> -{
> -	if (plane_no < vb->vb2.num_planes)
> -		vb->v4l2_planes[plane_no].bytesused = size;
> -}
> -
> -/**
> - * vb2_get_plane_payload() - get bytesused for the plane plane_no
> - * @vb:		buffer for which plane payload should be set
> - * @plane_no:	plane number for which payload should be set
> - * @size:	payload in bytes
> - */
> -static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
> -				 unsigned int plane_no)
> -{
> -	if (plane_no < vb->vb2.num_planes)
> -		return vb->v4l2_planes[plane_no].bytesused;
> -	return 0;
> -}
> -
> -/**
> - * vb2_plane_size() - return plane size in bytes
> - * @vb:		buffer for which plane size should be returned
> - * @plane_no:	plane number for which size should be returned
> - */
> -static inline unsigned long
> -vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
> -{
> -	if (plane_no < vb->vb2.num_planes)
> -		return vb->v4l2_planes[plane_no].length;
> -	return 0;
> -}
> -
> -/**
> - * vb2_start_streaming_called() - return streaming status of driver
> - * @q:		videobuf queue
> - */
> -static inline bool vb2_start_streaming_called(struct vb2_queue *q)
> -{
> -	return q->start_streaming_called;
> -}
> -
> -/*
> - * The following functions are not part of the vb2 core API, but are simple
> - * helper functions that you can use in your struct v4l2_file_operations,
> - * struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock
> - * or video_device->lock is set, and they will set and test vb2_queue->owner
> - * to check if the calling filehandle is permitted to do the queuing operation.
> - */
> -
> -/* struct v4l2_ioctl_ops helpers */
> -
> -int vb2_ioctl_reqbufs(struct file *file, void *priv,
> -			  struct v4l2_requestbuffers *p);
> -int vb2_ioctl_create_bufs(struct file *file, void *priv,
> -			  struct v4l2_create_buffers *p);
> -int vb2_ioctl_prepare_buf(struct file *file, void *priv,
> -			  struct v4l2_buffer *p);
> -int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
> -int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
> -int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
> -int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
> -int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
> -int vb2_ioctl_expbuf(struct file *file, void *priv,
> -	struct v4l2_exportbuffer *p);
> -
> -/* struct v4l2_file_operations helpers */
> -
> -int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
> -int vb2_fop_release(struct file *file);
> -int _vb2_fop_release(struct file *file, struct mutex *lock);
> -ssize_t vb2_fop_write(struct file *file, const char __user *buf,
> -		size_t count, loff_t *ppos);
> -ssize_t vb2_fop_read(struct file *file, char __user *buf,
> -		size_t count, loff_t *ppos);
> -unsigned int vb2_fop_poll(struct file *file, poll_table *wait);
> -#ifndef CONFIG_MMU
> -unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
> -		unsigned long len, unsigned long pgoff, unsigned long flags);
> -#endif
> -
> -/* struct vb2_ops helpers, only use if vq->lock is non-NULL. */
> -
> -void vb2_ops_wait_prepare(struct vb2_queue *vq);
> -void vb2_ops_wait_finish(struct vb2_queue *vq);
> -
>  #endif /* _MEDIA_VIDEOBUF2_CORE_H */
> diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h
> index 3de9111..c2e3476 100644
> --- a/include/media/videobuf2-dma-contig.h
> +++ b/include/media/videobuf2-dma-contig.h
> @@ -17,9 +17,9 @@
>  #include <linux/dma-mapping.h>
>  
>  static inline dma_addr_t
> -vb2_dma_contig_plane_dma_addr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
> +vb2_dma_contig_plane_dma_addr(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>  {
> -	dma_addr_t *addr = vb2_plane_cookie(vb, plane_no);
> +	dma_addr_t *addr = vb2_plane_cookie(cb, plane_no);
>  
>  	return *addr;
>  }

Just renaming. As said before, the best is to put those renames on
a separate patch that would be fixing the namespace.

> diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
> index 80b08cb..cd2b6b9 100644
> --- a/include/media/videobuf2-v4l2.h
> +++ b/include/media/videobuf2-v4l2.h
> @@ -17,214 +17,7 @@
>  #include <linux/poll.h>
>  #include <linux/videodev2.h>
>  #include <linux/dma-buf.h>
> -
> -struct vb2_alloc_ctx;
> -struct vb2_fileio_data;
> -struct vb2_threadio_data;
> -
> -/**
> - * struct vb2_mem_ops - memory handling/memory allocator operations
> - * @alloc:	allocate video memory and, optionally, allocator private data,
> - *		return NULL on failure or a pointer to allocator private,
> - *		per-buffer data on success; the returned private structure
> - *		will then be passed as buf_priv argument to other ops in this
> - *		structure. Additional gfp_flags to use when allocating the
> - *		are also passed to this operation. These flags are from the
> - *		gfp_flags field of vb2_queue.
> - * @put:	inform the allocator that the buffer will no longer be used;
> - *		usually will result in the allocator freeing the buffer (if
> - *		no other users of this buffer are present); the buf_priv
> - *		argument is the allocator private per-buffer structure
> - *		previously returned from the alloc callback.
> - * @get_userptr: acquire userspace memory for a hardware operation; used for
> - *		 USERPTR memory types; vaddr is the address passed to the
> - *		 videobuf layer when queuing a video buffer of USERPTR type;
> - *		 should return an allocator private per-buffer structure
> - *		 associated with the buffer on success, NULL on failure;
> - *		 the returned private structure will then be passed as buf_priv
> - *		 argument to other ops in this structure.
> - * @put_userptr: inform the allocator that a USERPTR buffer will no longer
> - *		 be used.
> - * @attach_dmabuf: attach a shared struct dma_buf for a hardware operation;
> - *		   used for DMABUF memory types; alloc_ctx is the alloc context
> - *		   dbuf is the shared dma_buf; returns NULL on failure;
> - *		   allocator private per-buffer structure on success;
> - *		   this needs to be used for further accesses to the buffer.
> - * @detach_dmabuf: inform the exporter of the buffer that the current DMABUF
> - *		   buffer is no longer used; the buf_priv argument is the
> - *		   allocator private per-buffer structure previously returned
> - *		   from the attach_dmabuf callback.
> - * @map_dmabuf: request for access to the dmabuf from allocator; the allocator
> - *		of dmabuf is informed that this driver is going to use the
> - *		dmabuf.
> - * @unmap_dmabuf: releases access control to the dmabuf - allocator is notified
> - *		  that this driver is done using the dmabuf for now.
> - * @prepare:	called every time the buffer is passed from userspace to the
> - *		driver, useful for cache synchronisation, optional.
> - * @finish:	called every time the buffer is passed back from the driver
> - *		to the userspace, also optional.
> - * @vaddr:	return a kernel virtual address to a given memory buffer
> - *		associated with the passed private structure or NULL if no
> - *		such mapping exists.
> - * @cookie:	return allocator specific cookie for a given memory buffer
> - *		associated with the passed private structure or NULL if not
> - *		available.
> - * @num_users:	return the current number of users of a memory buffer;
> - *		return 1 if the videobuf layer (or actually the driver using
> - *		it) is the only user.
> - * @mmap:	setup a userspace mapping for a given memory buffer under
> - *		the provided virtual memory region.
> - *
> - * Required ops for USERPTR types: get_userptr, put_userptr.
> - * Required ops for MMAP types: alloc, put, num_users, mmap.
> - * Required ops for read/write access types: alloc, put, num_users, vaddr.
> - * Required ops for DMABUF types: attach_dmabuf, detach_dmabuf, map_dmabuf,
> - *				  unmap_dmabuf.
> - */
> -struct vb2_mem_ops {
> -	void		*(*alloc)(void *alloc_ctx, unsigned long size,
> -				  enum dma_data_direction dma_dir,
> -				  gfp_t gfp_flags);
> -	void		(*put)(void *buf_priv);
> -	struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags);
> -
> -	void		*(*get_userptr)(void *alloc_ctx, unsigned long vaddr,
> -					unsigned long size,
> -					enum dma_data_direction dma_dir);
> -	void		(*put_userptr)(void *buf_priv);
> -
> -	void		(*prepare)(void *buf_priv);
> -	void		(*finish)(void *buf_priv);
> -
> -	void		*(*attach_dmabuf)(void *alloc_ctx, struct dma_buf *dbuf,
> -					  unsigned long size,
> -					  enum dma_data_direction dma_dir);
> -	void		(*detach_dmabuf)(void *buf_priv);
> -	int		(*map_dmabuf)(void *buf_priv);
> -	void		(*unmap_dmabuf)(void *buf_priv);
> -
> -	void		*(*vaddr)(void *buf_priv);
> -	void		*(*cookie)(void *buf_priv);
> -
> -	unsigned int	(*num_users)(void *buf_priv);
> -
> -	int		(*mmap)(void *buf_priv, struct vm_area_struct *vma);
> -};
> -
> -struct vb2_plane {
> -	void			*mem_priv;
> -	struct dma_buf		*dbuf;
> -	unsigned int		dbuf_mapped;
> -};
> -
> -/**
> - * enum vb2_io_modes - queue access methods
> - * @VB2_MMAP:		driver supports MMAP with streaming API
> - * @VB2_USERPTR:	driver supports USERPTR with streaming API
> - * @VB2_READ:		driver supports read() style access
> - * @VB2_WRITE:		driver supports write() style access
> - * @VB2_DMABUF:		driver supports DMABUF with streaming API
> - */
> -enum vb2_io_modes {
> -	VB2_MMAP	= (1 << 0),
> -	VB2_USERPTR	= (1 << 1),
> -	VB2_READ	= (1 << 2),
> -	VB2_WRITE	= (1 << 3),
> -	VB2_DMABUF	= (1 << 4),
> -};
> -
> -/**
> - * enum vb2_fileio_flags - flags for selecting a mode of the file io emulator,
> - * by default the 'streaming' style is used by the file io emulator
> - * @VB2_FILEIO_READ_ONCE:	report EOF after reading the first buffer
> - * @VB2_FILEIO_WRITE_IMMEDIATELY:	queue buffer after each write() call
> - */
> -enum vb2_fileio_flags {
> -	VB2_FILEIO_READ_ONCE		= (1 << 0),
> -	VB2_FILEIO_WRITE_IMMEDIATELY	= (1 << 1),
> -};
> -
> -/**
> - * enum vb2_buffer_state - current video buffer state
> - * @VB2_BUF_STATE_DEQUEUED:	buffer under userspace control
> - * @VB2_BUF_STATE_PREPARING:	buffer is being prepared in videobuf
> - * @VB2_BUF_STATE_PREPARED:	buffer prepared in videobuf and by the driver
> - * @VB2_BUF_STATE_QUEUED:	buffer queued in videobuf, but not in driver
> - * @VB2_BUF_STATE_ACTIVE:	buffer queued in driver and possibly used
> - *				in a hardware operation
> - * @VB2_BUF_STATE_DONE:		buffer returned from driver to videobuf, but
> - *				not yet dequeued to userspace
> - * @VB2_BUF_STATE_ERROR:	same as above, but the operation on the buffer
> - *				has ended with an error, which will be reported
> - *				to the userspace when it is dequeued
> - */
> -enum vb2_buffer_state {
> -	VB2_BUF_STATE_DEQUEUED,
> -	VB2_BUF_STATE_PREPARING,
> -	VB2_BUF_STATE_PREPARED,
> -	VB2_BUF_STATE_QUEUED,
> -	VB2_BUF_STATE_ACTIVE,
> -	VB2_BUF_STATE_DONE,
> -	VB2_BUF_STATE_ERROR,
> -};
> -
> -struct vb2_queue;
> -
> -/**
> - * struct vb2_buffer - represents a common video buffer
> - * @vb2_queue:		the queue to which this driver belongs
> - * @num_planes:		number of planes in the buffer
> - *			on an internal driver queue
> - * @state:		current buffer state; do not change
> - * @queued_entry:	entry on the queued buffers list, which holds all
> - *			buffers queued from userspace
> - * @done_entry:		entry on the list that stores all buffers ready to
> - *			be dequeued to userspace
> - * @planes:		private per-plane information; do not change
> - */
> -struct vb2_buffer {
> -	struct vb2_queue	*vb2_queue;
> -	unsigned int		num_planes;
> -
> -/* Private: internal use only */
> -	enum vb2_buffer_state	state;
> -
> -	struct list_head	queued_entry;
> -	struct list_head	done_entry;
> -
> -	struct vb2_plane	planes[VIDEO_MAX_PLANES];
> -
> -#ifdef CONFIG_VIDEO_ADV_DEBUG
> -	/*
> -	 * Counters for how often these buffer-related ops are
> -	 * called. Used to check for unbalanced ops.
> -	 */
> -	u32		cnt_mem_alloc;
> -	u32		cnt_mem_put;
> -	u32		cnt_mem_get_dmabuf;
> -	u32		cnt_mem_get_userptr;
> -	u32		cnt_mem_put_userptr;
> -	u32		cnt_mem_prepare;
> -	u32		cnt_mem_finish;
> -	u32		cnt_mem_attach_dmabuf;
> -	u32		cnt_mem_detach_dmabuf;
> -	u32		cnt_mem_map_dmabuf;
> -	u32		cnt_mem_unmap_dmabuf;
> -	u32		cnt_mem_vaddr;
> -	u32		cnt_mem_cookie;
> -	u32		cnt_mem_num_users;
> -	u32		cnt_mem_mmap;
> -
> -	u32		cnt_buf_init;
> -	u32		cnt_buf_prepare;
> -	u32		cnt_buf_finish;
> -	u32		cnt_buf_cleanup;
> -	u32		cnt_buf_queue;
> -
> -	/* This counts the number of calls to vb2_buffer_done() */
> -	u32		cnt_buf_done;
> -#endif
> -};
> +#include <media/videobuf2-core.h>
>  
>  /**
>   * struct vb2_v4l2_buffer - represents a video buffer for v4l2
> @@ -247,215 +40,10 @@ struct vb2_v4l2_buffer {
>  	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
>  };
>  
> -/**
> - * struct vb2_ops - driver-specific callbacks
> - *
> - * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
> - *			handlers before memory allocation, or, if
> - *			*num_planes != 0, after the allocation to verify a
> - *			smaller number of buffers. Driver should return
> - *			the required number of buffers in *num_buffers, the
> - *			required number of planes per buffer in *num_planes; the
> - *			size of each plane should be set in the sizes[] array
> - *			and optional per-plane allocator specific context in the
> - *			alloc_ctxs[] array. When called from VIDIOC_REQBUFS,
> - *			fmt == NULL, the driver has to use the currently
> - *			configured format and *num_buffers is the total number
> - *			of buffers, that are being allocated. When called from
> - *			VIDIOC_CREATE_BUFS, fmt != NULL and it describes the
> - *			target frame format (if the format isn't valid the
> - *			callback must return -EINVAL). In this case *num_buffers
> - *			are being allocated additionally to q->num_buffers.
> - * @wait_prepare:	release any locks taken while calling vb2 functions;
> - *			it is called before an ioctl needs to wait for a new
> - *			buffer to arrive; required to avoid a deadlock in
> - *			blocking access type.
> - * @wait_finish:	reacquire all locks released in the previous callback;
> - *			required to continue operation after sleeping while
> - *			waiting for a new buffer to arrive.
> - * @buf_init:		called once after allocating a buffer (in MMAP case)
> - *			or after acquiring a new USERPTR buffer; drivers may
> - *			perform additional buffer-related initialization;
> - *			initialization failure (return != 0) will prevent
> - *			queue setup from completing successfully; optional.
> - * @buf_prepare:	called every time the buffer is queued from userspace
> - *			and from the VIDIOC_PREPARE_BUF ioctl; drivers may
> - *			perform any initialization required before each
> - *			hardware operation in this callback; drivers can
> - *			access/modify the buffer here as it is still synced for
> - *			the CPU; drivers that support VIDIOC_CREATE_BUFS must
> - *			also validate the buffer size; if an error is returned,
> - *			the buffer will not be queued in driver; optional.
> - * @buf_finish:		called before every dequeue of the buffer back to
> - *			userspace; the buffer is synced for the CPU, so drivers
> - *			can access/modify the buffer contents; drivers may
> - *			perform any operations required before userspace
> - *			accesses the buffer; optional. The buffer state can be
> - *			one of the following: DONE and ERROR occur while
> - *			streaming is in progress, and the PREPARED state occurs
> - *			when the queue has been canceled and all pending
> - *			buffers are being returned to their default DEQUEUED
> - *			state. Typically you only have to do something if the
> - *			state is VB2_BUF_STATE_DONE, since in all other cases
> - *			the buffer contents will be ignored anyway.
> - * @buf_cleanup:	called once before the buffer is freed; drivers may
> - *			perform any additional cleanup; optional.
> - * @start_streaming:	called once to enter 'streaming' state; the driver may
> - *			receive buffers with @buf_queue callback before
> - *			@start_streaming is called; the driver gets the number
> - *			of already queued buffers in count parameter; driver
> - *			can return an error if hardware fails, in that case all
> - *			buffers that have been already given by the @buf_queue
> - *			callback are to be returned by the driver by calling
> - *			@vb2_buffer_done(VB2_BUF_STATE_QUEUED).
> - *			If you need a minimum number of buffers before you can
> - *			start streaming, then set @min_buffers_needed in the
> - *			vb2_queue structure. If that is non-zero then
> - *			start_streaming won't be called until at least that
> - *			many buffers have been queued up by userspace.
> - * @stop_streaming:	called when 'streaming' state must be disabled; driver
> - *			should stop any DMA transactions or wait until they
> - *			finish and give back all buffers it got from buf_queue()
> - *			callback by calling @vb2_buffer_done() with either
> - *			VB2_BUF_STATE_DONE or VB2_BUF_STATE_ERROR; may use
> - *			vb2_wait_for_all_buffers() function
> - * @buf_queue:		passes buffer vb to the driver; driver may start
> - *			hardware operation on this buffer; driver should give
> - *			the buffer back by calling vb2_buffer_done() function;
> - *			it is allways called after calling STREAMON ioctl;
> - *			might be called before start_streaming callback if user
> - *			pre-queued buffers before calling STREAMON.
> - */
> -struct vb2_ops {
> -	int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
> -			   unsigned int *num_buffers, unsigned int *num_planes,
> -			   unsigned int sizes[], void *alloc_ctxs[]);
> -
> -	void (*wait_prepare)(struct vb2_queue *q);
> -	void (*wait_finish)(struct vb2_queue *q);
> -
> -	int (*buf_init)(struct vb2_v4l2_buffer *vb);
> -	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
> -	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
> -	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
> -
> -	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
> -	void (*stop_streaming)(struct vb2_queue *q);
> -
> -	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
> -};
> -
> -struct v4l2_fh;
> -
> -/**
> - * struct vb2_queue - a videobuf queue
> - *
> - * @type:	queue type (see V4L2_BUF_TYPE_* in linux/videodev2.h
> - * @io_modes:	supported io methods (see vb2_io_modes enum)
> - * @io_flags:	additional io flags (see vb2_fileio_flags enum)
> - * @lock:	pointer to a mutex that protects the vb2_queue struct. The
> - *		driver can set this to a mutex to let the v4l2 core serialize
> - *		the queuing ioctls. If the driver wants to handle locking
> - *		itself, then this should be set to NULL. This lock is not used
> - *		by the videobuf2 core API.
> - * @owner:	The filehandle that 'owns' the buffers, i.e. the filehandle
> - *		that called reqbufs, create_buffers or started fileio.
> - *		This field is not used by the videobuf2 core API, but it allows
> - *		drivers to easily associate an owner filehandle with the queue.
> - * @ops:	driver-specific callbacks
> - * @mem_ops:	memory allocator specific callbacks
> - * @drv_priv:	driver private data
> - * @buf_struct_size: size of the driver-specific buffer structure;
> - *		"0" indicates the driver doesn't want to use a custom buffer
> - *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
> - * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
> - *		V4L2_BUF_FLAG_TSTAMP_SRC_*
> - * @gfp_flags:	additional gfp flags used when allocating the buffers.
> - *		Typically this is 0, but it may be e.g. GFP_DMA or __GFP_DMA32
> - *		to force the buffer allocation to a specific memory zone.
> - * @min_buffers_needed: the minimum number of buffers needed before
> - *		start_streaming() can be called. Used when a DMA engine
> - *		cannot be started unless at least this number of buffers
> - *		have been queued into the driver.
> - *
> - * @mmap_lock:	private mutex used when buffers are allocated/freed/mmapped
> - * @memory:	current memory type used
> - * @bufs:	videobuf buffer structures
> - * @num_buffers: number of allocated/used buffers
> - * @queued_list: list of buffers currently queued from userspace
> - * @queued_count: number of buffers queued and ready for streaming.
> - * @owned_by_drv_count: number of buffers owned by the driver
> - * @done_list:	list of buffers ready to be dequeued to userspace
> - * @done_lock:	lock to protect done_list list
> - * @done_wq:	waitqueue for processes waiting for buffers ready to be dequeued
> - * @alloc_ctx:	memory type/allocator-specific contexts for each plane
> - * @streaming:	current streaming state
> - * @start_streaming_called: start_streaming() was called successfully and we
> - *		started streaming.
> - * @error:	a fatal error occurred on the queue
> - * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for
> - *		buffers. Only set for capture queues if qbuf has not yet been
> - *		called since poll() needs to return POLLERR in that situation.
> - * @fileio:	file io emulator internal data, used only if emulator is active
> - * @threadio:	thread io internal data, used only if thread is active
> - */
> -struct vb2_queue {
> -	enum v4l2_buf_type		type;
> -	unsigned int			io_modes;
> -	unsigned int			io_flags;
> -	struct mutex			*lock;
> -	void					*owner;
> -
> -	const struct vb2_ops		*ops;
> -	const struct vb2_mem_ops	*mem_ops;
> -	void				*drv_priv;
> -	unsigned int			buf_struct_size;
> -	u32				timestamp_flags;
> -	gfp_t				gfp_flags;
> -	u32				min_buffers_needed;
> -
> -/* private: internal use only */
> -	struct mutex			mmap_lock;
> -	enum v4l2_memory		memory;
> -	void					*bufs[VIDEO_MAX_FRAME];
> -	unsigned int			num_buffers;
> -
> -	struct list_head		queued_list;
> -	unsigned int			queued_count;
> -
> -	atomic_t			owned_by_drv_count;
> -	struct list_head		done_list;
> -	spinlock_t			done_lock;
> -	wait_queue_head_t		done_wq;
> -
> -	void				*alloc_ctx[VIDEO_MAX_PLANES];
> -	unsigned int			plane_sizes[VIDEO_MAX_PLANES];
> -
> -	unsigned int			streaming:1;
> -	unsigned int			start_streaming_called:1;
> -	unsigned int			error:1;
> -	unsigned int			waiting_for_buffers:1;
> -
> -	struct vb2_fileio_data		*fileio;
> -	struct vb2_threadio_data	*threadio;
> -
> -#ifdef CONFIG_VIDEO_ADV_DEBUG
> -	/*
> -	 * Counters for how often these queue-related ops are
> -	 * called. Used to check for unbalanced ops.
> -	 */
> -	u32				cnt_queue_setup;
> -	u32				cnt_wait_prepare;
> -	u32				cnt_wait_finish;
> -	u32				cnt_start_streaming;
> -	u32				cnt_stop_streaming;
> -#endif
> -};
> -
> -void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
> -void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no);
> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no);
>  
> -void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
> +void vb2_buffer_done(struct vb2_v4l2_buffer *cb, enum vb2_buffer_state state);
>  void vb2_discard_done(struct vb2_queue *q);
>  int vb2_wait_for_all_buffers(struct vb2_queue *q);
>  
> @@ -495,7 +83,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
>   *
>   * This is called whenever a buffer is dequeued in the thread.
>   */
> -typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
> +typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *cb, void *priv);
>  
>  /**
>   * vb2_thread_start() - start a thread for the given queue.
> @@ -572,11 +160,11 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
>   * @plane_no:	plane number for which payload should be set
>   * @size:	payload in bytes
>   */
> -static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
> +static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *cb,
>  				 unsigned int plane_no, unsigned long size)
>  {
> -	if (plane_no < vb->vb2.num_planes)
> -		vb->v4l2_planes[plane_no].bytesused = size;
> +	if (plane_no < cb->vb2.num_planes)
> +		cb->v4l2_planes[plane_no].bytesused = size;
>  }
>  
>  /**
> @@ -585,11 +173,11 @@ static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>   * @plane_no:	plane number for which payload should be set
>   * @size:	payload in bytes
>   */
> -static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
> +static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *cb,
>  				 unsigned int plane_no)
>  {
> -	if (plane_no < vb->vb2.num_planes)
> -		return vb->v4l2_planes[plane_no].bytesused;
> +	if (plane_no < cb->vb2.num_planes)
> +		return cb->v4l2_planes[plane_no].bytesused;
>  	return 0;
>  }
>  
> @@ -599,10 +187,10 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>   * @plane_no:	plane number for which size should be returned
>   */
>  static inline unsigned long
> -vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
> +vb2_plane_size(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>  {
> -	if (plane_no < vb->vb2.num_planes)
> -		return vb->v4l2_planes[plane_no].length;
> +	if (plane_no < cb->vb2.num_planes)
> +		return cb->v4l2_planes[plane_no].length;
>  	return 0;
>  }
>  

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 0/3] Refactoring Videobuf2 for common use
  2015-06-12 10:51 ` Hans Verkuil
@ 2015-06-23  0:48   ` Junghak Sung
  0 siblings, 0 replies; 15+ messages in thread
From: Junghak Sung @ 2015-06-23  0:48 UTC (permalink / raw)
  To: Hans Verkuil, linux-media
  Cc: mchehab, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim


Hi Hans,

Thank you for your review.
I reply to your comments. See below.

Regards,
Junghak


On 06/12/2015 07:51 PM, Hans Verkuil wrote:
> Hi Junghak,
>
> On 06/08/2015 03:35 PM, Junghak Sung wrote:
>> Hello everybody,
>>
>> This patch series refactories exsiting Videobuf2, so that not only V4L2
>> but also other frameworks can use it to manage buffer and utilize
>> queue.
>>
>> I would separate existing Videobuf2-core framework into two parts - common
>> and v4l2-specific part. This work is as follows :
>>
>> 1. Separate existing vb2_buffer structure into common buffer and
>>     v4l2-specific parts by removing v4l2-specific members and
>>     embedding it into vb2_v4l2_buffer structure like this:
>>
>>      struct vb2_v4l2_buffer {
>>          struct vb2_buffer    vb2;
>>          struct v4l2_buffer   v4l2_buf;
>>          struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
>>      };
>>
>> 2. Abstract the v4l2-specific elements, and specify them when the device
>>     drives use them. For example, vb2_v4l2_buffer structure can be abstracted
>>     by vb2_buffer structure, and device drivers can get framework-specific
>>     object such as vb2_v4l2_buffer by using container_of().
>>
>> 3. Separate VB2-core framework into real VB2-core and v4l2-specific part.
>>     This means that it moves V4L2-specific parts of VB2-core to v4l2-specific
>>     part because current VB2-core framework has some codes dependent of V4L2.
>>     As a result, we will have two VB2 files - videobuf2-core.c and
>>     videobuf2-v4l2.c.
>>
>> Why do we try to make the VB2 framework to be common?
>>
>> As you may know, current DVB framework uses ringbuffer mechanism to demux
>> MPEG-2 TS data and pass it to userspace. However, this mechanism requires
>> extra memory copy because DVB framework provides only read() system call for
>> application - read() system call copies the kernel data to user-space buffer.
>>
>> So if we can use VB2 framework which supports streaming I/O and buffer
>> sharing mechanism, then we could enhance existing DVB framework by removing
>> the extra memory copy - with VB2 framework, application can access the kernel
>> data directly through mmap system call.
>>
>> This patch series is the first step for it.
>>
>> We have a plan for this work as follows:
>>
>> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2,
>>     and VB2-dvb. Of course, this change should not affect other v4l2-based
>>     device drivers. This patch series includes some parts of this step.
>>
>> 2. Add new APIs for DVB streaming I/O. These APIs will be implemented
>>     in VB2-dvb framework. So, we can remove unnecessary memory copy between
>>     kernel-space and user-space by using these new APIs.
>>     However, we leaves legacy interfaces as-is for backward compatibility.
>>
>> We are working on this project with Mauro and have a discussion with him
>> on IRC channel weekly. Nowaday, we are discussing more detailed DVB user
>> scenario for streaming I/O.
>>
>> The final goal of this project is to enhance current DVB framework.
>> The first mission is to achieve zero-copy functionality between kernel-space
>> and user-space with mmap system call. More missions are under consideration:
>> i.e., we could share the buffer not only between kernel-space and user-space
>> but also between devices - demux, hw video codec - by exporting a buffer
>> to dmabuf fd with VB2 framework.
>>
>> Any suggestions and comments are welcome.
> I've tried to review it, but in the current form it is too hard to do. It's not
> helped by the fact that patch 2 didn't make it to the mailinglist. It might
> be better to just split up such large patches and make a note that the pull
> request will combine the two (or more) patches into one.
I agree with your opinion that the patches should be rework to be
more easier to review. I will try to split up the patches and resend it.

> BTW, I fully agree with what you want to do, where I am having trouble is
> verifying that nothing breaks and in the details of the vb2 API changes.
>
> Can you make a new patch series that only shows the changes to the videobuf2
> sources and headers, so without all the driver changes? The driver changes
> are automatically checked by the compiler when you build the drivers, so I
> believe that that's correct (I hope :-) ).
>
> Also try to split it up in smaller pieces. I had the feeling that you combined
> multiple but otherwise independent changes in one patch. The vb2 framework is
> an important piece of code, and I want to be confident about the changes made.
>
> Regarding the split into core and v4l2 sources/headers: I've been thinking about
> this a bit more, and what would probably make reviewing easiest is if you start
> off with making a simple videobuf2-v4l2.h header that just includes core.h and
> slowly move the v4l2-specific parts from videobuf2-core.h to videobuf2-v4l2.h.
>
> And do the same with videobuf2-v4l2.c: start off with an empty source and move
> code from core.c to v4l2.c whenever a v4l2-specific part migrates.
That's a good point. I think I have made these patches too hastily.
As your comment, I will split the patch into two or more pieces.
The first is just renaming videobuf2-core.[ch] to videobuf2-v4l2.[ch].
> Another note: I noticed that the queue_setup op was changed so the v4l2_format
> argument became a void *. I do not think that that is the right approach since
> we lose strong typing.
>
> I wonder if v4l2-specific queue ops should be introduced. I'm not sure how that
> would work out, but I think we can look at that for the next round of patches.
OK, I will try to find out more reasonable way to make it commonly (not 
v4l2-specific)
without changing the v4l2-specivic queue ops.
> Regards,
>
> 	Hans
>
>> Best regards,
>> Junghak
>>
>> Junghak Sung (3):
>>    modify the vb2_buffer structure for common video buffer     and make
>>      struct vb2_v4l2_buffer
>>    move struct vb2_queue to common and apply the changes related with
>>      that     Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>>    make vb2-core part with not v4l2-specific elements
>>
>>   Documentation/video4linux/v4l2-pci-skeleton.c      |   16 +-
>>   drivers/media/dvb-frontends/rtl2832_sdr.c          |   13 +-
>>   drivers/media/pci/cx23885/cx23885-417.c            |   13 +-
>>   drivers/media/pci/cx23885/cx23885-core.c           |    4 +-
>>   drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
>>   drivers/media/pci/cx23885/cx23885-vbi.c            |   17 +-
>>   drivers/media/pci/cx23885/cx23885-video.c          |   19 +-
>>   drivers/media/pci/cx23885/cx23885.h                |    2 +-
>>   drivers/media/pci/cx25821/cx25821-video.c          |   20 +-
>>   drivers/media/pci/cx25821/cx25821.h                |    2 +-
>>   drivers/media/pci/cx88/cx88-blackbird.c            |   15 +-
>>   drivers/media/pci/cx88/cx88-core.c                 |    2 +-
>>   drivers/media/pci/cx88/cx88-dvb.c                  |   13 +-
>>   drivers/media/pci/cx88/cx88-mpeg.c                 |    2 +-
>>   drivers/media/pci/cx88/cx88-vbi.c                  |   17 +-
>>   drivers/media/pci/cx88/cx88-video.c                |   17 +-
>>   drivers/media/pci/cx88/cx88.h                      |    2 +-
>>   drivers/media/pci/saa7134/saa7134-core.c           |    4 +-
>>   drivers/media/pci/saa7134/saa7134-ts.c             |   28 +-
>>   drivers/media/pci/saa7134/saa7134-vbi.c            |   22 +-
>>   drivers/media/pci/saa7134/saa7134-video.c          |   17 +-
>>   drivers/media/pci/saa7134/saa7134.h                |    8 +-
>>   drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   19 +-
>>   drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   11 +-
>>   drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
>>   drivers/media/pci/sta2x11/sta2x11_vip.c            |   24 +-
>>   drivers/media/pci/tw68/tw68-video.c                |   20 +-
>>   drivers/media/pci/tw68/tw68.h                      |    2 +-
>>   drivers/media/platform/am437x/am437x-vpfe.c        |   33 +-
>>   drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
>>   drivers/media/platform/blackfin/bfin_capture.c     |   30 +-
>>   drivers/media/platform/coda/coda-bit.c             |   20 +-
>>   drivers/media/platform/coda/coda-common.c          |   28 +-
>>   drivers/media/platform/coda/coda-jpeg.c            |    2 +-
>>   drivers/media/platform/coda/coda.h                 |    6 +-
>>   drivers/media/platform/davinci/vpbe_display.c      |   25 +-
>>   drivers/media/platform/davinci/vpif_capture.c      |   30 +-
>>   drivers/media/platform/davinci/vpif_capture.h      |    2 +-
>>   drivers/media/platform/davinci/vpif_display.c      |   34 +-
>>   drivers/media/platform/davinci/vpif_display.h      |    6 +-
>>   drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
>>   drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
>>   drivers/media/platform/exynos-gsc/gsc-m2m.c        |   12 +-
>>   drivers/media/platform/exynos4-is/fimc-capture.c   |   23 +-
>>   drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
>>   drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
>>   drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
>>   drivers/media/platform/exynos4-is/fimc-isp-video.c |   25 +-
>>   drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
>>   drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
>>   drivers/media/platform/exynos4-is/fimc-lite.c      |   25 +-
>>   drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
>>   drivers/media/platform/exynos4-is/fimc-m2m.c       |   14 +-
>>   drivers/media/platform/m2m-deinterlace.c           |   16 +-
>>   drivers/media/platform/marvell-ccic/mcam-core.c    |   26 +-
>>   drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
>>   drivers/media/platform/mx2_emmaprp.c               |   16 +-
>>   drivers/media/platform/omap3isp/ispvideo.c         |   24 +-
>>   drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
>>   drivers/media/platform/s3c-camif/camif-capture.c   |   23 +-
>>   drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
>>   drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
>>   drivers/media/platform/s5p-g2d/g2d.c               |   14 +-
>>   drivers/media/platform/s5p-jpeg/jpeg-core.c        |   34 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc.c           |   14 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   36 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   57 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    4 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    4 +-
>>   drivers/media/platform/s5p-tv/mixer.h              |    4 +-
>>   drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
>>   drivers/media/platform/s5p-tv/mixer_video.c        |   11 +-
>>   drivers/media/platform/sh_veu.c                    |   25 +-
>>   drivers/media/platform/soc_camera/atmel-isi.c      |   26 +-
>>   drivers/media/platform/soc_camera/mx2_camera.c     |   41 +-
>>   drivers/media/platform/soc_camera/mx3_camera.c     |   34 +-
>>   drivers/media/platform/soc_camera/rcar_vin.c       |   30 +-
>>   .../platform/soc_camera/sh_mobile_ceu_camera.c     |   47 +-
>>   drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
>>   drivers/media/platform/ti-vpe/vpe.c                |   30 +-
>>   drivers/media/platform/vim2m.c                     |   28 +-
>>   drivers/media/platform/vivid/vivid-core.h          |    4 +-
>>   drivers/media/platform/vivid/vivid-kthread-cap.c   |    8 +-
>>   drivers/media/platform/vivid/vivid-kthread-out.c   |    8 +-
>>   drivers/media/platform/vivid/vivid-sdr-cap.c       |   18 +-
>>   drivers/media/platform/vivid/vivid-vbi-cap.c       |   14 +-
>>   drivers/media/platform/vivid/vivid-vbi-out.c       |   14 +-
>>   drivers/media/platform/vivid/vivid-vid-cap.c       |   24 +-
>>   drivers/media/platform/vivid/vivid-vid-out.c       |   21 +-
>>   drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
>>   drivers/media/platform/vsp1/vsp1_video.c           |   20 +-
>>   drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
>>   drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
>>   drivers/media/usb/airspy/airspy.c                  |   15 +-
>>   drivers/media/usb/au0828/au0828-vbi.c              |   17 +-
>>   drivers/media/usb/au0828/au0828-video.c            |   29 +-
>>   drivers/media/usb/au0828/au0828.h                  |    2 +-
>>   drivers/media/usb/em28xx/em28xx-vbi.c              |   15 +-
>>   drivers/media/usb/em28xx/em28xx-video.c            |   30 +-
>>   drivers/media/usb/em28xx/em28xx.h                  |    2 +-
>>   drivers/media/usb/go7007/go7007-driver.c           |    2 +-
>>   drivers/media/usb/go7007/go7007-priv.h             |    4 +-
>>   drivers/media/usb/go7007/go7007-v4l2.c             |   15 +-
>>   drivers/media/usb/hackrf/hackrf.c                  |   13 +-
>>   drivers/media/usb/msi2500/msi2500.c                |   13 +-
>>   drivers/media/usb/pwc/pwc-if.c                     |   26 +-
>>   drivers/media/usb/pwc/pwc.h                        |    2 +-
>>   drivers/media/usb/s2255/s2255drv.c                 |   16 +-
>>   drivers/media/usb/stk1160/stk1160-v4l.c            |   15 +-
>>   drivers/media/usb/stk1160/stk1160-video.c          |    2 +-
>>   drivers/media/usb/stk1160/stk1160.h                |    4 +-
>>   drivers/media/usb/usbtv/usbtv-video.c              |   11 +-
>>   drivers/media/usb/usbtv/usbtv.h                    |    2 +-
>>   drivers/media/usb/uvc/uvc_queue.c                  |   32 +-
>>   drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
>>   drivers/media/v4l2-core/Makefile                   |    2 +-
>>   drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
>>   drivers/media/v4l2-core/v4l2-mem2mem.c             |    8 +-
>>   drivers/media/v4l2-core/videobuf2-core.c           | 1888 ++------------------
>>   drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
>>   drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
>>   drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
>>   drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
>>   drivers/media/v4l2-core/videobuf2-v4l2.c           | 1878 +++++++++++++++++++
>>   drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
>>   drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
>>   drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
>>   drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
>>   drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
>>   drivers/staging/media/omap4iss/iss_video.c         |   16 +-
>>   drivers/staging/media/omap4iss/iss_video.h         |    4 +-
>>   drivers/usb/gadget/function/uvc_queue.c            |   14 +-
>>   drivers/usb/gadget/function/uvc_queue.h            |    4 +-
>>   include/media/davinci/vpbe_display.h               |    2 +-
>>   include/media/soc_camera.h                         |    2 +-
>>   include/media/v4l2-mem2mem.h                       |   10 +-
>>   include/media/videobuf2-core.h                     |  235 ++-
>>   include/media/videobuf2-dma-contig.h               |    6 +-
>>   include/media/videobuf2-dma-sg.h                   |    6 +-
>>   include/media/videobuf2-dvb.h                      |    2 +-
>>   include/media/videobuf2-memops.h                   |    2 +-
>>   include/media/videobuf2-v4l2.h                     |  139 ++
>>   include/media/videobuf2-vmalloc.h                  |    2 +-
>>   144 files changed, 3290 insertions(+), 2662 deletions(-)
>>   create mode 100644 drivers/media/v4l2-core/videobuf2-v4l2.c
>>   create mode 100644 include/media/videobuf2-v4l2.h
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer
  2015-06-17 12:27   ` Mauro Carvalho Chehab
@ 2015-06-23  1:11     ` Junghak Sung
  0 siblings, 0 replies; 15+ messages in thread
From: Junghak Sung @ 2015-06-23  1:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim


Hi Mauro,

Thank you for your reviewing.
I will rework this patch in order to be easier to review.
I reply to your comment. See below.

Regards,
Junghak


On 06/17/2015 09:27 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 08 Jun 2015 22:35:33 +0900
> Junghak Sung <jh1009.sung@samsung.com> escreveu:
>
>> Make the struct vb2_buffer to common buffer by removing v4l2-specific members.
>> And common video buffer is embedded into v4l2-specific video buffer like:
>> struct vb2_v4l2_buffer {
>>      struct vb2_buffer    vb2;
>>      struct v4l2_buffer    v4l2_buf;
>>      struct v4l2_plane    v4l2_planes[VIDEO_MAX_PLANES];
>> };
>> This changes require the modifications of all device drivers that use this structure.
> Thanks for the patch!
>
> In general, it looks fine. Just a few comments. See below.
>
> Regards,
> Mauro
>
>> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>> ---
>>   Documentation/video4linux/v4l2-pci-skeleton.c      |   12 +-
>>   drivers/media/dvb-frontends/rtl2832_sdr.c          |   10 +-
>>   drivers/media/pci/cx23885/cx23885-417.c            |   12 +-
>>   drivers/media/pci/cx23885/cx23885-dvb.c            |   12 +-
>>   drivers/media/pci/cx23885/cx23885-vbi.c            |   12 +-
>>   drivers/media/pci/cx23885/cx23885-video.c          |   12 +-
>>   drivers/media/pci/cx23885/cx23885.h                |    2 +-
>>   drivers/media/pci/cx25821/cx25821-video.c          |   12 +-
>>   drivers/media/pci/cx25821/cx25821.h                |    2 +-
>>   drivers/media/pci/cx88/cx88-blackbird.c            |   14 +-
>>   drivers/media/pci/cx88/cx88-dvb.c                  |   14 +-
>>   drivers/media/pci/cx88/cx88-vbi.c                  |   12 +-
>>   drivers/media/pci/cx88/cx88-video.c                |   12 +-
>>   drivers/media/pci/cx88/cx88.h                      |    2 +-
>>   drivers/media/pci/saa7134/saa7134-empress.c        |    2 +-
>>   drivers/media/pci/saa7134/saa7134-ts.c             |   10 +-
>>   drivers/media/pci/saa7134/saa7134-vbi.c            |   12 +-
>>   drivers/media/pci/saa7134/saa7134-video.c          |   18 +-
>>   drivers/media/pci/saa7134/saa7134.h                |    8 +-
>>   drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   14 +-
>>   drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    6 +-
>>   drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
>>   drivers/media/pci/sta2x11/sta2x11_vip.c            |   20 +-
>>   drivers/media/pci/tw68/tw68-video.c                |   12 +-
>>   drivers/media/pci/tw68/tw68.h                      |    2 +-
>>   drivers/media/platform/am437x/am437x-vpfe.c        |   16 +-
>>   drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
>>   drivers/media/platform/blackfin/bfin_capture.c     |   20 +-
>>   drivers/media/platform/coda/coda-bit.c             |   20 +-
>>   drivers/media/platform/coda/coda-common.c          |   24 +-
>>   drivers/media/platform/coda/coda-jpeg.c            |    2 +-
>>   drivers/media/platform/coda/coda.h                 |    6 +-
>>   drivers/media/platform/davinci/vpbe_display.c      |    8 +-
>>   drivers/media/platform/davinci/vpif_capture.c      |   16 +-
>>   drivers/media/platform/davinci/vpif_capture.h      |    2 +-
>>   drivers/media/platform/davinci/vpif_display.c      |   18 +-
>>   drivers/media/platform/davinci/vpif_display.h      |    6 +-
>>   drivers/media/platform/exynos-gsc/gsc-core.c       |    2 +-
>>   drivers/media/platform/exynos-gsc/gsc-core.h       |    6 +-
>>   drivers/media/platform/exynos-gsc/gsc-m2m.c        |   16 +-
>>   drivers/media/platform/exynos4-is/fimc-capture.c   |   12 +-
>>   drivers/media/platform/exynos4-is/fimc-core.c      |    4 +-
>>   drivers/media/platform/exynos4-is/fimc-core.h      |    6 +-
>>   drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
>>   drivers/media/platform/exynos4-is/fimc-isp-video.c |   14 +-
>>   drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
>>   drivers/media/platform/exynos4-is/fimc-isp.h       |    4 +-
>>   drivers/media/platform/exynos4-is/fimc-lite.c      |   10 +-
>>   drivers/media/platform/exynos4-is/fimc-lite.h      |    4 +-
>>   drivers/media/platform/exynos4-is/fimc-m2m.c       |   16 +-
>>   drivers/media/platform/m2m-deinterlace.c           |   16 +-
>>   drivers/media/platform/marvell-ccic/mcam-core.c    |   24 +-
>>   drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
>>   drivers/media/platform/mx2_emmaprp.c               |   16 +-
>>   drivers/media/platform/omap3isp/ispvideo.c         |    8 +-
>>   drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
>>   drivers/media/platform/s3c-camif/camif-capture.c   |   12 +-
>>   drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
>>   drivers/media/platform/s3c-camif/camif-core.h      |    4 +-
>>   drivers/media/platform/s5p-g2d/g2d.c               |   16 +-
>>   drivers/media/platform/s5p-jpeg/jpeg-core.c        |   30 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc.c           |    2 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   10 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   18 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    2 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    2 +-
>>   drivers/media/platform/s5p-tv/mixer.h              |    4 +-
>>   drivers/media/platform/s5p-tv/mixer_video.c        |    4 +-
>>   drivers/media/platform/sh_veu.c                    |   20 +-
>>   drivers/media/platform/soc_camera/atmel-isi.c      |   20 +-
>>   drivers/media/platform/soc_camera/mx2_camera.c     |   14 +-
>>   drivers/media/platform/soc_camera/mx3_camera.c     |   18 +-
>>   drivers/media/platform/soc_camera/rcar_vin.c       |   14 +-
>>   .../platform/soc_camera/sh_mobile_ceu_camera.c     |   22 +-
>>   drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
>>   drivers/media/platform/ti-vpe/vpe.c                |   26 +-
>>   drivers/media/platform/vim2m.c                     |   24 +-
>>   drivers/media/platform/vivid/vivid-core.h          |    4 +-
>>   drivers/media/platform/vivid/vivid-sdr-cap.c       |    8 +-
>>   drivers/media/platform/vivid/vivid-vbi-cap.c       |   10 +-
>>   drivers/media/platform/vivid/vivid-vbi-out.c       |   10 +-
>>   drivers/media/platform/vivid/vivid-vid-cap.c       |   12 +-
>>   drivers/media/platform/vivid/vivid-vid-out.c       |    8 +-
>>   drivers/media/platform/vsp1/vsp1_rpf.c             |    4 +-
>>   drivers/media/platform/vsp1/vsp1_video.c           |   16 +-
>>   drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
>>   drivers/media/platform/vsp1/vsp1_wpf.c             |    4 +-
>>   drivers/media/usb/airspy/airspy.c                  |    6 +-
>>   drivers/media/usb/au0828/au0828-vbi.c              |    8 +-
>>   drivers/media/usb/au0828/au0828-video.c            |    8 +-
>>   drivers/media/usb/au0828/au0828.h                  |    2 +-
>>   drivers/media/usb/em28xx/em28xx-vbi.c              |    8 +-
>>   drivers/media/usb/em28xx/em28xx-video.c            |    8 +-
>>   drivers/media/usb/em28xx/em28xx.h                  |    2 +-
>>   drivers/media/usb/go7007/go7007-priv.h             |    4 +-
>>   drivers/media/usb/go7007/go7007-v4l2.c             |   10 +-
>>   drivers/media/usb/hackrf/hackrf.c                  |    6 +-
>>   drivers/media/usb/msi2500/msi2500.c                |    6 +-
>>   drivers/media/usb/pwc/pwc-if.c                     |   18 +-
>>   drivers/media/usb/pwc/pwc.h                        |    2 +-
>>   drivers/media/usb/s2255/s2255drv.c                 |   10 +-
>>   drivers/media/usb/stk1160/stk1160-v4l.c            |    4 +-
>>   drivers/media/usb/stk1160/stk1160.h                |    4 +-
>>   drivers/media/usb/usbtv/usbtv-video.c              |    6 +-
>>   drivers/media/usb/usbtv/usbtv.h                    |    2 +-
>>   drivers/media/usb/uvc/uvc_queue.c                  |   14 +-
>>   drivers/media/usb/uvc/uvcvideo.h                   |    4 +-
>>   drivers/media/v4l2-core/Makefile                   |    2 +-
>>   drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
>>   drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
>>   drivers/media/v4l2-core/videobuf2-core.c           |  398 +++++++++----------
>>   drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
>>   drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
>>   drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
>>   drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
>>   .../{videobuf2-core.c => videobuf2-v4l2.c}         |  400 ++++++++++----------
>>   drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
>>   drivers/staging/media/davinci_vpfe/vpfe_video.c    |   30 +-
>>   drivers/staging/media/davinci_vpfe/vpfe_video.h    |    2 +-
>>   drivers/staging/media/dt3155v4l/dt3155v4l.c        |   14 +-
>>   drivers/staging/media/dt3155v4l/dt3155v4l.h        |    2 +-
>>   drivers/staging/media/omap4iss/iss_video.c         |   16 +-
>>   drivers/staging/media/omap4iss/iss_video.h         |    4 +-
>>   drivers/usb/gadget/function/uvc_queue.c            |   14 +-
>>   drivers/usb/gadget/function/uvc_queue.h            |    4 +-
>>   include/media/davinci/vpbe_display.h               |    2 +-
>>   include/media/soc_camera.h                         |    2 +-
>>   include/media/v4l2-mem2mem.h                       |    8 +-
>>   include/media/videobuf2-core.h                     |   76 ++--
>>   include/media/videobuf2-dma-contig.h               |    4 +-
>>   include/media/videobuf2-dma-sg.h                   |    4 +-
>>   include/media/videobuf2-dvb.h                      |    2 +-
>>   include/media/videobuf2-memops.h                   |    2 +-
>>   .../media/{videobuf2-core.h => videobuf2-v4l2.h}   |   80 ++--
>>   include/media/videobuf2-vmalloc.h                  |    2 +-
>>   136 files changed, 1081 insertions(+), 1045 deletions(-)
>>   copy drivers/media/v4l2-core/{videobuf2-core.c => videobuf2-v4l2.c} (89%)
>>   copy include/media/{videobuf2-core.h => videobuf2-v4l2.h} (94%)
>>
> Let me go directly to the header changes. Everything else is consequence
> of that. As I said before, the best is to have a script that would do the
> renaming changes to fulfill what was changed in the headers.
OK, I will try to make a script again.
>> --- a/include/media/videobuf2-core.h
>> +++ b/include/media/videobuf2-core.h
>> @@ -1,5 +1,5 @@
>>   /*
>> - * videobuf2-core.h - V4L2 driver helper framework
>> + * videobuf2-core.h - Video Buffer 2 framework
>>    *
>>    * Copyright (C) 2010 Samsung Electronics
>>    *
>> @@ -171,18 +171,7 @@ enum vb2_buffer_state {
>>   struct vb2_queue;
>>   
>>   /**
>> - * struct vb2_buffer - represents a video buffer
>> - * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
>> - *			be read by the driver and relevant entries can be
>> - *			changed by the driver in case of CAPTURE types
>> - *			(such as timestamp)
>> - * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
>> - *			be read by the driver and relevant entries can be
>> - *			changed by the driver in case of CAPTURE types
>> - *			(such as bytesused); NOTE that even for single-planar
>> - *			types, the v4l2_planes[0] struct should be used
>> - *			instead of v4l2_buf for filling bytesused - drivers
>> - *			should use the vb2_set_plane_payload() function for that
>> + * struct vb2_buffer - represents a common video buffer
>>    * @vb2_queue:		the queue to which this driver belongs
>>    * @num_planes:		number of planes in the buffer
>>    *			on an internal driver queue
>> @@ -194,11 +183,7 @@ struct vb2_queue;
>>    * @planes:		private per-plane information; do not change
>>    */
>>   struct vb2_buffer {
>> -	struct v4l2_buffer	v4l2_buf;
>> -	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
>> -
>>   	struct vb2_queue	*vb2_queue;
>> -
>>   	unsigned int		num_planes;
>>   
>>   /* Private: internal use only */
>> @@ -242,6 +227,27 @@ struct vb2_buffer {
>>   };
>>   
>>   /**
>> + * struct vb2_v4l2_buffer - represents a video buffer for v4l2
>> + * @vb2_buf:		common video buffer
>> + * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
>> + *			be read by the driver and relevant entries can be
>> + *			changed by the driver in case of CAPTURE types
>> + *			(such as timestamp)
>> + * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
>> + *			be read by the driver and relevant entries can be
>> + *			changed by the driver in case of CAPTURE types
>> + *			(such as bytesused); NOTE that even for single-planar
>> + *			types, the v4l2_planes[0] struct should be used
>> + *			instead of v4l2_buf for filling bytesused - drivers
>> + *			should use the vb2_set_plane_payload() function for that
>> + */
>> +struct vb2_v4l2_buffer {
>> +	struct vb2_buffer	vb2;
>> +	struct v4l2_buffer	v4l2_buf;
>> +	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
>> +};
>> +
>> +/**
>>    * struct vb2_ops - driver-specific callbacks
>>    *
>>    * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
>> @@ -328,15 +334,15 @@ struct vb2_ops {
>>   	void (*wait_prepare)(struct vb2_queue *q);
>>   	void (*wait_finish)(struct vb2_queue *q);
>>   
>> -	int (*buf_init)(struct vb2_buffer *vb);
>> -	int (*buf_prepare)(struct vb2_buffer *vb);
>> -	void (*buf_finish)(struct vb2_buffer *vb);
>> -	void (*buf_cleanup)(struct vb2_buffer *vb);
>> +	int (*buf_init)(struct vb2_v4l2_buffer *vb);
>> +	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
>> +	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
>> +	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
>>   
>>   	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
>>   	void (*stop_streaming)(struct vb2_queue *q);
>>   
>> -	void (*buf_queue)(struct vb2_buffer *vb);
>> +	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
>>   };
>>   
>>   struct v4l2_fh;
>> @@ -361,7 +367,7 @@ struct v4l2_fh;
>>    * @drv_priv:	driver private data
>>    * @buf_struct_size: size of the driver-specific buffer structure;
>>    *		"0" indicates the driver doesn't want to use a custom buffer
>> - *		structure type, so sizeof(struct vb2_buffer) will is used
>> + *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
>>    * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
>>    *		V4L2_BUF_FLAG_TSTAMP_SRC_*
>>    * @gfp_flags:	additional gfp flags used when allocating the buffers.
>> @@ -398,7 +404,7 @@ struct vb2_queue {
>>   	unsigned int			io_modes;
>>   	unsigned int			io_flags;
>>   	struct mutex			*lock;
>> -	struct v4l2_fh			*owner;
>> +	void					*owner;
> Looks ok, except for the extra tab that disaligns it. Please notice
> that, on Kernel, a tab is 8 spaces.
OK, I will correct that.
>>   
>>   	const struct vb2_ops		*ops;
>>   	const struct vb2_mem_ops	*mem_ops;
>> @@ -411,7 +417,7 @@ struct vb2_queue {
>>   /* private: internal use only */
>>   	struct mutex			mmap_lock;
>>   	enum v4l2_memory		memory;
>> -	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
>> +	void					*bufs[VIDEO_MAX_FRAME];
> Hmm.. why void? It can be struct vb2_buffer. Of course, in order
> to get the buffer, the code would need to do something like:
>
> 	struct vb2_v4l2_buffer *vb;
>
> 	vb = container_of(bufs[0], struct vb2_v4l2_buffer, vb2);
>
> But this would avoid the typecasts at the VB2 core, and, most importantly,
> it would ensure strong type checks by the compiler.
>
It was modified to struct vb2_buffer again at 2/3 patch.
>>   	unsigned int			num_buffers;
>>   
>>   	struct list_head		queued_list;
>> @@ -446,10 +452,10 @@ struct vb2_queue {
>>   #endif
>>   };
>>   
>> -void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
>> -void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
>> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>>   
>> -void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
>> +void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
>>   void vb2_discard_done(struct vb2_queue *q);
>>   int vb2_wait_for_all_buffers(struct vb2_queue *q);
>>   
>> @@ -489,7 +495,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
>>    *
>>    * This is called whenever a buffer is dequeued in the thread.
>>    */
>> -typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
>> +typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
>>   
>>   /**
>>    * vb2_thread_start() - start a thread for the given queue.
>> @@ -566,10 +572,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
>>    * @plane_no:	plane number for which payload should be set
>>    * @size:	payload in bytes
>>    */
>> -static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
>> +static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>>   				 unsigned int plane_no, unsigned long size)
>>   {
>> -	if (plane_no < vb->num_planes)
>> +	if (plane_no < vb->vb2.num_planes)
>>   		vb->v4l2_planes[plane_no].bytesused = size;
>>   }
>>   
>> @@ -579,10 +585,10 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
>>    * @plane_no:	plane number for which payload should be set
>>    * @size:	payload in bytes
>>    */
>> -static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
>> +static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>>   				 unsigned int plane_no)
>>   {
>> -	if (plane_no < vb->num_planes)
>> +	if (plane_no < vb->vb2.num_planes)
>>   		return vb->v4l2_planes[plane_no].bytesused;
>>   	return 0;
>>   }
>> @@ -593,9 +599,9 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
>>    * @plane_no:	plane number for which size should be returned
>>    */
>>   static inline unsigned long
>> -vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
>> +vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>>   {
>> -	if (plane_no < vb->num_planes)
>> +	if (plane_no < vb->vb2.num_planes)
>>   		return vb->v4l2_planes[plane_no].length;
>>   	return 0;
>>   }
>> diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h
>> index 8197f87..3de9111 100644
>> --- a/include/media/videobuf2-dma-contig.h
>> +++ b/include/media/videobuf2-dma-contig.h
>> @@ -13,11 +13,11 @@
>>   #ifndef _MEDIA_VIDEOBUF2_DMA_CONTIG_H
>>   #define _MEDIA_VIDEOBUF2_DMA_CONTIG_H
>>   
>> -#include <media/videobuf2-core.h>
>> +#include <media/videobuf2-v4l2.h>
>>   #include <linux/dma-mapping.h>
>>   
>>   static inline dma_addr_t
>> -vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no)
>> +vb2_dma_contig_plane_dma_addr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>>   {
>>   	dma_addr_t *addr = vb2_plane_cookie(vb, plane_no);
>>   
>> diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h
>> index 14ce306..36f7ea3 100644
>> --- a/include/media/videobuf2-dma-sg.h
>> +++ b/include/media/videobuf2-dma-sg.h
>> @@ -13,10 +13,10 @@
>>   #ifndef _MEDIA_VIDEOBUF2_DMA_SG_H
>>   #define _MEDIA_VIDEOBUF2_DMA_SG_H
>>   
>> -#include <media/videobuf2-core.h>
>> +#include <media/videobuf2-v4l2.h>
>>   
>>   static inline struct sg_table *vb2_dma_sg_plane_desc(
>> -		struct vb2_buffer *vb, unsigned int plane_no)
>> +		struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>>   {
>>   	return (struct sg_table *)vb2_plane_cookie(vb, plane_no);
>>   }
>> diff --git a/include/media/videobuf2-dvb.h b/include/media/videobuf2-dvb.h
>> index 8f61456..bef9127 100644
>> --- a/include/media/videobuf2-dvb.h
>> +++ b/include/media/videobuf2-dvb.h
>> @@ -6,7 +6,7 @@
>>   #include <dvb_demux.h>
>>   #include <dvb_net.h>
>>   #include <dvb_frontend.h>
>> -#include <media/videobuf2-core.h>
>> +#include <media/videobuf2-v4l2.h>
>>   
>>   struct vb2_dvb {
>>   	/* filling that the job of the driver */
>> diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
>> index f05444c..7b6d475 100644
>> --- a/include/media/videobuf2-memops.h
>> +++ b/include/media/videobuf2-memops.h
>> @@ -14,7 +14,7 @@
>>   #ifndef _MEDIA_VIDEOBUF2_MEMOPS_H
>>   #define _MEDIA_VIDEOBUF2_MEMOPS_H
>>   
>> -#include <media/videobuf2-core.h>
>> +#include <media/videobuf2-v4l2.h>
>>   
>>   /**
>>    * vb2_vmarea_handler - common vma refcount tracking handler
>> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-v4l2.h
>> similarity index 94%
>> copy from include/media/videobuf2-core.h
>> copy to include/media/videobuf2-v4l2.h
>> index bd2cec2..80b08cb 100644
>> --- a/include/media/videobuf2-core.h
>> +++ b/include/media/videobuf2-v4l2.h
>> @@ -9,8 +9,8 @@
>>    * it under the terms of the GNU General Public License as published by
>>    * the Free Software Foundation.
>>    */
>> -#ifndef _MEDIA_VIDEOBUF2_CORE_H
>> -#define _MEDIA_VIDEOBUF2_CORE_H
>> +#ifndef _MEDIA_VIDEOBUF2_V4L2_H
>> +#define _MEDIA_VIDEOBUF2_V4L2_H
>>   
>>   #include <linux/mm_types.h>
>>   #include <linux/mutex.h>
>> @@ -171,18 +171,7 @@ enum vb2_buffer_state {
>>   struct vb2_queue;
>>   
>>   /**
>> - * struct vb2_buffer - represents a video buffer
>> - * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
>> - *			be read by the driver and relevant entries can be
>> - *			changed by the driver in case of CAPTURE types
>> - *			(such as timestamp)
>> - * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
>> - *			be read by the driver and relevant entries can be
>> - *			changed by the driver in case of CAPTURE types
>> - *			(such as bytesused); NOTE that even for single-planar
>> - *			types, the v4l2_planes[0] struct should be used
>> - *			instead of v4l2_buf for filling bytesused - drivers
>> - *			should use the vb2_set_plane_payload() function for that
>> + * struct vb2_buffer - represents a common video buffer
>>    * @vb2_queue:		the queue to which this driver belongs
>>    * @num_planes:		number of planes in the buffer
>>    *			on an internal driver queue
>> @@ -194,11 +183,7 @@ struct vb2_queue;
>>    * @planes:		private per-plane information; do not change
>>    */
>>   struct vb2_buffer {
>> -	struct v4l2_buffer	v4l2_buf;
>> -	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
>> -
>>   	struct vb2_queue	*vb2_queue;
>> -
>>   	unsigned int		num_planes;
>>   
>>   /* Private: internal use only */
>> @@ -242,6 +227,27 @@ struct vb2_buffer {
>>   };
> Why are you declaring it again here? Instead, just include
> videobuf2-core.h.
It was removed at 2/3 patch.
>>   
>>   /**
>> + * struct vb2_v4l2_buffer - represents a video buffer for v4l2
>> + * @vb2_buf:		common video buffer
>> + * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
>> + *			be read by the driver and relevant entries can be
>> + *			changed by the driver in case of CAPTURE types
>> + *			(such as timestamp)
>> + * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
>> + *			be read by the driver and relevant entries can be
>> + *			changed by the driver in case of CAPTURE types
>> + *			(such as bytesused); NOTE that even for single-planar
>> + *			types, the v4l2_planes[0] struct should be used
>> + *			instead of v4l2_buf for filling bytesused - drivers
>> + *			should use the vb2_set_plane_payload() function for that
>> + */
>> +struct vb2_v4l2_buffer {
>> +	struct vb2_buffer	vb2;
>> +	struct v4l2_buffer	v4l2_buf;
>> +	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
>> +};
>> +
> Same here: this got declared twice.
>
> As I explained on my comment 0/3, in order to easy patch review, I would
> first rename the header, then do those changes and then move the
> non-vb4l2 functions to the new videobuf2-core.h
I agree with you. I will split the patch into two or more pieces to be 
easier to review.
>> +/**
>>    * struct vb2_ops - driver-specific callbacks
>>    *
>>    * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
>> @@ -328,15 +334,15 @@ struct vb2_ops {
>>   	void (*wait_prepare)(struct vb2_queue *q);
>>   	void (*wait_finish)(struct vb2_queue *q);
>>   
>> -	int (*buf_init)(struct vb2_buffer *vb);
>> -	int (*buf_prepare)(struct vb2_buffer *vb);
>> -	void (*buf_finish)(struct vb2_buffer *vb);
>> -	void (*buf_cleanup)(struct vb2_buffer *vb);
>> +	int (*buf_init)(struct vb2_v4l2_buffer *vb);
>> +	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
>> +	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
>> +	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
>>   
>>   	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
>>   	void (*stop_streaming)(struct vb2_queue *q);
>>   
>> -	void (*buf_queue)(struct vb2_buffer *vb);
>> +	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
>>   };
>>   
>>   struct v4l2_fh;
>> @@ -361,7 +367,7 @@ struct v4l2_fh;
>>    * @drv_priv:	driver private data
>>    * @buf_struct_size: size of the driver-specific buffer structure;
>>    *		"0" indicates the driver doesn't want to use a custom buffer
>> - *		structure type, so sizeof(struct vb2_buffer) will is used
>> + *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
>>    * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
>>    *		V4L2_BUF_FLAG_TSTAMP_SRC_*
>>    * @gfp_flags:	additional gfp flags used when allocating the buffers.
>> @@ -398,7 +404,7 @@ struct vb2_queue {
>>   	unsigned int			io_modes;
>>   	unsigned int			io_flags;
>>   	struct mutex			*lock;
>> -	struct v4l2_fh			*owner;
>> +	void					*owner;
> Again, there's an extra tab here.
OK, I checked it.
>
>>   
>>   	const struct vb2_ops		*ops;
>>   	const struct vb2_mem_ops	*mem_ops;
>> @@ -411,7 +417,7 @@ struct vb2_queue {
>>   /* private: internal use only */
>>   	struct mutex			mmap_lock;
>>   	enum v4l2_memory		memory;
>> -	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
>> +	void					*bufs[VIDEO_MAX_FRAME];
> Again, there's an extra tab here.
OK, I checked it.
>
>>   	unsigned int			num_buffers;
>>   
>>   	struct list_head		queued_list;
>> @@ -446,10 +452,10 @@ struct vb2_queue {
>>   #endif
>>   };
>>   
>> -void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
>> -void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
>> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>>   
>> -void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
>> +void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
>>   void vb2_discard_done(struct vb2_queue *q);
>>   int vb2_wait_for_all_buffers(struct vb2_queue *q);
>>   
>> @@ -489,7 +495,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
>>    *
>>    * This is called whenever a buffer is dequeued in the thread.
>>    */
>> -typedef int (*vb2_thread_fnc)(struct vb2_buffer *vb, void *priv);
>> +typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
>>   
>>   /**
>>    * vb2_thread_start() - start a thread for the given queue.
>> @@ -566,10 +572,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
>>    * @plane_no:	plane number for which payload should be set
>>    * @size:	payload in bytes
>>    */
>> -static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
>> +static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>>   				 unsigned int plane_no, unsigned long size)
>>   {
>> -	if (plane_no < vb->num_planes)
>> +	if (plane_no < vb->vb2.num_planes)
>>   		vb->v4l2_planes[plane_no].bytesused = size;
>>   }
>>   
>> @@ -579,10 +585,10 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
>>    * @plane_no:	plane number for which payload should be set
>>    * @size:	payload in bytes
>>    */
>> -static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
>> +static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>>   				 unsigned int plane_no)
>>   {
>> -	if (plane_no < vb->num_planes)
>> +	if (plane_no < vb->vb2.num_planes)
>>   		return vb->v4l2_planes[plane_no].bytesused;
>>   	return 0;
>>   }
>> @@ -593,9 +599,9 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
>>    * @plane_no:	plane number for which size should be returned
>>    */
>>   static inline unsigned long
>> -vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
>> +vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>>   {
>> -	if (plane_no < vb->num_planes)
>> +	if (plane_no < vb->vb2.num_planes)
>>   		return vb->v4l2_planes[plane_no].length;
>>   	return 0;
>>   }
>> @@ -653,4 +659,4 @@ unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
>>   void vb2_ops_wait_prepare(struct vb2_queue *vq);
>>   void vb2_ops_wait_finish(struct vb2_queue *vq);
>>   
>> -#endif /* _MEDIA_VIDEOBUF2_CORE_H */
>> +#endif /* _MEDIA_VIDEOBUF2_V4L2_H */
>> diff --git a/include/media/videobuf2-vmalloc.h b/include/media/videobuf2-vmalloc.h
>> index 93a76b4..a63fe66 100644
>> --- a/include/media/videobuf2-vmalloc.h
>> +++ b/include/media/videobuf2-vmalloc.h
>> @@ -13,7 +13,7 @@
>>   #ifndef _MEDIA_VIDEOBUF2_VMALLOC_H
>>   #define _MEDIA_VIDEOBUF2_VMALLOC_H
>>   
>> -#include <media/videobuf2-core.h>
>> +#include <media/videobuf2-v4l2.h>
>>   
>>   extern const struct vb2_mem_ops vb2_vmalloc_memops;
>>   
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH 2/3] make struct vb2_queue to common and apply the changes related with that.
  2015-06-17 13:16   ` [RFC PATCH 2/3] make struct vb2_queue to common and apply the changes related with that Mauro Carvalho Chehab
@ 2015-06-23  1:33     ` Junghak Sung
  0 siblings, 0 replies; 15+ messages in thread
From: Junghak Sung @ 2015-06-23  1:33 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, sangbae90.lee, inki.dae, nenggun.kim, sw0312.kim

Hi Mauro,

Thank you for your review.
I leave a reply to your comment at each lines.
I will rework all these patches to be easier to review.

Regards,
Junghak


On 06/17/2015 10:16 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 08 Jun 2015 22:35:34 +0900
> Junghak Sung <jh1009.sung@samsung.com> escreveu:
>
>> Abstract the v4l2-specific members of the struct vb2_queue,
>> and concrete it in the side of user.
>> For example, the struct vb2_v4l2_buffer can be abstracted by using
>> struct vb2_buffer, and concrete it by using container_of() in a device driver.
>>
>> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>> ---
>>   drivers/media/dvb-frontends/rtl2832_sdr.c          |   13 +-
>>   drivers/media/pci/cx23885/cx23885-417.c            |   23 +-
>>   drivers/media/pci/cx23885/cx23885-dvb.c            |   24 +-
>>   drivers/media/pci/cx23885/cx23885-vbi.c            |   27 +-
>>   drivers/media/pci/cx23885/cx23885-video.c          |   27 +-
>>   drivers/media/pci/cx25821/cx25821-video.c          |   28 +-
>>   drivers/media/pci/cx88/cx88-blackbird.c            |   25 +-
>>   drivers/media/pci/cx88/cx88-dvb.c                  |   25 +-
>>   drivers/media/pci/cx88/cx88-vbi.c                  |   27 +-
>>   drivers/media/pci/cx88/cx88-video.c                |   27 +-
>>   drivers/media/pci/saa7134/saa7134-empress.c        |    2 +-
>>   drivers/media/pci/saa7134/saa7134-ts.c             |   26 +-
>>   drivers/media/pci/saa7134/saa7134-vbi.c            |   22 +-
>>   drivers/media/pci/saa7134/saa7134-video.c          |   11 +-
>>   drivers/media/pci/saa7134/saa7134.h                |    2 +-
>>   drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   15 +-
>>   drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   11 +-
>>   drivers/media/pci/sta2x11/sta2x11_vip.c            |   32 +-
>>   drivers/media/pci/tw68/tw68-video.c                |   28 +-
>>   drivers/media/platform/am437x/am437x-vpfe.c        |   21 +-
>>   drivers/media/platform/blackfin/bfin_capture.c     |   32 +-
>>   drivers/media/platform/coda/coda-common.c          |   30 +-
>>   drivers/media/platform/davinci/vpbe_display.c      |   19 +-
>>   drivers/media/platform/davinci/vpif_capture.c      |   10 +-
>>   drivers/media/platform/davinci/vpif_display.c      |   10 +-
>>   drivers/media/platform/exynos-gsc/gsc-m2m.c        |   20 +-
>>   drivers/media/platform/exynos4-is/fimc-capture.c   |   25 +-
>>   drivers/media/platform/exynos4-is/fimc-isp-video.c |   29 +-
>>   drivers/media/platform/exynos4-is/fimc-lite.c      |   25 +-
>>   drivers/media/platform/exynos4-is/fimc-m2m.c       |   18 +-
>>   drivers/media/platform/m2m-deinterlace.c           |   24 +-
>>   drivers/media/platform/marvell-ccic/mcam-core.c    |   28 +-
>>   drivers/media/platform/mx2_emmaprp.c               |   24 +-
>>   drivers/media/platform/omap3isp/ispvideo.c         |   18 +-
>>   drivers/media/platform/s3c-camif/camif-capture.c   |   21 +-
>>   drivers/media/platform/s5p-g2d/g2d.c               |   18 +-
>>   drivers/media/platform/s5p-jpeg/jpeg-core.c        |   30 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   42 +-
>>   drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   57 +-
>>   drivers/media/platform/s5p-tv/mixer_video.c        |    9 +-
>>   drivers/media/platform/sh_veu.c                    |   25 +-
>>   drivers/media/platform/soc_camera/atmel-isi.c      |   34 +-
>>   drivers/media/platform/soc_camera/mx2_camera.c     |   37 +-
>>   drivers/media/platform/soc_camera/mx3_camera.c     |   36 +-
>>   drivers/media/platform/soc_camera/rcar_vin.c       |   16 +-
>>   .../platform/soc_camera/sh_mobile_ceu_camera.c     |   49 +-
>>   drivers/media/platform/ti-vpe/vpe.c                |   32 +-
>>   drivers/media/platform/vim2m.c                     |   32 +-
>>   drivers/media/platform/vivid/vivid-sdr-cap.c       |   20 +-
>>   drivers/media/platform/vivid/vivid-vbi-cap.c       |   22 +-
>>   drivers/media/platform/vivid/vivid-vbi-out.c       |   22 +-
>>   drivers/media/platform/vivid/vivid-vid-cap.c       |   34 +-
>>   drivers/media/platform/vivid/vivid-vid-out.c       |   27 +-
>>   drivers/media/usb/airspy/airspy.c                  |    9 +-
>>   drivers/media/usb/au0828/au0828-vbi.c              |   25 +-
>>   drivers/media/usb/au0828/au0828-video.c            |   25 +-
>>   drivers/media/usb/em28xx/em28xx-vbi.c              |   23 +-
>>   drivers/media/usb/em28xx/em28xx-video.c            |   28 +-
>>   drivers/media/usb/go7007/go7007-v4l2.c             |   25 +-
>>   drivers/media/usb/hackrf/hackrf.c                  |    9 +-
>>   drivers/media/usb/msi2500/msi2500.c                |    9 +-
>>   drivers/media/usb/pwc/pwc-if.c                     |   30 +-
>>   drivers/media/usb/s2255/s2255drv.c                 |   18 +-
>>   drivers/media/usb/stk1160/stk1160-v4l.c            |   13 +-
>>   drivers/media/usb/usbtv/usbtv-video.c              |    9 +-
>>   drivers/media/usb/uvc/uvc_queue.c                  |   40 +-
>>   drivers/media/v4l2-core/Makefile                   |    2 +-
>>   drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
>>   drivers/media/v4l2-core/videobuf2-core.c           | 3488 +-------------------
>>   drivers/media/v4l2-core/videobuf2-v4l2.c           |  615 ++--
>>   include/media/videobuf2-core.h                     |  249 +-
>>   include/media/videobuf2-dma-contig.h               |    4 +-
>>   include/media/videobuf2-v4l2.h                     |  440 +--
>>   73 files changed, 1227 insertions(+), 5131 deletions(-)
> (driver changes removed - those are consequences of the core changes.
>   Again, a script is the best way to do those driver changes, as it can
>   be easily reviewed and will be needed anyway when applying the changes, as
>   drivers may change or added while this changeset is not merged).
>
>>   static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
>> diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
>> index bd9a6ef..15789e9 100644
>> --- a/drivers/media/v4l2-core/Makefile
>> +++ b/drivers/media/v4l2-core/Makefile
>> @@ -28,7 +28,7 @@ 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_VIDEOBUF2_CORE) += videobuf2-v4l2.o
>> +obj-$(CONFIG_VIDEOBUF2_CORE) += videobuf2-core.o videobuf2-v4l2.o
>>   obj-$(CONFIG_VIDEOBUF2_MEMOPS) += videobuf2-memops.o
>>   obj-$(CONFIG_VIDEOBUF2_VMALLOC) += videobuf2-vmalloc.o
>>   obj-$(CONFIG_VIDEOBUF2_DMA_CONTIG) += videobuf2-dma-contig.o
>> diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
>> index 3392a58..bce2560 100644
>> --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
>> +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
>> @@ -739,13 +739,13 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_release);
>>    *
>>    * Call from buf_queue(), videobuf_queue_ops callback.
>>    */
>> -void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_v4l2_buffer *vb)
>> +void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct vb2_v4l2_buffer *cb)
> Why are you renaming it to "cb"? IMHO, we should standardize the namespace
> for those. On the past patch, you were using vb2 and vb.
>
> In any case, this namespace rename could happen on a separate patch, IMHO.
> This one is already big enough without namespace renaming.
The "cb" means "container buffer". I was very confused because the 
struct vb2_buffer uses
"vb" or "vb2" and the struct vb2_v4l2_buffer also uses same name. So, I 
replace it to "cb"
for struct vb2_v4l2_buffer. Is there any idea to remove this confusion?
>>   {
>> -	struct v4l2_m2m_buffer *b = container_of(vb, struct v4l2_m2m_buffer, vb);
>> +	struct v4l2_m2m_buffer *b = container_of(cb, struct v4l2_m2m_buffer, vb);
>>   	struct v4l2_m2m_queue_ctx *q_ctx;
>>   	unsigned long flags;
>>   
>> -	q_ctx = get_queue_ctx(m2m_ctx, vb->vb2.vb2_queue->type);
>> +	q_ctx = get_queue_ctx(m2m_ctx, cb->vb2.vb2_queue->type);
>>   	if (!q_ctx)
>>   		return;
>>   
>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
>> index 0d8bd9a..5f75937 100644
>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>> @@ -1,5 +1,5 @@
>>   /*
>> - * videobuf2-core.c - V4L2 driver helper framework
>> + * videobuf2-core.c - Video Buffer 2 framework
>>    *
>>    * Copyright (C) 2010 Samsung Electronics
>>    *
>> @@ -28,3492 +28,8 @@
>>   #include <media/v4l2-fh.h>
>>   #include <media/v4l2-event.h>
>>   #include <media/v4l2-common.h>
>> -#include <media/videobuf2-core.h>
>> +#include <media/videobuf2-v4l2.h>
>> -static int debug;
> ... (lots of lines removed here
>> -EXPORT_SYMBOL_GPL(vb2_ops_wait_finish);
>>   
>>   MODULE_DESCRIPTION("Driver helper framework for Video for Linux 2");
>>   MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>, Marek Szyprowski");
> Hmm... was most of this file just removed and just the above was
> preserved? This enforces the idea of just renaming it on the
> previous patch (as proposed on patches 0/3 and 1/3) and then
> creating a new one with the new content, moving out the functions
> added here from videobuf2-v4l2.c.
OK, I will rework for that.
>> diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
>> index cd28b4807f..fe07a2b 100644
>> --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
>> +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
>> @@ -51,12 +51,12 @@ module_param(debug, int, 0644);
>>   
>>   #define log_memop(vb, op)						\
>>   	dprintk(2, "call_memop(%p, %d, %s)%s\n",			\
>> -		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
>> -		(vb)->vb2.vb2_queue->mem_ops->op ? "" : " (nop)")
>> +		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
>> +		(vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
>>   
>>   #define call_memop(vb, op, args...)					\
>>   ({									\
>> -	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
>> +	struct vb2_queue *_q = (vb)->vb2_queue;				\
>>   	int err;							\
>>   									\
>>   	log_memop(vb, op);						\
>> @@ -68,7 +68,7 @@ module_param(debug, int, 0644);
>>   
>>   #define call_ptr_memop(vb, op, args...)					\
>>   ({									\
>> -	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
>> +	struct vb2_queue *_q = (vb)->vb2_queue;				\
>>   	void *ptr;							\
>>   									\
>>   	log_memop(vb, op);						\
>> @@ -80,7 +80,7 @@ module_param(debug, int, 0644);
>>   
>>   #define call_void_memop(vb, op, args...)				\
>>   ({									\
>> -	struct vb2_queue *_q = (vb)->vb2.vb2_queue;				\
>> +	struct vb2_queue *_q = (vb)->vb2_queue;				\
>>   									\
>>   	log_memop(vb, op);						\
>>   	if (_q->mem_ops->op)						\
>> @@ -113,16 +113,16 @@ module_param(debug, int, 0644);
>>   
>>   #define log_vb_qop(vb, op, args...)					\
>>   	dprintk(2, "call_vb_qop(%p, %d, %s)%s\n",			\
>> -		(vb)->vb2.vb2_queue, (vb)->v4l2_buf.index, #op,		\
>> -		(vb)->vb2.vb2_queue->ops->op ? "" : " (nop)")
>> +		(vb)->vb2_queue, (vb)->v4l2_buf.index, #op,		\
>> +		(vb)->vb2_queue->ops->op ? "" : " (nop)")
>>   
>>   #define call_vb_qop(vb, op, args...)					\
>>   ({									\
>>   	int err;							\
>>   									\
>>   	log_vb_qop(vb, op);						\
>> -	err = (vb)->vb2.vb2_queue->ops->op ?				\
>> -		(vb)->vb2.vb2_queue->ops->op(args) : 0;			\
>> +	err = (vb)->vb2_queue->ops->op ?				\
>> +		(vb)->vb2_queue->ops->op(args) : 0;			\
>>   	if (!err)							\
>>   		(vb)->cnt_ ## op++;					\
>>   	err;								\
>> @@ -131,25 +131,25 @@ module_param(debug, int, 0644);
>>   #define call_void_vb_qop(vb, op, args...)				\
>>   ({									\
>>   	log_vb_qop(vb, op);						\
>> -	if ((vb)->vb2.vb2_queue->ops->op)					\
>> -		(vb)->vb2.vb2_queue->ops->op(args);				\
>> +	if ((vb)->vb2_queue->ops->op)					\
>> +		(vb)->vb2_queue->ops->op(args);				\
>>   	(vb)->cnt_ ## op++;						\
>>   })
>>   
>>   #else
>>   
>>   #define call_memop(vb, op, args...)					\
>> -	((vb)->vb2.vb2_queue->mem_ops->op ?					\
>> -		(vb)->vb2.vb2_queue->mem_ops->op(args) : 0)
>> +	((vb)->vb2_queue->mem_ops->op ?					\
>> +		(vb)->vb2_queue->mem_ops->op(args) : 0)
>>   
>>   #define call_ptr_memop(vb, op, args...)					\
>> -	((vb)->vb2.vb2_queue->mem_ops->op ?					\
>> -		(vb)->vb2.vb2_queue->mem_ops->op(args) : NULL)
>> +	((vb)->vb2_queue->mem_ops->op ?					\
>> +		(vb)->vb2_queue->mem_ops->op(args) : NULL)
>>   
>>   #define call_void_memop(vb, op, args...)				\
>>   	do {								\
>> -		if ((vb)->vb2.vb2_queue->mem_ops->op)			\
>> -			(vb)->vb2.vb2_queue->mem_ops->op(args);		\
>> +		if ((vb)->vb2_queue->mem_ops->op)			\
>> +			(vb)->vb2_queue->mem_ops->op(args);		\
>>   	} while (0)
>>   
>>   #define call_qop(q, op, args...)					\
>> @@ -162,12 +162,12 @@ module_param(debug, int, 0644);
>>   	} while (0)
>>   
>>   #define call_vb_qop(vb, op, args...)					\
>> -	((vb)->vb2.vb2_queue->ops->op ? (vb)->vb2.vb2_queue->ops->op(args) : 0)
>> +	((vb)->vb2_queue->ops->op ? (vb)->vb2_queue->ops->op(args) : 0)
>>   
>>   #define call_void_vb_qop(vb, op, args...)				\
>>   	do {								\
>> -		if ((vb)->vb2.vb2_queue->ops->op)				\
>> -			(vb)->vb2.vb2_queue->ops->op(args);			\
>> +		if ((vb)->vb2_queue->ops->op)				\
>> +			(vb)->vb2_queue->ops->op(args);			\
>>   	} while (0)
>>   
>>   #endif
>> @@ -186,9 +186,10 @@ static void __vb2_queue_cancel(struct vb2_queue *q);
>>   /**
>>    * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
>>    */
>> -static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
>> +static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *cb)
> Why are you called the v4l2 buffer as "cb"? At least for me, "cb" would
> be an alias "common buffer". So, I would be expecting just the reverse ;)
'cb' means 'container buffer'. When vb2_buffer and vb2_v4l2_buffer are 
used together,
I needed new naming rule. So I used 'cb' to refer struct vb2_v4l2_buffer.
But, I will rework this patch.
Let me know if you have more efficient way to do naming these two structure.

>>   {
>> -	struct vb2_queue *q = vb->vb2.vb2_queue;
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	struct vb2_queue *q = vb->vb2_queue;
>>   	enum dma_data_direction dma_dir =
>>   		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
>>   	void *mem_priv;
>> @@ -198,7 +199,7 @@ static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
>>   	 * Allocate memory for all planes in this buffer
>>   	 * NOTE: mmapped areas should be page aligned
>>   	 */
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>>   		unsigned long size = PAGE_ALIGN(q->plane_sizes[plane]);
>>   
>>   		mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
>> @@ -207,16 +208,16 @@ static int __vb2_buf_mem_alloc(struct vb2_v4l2_buffer *vb)
>>   			goto free;
>>   
>>   		/* Associate allocator private data with this plane */
>> -		vb->vb2.planes[plane].mem_priv = mem_priv;
>> -		vb->v4l2_planes[plane].length = q->plane_sizes[plane];
>> +		vb->planes[plane].mem_priv = mem_priv;
>> +		cb->v4l2_planes[plane].length = q->plane_sizes[plane];
>>   	}
>>   
>>   	return 0;
>>   free:
>>   	/* Free already allocated memory if one of the allocations failed */
>>   	for (; plane > 0; --plane) {
>> -		call_void_memop(vb, put, vb->vb2.planes[plane - 1].mem_priv);
>> -		vb->vb2.planes[plane - 1].mem_priv = NULL;
>> +		call_void_memop(vb, put, vb->planes[plane - 1].mem_priv);
>> +		vb->planes[plane - 1].mem_priv = NULL;
>>   	}
>>   
>>   	return -ENOMEM;
>> @@ -225,15 +226,16 @@ free:
>>   /**
>>    * __vb2_buf_mem_free() - free memory of the given buffer
>>    */
>> -static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
>> +static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *cb)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	unsigned int plane;
>>   
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> -		call_void_memop(vb, put, vb->vb2.planes[plane].mem_priv);
>> -		vb->vb2.planes[plane].mem_priv = NULL;
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>> +		call_void_memop(vb, put, vb->planes[plane].mem_priv);
>> +		vb->planes[plane].mem_priv = NULL;
>>   		dprintk(3, "freed plane %d of buffer %d\n", plane,
>> -			vb->v4l2_buf.index);
>> +			cb->v4l2_buf.index);
>>   	}
>>   }
>>   
>> @@ -241,14 +243,15 @@ static void __vb2_buf_mem_free(struct vb2_v4l2_buffer *vb)
>>    * __vb2_buf_userptr_put() - release userspace memory associated with
>>    * a USERPTR buffer
>>    */
>> -static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
>> +static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *cb)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	unsigned int plane;
>>   
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> -		if (vb->vb2.planes[plane].mem_priv)
>> -			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
>> -		vb->vb2.planes[plane].mem_priv = NULL;
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>> +		if (vb->planes[plane].mem_priv)
>> +			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
>> +		vb->planes[plane].mem_priv = NULL;
>>   	}
>>   }
>>   
>> @@ -256,8 +259,9 @@ static void __vb2_buf_userptr_put(struct vb2_v4l2_buffer *vb)
>>    * __vb2_plane_dmabuf_put() - release memory associated with
>>    * a DMABUF shared plane
>>    */
>> -static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane *p)
>> +static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *cb, struct vb2_plane *p)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	if (!p->mem_priv)
>>   		return;
>>   
>> @@ -273,12 +277,13 @@ static void __vb2_plane_dmabuf_put(struct vb2_v4l2_buffer *vb, struct vb2_plane
>>    * __vb2_buf_dmabuf_put() - release memory associated with
>>    * a DMABUF shared buffer
>>    */
>> -static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
>> +static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *cb)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	unsigned int plane;
>>   
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
>> -		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
>> +	for (plane = 0; plane < vb->num_planes; ++plane)
>> +		__vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
>>   }
>>   
>>   /**
>> @@ -288,15 +293,17 @@ static void __vb2_buf_dmabuf_put(struct vb2_v4l2_buffer *vb)
>>   static void __setup_lengths(struct vb2_queue *q, unsigned int n)
>>   {
>>   	unsigned int buffer, plane;
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   
>>   	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
>>   		vb = q->bufs[buffer];
>>   		if (!vb)
>>   			continue;
>>   
>> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane)
>> -			vb->v4l2_planes[plane].length = q->plane_sizes[plane];
>> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>> +		for (plane = 0; plane < vb->num_planes; ++plane)
>> +			cb->v4l2_planes[plane].length = q->plane_sizes[plane];
>>   	}
>>   }
>>   
>> @@ -307,13 +314,15 @@ static void __setup_lengths(struct vb2_queue *q, unsigned int n)
>>   static void __setup_offsets(struct vb2_queue *q, unsigned int n)
>>   {
>>   	unsigned int buffer, plane;
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	unsigned long off;
>>   
>>   	if (q->num_buffers) {
>>   		struct v4l2_plane *p;
>>   		vb = q->bufs[q->num_buffers - 1];
>> -		p = &vb->v4l2_planes[vb->vb2.num_planes - 1];
>> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>> +		p = &cb->v4l2_planes[vb->num_planes - 1];
>>   		off = PAGE_ALIGN(p->m.mem_offset + p->length);
>>   	} else {
>>   		off = 0;
>> @@ -324,13 +333,14 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
>>   		if (!vb)
>>   			continue;
>>   
>> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> -			vb->v4l2_planes[plane].m.mem_offset = off;
>> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>> +		for (plane = 0; plane < vb->num_planes; ++plane) {
>> +			cb->v4l2_planes[plane].m.mem_offset = off;
>>   
>>   			dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
>>   					buffer, plane, off);
>>   
>> -			off += vb->v4l2_planes[plane].length;
>> +			off += cb->v4l2_planes[plane].length;
>>   			off = PAGE_ALIGN(off);
>>   		}
>>   	}
>> @@ -347,35 +357,37 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
>>   			     unsigned int num_buffers, unsigned int num_planes)
>>   {
>>   	unsigned int buffer;
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	int ret;
>>   
>>   	for (buffer = 0; buffer < num_buffers; ++buffer) {
>>   		/* Allocate videobuf buffer structures */
>> -		vb = kzalloc(q->buf_struct_size, GFP_KERNEL);
>> -		if (!vb) {
>> +		cb = kzalloc(q->buf_struct_size, GFP_KERNEL);
>> +		if (!cb) {
>>   			dprintk(1, "memory alloc for buffer struct failed\n");
>>   			break;
>>   		}
>>   
>> +		vb = &cb->vb2;
>>   		/* Length stores number of planes for multiplanar buffers */
>>   		if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
>> -			vb->v4l2_buf.length = num_planes;
>> +			cb->v4l2_buf.length = num_planes;
>>   
>> -		vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
>> -		vb->vb2.vb2_queue = q;
>> -		vb->vb2.num_planes = num_planes;
>> -		vb->v4l2_buf.index = q->num_buffers + buffer;
>> -		vb->v4l2_buf.type = q->type;
>> -		vb->v4l2_buf.memory = memory;
>> +		vb->state = VB2_BUF_STATE_DEQUEUED;
>> +		vb->vb2_queue = q;
>> +		vb->num_planes = num_planes;
>> +		cb->v4l2_buf.index = q->num_buffers + buffer;
>> +		cb->v4l2_buf.type = q->type;
>> +		cb->v4l2_buf.memory = memory;
>>   
>>   		/* Allocate video buffer memory for the MMAP type */
>>   		if (memory == V4L2_MEMORY_MMAP) {
>> -			ret = __vb2_buf_mem_alloc(vb);
>> +			ret = __vb2_buf_mem_alloc(cb);
>>   			if (ret) {
>>   				dprintk(1, "failed allocating memory for "
>>   						"buffer %d\n", buffer);
>> -				kfree(vb);
>> +				kfree(cb);
>>   				break;
>>   			}
>>   			/*
>> @@ -387,8 +399,8 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
>>   			if (ret) {
>>   				dprintk(1, "buffer %d %p initialization"
>>   					" failed\n", buffer, vb);
>> -				__vb2_buf_mem_free(vb);
>> -				kfree(vb);
>> +				__vb2_buf_mem_free(cb);
>> +				kfree(cb);
>>   				break;
>>   			}
>>   		}
>> @@ -412,21 +424,23 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
>>   static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
>>   {
>>   	unsigned int buffer;
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   
>>   	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
>>   	     ++buffer) {
>>   		vb = q->bufs[buffer];
>>   		if (!vb)
>>   			continue;
>> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   
>>   		/* Free MMAP buffers or release USERPTR buffers */
>>   		if (q->memory == V4L2_MEMORY_MMAP)
>> -			__vb2_buf_mem_free(vb);
>> +			__vb2_buf_mem_free(cb);
>>   		else if (q->memory == V4L2_MEMORY_DMABUF)
>> -			__vb2_buf_dmabuf_put(vb);
>> +			__vb2_buf_dmabuf_put(cb);
>>   		else
>> -			__vb2_buf_userptr_put(vb);
>> +			__vb2_buf_userptr_put(cb);
>>   	}
>>   }
>>   
>> @@ -438,7 +452,7 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
>>   static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>>   {
>>   	unsigned int buffer;
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_buffer *vb;
>>   
>>   	/*
>>   	 * Sanity check: when preparing a buffer the queue lock is released for
>> @@ -450,11 +464,11 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>>   	 */
>>   	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
>>   	     ++buffer) {
>> -		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
>> +		vb = q->bufs[buffer];
>>   
>>   		if (vb == NULL)
>>   			continue;
>> -		if (vb->vb2.state == VB2_BUF_STATE_PREPARING) {
>> +		if (vb->state == VB2_BUF_STATE_PREPARING) {
>>   			dprintk(1, "preparing buffers, cannot free\n");
>>   			return -EAGAIN;
>>   		}
>> @@ -463,9 +477,9 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>>   	/* Call driver-provided cleanup function for each buffer, if provided */
>>   	for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
>>   	     ++buffer) {
>> -		vb = (struct vb2_v4l2_buffer *)q->bufs[buffer];
>> +		vb = q->bufs[buffer];
>>   
>> -		if (vb && vb->vb2.planes[0].mem_priv)
>> +		if (vb && vb->planes[0].mem_priv)
>>   			call_void_vb_qop(vb, buf_cleanup, vb);
>>   	}
>>   
>> @@ -498,38 +512,38 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>>   		q->cnt_stop_streaming = 0;
>>   	}
>>   	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
>> -		struct vb2_v4l2_buffer *vb = q->bufs[buffer];
>> -		bool unbalanced = vb->vb2.cnt_mem_alloc != vb->vb2.cnt_mem_put ||
>> -				  vb->vb2.cnt_mem_prepare != vb->vb2.cnt_mem_finish ||
>> -				  vb->vb2.cnt_mem_get_userptr != vb->vb2.cnt_mem_put_userptr ||
>> -				  vb->vb2.cnt_mem_attach_dmabuf != vb->vb2.cnt_mem_detach_dmabuf ||
>> -				  vb->vb2.cnt_mem_map_dmabuf != vb->vb2.cnt_mem_unmap_dmabuf ||
>> -				  vb->vb2.cnt_buf_queue != vb->vb2.cnt_buf_done ||
>> -				  vb->vb2.cnt_buf_prepare != vb->vb2.cnt_buf_finish ||
>> -				  vb->vb2.cnt_buf_init != vb->vb2.cnt_buf_cleanup;
>> +		struct vb2_buffer *vb = q->bufs[buffer];
>> +		bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put ||
>> +				  vb->cnt_mem_prepare != vb->cnt_mem_finish ||
>> +				  vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr ||
>> +				  vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf ||
>> +				  vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf ||
>> +				  vb->cnt_buf_queue != vb->cnt_buf_done ||
>> +				  vb->cnt_buf_prepare != vb->cnt_buf_finish ||
>> +				  vb->cnt_buf_init != vb->cnt_buf_cleanup;
>>   
>>   		if (unbalanced || debug) {
>>   			pr_info("vb2:   counters for queue %p, buffer %d:%s\n",
>>   				q, buffer, unbalanced ? " UNBALANCED!" : "");
>>   			pr_info("vb2:     buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n",
>> -				vb->vb2.cnt_buf_init, vb->vb2.cnt_buf_cleanup,
>> -				vb->vb2.cnt_buf_prepare, vb->vb2.cnt_buf_finish);
>> +				vb->cnt_buf_init, vb->cnt_buf_cleanup,
>> +				vb->cnt_buf_prepare, vb->cnt_buf_finish);
>>   			pr_info("vb2:     buf_queue: %u buf_done: %u\n",
>> -				vb->vb2.cnt_buf_queue, vb->vb2.cnt_buf_done);
>> +				vb->cnt_buf_queue, vb->cnt_buf_done);
>>   			pr_info("vb2:     alloc: %u put: %u prepare: %u finish: %u mmap: %u\n",
>> -				vb->vb2.cnt_mem_alloc, vb->vb2.cnt_mem_put,
>> -				vb->vb2.cnt_mem_prepare, vb->vb2.cnt_mem_finish,
>> -				vb->vb2.cnt_mem_mmap);
>> +				vb->cnt_mem_alloc, vb->cnt_mem_put,
>> +				vb->cnt_mem_prepare, vb->cnt_mem_finish,
>> +				vb->cnt_mem_mmap);
>>   			pr_info("vb2:     get_userptr: %u put_userptr: %u\n",
>> -				vb->vb2.cnt_mem_get_userptr, vb->vb2.cnt_mem_put_userptr);
>> +				vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr);
>>   			pr_info("vb2:     attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n",
>> -				vb->vb2.cnt_mem_attach_dmabuf, vb->vb2.cnt_mem_detach_dmabuf,
>> -				vb->vb2.cnt_mem_map_dmabuf, vb->vb2.cnt_mem_unmap_dmabuf);
>> +				vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf,
>> +				vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf);
>>   			pr_info("vb2:     get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n",
>> -				vb->vb2.cnt_mem_get_dmabuf,
>> -				vb->vb2.cnt_mem_num_users,
>> -				vb->vb2.cnt_mem_vaddr,
>> -				vb->vb2.cnt_mem_cookie);
>> +				vb->cnt_mem_get_dmabuf,
>> +				vb->cnt_mem_num_users,
>> +				vb->cnt_mem_vaddr,
>> +				vb->cnt_mem_cookie);
>>   		}
>>   	}
>>   #endif
>> @@ -553,8 +567,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
>>    * __verify_planes_array() - verify that the planes array passed in struct
>>    * v4l2_buffer from userspace can be safely used
>>    */
>> -static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
>> +static int __verify_planes_array(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +
>>   	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
>>   		return 0;
>>   
>> @@ -565,9 +581,9 @@ static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_b
>>   		return -EINVAL;
>>   	}
>>   
>> -	if (b->length < vb->vb2.num_planes || b->length > VIDEO_MAX_PLANES) {
>> +	if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
>>   		dprintk(1, "incorrect planes array length, "
>> -			   "expected %d, got %d\n", vb->vb2.num_planes, b->length);
>> +			   "expected %d, got %d\n", vb->num_planes, b->length);
>>   		return -EINVAL;
>>   	}
>>   
>> @@ -578,8 +594,9 @@ static int __verify_planes_array(struct vb2_v4l2_buffer *vb, const struct v4l2_b
>>    * __verify_length() - Verify that the bytesused value for each plane fits in
>>    * the plane length and that the data offset doesn't exceed the bytesused value.
>>    */
>> -static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
>> +static int __verify_length(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	unsigned int length;
>>   	unsigned int bytesused;
>>   	unsigned int plane;
>> @@ -588,11 +605,11 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
>>   		return 0;
>>   
>>   	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
>> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> +		for (plane = 0; plane < vb->num_planes; ++plane) {
>>   			length = (b->memory == V4L2_MEMORY_USERPTR ||
>>   				  b->memory == V4L2_MEMORY_DMABUF)
>>   			       ? b->m.planes[plane].length
>> -			       : vb->v4l2_planes[plane].length;
>> +			       : cb->v4l2_planes[plane].length;
>>   			bytesused = b->m.planes[plane].bytesused
>>   				  ? b->m.planes[plane].bytesused : length;
>>   
>> @@ -605,7 +622,7 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
>>   		}
>>   	} else {
>>   		length = (b->memory == V4L2_MEMORY_USERPTR)
>> -		       ? b->length : vb->v4l2_planes[0].length;
>> +		       ? b->length : cb->v4l2_planes[0].length;
>>   		bytesused = b->bytesused ? b->bytesused : length;
>>   
>>   		if (b->bytesused > length)
>> @@ -619,11 +636,12 @@ static int __verify_length(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer
>>    * __buffer_in_use() - return true if the buffer is in use and
>>    * the queue cannot be freed (by the means of REQBUFS(0)) call
>>    */
>> -static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
>> +static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *cb)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	unsigned int plane;
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> -		void *mem_priv = vb->vb2.planes[plane].mem_priv;
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>> +		void *mem_priv = vb->planes[plane].mem_priv;
>>   		/*
>>   		 * If num_users() has not been provided, call_memop
>>   		 * will return 0, apparently nobody cares about this
>> @@ -642,9 +660,12 @@ static bool __buffer_in_use(struct vb2_queue *q, struct vb2_v4l2_buffer *vb)
>>    */
>>   static bool __buffers_in_use(struct vb2_queue *q)
>>   {
>> +	struct vb2_v4l2_buffer *cb;
>>   	unsigned int buffer;
>> +
>>   	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
>> -		if (__buffer_in_use(q, q->bufs[buffer]))
>> +		cb = container_of(q->bufs[buffer], struct vb2_v4l2_buffer, vb2);
>> +		if (__buffer_in_use(q, cb))
>>   			return true;
>>   	}
>>   	return false;
>> @@ -654,36 +675,37 @@ static bool __buffers_in_use(struct vb2_queue *q)
>>    * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
>>    * returned to userspace
>>    */
>> -static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b)
>> +static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *cb, struct v4l2_buffer *b)
>>   {
>> -	struct vb2_queue *q = vb->vb2.vb2_queue;
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	struct vb2_queue *q = vb->vb2_queue;
>>   
>>   	/* Copy back data such as timestamp, flags, etc. */
>> -	memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
>> -	b->reserved2 = vb->v4l2_buf.reserved2;
>> -	b->reserved = vb->v4l2_buf.reserved;
>> +	memcpy(b, &cb->v4l2_buf, offsetof(struct v4l2_buffer, m));
>> +	b->reserved2 = cb->v4l2_buf.reserved2;
>> +	b->reserved = cb->v4l2_buf.reserved;
>>   
>>   	if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) {
>>   		/*
>>   		 * Fill in plane-related data if userspace provided an array
>>   		 * for it. The caller has already verified memory and size.
>>   		 */
>> -		b->length = vb->vb2.num_planes;
>> -		memcpy(b->m.planes, vb->v4l2_planes,
>> +		b->length = vb->num_planes;
>> +		memcpy(b->m.planes, cb->v4l2_planes,
>>   			b->length * sizeof(struct v4l2_plane));
>>   	} else {
>>   		/*
>>   		 * We use length and offset in v4l2_planes array even for
>>   		 * single-planar buffers, but userspace does not.
>>   		 */
>> -		b->length = vb->v4l2_planes[0].length;
>> -		b->bytesused = vb->v4l2_planes[0].bytesused;
>> +		b->length = cb->v4l2_planes[0].length;
>> +		b->bytesused = cb->v4l2_planes[0].bytesused;
>>   		if (q->memory == V4L2_MEMORY_MMAP)
>> -			b->m.offset = vb->v4l2_planes[0].m.mem_offset;
>> +			b->m.offset = cb->v4l2_planes[0].m.mem_offset;
>>   		else if (q->memory == V4L2_MEMORY_USERPTR)
>> -			b->m.userptr = vb->v4l2_planes[0].m.userptr;
>> +			b->m.userptr = cb->v4l2_planes[0].m.userptr;
>>   		else if (q->memory == V4L2_MEMORY_DMABUF)
>> -			b->m.fd = vb->v4l2_planes[0].m.fd;
>> +			b->m.fd = cb->v4l2_planes[0].m.fd;
>>   	}
>>   
>>   	/*
>> @@ -701,7 +723,7 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
>>   		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
>>   	}
>>   
>> -	switch (vb->vb2.state) {
>> +	switch (vb->state) {
>>   	case VB2_BUF_STATE_QUEUED:
>>   	case VB2_BUF_STATE_ACTIVE:
>>   		b->flags |= V4L2_BUF_FLAG_QUEUED;
>> @@ -721,7 +743,7 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
>>   		break;
>>   	}
>>   
>> -	if (__buffer_in_use(q, vb))
>> +	if (__buffer_in_use(q, cb))
>>   		b->flags |= V4L2_BUF_FLAG_MAPPED;
>>   }
>>   
>> @@ -740,7 +762,8 @@ static void __fill_v4l2_buffer(struct vb2_v4l2_buffer *vb, struct v4l2_buffer *b
>>    */
>>   int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   {
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	int ret;
>>   
>>   	if (b->type != q->type) {
>> @@ -753,9 +776,10 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   		return -EINVAL;
>>   	}
>>   	vb = q->bufs[b->index];
>> -	ret = __verify_planes_array(vb, b);
>> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>> +	ret = __verify_planes_array(cb, b);
>>   	if (!ret)
>> -		__fill_v4l2_buffer(vb, b);
>> +		__fill_v4l2_buffer(cb, b);
>>   	return ret;
>>   }
>>   EXPORT_SYMBOL(vb2_querybuf);
>> @@ -1123,12 +1147,13 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs);
>>    * This function returns a kernel virtual address of a given plane if
>>    * such a mapping exist, NULL otherwise.
>>    */
>> -void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>>   {
>> -	if (plane_no > vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv)
>>   		return NULL;
>>   
>> -	return call_ptr_memop(vb, vaddr, vb->vb2.planes[plane_no].mem_priv);
>> +	return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv);
>>   
>>   }
>>   EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
>> @@ -1140,16 +1165,17 @@ EXPORT_SYMBOL_GPL(vb2_plane_vaddr);
>>    *
>>    * This function returns an allocator specific cookie for a given plane if
>>    * available, NULL otherwise. The allocator should provide some simple static
>> - * inline funaction, which would convert this cookie to the allocator specific
>> + * inline function, which would convert this cookie to the allocator specific
>>    * type that can be used directly by the driver to access the buffer. This can
>>    * be for example physical address, pointer to scatter list or IOMMU mapping.
>>    */
>> -void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>>   {
>> -	if (plane_no >= vb->vb2.num_planes || !vb->vb2.planes[plane_no].mem_priv)
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv)
>>   		return NULL;
>>   
>> -	return call_ptr_memop(vb, cookie, vb->vb2.planes[plane_no].mem_priv);
>> +	return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv);
>>   }
>>   EXPORT_SYMBOL_GPL(vb2_plane_cookie);
>>   
>> @@ -1172,13 +1198,14 @@ EXPORT_SYMBOL_GPL(vb2_plane_cookie);
>>    * be started for some reason. In that case the buffers should be returned with
>>    * state QUEUED.
>>    */
>> -void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
>> +void vb2_buffer_done(struct vb2_v4l2_buffer *cb, enum vb2_buffer_state state)
>>   {
>> -	struct vb2_queue *q = vb->vb2.vb2_queue;
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	struct vb2_queue *q = vb->vb2_queue;
>>   	unsigned long flags;
>>   	unsigned int plane;
>>   
>> -	if (WARN_ON(vb->vb2.state != VB2_BUF_STATE_ACTIVE))
>> +	if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
>>   		return;
>>   
>>   	if (WARN_ON(state != VB2_BUF_STATE_DONE &&
>> @@ -1191,20 +1218,20 @@ void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state)
>>   	 * Although this is not a callback, it still does have to balance
>>   	 * with the buf_queue op. So update this counter manually.
>>   	 */
>> -	vb->vb2.cnt_buf_done++;
>> +	vb->cnt_buf_done++;
>>   #endif
>>   	dprintk(4, "done processing on buffer %d, state: %d\n",
>> -			vb->v4l2_buf.index, state);
>> +			cb->v4l2_buf.index, state);
>>   
>>   	/* sync buffers */
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
>> -		call_void_memop(vb, finish, vb->vb2.planes[plane].mem_priv);
>> +	for (plane = 0; plane < vb->num_planes; ++plane)
>> +		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
>>   
>>   	/* Add the buffer to the done buffers list */
>>   	spin_lock_irqsave(&q->done_lock, flags);
>> -	vb->vb2.state = state;
>> +	vb->state = state;
>>   	if (state != VB2_BUF_STATE_QUEUED)
>> -		list_add_tail(&vb->vb2.done_entry, &q->done_list);
>> +		list_add_tail(&vb->done_entry, &q->done_list);
>>   	atomic_dec(&q->owned_by_drv_count);
>>   	spin_unlock_irqrestore(&q->done_lock, flags);
>>   
>> @@ -1245,14 +1272,15 @@ EXPORT_SYMBOL_GPL(vb2_discard_done);
>>    * v4l2_buffer by the userspace. The caller has already verified that struct
>>    * v4l2_buffer has a valid number of planes.
>>    */
>> -static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b,
>> +static void __fill_vb2_buffer(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b,
>>   				struct v4l2_plane *v4l2_planes)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	unsigned int plane;
>>   
>>   	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
>>   		if (b->memory == V4L2_MEMORY_USERPTR) {
>> -			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> +			for (plane = 0; plane < vb->num_planes; ++plane) {
>>   				v4l2_planes[plane].m.userptr =
>>   					b->m.planes[plane].m.userptr;
>>   				v4l2_planes[plane].length =
>> @@ -1260,7 +1288,7 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>>   			}
>>   		}
>>   		if (b->memory == V4L2_MEMORY_DMABUF) {
>> -			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> +			for (plane = 0; plane < vb->num_planes; ++plane) {
>>   				v4l2_planes[plane].m.fd =
>>   					b->m.planes[plane].m.fd;
>>   				v4l2_planes[plane].length =
>> @@ -1280,7 +1308,7 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>>   			 * it's a safe assumption that they really meant to
>>   			 * use the full plane sizes.
>>   			 */
>> -			for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> +			for (plane = 0; plane < vb->num_planes; ++plane) {
>>   				struct v4l2_plane *pdst = &v4l2_planes[plane];
>>   				struct v4l2_plane *psrc = &b->m.planes[plane];
>>   
>> @@ -1318,15 +1346,15 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>>   	}
>>   
>>   	/* Zero flags that the vb2 core handles */
>> -	vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
>> -	if ((vb->vb2.vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
>> +	cb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
>> +	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
>>   	    V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
>>   		/*
>>   		 * Non-COPY timestamps and non-OUTPUT queues will get
>>   		 * their timestamp and timestamp source flags from the
>>   		 * queue.
>>   		 */
>> -		vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
>> +		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
>>   	}
>>   
>>   	if (V4L2_TYPE_IS_OUTPUT(b->type)) {
>> @@ -1336,46 +1364,48 @@ static void __fill_vb2_buffer(struct vb2_v4l2_buffer *vb, const struct v4l2_buff
>>   		 * The 'field' is valid metadata for this output buffer
>>   		 * and so that needs to be copied here.
>>   		 */
>> -		vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
>> -		vb->v4l2_buf.field = b->field;
>> +		cb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
>> +		cb->v4l2_buf.field = b->field;
>>   	} else {
>>   		/* Zero any output buffer flags as this is a capture buffer */
>> -		vb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
>> +		cb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
>>   	}
>>   }
>>   
>>   /**
>>    * __qbuf_mmap() - handle qbuf of an MMAP buffer
>>    */
>> -static int __qbuf_mmap(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
>> +static int __qbuf_mmap(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>>   {
>> -	__fill_vb2_buffer(vb, b, vb->v4l2_planes);
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	__fill_vb2_buffer(cb, b, cb->v4l2_planes);
>>   	return call_vb_qop(vb, buf_prepare, vb);
>>   }
>>   
>>   /**
>>    * __qbuf_userptr() - handle qbuf of a USERPTR buffer
>>    */
>> -static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
>> +static int __qbuf_userptr(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	struct v4l2_plane planes[VIDEO_MAX_PLANES];
>> -	struct vb2_queue *q = vb->vb2.vb2_queue;
>> +	struct vb2_queue *q = vb->vb2_queue;
>>   	void *mem_priv;
>>   	unsigned int plane;
>>   	int ret;
>>   	enum dma_data_direction dma_dir =
>>   		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
>> -	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
>> +	bool reacquired = vb->planes[0].mem_priv == NULL;
>>   
>> -	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
>> +	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
>>   	/* Copy relevant information provided by the userspace */
>> -	__fill_vb2_buffer(vb, b, planes);
>> +	__fill_vb2_buffer(cb, b, planes);
>>   
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>>   		/* Skip the plane if already verified */
>> -		if (vb->v4l2_planes[plane].m.userptr &&
>> -		    vb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
>> -		    && vb->v4l2_planes[plane].length == planes[plane].length)
>> +		if (cb->v4l2_planes[plane].m.userptr &&
>> +		    cb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
>> +		    && cb->v4l2_planes[plane].length == planes[plane].length)
>>   			continue;
>>   
>>   		dprintk(3, "userspace address for plane %d changed, "
>> @@ -1392,16 +1422,16 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
>>   		}
>>   
>>   		/* Release previously acquired memory if present */
>> -		if (vb->vb2.planes[plane].mem_priv) {
>> +		if (vb->planes[plane].mem_priv) {
>>   			if (!reacquired) {
>>   				reacquired = true;
>>   				call_void_vb_qop(vb, buf_cleanup, vb);
>>   			}
>> -			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
>> +			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
>>   		}
>>   
>> -		vb->vb2.planes[plane].mem_priv = NULL;
>> -		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
>> +		vb->planes[plane].mem_priv = NULL;
>> +		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
>>   
>>   		/* Acquire each plane's memory */
>>   		mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane],
>> @@ -1413,15 +1443,15 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
>>   			ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
>>   			goto err;
>>   		}
>> -		vb->vb2.planes[plane].mem_priv = mem_priv;
>> +		vb->planes[plane].mem_priv = mem_priv;
>>   	}
>>   
>>   	/*
>>   	 * Now that everything is in order, copy relevant information
>>   	 * provided by userspace.
>>   	 */
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
>> -		vb->v4l2_planes[plane] = planes[plane];
>> +	for (plane = 0; plane < vb->num_planes; ++plane)
>> +		cb->v4l2_planes[plane] = planes[plane];
>>   
>>   	if (reacquired) {
>>   		/*
>> @@ -1446,12 +1476,12 @@ static int __qbuf_userptr(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *
>>   	return 0;
>>   err:
>>   	/* In case of errors, release planes that were already acquired */
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> -		if (vb->vb2.planes[plane].mem_priv)
>> -			call_void_memop(vb, put_userptr, vb->vb2.planes[plane].mem_priv);
>> -		vb->vb2.planes[plane].mem_priv = NULL;
>> -		vb->v4l2_planes[plane].m.userptr = 0;
>> -		vb->v4l2_planes[plane].length = 0;
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>> +		if (vb->planes[plane].mem_priv)
>> +			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
>> +		vb->planes[plane].mem_priv = NULL;
>> +		cb->v4l2_planes[plane].m.userptr = 0;
>> +		cb->v4l2_planes[plane].length = 0;
>>   	}
>>   
>>   	return ret;
>> @@ -1460,22 +1490,23 @@ err:
>>   /**
>>    * __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
>>    */
>> -static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
>> +static int __qbuf_dmabuf(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>>   {
>> +	struct vb2_buffer *vb = &cb->vb2;
>>   	struct v4l2_plane planes[VIDEO_MAX_PLANES];
>> -	struct vb2_queue *q = vb->vb2.vb2_queue;
>> +	struct vb2_queue *q = vb->vb2_queue;
>>   	void *mem_priv;
>>   	unsigned int plane;
>>   	int ret;
>>   	enum dma_data_direction dma_dir =
>>   		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
>> -	bool reacquired = vb->vb2.planes[0].mem_priv == NULL;
>> +	bool reacquired = vb->planes[0].mem_priv == NULL;
>>   
>> -	memset(planes, 0, sizeof(planes[0]) * vb->vb2.num_planes);
>> +	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
>>   	/* Copy relevant information provided by the userspace */
>> -	__fill_vb2_buffer(vb, b, planes);
>> +	__fill_vb2_buffer(cb, b, planes);
>>   
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>>   		struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
>>   
>>   		if (IS_ERR_OR_NULL(dbuf)) {
>> @@ -1497,8 +1528,8 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>>   		}
>>   
>>   		/* Skip the plane if already verified */
>> -		if (dbuf == vb->vb2.planes[plane].dbuf &&
>> -		    vb->v4l2_planes[plane].length == planes[plane].length) {
>> +		if (dbuf == vb->planes[plane].dbuf &&
>> +		    cb->v4l2_planes[plane].length == planes[plane].length) {
>>   			dma_buf_put(dbuf);
>>   			continue;
>>   		}
>> @@ -1511,8 +1542,8 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>>   		}
>>   
>>   		/* Release previously acquired memory if present */
>> -		__vb2_plane_dmabuf_put(vb, &vb->vb2.planes[plane]);
>> -		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
>> +		__vb2_plane_dmabuf_put(cb, &vb->planes[plane]);
>> +		memset(&cb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
>>   
>>   		/* Acquire each plane's memory */
>>   		mem_priv = call_ptr_memop(vb, attach_dmabuf, q->alloc_ctx[plane],
>> @@ -1524,30 +1555,30 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>>   			goto err;
>>   		}
>>   
>> -		vb->vb2.planes[plane].dbuf = dbuf;
>> -		vb->vb2.planes[plane].mem_priv = mem_priv;
>> +		vb->planes[plane].dbuf = dbuf;
>> +		vb->planes[plane].mem_priv = mem_priv;
>>   	}
>>   
>>   	/* TODO: This pins the buffer(s) with  dma_buf_map_attachment()).. but
>>   	 * really we want to do this just before the DMA, not while queueing
>>   	 * the buffer(s)..
>>   	 */
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> -		ret = call_memop(vb, map_dmabuf, vb->vb2.planes[plane].mem_priv);
>> +	for (plane = 0; plane < vb->num_planes; ++plane) {
>> +		ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv);
>>   		if (ret) {
>>   			dprintk(1, "failed to map dmabuf for plane %d\n",
>>   				plane);
>>   			goto err;
>>   		}
>> -		vb->vb2.planes[plane].dbuf_mapped = 1;
>> +		vb->planes[plane].dbuf_mapped = 1;
>>   	}
>>   
>>   	/*
>>   	 * Now that everything is in order, copy relevant information
>>   	 * provided by userspace.
>>   	 */
>> -	for (plane = 0; plane < vb->vb2.num_planes; ++plane)
>> -		vb->v4l2_planes[plane] = planes[plane];
>> +	for (plane = 0; plane < vb->num_planes; ++plane)
>> +		cb->v4l2_planes[plane] = planes[plane];
>>   
>>   	if (reacquired) {
>>   		/*
>> @@ -1571,7 +1602,7 @@ static int __qbuf_dmabuf(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>>   	return 0;
>>   err:
>>   	/* In case of errors, release planes that were already acquired */
>> -	__vb2_buf_dmabuf_put(vb);
>> +	__vb2_buf_dmabuf_put(cb);
>>   
>>   	return ret;
>>   }
>> @@ -1581,7 +1612,6 @@ err:
>>    */
>>   static void __enqueue_in_driver(struct vb2_buffer *vb)
>>   {
>> -	struct vb2_v4l2_buffer *pb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   	struct vb2_queue *q = vb->vb2_queue;
>>   	unsigned int plane;
>>   
>> @@ -1590,17 +1620,18 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
>>   
>>   	/* sync buffers */
>>   	for (plane = 0; plane < vb->num_planes; ++plane)
>> -		call_void_memop(pb, prepare, vb->planes[plane].mem_priv);
>> +		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
>>   
>> -	call_void_vb_qop(pb, buf_queue, pb);
>> +	call_void_vb_qop(vb, buf_queue, vb);
>>   }
>>   
>> -static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b)
>> +static int __buf_prepare(struct vb2_v4l2_buffer *cb, const struct v4l2_buffer *b)
>>   {
>> -	struct vb2_queue *q = vb->vb2.vb2_queue;
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	struct vb2_queue *q = vb->vb2_queue;
>>   	int ret;
>>   
>> -	ret = __verify_length(vb, b);
>> +	ret = __verify_length(cb, b);
>>   	if (ret < 0) {
>>   		dprintk(1, "plane parameters verification failed: %d\n", ret);
>>   		return ret;
>> @@ -1624,22 +1655,22 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>>   		return -EIO;
>>   	}
>>   
>> -	vb->vb2.state = VB2_BUF_STATE_PREPARING;
>> -	vb->v4l2_buf.timestamp.tv_sec = 0;
>> -	vb->v4l2_buf.timestamp.tv_usec = 0;
>> -	vb->v4l2_buf.sequence = 0;
>> +	vb->state = VB2_BUF_STATE_PREPARING;
>> +	cb->v4l2_buf.timestamp.tv_sec = 0;
>> +	cb->v4l2_buf.timestamp.tv_usec = 0;
>> +	cb->v4l2_buf.sequence = 0;
>>   
>>   	switch (q->memory) {
>>   	case V4L2_MEMORY_MMAP:
>> -		ret = __qbuf_mmap(vb, b);
>> +		ret = __qbuf_mmap(cb, b);
>>   		break;
>>   	case V4L2_MEMORY_USERPTR:
>>   		down_read(&current->mm->mmap_sem);
>> -		ret = __qbuf_userptr(vb, b);
>> +		ret = __qbuf_userptr(cb, b);
>>   		up_read(&current->mm->mmap_sem);
>>   		break;
>>   	case V4L2_MEMORY_DMABUF:
>> -		ret = __qbuf_dmabuf(vb, b);
>> +		ret = __qbuf_dmabuf(cb, b);
>>   		break;
>>   	default:
>>   		WARN(1, "Invalid queue type\n");
>> @@ -1648,7 +1679,7 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>>   
>>   	if (ret)
>>   		dprintk(1, "buffer preparation failed: %d\n", ret);
>> -	vb->vb2.state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
>> +	vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED;
>>   
>>   	return ret;
>>   }
>> @@ -1656,6 +1687,8 @@ static int __buf_prepare(struct vb2_v4l2_buffer *vb, const struct v4l2_buffer *b
>>   static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
>>   				    const char *opname)
>>   {
>> +	struct vb2_v4l2_buffer *cb;
>> +
>>   	if (b->type != q->type) {
>>   		dprintk(1, "%s: invalid buffer type\n", opname);
>>   		return -EINVAL;
>> @@ -1677,7 +1710,9 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
>>   		return -EINVAL;
>>   	}
>>   
>> -	return __verify_planes_array(q->bufs[b->index], b);
>> +	cb = container_of(q->bufs[b->index], struct vb2_v4l2_buffer, vb2);
>> +
>> +	return __verify_planes_array(cb, b);
>>   }
>>   
>>   /**
>> @@ -1697,7 +1732,8 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b,
>>    */
>>   int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   {
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	int ret;
>>   
>>   	if (vb2_fileio_is_active(q)) {
>> @@ -1710,18 +1746,19 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   		return ret;
>>   
>>   	vb = q->bufs[b->index];
>> -	if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
>> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>> +	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
>>   		dprintk(1, "invalid buffer state %d\n",
>> -			vb->vb2.state);
>> +			vb->state);
>>   		return -EINVAL;
>>   	}
>>   
>> -	ret = __buf_prepare(vb, b);
>> +	ret = __buf_prepare(cb, b);
>>   	if (!ret) {
>>   		/* Fill buffer information for the userspace */
>> -		__fill_v4l2_buffer(vb, b);
>> +		__fill_v4l2_buffer(cb, b);
>>   
>> -		dprintk(1, "prepare of buffer %d succeeded\n", vb->v4l2_buf.index);
>> +		dprintk(1, "prepare of buffer %d succeeded\n", cb->v4l2_buf.index);
>>   	}
>>   	return ret;
>>   }
>> @@ -1741,7 +1778,7 @@ EXPORT_SYMBOL_GPL(vb2_prepare_buf);
>>   static int vb2_start_streaming(struct vb2_queue *q)
>>   {
>>   	struct vb2_buffer *vb;
>> -	struct vb2_v4l2_buffer *pb;
>> +	struct vb2_v4l2_buffer *cb;
>>   	int ret;
>>   
>>   	/*
>> @@ -1775,9 +1812,10 @@ static int vb2_start_streaming(struct vb2_queue *q)
>>   		 * correctly return them to vb2.
>>   		 */
>>   		for (i = 0; i < q->num_buffers; ++i) {
>> -			pb = q->bufs[i];
>> -			if (pb->vb2.state == VB2_BUF_STATE_ACTIVE)
>> -				vb2_buffer_done(pb, VB2_BUF_STATE_QUEUED);
>> +			vb = q->bufs[i];
>> +			cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>> +			if (vb->state == VB2_BUF_STATE_ACTIVE)
>> +				vb2_buffer_done(cb, VB2_BUF_STATE_QUEUED);
>>   		}
>>   		/* Must be zero now */
>>   		WARN_ON(atomic_read(&q->owned_by_drv_count));
>> @@ -1794,16 +1832,18 @@ static int vb2_start_streaming(struct vb2_queue *q)
>>   static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   {
>>   	int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   
>>   	if (ret)
>>   		return ret;
>>   
>>   	vb = q->bufs[b->index];
>> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   
>> -	switch (vb->vb2.state) {
>> +	switch (vb->state) {
>>   	case VB2_BUF_STATE_DEQUEUED:
>> -		ret = __buf_prepare(vb, b);
>> +		ret = __buf_prepare(cb, b);
>>   		if (ret)
>>   			return ret;
>>   		break;
>> @@ -1813,7 +1853,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   		dprintk(1, "buffer still being prepared\n");
>>   		return -EINVAL;
>>   	default:
>> -		dprintk(1, "invalid buffer state %d\n", vb->vb2.state);
>> +		dprintk(1, "invalid buffer state %d\n", vb->state);
>>   		return -EINVAL;
>>   	}
>>   
>> @@ -1821,10 +1861,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   	 * Add to the queued buffers list, a buffer will stay on it until
>>   	 * dequeued in dqbuf.
>>   	 */
>> -	list_add_tail(&vb->vb2.queued_entry, &q->queued_list);
>> +	list_add_tail(&vb->queued_entry, &q->queued_list);
>>   	q->queued_count++;
>>   	q->waiting_for_buffers = false;
>> -	vb->vb2.state = VB2_BUF_STATE_QUEUED;
>> +	vb->state = VB2_BUF_STATE_QUEUED;
>>   	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
>>   		/*
>>   		 * For output buffers copy the timestamp if needed,
>> @@ -1832,10 +1872,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   		 */
>>   		if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
>>   		    V4L2_BUF_FLAG_TIMESTAMP_COPY)
>> -			vb->v4l2_buf.timestamp = b->timestamp;
>> -		vb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
>> +			cb->v4l2_buf.timestamp = b->timestamp;
>> +		cb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
>>   		if (b->flags & V4L2_BUF_FLAG_TIMECODE)
>> -			vb->v4l2_buf.timecode = b->timecode;
>> +			cb->v4l2_buf.timecode = b->timecode;
>>   	}
>>   
>>   	/*
>> @@ -1843,10 +1883,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   	 * If not, the buffer will be given to driver on next streamon.
>>   	 */
>>   	if (q->start_streaming_called)
>> -		__enqueue_in_driver(&vb->vb2);
>> +		__enqueue_in_driver(vb);
>>   
>>   	/* Fill buffer information for the userspace */
>> -	__fill_v4l2_buffer(vb, b);
>> +	__fill_v4l2_buffer(cb, b);
>>   
>>   	/*
>>   	 * If streamon has been called, and we haven't yet called
>> @@ -1861,7 +1901,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
>>   			return ret;
>>   	}
>>   
>> -	dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index);
>> +	dprintk(1, "qbuf of buffer %d succeeded\n", cb->v4l2_buf.index);
>>   	return 0;
>>   }
>>   
>> @@ -1969,12 +2009,12 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
>>    *
>>    * Will sleep if required for nonblocking == false.
>>    */
>> -static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
>> +static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **cb,
>>   				struct v4l2_buffer *b, int nonblocking)
>>   {
>>   	unsigned long flags;
>>   	int ret;
>> -	struct vb2_buffer *vb2 = NULL;
>> +	struct vb2_buffer *vb = NULL;
>>   
>>   	/*
>>   	 * Wait for at least one buffer to become available on the done_list.
>> @@ -1988,15 +2028,15 @@ static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_v4l2_buffer **vb,
>>   	 * is not empty, so no need for another list_empty(done_list) check.
>>   	 */
>>   	spin_lock_irqsave(&q->done_lock, flags);
>> -	vb2 = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
>> -	*vb = container_of(vb2, struct vb2_v4l2_buffer, vb2);
>> +	vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry);
>> +	*cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   	/*
>>   	 * Only remove the buffer from done_list if v4l2_buffer can handle all
>>   	 * the planes.
>>   	 */
>> -	ret = __verify_planes_array(*vb, b);
>> +	ret = __verify_planes_array(*cb, b);
>>   	if (!ret)
>> -		list_del(&(*vb)->vb2.done_entry);
>> +		list_del(&vb->done_entry);
>>   	spin_unlock_irqrestore(&q->done_lock, flags);
>>   
>>   	return ret;
>> @@ -2027,41 +2067,45 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
>>   /**
>>    * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
>>    */
>> -static void __vb2_dqbuf(struct vb2_v4l2_buffer *vb)
>> +static void __vb2_dqbuf(struct vb2_v4l2_buffer *cb)
>>   {
>> -	struct vb2_queue *q = vb->vb2.vb2_queue;
>> +	struct vb2_buffer *vb = &cb->vb2;
>> +	struct vb2_queue *q = vb->vb2_queue;
>>   	unsigned int i;
>>   
>>   	/* nothing to do if the buffer is already dequeued */
>> -	if (vb->vb2.state == VB2_BUF_STATE_DEQUEUED)
>> +	if (vb->state == VB2_BUF_STATE_DEQUEUED)
>>   		return;
>>   
>> -	vb->vb2.state = VB2_BUF_STATE_DEQUEUED;
>> +	vb->state = VB2_BUF_STATE_DEQUEUED;
>>   
>>   	/* unmap DMABUF buffer */
>>   	if (q->memory == V4L2_MEMORY_DMABUF)
>> -		for (i = 0; i < vb->vb2.num_planes; ++i) {
>> -			if (!vb->vb2.planes[i].dbuf_mapped)
>> +		for (i = 0; i < vb->num_planes; ++i) {
>> +			if (!vb->planes[i].dbuf_mapped)
>>   				continue;
>> -			call_void_memop(vb, unmap_dmabuf, vb->vb2.planes[i].mem_priv);
>> -			vb->vb2.planes[i].dbuf_mapped = 0;
>> +			call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
>> +			vb->planes[i].dbuf_mapped = 0;
>>   		}
>>   }
>>   
>>   static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
>>   {
>> -	struct vb2_v4l2_buffer *vb = NULL;
>> +	struct vb2_v4l2_buffer *cb = NULL;
>> +	struct vb2_buffer *vb = NULL;
>>   	int ret;
>>   
>>   	if (b->type != q->type) {
>>   		dprintk(1, "invalid buffer type\n");
>>   		return -EINVAL;
>>   	}
>> -	ret = __vb2_get_done_vb(q, &vb, b, nonblocking);
>> +	ret = __vb2_get_done_vb(q, &cb, b, nonblocking);
>>   	if (ret < 0)
>>   		return ret;
>>   
>> -	switch (vb->vb2.state) {
>> +	vb = &cb->vb2;
>> +
>> +	switch (vb->state) {
>>   	case VB2_BUF_STATE_DONE:
>>   		dprintk(3, "returning done buffer\n");
>>   		break;
>> @@ -2076,15 +2120,15 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
>>   	call_void_vb_qop(vb, buf_finish, vb);
>>   
>>   	/* Fill buffer information for the userspace */
>> -	__fill_v4l2_buffer(vb, b);
>> +	__fill_v4l2_buffer(cb, b);
>>   	/* Remove from videobuf queue */
>> -	list_del(&vb->vb2.queued_entry);
>> +	list_del(&vb->queued_entry);
>>   	q->queued_count--;
>>   	/* go back to dequeued state */
>> -	__vb2_dqbuf(vb);
>> +	__vb2_dqbuf(cb);
>>   
>>   	dprintk(1, "dqbuf of buffer %d, with state %d\n",
>> -			vb->v4l2_buf.index, vb->vb2.state);
>> +			cb->v4l2_buf.index, vb->state);
>>   
>>   	return 0;
>>   }
>> @@ -2128,8 +2172,9 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
>>    */
>>   static void __vb2_queue_cancel(struct vb2_queue *q)
>>   {
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	unsigned int i;
>> -	struct vb2_v4l2_buffer *vb;
>>   
>>   	/*
>>   	 * Tell driver to stop all transactions and release all queued
>> @@ -2147,9 +2192,10 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
>>   	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
>>   		for (i = 0; i < q->num_buffers; ++i)
>>   		{
>> -			vb = (struct vb2_v4l2_buffer *)q->bufs[i];
>> -			if (vb->vb2.state == VB2_BUF_STATE_ACTIVE)
>> -				vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
>> +			vb = q->bufs[i];
>> +			cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>> +			if (vb->state == VB2_BUF_STATE_ACTIVE)
>> +				vb2_buffer_done(cb, VB2_BUF_STATE_ERROR);
>>   		}
>>   		/* Must be zero now */
>>   		WARN_ON(atomic_read(&q->owned_by_drv_count));
>> @@ -2182,13 +2228,14 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
>>   	 * be changed, so we can't move the buf_finish() to __vb2_dqbuf().
>>   	 */
>>   	for (i = 0; i < q->num_buffers; ++i) {
>> -		struct vb2_v4l2_buffer *vb = q->bufs[i];
>> +		struct vb2_buffer *vb = q->bufs[i];
>> +		struct vb2_v4l2_buffer *cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   
>> -		if (vb->vb2.state != VB2_BUF_STATE_DEQUEUED) {
>> -			vb->vb2.state = VB2_BUF_STATE_PREPARED;
>> +		if (vb->state != VB2_BUF_STATE_DEQUEUED) {
>> +			vb->state = VB2_BUF_STATE_PREPARED;
>>   			call_void_vb_qop(vb, buf_finish, vb);
>>   		}
>> -		__vb2_dqbuf(vb);
>> +		__vb2_dqbuf(cb);
>>   	}
>>   }
>>   
>> @@ -2333,7 +2380,8 @@ EXPORT_SYMBOL_GPL(vb2_streamoff);
>>   static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
>>   			unsigned int *_buffer, unsigned int *_plane)
>>   {
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	unsigned int buffer, plane;
>>   
>>   	/*
>> @@ -2343,9 +2391,10 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
>>   	 */
>>   	for (buffer = 0; buffer < q->num_buffers; ++buffer) {
>>   		vb = q->bufs[buffer];
>> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   
>> -		for (plane = 0; plane < vb->vb2.num_planes; ++plane) {
>> -			if (vb->v4l2_planes[plane].m.mem_offset == off) {
>> +		for (plane = 0; plane < vb->num_planes; ++plane) {
>> +			if (cb->v4l2_planes[plane].m.mem_offset == off) {
>>   				*_buffer = buffer;
>>   				*_plane = plane;
>>   				return 0;
>> @@ -2367,7 +2416,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
>>    */
>>   int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
>>   {
>> -	struct vb2_v4l2_buffer *vb = NULL;
>> +	struct vb2_buffer *vb = NULL;
>>   	struct vb2_plane *vb_plane;
>>   	int ret;
>>   	struct dma_buf *dbuf;
>> @@ -2399,7 +2448,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
>>   
>>   	vb = q->bufs[eb->index];
>>   
>> -	if (eb->plane >= vb->vb2.num_planes) {
>> +	if (eb->plane >= vb->num_planes) {
>>   		dprintk(1, "buffer plane out of range\n");
>>   		return -EINVAL;
>>   	}
>> @@ -2409,7 +2458,7 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
>>   		return -EBUSY;
>>   	}
>>   
>> -	vb_plane = &vb->vb2.planes[eb->plane];
>> +	vb_plane = &vb->planes[eb->plane];
>>   
>>   	dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE);
>>   	if (IS_ERR_OR_NULL(dbuf)) {
>> @@ -2456,7 +2505,8 @@ EXPORT_SYMBOL_GPL(vb2_expbuf);
>>   int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>>   {
>>   	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	unsigned int buffer = 0, plane = 0;
>>   	int ret;
>>   	unsigned long length;
>> @@ -2497,13 +2547,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>>   		return ret;
>>   
>>   	vb = q->bufs[buffer];
>> -
>> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   	/*
>>   	 * MMAP requires page_aligned buffers.
>>   	 * The buffer length was page_aligned at __vb2_buf_mem_alloc(),
>>   	 * so, we need to do the same here.
>>   	 */
>> -	length = PAGE_ALIGN(vb->v4l2_planes[plane].length);
>> +	length = PAGE_ALIGN(cb->v4l2_planes[plane].length);
>>   	if (length < (vma->vm_end - vma->vm_start)) {
>>   		dprintk(1,
>>   			"MMAP invalid, as it would overflow buffer length\n");
>> @@ -2511,7 +2561,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
>>   	}
>>   
>>   	mutex_lock(&q->mmap_lock);
>> -	ret = call_memop(vb, mmap, vb->vb2.planes[plane].mem_priv, vma);
>> +	ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma);
>>   	mutex_unlock(&q->mmap_lock);
>>   	if (ret)
>>   		return ret;
>> @@ -2528,8 +2578,9 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
>>   				    unsigned long pgoff,
>>   				    unsigned long flags)
>>   {
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   	unsigned long off = pgoff << PAGE_SHIFT;
>> -	struct vb2_v4l2_buffer *vb;
>>   	unsigned int buffer, plane;
>>   	void *vaddr;
>>   	int ret;
>> @@ -2547,8 +2598,9 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
>>   		return ret;
>>   
>>   	vb = q->bufs[buffer];
>> +	cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   
>> -	vaddr = vb2_plane_vaddr(vb, plane);
>> +	vaddr = vb2_plane_vaddr(cb, plane);
>>   	return vaddr ? (unsigned long)vaddr : -EINVAL;
>>   }
>>   EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
>> @@ -2784,7 +2836,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>>   	struct vb2_fileio_data *fileio;
>>   	int i, ret;
>>   	unsigned int count = 0;
>> -	struct vb2_v4l2_buffer *vb;
>> +	struct vb2_v4l2_buffer *cb;
>> +	struct vb2_buffer *vb;
>>   
>>   	/*
>>   	 * Sanity check
>> @@ -2835,8 +2888,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>>   	 * Check if plane_count is correct
>>   	 * (multiplane buffers are not supported).
>>   	 */
>> -	vb = (struct vb2_v4l2_buffer *)q->bufs[0];
>> -	if (vb->vb2.num_planes != 1) {
>> +	vb = q->bufs[0];
>> +	if (vb->num_planes != 1) {
>>   		ret = -EBUSY;
>>   		goto err_reqbufs;
>>   	}
>> @@ -2845,12 +2898,13 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>>   	 * Get kernel address of each buffer.
>>   	 */
>>   	for (i = 0; i < q->num_buffers; i++) {
>> -		fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
>> +		cb = container_of(q->bufs[i], struct vb2_v4l2_buffer, vb2);
>> +		fileio->bufs[i].vaddr = vb2_plane_vaddr(cb, 0);
>>   		if (fileio->bufs[i].vaddr == NULL) {
>>   			ret = -EINVAL;
>>   			goto err_reqbufs;
>>   		}
>> -		fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
>> +		fileio->bufs[i].size = vb2_plane_size(cb, 0);
>>   	}
>>   
>>   	/*
>> @@ -2937,6 +2991,7 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
>>   static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
>>   		loff_t *ppos, int nonblock, int read)
>>   {
>> +	struct vb2_v4l2_buffer *cb;
>>   	struct vb2_fileio_data *fileio;
>>   	struct vb2_fileio_buf *buf;
>>   	bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
>> @@ -2996,10 +3051,11 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
>>   		/*
>>   		 * Get number of bytes filled by the driver
>>   		 */
>> +		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
>>   		buf->pos = 0;
>>   		buf->queued = 0;
>> -		buf->size = read ? vb2_get_plane_payload(q->bufs[index], 0)
>> -				 : vb2_plane_size(q->bufs[index], 0);
>> +		buf->size = read ? vb2_get_plane_payload(cb, 0)
>> +				 : vb2_plane_size(cb, 0);
>>   		/* Compensate for data_offset on read in the multiplanar case. */
>>   		if (is_multiplanar && read &&
>>   		    fileio->b.m.planes[0].data_offset < buf->size) {
>> @@ -3076,9 +3132,10 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
>>   		/*
>>   		 * Buffer has been queued, update the status
>>   		 */
>> +		cb = container_of(q->bufs[index], struct vb2_v4l2_buffer, vb2);
>>   		buf->pos = 0;
>>   		buf->queued = 1;
>> -		buf->size = vb2_plane_size(q->bufs[index], 0);
>> +		buf->size = vb2_plane_size(cb, 0);
>>   		fileio->q_count += 1;
>>   		/*
>>   		 * If we are queuing up buffers for the first time, then
>> @@ -3146,7 +3203,8 @@ static int vb2_thread(void *data)
>>   	set_freezable();
>>   
>>   	for (;;) {
>> -		struct vb2_v4l2_buffer *vb;
>> +		struct vb2_v4l2_buffer *cb;
>> +		struct vb2_buffer *vb;
>>   
>>   		/*
>>   		 * Call vb2_dqbuf to get buffer back.
>> @@ -3169,8 +3227,9 @@ static int vb2_thread(void *data)
>>   		try_to_freeze();
>>   
>>   		vb = q->bufs[fileio->b.index];
>> +		cb = container_of(vb, struct vb2_v4l2_buffer, vb2);
>>   		if (!(fileio->b.flags & V4L2_BUF_FLAG_ERROR))
>> -			if (threadio->fnc(vb, threadio->priv))
>> +			if (threadio->fnc(cb, threadio->priv))
>>   				break;
>>   		call_void_qop(q, wait_finish, q);
>>   		if (set_timestamp)
>> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
>> index 3b5df66..24c229d 100644
>> --- a/include/media/videobuf2-core.h
>> +++ b/include/media/videobuf2-core.h
>> @@ -227,27 +227,6 @@ struct vb2_buffer {
>>   };
>>   
>>   /**
>> - * struct vb2_v4l2_buffer - represents a video buffer for v4l2
>> - * @vb2_buf:		common video buffer
>> - * @v4l2_buf:		struct v4l2_buffer associated with this buffer; can
>> - *			be read by the driver and relevant entries can be
>> - *			changed by the driver in case of CAPTURE types
>> - *			(such as timestamp)
>> - * @v4l2_planes:	struct v4l2_planes associated with this buffer; can
>> - *			be read by the driver and relevant entries can be
>> - *			changed by the driver in case of CAPTURE types
>> - *			(such as bytesused); NOTE that even for single-planar
>> - *			types, the v4l2_planes[0] struct should be used
>> - *			instead of v4l2_buf for filling bytesused - drivers
>> - *			should use the vb2_set_plane_payload() function for that
>> - */
>> -struct vb2_v4l2_buffer {
>> -	struct vb2_buffer	vb2;
>> -	struct v4l2_buffer	v4l2_buf;
>> -	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
>> -};
>> -
>> -/**
>>    * struct vb2_ops - driver-specific callbacks
>>    *
>>    * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
>> @@ -327,26 +306,24 @@ struct vb2_v4l2_buffer {
>>    *			pre-queued buffers before calling STREAMON.
>>    */
>>   struct vb2_ops {
>> -	int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
>> +	int (*queue_setup)(struct vb2_queue *q, void *fmt,
>>   			   unsigned int *num_buffers, unsigned int *num_planes,
>>   			   unsigned int sizes[], void *alloc_ctxs[]);
> Better to rename "fmt" here to "priv", to indicate that the usage of
> this field is specific to the VB2-variant.
>
OK, I'll modify it.
>>   
>>   	void (*wait_prepare)(struct vb2_queue *q);
>>   	void (*wait_finish)(struct vb2_queue *q);
>>   
>> -	int (*buf_init)(struct vb2_v4l2_buffer *vb);
>> -	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
>> -	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
>> -	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
>> +	int (*buf_init)(struct vb2_buffer *vb);
>> +	int (*buf_prepare)(struct vb2_buffer *vb);
>> +	void (*buf_finish)(struct vb2_buffer *vb);
>> +	void (*buf_cleanup)(struct vb2_buffer *vb);
>>   
>>   	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
>>   	void (*stop_streaming)(struct vb2_queue *q);
>>   
>> -	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
>> +	void (*buf_queue)(struct vb2_buffer *vb);
>>   };
>>   
>> -struct v4l2_fh;
>> -
>>   /**
>>    * struct vb2_queue - a videobuf queue
>>    *
>> @@ -400,7 +377,7 @@ struct v4l2_fh;
>>    * @threadio:	thread io internal data, used only if thread is active
>>    */
>>   struct vb2_queue {
>> -	enum v4l2_buf_type		type;
>> +	unsigned int			type;
>>   	unsigned int			io_modes;
>>   	unsigned int			io_flags;
>>   	struct mutex			*lock;
>> @@ -416,8 +393,8 @@ struct vb2_queue {
>>   
>>   /* private: internal use only */
>>   	struct mutex			mmap_lock;
>> -	enum v4l2_memory		memory;
>> -	void					*bufs[VIDEO_MAX_FRAME];
>> +	unsigned int			memory;
>> +	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
> OK. IMHO, this change (struct vb2_buffer) should be part of
> the first patch.
>
>>   	unsigned int			num_buffers;
>>   
>>   	struct list_head		queued_list;
>> @@ -451,212 +428,4 @@ struct vb2_queue {
>>   	u32				cnt_stop_streaming;
>>   #endif
>>   };
>> -
>> -void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>> -void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>> -
>> -void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
>> -void vb2_discard_done(struct vb2_queue *q);
>> -int vb2_wait_for_all_buffers(struct vb2_queue *q);
>> -
>> -int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
>> -int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
>> -
>> -int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create);
>> -int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
>> -
>> -int __must_check vb2_queue_init(struct vb2_queue *q);
>> -
>> -void vb2_queue_release(struct vb2_queue *q);
>> -void vb2_queue_error(struct vb2_queue *q);
>> -
>> -int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
>> -int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
>> -int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
>> -
>> -int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
>> -int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
>> -
>> -int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
>> -#ifndef CONFIG_MMU
>> -unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
>> -				    unsigned long addr,
>> -				    unsigned long len,
>> -				    unsigned long pgoff,
>> -				    unsigned long flags);
>> -#endif
>> -unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
>> -size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
>> -		loff_t *ppos, int nonblock);
>> -size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
>> -		loff_t *ppos, int nonblock);
>> -/**
>> - * vb2_thread_fnc - callback function for use with vb2_thread
>> - *
>> - * This is called whenever a buffer is dequeued in the thread.
>> - */
>> -typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
>> -
>> -/**
>> - * vb2_thread_start() - start a thread for the given queue.
>> - * @q:		videobuf queue
>> - * @fnc:	callback function
>> - * @priv:	priv pointer passed to the callback function
>> - * @thread_name:the name of the thread. This will be prefixed with "vb2-".
>> - *
>> - * This starts a thread that will queue and dequeue until an error occurs
>> - * or @vb2_thread_stop is called.
>> - *
>> - * This function should not be used for anything else but the videobuf2-dvb
>> - * support. If you think you have another good use-case for this, then please
>> - * contact the linux-media mailinglist first.
>> - */
>> -int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
>> -		     const char *thread_name);
>> -
>> -/**
>> - * vb2_thread_stop() - stop the thread for the given queue.
>> - * @q:		videobuf queue
>> - */
>> -int vb2_thread_stop(struct vb2_queue *q);
>> -
>> -/**
>> - * vb2_is_streaming() - return streaming status of the queue
>> - * @q:		videobuf queue
>> - */
>> -static inline bool vb2_is_streaming(struct vb2_queue *q)
>> -{
>> -	return q->streaming;
>> -}
>> -
>> -/**
>> - * vb2_fileio_is_active() - return true if fileio is active.
>> - * @q:		videobuf queue
>> - *
>> - * This returns true if read() or write() is used to stream the data
>> - * as opposed to stream I/O. This is almost never an important distinction,
>> - * except in rare cases. One such case is that using read() or write() to
>> - * stream a format using V4L2_FIELD_ALTERNATE is not allowed since there
>> - * is no way you can pass the field information of each buffer to/from
>> - * userspace. A driver that supports this field format should check for
>> - * this in the queue_setup op and reject it if this function returns true.
>> - */
>> -static inline bool vb2_fileio_is_active(struct vb2_queue *q)
>> -{
>> -	return q->fileio;
>> -}
>> -
>> -/**
>> - * vb2_is_busy() - return busy status of the queue
>> - * @q:		videobuf queue
>> - *
>> - * This function checks if queue has any buffers allocated.
>> - */
>> -static inline bool vb2_is_busy(struct vb2_queue *q)
>> -{
>> -	return (q->num_buffers > 0);
>> -}
>> -
>> -/**
>> - * vb2_get_drv_priv() - return driver private data associated with the queue
>> - * @q:		videobuf queue
>> - */
>> -static inline void *vb2_get_drv_priv(struct vb2_queue *q)
>> -{
>> -	return q->drv_priv;
>> -}
>> -
>> -/**
>> - * vb2_set_plane_payload() - set bytesused for the plane plane_no
>> - * @vb:		buffer for which plane payload should be set
>> - * @plane_no:	plane number for which payload should be set
>> - * @size:	payload in bytes
>> - */
>> -static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>> -				 unsigned int plane_no, unsigned long size)
>> -{
>> -	if (plane_no < vb->vb2.num_planes)
>> -		vb->v4l2_planes[plane_no].bytesused = size;
>> -}
>> -
>> -/**
>> - * vb2_get_plane_payload() - get bytesused for the plane plane_no
>> - * @vb:		buffer for which plane payload should be set
>> - * @plane_no:	plane number for which payload should be set
>> - * @size:	payload in bytes
>> - */
>> -static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>> -				 unsigned int plane_no)
>> -{
>> -	if (plane_no < vb->vb2.num_planes)
>> -		return vb->v4l2_planes[plane_no].bytesused;
>> -	return 0;
>> -}
>> -
>> -/**
>> - * vb2_plane_size() - return plane size in bytes
>> - * @vb:		buffer for which plane size should be returned
>> - * @plane_no:	plane number for which size should be returned
>> - */
>> -static inline unsigned long
>> -vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>> -{
>> -	if (plane_no < vb->vb2.num_planes)
>> -		return vb->v4l2_planes[plane_no].length;
>> -	return 0;
>> -}
>> -
>> -/**
>> - * vb2_start_streaming_called() - return streaming status of driver
>> - * @q:		videobuf queue
>> - */
>> -static inline bool vb2_start_streaming_called(struct vb2_queue *q)
>> -{
>> -	return q->start_streaming_called;
>> -}
>> -
>> -/*
>> - * The following functions are not part of the vb2 core API, but are simple
>> - * helper functions that you can use in your struct v4l2_file_operations,
>> - * struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock
>> - * or video_device->lock is set, and they will set and test vb2_queue->owner
>> - * to check if the calling filehandle is permitted to do the queuing operation.
>> - */
>> -
>> -/* struct v4l2_ioctl_ops helpers */
>> -
>> -int vb2_ioctl_reqbufs(struct file *file, void *priv,
>> -			  struct v4l2_requestbuffers *p);
>> -int vb2_ioctl_create_bufs(struct file *file, void *priv,
>> -			  struct v4l2_create_buffers *p);
>> -int vb2_ioctl_prepare_buf(struct file *file, void *priv,
>> -			  struct v4l2_buffer *p);
>> -int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
>> -int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
>> -int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
>> -int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
>> -int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
>> -int vb2_ioctl_expbuf(struct file *file, void *priv,
>> -	struct v4l2_exportbuffer *p);
>> -
>> -/* struct v4l2_file_operations helpers */
>> -
>> -int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
>> -int vb2_fop_release(struct file *file);
>> -int _vb2_fop_release(struct file *file, struct mutex *lock);
>> -ssize_t vb2_fop_write(struct file *file, const char __user *buf,
>> -		size_t count, loff_t *ppos);
>> -ssize_t vb2_fop_read(struct file *file, char __user *buf,
>> -		size_t count, loff_t *ppos);
>> -unsigned int vb2_fop_poll(struct file *file, poll_table *wait);
>> -#ifndef CONFIG_MMU
>> -unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr,
>> -		unsigned long len, unsigned long pgoff, unsigned long flags);
>> -#endif
>> -
>> -/* struct vb2_ops helpers, only use if vq->lock is non-NULL. */
>> -
>> -void vb2_ops_wait_prepare(struct vb2_queue *vq);
>> -void vb2_ops_wait_finish(struct vb2_queue *vq);
>> -
>>   #endif /* _MEDIA_VIDEOBUF2_CORE_H */
>> diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h
>> index 3de9111..c2e3476 100644
>> --- a/include/media/videobuf2-dma-contig.h
>> +++ b/include/media/videobuf2-dma-contig.h
>> @@ -17,9 +17,9 @@
>>   #include <linux/dma-mapping.h>
>>   
>>   static inline dma_addr_t
>> -vb2_dma_contig_plane_dma_addr(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>> +vb2_dma_contig_plane_dma_addr(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>>   {
>> -	dma_addr_t *addr = vb2_plane_cookie(vb, plane_no);
>> +	dma_addr_t *addr = vb2_plane_cookie(cb, plane_no);
>>   
>>   	return *addr;
>>   }
> Just renaming. As said before, the best is to put those renames on
> a separate patch that would be fixing the namespace.
OK, I split the patch into two or more pieces. One of them will be just 
changing
the namespace.
>> diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
>> index 80b08cb..cd2b6b9 100644
>> --- a/include/media/videobuf2-v4l2.h
>> +++ b/include/media/videobuf2-v4l2.h
>> @@ -17,214 +17,7 @@
>>   #include <linux/poll.h>
>>   #include <linux/videodev2.h>
>>   #include <linux/dma-buf.h>
>> -
>> -struct vb2_alloc_ctx;
>> -struct vb2_fileio_data;
>> -struct vb2_threadio_data;
>> -
>> -/**
>> - * struct vb2_mem_ops - memory handling/memory allocator operations
>> - * @alloc:	allocate video memory and, optionally, allocator private data,
>> - *		return NULL on failure or a pointer to allocator private,
>> - *		per-buffer data on success; the returned private structure
>> - *		will then be passed as buf_priv argument to other ops in this
>> - *		structure. Additional gfp_flags to use when allocating the
>> - *		are also passed to this operation. These flags are from the
>> - *		gfp_flags field of vb2_queue.
>> - * @put:	inform the allocator that the buffer will no longer be used;
>> - *		usually will result in the allocator freeing the buffer (if
>> - *		no other users of this buffer are present); the buf_priv
>> - *		argument is the allocator private per-buffer structure
>> - *		previously returned from the alloc callback.
>> - * @get_userptr: acquire userspace memory for a hardware operation; used for
>> - *		 USERPTR memory types; vaddr is the address passed to the
>> - *		 videobuf layer when queuing a video buffer of USERPTR type;
>> - *		 should return an allocator private per-buffer structure
>> - *		 associated with the buffer on success, NULL on failure;
>> - *		 the returned private structure will then be passed as buf_priv
>> - *		 argument to other ops in this structure.
>> - * @put_userptr: inform the allocator that a USERPTR buffer will no longer
>> - *		 be used.
>> - * @attach_dmabuf: attach a shared struct dma_buf for a hardware operation;
>> - *		   used for DMABUF memory types; alloc_ctx is the alloc context
>> - *		   dbuf is the shared dma_buf; returns NULL on failure;
>> - *		   allocator private per-buffer structure on success;
>> - *		   this needs to be used for further accesses to the buffer.
>> - * @detach_dmabuf: inform the exporter of the buffer that the current DMABUF
>> - *		   buffer is no longer used; the buf_priv argument is the
>> - *		   allocator private per-buffer structure previously returned
>> - *		   from the attach_dmabuf callback.
>> - * @map_dmabuf: request for access to the dmabuf from allocator; the allocator
>> - *		of dmabuf is informed that this driver is going to use the
>> - *		dmabuf.
>> - * @unmap_dmabuf: releases access control to the dmabuf - allocator is notified
>> - *		  that this driver is done using the dmabuf for now.
>> - * @prepare:	called every time the buffer is passed from userspace to the
>> - *		driver, useful for cache synchronisation, optional.
>> - * @finish:	called every time the buffer is passed back from the driver
>> - *		to the userspace, also optional.
>> - * @vaddr:	return a kernel virtual address to a given memory buffer
>> - *		associated with the passed private structure or NULL if no
>> - *		such mapping exists.
>> - * @cookie:	return allocator specific cookie for a given memory buffer
>> - *		associated with the passed private structure or NULL if not
>> - *		available.
>> - * @num_users:	return the current number of users of a memory buffer;
>> - *		return 1 if the videobuf layer (or actually the driver using
>> - *		it) is the only user.
>> - * @mmap:	setup a userspace mapping for a given memory buffer under
>> - *		the provided virtual memory region.
>> - *
>> - * Required ops for USERPTR types: get_userptr, put_userptr.
>> - * Required ops for MMAP types: alloc, put, num_users, mmap.
>> - * Required ops for read/write access types: alloc, put, num_users, vaddr.
>> - * Required ops for DMABUF types: attach_dmabuf, detach_dmabuf, map_dmabuf,
>> - *				  unmap_dmabuf.
>> - */
>> -struct vb2_mem_ops {
>> -	void		*(*alloc)(void *alloc_ctx, unsigned long size,
>> -				  enum dma_data_direction dma_dir,
>> -				  gfp_t gfp_flags);
>> -	void		(*put)(void *buf_priv);
>> -	struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags);
>> -
>> -	void		*(*get_userptr)(void *alloc_ctx, unsigned long vaddr,
>> -					unsigned long size,
>> -					enum dma_data_direction dma_dir);
>> -	void		(*put_userptr)(void *buf_priv);
>> -
>> -	void		(*prepare)(void *buf_priv);
>> -	void		(*finish)(void *buf_priv);
>> -
>> -	void		*(*attach_dmabuf)(void *alloc_ctx, struct dma_buf *dbuf,
>> -					  unsigned long size,
>> -					  enum dma_data_direction dma_dir);
>> -	void		(*detach_dmabuf)(void *buf_priv);
>> -	int		(*map_dmabuf)(void *buf_priv);
>> -	void		(*unmap_dmabuf)(void *buf_priv);
>> -
>> -	void		*(*vaddr)(void *buf_priv);
>> -	void		*(*cookie)(void *buf_priv);
>> -
>> -	unsigned int	(*num_users)(void *buf_priv);
>> -
>> -	int		(*mmap)(void *buf_priv, struct vm_area_struct *vma);
>> -};
>> -
>> -struct vb2_plane {
>> -	void			*mem_priv;
>> -	struct dma_buf		*dbuf;
>> -	unsigned int		dbuf_mapped;
>> -};
>> -
>> -/**
>> - * enum vb2_io_modes - queue access methods
>> - * @VB2_MMAP:		driver supports MMAP with streaming API
>> - * @VB2_USERPTR:	driver supports USERPTR with streaming API
>> - * @VB2_READ:		driver supports read() style access
>> - * @VB2_WRITE:		driver supports write() style access
>> - * @VB2_DMABUF:		driver supports DMABUF with streaming API
>> - */
>> -enum vb2_io_modes {
>> -	VB2_MMAP	= (1 << 0),
>> -	VB2_USERPTR	= (1 << 1),
>> -	VB2_READ	= (1 << 2),
>> -	VB2_WRITE	= (1 << 3),
>> -	VB2_DMABUF	= (1 << 4),
>> -};
>> -
>> -/**
>> - * enum vb2_fileio_flags - flags for selecting a mode of the file io emulator,
>> - * by default the 'streaming' style is used by the file io emulator
>> - * @VB2_FILEIO_READ_ONCE:	report EOF after reading the first buffer
>> - * @VB2_FILEIO_WRITE_IMMEDIATELY:	queue buffer after each write() call
>> - */
>> -enum vb2_fileio_flags {
>> -	VB2_FILEIO_READ_ONCE		= (1 << 0),
>> -	VB2_FILEIO_WRITE_IMMEDIATELY	= (1 << 1),
>> -};
>> -
>> -/**
>> - * enum vb2_buffer_state - current video buffer state
>> - * @VB2_BUF_STATE_DEQUEUED:	buffer under userspace control
>> - * @VB2_BUF_STATE_PREPARING:	buffer is being prepared in videobuf
>> - * @VB2_BUF_STATE_PREPARED:	buffer prepared in videobuf and by the driver
>> - * @VB2_BUF_STATE_QUEUED:	buffer queued in videobuf, but not in driver
>> - * @VB2_BUF_STATE_ACTIVE:	buffer queued in driver and possibly used
>> - *				in a hardware operation
>> - * @VB2_BUF_STATE_DONE:		buffer returned from driver to videobuf, but
>> - *				not yet dequeued to userspace
>> - * @VB2_BUF_STATE_ERROR:	same as above, but the operation on the buffer
>> - *				has ended with an error, which will be reported
>> - *				to the userspace when it is dequeued
>> - */
>> -enum vb2_buffer_state {
>> -	VB2_BUF_STATE_DEQUEUED,
>> -	VB2_BUF_STATE_PREPARING,
>> -	VB2_BUF_STATE_PREPARED,
>> -	VB2_BUF_STATE_QUEUED,
>> -	VB2_BUF_STATE_ACTIVE,
>> -	VB2_BUF_STATE_DONE,
>> -	VB2_BUF_STATE_ERROR,
>> -};
>> -
>> -struct vb2_queue;
>> -
>> -/**
>> - * struct vb2_buffer - represents a common video buffer
>> - * @vb2_queue:		the queue to which this driver belongs
>> - * @num_planes:		number of planes in the buffer
>> - *			on an internal driver queue
>> - * @state:		current buffer state; do not change
>> - * @queued_entry:	entry on the queued buffers list, which holds all
>> - *			buffers queued from userspace
>> - * @done_entry:		entry on the list that stores all buffers ready to
>> - *			be dequeued to userspace
>> - * @planes:		private per-plane information; do not change
>> - */
>> -struct vb2_buffer {
>> -	struct vb2_queue	*vb2_queue;
>> -	unsigned int		num_planes;
>> -
>> -/* Private: internal use only */
>> -	enum vb2_buffer_state	state;
>> -
>> -	struct list_head	queued_entry;
>> -	struct list_head	done_entry;
>> -
>> -	struct vb2_plane	planes[VIDEO_MAX_PLANES];
>> -
>> -#ifdef CONFIG_VIDEO_ADV_DEBUG
>> -	/*
>> -	 * Counters for how often these buffer-related ops are
>> -	 * called. Used to check for unbalanced ops.
>> -	 */
>> -	u32		cnt_mem_alloc;
>> -	u32		cnt_mem_put;
>> -	u32		cnt_mem_get_dmabuf;
>> -	u32		cnt_mem_get_userptr;
>> -	u32		cnt_mem_put_userptr;
>> -	u32		cnt_mem_prepare;
>> -	u32		cnt_mem_finish;
>> -	u32		cnt_mem_attach_dmabuf;
>> -	u32		cnt_mem_detach_dmabuf;
>> -	u32		cnt_mem_map_dmabuf;
>> -	u32		cnt_mem_unmap_dmabuf;
>> -	u32		cnt_mem_vaddr;
>> -	u32		cnt_mem_cookie;
>> -	u32		cnt_mem_num_users;
>> -	u32		cnt_mem_mmap;
>> -
>> -	u32		cnt_buf_init;
>> -	u32		cnt_buf_prepare;
>> -	u32		cnt_buf_finish;
>> -	u32		cnt_buf_cleanup;
>> -	u32		cnt_buf_queue;
>> -
>> -	/* This counts the number of calls to vb2_buffer_done() */
>> -	u32		cnt_buf_done;
>> -#endif
>> -};
>> +#include <media/videobuf2-core.h>
>>   
>>   /**
>>    * struct vb2_v4l2_buffer - represents a video buffer for v4l2
>> @@ -247,215 +40,10 @@ struct vb2_v4l2_buffer {
>>   	struct v4l2_plane	v4l2_planes[VIDEO_MAX_PLANES];
>>   };
>>   
>> -/**
>> - * struct vb2_ops - driver-specific callbacks
>> - *
>> - * @queue_setup:	called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
>> - *			handlers before memory allocation, or, if
>> - *			*num_planes != 0, after the allocation to verify a
>> - *			smaller number of buffers. Driver should return
>> - *			the required number of buffers in *num_buffers, the
>> - *			required number of planes per buffer in *num_planes; the
>> - *			size of each plane should be set in the sizes[] array
>> - *			and optional per-plane allocator specific context in the
>> - *			alloc_ctxs[] array. When called from VIDIOC_REQBUFS,
>> - *			fmt == NULL, the driver has to use the currently
>> - *			configured format and *num_buffers is the total number
>> - *			of buffers, that are being allocated. When called from
>> - *			VIDIOC_CREATE_BUFS, fmt != NULL and it describes the
>> - *			target frame format (if the format isn't valid the
>> - *			callback must return -EINVAL). In this case *num_buffers
>> - *			are being allocated additionally to q->num_buffers.
>> - * @wait_prepare:	release any locks taken while calling vb2 functions;
>> - *			it is called before an ioctl needs to wait for a new
>> - *			buffer to arrive; required to avoid a deadlock in
>> - *			blocking access type.
>> - * @wait_finish:	reacquire all locks released in the previous callback;
>> - *			required to continue operation after sleeping while
>> - *			waiting for a new buffer to arrive.
>> - * @buf_init:		called once after allocating a buffer (in MMAP case)
>> - *			or after acquiring a new USERPTR buffer; drivers may
>> - *			perform additional buffer-related initialization;
>> - *			initialization failure (return != 0) will prevent
>> - *			queue setup from completing successfully; optional.
>> - * @buf_prepare:	called every time the buffer is queued from userspace
>> - *			and from the VIDIOC_PREPARE_BUF ioctl; drivers may
>> - *			perform any initialization required before each
>> - *			hardware operation in this callback; drivers can
>> - *			access/modify the buffer here as it is still synced for
>> - *			the CPU; drivers that support VIDIOC_CREATE_BUFS must
>> - *			also validate the buffer size; if an error is returned,
>> - *			the buffer will not be queued in driver; optional.
>> - * @buf_finish:		called before every dequeue of the buffer back to
>> - *			userspace; the buffer is synced for the CPU, so drivers
>> - *			can access/modify the buffer contents; drivers may
>> - *			perform any operations required before userspace
>> - *			accesses the buffer; optional. The buffer state can be
>> - *			one of the following: DONE and ERROR occur while
>> - *			streaming is in progress, and the PREPARED state occurs
>> - *			when the queue has been canceled and all pending
>> - *			buffers are being returned to their default DEQUEUED
>> - *			state. Typically you only have to do something if the
>> - *			state is VB2_BUF_STATE_DONE, since in all other cases
>> - *			the buffer contents will be ignored anyway.
>> - * @buf_cleanup:	called once before the buffer is freed; drivers may
>> - *			perform any additional cleanup; optional.
>> - * @start_streaming:	called once to enter 'streaming' state; the driver may
>> - *			receive buffers with @buf_queue callback before
>> - *			@start_streaming is called; the driver gets the number
>> - *			of already queued buffers in count parameter; driver
>> - *			can return an error if hardware fails, in that case all
>> - *			buffers that have been already given by the @buf_queue
>> - *			callback are to be returned by the driver by calling
>> - *			@vb2_buffer_done(VB2_BUF_STATE_QUEUED).
>> - *			If you need a minimum number of buffers before you can
>> - *			start streaming, then set @min_buffers_needed in the
>> - *			vb2_queue structure. If that is non-zero then
>> - *			start_streaming won't be called until at least that
>> - *			many buffers have been queued up by userspace.
>> - * @stop_streaming:	called when 'streaming' state must be disabled; driver
>> - *			should stop any DMA transactions or wait until they
>> - *			finish and give back all buffers it got from buf_queue()
>> - *			callback by calling @vb2_buffer_done() with either
>> - *			VB2_BUF_STATE_DONE or VB2_BUF_STATE_ERROR; may use
>> - *			vb2_wait_for_all_buffers() function
>> - * @buf_queue:		passes buffer vb to the driver; driver may start
>> - *			hardware operation on this buffer; driver should give
>> - *			the buffer back by calling vb2_buffer_done() function;
>> - *			it is allways called after calling STREAMON ioctl;
>> - *			might be called before start_streaming callback if user
>> - *			pre-queued buffers before calling STREAMON.
>> - */
>> -struct vb2_ops {
>> -	int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
>> -			   unsigned int *num_buffers, unsigned int *num_planes,
>> -			   unsigned int sizes[], void *alloc_ctxs[]);
>> -
>> -	void (*wait_prepare)(struct vb2_queue *q);
>> -	void (*wait_finish)(struct vb2_queue *q);
>> -
>> -	int (*buf_init)(struct vb2_v4l2_buffer *vb);
>> -	int (*buf_prepare)(struct vb2_v4l2_buffer *vb);
>> -	void (*buf_finish)(struct vb2_v4l2_buffer *vb);
>> -	void (*buf_cleanup)(struct vb2_v4l2_buffer *vb);
>> -
>> -	int (*start_streaming)(struct vb2_queue *q, unsigned int count);
>> -	void (*stop_streaming)(struct vb2_queue *q);
>> -
>> -	void (*buf_queue)(struct vb2_v4l2_buffer *vb);
>> -};
>> -
>> -struct v4l2_fh;
>> -
>> -/**
>> - * struct vb2_queue - a videobuf queue
>> - *
>> - * @type:	queue type (see V4L2_BUF_TYPE_* in linux/videodev2.h
>> - * @io_modes:	supported io methods (see vb2_io_modes enum)
>> - * @io_flags:	additional io flags (see vb2_fileio_flags enum)
>> - * @lock:	pointer to a mutex that protects the vb2_queue struct. The
>> - *		driver can set this to a mutex to let the v4l2 core serialize
>> - *		the queuing ioctls. If the driver wants to handle locking
>> - *		itself, then this should be set to NULL. This lock is not used
>> - *		by the videobuf2 core API.
>> - * @owner:	The filehandle that 'owns' the buffers, i.e. the filehandle
>> - *		that called reqbufs, create_buffers or started fileio.
>> - *		This field is not used by the videobuf2 core API, but it allows
>> - *		drivers to easily associate an owner filehandle with the queue.
>> - * @ops:	driver-specific callbacks
>> - * @mem_ops:	memory allocator specific callbacks
>> - * @drv_priv:	driver private data
>> - * @buf_struct_size: size of the driver-specific buffer structure;
>> - *		"0" indicates the driver doesn't want to use a custom buffer
>> - *		structure type, so sizeof(struct vb2_v4l2_buffer) will is used
>> - * @timestamp_flags: Timestamp flags; V4L2_BUF_FLAG_TIMESTAMP_* and
>> - *		V4L2_BUF_FLAG_TSTAMP_SRC_*
>> - * @gfp_flags:	additional gfp flags used when allocating the buffers.
>> - *		Typically this is 0, but it may be e.g. GFP_DMA or __GFP_DMA32
>> - *		to force the buffer allocation to a specific memory zone.
>> - * @min_buffers_needed: the minimum number of buffers needed before
>> - *		start_streaming() can be called. Used when a DMA engine
>> - *		cannot be started unless at least this number of buffers
>> - *		have been queued into the driver.
>> - *
>> - * @mmap_lock:	private mutex used when buffers are allocated/freed/mmapped
>> - * @memory:	current memory type used
>> - * @bufs:	videobuf buffer structures
>> - * @num_buffers: number of allocated/used buffers
>> - * @queued_list: list of buffers currently queued from userspace
>> - * @queued_count: number of buffers queued and ready for streaming.
>> - * @owned_by_drv_count: number of buffers owned by the driver
>> - * @done_list:	list of buffers ready to be dequeued to userspace
>> - * @done_lock:	lock to protect done_list list
>> - * @done_wq:	waitqueue for processes waiting for buffers ready to be dequeued
>> - * @alloc_ctx:	memory type/allocator-specific contexts for each plane
>> - * @streaming:	current streaming state
>> - * @start_streaming_called: start_streaming() was called successfully and we
>> - *		started streaming.
>> - * @error:	a fatal error occurred on the queue
>> - * @waiting_for_buffers: used in poll() to check if vb2 is still waiting for
>> - *		buffers. Only set for capture queues if qbuf has not yet been
>> - *		called since poll() needs to return POLLERR in that situation.
>> - * @fileio:	file io emulator internal data, used only if emulator is active
>> - * @threadio:	thread io internal data, used only if thread is active
>> - */
>> -struct vb2_queue {
>> -	enum v4l2_buf_type		type;
>> -	unsigned int			io_modes;
>> -	unsigned int			io_flags;
>> -	struct mutex			*lock;
>> -	void					*owner;
>> -
>> -	const struct vb2_ops		*ops;
>> -	const struct vb2_mem_ops	*mem_ops;
>> -	void				*drv_priv;
>> -	unsigned int			buf_struct_size;
>> -	u32				timestamp_flags;
>> -	gfp_t				gfp_flags;
>> -	u32				min_buffers_needed;
>> -
>> -/* private: internal use only */
>> -	struct mutex			mmap_lock;
>> -	enum v4l2_memory		memory;
>> -	void					*bufs[VIDEO_MAX_FRAME];
>> -	unsigned int			num_buffers;
>> -
>> -	struct list_head		queued_list;
>> -	unsigned int			queued_count;
>> -
>> -	atomic_t			owned_by_drv_count;
>> -	struct list_head		done_list;
>> -	spinlock_t			done_lock;
>> -	wait_queue_head_t		done_wq;
>> -
>> -	void				*alloc_ctx[VIDEO_MAX_PLANES];
>> -	unsigned int			plane_sizes[VIDEO_MAX_PLANES];
>> -
>> -	unsigned int			streaming:1;
>> -	unsigned int			start_streaming_called:1;
>> -	unsigned int			error:1;
>> -	unsigned int			waiting_for_buffers:1;
>> -
>> -	struct vb2_fileio_data		*fileio;
>> -	struct vb2_threadio_data	*threadio;
>> -
>> -#ifdef CONFIG_VIDEO_ADV_DEBUG
>> -	/*
>> -	 * Counters for how often these queue-related ops are
>> -	 * called. Used to check for unbalanced ops.
>> -	 */
>> -	u32				cnt_queue_setup;
>> -	u32				cnt_wait_prepare;
>> -	u32				cnt_wait_finish;
>> -	u32				cnt_start_streaming;
>> -	u32				cnt_stop_streaming;
>> -#endif
>> -};
>> -
>> -void *vb2_plane_vaddr(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>> -void *vb2_plane_cookie(struct vb2_v4l2_buffer *vb, unsigned int plane_no);
>> +void *vb2_plane_vaddr(struct vb2_v4l2_buffer *cb, unsigned int plane_no);
>> +void *vb2_plane_cookie(struct vb2_v4l2_buffer *cb, unsigned int plane_no);
>>   
>> -void vb2_buffer_done(struct vb2_v4l2_buffer *vb, enum vb2_buffer_state state);
>> +void vb2_buffer_done(struct vb2_v4l2_buffer *cb, enum vb2_buffer_state state);
>>   void vb2_discard_done(struct vb2_queue *q);
>>   int vb2_wait_for_all_buffers(struct vb2_queue *q);
>>   
>> @@ -495,7 +83,7 @@ size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
>>    *
>>    * This is called whenever a buffer is dequeued in the thread.
>>    */
>> -typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *vb, void *priv);
>> +typedef int (*vb2_thread_fnc)(struct vb2_v4l2_buffer *cb, void *priv);
>>   
>>   /**
>>    * vb2_thread_start() - start a thread for the given queue.
>> @@ -572,11 +160,11 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
>>    * @plane_no:	plane number for which payload should be set
>>    * @size:	payload in bytes
>>    */
>> -static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>> +static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *cb,
>>   				 unsigned int plane_no, unsigned long size)
>>   {
>> -	if (plane_no < vb->vb2.num_planes)
>> -		vb->v4l2_planes[plane_no].bytesused = size;
>> +	if (plane_no < cb->vb2.num_planes)
>> +		cb->v4l2_planes[plane_no].bytesused = size;
>>   }
>>   
>>   /**
>> @@ -585,11 +173,11 @@ static inline void vb2_set_plane_payload(struct vb2_v4l2_buffer *vb,
>>    * @plane_no:	plane number for which payload should be set
>>    * @size:	payload in bytes
>>    */
>> -static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>> +static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *cb,
>>   				 unsigned int plane_no)
>>   {
>> -	if (plane_no < vb->vb2.num_planes)
>> -		return vb->v4l2_planes[plane_no].bytesused;
>> +	if (plane_no < cb->vb2.num_planes)
>> +		return cb->v4l2_planes[plane_no].bytesused;
>>   	return 0;
>>   }
>>   
>> @@ -599,10 +187,10 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_v4l2_buffer *vb,
>>    * @plane_no:	plane number for which size should be returned
>>    */
>>   static inline unsigned long
>> -vb2_plane_size(struct vb2_v4l2_buffer *vb, unsigned int plane_no)
>> +vb2_plane_size(struct vb2_v4l2_buffer *cb, unsigned int plane_no)
>>   {
>> -	if (plane_no < vb->vb2.num_planes)
>> -		return vb->v4l2_planes[plane_no].length;
>> +	if (plane_no < cb->vb2.num_planes)
>> +		return cb->v4l2_planes[plane_no].length;
>>   	return 0;
>>   }
>>   
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-06-23  1:33 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-08 13:35 [RFC PATCH 0/3] Refactoring Videobuf2 for common use Junghak Sung
2015-06-08 13:35 ` [RFC PATCH 1/3] modify the vb2_buffer structure for common video buffer and make struct vb2_v4l2_buffer Junghak Sung
2015-06-12  9:58   ` Hans Verkuil
2015-06-12 10:09     ` Hans Verkuil
2015-06-17 11:55       ` Mauro Carvalho Chehab
2015-06-17 12:27   ` Mauro Carvalho Chehab
2015-06-23  1:11     ` Junghak Sung
2015-06-08 13:35 ` [RFC PATCH 3/3] make vb2-core part with not v4l2-specific elements Junghak Sung
2015-06-08 14:42 ` [RFC PATCH 0/3] Refactoring Videobuf2 for common use Hans Verkuil
2015-06-08 17:39   ` Mauro Carvalho Chehab
2015-06-09  1:41     ` Junghak Sung
2015-06-12 10:51 ` Hans Verkuil
2015-06-23  0:48   ` Junghak Sung
     [not found] ` <1433770535-21143-3-git-send-email-jh1009.sung@samsung.com>
2015-06-17 13:16   ` [RFC PATCH 2/3] make struct vb2_queue to common and apply the changes related with that Mauro Carvalho Chehab
2015-06-23  1:33     ` Junghak Sung

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.