linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use
@ 2015-07-31  8:44 Junghak Sung
  2015-07-31  8:44 ` [RFC PATCH v2 1/5] media: videobuf2: Rename videobuf2-core to videobuf2-v4l2 Junghak Sung
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Junghak Sung @ 2015-07-31  8:44 UTC (permalink / raw)
  To: linux-media, mchehab, hverkuil, laurent.pinchart, sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon, jh1009.sung

Hello everybody,

This is the 2nd round for refactoring Videobuf2(a.k.a VB2).
The purpose of this patch series is to separate existing VB2 framework
into core part and V4L2 specific part. So that not only V4L2 but also other
frameworks can use them to manage buffer and utilize queue.

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.

We have a plan for this work as follows:
1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2.
   Of course, this change will not affect other v4l2-based
   device drivers. This patch series corresponds to this step.

2. Add and implement new APIs for DVB streaming I/O.
   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.

This patch series is the first step for it.
The previous version of this patch series can be found at [1].

[1] RFC PATCH v1 - http://www.spinics.net/lists/linux-media/msg90688.html

Changes since v1:
1. Divide patch set into more pieces
v1 was not reviewed normally because the 2/3 patch is failed to send to mailing
list with size problem - over 300kb. So I have divided the patch set into five
pieces and refined them neatly, which was pointed by Hans.

2. Add shell scripts for renaming patch
In case of renaming patch, shell scripts are included inside the body of the
patches by Mauro's advice. 1/5 and 5/5 patches include these scripts, which can
be used by reviewers or maintainers to regenerate big patch file if something
goes wrong during patch apply.

3. Remove dependency on v4l2 from videobuf2
In previous patch set, videobuf2-core uses v4l2-specific stuff as it is.
e.g. enum v4l2_buf_type and enum v4l2_memory. That prevented other frameworks
from using videobuf2 independently and made them forced to include
v4l2-specific stuff.
In this version, these dependent stuffs are replaced with VB2 own stuffs.
e.g. enum vb2_buf_type and enum vb2_memory. So, v4l2-specific header file isn't
required to use videobuf2 in other modules. Please, note that videobuf2 stuffs
will be translated to v4l2-specific stuffs in videobuf2-v4l2.c file for
backward compatibility.

4. Unify duplicated definitions
VB2_DEBUG() is newly defined in videobuf2-core header file in order to unify
duplicated macro functions that invoke callback functions implemented in vb2
backends - i.e., videobuf2-vmalloc and videobuf2-dma-sg - and queue relevant
callbacks of device drivers.
In previous patch set, these macro functions were defined
in both videobuf2-core.c and videobuf2-v4l2.c.

This patch series is base on media_tree.git [2] by Mauro & Hans's request.
And I applied this patches to my own git [3] which can be helpful to review.
My test boards are ubuntu PC(Intel i7-3770) and odroid-xu3(exynos5422). And
basic oprerations, e.g. reqbuf, querybuf, qbuf, dqbuf, are tested with
v4l-utils. But, more tests for the all ioctls will be required on many other
targets.

[2] media_tree.git - http://git.linuxtv.org/cgit.cgi/media_tree.git/
[3] jsung/dvb-vb2.git - http://git.linuxtv.org/cgit.cgi/jsung/dvb-vb2.git/

Any suggestions and comments are welcome.

Regards,
Junghak

Junghak Sung (5):
  media: videobuf2: Rename videobuf2-core to videobuf2-v4l2
  media: videobuf2: Restructurng struct vb2_buffer for common use.
  media: videobuf2: Divide videobuf2-core into 2 parts
  media: videobuf2: Define vb2_buf_type and vb2_memory
  media: videobuf2: Modify prefix for VB2 functions

 drivers/input/touchscreen/sur40.c                  |   23 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |   19 +-
 drivers/media/pci/cobalt/cobalt-alsa-pcm.c         |    4 +-
 drivers/media/pci/cobalt/cobalt-v4l2.c             |    8 +-
 drivers/media/pci/cx23885/cx23885-417.c            |   15 +-
 drivers/media/pci/cx23885/cx23885-core.c           |   10 +-
 drivers/media/pci/cx23885/cx23885-dvb.c            |   13 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |   17 +-
 drivers/media/pci/cx23885/cx23885-video.c          |   23 +-
 drivers/media/pci/cx23885/cx23885.h                |    2 +-
 drivers/media/pci/cx25821/cx25821-video.c          |   22 +-
 drivers/media/pci/cx25821/cx25821.h                |    3 +-
 drivers/media/pci/cx88/cx88-blackbird.c            |   17 +-
 drivers/media/pci/cx88/cx88-core.c                 |    2 +-
 drivers/media/pci/cx88/cx88-dvb.c                  |   15 +-
 drivers/media/pci/cx88/cx88-mpeg.c                 |    8 +-
 drivers/media/pci/cx88/cx88-vbi.c                  |   17 +-
 drivers/media/pci/cx88/cx88-video.c                |   21 +-
 drivers/media/pci/cx88/cx88.h                      |    2 +-
 drivers/media/pci/dt3155/dt3155.c                  |   23 +-
 drivers/media/pci/dt3155/dt3155.h                  |    2 +-
 drivers/media/pci/saa7134/saa7134-core.c           |    9 +-
 drivers/media/pci/saa7134/saa7134-dvb.c            |    6 +-
 drivers/media/pci/saa7134/saa7134-empress.c        |    4 +-
 drivers/media/pci/saa7134/saa7134-ts.c             |   30 +-
 drivers/media/pci/saa7134/saa7134-vbi.c            |   24 +-
 drivers/media/pci/saa7134/saa7134-video.c          |   43 +-
 drivers/media/pci/saa7134/saa7134.h                |    9 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   35 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   20 +-
 drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c            |   35 +-
 drivers/media/pci/tw68/tw68-video.c                |   22 +-
 drivers/media/pci/tw68/tw68.h                      |    2 +-
 drivers/media/platform/am437x/am437x-vpfe.c        |   40 +-
 drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
 drivers/media/platform/blackfin/bfin_capture.c     |   42 +-
 drivers/media/platform/coda/coda-bit.c             |   62 +-
 drivers/media/platform/coda/coda-common.c          |   30 +-
 drivers/media/platform/coda/coda-jpeg.c            |    6 +-
 drivers/media/platform/coda/coda.h                 |    6 +-
 drivers/media/platform/coda/trace.h                |    2 +-
 drivers/media/platform/davinci/vpbe_display.c      |   16 +-
 drivers/media/platform/davinci/vpif_capture.c      |   43 +-
 drivers/media/platform/davinci/vpif_capture.h      |    2 +-
 drivers/media/platform/davinci/vpif_display.c      |   49 +-
 drivers/media/platform/davinci/vpif_display.h      |    2 +-
 drivers/media/platform/exynos-gsc/gsc-core.c       |   10 +-
 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   |   30 +-
 drivers/media/platform/exynos4-is/fimc-core.c      |   12 +-
 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 |   22 +-
 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       |   18 +-
 drivers/media/platform/m2m-deinterlace.c           |   26 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |   40 +-
 drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
 drivers/media/platform/mx2_emmaprp.c               |   25 +-
 drivers/media/platform/omap3isp/ispvideo.c         |   47 +-
 drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   49 +-
 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               |   22 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |   57 +-
 drivers/media/platform/s5p-mfc/s5p_mfc.c           |   42 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   63 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |  120 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |   28 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |   28 +-
 drivers/media/platform/s5p-tv/mixer.h              |    4 +-
 drivers/media/platform/s5p-tv/mixer_grp_layer.c    |    2 +-
 drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
 drivers/media/platform/s5p-tv/mixer_video.c        |   33 +-
 drivers/media/platform/s5p-tv/mixer_vp_layer.c     |    5 +-
 drivers/media/platform/sh_veu.c                    |   38 +-
 drivers/media/platform/sh_vou.c                    |    8 +-
 drivers/media/platform/soc_camera/atmel-isi.c      |   32 +-
 drivers/media/platform/soc_camera/mx2_camera.c     |   44 +-
 drivers/media/platform/soc_camera/mx3_camera.c     |   39 +-
 drivers/media/platform/soc_camera/rcar_vin.c       |   38 +-
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |   49 +-
 drivers/media/platform/soc_camera/soc_camera.c     |   24 +-
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c      |    8 +-
 drivers/media/platform/ti-vpe/vpe.c                |   39 +-
 drivers/media/platform/vim2m.c                     |   39 +-
 drivers/media/platform/vivid/vivid-core.c          |   10 +-
 drivers/media/platform/vivid/vivid-core.h          |    4 +-
 drivers/media/platform/vivid/vivid-kthread-cap.c   |   20 +-
 drivers/media/platform/vivid/vivid-kthread-out.c   |   14 +-
 drivers/media/platform/vivid/vivid-sdr-cap.c       |   24 +-
 drivers/media/platform/vivid/vivid-vbi-cap.c       |   23 +-
 drivers/media/platform/vivid/vivid-vbi-out.c       |   19 +-
 drivers/media/platform/vivid/vivid-vid-cap.c       |   25 +-
 drivers/media/platform/vivid/vivid-vid-out.c       |   20 +-
 drivers/media/platform/vsp1/vsp1_video.c           |   26 +-
 drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |    6 +-
 drivers/media/platform/xilinx/xilinx-dma.h         |    2 +-
 drivers/media/usb/airspy/airspy.c                  |   22 +-
 drivers/media/usb/au0828/au0828-vbi.c              |   15 +-
 drivers/media/usb/au0828/au0828-video.c            |   55 +-
 drivers/media/usb/au0828/au0828.h                  |    3 +-
 drivers/media/usb/em28xx/em28xx-vbi.c              |   17 +-
 drivers/media/usb/em28xx/em28xx-video.c            |   33 +-
 drivers/media/usb/em28xx/em28xx.h                  |    3 +-
 drivers/media/usb/go7007/go7007-driver.c           |    4 +-
 drivers/media/usb/go7007/go7007-priv.h             |    4 +-
 drivers/media/usb/go7007/go7007-v4l2.c             |   20 +-
 drivers/media/usb/hackrf/hackrf.c                  |   20 +-
 drivers/media/usb/msi2500/msi2500.c                |   23 +-
 drivers/media/usb/pwc/pwc-if.c                     |   28 +-
 drivers/media/usb/pwc/pwc-uncompress.c             |    8 +-
 drivers/media/usb/pwc/pwc.h                        |    3 +-
 drivers/media/usb/s2255/s2255drv.c                 |   26 +-
 drivers/media/usb/stk1160/stk1160-v4l.c            |   17 +-
 drivers/media/usb/stk1160/stk1160-video.c          |    4 +-
 drivers/media/usb/stk1160/stk1160.h                |    4 +-
 drivers/media/usb/usbtv/usbtv-video.c              |   24 +-
 drivers/media/usb/usbtv/usbtv.h                    |    3 +-
 drivers/media/usb/uvc/uvc_queue.c                  |   56 +-
 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             |   30 +-
 drivers/media/v4l2-core/videobuf2-core.c           | 2393 +++-----------------
 drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
 drivers/media/v4l2-core/videobuf2-v4l2.c           | 1970 ++++++++++++++++
 drivers/usb/gadget/function/uvc_queue.c            |   46 +-
 drivers/usb/gadget/function/uvc_queue.h            |    4 +-
 include/media/soc_camera.h                         |    2 +-
 include/media/v4l2-mem2mem.h                       |   10 +-
 include/media/videobuf2-core.h                     |  430 ++--
 include/media/videobuf2-dvb.h                      |    2 +-
 include/media/videobuf2-v4l2.h                     |  186 ++
 include/trace/events/v4l2.h                        |   38 +-
 143 files changed, 4185 insertions(+), 3462 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] 23+ messages in thread

* [RFC PATCH v2 1/5] media: videobuf2: Rename videobuf2-core to videobuf2-v4l2
  2015-07-31  8:44 [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Junghak Sung
@ 2015-07-31  8:44 ` Junghak Sung
  2015-08-10  8:06   ` Hans Verkuil
  2015-07-31  8:44 ` [RFC PATCH v2 2/5] media: videobuf2: Restructurng struct vb2_buffer for common use Junghak Sung
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Junghak Sung @ 2015-07-31  8:44 UTC (permalink / raw)
  To: linux-media, mchehab, hverkuil, laurent.pinchart, sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon, jh1009.sung

Rename file name - from videobuf2-core.[ch] to videobuf2-v4l2.[ch]
This renaming patch should be accompanied by the modifications for all device
drivers that include this header file. It can be done with just running this
shell script.

replace()
{
str1=$1
str2=$2
dir=$3
for file in $(find $dir -name *.h -o -name *.c -o -name Makefile)
do
    echo $file
    sed "s/$str1/$str2/g" $file > $file.out
    mv $file.out $file
done
}
replace "videobuf2-core" "videobuf2-v4l2" "include/media/"
replace "videobuf2-core" "videobuf2-v4l2" "drivers/media/"

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
---
 drivers/media/pci/solo6x10/solo6x10.h              |    2 +-
 drivers/media/platform/coda/coda-bit.c             |    2 +-
 drivers/media/platform/coda/coda-common.c          |    2 +-
 drivers/media/platform/coda/coda.h                 |    2 +-
 drivers/media/platform/coda/trace.h                |    2 +-
 drivers/media/platform/exynos-gsc/gsc-core.h       |    2 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |    2 +-
 drivers/media/platform/exynos4-is/fimc-core.c      |    2 +-
 drivers/media/platform/exynos4-is/fimc-core.h      |    2 +-
 drivers/media/platform/exynos4-is/fimc-is.h        |    2 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |    2 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.h |    2 +-
 drivers/media/platform/exynos4-is/fimc-isp.h       |    2 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |    2 +-
 drivers/media/platform/exynos4-is/fimc-lite.h      |    2 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c       |    2 +-
 drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
 drivers/media/platform/omap3isp/ispvideo.h         |    2 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |    2 +-
 drivers/media/platform/s3c-camif/camif-core.c      |    2 +-
 drivers/media/platform/s3c-camif/camif-core.h      |    2 +-
 drivers/media/platform/s5p-g2d/g2d.c               |    2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc.c           |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |    2 +-
 drivers/media/platform/s5p-tv/mixer.h              |    2 +-
 drivers/media/platform/soc_camera/mx2_camera.c     |    2 +-
 drivers/media/platform/soc_camera/soc_camera.c     |    2 +-
 drivers/media/platform/ti-vpe/vpe.c                |    2 +-
 drivers/media/platform/vivid/vivid-core.h          |    2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |    2 +-
 drivers/media/platform/vsp1/vsp1_video.h           |    2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |    2 +-
 drivers/media/platform/xilinx/xilinx-dma.h         |    2 +-
 drivers/media/usb/go7007/go7007-priv.h             |    2 +-
 drivers/media/usb/stk1160/stk1160.h                |    2 +-
 drivers/media/usb/usbtv/usbtv-video.c              |    2 +-
 drivers/media/usb/uvc/uvcvideo.h                   |    2 +-
 drivers/media/v4l2-core/Makefile                   |    2 +-
 drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +-
 drivers/media/v4l2-core/v4l2-mem2mem.c             |    2 +-
 drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
 drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
 drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
 .../{videobuf2-core.c => videobuf2-v4l2.c}         |   10 +++++-----
 drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
 drivers/usb/gadget/function/uvc_queue.h            |    2 +-
 include/media/soc_camera.h                         |    2 +-
 include/media/v4l2-mem2mem.h                       |    2 +-
 include/media/videobuf2-dma-contig.h               |    2 +-
 include/media/videobuf2-dma-sg.h                   |    2 +-
 include/media/videobuf2-dvb.h                      |    2 +-
 include/media/videobuf2-memops.h                   |    2 +-
 .../media/{videobuf2-core.h => videobuf2-v4l2.h}   |    2 +-
 include/media/videobuf2-vmalloc.h                  |    2 +-
 57 files changed, 61 insertions(+), 61 deletions(-)
 rename drivers/media/v4l2-core/{videobuf2-core.c => videobuf2-v4l2.c} (99%)
 rename include/media/{videobuf2-core.h => videobuf2-v4l2.h} (99%)

diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
index 27423d7..5cc9e9d 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"
 
diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 3d434a4..d058447 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -25,7 +25,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>
 
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 04310cd..6e0c9be 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -36,7 +36,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>
 
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index 59b2af9..feb9671 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -24,7 +24,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"
 
diff --git a/drivers/media/platform/coda/trace.h b/drivers/media/platform/coda/trace.h
index d9099a0..9db6a66 100644
--- a/drivers/media/platform/coda/trace.h
+++ b/drivers/media/platform/coda/trace.h
@@ -5,7 +5,7 @@
 #define __CODA_TRACE_H__
 
 #include <linux/tracepoint.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 #include "coda.h"
 
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.h b/drivers/media/platform/exynos-gsc/gsc-core.h
index fa572aa..769ff50 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>
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index cfebf29..d0ceae3 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"
diff --git a/drivers/media/platform/exynos4-is/fimc-core.c b/drivers/media/platform/exynos4-is/fimc-core.c
index 1101c41..cef2a7f 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"
diff --git a/drivers/media/platform/exynos4-is/fimc-core.h b/drivers/media/platform/exynos4-is/fimc-core.h
index 7328f08..ccb5d91 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>
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..195f9b5 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>
 
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..ad9908b 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>
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index ca6261a..7e37c9a 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>
 
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.h b/drivers/media/platform/exynos4-is/fimc-lite.h
index ea19dc7..7e4c708 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>
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index 0ad1b6f..9c27335 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"
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h
index 97167f6..35cd9e5 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/omap3isp/ispvideo.h b/drivers/media/platform/omap3isp/ispvideo.h
index 4071dd7..31c2445 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"
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index 76e6289..bb01eaa 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"
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332..1ba9bb0 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..8ef6f26 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"
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 421a7c3..81483da 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"
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index bfbf157..712d8c3 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"
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 8de61dc..b3758b8 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..10884a7 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"
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index aebe4fd..2fd59e7 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"
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index e65993f..3fb87ed 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"
diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
index fb2acc5..855b723 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"
 
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index ea4c423..6e41335 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>
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index d708df4..4595590 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..d82c2f2 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"
diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h
index c72349c..5f1b1da 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>
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 3c124c1..dfd45c7 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"
diff --git a/drivers/media/platform/vsp1/vsp1_video.h b/drivers/media/platform/vsp1/vsp1_video.h
index 0887a4d..d808301 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;
 
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index e779c93..d9dcd4b 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -22,7 +22,7 @@
 #include <media/v4l2-dev.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-ioctl.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "xilinx-dma.h"
diff --git a/drivers/media/platform/xilinx/xilinx-dma.h b/drivers/media/platform/xilinx/xilinx-dma.h
index a540111..7a1621a 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.h
+++ b/drivers/media/platform/xilinx/xilinx-dma.h
@@ -22,7 +22,7 @@
 
 #include <media/media-entity.h>
 #include <media/v4l2-dev.h>
-#include <media/videobuf2-core.h>
+#include <media/videobuf2-v4l2.h>
 
 struct dma_chan;
 struct xvip_composite_device;
diff --git a/drivers/media/usb/go7007/go7007-priv.h b/drivers/media/usb/go7007/go7007-priv.h
index 2251c3f..9e83bbf 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;
 
diff --git a/drivers/media/usb/stk1160/stk1160.h b/drivers/media/usb/stk1160/stk1160.h
index 72cc8e8..047131b 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>
 
diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c
index 08fb0f2..a46766c 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"
 
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 816dd1a..53e6484 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
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index dc3de00..16865b8 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -30,7 +30,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 85de455..e0bb729 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 af8d6b4..95100e3 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>
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 94c1e64..437b769 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 7289b81..eb90188 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-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 99%
rename from drivers/media/v4l2-core/videobuf2-core.c
rename to drivers/media/v4l2-core/videobuf2-v4l2.c
index b866a6b..ca15186 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -1,5 +1,5 @@
 /*
- * videobuf2-core.c - V4L2 driver helper framework
+ * videobuf2-v4l2.c - V4L2 driver helper framework
  *
  * Copyright (C) 2010 Samsung Electronics
  *
@@ -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>
 
 #include <trace/events/v4l2.h>
 
@@ -1810,7 +1810,7 @@ static int vb2_start_streaming(struct vb2_queue *q)
 	/*
 	 * 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
+	 * documentation in videobuf2-v4l2.h for more information how buffers
 	 * should be returned to vb2 in start_streaming().
 	 */
 	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
@@ -2197,7 +2197,7 @@ static void __vb2_queue_cancel(struct vb2_queue *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
+	 * videobuf2-v4l2.h for more information how buffers should be returned
 	 * to vb2 in stop_streaming().
 	 */
 	if (WARN_ON(atomic_read(&q->owned_by_drv_count))) {
@@ -2731,7 +2731,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)
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 2fe4c27..45da6cd 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/usb/gadget/function/uvc_queue.h b/drivers/usb/gadget/function/uvc_queue.h
index 01ca9ea..0ffe498 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)
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 3bbd96d..22f88c7 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
diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h
index 8197f87..c33dfa6 100644
--- a/include/media/videobuf2-dma-contig.h
+++ b/include/media/videobuf2-dma-contig.h
@@ -13,7 +13,7 @@
 #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
diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h
index 14ce306..8d1083f 100644
--- a/include/media/videobuf2-dma-sg.h
+++ b/include/media/videobuf2-dma-sg.h
@@ -13,7 +13,7 @@
 #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)
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 99%
rename from include/media/videobuf2-core.h
rename to include/media/videobuf2-v4l2.h
index 22a44c2..021a69c 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-v4l2.h
@@ -1,5 +1,5 @@
 /*
- * videobuf2-core.h - V4L2 driver helper framework
+ * videobuf2-v4l2.h - V4L2 driver helper framework
  *
  * Copyright (C) 2010 Samsung Electronics
  *
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] 23+ messages in thread

* [RFC PATCH v2 2/5] media: videobuf2: Restructurng struct vb2_buffer for common use.
  2015-07-31  8:44 [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Junghak Sung
  2015-07-31  8:44 ` [RFC PATCH v2 1/5] media: videobuf2: Rename videobuf2-core to videobuf2-v4l2 Junghak Sung
@ 2015-07-31  8:44 ` Junghak Sung
  2015-07-31  8:44 ` [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts Junghak Sung
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 23+ messages in thread
From: Junghak Sung @ 2015-07-31  8:44 UTC (permalink / raw)
  To: linux-media, mchehab, hverkuil, laurent.pinchart, sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon, jh1009.sung

Remove v4l2-specific stuff from struct vb2_buffer and create struct
vb2_v4l2_buffer as container buffer for v4l2 use.

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

And modify all device drivers related with this change.

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
---
 drivers/input/touchscreen/sur40.c                  |   13 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |   15 ++-
 drivers/media/pci/cx23885/cx23885-417.c            |   11 +-
 drivers/media/pci/cx23885/cx23885-core.c           |   10 +-
 drivers/media/pci/cx23885/cx23885-dvb.c            |    9 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |   11 +-
 drivers/media/pci/cx23885/cx23885-video.c          |   13 +-
 drivers/media/pci/cx23885/cx23885.h                |    2 +-
 drivers/media/pci/cx25821/cx25821-video.c          |   13 +-
 drivers/media/pci/cx25821/cx25821.h                |    2 +-
 drivers/media/pci/cx88/cx88-blackbird.c            |   13 +-
 drivers/media/pci/cx88/cx88-core.c                 |    2 +-
 drivers/media/pci/cx88/cx88-dvb.c                  |   11 +-
 drivers/media/pci/cx88/cx88-mpeg.c                 |    6 +-
 drivers/media/pci/cx88/cx88-vbi.c                  |   11 +-
 drivers/media/pci/cx88/cx88-video.c                |    9 +-
 drivers/media/pci/cx88/cx88.h                      |    2 +-
 drivers/media/pci/dt3155/dt3155.c                  |   13 +-
 drivers/media/pci/dt3155/dt3155.h                  |    2 +-
 drivers/media/pci/saa7134/saa7134-core.c           |    9 +-
 drivers/media/pci/saa7134/saa7134-ts.c             |   28 ++--
 drivers/media/pci/saa7134/saa7134-vbi.c            |   22 ++--
 drivers/media/pci/saa7134/saa7134-video.c          |   33 +++--
 drivers/media/pci/saa7134/saa7134.h                |    6 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   30 +++--
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   16 ++-
 drivers/media/pci/solo6x10/solo6x10.h              |    2 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c            |   23 ++--
 drivers/media/pci/tw68/tw68-video.c                |   13 +-
 drivers/media/pci/tw68/tw68.h                      |    2 +-
 drivers/media/platform/am437x/am437x-vpfe.c        |   30 +++--
 drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
 drivers/media/platform/blackfin/bfin_capture.c     |   30 +++--
 drivers/media/platform/coda/coda-bit.c             |   60 ++++-----
 drivers/media/platform/coda/coda-common.c          |   17 +--
 drivers/media/platform/coda/coda-jpeg.c            |    6 +-
 drivers/media/platform/coda/coda.h                 |    4 +-
 drivers/media/platform/davinci/vpbe_display.c      |    3 +-
 drivers/media/platform/davinci/vpif_capture.c      |   29 +++--
 drivers/media/platform/davinci/vpif_capture.h      |    2 +-
 drivers/media/platform/davinci/vpif_display.c      |   39 +++---
 drivers/media/platform/davinci/vpif_display.h      |    2 +-
 drivers/media/platform/exynos-gsc/gsc-core.c       |   10 +-
 drivers/media/platform/exynos-gsc/gsc-core.h       |    4 +-
 drivers/media/platform/exynos-gsc/gsc-m2m.c        |    7 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   17 ++-
 drivers/media/platform/exynos4-is/fimc-core.c      |   10 +-
 drivers/media/platform/exynos4-is/fimc-core.h      |    4 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |    9 +-
 drivers/media/platform/exynos4-is/fimc-isp.h       |    2 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |   12 +-
 drivers/media/platform/exynos4-is/fimc-lite.h      |    2 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c       |    8 +-
 drivers/media/platform/m2m-deinterlace.c           |   13 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |   31 +++--
 drivers/media/platform/mx2_emmaprp.c               |   12 +-
 drivers/media/platform/omap3isp/ispvideo.c         |   24 ++--
 drivers/media/platform/omap3isp/ispvideo.h         |    2 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   14 +-
 drivers/media/platform/s3c-camif/camif-core.h      |    2 +-
 drivers/media/platform/s5p-g2d/g2d.c               |   12 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |   40 +++---
 drivers/media/platform/s5p-mfc/s5p_mfc.c           |   32 +++--
 drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   17 ++-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   61 +++++----
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |   28 ++--
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |   28 ++--
 drivers/media/platform/s5p-tv/mixer.h              |    2 +-
 drivers/media/platform/s5p-tv/mixer_grp_layer.c    |    2 +-
 drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
 drivers/media/platform/s5p-tv/mixer_video.c        |   11 +-
 drivers/media/platform/s5p-tv/mixer_vp_layer.c     |    5 +-
 drivers/media/platform/sh_veu.c                    |   20 +--
 drivers/media/platform/soc_camera/atmel-isi.c      |   22 ++--
 drivers/media/platform/soc_camera/mx2_camera.c     |   25 ++--
 drivers/media/platform/soc_camera/mx3_camera.c     |   19 +--
 drivers/media/platform/soc_camera/rcar_vin.c       |   24 ++--
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |   27 ++--
 drivers/media/platform/ti-vpe/vpe.c                |   24 ++--
 drivers/media/platform/vim2m.c                     |   26 ++--
 drivers/media/platform/vivid/vivid-core.h          |    2 +-
 drivers/media/platform/vivid/vivid-kthread-cap.c   |   20 +--
 drivers/media/platform/vivid/vivid-kthread-out.c   |   14 +-
 drivers/media/platform/vivid/vivid-sdr-cap.c       |   16 ++-
 drivers/media/platform/vivid/vivid-vbi-cap.c       |   15 ++-
 drivers/media/platform/vivid/vivid-vbi-out.c       |   11 +-
 drivers/media/platform/vivid/vivid-vid-cap.c       |   16 ++-
 drivers/media/platform/vivid/vivid-vid-out.c       |   13 +-
 drivers/media/platform/vsp1/vsp1_video.c           |   13 +-
 drivers/media/platform/vsp1/vsp1_video.h           |    4 +-
 drivers/media/usb/airspy/airspy.c                  |   18 +--
 drivers/media/usb/au0828/au0828-vbi.c              |    6 +-
 drivers/media/usb/au0828/au0828-video.c            |   38 +++---
 drivers/media/usb/au0828/au0828.h                  |    2 +-
 drivers/media/usb/em28xx/em28xx-vbi.c              |    8 +-
 drivers/media/usb/em28xx/em28xx-video.c            |   20 +--
 drivers/media/usb/em28xx/em28xx.h                  |    2 +-
 drivers/media/usb/go7007/go7007-driver.c           |    4 +-
 drivers/media/usb/go7007/go7007-priv.h             |    2 +-
 drivers/media/usb/go7007/go7007-v4l2.c             |   15 ++-
 drivers/media/usb/hackrf/hackrf.c                  |   16 ++-
 drivers/media/usb/msi2500/msi2500.c                |   18 +--
 drivers/media/usb/pwc/pwc-if.c                     |   24 ++--
 drivers/media/usb/pwc/pwc-uncompress.c             |    8 +-
 drivers/media/usb/pwc/pwc.h                        |    2 +-
 drivers/media/usb/s2255/s2255drv.c                 |   17 +--
 drivers/media/usb/stk1160/stk1160-v4l.c            |   11 +-
 drivers/media/usb/stk1160/stk1160-video.c          |    4 +-
 drivers/media/usb/stk1160/stk1160.h                |    2 +-
 drivers/media/usb/usbtv/usbtv-video.c              |   13 +-
 drivers/media/usb/usbtv/usbtv.h                    |    2 +-
 drivers/media/usb/uvc/uvc_queue.c                  |   25 ++--
 drivers/media/usb/uvc/uvcvideo.h                   |    2 +-
 drivers/media/v4l2-core/v4l2-mem2mem.c             |    6 +-
 drivers/media/v4l2-core/videobuf2-v4l2.c           |  134 ++++++++++++--------
 drivers/usb/gadget/function/uvc_queue.c            |   20 +--
 drivers/usb/gadget/function/uvc_queue.h            |    2 +-
 include/media/v4l2-mem2mem.h                       |    8 +-
 include/media/videobuf2-v4l2.h                     |   70 ++++++----
 include/trace/events/v4l2.h                        |   35 ++---
 121 files changed, 1051 insertions(+), 795 deletions(-)

diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
index 8be7b9b..2147a90 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -163,7 +163,7 @@ struct sur40_state {
 };
 
 struct sur40_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
@@ -420,7 +420,7 @@ static void sur40_process_video(struct sur40_state *sur40)
 
 	dev_dbg(sur40->dev, "header acquired\n");
 
-	sgt = vb2_dma_sg_plane_desc(&new_buf->vb, 0);
+	sgt = vb2_dma_sg_plane_desc(&new_buf->vb.vb2_buf, 0);
 
 	result = usb_sg_init(&sgr, sur40->usbdev,
 		usb_rcvbulkpipe(sur40->usbdev, VIDEO_ENDPOINT), 0,
@@ -446,12 +446,12 @@ static void sur40_process_video(struct sur40_state *sur40)
 	v4l2_get_timestamp(&new_buf->vb.v4l2_buf.timestamp);
 	new_buf->vb.v4l2_buf.sequence = sur40->sequence++;
 	new_buf->vb.v4l2_buf.field = V4L2_FIELD_NONE;
-	vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
 	dev_dbg(sur40->dev, "buffer marked done\n");
 	return;
 
 err_poll:
-	vb2_buffer_done(&new_buf->vb, VB2_BUF_STATE_ERROR);
+	vb2_buffer_done(&new_buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
 }
 
 /* Initialize input device parameters. */
@@ -685,8 +685,9 @@ static int sur40_buffer_prepare(struct vb2_buffer *vb)
  */
 static void sur40_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
-	struct sur40_buffer *buf = (struct sur40_buffer *)vb;
+	struct sur40_buffer *buf = (struct sur40_buffer *)vbuf;
 
 	spin_lock(&sur40->qlock);
 	list_add_tail(&buf->list, &sur40->buf_list);
@@ -700,7 +701,7 @@ static void return_all_buffers(struct sur40_state *sur40,
 
 	spin_lock(&sur40->qlock);
 	list_for_each_entry_safe(buf, node, &sur40->buf_list, list) {
-		vb2_buffer_done(&buf->vb, state);
+		vb2_buffer_done(&buf->vb.vb2_buf, state);
 		list_del(&buf->list);
 	}
 	spin_unlock(&sur40->qlock);
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 7edb885..c900185d 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -107,7 +107,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;
 };
 
@@ -304,13 +304,13 @@ static void rtl2832_sdr_urb_complete(struct urb *urb)
 		}
 
 		/* fill framebuffer */
-		ptr = vb2_plane_vaddr(&fbuf->vb, 0);
+		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		len = rtl2832_sdr_convert_stream(dev, ptr, urb->transfer_buffer,
 				urb->actual_length);
-		vb2_set_plane_payload(&fbuf->vb, 0, len);
+		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 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_buf, VB2_BUF_STATE_DONE);
 	}
 skip:
 	usb_submit_urb(urb, GFP_ATOMIC);
@@ -464,7 +464,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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
 }
@@ -518,14 +518,15 @@ static int rtl2832_sdr_buf_prepare(struct vb2_buffer *vb)
 
 static void rtl2832_sdr_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
 	struct rtl2832_sdr_frame_buf *buf =
-			container_of(vb, struct rtl2832_sdr_frame_buf, vb);
+			container_of(vbuf, struct rtl2832_sdr_frame_buf, vb);
 	unsigned long flags;
 
 	/* 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 63c0ee5..316a322 100644
--- a/drivers/media/pci/cx23885/cx23885-417.c
+++ b/drivers/media/pci/cx23885/cx23885-417.c
@@ -1155,17 +1155,19 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
 	struct cx23885_buffer *buf =
-		container_of(vb, struct cx23885_buffer, vb);
+		container_of(vbuf, struct cx23885_buffer, vb);
 
 	return cx23885_buf_prepare(buf, &dev->ts1);
 }
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx23885_buffer *buf = container_of(vb,
+	struct cx23885_buffer *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 
 	cx23885_free_buffer(dev, buf);
@@ -1173,8 +1175,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx23885_buffer   *buf = container_of(vb,
+	struct cx23885_buffer   *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 
 	cx23885_buf_queue(&dev->ts1, buf);
@@ -1201,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_buf, 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 7aee76a..bbea734 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_buf, VB2_BUF_STATE_DONE);
 }
 
 int cx23885_sram_channel_setup(struct cx23885_dev *dev,
@@ -1453,12 +1453,12 @@ int cx23885_buf_prepare(struct cx23885_buffer *buf, struct cx23885_tsport *port)
 {
 	struct cx23885_dev *dev = port->dev;
 	int size = port->ts_packet_size * port->ts_packet_count;
-	struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb, 0);
+	struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb.vb2_buf, 0);
 
 	dprintk(1, "%s: %p\n", __func__, buf);
-	if (vb2_plane_size(&buf->vb, 0) < size)
+	if (vb2_plane_size(&buf->vb.vb2_buf, 0) < size)
 		return -EINVAL;
-	vb2_set_plane_payload(&buf->vb, 0, size);
+	vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
 
 	cx23885_risc_databuffer(dev->pci, &buf->risc,
 				sgt->sgl,
@@ -1530,7 +1530,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_buf, 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-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index 6e8c24c..09ad512 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -110,18 +110,20 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
 	struct cx23885_buffer *buf =
-		container_of(vb, struct cx23885_buffer, vb);
+		container_of(vbuf, struct cx23885_buffer, vb);
 
 	return cx23885_buf_prepare(buf, port);
 }
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
 	struct cx23885_dev *dev = port->dev;
-	struct cx23885_buffer *buf = container_of(vb,
+	struct cx23885_buffer *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 
 	cx23885_free_buffer(dev, buf);
@@ -129,8 +131,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_tsport *port = vb->vb2_queue->drv_priv;
-	struct cx23885_buffer   *buf = container_of(vb,
+	struct cx23885_buffer   *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 
 	cx23885_buf_queue(port, buf);
diff --git a/drivers/media/pci/cx23885/cx23885-vbi.c b/drivers/media/pci/cx23885/cx23885-vbi.c
index d362d38..e84e5bd 100644
--- a/drivers/media/pci/cx23885/cx23885-vbi.c
+++ b/drivers/media/pci/cx23885/cx23885-vbi.c
@@ -138,8 +138,9 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx23885_buffer *buf = container_of(vb,
+	struct cx23885_buffer *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
 	unsigned lines = VBI_PAL_LINE_COUNT;
@@ -161,7 +162,8 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
-	struct cx23885_buffer *buf = container_of(vb,
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct cx23885_buffer *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 
 	cx23885_free_buffer(vb->vb2_queue->drv_priv, buf);
@@ -190,8 +192,9 @@ static void buffer_finish(struct vb2_buffer *vb)
  */
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb);
+	struct cx23885_buffer *buf = container_of(vbuf, struct cx23885_buffer, vb);
 	struct cx23885_buffer *prev;
 	struct cx23885_dmaqueue *q = &dev->vbiq;
 	unsigned long flags;
@@ -245,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_buf, 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 ec76470..d06fc87 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_buf, VB2_BUF_STATE_DONE);
 }
 
 int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
@@ -329,9 +329,10 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
 	struct cx23885_buffer *buf =
-		container_of(vb, struct cx23885_buffer, vb);
+		container_of(vbuf, struct cx23885_buffer, vb);
 	u32 line0_offset, line1_offset;
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
 	int field_tff;
@@ -409,7 +410,8 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
-	struct cx23885_buffer *buf = container_of(vb,
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct cx23885_buffer *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 
 	cx23885_free_buffer(vb->vb2_queue->drv_priv, buf);
@@ -438,8 +440,9 @@ static void buffer_finish(struct vb2_buffer *vb)
  */
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx23885_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx23885_buffer   *buf = container_of(vb,
+	struct cx23885_buffer   *buf = container_of(vbuf,
 		struct cx23885_buffer, vb);
 	struct cx23885_buffer   *prev;
 	struct cx23885_dmaqueue *q    = &dev->vidq;
@@ -492,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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h
index 027ead4..c5ba083 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..af0e425 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_buf, VB2_BUF_STATE_DONE);
 		}
 		spin_unlock(&dev->slock);
 		handled++;
@@ -159,10 +159,11 @@ static int cx25821_queue_setup(struct vb2_queue *q, const struct v4l2_format *fm
 
 static int cx25821_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
 	struct cx25821_dev *dev = chan->dev;
 	struct cx25821_buffer *buf =
-		container_of(vb, struct cx25821_buffer, vb);
+		container_of(vbuf, struct cx25821_buffer, vb);
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
 	u32 line0_offset;
 	int bpl_local = LINE_SIZE_D1;
@@ -240,8 +241,9 @@ static int cx25821_buffer_prepare(struct vb2_buffer *vb)
 
 static void cx25821_buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx25821_buffer *buf =
-		container_of(vb, struct cx25821_buffer, vb);
+		container_of(vbuf, struct cx25821_buffer, vb);
 	struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
 	struct cx25821_dev *dev = chan->dev;
 
@@ -250,8 +252,9 @@ static void cx25821_buffer_finish(struct vb2_buffer *vb)
 
 static void cx25821_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx25821_buffer *buf =
-		container_of(vb, struct cx25821_buffer, vb);
+		container_of(vbuf, struct cx25821_buffer, vb);
 	struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
 	struct cx25821_dev *dev = chan->dev;
 	struct cx25821_buffer *prev;
@@ -300,7 +303,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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
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 24216ef..49d0b7c 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -653,16 +653,18 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 
 	return cx8802_buf_prepare(vb->vb2_queue, dev, buf);
 }
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
 	if (risc->cpu)
@@ -672,8 +674,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer    *buf = container_of(vbuf, struct cx88_buffer, vb);
 
 	cx8802_buf_queue(dev, buf);
 }
@@ -721,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_buf, VB2_BUF_STATE_QUEUED);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 	return err;
@@ -749,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_buf, 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 aab7cf4..38ddfaf 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -522,7 +522,7 @@ void cx88_wakeup(struct cx88_core *core,
 	buf->vb.v4l2_buf.field = core->field;
 	buf->vb.v4l2_buf.sequence = q->count++;
 	list_del(&buf->list);
-	vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&buf->vb.vb2_buf, 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 9dfa5ee..f0923fb 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -99,16 +99,18 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 
 	return cx8802_buf_prepare(vb->vb2_queue, dev, buf);
 }
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
 	if (risc->cpu)
@@ -118,8 +120,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8802_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer    *buf = container_of(vbuf, struct cx88_buffer, vb);
 
 	cx8802_buf_queue(dev, buf);
 }
@@ -149,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_buf, 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 34f5057..a4f5e1e 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -229,9 +229,9 @@ int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
 	struct cx88_riscmem *risc = &buf->risc;
 	int rc;
 
-	if (vb2_plane_size(&buf->vb, 0) < size)
+	if (vb2_plane_size(&buf->vb.vb2_buf, 0) < size)
 		return -EINVAL;
-	vb2_set_plane_payload(&buf->vb, 0, size);
+	vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
 
 	rc = cx88_risc_databuffer(dev->pci, risc, sgt->sgl,
 			     dev->ts_packet_size, dev->ts_packet_count, 0);
@@ -284,7 +284,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_buf, 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 7510e80..cd2f3fb 100644
--- a/drivers/media/pci/cx88/cx88-vbi.c
+++ b/drivers/media/pci/cx88/cx88-vbi.c
@@ -125,8 +125,9 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
 	unsigned int lines;
 	unsigned int size;
@@ -149,8 +150,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
 	if (risc->cpu)
@@ -160,8 +162,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer    *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct cx88_buffer    *prev;
 	struct cx88_dmaqueue  *q    = &dev->vbiq;
 
@@ -213,7 +216,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_buf, 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 400e5ca..fae28e7 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -444,6 +444,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
 	struct cx88_core *core = dev->core;
 	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
@@ -497,8 +498,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct cx88_riscmem *risc = &buf->risc;
 
 	if (risc->cpu)
@@ -508,8 +510,9 @@ static void buffer_finish(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
-	struct cx88_buffer    *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer    *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct cx88_buffer    *prev;
 	struct cx88_core      *core = dev->core;
 	struct cx88_dmaqueue  *q    = &dev->vidq;
@@ -560,7 +563,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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index 785fe2e..2996eb3 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/dt3155/dt3155.c b/drivers/media/pci/dt3155/dt3155.c
index 8df6345..f4f8355 100644
--- a/drivers/media/pci/dt3155/dt3155.c
+++ b/drivers/media/pci/dt3155/dt3155.c
@@ -160,11 +160,11 @@ static int dt3155_buf_prepare(struct vb2_buffer *vb)
 static int dt3155_start_streaming(struct vb2_queue *q, unsigned count)
 {
 	struct dt3155_priv *pd = vb2_get_drv_priv(q);
-	struct vb2_buffer *vb = pd->curr_buf;
+	struct vb2_v4l2_buffer *vb = pd->curr_buf;
 	dma_addr_t dma_addr;
 
 	pd->sequence = 0;
-	dma_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+	dma_addr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	iowrite32(dma_addr, pd->regs + EVEN_DMA_START);
 	iowrite32(dma_addr + pd->width, pd->regs + ODD_DMA_START);
 	iowrite32(pd->width, pd->regs + EVEN_DMA_STRIDE);
@@ -208,7 +208,7 @@ static void dt3155_stop_streaming(struct vb2_queue *q)
 
 	spin_lock_irq(&pd->lock);
 	if (pd->curr_buf) {
-		vb2_buffer_done(pd->curr_buf, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&pd->curr_buf->vb2_buf, VB2_BUF_STATE_ERROR);
 		pd->curr_buf = NULL;
 	}
 
@@ -222,6 +222,7 @@ static void dt3155_stop_streaming(struct vb2_queue *q)
 
 static void dt3155_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue);
 
 	/*  pd->vidq.streaming = 1 when dt3155_buf_queue() is invoked  */
@@ -229,7 +230,7 @@ static void dt3155_buf_queue(struct vb2_buffer *vb)
 	if (pd->curr_buf)
 		list_add_tail(&vb->done_entry, &pd->dmaq);
 	else
-		pd->curr_buf = vb;
+		pd->curr_buf = vbuf;
 	spin_unlock_irq(&pd->lock);
 }
 
@@ -272,11 +273,11 @@ static irqreturn_t dt3155_irq_handler_even(int irq, void *dev_id)
 		v4l2_get_timestamp(&ipd->curr_buf->v4l2_buf.timestamp);
 		ipd->curr_buf->v4l2_buf.sequence = ipd->sequence++;
 		ipd->curr_buf->v4l2_buf.field = V4L2_FIELD_NONE;
-		vb2_buffer_done(ipd->curr_buf, VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&ipd->curr_buf->vb2_buf, VB2_BUF_STATE_DONE);
 
 		ivb = list_first_entry(&ipd->dmaq, typeof(*ivb), done_entry);
 		list_del(&ivb->done_entry);
-		ipd->curr_buf = ivb;
+		ipd->curr_buf = to_vb2_v4l2_buffer(ivb);
 		dma_addr = vb2_dma_contig_plane_dma_addr(ivb, 0);
 		iowrite32(dma_addr, ipd->regs + EVEN_DMA_START);
 		iowrite32(dma_addr + ipd->width, ipd->regs + ODD_DMA_START);
diff --git a/drivers/media/pci/dt3155/dt3155.h b/drivers/media/pci/dt3155/dt3155.h
index 4e1f4d5..73d9d6e 100644
--- a/drivers/media/pci/dt3155/dt3155.h
+++ b/drivers/media/pci/dt3155/dt3155.h
@@ -181,7 +181,7 @@ struct dt3155_priv {
 	struct pci_dev *pdev;
 	struct vb2_queue vidq;
 	struct vb2_alloc_ctx *alloc_ctx;
-	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/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index 72d7f99..7d76e59 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -216,13 +216,13 @@ int saa7134_buffer_count(unsigned int size, unsigned int count)
 
 int saa7134_buffer_startpage(struct saa7134_buf *buf)
 {
-	return saa7134_buffer_pages(vb2_plane_size(&buf->vb2, 0)) * buf->vb2.v4l2_buf.index;
+	return saa7134_buffer_pages(vb2_plane_size(&buf->vb2.vb2_buf, 0)) * buf->vb2.v4l2_buf.index;
 }
 
 unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
 {
 	unsigned long base;
-	struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0);
+	struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2.vb2_buf, 0);
 
 	base  = saa7134_buffer_startpage(buf) * 4096;
 	base += dma->sgl[0].offset;
@@ -310,7 +310,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_buf, state);
 	q->curr = NULL;
 }
 
@@ -375,7 +375,8 @@ 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_buf,
+					 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 4b202fa..62b218b 100644
--- a/drivers/media/pci/saa7134/saa7134-ts.c
+++ b/drivers/media/pci/saa7134/saa7134-ts.c
@@ -77,10 +77,11 @@ 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_buffer *vb)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
-	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct saa7134_dmaqueue *dmaq = vb->vb2_queue->drv_priv;
+	struct saa7134_buf *buf = container_of(vbuf, struct saa7134_buf, vb2);
 
 	dmaq->curr = NULL;
 	buf->activate = buffer_activate;
@@ -89,12 +90,13 @@ 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_buffer *vb)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct saa7134_dmaqueue *dmaq = vb->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);
+	struct saa7134_buf *buf = container_of(vbuf, struct saa7134_buf, vb2);
+	struct sg_table *dma = vb2_dma_sg_plane_desc(vb, 0);
 	unsigned int lines, llength, size;
 
 	ts_dbg("buffer_prepare [%p]\n", buf);
@@ -103,11 +105,11 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2)
 	lines = dev->ts.nr_packets;
 
 	size = lines * llength;
-	if (vb2_plane_size(vb2, 0) < size)
+	if (vb2_plane_size(vb, 0) < size)
 		return -EINVAL;
 
-	vb2_set_plane_payload(vb2, 0, size);
-	vb2->v4l2_buf.field = dev->field;
+	vb2_set_plane_payload(vb, 0, size);
+	vbuf->v4l2_buf.field = dev->field;
 
 	return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents,
 				    saa7134_buffer_startpage(buf));
@@ -148,10 +150,12 @@ 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_buf,
+					VB2_BUF_STATE_QUEUED);
 		}
 		if (dmaq->curr) {
-			vb2_buffer_done(&dmaq->curr->vb2, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&dmaq->curr->vb2.vb2_buf,
+					VB2_BUF_STATE_QUEUED);
 			dmaq->curr = NULL;
 		}
 		return -EBUSY;
diff --git a/drivers/media/pci/saa7134/saa7134-vbi.c b/drivers/media/pci/saa7134/saa7134-vbi.c
index 4d36586..ecc4e61 100644
--- a/drivers/media/pci/saa7134/saa7134-vbi.c
+++ b/drivers/media/pci/saa7134/saa7134-vbi.c
@@ -83,7 +83,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_buf.vb2_queue->drv_priv;
 	unsigned long control, base;
 
 	vbi_dbg("buffer_activate [%p]\n", buf);
@@ -115,12 +115,13 @@ static int buffer_activate(struct saa7134_dev *dev,
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb2)
+static int buffer_prepare(struct vb2_buffer *vb)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct saa7134_dmaqueue *dmaq = vb->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);
+	struct saa7134_buf *buf = container_of(vbuf, struct saa7134_buf, vb2);
+	struct sg_table *dma = vb2_dma_sg_plane_desc(vb, 0);
 	unsigned int size;
 
 	if (dma->sgl->offset) {
@@ -128,10 +129,10 @@ static int buffer_prepare(struct vb2_buffer *vb2)
 		return -EINVAL;
 	}
 	size = dev->vbi_hlen * dev->vbi_vlen * 2;
-	if (vb2_plane_size(vb2, 0) < size)
+	if (vb2_plane_size(vb, 0) < size)
 		return -EINVAL;
 
-	vb2_set_plane_payload(vb2, 0, size);
+	vb2_set_plane_payload(vb, 0, size);
 
 	return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents,
 				    saa7134_buffer_startpage(buf));
@@ -158,10 +159,11 @@ 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_buffer *vb)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
-	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct saa7134_dmaqueue *dmaq = vb->vb2_queue->drv_priv;
+	struct saa7134_buf *buf = container_of(vbuf, struct saa7134_buf, vb2);
 
 	dmaq->curr = NULL;
 	buf->activate = buffer_activate;
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 035039c..a03bbb8 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -791,7 +791,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_buf.vb2_queue->drv_priv;
 	unsigned long base,control,bpl;
 	unsigned long bpl_uv,lines_uv,base2,base3,tmp; /* planar */
 
@@ -869,22 +869,24 @@ static int buffer_activate(struct saa7134_dev *dev,
 	return 0;
 }
 
-static int buffer_init(struct vb2_buffer *vb2)
+static int buffer_init(struct vb2_buffer *vb)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
-	struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct saa7134_dmaqueue *dmaq = vb->vb2_queue->drv_priv;
+	struct saa7134_buf *buf = container_of(vbuf, struct saa7134_buf, vb2);
 
 	dmaq->curr = NULL;
 	buf->activate = buffer_activate;
 	return 0;
 }
 
-static int buffer_prepare(struct vb2_buffer *vb2)
+static int buffer_prepare(struct vb2_buffer *vb)
 {
-	struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct saa7134_dmaqueue *dmaq = vb->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);
+	struct saa7134_buf *buf = container_of(vbuf, struct saa7134_buf, vb2);
+	struct sg_table *dma = vb2_dma_sg_plane_desc(vb, 0);
 	unsigned int size;
 
 	if (dma->sgl->offset) {
@@ -892,11 +894,11 @@ static int buffer_prepare(struct vb2_buffer *vb2)
 		return -EINVAL;
 	}
 	size = (dev->width * dev->height * dev->fmt->depth) >> 3;
-	if (vb2_plane_size(vb2, 0) < size)
+	if (vb2_plane_size(vb, 0) < size)
 		return -EINVAL;
 
-	vb2_set_plane_payload(vb2, 0, size);
-	vb2->v4l2_buf.field = dev->field;
+	vb2_set_plane_payload(vb, 0, size);
+	vbuf->v4l2_buf.field = dev->field;
 
 	return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents,
 				    saa7134_buffer_startpage(buf));
@@ -930,9 +932,10 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
  */
 void saa7134_vb2_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct saa7134_dmaqueue *dmaq = vb->vb2_queue->drv_priv;
 	struct saa7134_dev *dev = dmaq->dev;
-	struct saa7134_buf *buf = container_of(vb, struct saa7134_buf, vb2);
+	struct saa7134_buf *buf = container_of(vbuf, struct saa7134_buf, vb2);
 
 	saa7134_buffer_queue(dev, dmaq, buf);
 }
@@ -953,10 +956,12 @@ 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_buf,
+					VB2_BUF_STATE_QUEUED);
 		}
 		if (dmaq->curr) {
-			vb2_buffer_done(&dmaq->curr->vb2, VB2_BUF_STATE_QUEUED);
+			vb2_buffer_done(&dmaq->curr->vb2.vb2_buf,
+					VB2_BUF_STATE_QUEUED);
 			dmaq->curr = NULL;
 		}
 		return -EBUSY;
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
index 6b5f6f4..f3f9ba4 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -459,7 +459,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;
@@ -817,8 +817,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_buffer *vb);
+int saa7134_ts_buffer_prepare(struct vb2_buffer *vb);
 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..6238e09 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);
@@ -464,11 +464,12 @@ static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
 
 	vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
 
-	if (vb2_plane_size(vb, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len)
+	if (vb2_plane_size(&vb->vb2_buf, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len)
 		return -EIO;
 
 	frame_size = ALIGN(vop_jpeg_size(vh) + solo_enc->jpeg_len, DMA_ALIGN);
-	vb2_set_plane_payload(vb, 0, vop_jpeg_size(vh) + solo_enc->jpeg_len);
+	vb2_set_plane_payload(&vb->vb2_buf, 0,
+			      vop_jpeg_size(vh) + solo_enc->jpeg_len);
 
 	return solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf,
 			     vop_jpeg_offset(vh) - SOLO_JPEG_EXT_ADDR(solo_dev),
@@ -477,14 +478,14 @@ 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);
 	int frame_off, frame_size;
 	int skip = 0;
 
-	if (vb2_plane_size(vb, 0) < vop_mpeg_size(vh))
+	if (vb2_plane_size(&vb->vb2_buf, 0) < vop_mpeg_size(vh))
 		return -EIO;
 
 	/* If this is a key frame, add extra header */
@@ -493,11 +494,11 @@ static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
 	if (!vop_type(vh)) {
 		skip = solo_enc->vop_len;
 		vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
-		vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh) +
-			solo_enc->vop_len);
+		vb2_set_plane_payload(&vb->vb2_buf, 0,
+				      vop_mpeg_size(vh) + solo_enc->vop_len);
 	} else {
 		vb->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
-		vb2_set_plane_payload(vb, 0, vop_mpeg_size(vh));
+		vb2_set_plane_payload(&vb->vb2_buf, 0, vop_mpeg_size(vh));
 	}
 
 	/* Now get the actual mpeg payload */
@@ -511,7 +512,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;
@@ -546,7 +547,8 @@ 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_buf,
+			ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 
 	return ret;
 }
@@ -678,10 +680,11 @@ static int solo_enc_queue_setup(struct vb2_queue *q,
 
 static void solo_enc_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->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);
+		container_of(vbuf, struct solo_vb2_buf, vb);
 
 	spin_lock(&solo_enc->av_lock);
 	list_add_tail(&solo_vb->list, &solo_enc->vidq_active);
@@ -734,20 +737,21 @@ 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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&solo_enc->av_lock, flags);
 }
 
 static void solo_enc_buf_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vb->vb2_queue);
 	struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
 
 	switch (solo_enc->fmt) {
 	case V4L2_PIX_FMT_MPEG4:
 	case V4L2_PIX_FMT_H264:
-		if (vb->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME)
+		if (vbuf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME)
 			sg_copy_from_buffer(vbuf->sgl, vbuf->nents,
 					solo_enc->vop, solo_enc->vop_len);
 		break;
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2.c b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
index 63ae8a6..b46196b 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
@@ -189,19 +189,19 @@ 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;
 	int error = -1;
 	int i;
 
-	vbuf = vb2_dma_contig_plane_dma_addr(vb, 0);
+	vbuf = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	if (!vbuf)
 		goto finish_buf;
 
 	if (erase_off(solo_dev)) {
-		void *p = vb2_plane_vaddr(vb, 0);
+		void *p = vb2_plane_vaddr(&vb->vb2_buf, 0);
 		int image_size = solo_image_size(solo_dev);
 
 		for (i = 0; i < image_size; i += 2) {
@@ -220,13 +220,14 @@ static void solo_fillbuf(struct solo_dev *solo_dev,
 
 finish_buf:
 	if (!error) {
-		vb2_set_plane_payload(vb, 0,
-			solo_vlines(solo_dev) * solo_bytesperline(solo_dev));
+		vb2_set_plane_payload(&vb->vb2_buf, 0,
+				      solo_vlines(solo_dev) * solo_bytesperline(solo_dev));
 		vb->v4l2_buf.sequence = solo_dev->sequence++;
 		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_buf,
+			error ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 }
 
 static void solo_thread_try(struct solo_dev *solo_dev)
@@ -345,10 +346,11 @@ static void solo_stop_streaming(struct vb2_queue *q)
 
 static void solo_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->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);
+		container_of(vbuf, struct solo_vb2_buf, vb);
 
 	spin_lock(&solo_dev->slock);
 	list_add_tail(&solo_vb->list, &solo_dev->vidq_active);
diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
index 5cc9e9d..4ab6586 100644
--- a/drivers/media/pci/solo6x10/solo6x10.h
+++ b/drivers/media/pci/solo6x10/solo6x10.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 59b3a36..1edc1f2 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);
 }
@@ -287,7 +287,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 };
 static int buffer_init(struct vb2_buffer *vb)
 {
-	struct vip_buffer *vip_buf = to_vip_buffer(vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
 
 	vip_buf->dma = vb2_dma_contig_plane_dma_addr(vb, 0);
 	INIT_LIST_HEAD(&vip_buf->list);
@@ -296,8 +297,9 @@ static int buffer_init(struct vb2_buffer *vb)
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
-	struct vip_buffer *vip_buf = to_vip_buffer(vb);
+	struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
 	unsigned long size;
 
 	size = vip->format.sizeimage;
@@ -307,14 +309,15 @@ static int buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(&vip_buf->vb, 0, size);
+	vb2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
-	struct vip_buffer *vip_buf = to_vip_buffer(vb);
+	struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
 
 	spin_lock(&vip->lock);
 	list_add_tail(&vip_buf->list, &vip->buffer_list);
@@ -329,8 +332,9 @@ static void buffer_queue(struct vb2_buffer *vb)
 }
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
-	struct vip_buffer *vip_buf = to_vip_buffer(vb);
+	struct vip_buffer *vip_buf = to_vip_buffer(vbuf);
 
 	/* Buffer handled, remove it from the list */
 	spin_lock(&vip->lock);
@@ -370,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_buf, VB2_BUF_STATE_ERROR);
 		list_del(&vip_buf->list);
 	}
 	spin_unlock(&vip->lock);
@@ -815,7 +819,8 @@ static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip)
 		/* Remove the active buffer from the list */
 		v4l2_get_timestamp(&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_buf,
+				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 8355e55..a2ecc5c 100644
--- a/drivers/media/pci/tw68/tw68-video.c
+++ b/drivers/media/pci/tw68/tw68-video.c
@@ -423,9 +423,10 @@ static int tw68_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
  */
 static void tw68_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->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 *buf = container_of(vbuf, struct tw68_buf, vb);
 	struct tw68_buf *prev;
 	unsigned long flags;
 
@@ -457,9 +458,10 @@ static void tw68_buf_queue(struct vb2_buffer *vb)
  */
 static int tw68_buf_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->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 *buf = container_of(vbuf, struct tw68_buf, vb);
 	struct sg_table *dma = vb2_dma_sg_plane_desc(vb, 0);
 	unsigned size, bpl;
 
@@ -499,9 +501,10 @@ static int tw68_buf_prepare(struct vb2_buffer *vb)
 
 static void tw68_buf_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->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 *buf = container_of(vbuf, struct tw68_buf, vb);
 
 	pci_free_consistent(dev->pci, buf->size, buf->cpu, buf->dma);
 }
@@ -528,7 +531,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_buf, VB2_BUF_STATE_ERROR);
 	}
 }
 
@@ -1015,7 +1018,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_buf, VB2_BUF_STATE_DONE);
 		status &= ~(TW68_DMAPI);
 		if (0 == status)
 			return;
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 c8447fa..794408b 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -307,7 +307,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);
 }
@@ -1257,14 +1257,15 @@ static inline void vpfe_schedule_next_buffer(struct vpfe_device *vpfe)
 	list_del(&vpfe->next_frm->list);
 
 	vpfe_set_sdr_addr(&vpfe->ccdc,
-		       vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb, 0));
+		       vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb.vb2_buf, 0));
 }
 
 static inline void vpfe_schedule_bottom_field(struct vpfe_device *vpfe)
 {
 	unsigned long addr;
 
-	addr = vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb, 0) +
+	addr = vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb.vb2_buf,
+					     0) +
 					vpfe->field_off;
 
 	vpfe_set_sdr_addr(&vpfe->ccdc, addr);
@@ -1283,7 +1284,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_buf, VB2_BUF_STATE_DONE);
 	vpfe->cur_frm = vpfe->next_frm;
 }
 
@@ -1942,6 +1943,7 @@ static int vpfe_queue_setup(struct vb2_queue *vq,
  */
 static int vpfe_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
 
 	vb2_set_plane_payload(vb, 0, vpfe->fmt.fmt.pix.sizeimage);
@@ -1949,7 +1951,7 @@ static int vpfe_buffer_prepare(struct vb2_buffer *vb)
 	if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
 		return -EINVAL;
 
-	vb->v4l2_buf.field = vpfe->fmt.fmt.pix.field;
+	vbuf->v4l2_buf.field = vpfe->fmt.fmt.pix.field;
 
 	return 0;
 }
@@ -1960,8 +1962,9 @@ static int vpfe_buffer_prepare(struct vb2_buffer *vb)
  */
 static void vpfe_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
-	struct vpfe_cap_buffer *buf = to_vpfe_buffer(vb);
+	struct vpfe_cap_buffer *buf = to_vpfe_buffer(vbuf);
 	unsigned long flags = 0;
 
 	/* add the buffer to the DMA queue */
@@ -2006,7 +2009,8 @@ static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
 	list_del(&vpfe->cur_frm->list);
 	spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
 
-	addr = vb2_dma_contig_plane_dma_addr(&vpfe->cur_frm->vb, 0);
+	addr = vb2_dma_contig_plane_dma_addr(&vpfe->cur_frm->vb.vb2_buf,
+					     0);
 
 	vpfe_set_sdr_addr(&vpfe->ccdc, (unsigned long)(addr));
 
@@ -2023,7 +2027,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_buf, VB2_BUF_STATE_QUEUED);
 	}
 
 	return ret;
@@ -2055,13 +2059,14 @@ 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_buf,
+				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_buf,
 					VB2_BUF_STATE_ERROR);
 		if (vpfe->next_frm != NULL)
-			vb2_buffer_done(&vpfe->next_frm->vb,
+			vb2_buffer_done(&vpfe->next_frm->vb.vb2_buf,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -2069,7 +2074,8 @@ 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_buf,
+				VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
 }
diff --git a/drivers/media/platform/am437x/am437x-vpfe.h b/drivers/media/platform/am437x/am437x-vpfe.h
index 5bfb356..587a09f 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.h
+++ b/drivers/media/platform/am437x/am437x-vpfe.h
@@ -104,7 +104,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 b7e70fb..2a03c1a 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -54,7 +54,7 @@ struct bcap_format {
 };
 
 struct bcap_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
@@ -149,7 +149,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);
 }
@@ -223,6 +223,7 @@ static int bcap_queue_setup(struct vb2_queue *vq,
 
 static int bcap_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long size = bcap_dev->fmt.sizeimage;
 
@@ -232,16 +233,16 @@ static int bcap_buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 	vb2_set_plane_payload(vb, 0, size);
-
-	vb->v4l2_buf.field = bcap_dev->fmt.field;
+	vbuf->v4l2_buf.field = bcap_dev->fmt.field;
 
 	return 0;
 }
 
 static void bcap_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct bcap_buffer *buf = to_bcap_vb(vb);
+	struct bcap_buffer *buf = to_bcap_vb(vbuf);
 	unsigned long flags;
 
 	spin_lock_irqsave(&bcap_dev->lock, flags);
@@ -251,8 +252,9 @@ static void bcap_buffer_queue(struct vb2_buffer *vb)
 
 static void bcap_buffer_cleanup(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct bcap_buffer *buf = to_bcap_vb(vb);
+	struct bcap_buffer *buf = to_bcap_vb(vbuf);
 	unsigned long flags;
 
 	spin_lock_irqsave(&bcap_dev->lock, flags);
@@ -344,7 +346,7 @@ static int bcap_start_streaming(struct vb2_queue *vq, unsigned int count)
 err:
 	list_for_each_entry_safe(buf, tmp, &bcap_dev->dma_queue, list) {
 		list_del(&buf->list);
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
+		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
 	}
 
 	return ret;
@@ -367,13 +369,14 @@ static void bcap_stop_streaming(struct vb2_queue *vq)
 
 	/* release all active buffers */
 	if (bcap_dev->cur_frm)
-		vb2_buffer_done(&bcap_dev->cur_frm->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&bcap_dev->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR);
 
 	while (!list_empty(&bcap_dev->dma_queue)) {
 		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_buf,
+				VB2_BUF_STATE_ERROR);
 	}
 }
 
@@ -392,7 +395,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);
@@ -400,11 +403,11 @@ 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_buf, VB2_BUF_STATE_ERROR);
 			ppi->err = false;
 		} else {
 			vb->v4l2_buf.sequence = bcap_dev->sequence++;
-			vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&vb->vb2_buf, VB2_BUF_STATE_DONE);
 		}
 		bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
 				struct bcap_buffer, list);
@@ -420,7 +423,8 @@ static irqreturn_t bcap_isr(int irq, void *dev_id)
 	if (bcap_dev->stop) {
 		complete(&bcap_dev->comp);
 	} else {
-		addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0);
+		addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb.vb2_buf,
+						     0);
 		ppi->ops->update_addr(ppi, (unsigned long)addr);
 		ppi->ops->start(ppi);
 	}
diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index d058447..1b5e9ae 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -179,12 +179,13 @@ 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 src_size = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
 	u32 n;
 
-	n = kfifo_in(&ctx->bitstream_fifo, vb2_plane_vaddr(src_buf, 0),
+	n = kfifo_in(&ctx->bitstream_fifo,
+		     vb2_plane_vaddr(&src_buf->vb2_buf, 0),
 		     src_size);
 	if (n < src_size)
 		return -ENOSPC;
@@ -195,15 +196,15 @@ 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;
 
 	if (coda_get_bitstream_payload(ctx) +
-	    vb2_get_plane_payload(src_buf, 0) + 512 >= ctx->bitstream.size)
+	    vb2_get_plane_payload(&src_buf->vb2_buf, 0) + 512 >= ctx->bitstream.size)
 		return false;
 
-	if (vb2_plane_vaddr(src_buf, 0) == NULL) {
+	if (vb2_plane_vaddr(&src_buf->vb2_buf, 0) == NULL) {
 		v4l2_err(&ctx->dev->v4l2_dev, "trying to queue empty buffer\n");
 		return true;
 	}
@@ -224,7 +225,7 @@ static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
 
 void coda_fill_bitstream(struct coda_ctx *ctx, bool streaming)
 {
-	struct vb2_buffer *src_buf;
+	struct vb2_v4l2_buffer *src_buf;
 	struct coda_buffer_meta *meta;
 	unsigned long flags;
 	u32 start;
@@ -476,7 +477,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;
@@ -485,11 +486,11 @@ static int coda_encode_header(struct coda_ctx *ctx, struct vb2_buffer *buf,
 	int i;
 
 	if (dev->devtype->product == CODA_960)
-		memset(vb2_plane_vaddr(buf, 0), 0, 64);
+		memset(vb2_plane_vaddr(&buf->vb2_buf, 0), 0, 64);
 
-	coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0),
+	coda_write(dev, vb2_dma_contig_plane_dma_addr(&buf->vb2_buf, 0),
 		   CODA_CMD_ENC_HEADER_BB_START);
-	bufsize = vb2_plane_size(buf, 0);
+	bufsize = vb2_plane_size(&buf->vb2_buf, 0);
 	if (dev->devtype->product == CODA_960)
 		bufsize /= 1024;
 	coda_write(dev, bufsize, CODA_CMD_ENC_HEADER_BB_SIZE);
@@ -502,14 +503,14 @@ static int coda_encode_header(struct coda_ctx *ctx, struct vb2_buffer *buf,
 
 	if (dev->devtype->product == CODA_960) {
 		for (i = 63; i > 0; i--)
-			if (((char *)vb2_plane_vaddr(buf, 0))[i] != 0)
+			if (((char *)vb2_plane_vaddr(&buf->vb2_buf, 0))[i] != 0)
 				break;
 		*size = i + 1;
 	} else {
 		*size = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->reg_idx)) -
 			coda_read(dev, CODA_CMD_ENC_HEADER_BB_START);
 	}
-	memcpy(header, vb2_plane_vaddr(buf, 0), *size);
+	memcpy(header, vb2_plane_vaddr(&buf->vb2_buf, 0), *size);
 
 	return 0;
 }
@@ -792,7 +793,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;
@@ -803,7 +804,7 @@ static int coda_start_encoding(struct coda_ctx *ctx)
 	dst_fourcc = q_data_dst->fourcc;
 
 	buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
-	bitstream_buf = vb2_dma_contig_plane_dma_addr(buf, 0);
+	bitstream_buf = vb2_dma_contig_plane_dma_addr(&buf->vb2_buf, 0);
 	bitstream_size = q_data_dst->sizeimage;
 
 	if (!coda_is_initialized(dev)) {
@@ -1178,7 +1179,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;
@@ -1219,7 +1220,7 @@ static int coda_prepare_encode(struct coda_ctx *ctx)
 	 */
 	if (src_buf->v4l2_buf.sequence == 0) {
 		pic_stream_buffer_addr =
-			vb2_dma_contig_plane_dma_addr(dst_buf, 0) +
+			vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0) +
 			ctx->vpu_header_size[0] +
 			ctx->vpu_header_size[1] +
 			ctx->vpu_header_size[2];
@@ -1227,16 +1228,16 @@ static int coda_prepare_encode(struct coda_ctx *ctx)
 			ctx->vpu_header_size[0] -
 			ctx->vpu_header_size[1] -
 			ctx->vpu_header_size[2];
-		memcpy(vb2_plane_vaddr(dst_buf, 0),
+		memcpy(vb2_plane_vaddr(&dst_buf->vb2_buf, 0),
 		       &ctx->vpu_header[0][0], ctx->vpu_header_size[0]);
-		memcpy(vb2_plane_vaddr(dst_buf, 0) + ctx->vpu_header_size[0],
+		memcpy(vb2_plane_vaddr(&dst_buf->vb2_buf, 0) + ctx->vpu_header_size[0],
 		       &ctx->vpu_header[1][0], ctx->vpu_header_size[1]);
-		memcpy(vb2_plane_vaddr(dst_buf, 0) + ctx->vpu_header_size[0] +
+		memcpy(vb2_plane_vaddr(&dst_buf->vb2_buf, 0) + ctx->vpu_header_size[0] +
 			ctx->vpu_header_size[1], &ctx->vpu_header[2][0],
 			ctx->vpu_header_size[2]);
 	} else {
 		pic_stream_buffer_addr =
-			vb2_dma_contig_plane_dma_addr(dst_buf, 0);
+			vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
 		pic_stream_buffer_size = q_data_dst->sizeimage;
 	}
 
@@ -1317,7 +1318,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;
 
@@ -1332,12 +1333,11 @@ static void coda_finish_encode(struct coda_ctx *ctx)
 
 	/* Calculate bytesused field */
 	if (dst_buf->v4l2_buf.sequence == 0) {
-		vb2_set_plane_payload(dst_buf, 0, wr_ptr - start_ptr +
-					ctx->vpu_header_size[0] +
-					ctx->vpu_header_size[1] +
-					ctx->vpu_header_size[2]);
+		vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+				      wr_ptr - start_ptr + ctx->vpu_header_size[0] + ctx->vpu_header_size[1] + ctx->vpu_header_size[2]);
 	} else {
-		vb2_set_plane_payload(dst_buf, 0, wr_ptr - start_ptr);
+		vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+				      wr_ptr - start_ptr);
 	}
 
 	v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, "frame size = %u\n",
@@ -1709,7 +1709,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;
@@ -1831,7 +1831,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;
 	unsigned long flags;
@@ -2045,7 +2045,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 			payload = width * height * 2;
 			break;
 		}
-		vb2_set_plane_payload(dst_buf, 0, payload);
+		vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload);
 
 		coda_m2m_buf_done(ctx, dst_buf, ctx->frame_errors[display_idx] ?
 				  VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 6e0c9be..0b84bd3 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -84,9 +84,9 @@ 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_y = vb2_dma_contig_plane_dma_addr(&buf->vb2_buf, 0);
 	u32 base_cb, base_cr;
 
 	switch (q_data->fourcc) {
@@ -684,7 +684,7 @@ static int coda_qbuf(struct file *file, void *priv,
 }
 
 static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
-				      struct vb2_buffer *buf)
+				      struct vb2_v4l2_buffer *buf)
 {
 	struct vb2_queue *src_vq;
 
@@ -694,7 +694,7 @@ static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
 		(buf->v4l2_buf.sequence == (ctx->qsequence - 1)));
 }
 
-void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_buffer *buf,
+void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
 		       enum vb2_buffer_state state)
 {
 	const struct v4l2_event eos_event = {
@@ -1175,6 +1175,7 @@ static int coda_buf_prepare(struct vb2_buffer *vb)
 
 static void coda_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 	struct vb2_queue *vq = vb->vb2_queue;
 	struct coda_q_data *q_data;
@@ -1193,12 +1194,12 @@ static void coda_buf_queue(struct vb2_buffer *vb)
 		if (vb2_get_plane_payload(vb, 0) == 0)
 			coda_bit_stream_end_flag(ctx);
 		mutex_lock(&ctx->bitstream_mutex);
-		v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
+		v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 		if (vb2_is_streaming(vb->vb2_queue))
 			coda_fill_bitstream(ctx, true);
 		mutex_unlock(&ctx->bitstream_mutex);
 	} else {
-		v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
+		v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 	}
 }
 
@@ -1247,7 +1248,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);
@@ -1338,7 +1339,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;
 	unsigned long flags;
 	bool stop;
 
diff --git a/drivers/media/platform/coda/coda-jpeg.c b/drivers/media/platform/coda/coda-jpeg.c
index 11e734b..0d09ffd 100644
--- a/drivers/media/platform/coda/coda-jpeg.c
+++ b/drivers/media/platform/coda/coda-jpeg.c
@@ -178,12 +178,12 @@ 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);
+	void *vaddr = vb2_plane_vaddr(&vb->vb2_buf, 0);
 	u16 soi = be16_to_cpup((__be16 *)vaddr);
 	u16 eoi = be16_to_cpup((__be16 *)(vaddr +
-					  vb2_get_plane_payload(vb, 0) - 2));
+					  vb2_get_plane_payload(&vb->vb2_buf, 0) - 2));
 
 	return soi == SOI_MARKER && eoi == EOI_MARKER;
 }
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index feb9671..3684583 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.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);
@@ -289,7 +289,7 @@ void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_buffer *buf,
 
 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 f69cdd7..bf5bf69 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -260,7 +260,8 @@ vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 static void vpbe_buffer_queue(struct vb2_buffer *vb)
 {
 	/* Get the file handle object and layer object */
-	struct vpbe_disp_buffer *buf = container_of(vb,
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct vpbe_disp_buffer *buf = container_of(vbuf,
 				struct vpbe_disp_buffer, vb);
 	struct vpbe_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
 	struct vpbe_display *disp = layer->disp_dev;
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index a5f5481..d0d76e2 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -57,7 +57,7 @@ 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);
 }
@@ -72,6 +72,7 @@ static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_buffer *vb)
  */
 static int vpif_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *q = vb->vb2_queue;
 	struct channel_obj *ch = vb2_get_drv_priv(q);
 	struct common_obj *common;
@@ -85,7 +86,7 @@ static int vpif_buffer_prepare(struct vb2_buffer *vb)
 	if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
 		return -EINVAL;
 
-	vb->v4l2_buf.field = common->fmt.fmt.pix.field;
+	vbuf->v4l2_buf.field = common->fmt.fmt.pix.field;
 
 	addr = vb2_dma_contig_plane_dma_addr(vb, 0);
 	if (!IS_ALIGNED((addr + common->ytop_off), 8) ||
@@ -145,8 +146,9 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq,
  */
 static void vpif_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct channel_obj *ch = vb2_get_drv_priv(vb->vb2_queue);
-	struct vpif_cap_buffer *buf = to_vpif_buffer(vb);
+	struct vpif_cap_buffer *buf = to_vpif_buffer(vbuf);
 	struct common_obj *common;
 	unsigned long flags;
 
@@ -214,7 +216,8 @@ static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
 	list_del(&common->cur_frm->list);
 	spin_unlock_irqrestore(&common->irqlock, flags);
 
-	addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
+	addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb.vb2_buf,
+					     0);
 
 	common->set_addr(addr + common->ytop_off,
 			 addr + common->ybtm_off,
@@ -243,7 +246,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_buf, VB2_BUF_STATE_QUEUED);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 
@@ -286,13 +289,14 @@ 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_buf,
+				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_buf,
 					VB2_BUF_STATE_ERROR);
 		if (common->next_frm != NULL)
-			vb2_buffer_done(&common->next_frm->vb,
+			vb2_buffer_done(&common->next_frm->vb.vb2_buf,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -300,7 +304,8 @@ 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_buf,
+				VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 }
@@ -326,8 +331,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_BUF_STATE_DONE);
+	vb2_buffer_done(&common->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE);
 	/* Make curFrm pointing to nextFrm */
 	common->cur_frm = common->next_frm;
 }
@@ -350,7 +354,8 @@ static void vpif_schedule_next_buffer(struct common_obj *common)
 	/* Remove that buffer from the buffer queue */
 	list_del(&common->next_frm->list);
 	spin_unlock(&common->irqlock);
-	addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
+	addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb.vb2_buf,
+					     0);
 
 	/* Set top and bottom field addresses in VPIF registers */
 	common->set_addr(addr + common->ytop_off,
diff --git a/drivers/media/platform/davinci/vpif_capture.h b/drivers/media/platform/davinci/vpif_capture.h
index 8b8a663..4a76009 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 682e5d5..46fc783 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -53,7 +53,7 @@ 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);
 }
@@ -66,21 +66,22 @@ static inline struct vpif_disp_buffer *to_vpif_buffer(struct vb2_buffer *vb)
  * 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 common_obj *common;
 
 	common = &ch->common[VPIF_VIDEO_INDEX];
 
-	vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
-	if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
+	vb2_set_plane_payload(&vb->vb2_buf, 0, common->fmt.fmt.pix.sizeimage);
+	if (vb2_get_plane_payload(&vb->vb2_buf, 0) > vb2_plane_size(&vb->vb2_buf, 0))
 		return -EINVAL;
 
 	vb->v4l2_buf.field = common->fmt.fmt.pix.field;
 
 	if (vb->vb2_queue->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
-		unsigned long addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+		unsigned long addr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf,
+								   0);
 
 		if (!ISALIGNED(addr + common->ytop_off) ||
 			!ISALIGNED(addr + common->ybtm_off) ||
@@ -136,7 +137,7 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq,
  *
  * 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);
@@ -197,7 +198,8 @@ static int vpif_start_streaming(struct vb2_queue *vq, unsigned int count)
 	list_del(&common->cur_frm->list);
 	spin_unlock_irqrestore(&common->irqlock, flags);
 
-	addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb, 0);
+	addr = vb2_dma_contig_plane_dma_addr(&common->cur_frm->vb.vb2_buf,
+					     0);
 	common->set_addr((addr + common->ytop_off),
 			    (addr + common->ybtm_off),
 			    (addr + common->ctop_off),
@@ -229,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_buf, VB2_BUF_STATE_QUEUED);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 
@@ -264,13 +266,14 @@ 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_buf,
+				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_buf,
 					VB2_BUF_STATE_ERROR);
 		if (common->next_frm != NULL)
-			vb2_buffer_done(&common->next_frm->vb,
+			vb2_buffer_done(&common->next_frm->vb.vb2_buf,
 					VB2_BUF_STATE_ERROR);
 	}
 
@@ -278,7 +281,8 @@ 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_buf,
+				VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&common->irqlock, flags);
 }
@@ -306,7 +310,8 @@ static void process_progressive_mode(struct common_obj *common)
 	spin_unlock(&common->irqlock);
 
 	/* Set top and bottom field addrs in VPIF registers */
-	addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb, 0);
+	addr = vb2_dma_contig_plane_dma_addr(&common->next_frm->vb.vb2_buf,
+					     0);
 	common->set_addr(addr + common->ytop_off,
 				 addr + common->ybtm_off,
 				 addr + common->ctop_off,
@@ -326,8 +331,8 @@ 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_BUF_STATE_DONE);
+		vb2_buffer_done(&common->cur_frm->vb.vb2_buf,
+				VB2_BUF_STATE_DONE);
 		/* Make cur_frm pointing to next_frm */
 		common->cur_frm = common->next_frm;
 
@@ -382,8 +387,8 @@ 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_BUF_STATE_DONE);
+				vb2_buffer_done(&common->cur_frm->vb.vb2_buf,
+						VB2_BUF_STATE_DONE);
 				/* Make cur_frm pointing to next_frm */
 				common->cur_frm = common->next_frm;
 			}
diff --git a/drivers/media/platform/davinci/vpif_display.h b/drivers/media/platform/davinci/vpif_display.h
index 849e0e3..e7a1723 100644
--- a/drivers/media/platform/davinci/vpif_display.h
+++ b/drivers/media/platform/davinci/vpif_display.h
@@ -62,7 +62,7 @@ struct video_obj {
 };
 
 struct vpif_disp_buffer {
-	struct vb2_buffer vb;
+	struct vb2_v4l2_buffer vb;
 	struct list_head list;
 };
 
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 9b9e423..1ac17b4 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;
@@ -812,7 +812,7 @@ int gsc_prepare_addr(struct gsc_ctx *ctx, struct vb2_buffer *vb,
 	pr_debug("num_planes= %d, num_comp= %d, pix_size= %d",
 		frame->fmt->num_planes, frame->fmt->num_comp, pix_size);
 
-	addr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
+	addr->y = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 
 	if (frame->fmt->num_planes == 1) {
 		switch (frame->fmt->num_comp) {
@@ -841,10 +841,12 @@ int gsc_prepare_addr(struct gsc_ctx *ctx, struct vb2_buffer *vb,
 		}
 	} else {
 		if (frame->fmt->num_planes >= 2)
-			addr->cb = vb2_dma_contig_plane_dma_addr(vb, 1);
+			addr->cb = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf,
+								 1);
 
 		if (frame->fmt->num_planes == 3)
-			addr->cr = vb2_dma_contig_plane_dma_addr(vb, 2);
+			addr->cr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf,
+								 2);
 	}
 
 	if ((frame->fmt->pixelformat == V4L2_PIX_FMT_VYUY) ||
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.h b/drivers/media/platform/exynos-gsc/gsc-core.h
index 769ff50..7dd6aef 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.h
+++ b/drivers/media/platform/exynos-gsc/gsc-core.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..6003a4f 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;
@@ -255,12 +255,13 @@ static int gsc_m2m_buf_prepare(struct vb2_buffer *vb)
 
 static void gsc_m2m_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 
 	pr_debug("ctx: %p, ctx->state: 0x%x", ctx, ctx->state);
 
 	if (ctx->m2m_ctx)
-		v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
+		v4l2_m2m_buf_queue(ctx->m2m_ctx, vbuf);
 }
 
 static struct vb2_ops gsc_m2m_qops = {
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index d0ceae3..78133c1 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_buf, VB2_BUF_STATE_ERROR);
 	}
 	/* If suspending put unused buffers onto pending queue */
 	while (!list_empty(&cap->active_buf_q)) {
@@ -111,7 +111,8 @@ 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_buf,
+				        VB2_BUF_STATE_ERROR);
 	}
 
 	fimc_hw_reset(fimc);
@@ -202,7 +203,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_buf, VB2_BUF_STATE_DONE);
 	}
 
 	if (!list_empty(&cap->pending_buf_q)) {
@@ -233,7 +234,7 @@ void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf)
 		list_for_each_entry(v_buf, &cap->active_buf_q, list) {
 			if (v_buf->index != index)
 				continue;
-			vaddr = vb2_plane_vaddr(&v_buf->vb, plane);
+			vaddr = vb2_plane_vaddr(&v_buf->vb.vb2_buf, plane);
 			v4l2_subdev_call(csis, video, s_rx_buffer,
 					 vaddr, &size);
 			break;
@@ -338,7 +339,7 @@ int fimc_capture_resume(struct fimc_dev *fimc)
 		if (list_empty(&vid_cap->pending_buf_q))
 			break;
 		buf = fimc_pending_queue_pop(vid_cap);
-		buffer_queue(&buf->vb);
+		buffer_queue(&buf->vb.vb2_buf);
 	}
 	return 0;
 
@@ -410,8 +411,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct fimc_vid_buffer *buf
-		= container_of(vb, struct fimc_vid_buffer, vb);
+		= container_of(vbuf, struct fimc_vid_buffer, vb);
 	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 	struct fimc_dev *fimc = ctx->fimc_dev;
 	struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
@@ -1472,7 +1474,8 @@ void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification,
 		if (!list_empty(&fimc->vid_cap.active_buf_q)) {
 			buf = list_entry(fimc->vid_cap.active_buf_q.next,
 					 struct fimc_vid_buffer, list);
-			vb2_set_plane_payload(&buf->vb, 0, *((u32 *)arg));
+			vb2_set_plane_payload(&buf->vb.vb2_buf, 0,
+					      *((u32 *)arg));
 		}
 		fimc_capture_irq_handler(fimc, 1);
 		fimc_deactivate_capture(fimc);
diff --git a/drivers/media/platform/exynos4-is/fimc-core.c b/drivers/media/platform/exynos4-is/fimc-core.c
index cef2a7f..779ff35 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.c
+++ b/drivers/media/platform/exynos4-is/fimc-core.c
@@ -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;
@@ -362,7 +362,7 @@ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
 	dbg("memplanes= %d, colplanes= %d, pix_size= %d",
 		frame->fmt->memplanes, frame->fmt->colplanes, pix_size);
 
-	paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
+	paddr->y = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 
 	if (frame->fmt->memplanes == 1) {
 		switch (frame->fmt->colplanes) {
@@ -390,10 +390,12 @@ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
 		}
 	} else if (!frame->fmt->mdataplanes) {
 		if (frame->fmt->memplanes >= 2)
-			paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1);
+			paddr->cb = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf,
+								  1);
 
 		if (frame->fmt->memplanes == 3)
-			paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2);
+			paddr->cr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf,
+								  2);
 	}
 
 	dbg("PHYS_ADDR: y= 0x%X  cb= 0x%X cr= 0x%X ret= %d",
diff --git a/drivers/media/platform/exynos4-is/fimc-core.h b/drivers/media/platform/exynos4-is/fimc-core.h
index ccb5d91..042276c 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.h
+++ b/drivers/media/platform/exynos4-is/fimc-core.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-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 195f9b5..52e1d61 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -194,10 +194,11 @@ static int isp_video_capture_buffer_prepare(struct vb2_buffer *vb)
 
 static void isp_video_capture_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct fimc_isp *isp = vb2_get_drv_priv(vb->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);
+	struct isp_video_buf *ivb = to_isp_video_buf(vbuf);
 	unsigned long flags;
 	unsigned int i;
 
@@ -220,7 +221,7 @@ static void isp_video_capture_buffer_queue(struct vb2_buffer *vb)
 
 			isp_dbg(2, &video->ve.vdev,
 				"dma_buf %pad (%d/%d/%d) addr: %pad\n",
-				&buf_index, ivb->index, i, vb->v4l2_buf.index,
+				&buf_index, ivb->index, i, vbuf->v4l2_buf.index,
 				&ivb->dma_addr[i]);
 		}
 
@@ -242,7 +243,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 */
@@ -253,7 +254,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_buf, 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-isp.h b/drivers/media/platform/exynos4-is/fimc-isp.h
index ad9908b..c2d25df 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.h
+++ b/drivers/media/platform/exynos4-is/fimc-isp.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 7e37c9a..316d25b 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_buf, VB2_BUF_STATE_ERROR);
 	}
 	/* If suspending put unused buffers onto pending queue */
 	while (!list_empty(&fimc->active_buf_q)) {
@@ -208,7 +208,8 @@ 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_buf,
+					VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&fimc->slock, flags);
@@ -300,7 +301,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_buf, VB2_BUF_STATE_DONE);
 	}
 
 	if (test_bit(ST_FLITE_CONFIG, &fimc->state))
@@ -422,8 +423,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct flite_buffer *buf
-		= container_of(vb, struct flite_buffer, vb);
+		= container_of(vbuf, struct flite_buffer, vb);
 	struct fimc_lite *fimc = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long flags;
 
@@ -1637,7 +1639,7 @@ static int fimc_lite_resume(struct device *dev)
 		if (list_empty(&fimc->pending_buf_q))
 			break;
 		buf = fimc_lite_pending_queue_pop(fimc);
-		buffer_queue(&buf->vb);
+		buffer_queue(&buf->vb.vb2_buf);
 	}
 	return 0;
 }
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.h b/drivers/media/platform/exynos4-is/fimc-lite.h
index 7e4c708..b302305 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.h
+++ b/drivers/media/platform/exynos4-is/fimc-lite.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 9c27335..f6e72b4 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -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;
@@ -220,8 +220,10 @@ static int fimc_buf_prepare(struct vb2_buffer *vb)
 
 static void fimc_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
-	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
+
+	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
 static struct vb2_ops fimc_qops = {
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index c07f367..475e82d 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;
@@ -243,8 +243,9 @@ static void deinterlace_issue_dma(struct deinterlace_ctx *ctx, int op,
 	s_height = s_q_data->height;
 	s_size = s_width * s_height;
 
-	p_in = (dma_addr_t)vb2_dma_contig_plane_dma_addr(src_buf, 0);
-	p_out = (dma_addr_t)vb2_dma_contig_plane_dma_addr(dst_buf, 0);
+	p_in = (dma_addr_t)vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
+	p_out = (dma_addr_t)vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf,
+							  0);
 	if (!p_in || !p_out) {
 		v4l2_err(&pcdev->v4l2_dev,
 			 "Acquiring kernel pointers to buffers failed\n");
@@ -849,8 +850,10 @@ static int deinterlace_buf_prepare(struct vb2_buffer *vb)
 
 static void deinterlace_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct deinterlace_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
-	v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
+
+	v4l2_m2m_buf_queue(ctx->m2m_ctx, vbuf);
 }
 
 static struct vb2_ops deinterlace_qops = {
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 5e2b4df..645ebf8 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -201,18 +201,18 @@ struct mcam_dma_desc {
 
 /*
  * 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 */
 	int dma_desc_nent;		/* Number of mapped descriptors */
 };
 
-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);
 }
@@ -221,14 +221,14 @@ 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];
 	vbuf->v4l2_buf.field = V4L2_FIELD_NONE;
 	v4l2_get_timestamp(&vbuf->v4l2_buf.timestamp);
-	vb2_set_plane_payload(vbuf, 0, cam->pix_format.sizeimage);
-	vb2_buffer_done(vbuf, VB2_BUF_STATE_DONE);
+	vb2_set_plane_payload(&vbuf->vb2_buf, 0, cam->pix_format.sizeimage);
+	vb2_buffer_done(&vbuf->vb2_buf, VB2_BUF_STATE_DONE);
 }
 
 
@@ -482,7 +482,8 @@ static void mcam_frame_tasklet(unsigned long data)
 		 * Drop the lock during the big copy.  This *should* be safe...
 		 */
 		spin_unlock_irqrestore(&cam->dev_lock, flags);
-		memcpy(vb2_plane_vaddr(&buf->vb_buf, 0), cam->dma_bufs[bufno],
+		memcpy(vb2_plane_vaddr(&buf->vb_buf.vb2_buf, 0),
+				cam->dma_bufs[bufno],
 				cam->pix_format.sizeimage);
 		mcam_buffer_done(cam, bufno, &buf->vb_buf);
 		spin_lock_irqsave(&cam->dev_lock, flags);
@@ -548,7 +549,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 {
 	struct mcam_vb_buffer *buf;
 	dma_addr_t dma_handle;
-	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vb;
 
 	/*
 	 * If there are no available buffers, go into single mode
@@ -570,7 +571,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
 	cam->vb_bufs[frame] = buf;
 	vb = &buf->vb_buf;
 
-	dma_handle = vb2_dma_contig_plane_dma_addr(vb, 0);
+	dma_handle = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	mcam_write_yuv_bases(cam, frame, dma_handle);
 }
 
@@ -1071,7 +1072,8 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
 
 static void mcam_vb_buf_queue(struct vb2_buffer *vb)
 {
-	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct mcam_vb_buffer *mvb = vb_to_mvb(vbuf);
 	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long flags;
 	int start;
@@ -1198,7 +1200,8 @@ static const struct vb2_ops mcam_vb2_ops = {
  */
 static int mcam_vb_sg_buf_init(struct vb2_buffer *vb)
 {
-	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct mcam_vb_buffer *mvb = vb_to_mvb(vbuf);
 	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
 	int ndesc = cam->pix_format.sizeimage/PAGE_SIZE + 1;
 
@@ -1214,7 +1217,8 @@ static int mcam_vb_sg_buf_init(struct vb2_buffer *vb)
 
 static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
 {
-	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct mcam_vb_buffer *mvb = vb_to_mvb(vbuf);
 	struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
 	struct mcam_dma_desc *desc = mvb->dma_desc;
 	struct scatterlist *sg;
@@ -1230,8 +1234,9 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
 
 static void mcam_vb_sg_buf_cleanup(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct mcam_camera *cam = vb2_get_drv_priv(vb->vb2_queue);
-	struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
+	struct mcam_vb_buffer *mvb = vb_to_mvb(vbuf);
 	int ndesc = cam->pix_format.sizeimage/PAGE_SIZE + 1;
 
 	dma_free_coherent(cam->dev, ndesc * sizeof(struct mcam_dma_desc),
diff --git a/drivers/media/platform/mx2_emmaprp.c b/drivers/media/platform/mx2_emmaprp.c
index 87314b7..03072e2 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;
@@ -309,8 +309,8 @@ static void emmaprp_device_run(void *priv)
 	d_height = d_q_data->height;
 	d_size = d_width * d_height;
 
-	p_in = vb2_dma_contig_plane_dma_addr(src_buf, 0);
-	p_out = vb2_dma_contig_plane_dma_addr(dst_buf, 0);
+	p_in = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
+	p_out = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
 	if (!p_in || !p_out) {
 		v4l2_err(&pcdev->v4l2_dev,
 			 "Acquiring kernel pointers to buffers failed\n");
@@ -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;
 
@@ -742,8 +742,10 @@ static int emmaprp_buf_prepare(struct vb2_buffer *vb)
 
 static void emmaprp_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct emmaprp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
-	v4l2_m2m_buf_queue(ctx->m2m_ctx, vb);
+
+	v4l2_m2m_buf_queue(ctx->m2m_ctx, vbuf);
 }
 
 static struct vb2_ops emmaprp_qops = {
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index d285af1..09d4c82 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -340,10 +340,11 @@ 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_buffer *vb)
 {
-	struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
-	struct isp_buffer *buffer = to_isp_buffer(buf);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct isp_video_fh *vfh = vb2_get_drv_priv(vb->vb2_queue);
+	struct isp_buffer *buffer = to_isp_buffer(vbuf);
 	struct isp_video *video = vfh->video;
 	dma_addr_t addr;
 
@@ -356,14 +357,14 @@ static int isp_video_buffer_prepare(struct vb2_buffer *buf)
 	if (unlikely(video->error))
 		return -EIO;
 
-	addr = vb2_dma_contig_plane_dma_addr(buf, 0);
+	addr = vb2_dma_contig_plane_dma_addr(vb, 0);
 	if (!IS_ALIGNED(addr, 32)) {
 		dev_dbg(video->isp->dev,
 			"Buffer address must be aligned to 32 bytes boundary.\n");
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(&buffer->vb, 0, vfh->format.fmt.pix.sizeimage);
+	vb2_set_plane_payload(vb, 0, vfh->format.fmt.pix.sizeimage);
 	buffer->dma = addr;
 
 	return 0;
@@ -378,10 +379,11 @@ 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_buffer *vb)
 {
-	struct isp_video_fh *vfh = vb2_get_drv_priv(buf->vb2_queue);
-	struct isp_buffer *buffer = to_isp_buffer(buf);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct isp_video_fh *vfh = vb2_get_drv_priv(vb->vb2_queue);
+	struct isp_buffer *buffer = to_isp_buffer(vbuf);
 	struct isp_video *video = vfh->video;
 	struct isp_pipeline *pipe = to_isp_pipeline(&video->video.entity);
 	enum isp_pipeline_state state;
@@ -392,7 +394,7 @@ static void isp_video_buffer_queue(struct vb2_buffer *buf)
 	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_buf, VB2_BUF_STATE_ERROR);
 		spin_unlock_irqrestore(&video->irqlock, flags);
 		return;
 	}
@@ -491,7 +493,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_buf, state);
 
 	spin_lock_irqsave(&video->irqlock, flags);
 
@@ -546,7 +548,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_buf, VB2_BUF_STATE_ERROR);
 	}
 
 	video->error = true;
diff --git a/drivers/media/platform/omap3isp/ispvideo.h b/drivers/media/platform/omap3isp/ispvideo.h
index 31c2445..bcf0e0a 100644
--- a/drivers/media/platform/omap3isp/ispvideo.h
+++ b/drivers/media/platform/omap3isp/ispvideo.h
@@ -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 bb01eaa..c8bf624 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_buf, 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_buf, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&camif->slock, flags);
@@ -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;
@@ -253,7 +253,7 @@ static int camif_prepare_addr(struct camif_vp *vp, struct vb2_buffer *vb,
 	pr_debug("colplanes: %d, pix_size: %u\n",
 		 vp->out_fmt->colplanes, pix_size);
 
-	paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
+	paddr->y = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 
 	switch (vp->out_fmt->colplanes) {
 	case 1:
@@ -346,7 +346,8 @@ 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_buf,
+					VB2_BUF_STATE_DONE);
 
 			/* Set up an empty buffer at the DMA engine */
 			vbuf = camif_pending_queue_pop(vp);
@@ -496,7 +497,8 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
-	struct camif_buffer *buf = container_of(vb, struct camif_buffer, vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct camif_buffer *buf = container_of(vbuf, struct camif_buffer, vb);
 	struct camif_vp *vp = vb2_get_drv_priv(vb->vb2_queue);
 	struct camif_dev *camif = vp->camif;
 	unsigned long flags;
diff --git a/drivers/media/platform/s3c-camif/camif-core.h b/drivers/media/platform/s3c-camif/camif-core.h
index 8ef6f26..adaf196 100644
--- a/drivers/media/platform/s3c-camif/camif-core.h
+++ b/drivers/media/platform/s3c-camif/camif-core.h
@@ -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 81483da..9e50173 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -134,8 +134,10 @@ static int g2d_buf_prepare(struct vb2_buffer *vb)
 
 static void g2d_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct g2d_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
-	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
+
+	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
 static struct vb2_ops g2d_qops = {
@@ -496,7 +498,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;
 
@@ -511,10 +513,10 @@ static void device_run(void *prv)
 	spin_lock_irqsave(&dev->ctrl_lock, flags);
 
 	g2d_set_src_size(dev, &ctx->in);
-	g2d_set_src_addr(dev, vb2_dma_contig_plane_dma_addr(src, 0));
+	g2d_set_src_addr(dev, vb2_dma_contig_plane_dma_addr(&src->vb2_buf, 0));
 
 	g2d_set_dst_size(dev, &ctx->out);
-	g2d_set_dst_addr(dev, vb2_dma_contig_plane_dma_addr(dst, 0));
+	g2d_set_dst_addr(dev, vb2_dma_contig_plane_dma_addr(&dst->vb2_buf, 0));
 
 	g2d_set_rop4(dev, ctx->rop);
 	g2d_set_flip(dev, ctx->flip);
@@ -537,7 +539,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 712d8c3..2300740 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1762,15 +1762,15 @@ 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);
 
 	src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
-	src_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
-	dst_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0);
+	src_addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
 
 	s5p_jpeg_reset(jpeg->regs);
 	s5p_jpeg_poweron(jpeg->regs);
@@ -1843,8 +1843,9 @@ 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;
 
 	jpeg_addr.cb = 0;
@@ -1862,7 +1863,7 @@ static void exynos4_jpeg_set_img_addr(struct s5p_jpeg_ctx *ctx)
 		vb = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 	}
 
-	jpeg_addr.y = vb2_dma_contig_plane_dma_addr(vb, 0);
+	jpeg_addr.y = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 
 	if (fmt->colplanes == 2) {
 		jpeg_addr.cb = jpeg_addr.y + pix_size - padding_bytes;
@@ -1880,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)
@@ -1888,7 +1889,7 @@ static void exynos4_jpeg_set_jpeg_addr(struct s5p_jpeg_ctx *ctx)
 	else
 		vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 
-	jpeg_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+	jpeg_addr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	exynos4_jpeg_set_stream_buf_address(jpeg->regs, jpeg_addr);
 }
 
@@ -1947,8 +1948,9 @@ 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;
 
 	pix_size = ctx->cap_q.w * ctx->cap_q.h;
@@ -1961,7 +1963,7 @@ static void exynos3250_jpeg_set_img_addr(struct s5p_jpeg_ctx *ctx)
 		fmt = ctx->cap_q.fmt;
 	}
 
-	jpeg_addr.y = vb2_dma_contig_plane_dma_addr(vb, 0);
+	jpeg_addr.y = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 
 	if (fmt->colplanes == 2) {
 		jpeg_addr.cb = jpeg_addr.y + pix_size;
@@ -1979,7 +1981,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)
@@ -1987,7 +1989,7 @@ static void exynos3250_jpeg_set_jpeg_addr(struct s5p_jpeg_ctx *ctx)
 	else
 		vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 
-	jpeg_addr = vb2_dma_contig_plane_dma_addr(vb, 0);
+	jpeg_addr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	exynos3250_jpeg_jpgadr(jpeg->regs, jpeg_addr);
 }
 
@@ -2170,6 +2172,7 @@ static int s5p_jpeg_buf_prepare(struct vb2_buffer *vb)
 
 static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 
 	if (ctx->mode == S5P_JPEG_DECODE &&
@@ -2193,7 +2196,7 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
 		q_data->h = tmp.h;
 	}
 
-	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
+	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
 static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count)
@@ -2264,7 +2267,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;
@@ -2306,7 +2309,7 @@ static irqreturn_t s5p_jpeg_irq(int irq, void *dev_id)
 
 	v4l2_m2m_buf_done(src_buf, state);
 	if (curr_ctx->mode == S5P_JPEG_ENCODE)
-		vb2_set_plane_payload(dst_buf, 0, payload_size);
+		vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size);
 	v4l2_m2m_buf_done(dst_buf, state);
 	v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx);
 
@@ -2321,7 +2324,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;
@@ -2363,7 +2366,8 @@ static irqreturn_t exynos4_jpeg_irq(int irq, void *priv)
 	if (jpeg->irq_ret == OK_ENC_OR_DEC) {
 		if (curr_ctx->mode == S5P_JPEG_ENCODE) {
 			payload_size = exynos4_jpeg_get_stream_size(jpeg->regs);
-			vb2_set_plane_payload(dst_vb, 0, payload_size);
+			vb2_set_plane_payload(&dst_vb->vb2_buf, 0,
+					      payload_size);
 		}
 		v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
 		v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE);
@@ -2383,7 +2387,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;
@@ -2432,7 +2436,7 @@ static irqreturn_t exynos3250_jpeg_irq(int irq, void *dev_id)
 
 	v4l2_m2m_buf_done(src_buf, state);
 	if (curr_ctx->mode == S5P_JPEG_ENCODE)
-		vb2_set_plane_payload(dst_buf, 0, payload_size);
+		vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size);
 	v4l2_m2m_buf_done(dst_buf, state);
 	v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx);
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index b3758b8..5baa069 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -200,8 +200,8 @@ static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
 				     struct s5p_mfc_buf, list);
 		mfc_debug(2, "Cleaning up buffer: %d\n",
 					  dst_buf->b->v4l2_buf.index);
-		vb2_set_plane_payload(dst_buf->b, 0, 0);
-		vb2_set_plane_payload(dst_buf->b, 1, 0);
+		vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0, 0);
+		vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1, 0);
 		list_del(&dst_buf->list);
 		ctx->dst_queue_cnt--;
 		dst_buf->b->v4l2_buf.sequence = (ctx->sequence++);
@@ -214,7 +214,7 @@ static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
 		dst_buf->b->v4l2_buf.flags |= V4L2_BUF_FLAG_LAST;
 
 		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_buf, VB2_BUF_STATE_DONE);
 	}
 }
 
@@ -235,7 +235,7 @@ static void s5p_mfc_handle_frame_copy_time(struct s5p_mfc_ctx *ctx)
 	   appropriate flags. */
 	src_buf = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
 	list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
-		if (vb2_dma_contig_plane_dma_addr(dst_buf->b, 0) == dec_y_addr) {
+		if (vb2_dma_contig_plane_dma_addr(&dst_buf->b->vb2_buf, 0) == dec_y_addr) {
 			dst_buf->b->v4l2_buf.timecode =
 						src_buf->b->v4l2_buf.timecode;
 			dst_buf->b->v4l2_buf.timestamp =
@@ -296,7 +296,7 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
 	 * check which videobuf does it correspond to */
 	list_for_each_entry(dst_buf, &ctx->dst_queue, list) {
 		/* Check if this is the buffer we're looking for */
-		if (vb2_dma_contig_plane_dma_addr(dst_buf->b, 0) == dspl_y_addr) {
+		if (vb2_dma_contig_plane_dma_addr(&dst_buf->b->vb2_buf, 0) == dspl_y_addr) {
 			list_del(&dst_buf->list);
 			ctx->dst_queue_cnt--;
 			dst_buf->b->v4l2_buf.sequence = ctx->sequence;
@@ -308,13 +308,15 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
 			else
 				dst_buf->b->v4l2_buf.field =
 							V4L2_FIELD_INTERLACED;
-			vb2_set_plane_payload(dst_buf->b, 0, ctx->luma_size);
-			vb2_set_plane_payload(dst_buf->b, 1, ctx->chroma_size);
+			vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0,
+					      ctx->luma_size);
+			vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1,
+					      ctx->chroma_size);
 			clear_bit(dst_buf->b->v4l2_buf.index,
 							&ctx->dec_dst_flag);
 
-			vb2_buffer_done(dst_buf->b,
-				err ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&dst_buf->b->vb2_buf,
+					err ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 
 			break;
 		}
@@ -407,9 +409,11 @@ 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_buf,
+						VB2_BUF_STATE_ERROR);
 			else
-				vb2_buffer_done(src_buf->b, VB2_BUF_STATE_DONE);
+				vb2_buffer_done(&src_buf->b->vb2_buf,
+						VB2_BUF_STATE_DONE);
 		}
 	}
 leave_handle_frame:
@@ -551,7 +555,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_buf,
 						VB2_BUF_STATE_DONE);
 			}
 			spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -592,8 +596,8 @@ static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx,
 									list);
 		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_set_plane_payload(&mb_entry->b->vb2_buf, 0, 0);
+		vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
 	}
 	spin_unlock(&dev->irqlock);
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index 10884a7..e8740fa 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.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 2fd59e7..7d75d8e 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -945,6 +945,7 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq,
 
 static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	unsigned int i;
@@ -964,8 +965,8 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 			mfc_err("Plane buffer (CAPTURE) is too small\n");
 			return -EINVAL;
 		}
-		i = vb->v4l2_buf.index;
-		ctx->dst_bufs[i].b = vb;
+		i = vbuf->v4l2_buf.index;
+		ctx->dst_bufs[i].b = vbuf;
 		ctx->dst_bufs[i].cookie.raw.luma =
 					vb2_dma_contig_plane_dma_addr(vb, 0);
 		ctx->dst_bufs[i].cookie.raw.chroma =
@@ -982,8 +983,8 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 			return -EINVAL;
 		}
 
-		i = vb->v4l2_buf.index;
-		ctx->src_bufs[i].b = vb;
+		i = vbuf->v4l2_buf.index;
+		ctx->src_bufs[i].b = vbuf;
 		ctx->src_bufs[i].cookie.stream =
 					vb2_dma_contig_plane_dma_addr(vb, 0);
 		ctx->src_bufs_cnt++;
@@ -994,6 +995,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 	return 0;
 }
 
+
 static int s5p_mfc_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
@@ -1058,6 +1060,7 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q)
 
 static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	struct s5p_mfc_dev *dev = ctx->dev;
@@ -1065,18 +1068,18 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
 	struct s5p_mfc_buf *mfc_buf;
 
 	if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-		mfc_buf = &ctx->src_bufs[vb->v4l2_buf.index];
+		mfc_buf = &ctx->src_bufs[vbuf->v4l2_buf.index];
 		mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
 		spin_lock_irqsave(&dev->irqlock, flags);
 		list_add_tail(&mfc_buf->list, &ctx->src_queue);
 		ctx->src_queue_cnt++;
 		spin_unlock_irqrestore(&dev->irqlock, flags);
 	} else if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
-		mfc_buf = &ctx->dst_bufs[vb->v4l2_buf.index];
+		mfc_buf = &ctx->dst_bufs[vbuf->v4l2_buf.index];
 		mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
 		/* Mark destination as available for use by MFC */
 		spin_lock_irqsave(&dev->irqlock, flags);
-		set_bit(vb->v4l2_buf.index, &ctx->dec_dst_flag);
+		set_bit(vbuf->v4l2_buf.index, &ctx->dec_dst_flag);
 		list_add_tail(&mfc_buf->list, &ctx->dst_queue);
 		ctx->dst_queue_cnt++;
 		spin_unlock_irqrestore(&dev->irqlock, flags);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 3fb87ed..e65249a 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -773,8 +773,8 @@ static int enc_pre_seq_start(struct s5p_mfc_ctx *ctx)
 
 	spin_lock_irqsave(&dev->irqlock, flags);
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
-	dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
-	dst_size = vb2_plane_size(dst_mb->b, 0);
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
 			dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -796,10 +796,10 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
 					struct s5p_mfc_buf, list);
 			list_del(&dst_mb->list);
 			ctx->dst_queue_cnt--;
-			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_set_plane_payload(&dst_mb->b->vb2_buf, 0,
+					      s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev));
+			vb2_buffer_done(&dst_mb->b->vb2_buf,
+					VB2_BUF_STATE_DONE);
 		}
 		spin_unlock_irqrestore(&dev->irqlock, flags);
 	}
@@ -831,16 +831,16 @@ static int enc_pre_frame_start(struct s5p_mfc_ctx *ctx)
 
 	spin_lock_irqsave(&dev->irqlock, flags);
 	src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
-	src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
-	src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
+	src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 0);
+	src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1);
 	s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_frame_buffer, ctx,
 							src_y_addr, src_c_addr);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 
 	spin_lock_irqsave(&dev->irqlock, flags);
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
-	dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
-	dst_size = vb2_plane_size(dst_mb->b, 0);
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
 			dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -869,26 +869,30 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
 		s5p_mfc_hw_call_void(dev->mfc_ops, get_enc_frame_buffer, ctx,
 				&enc_y_addr, &enc_c_addr);
 		list_for_each_entry(mb_entry, &ctx->src_queue, list) {
-			mb_y_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 0);
-			mb_c_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 1);
+			mb_y_addr = vb2_dma_contig_plane_dma_addr(&mb_entry->b->vb2_buf,
+								  0);
+			mb_c_addr = vb2_dma_contig_plane_dma_addr(&mb_entry->b->vb2_buf,
+								  1);
 			if ((enc_y_addr == mb_y_addr) &&
 						(enc_c_addr == mb_c_addr)) {
 				list_del(&mb_entry->list);
 				ctx->src_queue_cnt--;
-				vb2_buffer_done(mb_entry->b,
-							VB2_BUF_STATE_DONE);
+				vb2_buffer_done(&mb_entry->b->vb2_buf,
+						VB2_BUF_STATE_DONE);
 				break;
 			}
 		}
 		list_for_each_entry(mb_entry, &ctx->ref_queue, list) {
-			mb_y_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 0);
-			mb_c_addr = vb2_dma_contig_plane_dma_addr(mb_entry->b, 1);
+			mb_y_addr = vb2_dma_contig_plane_dma_addr(&mb_entry->b->vb2_buf,
+								  0);
+			mb_c_addr = vb2_dma_contig_plane_dma_addr(&mb_entry->b->vb2_buf,
+								  1);
 			if ((enc_y_addr == mb_y_addr) &&
 						(enc_c_addr == mb_c_addr)) {
 				list_del(&mb_entry->list);
 				ctx->ref_queue_cnt--;
-				vb2_buffer_done(mb_entry->b,
-							VB2_BUF_STATE_DONE);
+				vb2_buffer_done(&mb_entry->b->vb2_buf,
+						VB2_BUF_STATE_DONE);
 				break;
 			}
 		}
@@ -921,8 +925,8 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
 			mb_entry->b->v4l2_buf.flags |= V4L2_BUF_FLAG_BFRAME;
 			break;
 		}
-		vb2_set_plane_payload(mb_entry->b, 0, strm_size);
-		vb2_buffer_done(mb_entry->b, VB2_BUF_STATE_DONE);
+		vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, strm_size);
+		vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
 	}
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	if ((ctx->src_queue_cnt == 0) || (ctx->dst_queue_cnt == 0))
@@ -1791,6 +1795,7 @@ static const struct v4l2_ioctl_ops s5p_mfc_enc_ioctl_ops = {
 
 static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	int i;
 
 	if (!fmt)
@@ -1806,7 +1811,7 @@ static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
 			return -EINVAL;
 		}
 		mfc_debug(2, "index: %d, plane[%d] cookie: %pad\n",
-			  vb->v4l2_buf.index, i, &dma);
+			  vbuf->v4l2_buf.index, i, &dma);
 	}
 	return 0;
 }
@@ -1868,6 +1873,7 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq,
 
 static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	unsigned int i;
@@ -1877,8 +1883,8 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 		ret = check_vb_with_fmt(ctx->dst_fmt, vb);
 		if (ret < 0)
 			return ret;
-		i = vb->v4l2_buf.index;
-		ctx->dst_bufs[i].b = vb;
+		i = vbuf->v4l2_buf.index;
+		ctx->dst_bufs[i].b = vbuf;
 		ctx->dst_bufs[i].cookie.stream =
 					vb2_dma_contig_plane_dma_addr(vb, 0);
 		ctx->dst_bufs_cnt++;
@@ -1886,8 +1892,8 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 		ret = check_vb_with_fmt(ctx->src_fmt, vb);
 		if (ret < 0)
 			return ret;
-		i = vb->v4l2_buf.index;
-		ctx->src_bufs[i].b = vb;
+		i = vbuf->v4l2_buf.index;
+		ctx->src_bufs[i].b = vbuf;
 		ctx->src_bufs[i].cookie.raw.luma =
 					vb2_dma_contig_plane_dma_addr(vb, 0);
 		ctx->src_bufs[i].cookie.raw.chroma =
@@ -1999,6 +2005,7 @@ static void s5p_mfc_stop_streaming(struct vb2_queue *q)
 
 static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->vb2_queue;
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
 	struct s5p_mfc_dev *dev = ctx->dev;
@@ -2011,7 +2018,7 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
 		return;
 	}
 	if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
-		mfc_buf = &ctx->dst_bufs[vb->v4l2_buf.index];
+		mfc_buf = &ctx->dst_bufs[vbuf->v4l2_buf.index];
 		mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
 		/* Mark destination as available for use by MFC */
 		spin_lock_irqsave(&dev->irqlock, flags);
@@ -2019,7 +2026,7 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
 		ctx->dst_queue_cnt++;
 		spin_unlock_irqrestore(&dev->irqlock, flags);
 	} else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-		mfc_buf = &ctx->src_bufs[vb->v4l2_buf.index];
+		mfc_buf = &ctx->src_bufs[vbuf->v4l2_buf.index];
 		mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
 		spin_lock_irqsave(&dev->irqlock, flags);
 		list_add_tail(&mfc_buf->list, &ctx->src_queue);
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 9a923b1..13aff41 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -1206,7 +1206,7 @@ static int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx, int last_frame)
 	temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
 	temp_vb->flags |= MFC_BUF_FLAG_USED;
 	s5p_mfc_set_dec_stream_buffer_v5(ctx,
-		vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
+		vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0),
 		ctx->consumed_stream, temp_vb->b->v4l2_planes[0].bytesused);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1253,10 +1253,10 @@ static int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
 								dev->bank2);
 			ctx->state = MFCINST_FINISHING;
 		} else {
-			src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b,
-									0);
-			src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b,
-									1);
+			src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf,
+								   0);
+			src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf,
+								   1);
 			s5p_mfc_set_enc_frame_buffer_v5(ctx, src_y_addr,
 								src_c_addr);
 			if (src_mb->flags & MFC_BUF_FLAG_EOS)
@@ -1265,8 +1265,8 @@ static int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
 	}
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_mb->flags |= MFC_BUF_FLAG_USED;
-	dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
-	dst_size = vb2_plane_size(dst_mb->b, 0);
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_set_enc_stream_buffer_v5(ctx, dst_addr, dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1289,7 +1289,7 @@ static void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
 	s5p_mfc_set_dec_desc_buffer(ctx);
 	mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
 	s5p_mfc_set_dec_stream_buffer_v5(ctx,
-				vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
+				vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0),
 				0, temp_vb->b->v4l2_planes[0].bytesused);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1307,8 +1307,8 @@ static void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
 	s5p_mfc_set_enc_ref_buffer_v5(ctx);
 	spin_lock_irqsave(&dev->irqlock, flags);
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
-	dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
-	dst_size = vb2_plane_size(dst_mb->b, 0);
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_set_enc_stream_buffer_v5(ctx, dst_addr, dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1342,7 +1342,7 @@ static int s5p_mfc_run_init_dec_buffers(struct s5p_mfc_ctx *ctx)
 	temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
 	mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
 	s5p_mfc_set_dec_stream_buffer_v5(ctx,
-				vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
+				vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0),
 				0, temp_vb->b->v4l2_planes[0].bytesused);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1476,9 +1476,9 @@ 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++)
-			vb2_set_plane_payload(b->b, i, 0);
-		vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
+		for (i = 0; i < b->b->vb2_buf.num_planes; i++)
+			vb2_set_plane_payload(&b->b->vb2_buf, i, 0);
+		vb2_buffer_done(&b->b->vb2_buf, 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 12497f5..5c7f35a 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1560,9 +1560,9 @@ static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
 	temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
 	temp_vb->flags |= MFC_BUF_FLAG_USED;
 	s5p_mfc_set_dec_stream_buffer_v6(ctx,
-		vb2_dma_contig_plane_dma_addr(temp_vb->b, 0),
-			ctx->consumed_stream,
-			temp_vb->b->v4l2_planes[0].bytesused);
+		vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0),
+		ctx->consumed_stream,
+		temp_vb->b->v4l2_planes[0].bytesused);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 
 	dev->curr_ctx = ctx->num;
@@ -1604,8 +1604,8 @@ static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
 
 	src_mb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
 	src_mb->flags |= MFC_BUF_FLAG_USED;
-	src_y_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 0);
-	src_c_addr = vb2_dma_contig_plane_dma_addr(src_mb->b, 1);
+	src_y_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 0);
+	src_c_addr = vb2_dma_contig_plane_dma_addr(&src_mb->b->vb2_buf, 1);
 
 	mfc_debug(2, "enc src y addr: 0x%08lx\n", src_y_addr);
 	mfc_debug(2, "enc src c addr: 0x%08lx\n", src_c_addr);
@@ -1614,8 +1614,8 @@ static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
 
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_mb->flags |= MFC_BUF_FLAG_USED;
-	dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
-	dst_size = vb2_plane_size(dst_mb->b, 0);
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
 
 	s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
 
@@ -1639,8 +1639,8 @@ static inline void s5p_mfc_run_init_dec(struct s5p_mfc_ctx *ctx)
 	temp_vb = list_entry(ctx->src_queue.next, struct s5p_mfc_buf, list);
 	mfc_debug(2, "Header size: %d\n", temp_vb->b->v4l2_planes[0].bytesused);
 	s5p_mfc_set_dec_stream_buffer_v6(ctx,
-		vb2_dma_contig_plane_dma_addr(temp_vb->b, 0), 0,
-			temp_vb->b->v4l2_planes[0].bytesused);
+		vb2_dma_contig_plane_dma_addr(&temp_vb->b->vb2_buf, 0), 0,
+		temp_vb->b->v4l2_planes[0].bytesused);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
 	s5p_mfc_init_decode_v6(ctx);
@@ -1657,8 +1657,8 @@ static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
 	spin_lock_irqsave(&dev->irqlock, flags);
 
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
-	dst_addr = vb2_dma_contig_plane_dma_addr(dst_mb->b, 0);
-	dst_size = vb2_plane_size(dst_mb->b, 0);
+	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1834,9 +1834,9 @@ 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++)
-			vb2_set_plane_payload(b->b, i, 0);
-		vb2_buffer_done(b->b, VB2_BUF_STATE_ERROR);
+		for (i = 0; i < b->b->vb2_buf.num_planes; i++)
+			vb2_set_plane_payload(&b->b->vb2_buf, i, 0);
+		vb2_buffer_done(&b->b->vb2_buf, 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 855b723..be7ed5f 100644
--- a/drivers/media/platform/s5p-tv/mixer.h
+++ b/drivers/media/platform/s5p-tv/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_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
index 74344c7..db3163b 100644
--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
@@ -86,7 +86,7 @@ static void mxr_graph_buffer_set(struct mxr_layer *layer,
 	dma_addr_t addr = 0;
 
 	if (buf)
-		addr = vb2_dma_contig_plane_dma_addr(&buf->vb, 0);
+		addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
 	mxr_reg_graph_buffer(layer->mdev, layer->idx, addr);
 }
 
diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
index b713403..15be562 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_buf, 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 751f3b6..dba92b5 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -914,7 +914,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
 
 static void buf_queue(struct vb2_buffer *vb)
 {
-	struct mxr_buffer *buffer = container_of(vb, struct mxr_buffer, vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct mxr_buffer *buffer = container_of(vbuf, struct mxr_buffer, vb);
 	struct mxr_layer *layer = vb2_get_drv_priv(vb->vb2_queue);
 	struct mxr_device *mdev = layer->mdev;
 	unsigned long flags;
@@ -963,11 +964,13 @@ 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_buf,
+				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_buf,
+				VB2_BUF_STATE_ERROR);
 		layer->shadow_buf = NULL;
 	}
 	spin_unlock_irqrestore(&layer->enq_slock, flags);
@@ -991,7 +994,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_buf, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&layer->enq_slock, flags);
diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
index c9388c4..459cd2b 100644
--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
@@ -97,9 +97,10 @@ static void mxr_vp_buffer_set(struct mxr_layer *layer,
 		mxr_reg_vp_buffer(layer->mdev, luma_addr, chroma_addr);
 		return;
 	}
-	luma_addr[0] = vb2_dma_contig_plane_dma_addr(&buf->vb, 0);
+	luma_addr[0] = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
 	if (layer->fmt->num_subframes == 2) {
-		chroma_addr[0] = vb2_dma_contig_plane_dma_addr(&buf->vb, 1);
+		chroma_addr[0] = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf,
+							       1);
 	} else {
 		/* FIXME: mxr_get_plane_size compute integer division,
 		 * which is slow and should not be performed in interrupt */
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
index 7bb249c..a0910d9 100644
--- a/drivers/media/platform/sh_veu.c
+++ b/drivers/media/platform/sh_veu.c
@@ -243,10 +243,10 @@ 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);
+	dma_addr_t addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
 
 	sh_veu_reg_write(veu, VEU_DAYR, addr + veu->vfmt_out.offset_y);
 	sh_veu_reg_write(veu, VEU_DACR, veu->vfmt_out.offset_c ?
@@ -255,7 +255,7 @@ static void sh_veu_process(struct sh_veu_dev *veu,
 		(unsigned long)addr,
 		veu->vfmt_out.offset_y, veu->vfmt_out.offset_c);
 
-	addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
+	addr = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
 	sh_veu_reg_write(veu, VEU_SAYR, addr + veu->vfmt_in.offset_y);
 	sh_veu_reg_write(veu, VEU_SACR, veu->vfmt_in.offset_c ?
 			 addr + veu->vfmt_in.offset_c : 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);
@@ -931,9 +931,11 @@ static int sh_veu_buf_prepare(struct vb2_buffer *vb)
 
 static void sh_veu_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct sh_veu_dev *veu = vb2_get_drv_priv(vb->vb2_queue);
-	dev_dbg(veu->dev, "%s(%d)\n", __func__, vb->v4l2_buf.type);
-	v4l2_m2m_buf_queue(veu->m2m_ctx, vb);
+
+	dev_dbg(veu->dev, "%s(%d)\n", __func__, vbuf->v4l2_buf.type);
+	v4l2_m2m_buf_queue(veu->m2m_ctx, vbuf);
 }
 
 static const struct vb2_ops sh_veu_qops = {
@@ -1082,8 +1084,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 9070172..621a1a7 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;
 };
@@ -151,13 +151,13 @@ 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);
 		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_buf, VB2_BUF_STATE_DONE);
 	}
 
 	if (list_empty(&isi->video_buffer_list)) {
@@ -267,7 +267,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 static int buffer_init(struct vb2_buffer *vb)
 {
-	struct frame_buffer *buf = container_of(vb, struct frame_buffer, vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
 
 	buf->p_dma_desc = NULL;
 	INIT_LIST_HEAD(&buf->list);
@@ -277,8 +278,9 @@ static int buffer_init(struct vb2_buffer *vb)
 
 static int buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
-	struct frame_buffer *buf = container_of(vb, struct frame_buffer, vb);
+	struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct atmel_isi *isi = ici->priv;
 	unsigned long size;
@@ -292,7 +294,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(&buf->vb, 0, size);
+	vb2_set_plane_payload(vb, 0, size);
 
 	if (!buf->p_dma_desc) {
 		if (list_empty(&isi->dma_desc_head)) {
@@ -319,10 +321,11 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_cleanup(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->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);
+	struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
 
 	/* This descriptor is available now and we add to head list */
 	if (buf->p_dma_desc)
@@ -360,10 +363,11 @@ static void start_dma(struct atmel_isi *isi, struct frame_buffer *buffer)
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->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);
+	struct frame_buffer *buf = container_of(vbuf, struct frame_buffer, vb);
 	unsigned long flags = 0;
 
 	spin_lock_irqsave(&isi->lock, flags);
@@ -422,7 +426,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_buf, 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 6e41335..b250706 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -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;
 };
 
@@ -530,11 +530,12 @@ out:
 
 static void mx2_videobuf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
 	struct soc_camera_host *ici =
 		to_soc_camera_host(icd->parent);
 	struct mx2_camera_dev *pcdev = ici->priv;
-	struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb);
+	struct mx2_buffer *buf = container_of(vbuf, struct mx2_buffer, vb);
 	unsigned long flags;
 
 	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
@@ -650,7 +651,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;
@@ -666,7 +667,7 @@ static int mx2_start_streaming(struct vb2_queue *q, unsigned int count)
 	buf->internal.bufnum = 0;
 	vb = &buf->vb;
 
-	phys = vb2_dma_contig_plane_dma_addr(vb, 0);
+	phys = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
 	list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
 
@@ -675,7 +676,7 @@ static int mx2_start_streaming(struct vb2_queue *q, unsigned int count)
 	buf->internal.bufnum = 1;
 	vb = &buf->vb;
 
-	phys = vb2_dma_contig_plane_dma_addr(vb, 0);
+	phys = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
 	list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
 
@@ -1306,7 +1307,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,
@@ -1325,7 +1326,7 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
 
 		vb = &buf->vb;
 #ifdef DEBUG
-		phys = vb2_dma_contig_plane_dma_addr(vb, 0);
+		phys = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 		if (prp->cfg.channel == 1) {
 			if (readl(pcdev->base_emma + PRP_DEST_RGB1_PTR +
 				4 * bufnum) != phys) {
@@ -1343,16 +1344,16 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
 		}
 #endif
 		dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%p %lu\n", __func__, vb,
-				vb2_plane_vaddr(vb, 0),
-				vb2_get_plane_payload(vb, 0));
+				vb2_plane_vaddr(&vb->vb2_buf, 0),
+				vb2_get_plane_payload(&vb->vb2_buf, 0));
 
 		list_del_init(&buf->internal.queue);
 		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_buf, VB2_BUF_STATE_ERROR);
 		else
-			vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+			vb2_buffer_done(&vb->vb2_buf, VB2_BUF_STATE_DONE);
 	}
 
 	pcdev->frame_count++;
@@ -1382,7 +1383,7 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
 
 	vb = &buf->vb;
 
-	phys = vb2_dma_contig_plane_dma_addr(vb, 0);
+	phys = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	mx27_update_emma_buf(pcdev, phys, bufnum);
 }
 
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index ace41f5..6c566b8 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,14 +151,14 @@ 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);
 		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_buf, VB2_BUF_STATE_DONE);
 	}
 
 	if (list_empty(&mx3_cam->capture)) {
@@ -257,10 +257,11 @@ static enum pixel_fmt fourcc_to_ipu_pix(__u32 fourcc)
 
 static void mx3_videobuf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->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);
+	struct mx3_camera_buffer *buf = to_mx3_vb(vbuf);
 	struct scatterlist *sg = &buf->sg;
 	struct dma_async_tx_descriptor *txd;
 	struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
@@ -357,10 +358,11 @@ error:
 
 static void mx3_videobuf_release(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->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);
+	struct mx3_camera_buffer *buf = to_mx3_vb(vbuf);
 	struct dma_async_tx_descriptor *txd = buf->txd;
 	unsigned long flags;
 
@@ -390,10 +392,11 @@ static void mx3_videobuf_release(struct vb2_buffer *vb)
 
 static int mx3_videobuf_init(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->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);
+	struct mx3_camera_buffer *buf = to_mx3_vb(vbuf);
 
 	if (!buf->txd) {
 		/* This is for locking debugging only */
@@ -424,7 +427,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_buf, 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 db7700b..afa887e 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -477,7 +477,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;
@@ -491,7 +491,7 @@ 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;
 };
 
@@ -738,7 +738,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;
 
@@ -753,7 +753,7 @@ static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv)
 	vb = &list_entry(priv->capture.next, struct rcar_vin_buffer, list)->vb;
 	list_del_init(to_buf_list(vb));
 	priv->queue_buf[slot] = vb;
-	phys_addr_top = vb2_dma_contig_plane_dma_addr(vb, 0);
+	phys_addr_top = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, 0);
 	iowrite32(phys_addr_top, priv->base + VNMB_REG(slot));
 
 	return 1;
@@ -761,6 +761,7 @@ static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv)
 
 static void rcar_vin_videobuf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct rcar_vin_priv *priv = ici->priv;
@@ -770,7 +771,7 @@ static void rcar_vin_videobuf_queue(struct vb2_buffer *vb)
 
 	if (vb2_plane_size(vb, 0) < size) {
 		dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
-			vb->v4l2_buf.index, vb2_plane_size(vb, 0), size);
+			vbuf->v4l2_buf.index, vb2_plane_size(vb, 0), size);
 		goto error;
 	}
 
@@ -781,14 +782,14 @@ static void rcar_vin_videobuf_queue(struct vb2_buffer *vb)
 
 	spin_lock_irq(&priv->lock);
 
-	list_add_tail(to_buf_list(vb), &priv->capture);
+	list_add_tail(to_buf_list(vbuf), &priv->capture);
 	rcar_vin_fill_hw_slot(priv);
 
 	/* If we weren't running, and have enough buffers, start capturing! */
 	if (priv->state != RUNNING && rcar_vin_hw_ready(priv)) {
 		if (rcar_vin_setup(priv)) {
 			/* Submit error */
-			list_del_init(to_buf_list(vb));
+			list_del_init(to_buf_list(vbuf));
 			spin_unlock_irq(&priv->lock);
 			goto error;
 		}
@@ -844,7 +845,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_buf,
 					VB2_BUF_STATE_ERROR);
 			priv->queue_buf[i] = NULL;
 		}
@@ -900,7 +901,8 @@ 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++;
 		v4l2_get_timestamp(&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_buf,
+				VB2_BUF_STATE_DONE);
 		priv->queue_buf[slot] = NULL;
 
 		if (priv->state != STOPPING)
@@ -954,7 +956,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 */
@@ -971,7 +973,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_buf, 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 c5c6c4e..b46c3e3 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);
 }
@@ -334,7 +334,8 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
 		bottom2	= CDBCR;
 	}
 
-	phys_addr_top = vb2_dma_contig_plane_dma_addr(pcdev->active, 0);
+	phys_addr_top = vb2_dma_contig_plane_dma_addr(&pcdev->active->vb2_buf,
+						      0);
 
 	switch (icd->current_fmt->host_fmt->fourcc) {
 	case V4L2_PIX_FMT_NV12:
@@ -369,7 +370,8 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
 
 static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
 {
-	struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vbuf);
 
 	/* Added list head initialization on alloc */
 	WARN(!list_empty(&buf->queue), "Buffer %p on queue!\n", vb);
@@ -379,10 +381,11 @@ static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
 
 static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = container_of(vb->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);
+	struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vbuf);
 	unsigned long size;
 
 	size = icd->sizeimage;
@@ -429,14 +432,15 @@ error:
 
 static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct soc_camera_device *icd = container_of(vb->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_buffer *buf = to_ceu_vb(vbuf);
 	struct sh_mobile_ceu_dev *pcdev = ici->priv;
 
 	spin_lock_irq(&pcdev->lock);
 
-	if (pcdev->active == vb) {
+	if (pcdev->active == vbuf) {
 		/* disable capture (release DMA buffer), reset */
 		ceu_write(pcdev, CAPSR, 1 << 16);
 		pcdev->active = NULL;
@@ -504,7 +508,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);
@@ -528,7 +532,8 @@ 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_buf,
+			ret < 0 ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 
 out:
 	spin_unlock(&pcdev->lock);
@@ -633,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_buf, VB2_BUF_STATE_ERROR);
 		pcdev->active = NULL;
 	}
 	spin_unlock_irq(&pcdev->lock);
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index d82c2f2..19fea47 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -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;
@@ -1003,7 +1003,7 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
 		int plane = fmt->coplanar ? p_data->vb_part : 0;
 
 		vpdma_fmt = fmt->vpdma_fmt[plane];
-		dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+		dma_addr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, plane);
 		if (!dma_addr) {
 			vpe_err(ctx->dev,
 				"acquiring output buffer(%d) dma_addr failed\n",
@@ -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;
@@ -1043,7 +1043,7 @@ static void add_in_dtd(struct vpe_ctx *ctx, int port)
 
 		vpdma_fmt = fmt->vpdma_fmt[plane];
 
-		dma_addr = vb2_dma_contig_plane_dma_addr(vb, plane);
+		dma_addr = vb2_dma_contig_plane_dma_addr(&vb->vb2_buf, plane);
 		if (!dma_addr) {
 			vpe_err(ctx->dev,
 				"acquiring input buffer(%d) dma_addr failed\n",
@@ -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;
@@ -1825,6 +1825,7 @@ static int vpe_queue_setup(struct vb2_queue *vq,
 
 static int vpe_buf_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 	struct vpe_q_data *q_data;
 	int i, num_planes;
@@ -1836,10 +1837,10 @@ static int vpe_buf_prepare(struct vb2_buffer *vb)
 
 	if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
 		if (!(q_data->flags & Q_DATA_INTERLACED)) {
-			vb->v4l2_buf.field = V4L2_FIELD_NONE;
+			vbuf->v4l2_buf.field = V4L2_FIELD_NONE;
 		} else {
-			if (vb->v4l2_buf.field != V4L2_FIELD_TOP &&
-					vb->v4l2_buf.field != V4L2_FIELD_BOTTOM)
+			if (vbuf->v4l2_buf.field != V4L2_FIELD_TOP &&
+					vbuf->v4l2_buf.field != V4L2_FIELD_BOTTOM)
 				return -EINVAL;
 		}
 	}
@@ -1862,9 +1863,10 @@ static int vpe_buf_prepare(struct vb2_buffer *vb)
 
 static void vpe_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 
-	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
+	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
 static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
index 295fde5..267525a 100644
--- a/drivers/media/platform/vim2m.c
+++ b/drivers/media/platform/vim2m.c
@@ -197,8 +197,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;
@@ -213,15 +213,15 @@ static int device_process(struct vim2m_ctx *ctx,
 	height	= q_data->height;
 	bytesperline	= (q_data->width * q_data->fmt->depth) >> 3;
 
-	p_in = vb2_plane_vaddr(in_vb, 0);
-	p_out = vb2_plane_vaddr(out_vb, 0);
+	p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0);
+	p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0);
 	if (!p_in || !p_out) {
 		v4l2_err(&dev->v4l2_dev,
 			 "Acquiring kernel pointers to buffers failed\n");
 		return -EFAULT;
 	}
 
-	if (vb2_plane_size(in_vb, 0) > vb2_plane_size(out_vb, 0)) {
+	if (vb2_plane_size(&in_vb->vb2_buf, 0) > vb2_plane_size(&out_vb->vb2_buf, 0)) {
 		v4l2_err(&dev->v4l2_dev, "Output buffer is too small\n");
 		return -EINVAL;
 	}
@@ -374,7 +374,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);
@@ -389,7 +389,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);
@@ -747,6 +747,7 @@ static int vim2m_queue_setup(struct vb2_queue *vq,
 
 static int vim2m_buf_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 	struct vim2m_q_data *q_data;
 
@@ -754,9 +755,9 @@ static int vim2m_buf_prepare(struct vb2_buffer *vb)
 
 	q_data = get_q_data(ctx, vb->vb2_queue->type);
 	if (V4L2_TYPE_IS_OUTPUT(vb->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) {
+		if (vbuf->v4l2_buf.field == V4L2_FIELD_ANY)
+			vbuf->v4l2_buf.field = V4L2_FIELD_NONE;
+		if (vbuf->v4l2_buf.field != V4L2_FIELD_NONE) {
 			dprintk(ctx->dev, "%s field isn't supported\n",
 					__func__);
 			return -EINVAL;
@@ -776,9 +777,10 @@ static int vim2m_buf_prepare(struct vb2_buffer *vb)
 
 static void vim2m_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vim2m_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 
-	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
+	v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
 }
 
 static int vim2m_start_streaming(struct vb2_queue *q, unsigned count)
@@ -793,7 +795,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 5f1b1da..ddd84dd 100644
--- a/drivers/media/platform/vivid/vivid-core.h
+++ b/drivers/media/platform/vivid/vivid-core.h
@@ -93,7 +93,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-kthread-cap.c b/drivers/media/platform/vivid/vivid-kthread-cap.c
index 1727f54..b472043 100644
--- a/drivers/media/platform/vivid/vivid-kthread-cap.c
+++ b/drivers/media/platform/vivid/vivid-kthread-cap.c
@@ -236,8 +236,8 @@ static void *plane_vaddr(struct tpg_data *tpg, struct vivid_buffer *buf,
 	void *vbuf;
 
 	if (p == 0 || tpg_g_buffers(tpg) > 1)
-		return vb2_plane_vaddr(&buf->vb, p);
-	vbuf = vb2_plane_vaddr(&buf->vb, 0);
+		return vb2_plane_vaddr(&buf->vb.vb2_buf, p);
+	vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 	for (i = 0; i < p; i++)
 		vbuf += bpl[i] * h / tpg->vdownsampling[i];
 	return vbuf;
@@ -600,7 +600,7 @@ static void vivid_overlay(struct vivid_dev *dev, struct vivid_buffer *buf)
 	struct tpg_data *tpg = &dev->tpg;
 	unsigned pixsize = tpg_g_twopixelsize(tpg, 0) / 2;
 	void *vbase = dev->fb_vbase_cap;
-	void *vbuf = vb2_plane_vaddr(&buf->vb, 0);
+	void *vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 	unsigned img_width = dev->compose_cap.width;
 	unsigned img_height = dev->compose_cap.height;
 	unsigned stride = tpg->bytesperline[0];
@@ -706,8 +706,8 @@ 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_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vid_cap_buf->vb.vb2_buf,
+				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);
 	}
@@ -717,8 +717,8 @@ 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_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vbi_cap_buf->vb.vb2_buf,
+				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);
 	}
@@ -884,7 +884,8 @@ 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_buf,
+					VB2_BUF_STATE_ERROR);
 			dprintk(dev, 2, "vid_cap buffer %d done\n",
 				buf->vb.v4l2_buf.index);
 		}
@@ -897,7 +898,8 @@ 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_buf,
+					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..cb436f4 100644
--- a/drivers/media/platform/vivid/vivid-kthread-out.c
+++ b/drivers/media/platform/vivid/vivid-kthread-out.c
@@ -97,8 +97,8 @@ 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_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vid_out_buf->vb.vb2_buf,
+				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,8 +110,8 @@ 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_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&vbi_out_buf->vb.vb2_buf,
+				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,8 @@ 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_buf,
+					VB2_BUF_STATE_ERROR);
 			dprintk(dev, 2, "vid_out buffer %d done\n",
 				buf->vb.v4l2_buf.index);
 		}
@@ -287,7 +288,8 @@ 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_buf,
+					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 d2f2188..2b46175 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
@@ -118,8 +118,8 @@ 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_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
+		vb2_buffer_done(&sdr_cap_buf->vb.vb2_buf,
+				dev->dqbuf_error ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 		dev->dqbuf_error = false;
 	}
 }
@@ -247,8 +247,9 @@ static int sdr_cap_buf_prepare(struct vb2_buffer *vb)
 
 static void sdr_cap_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
+	struct vivid_buffer *buf = container_of(vbuf, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
 
@@ -282,7 +283,8 @@ 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_buf,
+					VB2_BUF_STATE_QUEUED);
 		}
 	}
 	return err;
@@ -301,7 +303,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_buf, VB2_BUF_STATE_ERROR);
 	}
 
 	/* shutdown control thread */
@@ -491,9 +493,9 @@ int vidioc_try_fmt_sdr_cap(struct file *file, void *fh, struct v4l2_format *f)
 
 void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 {
-	u8 *vbuf = vb2_plane_vaddr(&buf->vb, 0);
+	u8 *vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 	unsigned long i;
-	unsigned long plane_size = vb2_plane_size(&buf->vb, 0);
+	unsigned long plane_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
 	s32 src_phase_step;
 	s32 mod_phase_step;
 	s32 fixp_i;
diff --git a/drivers/media/platform/vivid/vivid-vbi-cap.c b/drivers/media/platform/vivid/vivid-vbi-cap.c
index ef81b01..0ea990b 100644
--- a/drivers/media/platform/vivid/vivid-vbi-cap.c
+++ b/drivers/media/platform/vivid/vivid-vbi-cap.c
@@ -94,7 +94,7 @@ static void vivid_g_fmt_vbi_cap(struct vivid_dev *dev, struct v4l2_vbi_format *v
 void vivid_raw_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 {
 	struct v4l2_vbi_format vbi;
-	u8 *vbuf = vb2_plane_vaddr(&buf->vb, 0);
+	u8 *vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 
 	vivid_g_fmt_vbi_cap(dev, &vbi);
 	buf->vb.v4l2_buf.sequence = dev->vbi_cap_seq_count;
@@ -103,7 +103,7 @@ void vivid_raw_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 
 	vivid_sliced_vbi_cap_fill(dev, buf->vb.v4l2_buf.sequence);
 
-	memset(vbuf, 0x10, vb2_plane_size(&buf->vb, 0));
+	memset(vbuf, 0x10, vb2_plane_size(&buf->vb.vb2_buf, 0));
 
 	if (!VIVID_INVALID_SIGNAL(dev->std_signal_mode))
 		vivid_vbi_gen_raw(&dev->vbi_gen, &vbi, vbuf);
@@ -115,7 +115,8 @@ void vivid_raw_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 
 void vivid_sliced_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 {
-	struct v4l2_sliced_vbi_data *vbuf = vb2_plane_vaddr(&buf->vb, 0);
+	struct v4l2_sliced_vbi_data *vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf,
+							    0);
 
 	buf->vb.v4l2_buf.sequence = dev->vbi_cap_seq_count;
 	if (dev->field_cap == V4L2_FIELD_ALTERNATE)
@@ -123,7 +124,7 @@ void vivid_sliced_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *bu
 
 	vivid_sliced_vbi_cap_fill(dev, buf->vb.v4l2_buf.sequence);
 
-	memset(vbuf, 0, vb2_plane_size(&buf->vb, 0));
+	memset(vbuf, 0, vb2_plane_size(&buf->vb.vb2_buf, 0));
 	if (!VIVID_INVALID_SIGNAL(dev->std_signal_mode)) {
 		unsigned i;
 
@@ -187,8 +188,9 @@ static int vbi_cap_buf_prepare(struct vb2_buffer *vb)
 
 static void vbi_cap_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
+	struct vivid_buffer *buf = container_of(vbuf, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
 
@@ -215,7 +217,8 @@ 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_buf,
+					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 4e4c70e..65097c6 100644
--- a/drivers/media/platform/vivid/vivid-vbi-out.c
+++ b/drivers/media/platform/vivid/vivid-vbi-out.c
@@ -79,8 +79,9 @@ static int vbi_out_buf_prepare(struct vb2_buffer *vb)
 
 static void vbi_out_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
+	struct vivid_buffer *buf = container_of(vbuf, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
 
@@ -107,7 +108,8 @@ 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_buf,
+					VB2_BUF_STATE_QUEUED);
 		}
 	}
 	return err;
@@ -219,8 +221,9 @@ int vidioc_s_fmt_sliced_vbi_out(struct file *file, void *fh, struct v4l2_format
 
 void vivid_sliced_vbi_out_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 {
-	struct v4l2_sliced_vbi_data *vbi = vb2_plane_vaddr(&buf->vb, 0);
-	unsigned elems = vb2_get_plane_payload(&buf->vb, 0) / sizeof(*vbi);
+	struct v4l2_sliced_vbi_data *vbi = vb2_plane_vaddr(&buf->vb.vb2_buf,
+							   0);
+	unsigned elems = vb2_get_plane_payload(&buf->vb.vb2_buf, 0) / sizeof(*vbi);
 
 	dev->vbi_out_have_cc[0] = false;
 	dev->vbi_out_have_cc[1] = false;
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index ed0b878..1828a27 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -169,6 +169,7 @@ static int vid_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *f
 
 static int vid_cap_buf_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long size;
 	unsigned buffers = tpg_g_buffers(&dev->tpg);
@@ -198,7 +199,7 @@ static int vid_cap_buf_prepare(struct vb2_buffer *vb)
 		}
 
 		vb2_set_plane_payload(vb, p, size);
-		vb->v4l2_planes[p].data_offset = dev->fmt_cap->data_offset[p];
+		vbuf->v4l2_planes[p].data_offset = dev->fmt_cap->data_offset[p];
 	}
 
 	return 0;
@@ -206,10 +207,11 @@ static int vid_cap_buf_prepare(struct vb2_buffer *vb)
 
 static void vid_cap_buf_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct v4l2_timecode *tc = &vb->v4l2_buf.timecode;
+	struct v4l2_timecode *tc = &vbuf->v4l2_buf.timecode;
 	unsigned fps = 25;
-	unsigned seq = vb->v4l2_buf.sequence;
+	unsigned seq = vbuf->v4l2_buf.sequence;
 
 	if (!vivid_is_sdtv_cap(dev))
 		return;
@@ -218,7 +220,7 @@ static void vid_cap_buf_finish(struct vb2_buffer *vb)
 	 * Set the timecode. Rarely used, so it is interesting to
 	 * test this.
 	 */
-	vb->v4l2_buf.flags |= V4L2_BUF_FLAG_TIMECODE;
+	vbuf->v4l2_buf.flags |= V4L2_BUF_FLAG_TIMECODE;
 	if (dev->std_cap & V4L2_STD_525_60)
 		fps = 30;
 	tc->type = (fps == 30) ? V4L2_TC_TYPE_30FPS : V4L2_TC_TYPE_25FPS;
@@ -231,8 +233,9 @@ static void vid_cap_buf_finish(struct vb2_buffer *vb)
 
 static void vid_cap_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
+	struct vivid_buffer *buf = container_of(vbuf, struct vivid_buffer, vb);
 
 	dprintk(dev, 1, "%s\n", __func__);
 
@@ -268,7 +271,8 @@ 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_buf,
+					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 0862c1f..de7a076 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -109,6 +109,7 @@ static int vid_out_queue_setup(struct vb2_queue *vq, const struct v4l2_format *f
 
 static int vid_out_buf_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long size;
 	unsigned planes;
@@ -131,14 +132,14 @@ static int vid_out_buf_prepare(struct vb2_buffer *vb)
 	}
 
 	if (dev->field_out != V4L2_FIELD_ALTERNATE)
-		vb->v4l2_buf.field = dev->field_out;
-	else if (vb->v4l2_buf.field != V4L2_FIELD_TOP &&
-		 vb->v4l2_buf.field != V4L2_FIELD_BOTTOM)
+		vbuf->v4l2_buf.field = dev->field_out;
+	else if (vbuf->v4l2_buf.field != V4L2_FIELD_TOP &&
+		 vbuf->v4l2_buf.field != V4L2_FIELD_BOTTOM)
 		return -EINVAL;
 
 	for (p = 0; p < planes; p++) {
 		size = dev->bytesperline_out[p] * dev->fmt_out_rect.height +
-			vb->v4l2_planes[p].data_offset;
+			vbuf->v4l2_planes[p].data_offset;
 
 		if (vb2_get_plane_payload(vb, p) < size) {
 			dprintk(dev, 1, "%s the payload is too small for plane %u (%lu < %lu)\n",
@@ -152,6 +153,7 @@ static int vid_out_buf_prepare(struct vb2_buffer *vb)
 
 static void vid_out_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
 	struct vivid_buffer *buf = container_of(vb, struct vivid_buffer, vb);
 
@@ -186,7 +188,8 @@ 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_buf,
+					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 dfd45c7..389fb0b 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -613,8 +613,9 @@ 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)
-		vb2_set_plane_payload(&done->buf, i, done->length[i]);
-	vb2_buffer_done(&done->buf, VB2_BUF_STATE_DONE);
+		vb2_set_plane_payload(&done->buf.vb2_buf, i,
+				      done->length[i]);
+	vb2_buffer_done(&done->buf.vb2_buf, VB2_BUF_STATE_DONE);
 
 	return next;
 }
@@ -820,8 +821,9 @@ vsp1_video_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 static int vsp1_video_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue);
-	struct vsp1_video_buffer *buf = to_vsp1_video_buffer(vb);
+	struct vsp1_video_buffer *buf = to_vsp1_video_buffer(vbuf);
 	const struct v4l2_pix_format_mplane *format = &video->format;
 	unsigned int i;
 
@@ -841,9 +843,10 @@ static int vsp1_video_buffer_prepare(struct vb2_buffer *vb)
 
 static void vsp1_video_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue);
 	struct vsp1_pipeline *pipe = to_vsp1_pipeline(&video->video.entity);
-	struct vsp1_video_buffer *buf = to_vsp1_video_buffer(vb);
+	struct vsp1_video_buffer *buf = to_vsp1_video_buffer(vbuf);
 	unsigned long flags;
 	bool empty;
 
@@ -954,7 +957,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_buf, VB2_BUF_STATE_ERROR);
 	INIT_LIST_HEAD(&video->irqqueue);
 	spin_unlock_irqrestore(&video->irqlock, flags);
 }
diff --git a/drivers/media/platform/vsp1/vsp1_video.h b/drivers/media/platform/vsp1/vsp1_video.h
index d808301..c3af62e 100644
--- a/drivers/media/platform/vsp1/vsp1_video.h
+++ b/drivers/media/platform/vsp1/vsp1_video.h
@@ -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/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c
index 4069234..253884a 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;
 };
 
@@ -310,13 +310,13 @@ static void airspy_urb_complete(struct urb *urb)
 		}
 
 		/* fill framebuffer */
-		ptr = vb2_plane_vaddr(&fbuf->vb, 0);
+		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		len = airspy_convert_stream(s, ptr, urb->transfer_buffer,
 				urb->actual_length);
-		vb2_set_plane_payload(&fbuf->vb, 0, len);
+		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 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_buf, 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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&s->queued_bufs_lock, flags);
 }
@@ -505,14 +505,15 @@ static int airspy_queue_setup(struct vb2_queue *vq,
 
 static void airspy_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct airspy *s = vb2_get_drv_priv(vb->vb2_queue);
 	struct airspy_frame_buf *buf =
-			container_of(vb, struct airspy_frame_buf, vb);
+			container_of(vbuf, struct airspy_frame_buf, vb);
 	unsigned long flags;
 
 	/* 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(vb, VB2_BUF_STATE_ERROR);
 		return;
 	}
 
@@ -571,7 +572,8 @@ 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_buf,
+					VB2_BUF_STATE_QUEUED);
 		}
 	}
 
diff --git a/drivers/media/usb/au0828/au0828-vbi.c b/drivers/media/usb/au0828/au0828-vbi.c
index f67247c..5fbf279 100644
--- a/drivers/media/usb/au0828/au0828-vbi.c
+++ b/drivers/media/usb/au0828/au0828-vbi.c
@@ -52,7 +52,6 @@ static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 static int vbi_buffer_prepare(struct vb2_buffer *vb)
 {
 	struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
 	unsigned long size;
 
 	size = dev->vbi_width * dev->vbi_height * 2;
@@ -62,7 +61,7 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 			__func__, vb2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(&buf->vb, 0, size);
+	vb2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -70,8 +69,9 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 static void
 vbi_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
+	struct au0828_buffer *buf = container_of(vbuf, 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 1a362a0..28e374e 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -302,8 +302,8 @@ static inline void buffer_filled(struct au0828_dev *dev,
 				 struct au0828_dmaqueue *dma_q,
 				 struct au0828_buffer *buf)
 {
-	struct vb2_buffer *vb = &buf->vb;
-	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *vb = &buf->vb;
+	struct vb2_queue *q = vb->vb2_buf.vb2_queue;
 
 	/* Advice that buffer was filled */
 	au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field);
@@ -315,7 +315,7 @@ static inline void buffer_filled(struct au0828_dev *dev,
 
 	vb->v4l2_buf.field = V4L2_FIELD_INTERLACED;
 	v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
-	vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
+	vb2_buffer_done(&vb->vb2_buf, VB2_BUF_STATE_DONE);
 }
 
 /*
@@ -531,11 +531,11 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
 
 	buf = dev->isoc_ctl.buf;
 	if (buf != NULL)
-		outp = vb2_plane_vaddr(&buf->vb, 0);
+		outp = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 
 	vbi_buf = dev->isoc_ctl.vbi_buf;
 	if (vbi_buf != NULL)
-		vbioutp = vb2_plane_vaddr(&vbi_buf->vb, 0);
+		vbioutp = vb2_plane_vaddr(&vbi_buf->vb.vb2_buf, 0);
 
 	for (i = 0; i < urb->number_of_packets; i++) {
 		int status = urb->iso_frame_desc[i].status;
@@ -573,8 +573,8 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
 				if (vbi_buf == NULL)
 					vbioutp = NULL;
 				else
-					vbioutp = vb2_plane_vaddr(
-						&vbi_buf->vb, 0);
+					vbioutp = vb2_plane_vaddr(&vbi_buf->vb.vb2_buf,
+								  0);
 
 				/* Video */
 				if (buf != NULL)
@@ -583,7 +583,8 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
 				if (buf == NULL)
 					outp = NULL;
 				else
-					outp = vb2_plane_vaddr(&buf->vb, 0);
+					outp = vb2_plane_vaddr(&buf->vb.vb2_buf,
+							       0);
 
 				/* As long as isoc traffic is arriving, keep
 				   resetting the timer */
@@ -658,7 +659,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 static int
 buffer_prepare(struct vb2_buffer *vb)
 {
-	struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct au0828_buffer *buf = container_of(vbuf, struct au0828_buffer, vb);
 	struct au0828_dev    *dev = vb2_get_drv_priv(vb->vb2_queue);
 
 	buf->length = dev->height * dev->bytesperline;
@@ -668,14 +670,15 @@ buffer_prepare(struct vb2_buffer *vb)
 			__func__, vb2_plane_size(vb, 0), buf->length);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(&buf->vb, 0, buf->length);
+	vb2_set_plane_payload(vb, 0, buf->length);
 	return 0;
 }
 
 static void
 buffer_queue(struct vb2_buffer *vb)
 {
-	struct au0828_buffer    *buf     = container_of(vb,
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct au0828_buffer    *buf     = container_of(vbuf,
 							struct au0828_buffer,
 							vb);
 	struct au0828_dev       *dev     = vb2_get_drv_priv(vb->vb2_queue);
@@ -826,14 +829,15 @@ 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_buf,
+				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_buf, VB2_BUF_STATE_ERROR);
 		list_del(&buf->list);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
@@ -853,7 +857,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_buf,
 				VB2_BUF_STATE_ERROR);
 		dev->isoc_ctl.vbi_buf = NULL;
 	}
@@ -862,7 +866,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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 
@@ -911,7 +915,7 @@ static void au0828_vid_buffer_timeout(unsigned long data)
 
 	buf = dev->isoc_ctl.buf;
 	if (buf != NULL) {
-		vid_data = vb2_plane_vaddr(&buf->vb, 0);
+		vid_data = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 		memset(vid_data, 0x00, buf->length); /* Blank green frame */
 		buffer_filled(dev, dma_q, buf);
 	}
@@ -935,7 +939,7 @@ static void au0828_vbi_buffer_timeout(unsigned long data)
 
 	buf = dev->isoc_ctl.vbi_buf;
 	if (buf != NULL) {
-		vbi_data = vb2_plane_vaddr(&buf->vb, 0);
+		vbi_data = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 		memset(vbi_data, 0x00, buf->length);
 		buffer_filled(dev, dma_q, buf);
 	}
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index 3b48000..270aa47 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..50b33c9 100644
--- a/drivers/media/usb/em28xx/em28xx-vbi.c
+++ b/drivers/media/usb/em28xx/em28xx-vbi.c
@@ -59,9 +59,10 @@ static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 static int vbi_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct em28xx        *dev  = vb2_get_drv_priv(vb->vb2_queue);
 	struct em28xx_v4l2   *v4l2 = dev->v4l2;
-	struct em28xx_buffer *buf  = container_of(vb, struct em28xx_buffer, vb);
+	struct em28xx_buffer *buf  = container_of(vbuf, struct em28xx_buffer, vb);
 	unsigned long        size;
 
 	size = v4l2->vbi_width * v4l2->vbi_height * 2;
@@ -71,7 +72,7 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 		       __func__, vb2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(&buf->vb, 0, size);
+	vb2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -79,8 +80,9 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 static void
 vbi_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
+	struct em28xx_buffer *buf = container_of(vbuf, 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 4397ce5..bbccaed 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_buf, VB2_BUF_STATE_DONE);
 }
 
 /*
@@ -900,9 +900,10 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 static int
 buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct em28xx        *dev = vb2_get_drv_priv(vb->vb2_queue);
 	struct em28xx_v4l2   *v4l2 = dev->v4l2;
-	struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
+	struct em28xx_buffer *buf = container_of(vbuf, struct em28xx_buffer, vb);
 	unsigned long size;
 
 	em28xx_videodbg("%s, field=%d\n", __func__, vb->v4l2_buf.field);
@@ -914,7 +915,7 @@ buffer_prepare(struct vb2_buffer *vb)
 				__func__, vb2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(&buf->vb, 0, size);
+	vb2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -995,7 +996,8 @@ 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_buf,
+				VB2_BUF_STATE_ERROR);
 		dev->usb_ctl.vid_buf = NULL;
 	}
 	while (!list_empty(&vidq->active)) {
@@ -1003,7 +1005,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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
@@ -1026,7 +1028,8 @@ 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_buf,
+				VB2_BUF_STATE_ERROR);
 		dev->usb_ctl.vbi_buf = NULL;
 	}
 	while (!list_empty(&vbiq->active)) {
@@ -1034,7 +1037,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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->slock, flags);
 }
@@ -1042,8 +1045,9 @@ void em28xx_stop_vbi_streaming(struct vb2_queue *vq)
 static void
 buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
+	struct em28xx_buffer *buf = container_of(vbuf, 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 e6559c6..e8512c4 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -264,7 +264,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-driver.c b/drivers/media/usb/go7007/go7007-driver.c
index 0ab81ec..0814135 100644
--- a/drivers/media/usb/go7007/go7007-driver.c
+++ b/drivers/media/usb/go7007/go7007-driver.c
@@ -387,7 +387,7 @@ start_error:
 static inline void store_byte(struct go7007_buffer *vb, u8 byte)
 {
 	if (vb && vb->vb.v4l2_planes[0].bytesused < GO7007_BUF_SIZE) {
-		u8 *ptr = vb2_plane_vaddr(&vb->vb, 0);
+		u8 *ptr = vb2_plane_vaddr(&vb->vb.vb2_buf, 0);
 
 		ptr[vb->vb.v4l2_planes[0].bytesused++] = byte;
 	}
@@ -476,7 +476,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_buf, VB2_BUF_STATE_DONE);
 	return vb;
 }
 
diff --git a/drivers/media/usb/go7007/go7007-priv.h b/drivers/media/usb/go7007/go7007-priv.h
index 9e83bbf..745185e 100644
--- a/drivers/media/usb/go7007/go7007-priv.h
+++ b/drivers/media/usb/go7007/go7007-priv.h
@@ -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 c57207e..3d4e5db 100644
--- a/drivers/media/usb/go7007/go7007-v4l2.c
+++ b/drivers/media/usb/go7007/go7007-v4l2.c
@@ -52,7 +52,7 @@ static bool valid_pixelformat(u32 pixelformat)
 
 static u32 get_frame_type_flag(struct go7007_buffer *vb, int format)
 {
-	u8 *ptr = vb2_plane_vaddr(&vb->vb, 0);
+	u8 *ptr = vb2_plane_vaddr(&vb->vb.vb2_buf, 0);
 
 	switch (format) {
 	case V4L2_PIX_FMT_MJPEG:
@@ -384,10 +384,11 @@ static int go7007_queue_setup(struct vb2_queue *q,
 
 static void go7007_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->vb2_queue;
 	struct go7007 *go = vb2_get_drv_priv(vq);
 	struct go7007_buffer *go7007_vb =
-		container_of(vb, struct go7007_buffer, vb);
+		container_of(vbuf, struct go7007_buffer, vb);
 	unsigned long flags;
 
 	spin_lock_irqsave(&go->spinlock, flags);
@@ -397,23 +398,25 @@ static void go7007_buf_queue(struct vb2_buffer *vb)
 
 static int go7007_buf_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct go7007_buffer *go7007_vb =
-		container_of(vb, struct go7007_buffer, vb);
+		container_of(vbuf, struct go7007_buffer, vb);
 
 	go7007_vb->modet_active = 0;
 	go7007_vb->frame_offset = 0;
-	vb->v4l2_planes[0].bytesused = 0;
+	vbuf->v4l2_planes[0].bytesused = 0;
 	return 0;
 }
 
 static void go7007_buf_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vb2_queue *vq = vb->vb2_queue;
 	struct go7007 *go = vb2_get_drv_priv(vq);
 	struct go7007_buffer *go7007_vb =
-		container_of(vb, struct go7007_buffer, vb);
+		container_of(vbuf, struct go7007_buffer, vb);
 	u32 frame_type_flag = get_frame_type_flag(go7007_vb, go->format);
-	struct v4l2_buffer *buf = &vb->v4l2_buf;
+	struct v4l2_buffer *buf = &vbuf->v4l2_buf;
 
 	buf->flags &= ~(V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_BFRAME |
 			V4L2_BUF_FLAG_PFRAME);
diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c
index fd1fa41..935b920 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;
 };
 
@@ -287,13 +287,13 @@ static void hackrf_urb_complete(struct urb *urb)
 		}
 
 		/* fill framebuffer */
-		ptr = vb2_plane_vaddr(&fbuf->vb, 0);
+		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		len = hackrf_convert_stream(dev, ptr, urb->transfer_buffer,
 				urb->actual_length);
-		vb2_set_plane_payload(&fbuf->vb, 0, len);
+		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 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_buf, 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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
 }
@@ -483,9 +483,10 @@ static int hackrf_queue_setup(struct vb2_queue *vq,
 
 static void hackrf_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct hackrf_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
 	struct hackrf_frame_buf *buf =
-			container_of(vb, struct hackrf_frame_buf, vb);
+			container_of(vbuf, struct hackrf_frame_buf, vb);
 	unsigned long flags;
 
 	spin_lock_irqsave(&dev->queued_bufs_lock, flags);
@@ -539,7 +540,8 @@ 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_buf,
+					VB2_BUF_STATE_QUEUED);
 		}
 	}
 
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index 3f276d9..77cfb7d 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -112,7 +112,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;
 };
 
@@ -431,10 +431,10 @@ static void msi2500_isoc_handler(struct urb *urb)
 		}
 
 		/* fill framebuffer */
-		ptr = vb2_plane_vaddr(&fbuf->vb, 0);
+		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		flen = msi2500_convert_stream(dev, ptr, iso_buf, flen);
-		vb2_set_plane_payload(&fbuf->vb, 0, flen);
-		vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
+		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, flen);
+		vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE);
 	}
 
 handler_end:
@@ -569,7 +569,7 @@ static void msi2500_cleanup_queued_bufs(struct msi2500_dev *dev)
 		buf = list_entry(dev->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_buf, VB2_BUF_STATE_ERROR);
 	}
 	spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
 }
@@ -633,15 +633,15 @@ static int msi2500_queue_setup(struct vb2_queue *vq,
 
 static void msi2500_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct msi2500_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	struct msi2500_frame_buf *buf = container_of(vb,
-						     struct msi2500_frame_buf,
-						     vb);
+	struct msi2500_frame_buf *buf =
+			container_of(vbuf, struct msi2500_frame_buf, vb);
 	unsigned long flags;
 
 	/* Check the device has not disconnected between prep and queuing */
 	if (unlikely(!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/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 702267e..2fc3c0f 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -242,7 +242,8 @@ 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_buf,
+					VB2_BUF_STATE_DONE);
 			pdev->fill_buf = NULL;
 			pdev->vsync = 0;
 		}
@@ -287,7 +288,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_buf,
 						VB2_BUF_STATE_ERROR);
 				pdev->fill_buf = NULL;
 			}
@@ -520,7 +521,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_buf, state);
 	}
 	spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
 }
@@ -594,7 +595,8 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 static int buffer_init(struct vb2_buffer *vb)
 {
-	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct pwc_frame_buf *buf = container_of(vbuf, struct pwc_frame_buf, vb);
 
 	/* need vmalloc since frame buffer > 128K */
 	buf->data = vzalloc(PWC_FRAME_SIZE);
@@ -617,8 +619,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 static void buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
-	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
+	struct pwc_frame_buf *buf = container_of(vbuf, struct pwc_frame_buf, vb);
 
 	if (vb->state == VB2_BUF_STATE_DONE) {
 		/*
@@ -633,20 +636,22 @@ static void buffer_finish(struct vb2_buffer *vb)
 
 static void buffer_cleanup(struct vb2_buffer *vb)
 {
-	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct pwc_frame_buf *buf = container_of(vbuf, struct pwc_frame_buf, vb);
 
 	vfree(buf->data);
 }
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct pwc_device *pdev = vb2_get_drv_priv(vb->vb2_queue);
-	struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
+	struct pwc_frame_buf *buf = container_of(vbuf, struct pwc_frame_buf, vb);
 	unsigned long flags = 0;
 
 	/* 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(vb, VB2_BUF_STATE_ERROR);
 		return;
 	}
 
@@ -695,7 +700,8 @@ 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_buf,
+				VB2_BUF_STATE_ERROR);
 	mutex_unlock(&pdev->v4l2_lock);
 }
 
diff --git a/drivers/media/usb/pwc/pwc-uncompress.c b/drivers/media/usb/pwc/pwc-uncompress.c
index b65903f..58b5518 100644
--- a/drivers/media/usb/pwc/pwc-uncompress.c
+++ b/drivers/media/usb/pwc/pwc-uncompress.c
@@ -40,7 +40,7 @@ int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
 	u16 *src;
 	u16 *dsty, *dstu, *dstv;
 
-	image = vb2_plane_vaddr(&fbuf->vb, 0);
+	image = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 
 	yuv = fbuf->data + pdev->frame_header_size;  /* Skip header */
 
@@ -55,12 +55,12 @@ int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
 			 * determine this using the type of the webcam */
 		memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
 		memcpy(raw_frame+1, yuv, pdev->frame_size);
-		vb2_set_plane_payload(&fbuf->vb, 0,
-			pdev->frame_size + sizeof(struct pwc_raw_frame));
+		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
+				      pdev->frame_size + sizeof(struct pwc_raw_frame));
 		return 0;
 	}
 
-	vb2_set_plane_payload(&fbuf->vb, 0,
+	vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
 			      pdev->width * pdev->height * 3 / 2);
 
 	if (pdev->vbandlength == 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..4284e56 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;
 };
 
@@ -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_buf, VB2_BUF_STATE_DONE);
 	dprintk(dev, 2, "%s: [buf] [%p]\n", __func__, buf);
 }
 
@@ -612,7 +612,7 @@ static void s2255_fillbuff(struct s2255_vc *vc,
 {
 	int pos = 0;
 	const char *tmpbuf;
-	char *vbuf = vb2_plane_vaddr(&buf->vb, 0);
+	char *vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 	unsigned long last_frame;
 	struct s2255_dev *dev = vc->dev;
 
@@ -635,7 +635,8 @@ static void s2255_fillbuff(struct s2255_vc *vc,
 			break;
 		case V4L2_PIX_FMT_JPEG:
 		case V4L2_PIX_FMT_MJPEG:
-			vb2_set_plane_payload(&buf->vb, 0, jpgsize);
+			vb2_set_plane_payload(&buf->vb.vb2_buf, 0,
+					      jpgsize);
 			memcpy(vbuf, tmpbuf, jpgsize);
 			break;
 		case V4L2_PIX_FMT_YUV422P:
@@ -674,7 +675,6 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 static int buffer_prepare(struct vb2_buffer *vb)
 {
 	struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2_queue);
-	struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb);
 	int w = vc->width;
 	int h = vc->height;
 	unsigned long size;
@@ -696,13 +696,14 @@ static int buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(&buf->vb, 0, size);
+	vb2_set_plane_payload(vb, 0, size);
 	return 0;
 }
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
-	struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct s2255_buffer *buf = container_of(vbuf, struct s2255_buffer, vb);
 	struct s2255_vc *vc = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long flags = 0;
 	dprintk(vc->dev, 1, "%s\n", __func__);
@@ -1116,7 +1117,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_buf, 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 e12b103..6e23b2b 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -693,10 +693,11 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *v4l_fmt,
 
 static void buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	unsigned long flags;
 	struct stk1160 *dev = vb2_get_drv_priv(vb->vb2_queue);
 	struct stk1160_buffer *buf =
-		container_of(vb, struct stk1160_buffer, vb);
+		container_of(vbuf, struct stk1160_buffer, vb);
 
 	spin_lock_irqsave(&dev->buf_lock, flags);
 	if (!dev->udev) {
@@ -704,7 +705,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(vb, VB2_BUF_STATE_ERROR);
 	} else {
 
 		buf->mem = vb2_plane_vaddr(vb, 0);
@@ -717,7 +718,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(vb, VB2_BUF_STATE_ERROR);
 		else
 			list_add_tail(&buf->list, &dev->avail_bufs);
 
@@ -769,7 +770,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_buf, VB2_BUF_STATE_ERROR);
 		stk1160_dbg("buffer [%p/%d] aborted\n",
 			    buf, buf->vb.v4l2_buf.index);
 	}
@@ -779,7 +780,7 @@ void stk1160_clear_queue(struct stk1160 *dev)
 		buf = dev->isoc_ctl.buf;
 		dev->isoc_ctl.buf = NULL;
 
-		vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
 		stk1160_dbg("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 940c3ea..ff1f327 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -101,8 +101,8 @@ void stk1160_buffer_done(struct stk1160 *dev)
 	buf->vb.v4l2_buf.bytesused = buf->bytesused;
 	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_set_plane_payload(&buf->vb.vb2_buf, 0, buf->bytesused);
+	vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
 
 	dev->isoc_ctl.buf = NULL;
 }
diff --git a/drivers/media/usb/stk1160/stk1160.h b/drivers/media/usb/stk1160/stk1160.h
index 047131b..1ed1cc4 100644
--- a/drivers/media/usb/stk1160/stk1160.h
+++ b/drivers/media/usb/stk1160/stk1160.h
@@ -77,7 +77,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 a46766c..2f8674d 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -306,7 +306,7 @@ static void usbtv_image_chunk(struct usbtv *usbtv, __be32 *chunk)
 
 	/* First available buffer. */
 	buf = list_first_entry(&usbtv->bufs, struct usbtv_buf, list);
-	frame = vb2_plane_vaddr(&buf->vb, 0);
+	frame = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 
 	/* Copy the chunk data. */
 	usbtv_chunk_to_vbuf(frame, &chunk[1], chunk_no, odd);
@@ -314,7 +314,7 @@ static void usbtv_image_chunk(struct usbtv *usbtv, __be32 *chunk)
 
 	/* Last chunk in a frame, signalling an end */
 	if (odd && chunk_no == usbtv->n_chunks-1) {
-		int size = vb2_plane_size(&buf->vb, 0);
+		int size = vb2_plane_size(&buf->vb.vb2_buf, 0);
 		enum vb2_buffer_state state = usbtv->chunks_done ==
 						usbtv->n_chunks ?
 						VB2_BUF_STATE_DONE :
@@ -323,8 +323,8 @@ static void usbtv_image_chunk(struct usbtv *usbtv, __be32 *chunk)
 		buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
 		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_set_plane_payload(&buf->vb.vb2_buf, 0, size);
+		vb2_buffer_done(&buf->vb.vb2_buf, 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_buf, VB2_BUF_STATE_ERROR);
 		list_del(&buf->list);
 	}
 	spin_unlock_irqrestore(&usbtv->buflock, flags);
@@ -617,8 +617,9 @@ static int usbtv_queue_setup(struct vb2_queue *vq,
 
 static void usbtv_buf_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct usbtv *usbtv = vb2_get_drv_priv(vb->vb2_queue);
-	struct usbtv_buf *buf = container_of(vb, struct usbtv_buf, vb);
+	struct usbtv_buf *buf = container_of(vbuf, struct usbtv_buf, vb);
 	unsigned long flags;
 
 	if (usbtv->udev == NULL) {
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 f16b9b4..2db04b2 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_buf, vb2_state);
 	}
 }
 
@@ -89,10 +89,11 @@ static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 static int uvc_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
-	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
+	struct uvc_buffer *buf = container_of(vbuf, struct uvc_buffer, buf);
 
-	if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
+	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
 	    vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
 		uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
 		return -EINVAL;
@@ -105,7 +106,7 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 	buf->error = 0;
 	buf->mem = vb2_plane_vaddr(vb, 0);
 	buf->length = vb2_plane_size(vb, 0);
-	if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
 		buf->bytesused = 0;
 	else
 		buf->bytesused = vb2_get_plane_payload(vb, 0);
@@ -115,8 +116,9 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 
 static void uvc_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
-	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
+	struct uvc_buffer *buf = container_of(vbuf, struct uvc_buffer, buf);
 	unsigned long flags;
 
 	spin_lock_irqsave(&queue->irqlock, flags);
@@ -127,7 +129,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(vb, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&queue->irqlock, flags);
@@ -135,12 +137,13 @@ static void uvc_buffer_queue(struct vb2_buffer *vb)
 
 static void uvc_buffer_finish(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
 	struct uvc_streaming *stream = uvc_queue_to_stream(queue);
-	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
+	struct uvc_buffer *buf = container_of(vbuf, struct uvc_buffer, buf);
 
 	if (vb->state == VB2_BUF_STATE_DONE)
-		uvc_video_clock_update(stream, &vb->v4l2_buf, buf);
+		uvc_video_clock_update(stream, &vbuf->v4l2_buf, buf);
 }
 
 static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
@@ -398,7 +401,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
 		buf->error = 0;
 		buf->state = UVC_BUF_STATE_QUEUED;
 		buf->bytesused = 0;
-		vb2_set_plane_payload(&buf->buf, 0, 0);
+		vb2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
 		return buf;
 	}
 
@@ -412,8 +415,8 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
 	spin_unlock_irqrestore(&queue->irqlock, flags);
 
 	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_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
+	vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
 
 	return nextbuf;
 }
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 53e6484..f5c2e99 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -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/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 95100e3..8ea5de6 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -773,13 +773,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 *vbuf)
 {
-	struct v4l2_m2m_buffer *b = container_of(vb, struct v4l2_m2m_buffer, vb);
+	struct v4l2_m2m_buffer *b = container_of(vbuf, 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, vbuf->vb2_buf.vb2_queue->type);
 	if (!q_ctx)
 		return;
 
diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index ca15186..7956776 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -53,7 +53,7 @@ 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, vb2_v4l2_index(vb), #op,		\
 		(vb)->vb2_queue->mem_ops->op ? "" : " (nop)")
 
 #define call_memop(vb, op, args...)					\
@@ -115,7 +115,7 @@ 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, vb2_v4l2_index(vb), #op,		\
 		(vb)->vb2_queue->ops->op ? "" : " (nop)")
 
 #define call_vb_qop(vb, op, args...)					\
@@ -192,6 +192,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb);
 static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 {
 	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	enum dma_data_direction dma_dir =
 		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
 	void *mem_priv;
@@ -211,7 +212,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 
 		/* Associate allocator private data with this plane */
 		vb->planes[plane].mem_priv = mem_priv;
-		vb->v4l2_planes[plane].length = q->plane_sizes[plane];
+		vbuf->v4l2_planes[plane].length = q->plane_sizes[plane];
 	}
 
 	return 0;
@@ -236,7 +237,7 @@ static void __vb2_buf_mem_free(struct vb2_buffer *vb)
 		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);
+			vb2_v4l2_index(vb));
 	}
 }
 
@@ -292,14 +293,16 @@ static void __setup_lengths(struct vb2_queue *q, unsigned int n)
 {
 	unsigned int buffer, plane;
 	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vbuf;
 
 	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
 		vb = q->bufs[buffer];
 		if (!vb)
 			continue;
+		vbuf = to_vb2_v4l2_buffer(vb);
 
 		for (plane = 0; plane < vb->num_planes; ++plane)
-			vb->v4l2_planes[plane].length = q->plane_sizes[plane];
+			vbuf->v4l2_planes[plane].length = q->plane_sizes[plane];
 	}
 }
 
@@ -311,12 +314,14 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
 {
 	unsigned int buffer, plane;
 	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vbuf;
 	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];
+		vbuf = to_vb2_v4l2_buffer(vb);
+		p = &vbuf->v4l2_planes[vb->num_planes - 1];
 		off = PAGE_ALIGN(p->m.mem_offset + p->length);
 	} else {
 		off = 0;
@@ -326,14 +331,15 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
 		vb = q->bufs[buffer];
 		if (!vb)
 			continue;
+		vbuf = to_vb2_v4l2_buffer(vb);
 
 		for (plane = 0; plane < vb->num_planes; ++plane) {
-			vb->v4l2_planes[plane].m.mem_offset = off;
+			vbuf->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 += vbuf->v4l2_planes[plane].length;
 			off = PAGE_ALIGN(off);
 		}
 	}
@@ -351,6 +357,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 {
 	unsigned int buffer;
 	struct vb2_buffer *vb;
+	struct vb2_v4l2_buffer *vbuf;
 	int ret;
 
 	for (buffer = 0; buffer < num_buffers; ++buffer) {
@@ -361,16 +368,18 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
 			break;
 		}
 
+		vbuf = to_vb2_v4l2_buffer(vb);
+
 		/* Length stores number of planes for multiplanar buffers */
 		if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
-			vb->v4l2_buf.length = num_planes;
+			vbuf->v4l2_buf.length = num_planes;
 
 		vb->state = VB2_BUF_STATE_DEQUEUED;
 		vb->vb2_queue = q;
 		vb->num_planes = num_planes;
-		vb->v4l2_buf.index = q->num_buffers + buffer;
-		vb->v4l2_buf.type = q->type;
-		vb->v4l2_buf.memory = memory;
+		vbuf->v4l2_buf.index = q->num_buffers + buffer;
+		vbuf->v4l2_buf.type = q->type;
+		vbuf->v4l2_buf.memory = memory;
 
 		/* Allocate video buffer memory for the MMAP type */
 		if (memory == V4L2_MEMORY_MMAP) {
@@ -580,6 +589,7 @@ static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer
  */
 static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	unsigned int length;
 	unsigned int bytesused;
 	unsigned int plane;
@@ -592,7 +602,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 			length = (b->memory == V4L2_MEMORY_USERPTR ||
 				  b->memory == V4L2_MEMORY_DMABUF)
 			       ? b->m.planes[plane].length
-			       : vb->v4l2_planes[plane].length;
+			       : vbuf->v4l2_planes[plane].length;
 			bytesused = b->m.planes[plane].bytesused
 				  ? b->m.planes[plane].bytesused : length;
 
@@ -605,7 +615,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 	} else {
 		length = (b->memory == V4L2_MEMORY_USERPTR)
-		       ? b->length : vb->v4l2_planes[0].length;
+		       ? b->length : vbuf->v4l2_planes[0].length;
 		bytesused = b->bytesused ? b->bytesused : length;
 
 		if (b->bytesused > length)
@@ -657,11 +667,12 @@ static bool __buffers_in_use(struct vb2_queue *q)
 static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 {
 	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
 	/* 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, &vbuf->v4l2_buf, offsetof(struct v4l2_buffer, m));
+	b->reserved2 = vbuf->v4l2_buf.reserved2;
+	b->reserved = vbuf->v4l2_buf.reserved;
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) {
 		/*
@@ -669,21 +680,21 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 		 * for it. The caller has already verified memory and size.
 		 */
 		b->length = vb->num_planes;
-		memcpy(b->m.planes, vb->v4l2_planes,
+		memcpy(b->m.planes, vbuf->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 = vbuf->v4l2_planes[0].length;
+		b->bytesused = vbuf->v4l2_planes[0].bytesused;
 		if (q->memory == V4L2_MEMORY_MMAP)
-			b->m.offset = vb->v4l2_planes[0].m.mem_offset;
+			b->m.offset = vbuf->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 = vbuf->v4l2_planes[0].m.userptr;
 		else if (q->memory == V4L2_MEMORY_DMABUF)
-			b->m.fd = vb->v4l2_planes[0].m.fd;
+			b->m.fd = vbuf->v4l2_planes[0].m.fd;
 	}
 
 	/*
@@ -1195,7 +1206,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 	vb->cnt_buf_done++;
 #endif
 	dprintk(4, "done processing on buffer %d, state: %d\n",
-			vb->v4l2_buf.index, state);
+			vb2_v4l2_index(vb), state);
 
 	/* sync buffers */
 	for (plane = 0; plane < vb->num_planes; ++plane)
@@ -1272,6 +1283,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 				struct v4l2_plane *v4l2_planes)
 {
 	unsigned int plane;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
 		if (b->memory == V4L2_MEMORY_USERPTR) {
@@ -1364,7 +1376,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;
+	vbuf->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)) {
 		/*
@@ -1372,7 +1384,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 		 * their timestamp and timestamp source flags from the
 		 * queue.
 		 */
-		vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
+		vbuf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 	}
 
 	if (V4L2_TYPE_IS_OUTPUT(b->type)) {
@@ -1382,11 +1394,11 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 		 * 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;
+		vbuf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
+		vbuf->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;
+		vbuf->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
 	}
 }
 
@@ -1395,7 +1407,9 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
  */
 static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 {
-	__fill_vb2_buffer(vb, b, vb->v4l2_planes);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
+	__fill_vb2_buffer(vb, b, vbuf->v4l2_planes);
 	return call_vb_qop(vb, buf_prepare, vb);
 }
 
@@ -1406,6 +1420,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct v4l2_plane planes[VIDEO_MAX_PLANES];
 	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	void *mem_priv;
 	unsigned int plane;
 	int ret;
@@ -1419,9 +1434,9 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 
 	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 (vbuf->v4l2_planes[plane].m.userptr &&
+		    vbuf->v4l2_planes[plane].m.userptr == planes[plane].m.userptr
+		    && vbuf->v4l2_planes[plane].length == planes[plane].length)
 			continue;
 
 		dprintk(3, "userspace address for plane %d changed, "
@@ -1447,7 +1462,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		}
 
 		vb->planes[plane].mem_priv = NULL;
-		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
+		memset(&vbuf->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],
@@ -1467,7 +1482,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	 * provided by userspace.
 	 */
 	for (plane = 0; plane < vb->num_planes; ++plane)
-		vb->v4l2_planes[plane] = planes[plane];
+		vbuf->v4l2_planes[plane] = planes[plane];
 
 	if (reacquired) {
 		/*
@@ -1496,8 +1511,8 @@ err:
 		if (vb->planes[plane].mem_priv)
 			call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv);
 		vb->planes[plane].mem_priv = NULL;
-		vb->v4l2_planes[plane].m.userptr = 0;
-		vb->v4l2_planes[plane].length = 0;
+		vbuf->v4l2_planes[plane].m.userptr = 0;
+		vbuf->v4l2_planes[plane].length = 0;
 	}
 
 	return ret;
@@ -1510,6 +1525,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct v4l2_plane planes[VIDEO_MAX_PLANES];
 	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	void *mem_priv;
 	unsigned int plane;
 	int ret;
@@ -1544,7 +1560,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 &&
-		    vb->v4l2_planes[plane].length == planes[plane].length) {
+		    vbuf->v4l2_planes[plane].length == planes[plane].length) {
 			dma_buf_put(dbuf);
 			continue;
 		}
@@ -1558,7 +1574,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]);
-		memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
+		memset(&vbuf->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],
@@ -1593,7 +1609,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	 * provided by userspace.
 	 */
 	for (plane = 0; plane < vb->num_planes; ++plane)
-		vb->v4l2_planes[plane] = planes[plane];
+		vbuf->v4l2_planes[plane] = planes[plane];
 
 	if (reacquired) {
 		/*
@@ -1645,6 +1661,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
 static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct vb2_queue *q = vb->vb2_queue;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	int ret;
 
 	ret = __verify_length(vb, b);
@@ -1672,9 +1689,9 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	}
 
 	vb->state = VB2_BUF_STATE_PREPARING;
-	vb->v4l2_buf.timestamp.tv_sec = 0;
-	vb->v4l2_buf.timestamp.tv_usec = 0;
-	vb->v4l2_buf.sequence = 0;
+	vbuf->v4l2_buf.timestamp.tv_sec = 0;
+	vbuf->v4l2_buf.timestamp.tv_usec = 0;
+	vbuf->v4l2_buf.sequence = 0;
 
 	switch (q->memory) {
 	case V4L2_MEMORY_MMAP:
@@ -1768,7 +1785,8 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 		/* Fill buffer information for the userspace */
 		__fill_v4l2_buffer(vb, b);
 
-		dprintk(1, "prepare of buffer %d succeeded\n", vb->v4l2_buf.index);
+		dprintk(1, "prepare of buffer %d succeeded\n",
+			vb2_v4l2_index(vb));
 	}
 	return ret;
 }
@@ -1872,16 +1890,18 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 	q->waiting_for_buffers = false;
 	vb->state = VB2_BUF_STATE_QUEUED;
 	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+		struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
 		/*
 		 * For output buffers copy the timestamp if needed,
 		 * and the timecode field and flag if needed.
 		 */
 		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;
+			vbuf->v4l2_buf.timestamp = b->timestamp;
+		vbuf->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
 		if (b->flags & V4L2_BUF_FLAG_TIMECODE)
-			vb->v4l2_buf.timecode = b->timecode;
+			vbuf->v4l2_buf.timecode = b->timecode;
 	}
 
 	trace_vb2_qbuf(q, vb);
@@ -1909,7 +1929,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", vb2_v4l2_index(vb));
 	return 0;
 }
 
@@ -2102,6 +2122,7 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
 static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
 	struct vb2_buffer *vb = NULL;
+	struct vb2_v4l2_buffer *vbuf = NULL;
 	int ret;
 
 	if (b->type != q->type) {
@@ -2134,14 +2155,16 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
 
 	trace_vb2_dqbuf(q, vb);
 
+	vbuf = to_vb2_v4l2_buffer(vb);
+
 	if (!V4L2_TYPE_IS_OUTPUT(q->type) &&
-	    vb->v4l2_buf.flags & V4L2_BUF_FLAG_LAST)
+	    vbuf->v4l2_buf.flags & V4L2_BUF_FLAG_LAST)
 		q->last_buffer_dequeued = true;
 	/* go back to dequeued state */
 	__vb2_dqbuf(vb);
 
 	dprintk(1, "dqbuf of buffer %d, with state %d\n",
-			vb->v4l2_buf.index, vb->state);
+			vb2_v4l2_index(vb), vb->state);
 
 	return 0;
 }
@@ -2388,6 +2411,7 @@ 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 *vbuf;
 	unsigned int buffer, plane;
 
 	/*
@@ -2397,9 +2421,9 @@ 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];
-
+		vbuf = to_vb2_v4l2_buffer(vb);
 		for (plane = 0; plane < vb->num_planes; ++plane) {
-			if (vb->v4l2_planes[plane].m.mem_offset == off) {
+			if (vbuf->v4l2_planes[plane].m.mem_offset == off) {
 				*_buffer = buffer;
 				*_plane = plane;
 				return 0;
@@ -2511,6 +2535,7 @@ 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 *vbuf;
 	unsigned int buffer = 0, plane = 0;
 	int ret;
 	unsigned long length;
@@ -2551,13 +2576,14 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 		return ret;
 
 	vb = q->bufs[buffer];
+	vbuf = to_vb2_v4l2_buffer(vb);
 
 	/*
 	 * 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(vbuf->v4l2_planes[plane].length);
 	if (length < (vma->vm_end - vma->vm_start)) {
 		dprintk(1,
 			"MMAP invalid, as it would overflow buffer length\n");
@@ -2762,7 +2788,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;
 }
diff --git a/drivers/usb/gadget/function/uvc_queue.c b/drivers/usb/gadget/function/uvc_queue.c
index d617c39..d903ece 100644
--- a/drivers/usb/gadget/function/uvc_queue.c
+++ b/drivers/usb/gadget/function/uvc_queue.c
@@ -60,10 +60,11 @@ static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 
 static int uvc_buffer_prepare(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
-	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
+	struct uvc_buffer *buf = container_of(vbuf, struct uvc_buffer, buf);
 
-	if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
+	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
 	    vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
 		uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
 		return -EINVAL;
@@ -75,7 +76,7 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 	buf->state = UVC_BUF_STATE_QUEUED;
 	buf->mem = vb2_plane_vaddr(vb, 0);
 	buf->length = vb2_plane_size(vb, 0);
-	if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
 		buf->bytesused = 0;
 	else
 		buf->bytesused = vb2_get_plane_payload(vb, 0);
@@ -85,8 +86,9 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 
 static void uvc_buffer_queue(struct vb2_buffer *vb)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
-	struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
+	struct uvc_buffer *buf = container_of(vbuf, struct uvc_buffer, buf);
 	unsigned long flags;
 
 	spin_lock_irqsave(&queue->irqlock, flags);
@@ -98,7 +100,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(vb, VB2_BUF_STATE_ERROR);
 	}
 
 	spin_unlock_irqrestore(&queue->irqlock, flags);
@@ -242,7 +244,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_buffer_done(&buf->buf.vb2_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
@@ -314,7 +316,7 @@ struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
 	if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
 	     buf->length != buf->bytesused) {
 		buf->state = UVC_BUF_STATE_QUEUED;
-		vb2_set_plane_payload(&buf->buf, 0, 0);
+		vb2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
 		return buf;
 	}
 
@@ -329,8 +331,8 @@ struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
 	buf->buf.v4l2_buf.sequence = queue->sequence++;
 	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_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
+	vb2_buffer_done(&buf->buf.vb2_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 0ffe498..ac461a9 100644
--- a/drivers/usb/gadget/function/uvc_queue.h
+++ b/drivers/usb/gadget/function/uvc_queue.h
@@ -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/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index 22f88c7..b59c4ea 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -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,9 +101,9 @@ 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);
+	vb2_buffer_done(&buf->vb2_buf, state);
 }
 
 int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
@@ -156,7 +156,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 *vbuf);
 
 /**
  * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index 021a69c..76500f4 100644
--- a/include/media/videobuf2-v4l2.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>
@@ -161,17 +161,6 @@ 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
  * @vb2_queue:		the queue to which this driver belongs
  * @num_planes:		number of planes in the buffer
  *			on an internal driver queue
@@ -183,9 +172,6 @@ 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;
@@ -231,6 +217,26 @@ struct vb2_buffer {
 };
 
 /**
+ * struct vb2_v4l2_buffer - represents a video buffer for v4l2
+ * @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_buf;
+	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
@@ -339,7 +345,7 @@ struct v4l2_fh;
  * @fileio_write_immediately:	queue buffer after each write() call
  * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
  * @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 vb2 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.
@@ -352,7 +358,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.
@@ -444,6 +450,20 @@ struct vb2_queue {
 #endif
 };
 
+/**
+ * to_vb2_v4l2_buffer() - cast to struct vb2_v4l2_buffer *
+ * @vb:		struct vb2_buffer *vb
+ */
+#define to_vb2_v4l2_buffer(vb) \
+	(container_of(vb, struct vb2_v4l2_buffer, vb2_buf))
+
+#define vb2_v4l2_index(vb)						\
+({								\
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);	\
+	int ret = vbuf->v4l2_buf.index;				\
+	ret;							\
+})
+
 void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
 void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
 
@@ -567,8 +587,10 @@ static inline void *vb2_get_drv_priv(struct vb2_queue *q)
 static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
 				 unsigned int plane_no, unsigned long size)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
 	if (plane_no < vb->num_planes)
-		vb->v4l2_planes[plane_no].bytesused = size;
+		vbuf->v4l2_planes[plane_no].bytesused = size;
 }
 
 /**
@@ -580,8 +602,10 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
 static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
 				 unsigned int plane_no)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
 	if (plane_no < vb->num_planes)
-		return vb->v4l2_planes[plane_no].bytesused;
+		return vbuf->v4l2_planes[plane_no].bytesused;
 	return 0;
 }
 
@@ -593,8 +617,10 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
 static inline unsigned long
 vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
 {
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+
 	if (plane_no < vb->num_planes)
-		return vb->v4l2_planes[plane_no].length;
+		return vbuf->v4l2_planes[plane_no].length;
 	return 0;
 }
 
@@ -660,4 +686,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/trace/events/v4l2.h b/include/trace/events/v4l2.h
index dbf017b..dabd780 100644
--- a/include/trace/events/v4l2.h
+++ b/include/trace/events/v4l2.h
@@ -202,27 +202,28 @@ DECLARE_EVENT_CLASS(vb2_event_class,
 	),
 
 	TP_fast_assign(
+		struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 		__entry->minor = q->owner ? q->owner->vdev->minor : -1;
 		__entry->queued_count = q->queued_count;
 		__entry->owned_by_drv_count =
 			atomic_read(&q->owned_by_drv_count);
-		__entry->index = vb->v4l2_buf.index;
-		__entry->type = vb->v4l2_buf.type;
-		__entry->bytesused = vb->v4l2_planes[0].bytesused;
-		__entry->flags = vb->v4l2_buf.flags;
-		__entry->field = vb->v4l2_buf.field;
-		__entry->timestamp = timeval_to_ns(&vb->v4l2_buf.timestamp);
-		__entry->timecode_type = vb->v4l2_buf.timecode.type;
-		__entry->timecode_flags = vb->v4l2_buf.timecode.flags;
-		__entry->timecode_frames = vb->v4l2_buf.timecode.frames;
-		__entry->timecode_seconds = vb->v4l2_buf.timecode.seconds;
-		__entry->timecode_minutes = vb->v4l2_buf.timecode.minutes;
-		__entry->timecode_hours = vb->v4l2_buf.timecode.hours;
-		__entry->timecode_userbits0 = vb->v4l2_buf.timecode.userbits[0];
-		__entry->timecode_userbits1 = vb->v4l2_buf.timecode.userbits[1];
-		__entry->timecode_userbits2 = vb->v4l2_buf.timecode.userbits[2];
-		__entry->timecode_userbits3 = vb->v4l2_buf.timecode.userbits[3];
-		__entry->sequence = vb->v4l2_buf.sequence;
+		__entry->index = vbuf->v4l2_buf.index;
+		__entry->type = vbuf->v4l2_buf.type;
+		__entry->bytesused = vbuf->v4l2_planes[0].bytesused;
+		__entry->flags = vbuf->v4l2_buf.flags;
+		__entry->field = vbuf->v4l2_buf.field;
+		__entry->timestamp = timeval_to_ns(&vbuf->v4l2_buf.timestamp);
+		__entry->timecode_type = vbuf->v4l2_buf.timecode.type;
+		__entry->timecode_flags = vbuf->v4l2_buf.timecode.flags;
+		__entry->timecode_frames = vbuf->v4l2_buf.timecode.frames;
+		__entry->timecode_seconds = vbuf->v4l2_buf.timecode.seconds;
+		__entry->timecode_minutes = vbuf->v4l2_buf.timecode.minutes;
+		__entry->timecode_hours = vbuf->v4l2_buf.timecode.hours;
+		__entry->timecode_userbits0 = vbuf->v4l2_buf.timecode.userbits[0];
+		__entry->timecode_userbits1 = vbuf->v4l2_buf.timecode.userbits[1];
+		__entry->timecode_userbits2 = vbuf->v4l2_buf.timecode.userbits[2];
+		__entry->timecode_userbits3 = vbuf->v4l2_buf.timecode.userbits[3];
+		__entry->sequence = vbuf->v4l2_buf.sequence;
 	),
 
 	TP_printk("minor = %d, queued = %u, owned_by_drv = %d, index = %u, "
-- 
1.7.9.5


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

* [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts
  2015-07-31  8:44 [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Junghak Sung
  2015-07-31  8:44 ` [RFC PATCH v2 1/5] media: videobuf2: Rename videobuf2-core to videobuf2-v4l2 Junghak Sung
  2015-07-31  8:44 ` [RFC PATCH v2 2/5] media: videobuf2: Restructurng struct vb2_buffer for common use Junghak Sung
@ 2015-07-31  8:44 ` Junghak Sung
  2015-08-10 12:07   ` Hans Verkuil
  2015-07-31  8:44 ` [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory Junghak Sung
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 23+ messages in thread
From: Junghak Sung @ 2015-07-31  8:44 UTC (permalink / raw)
  To: linux-media, mchehab, hverkuil, laurent.pinchart, sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon, jh1009.sung

Divide videobuf2-core into core part and v4l2-specific part
 - core part: videobuf2 core related with buffer management & memory allocation
 - v4l2-specific part: v4l2-specific stuff

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
---
 drivers/input/touchscreen/sur40.c                  |    4 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |    2 +-
 drivers/media/pci/cx23885/cx23885-417.c            |    2 +-
 drivers/media/pci/cx23885/cx23885-dvb.c            |    2 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |    2 +-
 drivers/media/pci/cx23885/cx23885-video.c          |    2 +-
 drivers/media/pci/cx25821/cx25821-video.c          |    3 +-
 drivers/media/pci/cx25821/cx25821.h                |    1 +
 drivers/media/pci/cx88/cx88-blackbird.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                |    4 +-
 drivers/media/pci/dt3155/dt3155.c                  |    4 +-
 drivers/media/pci/saa7134/saa7134-ts.c             |    2 +-
 drivers/media/pci/saa7134/saa7134-vbi.c            |    2 +-
 drivers/media/pci/saa7134/saa7134-video.c          |    2 +-
 drivers/media/pci/saa7134/saa7134.h                |    3 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |    3 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    2 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c            |    2 +-
 drivers/media/pci/tw68/tw68-video.c                |    3 +-
 drivers/media/platform/blackfin/bfin_capture.c     |    4 +-
 drivers/media/platform/coda/coda-common.c          |    3 +-
 drivers/media/platform/davinci/vpbe_display.c      |    3 +-
 drivers/media/platform/davinci/vpif_capture.c      |    4 +-
 drivers/media/platform/davinci/vpif_display.c      |    4 +-
 drivers/media/platform/exynos-gsc/gsc-m2m.c        |    3 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |    3 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |    3 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |    3 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c       |    2 +-
 drivers/media/platform/m2m-deinterlace.c           |    3 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |    7 +-
 drivers/media/platform/mx2_emmaprp.c               |    3 +-
 drivers/media/platform/omap3isp/ispvideo.c         |    3 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |    3 +-
 drivers/media/platform/s5p-g2d/g2d.c               |    2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |    3 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |    2 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |    3 +-
 drivers/media/platform/s5p-tv/mixer_video.c        |    2 +-
 drivers/media/platform/sh_veu.c                    |    4 +-
 drivers/media/platform/soc_camera/atmel-isi.c      |    2 +-
 drivers/media/platform/soc_camera/mx2_camera.c     |    3 +-
 drivers/media/platform/soc_camera/mx3_camera.c     |    4 +-
 drivers/media/platform/soc_camera/rcar_vin.c       |    4 +-
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |    4 +-
 drivers/media/platform/ti-vpe/vpe.c                |    3 +-
 drivers/media/platform/vim2m.c                     |    3 +-
 drivers/media/platform/vivid/vivid-sdr-cap.c       |    2 +-
 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       |    3 +-
 drivers/media/platform/vivid/vivid-vid-out.c       |    3 +-
 drivers/media/platform/vsp1/vsp1_video.c           |    3 +-
 drivers/media/usb/airspy/airspy.c                  |    2 +-
 drivers/media/usb/au0828/au0828-vbi.c              |    3 +-
 drivers/media/usb/au0828/au0828-video.c            |    3 +-
 drivers/media/usb/au0828/au0828.h                  |    1 +
 drivers/media/usb/em28xx/em28xx-vbi.c              |    3 +-
 drivers/media/usb/em28xx/em28xx-video.c            |    3 +-
 drivers/media/usb/em28xx/em28xx.h                  |    1 +
 drivers/media/usb/go7007/go7007-v4l2.c             |    3 +-
 drivers/media/usb/hackrf/hackrf.c                  |    2 +-
 drivers/media/usb/msi2500/msi2500.c                |    3 +-
 drivers/media/usb/pwc/pwc-if.c                     |    2 +-
 drivers/media/usb/pwc/pwc.h                        |    1 +
 drivers/media/usb/s2255/s2255drv.c                 |    3 +-
 drivers/media/usb/stk1160/stk1160-v4l.c            |    2 +-
 drivers/media/usb/usbtv/usbtv-video.c              |    3 +-
 drivers/media/usb/usbtv/usbtv.h                    |    1 +
 drivers/media/usb/uvc/uvc_queue.c                  |    3 +-
 drivers/media/v4l2-core/Makefile                   |    2 +-
 drivers/media/v4l2-core/videobuf2-core.c           | 1797 ++++++++++++++++
 drivers/media/v4l2-core/videobuf2-dma-contig.c     |    2 +-
 drivers/media/v4l2-core/videobuf2-dma-sg.c         |    2 +-
 drivers/media/v4l2-core/videobuf2-memops.c         |    2 +-
 drivers/media/v4l2-core/videobuf2-v4l2.c           | 2260 +++-----------------
 drivers/media/v4l2-core/videobuf2-vmalloc.c        |    2 +-
 drivers/usb/gadget/function/uvc_queue.c            |    2 +-
 include/media/videobuf2-core.h                     |  724 +++++++
 include/media/videobuf2-dma-contig.h               |    2 +-
 include/media/videobuf2-dma-sg.h                   |    2 +-
 include/media/videobuf2-memops.h                   |    2 +-
 include/media/videobuf2-v4l2.h                     |  509 +----
 include/media/videobuf2-vmalloc.h                  |    2 +-
 include/trace/events/v4l2.h                        |    3 +-
 88 files changed, 2919 insertions(+), 2591 deletions(-)
 create mode 100644 drivers/media/v4l2-core/videobuf2-core.c
 create mode 100644 include/media/videobuf2-core.h

diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
index 2147a90..d7ea662 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -38,6 +38,7 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-dev.h>
 #include <media/v4l2-ioctl.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-sg.h>
 
 /* read 512 bytes from endpoint 0x86 -> get header + blobs */
@@ -642,10 +643,11 @@ static void sur40_disconnect(struct usb_interface *interface)
  * minimum number: many DMA engines need a minimum of 2 buffers in the
  * queue and you need to have another available for userspace processing.
  */
-static int sur40_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int sur40_queue_setup(struct vb2_queue *q, const void *parg,
 		       unsigned int *nbuffers, unsigned int *nplanes,
 		       unsigned int sizes[], void *alloc_ctxs[])
 {
+	const struct v4l2_format *fmt = (const struct v4l2_format *) parg;
 	struct sur40_state *sur40 = vb2_get_drv_priv(q);
 
 	if (q->num_buffers + *nbuffers < 3)
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index c900185d..8d36149 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -488,7 +488,7 @@ static int rtl2832_sdr_querycap(struct file *file, void *fh,
 
 /* Videobuf2 operations */
 static int rtl2832_sdr_queue_setup(struct vb2_queue *vq,
-		const struct v4l2_format *fmt, unsigned int *nbuffers,
+		const void *parg, unsigned int *nbuffers,
 		unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
 {
 	struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq);
diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c
index 316a322..88a3afb 100644
--- a/drivers/media/pci/cx23885/cx23885-417.c
+++ b/drivers/media/pci/cx23885/cx23885-417.c
@@ -1138,7 +1138,7 @@ static int cx23885_initialize_codec(struct cx23885_dev *dev, int startencoder)
 
 /* ------------------------------------------------------------------ */
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index 09ad512..c4307ad 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -92,7 +92,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 /* ------------------------------------------------------------------ */
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/cx23885/cx23885-vbi.c b/drivers/media/pci/cx23885/cx23885-vbi.c
index e84e5bd..d1fd585 100644
--- a/drivers/media/pci/cx23885/cx23885-vbi.c
+++ b/drivers/media/pci/cx23885/cx23885-vbi.c
@@ -121,7 +121,7 @@ static int cx23885_start_vbi_dma(struct cx23885_dev    *dev,
 
 /* ------------------------------------------------------------------ */
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index d06fc87..d7c6729 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -315,7 +315,7 @@ static int cx23885_start_video_dma(struct cx23885_dev *dev,
 	return 0;
 }
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c
index af0e425..5e672f2 100644
--- a/drivers/media/pci/cx25821/cx25821-video.c
+++ b/drivers/media/pci/cx25821/cx25821-video.c
@@ -141,10 +141,11 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
 	return handled;
 }
 
-static int cx25821_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int cx25821_queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct cx25821_channel *chan = q->drv_priv;
 	unsigned size = (chan->fmt->depth * chan->width * chan->height) >> 3;
 
diff --git a/drivers/media/pci/cx25821/cx25821.h b/drivers/media/pci/cx25821/cx25821.h
index fb2920c..a513b68 100644
--- a/drivers/media/pci/cx25821/cx25821.h
+++ b/drivers/media/pci/cx25821/cx25821.h
@@ -34,6 +34,7 @@
 #include <media/v4l2-common.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ctrls.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-sg.h>
 
 #include "cx25821-reg.h"
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index 49d0b7c..8b88913 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -637,7 +637,7 @@ static int blackbird_stop_codec(struct cx8802_dev *dev)
 
 /* ------------------------------------------------------------------ */
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index f0923fb..f048350 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -82,7 +82,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 /* ------------------------------------------------------------------ */
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index a4f5e1e..a315cd6 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -225,7 +225,7 @@ int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
 			struct cx88_buffer *buf)
 {
 	int size = dev->ts_packet_size * dev->ts_packet_count;
-	struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb, 0);
+	struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb.vb2_buf, 0);
 	struct cx88_riscmem *risc = &buf->risc;
 	int rc;
 
diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c
index cd2f3fb..2bdfbb9 100644
--- a/drivers/media/pci/cx88/cx88-vbi.c
+++ b/drivers/media/pci/cx88/cx88-vbi.c
@@ -107,7 +107,7 @@ int cx8800_restart_vbi_queue(struct cx8800_dev    *dev,
 
 /* ------------------------------------------------------------------ */
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index fae28e7..4af3808 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -429,7 +429,7 @@ static int restart_video_queue(struct cx8800_dev    *dev,
 
 /* ------------------------------------------------------------------ */
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
@@ -447,7 +447,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct cx8800_dev *dev = vb->vb2_queue->drv_priv;
 	struct cx88_core *core = dev->core;
-	struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb);
+	struct cx88_buffer *buf = container_of(vbuf, struct cx88_buffer, vb);
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
 
 	buf->bpl = core->width * dev->fmt->depth >> 3;
diff --git a/drivers/media/pci/dt3155/dt3155.c b/drivers/media/pci/dt3155/dt3155.c
index f4f8355..0aa45d0 100644
--- a/drivers/media/pci/dt3155/dt3155.c
+++ b/drivers/media/pci/dt3155/dt3155.c
@@ -22,6 +22,7 @@
 #include <media/v4l2-dev.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-common.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-contig.h>
 
 #include "dt3155.h"
@@ -131,11 +132,12 @@ static int wait_i2c_reg(void __iomem *addr)
 }
 
 static int
-dt3155_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+dt3155_queue_setup(struct vb2_queue *vq, const void *parg,
 		unsigned int *nbuffers, unsigned int *num_planes,
 		unsigned int sizes[], void *alloc_ctxs[])
 
 {
+	const struct v4l2_format *fmt = (const struct v4l2_format *) parg;
 	struct dt3155_priv *pd = vb2_get_drv_priv(vq);
 	unsigned size = pd->width * pd->height;
 
diff --git a/drivers/media/pci/saa7134/saa7134-ts.c b/drivers/media/pci/saa7134/saa7134-ts.c
index 62b218b..b19a00f 100644
--- a/drivers/media/pci/saa7134/saa7134-ts.c
+++ b/drivers/media/pci/saa7134/saa7134-ts.c
@@ -116,7 +116,7 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb)
 }
 EXPORT_SYMBOL_GPL(saa7134_ts_buffer_prepare);
 
-int saa7134_ts_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+int saa7134_ts_queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/saa7134/saa7134-vbi.c b/drivers/media/pci/saa7134/saa7134-vbi.c
index ecc4e61..c3cdb89 100644
--- a/drivers/media/pci/saa7134/saa7134-vbi.c
+++ b/drivers/media/pci/saa7134/saa7134-vbi.c
@@ -138,7 +138,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
 				    saa7134_buffer_startpage(buf));
 }
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index a03bbb8..7ea9411 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -904,7 +904,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
 				    saa7134_buffer_startpage(buf));
 }
 
-static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
index f3f9ba4..ffeaf65 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -43,6 +43,7 @@
 #include <media/tuner.h>
 #include <media/rc-core.h>
 #include <media/ir-kbd-i2c.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-dma-sg.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -819,7 +820,7 @@ void saa7134_video_fini(struct saa7134_dev *dev);
 
 int saa7134_ts_buffer_init(struct vb2_buffer *vb);
 int saa7134_ts_buffer_prepare(struct vb2_buffer *vb);
-int saa7134_ts_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+int saa7134_ts_queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[]);
 int saa7134_ts_start_streaming(struct vb2_queue *vq, unsigned int count);
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
index 6238e09..19dc488 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
@@ -660,8 +660,7 @@ static int solo_ring_thread(void *data)
 	return 0;
 }
 
-static int solo_enc_queue_setup(struct vb2_queue *q,
-				const struct v4l2_format *fmt,
+static int solo_enc_queue_setup(struct vb2_queue *q, const void *parg,
 				unsigned int *num_buffers,
 				unsigned int *num_planes, unsigned int sizes[],
 				void *alloc_ctxs[])
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2.c b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
index b46196b..628d019 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
@@ -312,7 +312,7 @@ static void solo_stop_thread(struct solo_dev *solo_dev)
 	solo_dev->kthread = NULL;
 }
 
-static int solo_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int solo_queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 1edc1f2..a4dc2d5 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -265,7 +265,7 @@ static void vip_active_buf_next(struct sta2x11_vip *vip)
 
 
 /* Videobuf2 Operations */
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned int *nbuffers, unsigned int *nplanes,
 		       unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c
index a2ecc5c..82dbc9a 100644
--- a/drivers/media/pci/tw68/tw68-video.c
+++ b/drivers/media/pci/tw68/tw68-video.c
@@ -376,10 +376,11 @@ static int tw68_buffer_count(unsigned int size, unsigned int count)
 /* ------------------------------------------------------------- */
 /* vb2 queue operations                                          */
 
-static int tw68_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
+static int tw68_queue_setup(struct vb2_queue *q, const void *parg,
 			   unsigned int *num_buffers, unsigned int *num_planes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct tw68_dev *dev = vb2_get_drv_priv(q);
 	unsigned tot_bufs = q->num_buffers + *num_buffers;
 
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index 2a03c1a..1c87afe 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -201,11 +201,11 @@ static void bcap_free_sensor_formats(struct bcap_device *bcap_dev)
 	bcap_dev->sensor_formats = NULL;
 }
 
-static int bcap_queue_setup(struct vb2_queue *vq,
-				const struct v4l2_format *fmt,
+static int bcap_queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
+	const struct v4l2_format *fmt = (const struct v4l2_format *)parg;
 	struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
 
 	if (fmt && fmt->fmt.pix.sizeimage < bcap_dev->fmt.sizeimage)
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 0b84bd3..10c4a9e 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1131,8 +1131,7 @@ static void set_default_params(struct coda_ctx *ctx)
 /*
  * Queue operations
  */
-static int coda_queue_setup(struct vb2_queue *vq,
-				const struct v4l2_format *fmt,
+static int coda_queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index bf5bf69..c0703aa 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -228,11 +228,12 @@ static int vpbe_buffer_prepare(struct vb2_buffer *vb)
  * This function allocates memory for the buffers
  */
 static int
-vpbe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+vpbe_buffer_queue_setup(struct vb2_queue *vq, const void *parg,
 			unsigned int *nbuffers, unsigned int *nplanes,
 			unsigned int sizes[], void *alloc_ctxs[])
 
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	/* Get the file handle object and layer object */
 	struct vpbe_layer *layer = vb2_get_drv_priv(vq);
 	struct vpbe_device *vpbe_dev = layer->disp_dev->vpbe_dev;
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index d0d76e2..b583ff1 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -112,11 +112,11 @@ static int vpif_buffer_prepare(struct vb2_buffer *vb)
  * This callback function is called when reqbuf() is called to adjust
  * the buffer count and buffer size
  */
-static int vpif_buffer_queue_setup(struct vb2_queue *vq,
-				const struct v4l2_format *fmt,
+static int vpif_buffer_queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct channel_obj *ch = vb2_get_drv_priv(vq);
 	struct common_obj *common;
 
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 46fc783..f7963bd 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -107,11 +107,11 @@ static int vpif_buffer_prepare(struct vb2_v4l2_buffer *vb)
  * This callback function is called when reqbuf() is called to adjust
  * the buffer count and buffer size
  */
-static int vpif_buffer_queue_setup(struct vb2_queue *vq,
-				const struct v4l2_format *fmt,
+static int vpif_buffer_queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct channel_obj *ch = vb2_get_drv_priv(vq);
 	struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX];
 
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 6003a4f..95df3a9 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -211,8 +211,7 @@ put_device:
 	spin_unlock_irqrestore(&gsc->slock, flags);
 }
 
-static int gsc_m2m_queue_setup(struct vb2_queue *vq,
-			const struct v4l2_format *fmt,
+static int gsc_m2m_queue_setup(struct vb2_queue *vq, const void *parg,
 			unsigned int *num_buffers, unsigned int *num_planes,
 			unsigned int sizes[], void *allocators[])
 {
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 78133c1..01bb3d7 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -345,10 +345,11 @@ int fimc_capture_resume(struct fimc_dev *fimc)
 
 }
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned int *num_buffers, unsigned int *num_planes,
 		       unsigned int sizes[], void *allocators[])
 {
+	struct v4l2_format *pfmt = (struct v4l2_format *)parg;
 	const struct v4l2_pix_format_mplane *pixm = NULL;
 	struct fimc_ctx *ctx = vq->drv_priv;
 	struct fimc_frame *frame = &ctx->d_frame;
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 52e1d61..2383724 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -39,10 +39,11 @@
 #include "fimc-is-param.h"
 
 static int isp_video_capture_queue_setup(struct vb2_queue *vq,
-			const struct v4l2_format *pfmt,
+			const void *parg,
 			unsigned int *num_buffers, unsigned int *num_planes,
 			unsigned int sizes[], void *allocators[])
 {
+	struct v4l2_format *pfmt = (struct v4l2_format *)parg;
 	struct fimc_isp *isp = vb2_get_drv_priv(vq);
 	struct v4l2_pix_format_mplane *vid_fmt = &isp->video_capture.pixfmt;
 	const struct v4l2_pix_format_mplane *pixm = NULL;
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index 316d25b..e9aaee7 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -361,10 +361,11 @@ static void stop_streaming(struct vb2_queue *q)
 	fimc_lite_stop_capture(fimc, false);
 }
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned int *num_buffers, unsigned int *num_planes,
 		       unsigned int sizes[], void *allocators[])
 {
+	struct v4l2_format *pfmt = (struct v4l2_format *)parg;
 	const struct v4l2_pix_format_mplane *pixm = NULL;
 	struct fimc_lite *fimc = vq->drv_priv;
 	struct flite_frame *frame = &fimc->out_frame;
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index f6e72b4..06d6436 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -176,7 +176,7 @@ static void fimc_job_abort(void *priv)
 	fimc_m2m_shutdown(priv);
 }
 
-static int fimc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int fimc_queue_setup(struct vb2_queue *vq, const void *parg,
 			    unsigned int *num_buffers, unsigned int *num_planes,
 			    unsigned int sizes[], void *allocators[])
 {
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index 475e82d..e67f9d2 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -797,8 +797,7 @@ struct vb2_dc_conf {
 	struct device           *dev;
 };
 
-static int deinterlace_queue_setup(struct vb2_queue *vq,
-				const struct v4l2_format *fmt,
+static int deinterlace_queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 645ebf8..b3735a7 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1049,10 +1049,11 @@ static int mcam_read_setup(struct mcam_camera *cam)
  */
 
 static int mcam_vb_queue_setup(struct vb2_queue *vq,
-		const struct v4l2_format *fmt, unsigned int *nbufs,
+		const void *parg, unsigned int *nbufs,
 		unsigned int *num_planes, unsigned int sizes[],
 		void *alloc_ctxs[])
 {
+	const struct v4l2_format *fmt = (const struct v4l2_format *) parg;
 	struct mcam_camera *cam = vb2_get_drv_priv(vq);
 	int minbufs = (cam->buffer_mode == B_DMA_contig) ? 3 : 2;
 
@@ -1098,14 +1099,14 @@ static void mcam_vb_requeue_bufs(struct vb2_queue *vq,
 
 	spin_lock_irqsave(&cam->dev_lock, flags);
 	list_for_each_entry_safe(buf, node, &cam->buffers, queue) {
-		vb2_buffer_done(&buf->vb_buf, state);
+		vb2_buffer_done(&buf->vb_buf.vb2_buf, state);
 		list_del(&buf->queue);
 	}
 	for (i = 0; i < MAX_DMA_BUFS; i++) {
 		buf = cam->vb_bufs[i];
 
 		if (buf) {
-			vb2_buffer_done(&buf->vb_buf, state);
+			vb2_buffer_done(&buf->vb_buf.vb2_buf, state);
 			cam->vb_bufs[i] = NULL;
 		}
 	}
diff --git a/drivers/media/platform/mx2_emmaprp.c b/drivers/media/platform/mx2_emmaprp.c
index 03072e2..269e1bc 100644
--- a/drivers/media/platform/mx2_emmaprp.c
+++ b/drivers/media/platform/mx2_emmaprp.c
@@ -688,8 +688,7 @@ static const struct v4l2_ioctl_ops emmaprp_ioctl_ops = {
 /*
  * Queue operations
  */
-static int emmaprp_queue_setup(struct vb2_queue *vq,
-				const struct v4l2_format *fmt,
+static int emmaprp_queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 09d4c82..65f57a2 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -319,8 +319,7 @@ isp_video_check_format(struct isp_video *video, struct isp_video_fh *vfh)
  * Video queue operations
  */
 
-static int isp_video_queue_setup(struct vb2_queue *queue,
-				 const struct v4l2_format *fmt,
+static int isp_video_queue_setup(struct vb2_queue *queue, const void *parg,
 				 unsigned int *count, unsigned int *num_planes,
 				 unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index c8bf624..8f4e9f4 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -442,10 +442,11 @@ static void stop_streaming(struct vb2_queue *vq)
 	camif_stop_capture(vp);
 }
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned int *num_buffers, unsigned int *num_planes,
 		       unsigned int sizes[], void *allocators[])
 {
+	struct v4l2_format *pfmt = (struct v4l2_format *)parg;
 	const struct v4l2_pix_format *pix = NULL;
 	struct camif_vp *vp = vb2_get_drv_priv(vq);
 	struct camif_dev *camif = vp->camif;
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 9e50173..9fade63 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -101,7 +101,7 @@ static struct g2d_frame *get_frame(struct g2d_ctx *ctx,
 	}
 }
 
-static int g2d_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int g2d_queue_setup(struct vb2_queue *vq, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 2300740..8fd178d 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -2121,8 +2121,7 @@ static struct v4l2_m2m_ops exynos4_jpeg_m2m_ops = {
  * ============================================================================
  */
 
-static int s5p_jpeg_queue_setup(struct vb2_queue *vq,
-			   const struct v4l2_format *fmt,
+static int s5p_jpeg_queue_setup(struct vb2_queue *vq, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 7d75d8e..1de804d 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -883,7 +883,7 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
 };
 
 static int s5p_mfc_queue_setup(struct vb2_queue *vq,
-			const struct v4l2_format *fmt, unsigned int *buf_count,
+			const void *parg, unsigned int *buf_count,
 			unsigned int *plane_count, unsigned int psize[],
 			void *allocators[])
 {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index e65249a..3b4b556 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1816,8 +1816,7 @@ static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
 	return 0;
 }
 
-static int s5p_mfc_queue_setup(struct vb2_queue *vq,
-			const struct v4l2_format *fmt,
+static int s5p_mfc_queue_setup(struct vb2_queue *vq, const void *parg,
 			unsigned int *buf_count, unsigned int *plane_count,
 			unsigned int psize[], void *allocators[])
 {
diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
index dba92b5..dc1c679 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -881,7 +881,7 @@ static const struct v4l2_file_operations mxr_fops = {
 	.unlocked_ioctl = video_ioctl2,
 };
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 	unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[],
 	void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
index a0910d9..1affcae 100644
--- a/drivers/media/platform/sh_veu.c
+++ b/drivers/media/platform/sh_veu.c
@@ -864,11 +864,11 @@ static const struct v4l2_ioctl_ops sh_veu_ioctl_ops = {
 
 		/* ========== Queue operations ========== */
 
-static int sh_veu_queue_setup(struct vb2_queue *vq,
-			      const struct v4l2_format *f,
+static int sh_veu_queue_setup(struct vb2_queue *vq, const void *parg,
 			      unsigned int *nbuffers, unsigned int *nplanes,
 			      unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *f = (struct v4l2_format *)parg;
 	struct sh_veu_dev *veu = vb2_get_drv_priv(vq);
 	struct sh_veu_vfmt *vfmt;
 	unsigned int size, count = *nbuffers;
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index 621a1a7..7268a2f 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -235,7 +235,7 @@ static int atmel_isi_wait_status(struct atmel_isi *isi, int wait_reset)
 /* ------------------------------------------------------------------
 	Videobuf operations
    ------------------------------------------------------------------*/
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index b250706..57e8ad0 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -469,10 +469,11 @@ static void mx2_camera_clock_stop(struct soc_camera_host *ici)
  *  Videobuf operations
  */
 static int mx2_videobuf_setup(struct vb2_queue *vq,
-			const struct v4l2_format *fmt,
+			const void *parg,
 			unsigned int *count, unsigned int *num_planes,
 			unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct mx2_camera_dev *pcdev = ici->priv;
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index 6c566b8..fa8849f 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -184,11 +184,11 @@ static void mx3_cam_dma_done(void *arg)
 /*
  * Calculate the __buffer__ (not data) size and number of buffers.
  */
-static int mx3_videobuf_setup(struct vb2_queue *vq,
-			const struct v4l2_format *fmt,
+static int mx3_videobuf_setup(struct vb2_queue *vq, const void *parg,
 			unsigned int *count, unsigned int *num_planes,
 			unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct mx3_camera_dev *mx3_cam = ici->priv;
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index afa887e..c529d10 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -526,11 +526,11 @@ struct rcar_vin_cam {
  * required
  */
 static int rcar_vin_videobuf_setup(struct vb2_queue *vq,
-				   const struct v4l2_format *fmt,
-				   unsigned int *count,
+				   const void *parg, unsigned int *count,
 				   unsigned int *num_planes,
 				   unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct rcar_vin_priv *priv = ici->priv;
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 b46c3e3..7335b79 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -209,11 +209,11 @@ static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
  *		  requested number of buffers and to fill in plane sizes
  *		  for the current frame format if required
  */
-static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
-			const struct v4l2_format *fmt,
+static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq, const void *parg,
 			unsigned int *count, unsigned int *num_planes,
 			unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct soc_camera_device *icd = container_of(vq, 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;
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index 19fea47..6934a95 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1797,8 +1797,7 @@ static const struct v4l2_ioctl_ops vpe_ioctl_ops = {
 /*
  * Queue operations
  */
-static int vpe_queue_setup(struct vb2_queue *vq,
-			   const struct v4l2_format *fmt,
+static int vpe_queue_setup(struct vb2_queue *vq, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
index 267525a..7664319 100644
--- a/drivers/media/platform/vim2m.c
+++ b/drivers/media/platform/vim2m.c
@@ -709,8 +709,7 @@ static const struct v4l2_ioctl_ops vim2m_ioctl_ops = {
  * Queue operations
  */
 
-static int vim2m_queue_setup(struct vb2_queue *vq,
-				const struct v4l2_format *fmt,
+static int vim2m_queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.c b/drivers/media/platform/vivid/vivid-sdr-cap.c
index 2b46175..cf7f56c 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
@@ -210,7 +210,7 @@ static int vivid_thread_sdr_cap(void *data)
 	return 0;
 }
 
-static int sdr_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int sdr_cap_queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned *nbuffers, unsigned *nplanes,
 		       unsigned sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/vivid/vivid-vbi-cap.c b/drivers/media/platform/vivid/vivid-vbi-cap.c
index 0ea990b..26837e4 100644
--- a/drivers/media/platform/vivid/vivid-vbi-cap.c
+++ b/drivers/media/platform/vivid/vivid-vbi-cap.c
@@ -136,7 +136,7 @@ void vivid_sliced_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *bu
 	buf->vb.v4l2_buf.timestamp.tv_sec += dev->time_wrap_offset;
 }
 
-static int vbi_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int vbi_cap_queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned *nbuffers, unsigned *nplanes,
 		       unsigned sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/vivid/vivid-vbi-out.c b/drivers/media/platform/vivid/vivid-vbi-out.c
index 65097c6..a51fc70 100644
--- a/drivers/media/platform/vivid/vivid-vbi-out.c
+++ b/drivers/media/platform/vivid/vivid-vbi-out.c
@@ -27,7 +27,7 @@
 #include "vivid-vbi-out.h"
 #include "vivid-vbi-cap.h"
 
-static int vbi_out_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int vbi_out_queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned *nbuffers, unsigned *nplanes,
 		       unsigned sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index 1828a27..3ffa410 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -95,10 +95,11 @@ static const struct v4l2_discrete_probe webcam_probe = {
 	VIVID_WEBCAM_SIZES
 };
 
-static int vid_cap_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int vid_cap_queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned *nbuffers, unsigned *nplanes,
 		       unsigned sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
 	unsigned buffers = tpg_g_buffers(&dev->tpg);
 	unsigned h = dev->fmt_cap_rect.height;
diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index de7a076..9d3055c 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -31,10 +31,11 @@
 #include "vivid-kthread-out.h"
 #include "vivid-vid-out.h"
 
-static int vid_out_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int vid_out_queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned *nbuffers, unsigned *nplanes,
 		       unsigned sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct vivid_dev *dev = vb2_get_drv_priv(vq);
 	const struct vivid_fmt *vfmt = dev->fmt_out;
 	unsigned planes = vfmt->buffers;
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 389fb0b..ee47aaf 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -788,10 +788,11 @@ void vsp1_pipelines_resume(struct vsp1_device *vsp1)
  */
 
 static int
-vsp1_video_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+vsp1_video_queue_setup(struct vb2_queue *vq, const void *parg,
 		     unsigned int *nbuffers, unsigned int *nplanes,
 		     unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct vsp1_video *video = vb2_get_drv_priv(vq);
 	const struct v4l2_pix_format_mplane *format;
 	struct v4l2_pix_format_mplane pix_mp;
diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c
index 253884a..826687b 100644
--- a/drivers/media/usb/airspy/airspy.c
+++ b/drivers/media/usb/airspy/airspy.c
@@ -486,7 +486,7 @@ static void airspy_disconnect(struct usb_interface *intf)
 
 /* Videobuf2 operations */
 static int airspy_queue_setup(struct vb2_queue *vq,
-		const struct v4l2_format *fmt, unsigned int *nbuffers,
+		const void *parg, unsigned int *nbuffers,
 		unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
 {
 	struct airspy *s = vb2_get_drv_priv(vq);
diff --git a/drivers/media/usb/au0828/au0828-vbi.c b/drivers/media/usb/au0828/au0828-vbi.c
index 5fbf279..c207c03 100644
--- a/drivers/media/usb/au0828/au0828-vbi.c
+++ b/drivers/media/usb/au0828/au0828-vbi.c
@@ -30,10 +30,11 @@
 
 /* ------------------------------------------------------------------ */
 
-static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int vbi_queue_setup(struct vb2_queue *vq, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct au0828_dev *dev = vb2_get_drv_priv(vq);
 	unsigned long img_size = dev->vbi_width * dev->vbi_height * 2;
 	unsigned long size;
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 28e374e..c73c627 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -638,10 +638,11 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
 	return rc;
 }
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned int *nbuffers, unsigned int *nplanes,
 		       unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct au0828_dev *dev = vb2_get_drv_priv(vq);
 	unsigned long img_size = dev->height * dev->bytesperline;
 	unsigned long size;
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index 270aa47..073ee00 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -29,6 +29,7 @@
 /* Analog */
 #include <linux/videodev2.h>
 #include <media/videobuf2-vmalloc.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
diff --git a/drivers/media/usb/em28xx/em28xx-vbi.c b/drivers/media/usb/em28xx/em28xx-vbi.c
index 50b33c9..4007b44 100644
--- a/drivers/media/usb/em28xx/em28xx-vbi.c
+++ b/drivers/media/usb/em28xx/em28xx-vbi.c
@@ -31,10 +31,11 @@
 
 /* ------------------------------------------------------------------ */
 
-static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int vbi_queue_setup(struct vb2_queue *vq, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct em28xx *dev = vb2_get_drv_priv(vq);
 	struct em28xx_v4l2 *v4l2 = dev->v4l2;
 	unsigned long size;
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index bbccaed..b34ff421 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -871,10 +871,11 @@ static void res_free(struct em28xx *dev, enum v4l2_buf_type f_type)
 	Videobuf2 operations
    ------------------------------------------------------------------*/
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned int *nbuffers, unsigned int *nplanes,
 		       unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct em28xx *dev = vb2_get_drv_priv(vq);
 	struct em28xx_v4l2 *v4l2 = dev->v4l2;
 	unsigned long size;
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index e8512c4..76bf8ba 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -35,6 +35,7 @@
 #include <linux/kref.h>
 #include <linux/videodev2.h>
 
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-vmalloc.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ctrls.h>
diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c
index 3d4e5db..8183a1d 100644
--- a/drivers/media/usb/go7007/go7007-v4l2.c
+++ b/drivers/media/usb/go7007/go7007-v4l2.c
@@ -368,8 +368,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
 	return set_capture_size(go, fmt, 0);
 }
 
-static int go7007_queue_setup(struct vb2_queue *q,
-		const struct v4l2_format *fmt,
+static int go7007_queue_setup(struct vb2_queue *q, const void *parg,
 		unsigned int *num_buffers, unsigned int *num_planes,
 		unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c
index 935b920..c07b44f 100644
--- a/drivers/media/usb/hackrf/hackrf.c
+++ b/drivers/media/usb/hackrf/hackrf.c
@@ -464,7 +464,7 @@ static void hackrf_disconnect(struct usb_interface *intf)
 
 /* Videobuf2 operations */
 static int hackrf_queue_setup(struct vb2_queue *vq,
-		const struct v4l2_format *fmt, unsigned int *nbuffers,
+		const void *parg, unsigned int *nbuffers,
 		unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
 {
 	struct hackrf_dev *dev = vb2_get_drv_priv(vq);
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index 77cfb7d..af4dd23 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -613,8 +613,7 @@ static int msi2500_querycap(struct file *file, void *fh,
 }
 
 /* Videobuf2 operations */
-static int msi2500_queue_setup(struct vb2_queue *vq,
-			       const struct v4l2_format *fmt,
+static int msi2500_queue_setup(struct vb2_queue *vq, const void *parg,
 			       unsigned int *nbuffers,
 			       unsigned int *nplanes, unsigned int sizes[],
 			       void *alloc_ctxs[])
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 2fc3c0f..79e4ca2 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -572,7 +572,7 @@ static void pwc_video_release(struct v4l2_device *v)
 /***************************************************************************/
 /* Videobuf2 operations */
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/usb/pwc/pwc.h b/drivers/media/usb/pwc/pwc.h
index e2c12dc..e0d9125 100644
--- a/drivers/media/usb/pwc/pwc.h
+++ b/drivers/media/usb/pwc/pwc.h
@@ -40,6 +40,7 @@
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-event.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-vmalloc.h>
 #ifdef CONFIG_USB_PWC_INPUT_EVDEV
 #include <linux/input.h>
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 4284e56..0d909a4 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -45,6 +45,7 @@
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
 #include <linux/usb.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-vmalloc.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-device.h>
@@ -660,7 +661,7 @@ static void s2255_fillbuff(struct s2255_vc *vc,
    Videobuf operations
    ------------------------------------------------------------------*/
 
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 		       unsigned int *nbuffers, unsigned int *nplanes,
 		       unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index 6e23b2b..a7daa08 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -664,7 +664,7 @@ static const struct v4l2_ioctl_ops stk1160_ioctl_ops = {
 /*
  * Videobuf2 operations
  */
-static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *v4l_fmt,
+static int queue_setup(struct vb2_queue *vq, const void *parg,
 				unsigned int *nbuffers, unsigned int *nplanes,
 				unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c
index 2f8674d..3e17802 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -599,9 +599,10 @@ static struct v4l2_file_operations usbtv_fops = {
 };
 
 static int usbtv_queue_setup(struct vb2_queue *vq,
-	const struct v4l2_format *fmt, unsigned int *nbuffers,
+	const void *varg, unsigned int *nbuffers,
 	unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
 {
+	const struct v4l2_format *fmt = (const struct v4l2_format *)varg;
 	struct usbtv *usbtv = vb2_get_drv_priv(vq);
 	unsigned size = USBTV_CHUNK * usbtv->n_chunks * 2 * sizeof(u32);
 
diff --git a/drivers/media/usb/usbtv/usbtv.h b/drivers/media/usb/usbtv/usbtv.h
index a1a4d95..19cb8bf 100644
--- a/drivers/media/usb/usbtv/usbtv.h
+++ b/drivers/media/usb/usbtv/usbtv.h
@@ -24,6 +24,7 @@
 #include <linux/usb.h>
 
 #include <media/v4l2-device.h>
+#include <media/videobuf2-v4l2.h>
 #include <media/videobuf2-vmalloc.h>
 
 /* Hardware. */
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 2db04b2..2905123 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -68,10 +68,11 @@ static void uvc_queue_return_buffers(struct uvc_video_queue *queue,
  * videobuf2 queue operations
  */
 
-static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int uvc_queue_setup(struct vb2_queue *vq, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
+	struct v4l2_format *fmt = (struct v4l2_format *)parg;
 	struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
 	struct uvc_streaming *stream = uvc_queue_to_stream(queue);
 
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 16865b8..c54dd26 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -30,7 +30,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/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
new file mode 100644
index 0000000..0460a99
--- /dev/null
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -0,0 +1,1797 @@
+/*
+ * videobuf2-core.c - Video Buffer 2 Core Framework
+ *
+ * Copyright (C) 2010 Samsung Electronics
+ *
+ * Author: Pawel Osciak <pawel@osciak.com>
+ *	   Marek Szyprowski <m.szyprowski@samsung.com>
+ *
+ * The vb2_thread implementation was based on code from videobuf-dvb.c:
+ *	(c) 2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/poll.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include <linux/freezer.h>
+#include <linux/kthread.h>
+
+#include <media/videobuf2-core.h>
+
+#include <trace/events/v4l2.h>
+
+int vb2_debug;
+module_param_named(debug, vb2_debug, int, 0644);
+
+static void __enqueue_in_driver(struct vb2_buffer *vb);
+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)
+{
+	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;
+		call_bufop(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;
+		VB2_DEBUG(3, "freed plane %d of buffer %d\n", plane,
+			vb2_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_bufop(q, set_plane_length, vb, plane,
+					q->plane_sizes[plane]);
+	}
+}
+
+/**
+ * __setup_offsets() - setup unique offsets ("cookies") for every plane in
+ * every buffer on the queue
+ */
+static void __setup_offsets(struct vb2_queue *q, unsigned int n)
+{
+	unsigned int buffer, plane;
+	struct vb2_buffer *vb;
+	unsigned long off;
+
+	if (q->num_buffers) {
+		vb = q->bufs[q->num_buffers - 1];
+		off = call_u32_bufop(q, get_plane_offset, vb, vb->num_planes - 1);
+		off += call_u32_bufop(q, get_plane_length, vb, vb->num_planes - 1);
+		off = PAGE_ALIGN(off);
+	} else {
+		off = 0;
+	}
+
+	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_bufop(q, set_plane_offset, vb, plane, off);
+
+			VB2_DEBUG(3, "buffer %d, plane %d offset 0x%08lx\n",
+					buffer, plane, off);
+
+			off += call_u32_bufop(q, get_plane_length, vb, plane);
+			off = PAGE_ALIGN(off);
+		}
+	}
+}
+
+/**
+ * __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, unsigned int 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) {
+			VB2_DEBUG(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_bufop(q, init_buffer, vb, memory, q->type,
+				q->num_buffers + buffer, num_planes);
+
+		/* Allocate video buffer memory for the MMAP type */
+		if (memory == V4L2_MEMORY_MMAP) {
+			ret = __vb2_buf_mem_alloc(vb);
+			if (ret) {
+				VB2_DEBUG(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) {
+				VB2_DEBUG(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 == V4L2_MEMORY_MMAP)
+		__setup_offsets(q, buffer);
+
+	VB2_DEBUG(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 == V4L2_MEMORY_MMAP)
+			__vb2_buf_mem_free(vb);
+		else if (q->memory == V4L2_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.
+ */
+static 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) {
+			VB2_DEBUG(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 || 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 || 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 v4l2_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) {
+		VB2_DEBUG(1, "wrong buffer type\n");
+		return -EINVAL;
+	}
+
+	if (index >= q->num_buffers) {
+		VB2_DEBUG(1, "buffer index out of range\n");
+		return -EINVAL;
+	}
+	vb = q->bufs[index];
+	ret = call_bufop(q, verify_planes, vb, pb);
+	if (!ret)
+		ret = call_bufop(q, fill_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,
+		unsigned int memory, enum v4l2_buf_type type)
+{
+	if (memory != V4L2_MEMORY_MMAP && memory != V4L2_MEMORY_USERPTR &&
+	    memory != V4L2_MEMORY_DMABUF) {
+		VB2_DEBUG(1, "unsupported memory type\n");
+		return -EINVAL;
+	}
+
+	if (type != q->type) {
+		VB2_DEBUG(1, "requested type is incorrect\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Make sure all the required memory ops for given memory type
+	 * are available.
+	 */
+	if (memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
+		VB2_DEBUG(1, "MMAP for current setup unsupported\n");
+		return -EINVAL;
+	}
+
+	if (memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
+		VB2_DEBUG(1, "USERPTR for current setup unsupported\n");
+		return -EINVAL;
+	}
+
+	if (memory == V4L2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) {
+		VB2_DEBUG(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)) {
+		VB2_DEBUG(1, "file io in progress\n");
+		return -EBUSY;
+	}
+	return 0;
+}
+
+
+/**
+ * vb2_core_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 vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *count)
+{
+	unsigned int num_buffers, allocated_buffers, num_planes = 0;
+	int ret;
+
+	if (q->streaming) {
+		VB2_DEBUG(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 == V4L2_MEMORY_MMAP && __buffers_in_use(q)) {
+			mutex_unlock(&q->mmap_lock);
+			VB2_DEBUG(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, 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 = 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) {
+		VB2_DEBUG(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);
+
+	/*
+	 * Return the number of successfully allocated buffers
+	 * to the userspace.
+	 */
+	*count = allocated_buffers;
+	q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
+
+	return 0;
+}
+
+/**
+ * vb2_core_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 vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
+		unsigned int *count, void *parg)
+{
+	unsigned int num_planes = 0, num_buffers, allocated_buffers;
+	int ret;
+
+	if (q->num_buffers == VIDEO_MAX_FRAME) {
+		VB2_DEBUG(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 = !V4L2_TYPE_IS_OUTPUT(q->type);
+	}
+
+	num_buffers = min(*count, VIDEO_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, parg, &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) {
+		VB2_DEBUG(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, parg, &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.
+	 */
+	*count = allocated_buffers;
+
+	return 0;
+}
+
+/**
+ * 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
+ *
+ * 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)
+{
+	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_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_buffer *vb, unsigned int plane_no)
+{
+	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_buffer returned from the driver
+ * @state:	either VB2_BUF_STATE_DONE if the operation finished successfully,
+ *		VB2_BUF_STATE_ERROR if the operation finished with an error or
+ *		VB2_BUF_STATE_QUEUED if the driver wants to requeue buffers.
+ *		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
+	VB2_DEBUG(4, "done processing on buffer %d, state: %d\n",
+			vb2_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);
+
+	trace_vb2_buf_done(q, vb);
+
+	if (state == VB2_BUF_STATE_QUEUED) {
+		if (q->start_streaming_called)
+			__enqueue_in_driver(vb);
+		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);
+
+	trace_vb2_buf_queue(q, vb);
+
+	/* 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 vb2_queue_or_prepare_buf(struct vb2_queue *q, unsigned int memory,
+		unsigned int type, unsigned int index, void *pb,
+		const char *opname)
+{
+	if (type != q->type) {
+		VB2_DEBUG(1, "%s: invalid buffer type\n", opname);
+		return -EINVAL;
+	}
+
+	if (index >= q->num_buffers) {
+		VB2_DEBUG(1, "%s: buffer index out of range\n", opname);
+		return -EINVAL;
+	}
+
+	if (q->bufs[index] == NULL) {
+		/* Should never happen */
+		VB2_DEBUG(1, "%s: buffer is NULL\n", opname);
+		return -EINVAL;
+	}
+
+	if (memory != q->memory) {
+		VB2_DEBUG(1, "%s: invalid memory type\n", opname);
+		return -EINVAL;
+	}
+
+	return call_bufop(q, verify_planes, q->bufs[index], pb);
+}
+
+/**
+ * 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, unsigned int memory,
+		unsigned int type, unsigned int index, void *pb)
+{
+	struct vb2_buffer *vb;
+	int ret;
+
+	if (vb2_fileio_is_active(q)) {
+		VB2_DEBUG(1, "file io in progress\n");
+		return -EBUSY;
+	}
+
+	ret = vb2_queue_or_prepare_buf(q, memory, type, index, pb,
+			"prepare_buf");
+	if (ret)
+		return ret;
+
+	vb = q->bufs[index];
+	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
+		VB2_DEBUG(1, "invalid buffer state %d\n",
+			vb->state);
+		return -EINVAL;
+	}
+
+	ret = call_bufop(q, prepare_buffer, vb, pb);
+	if (!ret) {
+		/* Fill buffer information for the userspace */
+		call_bufop(q, fill_buffer, vb, pb);
+		VB2_DEBUG(1, "prepare of buffer %d succeeded\n",
+			vb2_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;
+
+	VB2_DEBUG(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_core_qbuf(struct vb2_queue *q, unsigned int memory,
+		unsigned int type, unsigned int index, void *pb)
+{
+	int ret = vb2_queue_or_prepare_buf(q, memory, type, index, pb, "qbuf");
+	struct vb2_buffer *vb;
+
+	if (ret)
+		return ret;
+
+	vb = q->bufs[index];
+
+	switch (vb->state) {
+	case VB2_BUF_STATE_DEQUEUED:
+		ret = call_bufop(q, prepare_buffer, vb, pb);
+		if (ret)
+			return ret;
+		break;
+	case VB2_BUF_STATE_PREPARED:
+		break;
+	case VB2_BUF_STATE_PREPARING:
+		VB2_DEBUG(1, "buffer still being prepared\n");
+		return -EINVAL;
+	default:
+		VB2_DEBUG(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_bufop(q, set_timestamp, vb, pb);
+	}
+
+	trace_vb2_qbuf(q, vb);
+
+	/*
+	 * 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_bufop(q, fill_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;
+	}
+
+	VB2_DEBUG(1, "qbuf of buffer %d succeeded\n", vb2_index(vb));
+	return 0;
+}
+
+/**
+ * __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) {
+			VB2_DEBUG(1, "streaming off, will not wait for buffers\n");
+			return -EINVAL;
+		}
+
+		if (q->error) {
+			VB2_DEBUG(1, "Queue in error state, will not wait for buffers\n");
+			return -EIO;
+		}
+
+		if (q->last_buffer_dequeued) {
+			VB2_DEBUG(3, "last buffer dequeued already, will not wait for buffers\n");
+			return -EPIPE;
+		}
+
+		if (!list_empty(&q->done_list)) {
+			/*
+			 * Found a buffer that we were waiting for.
+			 */
+			break;
+		}
+
+		if (nonblocking) {
+			VB2_DEBUG(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.
+		 */
+		VB2_DEBUG(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) {
+			VB2_DEBUG(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_bufop(q, verify_planes, *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) {
+		VB2_DEBUG(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 == 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;
+		}
+}
+
+int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb,
+		bool nonblocking)
+{
+	struct vb2_buffer *vb = NULL;
+	int ret;
+
+	if (type != q->type) {
+		VB2_DEBUG(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:
+		VB2_DEBUG(3, "returning done buffer\n");
+		break;
+	case VB2_BUF_STATE_ERROR:
+		VB2_DEBUG(3, "returning done buffer with errors\n");
+		break;
+	default:
+		VB2_DEBUG(1, "invalid buffer state\n");
+		return -EINVAL;
+	}
+
+	call_void_vb_qop(vb, buf_finish, vb);
+
+	/* Fill buffer information for the userspace */
+	call_bufop(q, fill_buffer, vb, pb);
+	/* Remove from videobuf queue */
+	list_del(&vb->queued_entry);
+	q->queued_count--;
+
+	trace_vb2_dqbuf(q, vb);
+
+	if (!V4L2_TYPE_IS_OUTPUT(q->type) && call_bufop(q, is_last, vb))
+		q->last_buffer_dequeued = true;
+	/* go back to dequeued state */
+	__vb2_dqbuf(vb);
+
+	VB2_DEBUG(1, "dqbuf of buffer %d, with state %d\n",
+			vb2_index(vb), vb->state);
+
+	return 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)
+{
+	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_core_streamon(struct vb2_queue *q, unsigned int type)
+{
+	int ret;
+
+	if (type != q->type) {
+		VB2_DEBUG(1, "invalid stream type\n");
+		return -EINVAL;
+	}
+
+	if (q->streaming) {
+		VB2_DEBUG(3, "already streaming\n");
+		return 0;
+	}
+
+	if (!q->num_buffers) {
+		VB2_DEBUG(1, "no buffers have been allocated\n");
+		return -EINVAL;
+	}
+
+	if (q->num_buffers < q->min_buffers_needed) {
+		VB2_DEBUG(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;
+
+	VB2_DEBUG(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);
+
+int vb2_core_streamoff(struct vb2_queue *q, unsigned int type)
+{
+	if (type != q->type) {
+		VB2_DEBUG(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);
+	q->last_buffer_dequeued = false;
+
+	VB2_DEBUG(3, "successful\n");
+	return 0;
+}
+
+/**
+ * __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)
+{
+	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];
+
+		for (plane = 0; plane < vb->num_planes; ++plane) {
+			if (call_bufop(q, get_plane_offset, vb, plane) == off) {
+				*_buffer = buffer;
+				*_plane = plane;
+				return 0;
+			}
+		}
+	}
+
+	return -EINVAL;
+}
+
+/**
+ * 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 != V4L2_MEMORY_MMAP) {
+		VB2_DEBUG(1, "queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	if (!q->mem_ops->get_dmabuf) {
+		VB2_DEBUG(1, "queue does not support DMA buffer exporting\n");
+		return -EINVAL;
+	}
+
+	if (flags & ~(O_CLOEXEC | O_ACCMODE)) {
+		VB2_DEBUG(1, "queue does support only O_CLOEXEC and access mode flags\n");
+		return -EINVAL;
+	}
+
+	if (type != q->type) {
+		VB2_DEBUG(1, "invalid buffer type\n");
+		return -EINVAL;
+	}
+
+	if (index >= q->num_buffers) {
+		VB2_DEBUG(1, "buffer index out of range\n");
+		return -EINVAL;
+	}
+
+	vb = q->bufs[index];
+
+	if (plane >= vb->num_planes) {
+		VB2_DEBUG(1, "buffer plane out of range\n");
+		return -EINVAL;
+	}
+
+	if (vb2_fileio_is_active(q)) {
+		VB2_DEBUG(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)) {
+		VB2_DEBUG(1, "failed to export buffer %d, plane %d\n", index, plane);
+		return -EINVAL;
+	}
+
+	ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE);
+	if (ret < 0) {
+		VB2_DEBUG(3, "buffer %d, plane %d failed to export (%d)\n",
+			index, plane, ret);
+		dma_buf_put(dbuf);
+		return ret;
+	}
+
+	VB2_DEBUG(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 != V4L2_MEMORY_MMAP) {
+		VB2_DEBUG(1, "queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Check memory area access mode.
+	 */
+	if (!(vma->vm_flags & VM_SHARED)) {
+		VB2_DEBUG(1, "invalid vma flags, VM_SHARED needed\n");
+		return -EINVAL;
+	}
+	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+		if (!(vma->vm_flags & VM_WRITE)) {
+			VB2_DEBUG(1, "invalid vma flags, VM_WRITE needed\n");
+			return -EINVAL;
+		}
+	} else {
+		if (!(vma->vm_flags & VM_READ)) {
+			VB2_DEBUG(1, "invalid vma flags, VM_READ needed\n");
+			return -EINVAL;
+		}
+	}
+	if (vb2_fileio_is_active(q)) {
+		VB2_DEBUG(1, "mmap: file io in progress\n");
+		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;
+
+	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 = PAGE_ALIGN(call_u32_bufop(q, get_plane_length, vb, plane));
+	if (length < (vma->vm_end - vma->vm_start)) {
+		VB2_DEBUG(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;
+
+	VB2_DEBUG(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 != V4L2_MEMORY_MMAP) {
+		VB2_DEBUG(1, "queue is not currently set up for mmap\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * 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];
+
+	vaddr = vb2_plane_vaddr(vb, plane);
+	return vaddr ? (unsigned long)vaddr : -EINVAL;
+}
+EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
+#endif
+
+/**
+ * vb2_core_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_core_queue_init(struct vb2_queue *q)
+{
+	/*
+	 * 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))
+		return -EINVAL;
+
+	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 0;
+}
+
+/**
+ * vb2_core_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_core_queue_release(struct vb2_queue *q)
+{
+	__vb2_queue_cancel(q);
+	mutex_lock(&q->mmap_lock);
+	__vb2_queue_free(q, q->num_buffers);
+	mutex_unlock(&q->mmap_lock);
+}
+
+MODULE_DESCRIPTION("Driver helper framework for Video for Linux 2");
+MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>, Marek Szyprowski");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 437b769..94c1e64 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-v4l2.h>
+#include <media/videobuf2-core.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 eb90188..7289b81 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-v4l2.h>
+#include <media/videobuf2-core.h>
 #include <media/videobuf2-memops.h>
 #include <media/videobuf2-dma-sg.h>
 
diff --git a/drivers/media/v4l2-core/videobuf2-memops.c b/drivers/media/v4l2-core/videobuf2-memops.c
index e5da47a..81c1ad8 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-v4l2.h>
+#include <media/videobuf2-core.h>
 #include <media/videobuf2-memops.h>
 
 /**
diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 7956776..85527e9 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -32,148 +32,6 @@
 
 #include <trace/events/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); \
-	} 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, vb2_v4l2_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, vb2_v4l2_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
-
 /* Flags that are set by the vb2 core */
 #define V4L2_BUFFER_MASK_FLAGS	(V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
 				 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
@@ -183,399 +41,82 @@ 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);
-static void __enqueue_in_driver(struct vb2_buffer *vb);
-
-/**
- * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
- */
-static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
+static int v4l2_init_buffer(struct vb2_buffer *vb,
+		unsigned int memory, unsigned int type, unsigned int index,
+		unsigned int planes)
 {
-	struct vb2_queue *q = vb->vb2_queue;
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
-	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;
+	/* Length stores number of planes for multiplanar buffers */
+	if (V4L2_TYPE_IS_MULTIPLANAR(type))
+		vbuf->v4l2_buf.length = planes;
 
-		/* Associate allocator private data with this plane */
-		vb->planes[plane].mem_priv = mem_priv;
-		vbuf->v4l2_planes[plane].length = q->plane_sizes[plane];
-	}
+	vbuf->v4l2_buf.index = index;
+	vbuf->v4l2_buf.type = type;
+	vbuf->v4l2_buf.memory = memory;
 
 	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,
-			vb2_v4l2_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
- */
-static 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
- */
-static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
+static unsigned int v4l2_get_index(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;
-	struct vb2_v4l2_buffer *vbuf;
-
-	for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
-		vb = q->bufs[buffer];
-		if (!vb)
-			continue;
-		vbuf = to_vb2_v4l2_buffer(vb);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-		for (plane = 0; plane < vb->num_planes; ++plane)
-			vbuf->v4l2_planes[plane].length = q->plane_sizes[plane];
-	}
+	return (vbuf->v4l2_buf.index);
 }
 
-/**
- * __setup_offsets() - setup unique offsets ("cookies") for every plane in
- * every buffer on the queue
- */
-static void __setup_offsets(struct vb2_queue *q, unsigned int n)
+static int v4l2_set_plane_length(struct vb2_buffer *vb, int plane,
+				unsigned int length)
 {
-	unsigned int buffer, plane;
-	struct vb2_buffer *vb;
-	struct vb2_v4l2_buffer *vbuf;
-	unsigned long off;
-
-	if (q->num_buffers) {
-		struct v4l2_plane *p;
-		vb = q->bufs[q->num_buffers - 1];
-		vbuf = to_vb2_v4l2_buffer(vb);
-		p = &vbuf->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;
-		vbuf = to_vb2_v4l2_buffer(vb);
-
-		for (plane = 0; plane < vb->num_planes; ++plane) {
-			vbuf->v4l2_planes[plane].m.mem_offset = off;
-
-			dprintk(3, "buffer %d, plane %d offset 0x%08lx\n",
-					buffer, plane, off);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-			off += vbuf->v4l2_planes[plane].length;
-			off = PAGE_ALIGN(off);
-		}
-	}
+	vbuf->v4l2_planes[plane].length = length;
+	return 0;
 }
 
-/**
- * __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 v4l2_memory memory,
-			     unsigned int num_buffers, unsigned int num_planes)
+static unsigned int v4l2_get_plane_length(struct vb2_buffer *vb, int plane)
 {
-	unsigned int buffer;
-	struct vb2_buffer *vb;
-	struct vb2_v4l2_buffer *vbuf;
-	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;
-		}
-
-		vbuf = to_vb2_v4l2_buffer(vb);
-
-		/* Length stores number of planes for multiplanar buffers */
-		if (V4L2_TYPE_IS_MULTIPLANAR(q->type))
-			vbuf->v4l2_buf.length = num_planes;
-
-		vb->state = VB2_BUF_STATE_DEQUEUED;
-		vb->vb2_queue = q;
-		vb->num_planes = num_planes;
-		vbuf->v4l2_buf.index = q->num_buffers + buffer;
-		vbuf->v4l2_buf.type = q->type;
-		vbuf->v4l2_buf.memory = memory;
-
-		/* Allocate video buffer memory for the MMAP type */
-		if (memory == V4L2_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 == V4L2_MEMORY_MMAP)
-		__setup_offsets(q, buffer);
-
-	dprintk(1, "allocated %d buffers, %d plane(s) each\n",
-			buffer, num_planes);
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-	return buffer;
+	return (vbuf->v4l2_planes[plane].length);
 }
 
-/**
- * __vb2_free_mem() - release all video buffer memory for a given queue
- */
-static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
+static int v4l2_set_plane_offset(struct vb2_buffer *vb, int plane,
+				unsigned int offset)
 {
-	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;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-		/* Free MMAP buffers or release USERPTR buffers */
-		if (q->memory == V4L2_MEMORY_MMAP)
-			__vb2_buf_mem_free(vb);
-		else if (q->memory == V4L2_MEMORY_DMABUF)
-			__vb2_buf_dmabuf_put(vb);
-		else
-			__vb2_buf_userptr_put(vb);
-	}
+	vbuf->v4l2_planes[plane].m.mem_offset = offset;
+	return 0;
 }
 
-/**
- * __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.
- */
-static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
+static unsigned int v4l2_get_plane_offset(struct vb2_buffer *vb, int plane)
 {
-	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 || 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 || 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;
-	}
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-	q->num_buffers -= buffers;
-	if (!q->num_buffers) {
-		q->memory = 0;
-		INIT_LIST_HEAD(&q->queued_list);
-	}
-	return 0;
+	return (vbuf->v4l2_planes[plane].m.mem_offset);
 }
 
 /**
- * __verify_planes_array() - verify that the planes array passed in struct
+ * v4l2_verify_planes() - 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 v4l2_verify_planes(struct vb2_buffer *vb, void *pb)
 {
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+
 	if (!V4L2_TYPE_IS_MULTIPLANAR(b->type))
 		return 0;
 
 	/* Is memory for copying plane information present? */
 	if (NULL == b->m.planes) {
-		dprintk(1, "multi-planar buffer passed but "
+		VB2_DEBUG(1, "multi-planar buffer passed but "
 			   "planes array not provided\n");
 		return -EINVAL;
 	}
 
 	if (b->length < vb->num_planes || b->length > VIDEO_MAX_PLANES) {
-		dprintk(1, "incorrect planes array length, "
+		VB2_DEBUG(1, "incorrect planes array length, "
 			   "expected %d, got %d\n", vb->num_planes, b->length);
 		return -EINVAL;
 	}
@@ -584,88 +125,12 @@ 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)
-{
-	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
-	unsigned int length;
-	unsigned int bytesused;
-	unsigned int plane;
-
-	if (!V4L2_TYPE_IS_OUTPUT(b->type))
-		return 0;
-
-	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
-			       : vbuf->v4l2_planes[plane].length;
-			bytesused = b->m.planes[plane].bytesused
-				  ? b->m.planes[plane].bytesused : length;
-
-			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 : vbuf->v4l2_planes[0].length;
-		bytesused = b->bytesused ? b->bytesused : length;
-
-		if (b->bytesused > length)
-			return -EINVAL;
-	}
-
-	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
- */
-static 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;
-}
-
-/**
- * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be
+ * v4l2_fill_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 int v4l2_fill_buffer(struct vb2_buffer *vb, void *pb)
 {
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
 	struct vb2_queue *q = vb->vb2_queue;
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
@@ -734,530 +199,11 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
 
 	if (__buffer_in_use(q, vb))
 		b->flags |= V4L2_BUF_FLAG_MAPPED;
-}
-
-/**
- * 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_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];
-	ret = __verify_planes_array(vb, b);
-	if (!ret)
-		__fill_v4l2_buffer(vb, 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;
-	}
-
-	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 == 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;
-	}
-
-	/*
-	 * 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.
- */
-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;
-	}
-
-	/*
-	 * 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.
-	 */
-	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;
-	}
-
-	/*
-	 * 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);
-
-	/*
-	 * Return the number of successfully allocated buffers
-	 * to the userspace.
-	 */
-	req->count = allocated_buffers;
-	q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
-
-	return 0;
-}
-
-/**
- * vb2_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_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
-{
-	int ret = __verify_memory_type(q, req->memory, req->type);
-
-	return ret ? ret : __reqbufs(q, req);
-}
-EXPORT_SYMBOL_GPL(vb2_reqbufs);
-
-/**
- * __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.
- */
-static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
-{
-	unsigned int num_planes = 0, num_buffers, allocated_buffers;
-	int ret;
-
-	if (q->num_buffers == VIDEO_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 = create->memory;
-		q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
-	}
-
-	num_buffers = min(create->count, VIDEO_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, &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;
-	}
-
-	/*
-	 * 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, &create->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.
-	 */
-	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_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)
-{
-	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_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_buffer *vb, unsigned int plane_no)
-{
-	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_buffer returned from the driver
- * @state:	either VB2_BUF_STATE_DONE if the operation finished successfully,
- *		VB2_BUF_STATE_ERROR if the operation finished with an error or
- *		VB2_BUF_STATE_QUEUED if the driver wants to requeue buffers.
- *		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",
-			vb2_v4l2_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);
-
-	trace_vb2_buf_done(q, vb);
-
-	if (state == VB2_BUF_STATE_QUEUED) {
-		if (q->start_streaming_called)
-			__enqueue_in_driver(vb);
-		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);
-
-static void vb2_warn_zero_bytesused(struct vb2_buffer *vb)
+static void __warn_zero_bytesused(struct vb2_buffer *vb)
 {
 	static bool __check_once __read_mostly;
 
@@ -1275,15 +221,17 @@ static void vb2_warn_zero_bytesused(struct vb2_buffer *vb)
 }
 
 /**
- * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a
+ * v4l2_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 void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b,
-				struct v4l2_plane *v4l2_planes)
+static int v4l2_fill_vb2_buffer(struct vb2_buffer *vb,
+		const void *pb, void *planes)
 {
-	unsigned int plane;
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct v4l2_plane *v4l2_planes = (struct v4l2_plane *)planes;
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	unsigned int plane;
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) {
 		if (b->memory == V4L2_MEMORY_USERPTR) {
@@ -1326,7 +274,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 				struct v4l2_plane *psrc = &b->m.planes[plane];
 
 				if (psrc->bytesused == 0)
-					vb2_warn_zero_bytesused(vb);
+					__warn_zero_bytesused(vb);
 
 				if (vb->vb2_queue->allow_zero_bytesused)
 					pdst->bytesused = psrc->bytesused;
@@ -1363,7 +311,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 
 		if (V4L2_TYPE_IS_OUTPUT(b->type)) {
 			if (b->bytesused == 0)
-				vb2_warn_zero_bytesused(vb);
+				__warn_zero_bytesused(vb);
 
 			if (vb->vb2_queue->allow_zero_bytesused)
 				v4l2_planes[0].bytesused = b->bytesused;
@@ -1387,19 +335,64 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
 		vbuf->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.
-		 */
-		vbuf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
-		vbuf->v4l2_buf.field = b->field;
+	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.
+		 */
+		vbuf->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE;
+		vbuf->v4l2_buf.field = b->field;
+	} else {
+		/* Zero any output buffer flags as this is a capture buffer */
+		vbuf->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
+	}
+
+	return 0;
+}
+
+/**
+ * __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, void *pb)
+{
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	unsigned int length;
+	unsigned int bytesused;
+	unsigned int plane;
+
+	if (!V4L2_TYPE_IS_OUTPUT(b->type))
+		return 0;
+
+	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
+			       : vbuf->v4l2_planes[plane].length;
+			bytesused = b->m.planes[plane].bytesused
+				  ? b->m.planes[plane].bytesused : length;
+
+			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 {
-		/* Zero any output buffer flags as this is a capture buffer */
-		vbuf->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS;
+		length = (b->memory == V4L2_MEMORY_USERPTR)
+		       ? b->length : vbuf->v4l2_planes[0].length;
+		bytesused = b->bytesused ? b->bytesused : length;
+
+		if (b->bytesused > length)
+			return -EINVAL;
 	}
+
+	return 0;
 }
 
 /**
@@ -1409,7 +402,7 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 {
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-	__fill_vb2_buffer(vb, b, vbuf->v4l2_planes);
+	v4l2_fill_vb2_buffer(vb, b, vbuf->v4l2_planes);
 	return call_vb_qop(vb, buf_prepare, vb);
 }
 
@@ -1430,7 +423,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 
 	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
 	/* Copy relevant information provided by the userspace */
-	__fill_vb2_buffer(vb, b, planes);
+	v4l2_fill_vb2_buffer(vb, b, planes);
 
 	for (plane = 0; plane < vb->num_planes; ++plane) {
 		/* Skip the plane if already verified */
@@ -1439,12 +432,12 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		    && vbuf->v4l2_planes[plane].length == planes[plane].length)
 			continue;
 
-		dprintk(3, "userspace address for plane %d changed, "
+		VB2_DEBUG(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 "
+			VB2_DEBUG(1, "provided buffer size %u is less than "
 						"setup size %u for plane %d\n",
 						planes[plane].length,
 						q->plane_sizes[plane], plane);
@@ -1469,7 +462,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 				      planes[plane].m.userptr,
 				      planes[plane].length, dma_dir);
 		if (IS_ERR_OR_NULL(mem_priv)) {
-			dprintk(1, "failed acquiring userspace "
+			VB2_DEBUG(1, "failed acquiring userspace "
 						"memory for plane %d\n", plane);
 			ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
 			goto err;
@@ -1492,14 +485,14 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		 */
 		ret = call_vb_qop(vb, buf_init, vb);
 		if (ret) {
-			dprintk(1, "buffer initialization failed\n");
+			VB2_DEBUG(1, "buffer initialization failed\n");
 			goto err;
 		}
 	}
 
 	ret = call_vb_qop(vb, buf_prepare, vb);
 	if (ret) {
-		dprintk(1, "buffer preparation failed\n");
+		VB2_DEBUG(1, "buffer preparation failed\n");
 		call_void_vb_qop(vb, buf_cleanup, vb);
 		goto err;
 	}
@@ -1535,13 +528,13 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 
 	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
 	/* Copy relevant information provided by the userspace */
-	__fill_vb2_buffer(vb, b, planes);
+	v4l2_fill_vb2_buffer(vb, 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",
+			VB2_DEBUG(1, "invalid dmabuf fd for plane %d\n",
 				plane);
 			ret = -EINVAL;
 			goto err;
@@ -1552,7 +545,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 			planes[plane].length = dbuf->size;
 
 		if (planes[plane].length < q->plane_sizes[plane]) {
-			dprintk(1, "invalid dmabuf length for plane %d\n",
+			VB2_DEBUG(1, "invalid dmabuf length for plane %d\n",
 				plane);
 			ret = -EINVAL;
 			goto err;
@@ -1565,7 +558,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 			continue;
 		}
 
-		dprintk(1, "buffer for plane %d changed\n", plane);
+		VB2_DEBUG(1, "buffer for plane %d changed\n", plane);
 
 		if (!reacquired) {
 			reacquired = true;
@@ -1580,7 +573,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		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");
+			VB2_DEBUG(1, "failed to attach dmabuf\n");
 			ret = PTR_ERR(mem_priv);
 			dma_buf_put(dbuf);
 			goto err;
@@ -1597,7 +590,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	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",
+			VB2_DEBUG(1, "failed to map dmabuf for plane %d\n",
 				plane);
 			goto err;
 		}
@@ -1618,14 +611,14 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		 */
 		ret = call_vb_qop(vb, buf_init, vb);
 		if (ret) {
-			dprintk(1, "buffer initialization failed\n");
+			VB2_DEBUG(1, "buffer initialization failed\n");
 			goto err;
 		}
 	}
 
 	ret = call_vb_qop(vb, buf_prepare, vb);
 	if (ret) {
-		dprintk(1, "buffer preparation failed\n");
+		VB2_DEBUG(1, "buffer preparation failed\n");
 		call_void_vb_qop(vb, buf_cleanup, vb);
 		goto err;
 	}
@@ -1638,35 +631,16 @@ err:
 	return ret;
 }
 
-/**
- * __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);
-
-	trace_vb2_buf_queue(q, vb);
-
-	/* 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, const struct v4l2_buffer *b)
+static int v4l2_buf_prepare(struct vb2_buffer *vb, void *pb)
 {
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
 	struct vb2_queue *q = vb->vb2_queue;
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	int ret;
 
 	ret = __verify_length(vb, b);
 	if (ret < 0) {
-		dprintk(1, "plane parameters verification failed: %d\n", ret);
+		VB2_DEBUG(1, "plane parameters verification failed: %d\n", ret);
 		return ret;
 	}
 	if (b->field == V4L2_FIELD_ALTERNATE && V4L2_TYPE_IS_OUTPUT(q->type)) {
@@ -1679,12 +653,12 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 		 * 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");
+		VB2_DEBUG(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");
+		VB2_DEBUG(1, "fatal error occurred on queue\n");
 		return -EIO;
 	}
 
@@ -1711,463 +685,149 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	}
 
 	if (ret)
-		dprintk(1, "buffer preparation failed: %d\n", ret);
+		VB2_DEBUG(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)
-{
-	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;
-	}
-
-	return __verify_planes_array(q->bufs[b->index], 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_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];
-	if (vb->state != VB2_BUF_STATE_DEQUEUED) {
-		dprintk(1, "invalid buffer state %d\n",
-			vb->state);
-		return -EINVAL;
-	}
-
-	ret = __buf_prepare(vb, b);
-	if (!ret) {
-		/* Fill buffer information for the userspace */
-		__fill_v4l2_buffer(vb, b);
-
-		dprintk(1, "prepare of buffer %d succeeded\n",
-			vb2_v4l2_index(vb));
-	}
-	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)
+static int v4l2_set_timestamp(struct vb2_buffer *vb, void *pb)
 {
-	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;
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct v4l2_buffer *b = (struct v4l2_buffer *)pb;
+	struct vb2_queue *q = vb->vb2_queue;
 
-	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-v4l2.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;
+	if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
+	    V4L2_BUF_FLAG_TIMESTAMP_COPY)
+		vbuf->v4l2_buf.timestamp = b->timestamp;
+	vbuf->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
+	if (b->flags & V4L2_BUF_FLAG_TIMECODE)
+		vbuf->v4l2_buf.timecode = b->timecode;
 
-		/*
-		 * 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;
+	return 0;
 }
 
-static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
+static int v4l2_is_last(struct vb2_buffer *vb)
 {
-	int ret = vb2_queue_or_prepare_buf(q, b, "qbuf");
-	struct vb2_buffer *vb;
-
-	if (ret)
-		return ret;
-
-	vb = q->bufs[b->index];
-
-	switch (vb->state) {
-	case VB2_BUF_STATE_DEQUEUED:
-		ret = __buf_prepare(vb, 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)) {
-		struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
-
-		/*
-		 * For output buffers copy the timestamp if needed,
-		 * and the timecode field and flag if needed.
-		 */
-		if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
-		    V4L2_BUF_FLAG_TIMESTAMP_COPY)
-			vbuf->v4l2_buf.timestamp = b->timestamp;
-		vbuf->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
-		if (b->flags & V4L2_BUF_FLAG_TIMECODE)
-			vbuf->v4l2_buf.timecode = b->timecode;
-	}
-
-	trace_vb2_qbuf(q, vb);
-
-	/*
-	 * 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(vb, 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);
-		if (ret)
-			return ret;
-	}
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-	dprintk(1, "qbuf of buffer %d succeeded\n", vb2_v4l2_index(vb));
-	return 0;
-}
+	return (vbuf->v4l2_buf.flags & V4L2_BUF_FLAG_LAST);
+}
+
+const struct vb2_buf_ops vb2_v4l2_buf_ops = {
+	.init_buffer		= v4l2_init_buffer,
+	.get_index 		= v4l2_get_index,
+	.set_plane_length	= v4l2_set_plane_length,
+	.get_plane_length	= v4l2_get_plane_length,
+	.set_plane_offset	= v4l2_set_plane_offset,
+	.get_plane_offset	= v4l2_get_plane_offset,
+	.verify_planes		= v4l2_verify_planes,
+	.fill_buffer		= v4l2_fill_buffer,
+	.fill_vb2_buffer	= v4l2_fill_vb2_buffer,
+	.prepare_buffer		= v4l2_buf_prepare,
+	.set_timestamp		= v4l2_set_timestamp,
+	.is_last		= v4l2_is_last,
+};
 
 /**
- * vb2_qbuf() - Queue a buffer from userspace
- * @q:		videobuf2 queue
- * @b:		buffer structure passed from userspace to vidioc_qbuf handler
+ * 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_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.
+ * 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_qbuf handler in driver.
+ * from vidioc_querybuf handler in driver.
  */
-int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
+int vb2_querybuf(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);
+	return vb2_core_querybuf(q, b->type, b->index, b);
 }
-EXPORT_SYMBOL_GPL(vb2_qbuf);
+EXPORT_SYMBOL(vb2_querybuf);
 
 /**
- * __vb2_wait_for_done_vb() - wait for a buffer to become available
- * for dequeuing
- *
- * Will sleep if required for nonblocking == false.
+ * vb2_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
  */
-static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)
+int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 {
-	/*
-	 * 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 (q->last_buffer_dequeued) {
-			dprintk(3, "last buffer dequeued already, will not wait for buffers\n");
-			return -EPIPE;
-		}
-
-		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);
+	int ret = __verify_memory_type(q, req->memory, req->type);
 
-		/*
-		 * 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;
+	return ret ? ret : vb2_core_reqbufs(q, req->memory, &req->count);
 }
+EXPORT_SYMBOL_GPL(vb2_reqbufs);
 
 /**
- * __vb2_get_done_vb() - get a buffer ready for dequeuing
- *
- * Will sleep if required for nonblocking == false.
+ * 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
  */
-static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb,
-				struct v4l2_buffer *b, int nonblocking)
+int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb)
 {
-	unsigned long flags;
-	int ret;
+	int ret = __verify_memory_type(q, cb->memory, cb->format.type);
 
-	/*
-	 * 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.
-	 */
-	ret = __verify_planes_array(*vb, b);
-	if (!ret)
-		list_del(&(*vb)->done_entry);
-	spin_unlock_irqrestore(&q->done_lock, flags);
-
-	return ret;
+	cb->index = q->num_buffers;
+	if (cb->count == 0)
+		return ret != -EBUSY ? ret : 0;
+	return ret ? ret : vb2_core_create_bufs(q, cb->memory, &cb->count, &cb->format);
 }
+EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
 /**
- * vb2_wait_for_all_buffers() - wait until all buffers are given back to vb2
+ * 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
  *
- * 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
+ * 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.
  */
-static void __vb2_dqbuf(struct vb2_buffer *vb)
+int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	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_core_prepare_buf(q, b->memory, b->type, b->index, b);
 }
+EXPORT_SYMBOL_GPL(vb2_prepare_buf);
 
-static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
+/**
+ * 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)
 {
-	struct vb2_buffer *vb = NULL;
-	struct vb2_v4l2_buffer *vbuf = 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);
-	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;
+	if (vb2_fileio_is_active(q)) {
+		VB2_DEBUG(1, "file io in progress\n");
+		return -EBUSY;
 	}
 
-	call_void_vb_qop(vb, buf_finish, vb);
-
-	/* Fill buffer information for the userspace */
-	__fill_v4l2_buffer(vb, b);
-	/* Remove from videobuf queue */
-	list_del(&vb->queued_entry);
-	q->queued_count--;
-
-	trace_vb2_dqbuf(q, vb);
-
-	vbuf = to_vb2_v4l2_buffer(vb);
-
-	if (!V4L2_TYPE_IS_OUTPUT(q->type) &&
-	    vbuf->v4l2_buf.flags & V4L2_BUF_FLAG_LAST)
-		q->last_buffer_dequeued = true;
-	/* go back to dequeued state */
-	__vb2_dqbuf(vb);
-
-	dprintk(1, "dqbuf of buffer %d, with state %d\n",
-			vb2_v4l2_index(vb), vb->state);
-
-	return 0;
+	return vb2_core_qbuf(q, b->memory, b->type, b->index, b);
 }
+EXPORT_SYMBOL_GPL(vb2_qbuf);
 
 /**
  * vb2_dqbuf() - Dequeue a buffer to the userspace
@@ -2193,144 +853,29 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n
 int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
 	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
+		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_internal_dqbuf(q, b, nonblocking);
+	return vb2_core_dqbuf(q, b->type, b, nonblocking);
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
 /**
- * __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)
-{
-	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-v4l2.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);
-	}
-}
-
-static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_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
+ * 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
  *
- * 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.
+ * The return values from this function are intended to be directly returned
+ * from vidioc_expbuf handler in driver.
  */
-void vb2_queue_error(struct vb2_queue *q)
+int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 {
-	q->error = 1;
+	eb->fd = vb2_core_expbuf(q, eb->type, eb->index, eb->plane, eb->flags);
 
-	wake_up_all(&q->done_wq);
+	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_queue_error);
+EXPORT_SYMBOL_GPL(vb2_expbuf);
 
 /**
  * vb2_streamon - start streaming
@@ -2348,36 +893,13 @@ EXPORT_SYMBOL_GPL(vb2_queue_error);
 int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
 {
 	if (vb2_fileio_is_active(q)) {
-		dprintk(1, "file io in progress\n");
+		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_internal_streamon(q, type);
-}
-EXPORT_SYMBOL_GPL(vb2_streamon);
-
-static int vb2_internal_streamoff(struct vb2_queue *q, enum v4l2_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 = !V4L2_TYPE_IS_OUTPUT(q->type);
-	q->last_buffer_dequeued = false;
-
-	dprintk(3, "successful\n");
-	return 0;
+	return vb2_core_streamon(q, type);
 }
+EXPORT_SYMBOL_GPL(vb2_streamon);
 
 /**
  * vb2_streamoff - stop streaming
@@ -2397,243 +919,13 @@ static int vb2_internal_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
 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");
+		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_internal_streamoff(q, type);
+	return vb2_core_streamoff(q, type);
 }
 EXPORT_SYMBOL_GPL(vb2_streamoff);
 
-/**
- * __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)
-{
-	struct vb2_buffer *vb;
-	struct vb2_v4l2_buffer *vbuf;
-	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];
-		vbuf = to_vb2_v4l2_buffer(vb);
-		for (plane = 0; plane < vb->num_planes; ++plane) {
-			if (vbuf->v4l2_planes[plane].m.mem_offset == off) {
-				*_buffer = buffer;
-				*_plane = plane;
-				return 0;
-			}
-		}
-	}
-
-	return -EINVAL;
-}
-
-/**
- * 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)
-{
-	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;
-	}
-
-	vb = q->bufs[eb->index];
-
-	if (eb->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[eb->plane];
-
-	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;
-	}
-
-	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;
-	}
-
-	dprintk(3, "buffer %d, plane %d exported as %d descriptor\n",
-		eb->index, eb->plane, ret);
-	eb->fd = ret;
-
-	return 0;
-}
-EXPORT_SYMBOL_GPL(vb2_expbuf);
-
-/**
- * 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;
-	struct vb2_v4l2_buffer *vbuf;
-	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;
-	}
-
-	/*
-	 * 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");
-		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;
-
-	vb = q->bufs[buffer];
-	vbuf = to_vb2_v4l2_buffer(vb);
-
-	/*
-	 * 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(vbuf->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;
-	}
-
-	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 != V4L2_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 = __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
-
 static int __vb2_init_fileio(struct vb2_queue *q, int read);
 static int __vb2_cleanup_fileio(struct vb2_queue *q);
 
@@ -2757,22 +1049,20 @@ 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-v4l2.h
+ * to the struct vb2_queue description in include/media/videobuf2-core.h
  * for more information.
  */
 int vb2_queue_init(struct vb2_queue *q)
 {
+	int ret = vb2_core_queue_init(q);
+
+	if (ret < 0)
+		return ret;
+
 	/*
 	 * 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 &
+	if (WARN_ON(q->timestamp_flags &
 		    ~(V4L2_BUF_FLAG_TIMESTAMP_MASK |
 		      V4L2_BUF_FLAG_TSTAMP_SRC_MASK)))
 		return -EINVAL;
@@ -2781,15 +1071,11 @@ int vb2_queue_init(struct vb2_queue *q)
 	WARN_ON((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
 		V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN);
 
-	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 (q->buf_struct_size == 0)
 		q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
 
+	q->buf_ops = &vb2_v4l2_buf_ops;
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(vb2_queue_init);
@@ -2805,10 +1091,7 @@ EXPORT_SYMBOL_GPL(vb2_queue_init);
 void vb2_queue_release(struct vb2_queue *q)
 {
 	__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);
+	vb2_core_queue_release(q);
 }
 EXPORT_SYMBOL_GPL(vb2_queue_release);
 
@@ -2898,7 +1181,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	 */
 	count = 1;
 
-	dprintk(3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n",
+	VB2_DEBUG(3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n",
 		(read) ? "read" : "write", count, q->fileio_read_once,
 		q->fileio_write_immediately);
 
@@ -2917,7 +1200,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	fileio->req.memory = V4L2_MEMORY_MMAP;
 	fileio->req.type = q->type;
 	q->fileio = fileio;
-	ret = __reqbufs(q, &fileio->req);
+	ret = vb2_core_reqbufs(q, fileio->req.memory, &fileio->req.count);
 	if (ret)
 		goto err_kfree;
 
@@ -2963,7 +1246,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 			}
 			b->memory = q->memory;
 			b->index = i;
-			ret = vb2_internal_qbuf(q, b);
+			ret = vb2_core_qbuf(q, b->memory, b->type, i, b);
 			if (ret)
 				goto err_reqbufs;
 			fileio->bufs[i].queued = 1;
@@ -2979,7 +1262,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	/*
 	 * Start streaming.
 	 */
-	ret = vb2_internal_streamon(q, q->type);
+	ret = vb2_core_streamon(q, q->type);
 	if (ret)
 		goto err_reqbufs;
 
@@ -2987,7 +1270,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 
 err_reqbufs:
 	fileio->req.count = 0;
-	__reqbufs(q, &fileio->req);
+	vb2_core_reqbufs(q, fileio->req.memory, &fileio->req.count);
 
 err_kfree:
 	q->fileio = NULL;
@@ -3004,12 +1287,12 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
 	struct vb2_fileio_data *fileio = q->fileio;
 
 	if (fileio) {
-		vb2_internal_streamoff(q, q->type);
+		vb2_core_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");
+		VB2_DEBUG(3, "file io emulator closed\n");
 	}
 	return 0;
 }
@@ -3039,7 +1322,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	int ret, index;
 
-	dprintk(3, "mode %s, offset %ld, count %zd, %sblocking\n",
+	VB2_DEBUG(3, "mode %s, offset %ld, count %zd, %sblocking\n",
 		read ? "read" : "write", (long)*ppos, count,
 		nonblock ? "non" : "");
 
@@ -3051,7 +1334,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 	 */
 	if (!vb2_fileio_is_active(q)) {
 		ret = __vb2_init_fileio(q, read);
-		dprintk(3, "vb2_init_fileio result: %d\n", ret);
+		VB2_DEBUG(3, "vb2_init_fileio result: %d\n", ret);
 		if (ret)
 			return ret;
 	}
@@ -3073,8 +1356,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 			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);
+		ret = vb2_core_dqbuf(q, fileio->b.type, &fileio->b, nonblock);
+		VB2_DEBUG(5, "vb2_dqbuf result: %d\n", ret);
 		if (ret)
 			return ret;
 		fileio->dq_count += 1;
@@ -3104,20 +1387,20 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 	 */
 	if (buf->pos + count > buf->size) {
 		count = buf->size - buf->pos;
-		dprintk(5, "reducing read count: %zd\n", count);
+		VB2_DEBUG(5, "reducing read count: %zd\n", count);
 	}
 
 	/*
 	 * Transfer data to userspace.
 	 */
-	dprintk(3, "copying %zd bytes - buffer %d, offset %u\n",
+	VB2_DEBUG(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");
+		VB2_DEBUG(3, "error copying data\n");
 		return -EFAULT;
 	}
 
@@ -3135,7 +1418,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		 * Check if this is the last buffer to read.
 		 */
 		if (read && fileio->read_once && fileio->dq_count == 1) {
-			dprintk(3, "read limit reached\n");
+			VB2_DEBUG(3, "read limit reached\n");
 			return __vb2_cleanup_fileio(q);
 		}
 
@@ -3155,8 +1438,9 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		}
 		if (set_timestamp)
 			v4l2_get_timestamp(&fileio->b.timestamp);
-		ret = vb2_internal_qbuf(q, &fileio->b);
-		dprintk(5, "vb2_dbuf result: %d\n", ret);
+		ret = vb2_core_qbuf(q, fileio->b.memory, fileio->b.type, index,
+				&fileio->b);
+		VB2_DEBUG(5, "vb2_dbuf result: %d\n", ret);
 		if (ret)
 			return ret;
 
@@ -3247,9 +1531,9 @@ static int vb2_thread(void *data)
 		} else {
 			call_void_qop(q, wait_finish, q);
 			if (!threadio->stop)
-				ret = vb2_internal_dqbuf(q, &fileio->b, 0);
+				ret = vb2_core_dqbuf(q, fileio->b.type, &fileio->b, 0);
 			call_void_qop(q, wait_prepare, q);
-			dprintk(5, "file io: vb2_dqbuf result: %d\n", ret);
+			VB2_DEBUG(5, "file io: vb2_dqbuf result: %d\n", ret);
 		}
 		if (ret || threadio->stop)
 			break;
@@ -3263,7 +1547,8 @@ static int vb2_thread(void *data)
 		if (set_timestamp)
 			v4l2_get_timestamp(&fileio->b.timestamp);
 		if (!threadio->stop)
-			ret = vb2_internal_qbuf(q, &fileio->b);
+			ret = vb2_core_qbuf(q, fileio->b.memory,
+				fileio->b.type, fileio->b.index, &fileio->b);
 		call_void_qop(q, wait_prepare, q);
 		if (ret || threadio->stop)
 			break;
@@ -3302,7 +1587,7 @@ int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
 	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);
+	VB2_DEBUG(3, "file io: vb2_init_fileio result: %d\n", ret);
 	if (ret)
 		goto nomem;
 	q->threadio = threadio;
@@ -3367,7 +1652,7 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv,
 		return res;
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	res = __reqbufs(vdev->queue, p);
+	res = vb2_core_reqbufs(vdev->queue, p->memory, &p->count);
 	/* 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)
@@ -3391,7 +1676,7 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv,
 		return res;
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	res = __create_bufs(vdev->queue, p);
+	res = vb2_core_create_bufs(vdev->queue, p->memory, &p->count, &p->format);
 	if (res == 0)
 		vdev->queue->owner = file->private_data;
 	return res;
@@ -3405,7 +1690,8 @@ int vb2_ioctl_prepare_buf(struct file *file, void *priv,
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_prepare_buf(vdev->queue, p);
+	return vb2_core_prepare_buf(vdev->queue,
+			p->memory, p->type, p->index, p);
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_prepare_buf);
 
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index 45da6cd..2fe4c27 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-v4l2.h>
+#include <media/videobuf2-core.h>
 #include <media/videobuf2-vmalloc.h>
 #include <media/videobuf2-memops.h>
 
diff --git a/drivers/usb/gadget/function/uvc_queue.c b/drivers/usb/gadget/function/uvc_queue.c
index d903ece..264d76f 100644
--- a/drivers/usb/gadget/function/uvc_queue.c
+++ b/drivers/usb/gadget/function/uvc_queue.c
@@ -41,7 +41,7 @@
  * videobuf2 queue operations
  */
 
-static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
+static int uvc_queue_setup(struct vb2_queue *vq, const void *parg,
 			   unsigned int *nbuffers, unsigned int *nplanes,
 			   unsigned int sizes[], void *alloc_ctxs[])
 {
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
new file mode 100644
index 0000000..dc405da
--- /dev/null
+++ b/include/media/videobuf2-core.h
@@ -0,0 +1,724 @@
+/*
+ * videobuf2-core.h - Video Buffer 2 Core Framework
+ *
+ * Copyright (C) 2010 Samsung Electronics
+ *
+ * Author: Pawel Osciak <pawel@osciak.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ */
+#ifndef _MEDIA_VIDEOBUF2_CORE_H
+#define _MEDIA_VIDEOBUF2_CORE_H
+
+#include <linux/mm_types.h>
+#include <linux/mutex.h>
+#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_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 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
+};
+
+/**
+ * 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 void *parg,
+			   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_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_buffer *vb);
+};
+
+struct vb2_buf_ops {
+	int (*init_buffer)(struct vb2_buffer *vb, unsigned int memory,
+		unsigned int type, unsigned int index, unsigned int planes);
+	unsigned int (*get_index)(struct vb2_buffer *vb);
+	int (*set_plane_length)(struct vb2_buffer *vb, int plane,
+		unsigned int length);
+	unsigned int (*get_plane_length)(struct vb2_buffer *vb, int plane);
+	int (*set_plane_offset)(struct vb2_buffer *vb, int plane,
+		unsigned int offset);
+	unsigned int (*get_plane_offset)(struct vb2_buffer *vb, int plane);
+	int (*verify_planes)(struct vb2_buffer *vb, void *pb);
+	int (*fill_buffer)(struct vb2_buffer *vb, void *pb);
+	int (*fill_vb2_buffer)(struct vb2_buffer *vb, const void *pb,
+		void *planes);
+	int (*prepare_buffer)(struct vb2_buffer *vb, void *pb);
+	int (*set_timestamp)(struct vb2_buffer *vb, void *pb);
+	int (*is_last)(struct vb2_buffer *vb);
+};
+
+/**
+ * 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)
+ * @fileio_read_once:		report EOF after reading the first buffer
+ * @fileio_write_immediately:	queue buffer after each write() call
+ * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
+ * @lock:	pointer to a mutex that protects the vb2_queue struct. The
+ *		driver can set this to a mutex to let the vb2 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
+ *		in case of v4l2.
+ * @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.
+ * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
+ *		last decoded buffer was already dequeued. Set for capture queues
+ *		when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
+ * @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 {
+	unsigned int			type;
+	unsigned int			io_modes;
+	unsigned			fileio_read_once:1;
+	unsigned			fileio_write_immediately:1;
+	unsigned			allow_zero_bytesused:1;
+
+	struct mutex			*lock;
+	void				*owner;
+
+	const struct vb2_ops		*ops;
+	const struct vb2_mem_ops	*mem_ops;
+	const struct vb2_buf_ops	*buf_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;
+	unsigned int			memory;
+	struct vb2_buffer		*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;
+	unsigned int			last_buffer_dequeued: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
+};
+
+extern int vb2_debug;
+
+#define VB2_DEBUG(level, fmt, arg...)					 \
+	do {								 \
+		if (vb2_debug >= level)					 \
+			pr_info("vb2-core: %s: " fmt, __func__, ## arg); \
+	} while (0)
+
+#define call_bufop(q, op, args...)					\
+({ 									\
+	int ret = 0;							\
+									\
+	if(q && q->buf_ops && q->buf_ops->op)				\
+		ret = q->buf_ops->op(args);				\
+	ret;								\
+})
+
+#define call_u32_bufop(q, op, args...)					\
+({ 									\
+	unsigned int ret = 0;						\
+									\
+	if(q && q->buf_ops && q->buf_ops->op)				\
+		ret = q->buf_ops->op(args);				\
+	ret;								\
+})
+
+#define vb2_index(vb) (call_u32_bufop((vb)->vb2_queue, get_index, vb))
+
+#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)						\
+	VB2_DEBUG(2, "call_memop(%p, %d, %s)%s\n",			\
+		(vb)->vb2_queue, vb2_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)							\
+	VB2_DEBUG(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...)					\
+	VB2_DEBUG(2, "call_vb_qop(%p, %d, %s)%s\n",			\
+		(vb)->vb2_queue, vb2_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_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
+void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
+
+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, unsigned int type,
+		unsigned int index, void *pb);
+int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *count);
+int vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
+		unsigned int *count, void *parg);
+int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int memory,
+		unsigned int type, unsigned int index, void *pb);
+
+int __must_check vb2_core_queue_init(struct vb2_queue *q);
+
+void vb2_core_queue_release(struct vb2_queue *q);
+void vb2_queue_error(struct vb2_queue *q);
+
+int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory, unsigned int type,
+		unsigned int index, void *pb);
+int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb, bool nonblock);
+int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
+		unsigned int plane, unsigned int flags);
+
+int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
+int vb2_core_streamoff(struct vb2_queue *q, unsigned int 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
+
+/*
+ * The following functions are for internal uses.
+ */
+bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
+void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p);
+void __vb2_buf_dmabuf_put(struct vb2_buffer *vb);
+int __verify_memory_type(struct vb2_queue *q,
+		enum v4l2_memory memory, enum v4l2_buf_type type);
+
+/**
+ * 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;
+}
+
+/**
+ * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue
+ * @q:		videobuf queue
+ */
+static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
+{
+	q->last_buffer_dequeued = false;
+}
+
+#endif /* _MEDIA_VIDEOBUF2_CORE_H */
diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h
index c33dfa6..8197f87 100644
--- a/include/media/videobuf2-dma-contig.h
+++ b/include/media/videobuf2-dma-contig.h
@@ -13,7 +13,7 @@
 #ifndef _MEDIA_VIDEOBUF2_DMA_CONTIG_H
 #define _MEDIA_VIDEOBUF2_DMA_CONTIG_H
 
-#include <media/videobuf2-v4l2.h>
+#include <media/videobuf2-core.h>
 #include <linux/dma-mapping.h>
 
 static inline dma_addr_t
diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h
index 8d1083f..14ce306 100644
--- a/include/media/videobuf2-dma-sg.h
+++ b/include/media/videobuf2-dma-sg.h
@@ -13,7 +13,7 @@
 #ifndef _MEDIA_VIDEOBUF2_DMA_SG_H
 #define _MEDIA_VIDEOBUF2_DMA_SG_H
 
-#include <media/videobuf2-v4l2.h>
+#include <media/videobuf2-core.h>
 
 static inline struct sg_table *vb2_dma_sg_plane_desc(
 		struct vb2_buffer *vb, unsigned int plane_no)
diff --git a/include/media/videobuf2-memops.h b/include/media/videobuf2-memops.h
index 7b6d475..f05444c 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-v4l2.h>
+#include <media/videobuf2-core.h>
 
 /**
  * vb2_vmarea_handler - common vma refcount tracking handler
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index 76500f4..3f76e53 100644
--- a/include/media/videobuf2-v4l2.h
+++ b/include/media/videobuf2-v4l2.h
@@ -12,212 +12,11 @@
 #ifndef _MEDIA_VIDEOBUF2_V4L2_H
 #define _MEDIA_VIDEOBUF2_V4L2_H
 
-#include <linux/mm_types.h>
-#include <linux/mutex.h>
-#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_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 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
+ * @vb2_buf:		videobuf2
  * @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
@@ -237,266 +36,34 @@ struct vb2_v4l2_buffer {
 };
 
 /**
- * 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_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_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)
- * @fileio_read_once:		report EOF after reading the first buffer
- * @fileio_write_immediately:	queue buffer after each write() call
- * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
- * @lock:	pointer to a mutex that protects the vb2_queue struct. The
- *		driver can set this to a mutex to let the vb2 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.
- * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
- *		last decoded buffer was already dequeued. Set for capture queues
- *		when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
- * @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			fileio_read_once:1;
-	unsigned			fileio_write_immediately:1;
-	unsigned			allow_zero_bytesused:1;
-
-	struct mutex			*lock;
-	struct v4l2_fh			*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;
-	struct vb2_buffer		*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;
-	unsigned int			last_buffer_dequeued: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
-};
-
-/**
  * to_vb2_v4l2_buffer() - cast to struct vb2_v4l2_buffer *
  * @vb:		struct vb2_buffer *vb
  */
 #define to_vb2_v4l2_buffer(vb) \
 	(container_of(vb, struct vb2_v4l2_buffer, vb2_buf))
 
-#define vb2_v4l2_index(vb)						\
+#define vb2_v4l2_index(vb)					\
 ({								\
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);	\
-	int ret = vbuf->v4l2_buf.index;				\
+	unsigned int ret = vbuf->v4l2_buf.index;		\
 	ret;							\
 })
 
-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_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_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_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb);
 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_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblock);
 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);
@@ -533,52 +100,6 @@ int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
 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
@@ -624,24 +145,6 @@ vb2_plane_size(struct vb2_buffer *vb, 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;
-}
-
-/**
- * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue
- * @q:		videobuf queue
- */
-static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
-{
-	q->last_buffer_dequeued = false;
-}
-
 /*
  * 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,
diff --git a/include/media/videobuf2-vmalloc.h b/include/media/videobuf2-vmalloc.h
index a63fe66..93a76b4 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-v4l2.h>
+#include <media/videobuf2-core.h>
 
 extern const struct vb2_mem_ops vb2_vmalloc_memops;
 
diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h
index dabd780..0ae549f 100644
--- a/include/trace/events/v4l2.h
+++ b/include/trace/events/v4l2.h
@@ -203,7 +203,8 @@ DECLARE_EVENT_CLASS(vb2_event_class,
 
 	TP_fast_assign(
 		struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
-		__entry->minor = q->owner ? q->owner->vdev->minor : -1;
+		struct v4l2_fh *owner = (struct v4l2_fh *)q->owner;
+		__entry->minor = owner ? owner->vdev->minor : -1;
 		__entry->queued_count = q->queued_count;
 		__entry->owned_by_drv_count =
 			atomic_read(&q->owned_by_drv_count);
-- 
1.7.9.5


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

* [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory
  2015-07-31  8:44 [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Junghak Sung
                   ` (2 preceding siblings ...)
  2015-07-31  8:44 ` [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts Junghak Sung
@ 2015-07-31  8:44 ` Junghak Sung
  2015-08-10  8:22   ` Hans Verkuil
  2015-07-31  8:44 ` [RFC PATCH v2 5/5] media: videobuf2: Modify prefix for VB2 functions Junghak Sung
  2015-08-10  8:31 ` [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Hans Verkuil
  5 siblings, 1 reply; 23+ messages in thread
From: Junghak Sung @ 2015-07-31  8:44 UTC (permalink / raw)
  To: linux-media, mchehab, hverkuil, laurent.pinchart, sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon, jh1009.sung

Define enum vb2_buf_type and enum vb2_memory for videobuf2-core. This
change requires translation functions that could covert v4l2-core stuffs
to videobuf2-core stuffs in videobuf2-v4l2.c file.
The v4l2-specific member variables(e.g. type, memory) remains in
struct vb2_queue for backward compatibility and performance of type translation.

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
---
 drivers/media/v4l2-core/videobuf2-core.c |  139 +++++++++++---------
 drivers/media/v4l2-core/videobuf2-v4l2.c |  209 ++++++++++++++++++++----------
 include/media/videobuf2-core.h           |   99 +++++++++++---
 include/media/videobuf2-v4l2.h           |   12 +-
 4 files changed, 299 insertions(+), 160 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 0460a99..7888338 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -26,10 +26,9 @@
 
 #include <media/videobuf2-core.h>
 
-#include <trace/events/v4l2.h>
-
 int vb2_debug;
 module_param_named(debug, vb2_debug, int, 0644);
+EXPORT_SYMBOL_GPL(vb2_debug);
 
 static void __enqueue_in_driver(struct vb2_buffer *vb);
 static void __vb2_queue_cancel(struct vb2_queue *q);
@@ -41,7 +40,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 {
 	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;
+		VB2_TYPE_IS_OUTPUT(q->vb2_type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
 	void *mem_priv;
 	int plane;
 
@@ -120,6 +119,7 @@ void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p)
 	dma_buf_put(p->dbuf);
 	memset(p, 0, sizeof(*p));
 }
+EXPORT_SYMBOL_GPL(__vb2_plane_dmabuf_put);
 
 /**
  * __vb2_buf_dmabuf_put() - release memory associated with
@@ -132,6 +132,7 @@ void __vb2_buf_dmabuf_put(struct vb2_buffer *vb)
 	for (plane = 0; plane < vb->num_planes; ++plane)
 		__vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
 }
+EXPORT_SYMBOL_GPL(__vb2_buf_dmabuf_put);
 
 /**
  * __setup_lengths() - setup initial lengths for every plane in
@@ -196,7 +197,7 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n)
  *
  * Returns the number of buffers successfully allocated.
  */
-static int __vb2_queue_alloc(struct vb2_queue *q, unsigned int memory,
+static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
 			     unsigned int num_buffers, unsigned int num_planes)
 {
 	unsigned int buffer;
@@ -214,11 +215,11 @@ static int __vb2_queue_alloc(struct vb2_queue *q, unsigned int memory,
 		vb->state = VB2_BUF_STATE_DEQUEUED;
 		vb->vb2_queue = q;
 		vb->num_planes = num_planes;
-		call_bufop(q, init_buffer, vb, memory, q->type,
+		call_bufop(q, init_buffer, vb, memory,
 				q->num_buffers + buffer, num_planes);
 
 		/* Allocate video buffer memory for the MMAP type */
-		if (memory == V4L2_MEMORY_MMAP) {
+		if (memory == VB2_MEMORY_MMAP) {
 			ret = __vb2_buf_mem_alloc(vb);
 			if (ret) {
 				VB2_DEBUG(1, "failed allocating memory for "
@@ -245,7 +246,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, unsigned int memory,
 	}
 
 	__setup_lengths(q, buffer);
-	if (memory == V4L2_MEMORY_MMAP)
+	if (memory == VB2_MEMORY_MMAP)
 		__setup_offsets(q, buffer);
 
 	VB2_DEBUG(1, "allocated %d buffers, %d plane(s) each\n",
@@ -269,9 +270,9 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
 			continue;
 
 		/* Free MMAP buffers or release USERPTR buffers */
-		if (q->memory == V4L2_MEMORY_MMAP)
+		if (q->vb2_memory == VB2_MEMORY_MMAP)
 			__vb2_buf_mem_free(vb);
-		else if (q->memory == V4L2_MEMORY_DMABUF)
+		else if (q->vb2_memory == VB2_MEMORY_DMABUF)
 			__vb2_buf_dmabuf_put(vb);
 		else
 			__vb2_buf_userptr_put(vb);
@@ -388,7 +389,7 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
 
 	q->num_buffers -= buffers;
 	if (!q->num_buffers) {
-		q->memory = 0;
+		q->vb2_memory = 0;
 		INIT_LIST_HEAD(&q->queued_list);
 	}
 	return 0;
@@ -414,6 +415,7 @@ bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb)
 	}
 	return false;
 }
+EXPORT_SYMBOL_GPL(__buffer_in_use);
 
 /**
  * __buffers_in_use() - return true if any buffers on the queue are in use and
@@ -432,7 +434,7 @@ static bool __buffers_in_use(struct vb2_queue *q)
 /**
  * vb2_core_querybuf() - query video buffer information
  * @q:		videobuf queue
- * @type:	enum v4l2_buf_type; buffer type (type == *_MPLANE for
+ * @type:	enum vb2_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
@@ -445,13 +447,13 @@ static bool __buffers_in_use(struct vb2_queue *q)
  * 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,
+int vb2_core_querybuf(struct vb2_queue *q, enum vb2_buf_type type,
 		unsigned int index, void *pb)
 {
 	struct vb2_buffer *vb;
 	int ret;
 
-	if (type != q->type) {
+	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "wrong buffer type\n");
 		return -EINVAL;
 	}
@@ -467,6 +469,7 @@ int vb2_core_querybuf(struct vb2_queue *q, unsigned int type,
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_core_querybuf);
 
 /**
  * __verify_userptr_ops() - verify that all memory operations required for
@@ -513,15 +516,15 @@ static int __verify_dmabuf_ops(struct vb2_queue *q)
  * passed to a buffer operation are compatible with the queue.
  */
 int __verify_memory_type(struct vb2_queue *q,
-		unsigned int memory, enum v4l2_buf_type type)
+		enum vb2_memory memory, enum vb2_buf_type type)
 {
-	if (memory != V4L2_MEMORY_MMAP && memory != V4L2_MEMORY_USERPTR &&
-	    memory != V4L2_MEMORY_DMABUF) {
+	if (memory != VB2_MEMORY_MMAP && memory != VB2_MEMORY_USERPTR &&
+	    memory != VB2_MEMORY_DMABUF) {
 		VB2_DEBUG(1, "unsupported memory type\n");
 		return -EINVAL;
 	}
 
-	if (type != q->type) {
+	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "requested type is incorrect\n");
 		return -EINVAL;
 	}
@@ -530,17 +533,17 @@ int __verify_memory_type(struct vb2_queue *q,
 	 * Make sure all the required memory ops for given memory type
 	 * are available.
 	 */
-	if (memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
+	if (memory == VB2_MEMORY_MMAP && __verify_mmap_ops(q)) {
 		VB2_DEBUG(1, "MMAP for current setup unsupported\n");
 		return -EINVAL;
 	}
 
-	if (memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
+	if (memory == VB2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
 		VB2_DEBUG(1, "USERPTR for current setup unsupported\n");
 		return -EINVAL;
 	}
 
-	if (memory == V4L2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) {
+	if (memory == VB2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) {
 		VB2_DEBUG(1, "DMABUF for current setup unsupported\n");
 		return -EINVAL;
 	}
@@ -556,7 +559,7 @@ int __verify_memory_type(struct vb2_queue *q,
 	}
 	return 0;
 }
-
+EXPORT_SYMBOL_GPL(__verify_memory_type);
 
 /**
  * vb2_core_reqbufs() - Initiate streaming
@@ -581,7 +584,8 @@ int __verify_memory_type(struct vb2_queue *q,
  * The return values from this function are intended to be directly returned
  * from vidioc_reqbufs handler in driver.
  */
-int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *count)
+int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
+		unsigned int *count)
 {
 	unsigned int num_buffers, allocated_buffers, num_planes = 0;
 	int ret;
@@ -591,13 +595,13 @@ int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *cou
 		return -EBUSY;
 	}
 
-	if (*count == 0 || q->num_buffers != 0 || q->memory != memory) {
+	if (*count == 0 || q->num_buffers != 0 || q->vb2_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 == V4L2_MEMORY_MMAP && __buffers_in_use(q)) {
+		if (q->vb2_memory == VB2_MEMORY_MMAP && __buffers_in_use(q)) {
 			mutex_unlock(&q->mmap_lock);
 			VB2_DEBUG(1, "memory in use, cannot free\n");
 			return -EBUSY;
@@ -625,11 +629,11 @@ int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *cou
 	/*
 	 * Make sure the requested values and current defaults are sane.
 	 */
-	num_buffers = min_t(unsigned int, *count, VIDEO_MAX_FRAME);
+	num_buffers = min_t(unsigned int, *count, VB2_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;
+	q->vb2_memory = memory;
 
 	/*
 	 * Ask the driver how many buffers and planes per buffer it requires.
@@ -691,10 +695,11 @@ int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *cou
 	 * to the userspace.
 	 */
 	*count = allocated_buffers;
-	q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
+	q->waiting_for_buffers = !VB2_TYPE_IS_OUTPUT(q->vb2_type);
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_core_reqbufs);
 
 /**
  * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs
@@ -711,13 +716,13 @@ int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *cou
  * The return values from this function are intended to be directly returned
  * from vidioc_create_bufs handler in driver.
  */
-int vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
+int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 		unsigned int *count, void *parg)
 {
 	unsigned int num_planes = 0, num_buffers, allocated_buffers;
 	int ret;
 
-	if (q->num_buffers == VIDEO_MAX_FRAME) {
+	if (q->num_buffers == VB2_MAX_FRAME) {
 		VB2_DEBUG(1, "maximum number of buffers already allocated\n");
 		return -ENOBUFS;
 	}
@@ -725,11 +730,11 @@ int vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
 	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 = !V4L2_TYPE_IS_OUTPUT(q->type);
+		q->vb2_memory = memory;
+		q->waiting_for_buffers = !VB2_TYPE_IS_OUTPUT(q->vb2_type);
 	}
 
-	num_buffers = min(*count, VIDEO_MAX_FRAME - q->num_buffers);
+	num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers);
 
 	/*
 	 * Ask the driver, whether the requested number of buffers, planes per
@@ -792,6 +797,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_core_create_bufs);
 
 /**
  * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
@@ -887,7 +893,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 	atomic_dec(&q->owned_by_drv_count);
 	spin_unlock_irqrestore(&q->done_lock, flags);
 
-	trace_vb2_buf_done(q, vb);
+	trace_op(q, buf_done, q, vb);
 
 	if (state == VB2_BUF_STATE_QUEUED) {
 		if (q->start_streaming_called)
@@ -935,7 +941,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
 	vb->state = VB2_BUF_STATE_ACTIVE;
 	atomic_inc(&q->owned_by_drv_count);
 
-	trace_vb2_buf_queue(q, vb);
+	trace_op(q, buf_queue, q, vb);
 
 	/* sync buffers */
 	for (plane = 0; plane < vb->num_planes; ++plane)
@@ -944,11 +950,11 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
 	call_void_vb_qop(vb, buf_queue, vb);
 }
 
-static int vb2_queue_or_prepare_buf(struct vb2_queue *q, unsigned int memory,
-		unsigned int type, unsigned int index, void *pb,
+static int vb2_queue_or_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
+		enum vb2_buf_type type, unsigned int index, void *pb,
 		const char *opname)
 {
-	if (type != q->type) {
+	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "%s: invalid buffer type\n", opname);
 		return -EINVAL;
 	}
@@ -964,7 +970,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, unsigned int memory,
 		return -EINVAL;
 	}
 
-	if (memory != q->memory) {
+	if (memory != q->vb2_memory) {
 		VB2_DEBUG(1, "%s: invalid memory type\n", opname);
 		return -EINVAL;
 	}
@@ -987,8 +993,8 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, unsigned int memory,
  * 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, unsigned int memory,
-		unsigned int type, unsigned int index, void *pb)
+int vb2_core_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
+		enum vb2_buf_type type, unsigned int index, void *pb)
 {
 	struct vb2_buffer *vb;
 	int ret;
@@ -1019,6 +1025,7 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int memory,
 	}
 	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_core_prepare_buf);
 
 /**
  * vb2_start_streaming() - Attempt to start streaming.
@@ -1083,8 +1090,8 @@ static int vb2_start_streaming(struct vb2_queue *q)
 	return ret;
 }
 
-int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory,
-		unsigned int type, unsigned int index, void *pb)
+int vb2_core_qbuf(struct vb2_queue *q, enum vb2_memory memory,
+		enum vb2_buf_type type, unsigned int index, void *pb)
 {
 	int ret = vb2_queue_or_prepare_buf(q, memory, type, index, pb, "qbuf");
 	struct vb2_buffer *vb;
@@ -1118,7 +1125,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory,
 	q->queued_count++;
 	q->waiting_for_buffers = false;
 	vb->state = VB2_BUF_STATE_QUEUED;
-	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+	if (VB2_TYPE_IS_OUTPUT(q->vb2_type)) {
 		/*
 		 * For output buffers copy the timestamp if needed,
 		 * and the timecode field and flag if needed.
@@ -1126,7 +1133,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory,
 		call_bufop(q, set_timestamp, vb, pb);
 	}
 
-	trace_vb2_qbuf(q, vb);
+	trace_op(q, qbuf, q, vb);
 
 	/*
 	 * If already streaming, give the buffer to driver for processing.
@@ -1154,6 +1161,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory,
 	VB2_DEBUG(1, "qbuf of buffer %d succeeded\n", vb2_index(vb));
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_core_qbuf);
 
 /**
  * __vb2_wait_for_done_vb() - wait for a buffer to become available
@@ -1305,7 +1313,7 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
 	vb->state = VB2_BUF_STATE_DEQUEUED;
 
 	/* unmap DMABUF buffer */
-	if (q->memory == V4L2_MEMORY_DMABUF)
+	if (q->vb2_memory == VB2_MEMORY_DMABUF)
 		for (i = 0; i < vb->num_planes; ++i) {
 			if (!vb->planes[i].dbuf_mapped)
 				continue;
@@ -1314,13 +1322,13 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
 		}
 }
 
-int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb,
+int vb2_core_dqbuf(struct vb2_queue *q, enum vb2_buf_type type, void *pb,
 		bool nonblocking)
 {
 	struct vb2_buffer *vb = NULL;
 	int ret;
 
-	if (type != q->type) {
+	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "invalid buffer type\n");
 		return -EINVAL;
 	}
@@ -1348,9 +1356,9 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb,
 	list_del(&vb->queued_entry);
 	q->queued_count--;
 
-	trace_vb2_dqbuf(q, vb);
+	trace_op(q, dqbuf, q, vb);
 
-	if (!V4L2_TYPE_IS_OUTPUT(q->type) && call_bufop(q, is_last, vb))
+	if (!VB2_TYPE_IS_OUTPUT(q->vb2_type) && call_bufop(q, is_last, vb))
 		q->last_buffer_dequeued = true;
 	/* go back to dequeued state */
 	__vb2_dqbuf(vb);
@@ -1360,6 +1368,7 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb,
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_core_dqbuf);
 
 /**
  * __vb2_queue_cancel() - cancel and stop (pause) streaming
@@ -1429,11 +1438,11 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 	}
 }
 
-int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
+int vb2_core_streamon(struct vb2_queue *q, enum vb2_buf_type type)
 {
 	int ret;
 
-	if (type != q->type) {
+	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "invalid stream type\n");
 		return -EINVAL;
 	}
@@ -1471,6 +1480,7 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type)
 	VB2_DEBUG(3, "successful\n");
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_core_streamon);
 
 /**
  * vb2_queue_error() - signal a fatal error on the queue
@@ -1493,9 +1503,9 @@ void vb2_queue_error(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(vb2_queue_error);
 
-int vb2_core_streamoff(struct vb2_queue *q, unsigned int type)
+int vb2_core_streamoff(struct vb2_queue *q, enum vb2_buf_type type)
 {
-	if (type != q->type) {
+	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "invalid stream type\n");
 		return -EINVAL;
 	}
@@ -1510,12 +1520,13 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned int type)
 	 * their normal dequeued state.
 	 */
 	__vb2_queue_cancel(q);
-	q->waiting_for_buffers = !V4L2_TYPE_IS_OUTPUT(q->type);
+	q->waiting_for_buffers = !VB2_TYPE_IS_OUTPUT(q->vb2_type);
 	q->last_buffer_dequeued = false;
 
 	VB2_DEBUG(3, "successful\n");
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_core_streamoff);
 
 /**
  * __find_plane_by_offset() - find plane associated with the given offset off
@@ -1555,7 +1566,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
  * 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,
+int vb2_core_expbuf(struct vb2_queue *q, enum vb2_buf_type type, unsigned int index,
 		unsigned int plane, unsigned int flags)
 {
 	struct vb2_buffer *vb = NULL;
@@ -1563,7 +1574,7 @@ int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
 	int ret;
 	struct dma_buf *dbuf;
 
-	if (q->memory != V4L2_MEMORY_MMAP) {
+	if (q->vb2_memory != VB2_MEMORY_MMAP) {
 		VB2_DEBUG(1, "queue is not currently set up for mmap\n");
 		return -EINVAL;
 	}
@@ -1578,7 +1589,7 @@ int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
 		return -EINVAL;
 	}
 
-	if (type != q->type) {
+	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "invalid buffer type\n");
 		return -EINVAL;
 	}
@@ -1621,6 +1632,7 @@ int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(vb2_core_expbuf);
 
 /**
  * vb2_mmap() - map video buffers into application address space
@@ -1649,7 +1661,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 	int ret;
 	unsigned long length;
 
-	if (q->memory != V4L2_MEMORY_MMAP) {
+	if (q->vb2_memory != VB2_MEMORY_MMAP) {
 		VB2_DEBUG(1, "queue is not currently set up for mmap\n");
 		return -EINVAL;
 	}
@@ -1661,7 +1673,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
 		VB2_DEBUG(1, "invalid vma flags, VM_SHARED needed\n");
 		return -EINVAL;
 	}
-	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+	if (VB2_TYPE_IS_OUTPUT(q->vb2_type)) {
 		if (!(vma->vm_flags & VM_WRITE)) {
 			VB2_DEBUG(1, "invalid vma flags, VM_WRITE needed\n");
 			return -EINVAL;
@@ -1722,7 +1734,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
 	void *vaddr;
 	int ret;
 
-	if (q->memory != V4L2_MEMORY_MMAP) {
+	if (q->vb2_memory != VB2_MEMORY_MMAP) {
 		VB2_DEBUG(1, "queue is not currently set up for mmap\n");
 		return -EINVAL;
 	}
@@ -1749,7 +1761,7 @@ EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
  * 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
+ * q->ops, q->mem_ops, q->vb2_type and q->io_modes are mandatory. Please refer
  * to the struct vb2_queue description in include/media/videobuf2-v4l2.h
  * for more information.
  */
@@ -1761,7 +1773,8 @@ int vb2_core_queue_init(struct vb2_queue *q)
 	if (WARN_ON(!q)			  ||
 	    WARN_ON(!q->ops)		  ||
 	    WARN_ON(!q->mem_ops)	  ||
-	    WARN_ON(!q->type)		  ||
+	    WARN_ON(!q->buf_ops)	  ||
+	    WARN_ON(!q->vb2_type)	  ||
 	    WARN_ON(!q->io_modes)	  ||
 	    WARN_ON(!q->ops->queue_setup) ||
 	    WARN_ON(!q->ops->buf_queue))
@@ -1775,6 +1788,7 @@ int vb2_core_queue_init(struct vb2_queue *q)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(vb2_core_queue_init);
 
 /**
  * vb2_core_queue_release() - stop streaming, release the queue and free memory
@@ -1791,6 +1805,7 @@ void vb2_core_queue_release(struct vb2_queue *q)
 	__vb2_queue_free(q, q->num_buffers);
 	mutex_unlock(&q->mmap_lock);
 }
+EXPORT_SYMBOL_GPL(vb2_core_queue_release);
 
 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 85527e9..22dd19c 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -30,8 +30,46 @@
 #include <media/v4l2-common.h>
 #include <media/videobuf2-v4l2.h>
 
+#define CREATE_TRACE_POINTS
 #include <trace/events/v4l2.h>
 
+static const enum vb2_buf_type _tbl_buf_type[] = {
+	[V4L2_BUF_TYPE_VIDEO_CAPTURE]		= VB2_BUF_TYPE_VIDEO_CAPTURE,
+	[V4L2_BUF_TYPE_VIDEO_OUTPUT]		= VB2_BUF_TYPE_VIDEO_OUTPUT,
+	[V4L2_BUF_TYPE_VIDEO_OVERLAY]		= VB2_BUF_TYPE_VIDEO_OVERLAY,
+	[V4L2_BUF_TYPE_VBI_CAPTURE]		= VB2_BUF_TYPE_VBI_CAPTURE,
+	[V4L2_BUF_TYPE_VBI_OUTPUT]		= VB2_BUF_TYPE_VBI_OUTPUT,
+	[V4L2_BUF_TYPE_SLICED_VBI_CAPTURE]	= VB2_BUF_TYPE_SLICED_VBI_CAPTURE,
+	[V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]	= VB2_BUF_TYPE_SLICED_VBI_OUTPUT,
+	[V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY]	= VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY,
+	[V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE]	= VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+	[V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE]	= VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
+	[V4L2_BUF_TYPE_SDR_CAPTURE]		= VB2_BUF_TYPE_SDR_CAPTURE,
+	[V4L2_BUF_TYPE_PRIVATE]			= VB2_BUF_TYPE_PRIVATE,
+};
+
+static const enum vb2_memory _tbl_memory[] = {
+	[V4L2_MEMORY_MMAP]	= VB2_MEMORY_MMAP,
+	[V4L2_MEMORY_USERPTR]	= VB2_MEMORY_USERPTR,
+	[V4L2_MEMORY_DMABUF]	= VB2_MEMORY_DMABUF,
+};
+
+#define to_vb2_buf_type(type)					\
+({								\
+	enum vb2_buf_type ret = 0;				\
+	if( type > 0 && type < ARRAY_SIZE(_tbl_buf_type) )	\
+		ret = (_tbl_buf_type[type]);			\
+	ret;							\
+})
+
+#define to_vb2_memory(memory)					\
+({								\
+	enum vb2_memory ret = 0;				\
+	if( memory > 0 && memory < ARRAY_SIZE(_tbl_memory) )	\
+		ret = (_tbl_memory[memory]);			\
+	ret;							\
+})
+
 /* Flags that are set by the vb2 core */
 #define V4L2_BUFFER_MASK_FLAGS	(V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
 				 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
@@ -41,19 +79,19 @@
 #define V4L2_BUFFER_OUT_FLAGS	(V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME | \
 				 V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_TIMECODE)
 
-static int v4l2_init_buffer(struct vb2_buffer *vb,
-		unsigned int memory, unsigned int type, unsigned int index,
-		unsigned int planes)
+static int v4l2_init_buffer(struct vb2_buffer *vb, enum vb2_memory memory,
+		unsigned int index, unsigned int planes)
 {
+	struct vb2_queue *q = vb->vb2_queue;
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
 	/* Length stores number of planes for multiplanar buffers */
-	if (V4L2_TYPE_IS_MULTIPLANAR(type))
+	if (VB2_TYPE_IS_MULTIPLANAR(q->vb2_type))
 		vbuf->v4l2_buf.length = planes;
 
 	vbuf->v4l2_buf.index = index;
-	vbuf->v4l2_buf.type = type;
-	vbuf->v4l2_buf.memory = memory;
+	vbuf->v4l2_buf.type = q->type;
+	vbuf->v4l2_buf.memory = q->memory;
 
 	return 0;
 }
@@ -139,7 +177,7 @@ static int v4l2_fill_buffer(struct vb2_buffer *vb, void *pb)
 	b->reserved2 = vbuf->v4l2_buf.reserved2;
 	b->reserved = vbuf->v4l2_buf.reserved;
 
-	if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) {
+	if (VB2_TYPE_IS_MULTIPLANAR(q->vb2_type)) {
 		/*
 		 * Fill in plane-related data if userspace provided an array
 		 * for it. The caller has already verified memory and size.
@@ -154,11 +192,11 @@ static int v4l2_fill_buffer(struct vb2_buffer *vb, void *pb)
 		 */
 		b->length = vbuf->v4l2_planes[0].length;
 		b->bytesused = vbuf->v4l2_planes[0].bytesused;
-		if (q->memory == V4L2_MEMORY_MMAP)
+		if (q->vb2_memory == VB2_MEMORY_MMAP)
 			b->m.offset = vbuf->v4l2_planes[0].m.mem_offset;
-		else if (q->memory == V4L2_MEMORY_USERPTR)
+		else if (q->vb2_memory == VB2_MEMORY_USERPTR)
 			b->m.userptr = vbuf->v4l2_planes[0].m.userptr;
-		else if (q->memory == V4L2_MEMORY_DMABUF)
+		else if (q->vb2_memory == VB2_MEMORY_DMABUF)
 			b->m.fd = vbuf->v4l2_planes[0].m.fd;
 	}
 
@@ -418,7 +456,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	unsigned int plane;
 	int ret;
 	enum dma_data_direction dma_dir =
-		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
+		VB2_TYPE_IS_OUTPUT(q->vb2_type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
 	bool reacquired = vb->planes[0].mem_priv == NULL;
 
 	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
@@ -523,7 +561,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
 	unsigned int plane;
 	int ret;
 	enum dma_data_direction dma_dir =
-		V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
+		VB2_TYPE_IS_OUTPUT(q->vb2_type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
 	bool reacquired = vb->planes[0].mem_priv == NULL;
 
 	memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
@@ -643,7 +681,7 @@ static int v4l2_buf_prepare(struct vb2_buffer *vb, void *pb)
 		VB2_DEBUG(1, "plane parameters verification failed: %d\n", ret);
 		return ret;
 	}
-	if (b->field == V4L2_FIELD_ALTERNATE && V4L2_TYPE_IS_OUTPUT(q->type)) {
+	if (b->field == V4L2_FIELD_ALTERNATE && VB2_TYPE_IS_OUTPUT(q->vb2_type)) {
 		/*
 		 * If the format's field is ALTERNATE, then the buffer's field
 		 * should be either TOP or BOTTOM, not ALTERNATE since that
@@ -667,16 +705,16 @@ static int v4l2_buf_prepare(struct vb2_buffer *vb, void *pb)
 	vbuf->v4l2_buf.timestamp.tv_usec = 0;
 	vbuf->v4l2_buf.sequence = 0;
 
-	switch (q->memory) {
-	case V4L2_MEMORY_MMAP:
+	switch (q->vb2_memory) {
+	case VB2_MEMORY_MMAP:
 		ret = __qbuf_mmap(vb, b);
 		break;
-	case V4L2_MEMORY_USERPTR:
+	case VB2_MEMORY_USERPTR:
 		down_read(&current->mm->mmap_sem);
 		ret = __qbuf_userptr(vb, b);
 		up_read(&current->mm->mmap_sem);
 		break;
-	case V4L2_MEMORY_DMABUF:
+	case VB2_MEMORY_DMABUF:
 		ret = __qbuf_dmabuf(vb, b);
 		break;
 	default:
@@ -698,7 +736,7 @@ static int v4l2_set_timestamp(struct vb2_buffer *vb, void *pb)
 	struct vb2_queue *q = vb->vb2_queue;
 
 	if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
-	    V4L2_BUF_FLAG_TIMESTAMP_COPY)
+			V4L2_BUF_FLAG_TIMESTAMP_COPY)
 		vbuf->v4l2_buf.timestamp = b->timestamp;
 	vbuf->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE;
 	if (b->flags & V4L2_BUF_FLAG_TIMECODE)
@@ -729,6 +767,33 @@ const struct vb2_buf_ops vb2_v4l2_buf_ops = {
 	.is_last		= v4l2_is_last,
 };
 
+static void v4l2_trace_buf_done(struct vb2_queue *q, struct vb2_buffer *vb)
+{
+	trace_vb2_buf_done(q, vb);
+}
+
+static void v4l2_trace_buf_queue(struct vb2_queue *q, struct vb2_buffer *vb)
+{
+	trace_vb2_buf_queue(q, vb);
+}
+
+static void v4l2_trace_qbuf(struct vb2_queue *q, struct vb2_buffer *vb)
+{
+	trace_vb2_qbuf(q, vb);
+}
+
+static void v4l2_trace_dqbuf(struct vb2_queue *q, struct vb2_buffer *vb)
+{
+	trace_vb2_dqbuf(q, vb);
+}
+
+const struct vb2_trace_ops vb2_v4l2_trace_ops = {
+	.buf_done		= v4l2_trace_buf_done,
+	.buf_queue 		= v4l2_trace_buf_queue,
+	.qbuf			= v4l2_trace_qbuf,
+	.dqbuf			= v4l2_trace_dqbuf,
+};
+
 /**
  * vb2_querybuf() - query video buffer information
  * @q:		videobuf queue
@@ -744,7 +809,7 @@ const struct vb2_buf_ops vb2_v4l2_buf_ops = {
  */
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	return vb2_core_querybuf(q, b->type, b->index, b);
+	return vb2_core_querybuf(q, to_vb2_buf_type(b->type), b->index, b);
 }
 EXPORT_SYMBOL(vb2_querybuf);
 
@@ -756,9 +821,10 @@ EXPORT_SYMBOL(vb2_querybuf);
  */
 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 {
-	int ret = __verify_memory_type(q, req->memory, req->type);
-
-	return ret ? ret : vb2_core_reqbufs(q, req->memory, &req->count);
+	int ret = __verify_memory_type(q, to_vb2_memory(req->memory),
+			to_vb2_buf_type(req->type));
+	q->memory = req->memory;
+	return ret ? ret : vb2_core_reqbufs(q, to_vb2_memory(req->memory), &req->count);
 }
 EXPORT_SYMBOL_GPL(vb2_reqbufs);
 
@@ -771,12 +837,14 @@ EXPORT_SYMBOL_GPL(vb2_reqbufs);
  */
 int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb)
 {
-	int ret = __verify_memory_type(q, cb->memory, cb->format.type);
+	int ret = __verify_memory_type(q, to_vb2_memory(cb->memory),
+			to_vb2_buf_type(cb->format.type));
 
 	cb->index = q->num_buffers;
 	if (cb->count == 0)
 		return ret != -EBUSY ? ret : 0;
-	return ret ? ret : vb2_core_create_bufs(q, cb->memory, &cb->count, &cb->format);
+	q->memory = cb->memory;
+	return ret ? ret : vb2_core_create_bufs(q, to_vb2_memory(cb->memory), &cb->count, &cb->format);
 }
 EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
@@ -797,7 +865,7 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs);
  */
 int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	return vb2_core_prepare_buf(q, b->memory, b->type, b->index, b);
+	return vb2_core_prepare_buf(q, to_vb2_memory(b->memory), to_vb2_buf_type(b->type), b->index, b);
 }
 EXPORT_SYMBOL_GPL(vb2_prepare_buf);
 
@@ -825,7 +893,7 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 		return -EBUSY;
 	}
 
-	return vb2_core_qbuf(q, b->memory, b->type, b->index, b);
+	return vb2_core_qbuf(q, to_vb2_memory(b->memory), to_vb2_buf_type(b->type), b->index, b);
 }
 EXPORT_SYMBOL_GPL(vb2_qbuf);
 
@@ -856,7 +924,7 @@ int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_core_dqbuf(q, b->type, b, nonblocking);
+	return vb2_core_dqbuf(q, to_vb2_buf_type(b->type), b, nonblocking);
 }
 EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
@@ -871,7 +939,7 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
  */
 int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 {
-	eb->fd = vb2_core_expbuf(q, eb->type, eb->index, eb->plane, eb->flags);
+	eb->fd = vb2_core_expbuf(q, to_vb2_buf_type(eb->type), eb->index, eb->plane, eb->flags);
 
 	return 0;
 }
@@ -897,7 +965,7 @@ int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
 		return -EBUSY;
 	}
 
-	return vb2_core_streamon(q, type);
+	return vb2_core_streamon(q, to_vb2_buf_type(type));
 }
 EXPORT_SYMBOL_GPL(vb2_streamon);
 
@@ -922,7 +990,7 @@ int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
 		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_core_streamoff(q, type);
+	return vb2_core_streamoff(q, to_vb2_buf_type(type));
 }
 EXPORT_SYMBOL_GPL(vb2_streamoff);
 
@@ -965,21 +1033,21 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 			poll_wait(file, &fh->wait, wait);
 	}
 
-	if (!V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLIN | POLLRDNORM)))
+	if (!VB2_TYPE_IS_OUTPUT(q->vb2_type) && !(req_events & (POLLIN | POLLRDNORM)))
 		return res;
-	if (V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLOUT | POLLWRNORM)))
+	if (VB2_TYPE_IS_OUTPUT(q->vb2_type) && !(req_events & (POLLOUT | POLLWRNORM)))
 		return res;
 
 	/*
 	 * 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) &&
+		if (!VB2_TYPE_IS_OUTPUT(q->vb2_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) &&
+		if (VB2_TYPE_IS_OUTPUT(q->vb2_type) && (q->io_modes & VB2_WRITE) &&
 				(req_events & (POLLOUT | POLLWRNORM))) {
 			if (__vb2_init_fileio(q, 0))
 				return res | POLLERR;
@@ -1008,7 +1076,7 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 	 * 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)
+	if (VB2_TYPE_IS_OUTPUT(q->vb2_type) && q->queued_count < q->num_buffers)
 		return res | POLLOUT | POLLWRNORM;
 
 	if (list_empty(&q->done_list)) {
@@ -1033,7 +1101,7 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 
 	if (vb && (vb->state == VB2_BUF_STATE_DONE
 			|| vb->state == VB2_BUF_STATE_ERROR)) {
-		return (V4L2_TYPE_IS_OUTPUT(q->type)) ?
+		return (VB2_TYPE_IS_OUTPUT(q->vb2_type)) ?
 				res | POLLOUT | POLLWRNORM :
 				res | POLLIN | POLLRDNORM;
 	}
@@ -1048,20 +1116,18 @@ EXPORT_SYMBOL_GPL(vb2_poll);
  * 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
+ * q->ops, q->mem_ops, q->vb2_type and q->io_modes are mandatory. Please refer
  * to the struct vb2_queue description in include/media/videobuf2-core.h
  * for more information.
  */
 int vb2_queue_init(struct vb2_queue *q)
 {
-	int ret = vb2_core_queue_init(q);
-
-	if (ret < 0)
-		return ret;
-
 	/*
 	 * Sanity check
 	 */
+	if (WARN_ON(!q)	|| WARN_ON(!q->type))
+		return -EINVAL;
+
 	if (WARN_ON(q->timestamp_flags &
 		    ~(V4L2_BUF_FLAG_TIMESTAMP_MASK |
 		      V4L2_BUF_FLAG_TSTAMP_SRC_MASK)))
@@ -1075,8 +1141,10 @@ int vb2_queue_init(struct vb2_queue *q)
 		q->buf_struct_size = sizeof(struct vb2_v4l2_buffer);
 
 	q->buf_ops = &vb2_v4l2_buf_ops;
+	q->trace_ops = &vb2_v4l2_trace_ops;
+	q->vb2_type = to_vb2_buf_type(q->type);
 
-	return 0;
+	return vb2_core_queue_init(q);
 }
 EXPORT_SYMBOL_GPL(vb2_queue_init);
 
@@ -1197,10 +1265,10 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	 * to allocate buffers by itself.
 	 */
 	fileio->req.count = count;
-	fileio->req.memory = V4L2_MEMORY_MMAP;
+	fileio->req.memory = q->memory = V4L2_MEMORY_MMAP;
 	fileio->req.type = q->type;
 	q->fileio = fileio;
-	ret = vb2_core_reqbufs(q, fileio->req.memory, &fileio->req.count);
+	ret = vb2_core_reqbufs(q, to_vb2_memory(fileio->req.memory), &fileio->req.count);
 	if (ret)
 		goto err_kfree;
 
@@ -1229,7 +1297,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	 * Read mode requires pre queuing of all buffers.
 	 */
 	if (read) {
-		bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
+		bool is_multiplanar = VB2_TYPE_IS_MULTIPLANAR(q->vb2_type);
 
 		/*
 		 * Queue all buffers.
@@ -1246,7 +1314,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 			}
 			b->memory = q->memory;
 			b->index = i;
-			ret = vb2_core_qbuf(q, b->memory, b->type, i, b);
+			ret = vb2_core_qbuf(q, q->vb2_memory, q->vb2_type, i, b);
 			if (ret)
 				goto err_reqbufs;
 			fileio->bufs[i].queued = 1;
@@ -1262,7 +1330,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	/*
 	 * Start streaming.
 	 */
-	ret = vb2_core_streamon(q, q->type);
+	ret = vb2_core_streamon(q, q->vb2_type);
 	if (ret)
 		goto err_reqbufs;
 
@@ -1270,7 +1338,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 
 err_reqbufs:
 	fileio->req.count = 0;
-	vb2_core_reqbufs(q, fileio->req.memory, &fileio->req.count);
+	vb2_core_reqbufs(q, to_vb2_memory(fileio->req.memory), &fileio->req.count);
 
 err_kfree:
 	q->fileio = NULL;
@@ -1287,7 +1355,7 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
 	struct vb2_fileio_data *fileio = q->fileio;
 
 	if (fileio) {
-		vb2_core_streamoff(q, q->type);
+		vb2_core_streamoff(q, q->vb2_type);
 		q->fileio = NULL;
 		fileio->req.count = 0;
 		vb2_reqbufs(q, &fileio->req);
@@ -1311,7 +1379,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 {
 	struct vb2_fileio_data *fileio;
 	struct vb2_fileio_buf *buf;
-	bool is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type);
+	bool is_multiplanar = VB2_TYPE_IS_MULTIPLANAR(q->vb2_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
@@ -1356,7 +1424,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 			fileio->b.m.planes = &fileio->p;
 			fileio->b.length = 1;
 		}
-		ret = vb2_core_dqbuf(q, fileio->b.type, &fileio->b, nonblock);
+		ret = vb2_core_dqbuf(q, q->vb2_type, &fileio->b, nonblock);
 		VB2_DEBUG(5, "vb2_dqbuf result: %d\n", ret);
 		if (ret)
 			return ret;
@@ -1438,7 +1506,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		}
 		if (set_timestamp)
 			v4l2_get_timestamp(&fileio->b.timestamp);
-		ret = vb2_core_qbuf(q, fileio->b.memory, fileio->b.type, index,
+		ret = vb2_core_qbuf(q, q->vb2_memory, q->vb2_type, index,
 				&fileio->b);
 		VB2_DEBUG(5, "vb2_dbuf result: %d\n", ret);
 		if (ret)
@@ -1507,7 +1575,7 @@ static int vb2_thread(void *data)
 	int index = 0;
 	int ret = 0;
 
-	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+	if (VB2_TYPE_IS_OUTPUT(q->vb2_type)) {
 		prequeue = q->num_buffers;
 		set_timestamp =
 			(q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
@@ -1531,7 +1599,7 @@ static int vb2_thread(void *data)
 		} else {
 			call_void_qop(q, wait_finish, q);
 			if (!threadio->stop)
-				ret = vb2_core_dqbuf(q, fileio->b.type, &fileio->b, 0);
+				ret = vb2_core_dqbuf(q, q->vb2_type, &fileio->b, 0);
 			call_void_qop(q, wait_prepare, q);
 			VB2_DEBUG(5, "file io: vb2_dqbuf result: %d\n", ret);
 		}
@@ -1547,8 +1615,8 @@ static int vb2_thread(void *data)
 		if (set_timestamp)
 			v4l2_get_timestamp(&fileio->b.timestamp);
 		if (!threadio->stop)
-			ret = vb2_core_qbuf(q, fileio->b.memory,
-				fileio->b.type, fileio->b.index, &fileio->b);
+			ret = vb2_core_qbuf(q, q->vb2_memory,
+				q->vb2_type, fileio->b.index, &fileio->b);
 		call_void_qop(q, wait_prepare, q);
 		if (ret || threadio->stop)
 			break;
@@ -1586,7 +1654,7 @@ int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
 	threadio->fnc = fnc;
 	threadio->priv = priv;
 
-	ret = __vb2_init_fileio(q, !V4L2_TYPE_IS_OUTPUT(q->type));
+	ret = __vb2_init_fileio(q, !VB2_TYPE_IS_OUTPUT(q->vb2_type));
 	VB2_DEBUG(3, "file io: vb2_init_fileio result: %d\n", ret);
 	if (ret)
 		goto nomem;
@@ -1646,13 +1714,15 @@ 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);
+	int res = __verify_memory_type(vdev->queue, to_vb2_memory(p->memory),
+			to_vb2_buf_type(p->type));
 
 	if (res)
 		return res;
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	res = vb2_core_reqbufs(vdev->queue, p->memory, &p->count);
+	vdev->queue->memory = p->memory;
+	res = vb2_core_reqbufs(vdev->queue, to_vb2_memory(p->memory), &p->count);
 	/* 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)
@@ -1665,7 +1735,8 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv,
 			  struct v4l2_create_buffers *p)
 {
 	struct video_device *vdev = video_devdata(file);
-	int res = __verify_memory_type(vdev->queue, p->memory, p->format.type);
+	int res = __verify_memory_type(vdev->queue, to_vb2_memory(p->memory),
+			to_vb2_buf_type(p->format.type));
 
 	p->index = vdev->queue->num_buffers;
 	/* If count == 0, then just check if memory and type are valid.
@@ -1676,7 +1747,9 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv,
 		return res;
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	res = vb2_core_create_bufs(vdev->queue, p->memory, &p->count, &p->format);
+	vdev->queue->memory = p->memory;
+	res = vb2_core_create_bufs(vdev->queue, to_vb2_memory(p->memory),
+			&p->count, &p->format);
 	if (res == 0)
 		vdev->queue->owner = file->private_data;
 	return res;
@@ -1690,8 +1763,8 @@ int vb2_ioctl_prepare_buf(struct file *file, void *priv,
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_core_prepare_buf(vdev->queue,
-			p->memory, p->type, p->index, p);
+	return vb2_core_prepare_buf(vdev->queue, to_vb2_memory(p->memory),
+			to_vb2_buf_type(p->type), p->index, p);
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_prepare_buf);
 
@@ -1724,23 +1797,23 @@ int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_dqbuf);
 
-int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
+int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type type)
 {
 	struct video_device *vdev = video_devdata(file);
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_streamon(vdev->queue, i);
+	return vb2_streamon(vdev->queue, to_vb2_buf_type(type));
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_streamon);
 
-int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
+int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type type)
 {
 	struct video_device *vdev = video_devdata(file);
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_streamoff(vdev->queue, i);
+	return vb2_streamoff(vdev->queue, to_vb2_buf_type(type));
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_streamoff);
 
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index dc405da..871fcc6 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -15,9 +15,47 @@
 #include <linux/mm_types.h>
 #include <linux/mutex.h>
 #include <linux/poll.h>
-#include <linux/videodev2.h>
 #include <linux/dma-buf.h>
 
+#define VB2_MAX_FRAME               32
+#define VB2_MAX_PLANES               8
+
+enum vb2_buf_type {
+	VB2_BUF_TYPE_UNKNOWN			= 0,
+	VB2_BUF_TYPE_VIDEO_CAPTURE		= 1,
+	VB2_BUF_TYPE_VIDEO_OUTPUT		= 2,
+	VB2_BUF_TYPE_VIDEO_OVERLAY		= 3,
+	VB2_BUF_TYPE_VBI_CAPTURE		= 4,
+	VB2_BUF_TYPE_VBI_OUTPUT			= 5,
+	VB2_BUF_TYPE_SLICED_VBI_CAPTURE		= 6,
+	VB2_BUF_TYPE_SLICED_VBI_OUTPUT		= 7,
+	VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY	= 8,
+	VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	= 9,
+	VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE	= 10,
+	VB2_BUF_TYPE_SDR_CAPTURE		= 11,
+	VB2_BUF_TYPE_DVB_CAPTURE		= 12,
+	VB2_BUF_TYPE_PRIVATE			= 0x80,
+};
+
+enum vb2_memory {
+	VB2_MEMORY_UNKNOWN	= 0,
+	VB2_MEMORY_MMAP		= 1,
+	VB2_MEMORY_USERPTR	= 2,
+	VB2_MEMORY_DMABUF	= 4,
+};
+
+#define VB2_TYPE_IS_MULTIPLANAR(type)			\
+	((type) == VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	\
+	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
+
+#define VB2_TYPE_IS_OUTPUT(type)				\
+	((type) == VB2_BUF_TYPE_VIDEO_OUTPUT			\
+	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE		\
+	 || (type) == VB2_BUF_TYPE_VIDEO_OVERLAY		\
+	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY		\
+	 || (type) == VB2_BUF_TYPE_VBI_OUTPUT			\
+	 || (type) == VB2_BUF_TYPE_SLICED_VBI_OUTPUT)
+
 struct vb2_alloc_ctx;
 struct vb2_fileio_data;
 struct vb2_threadio_data;
@@ -181,7 +219,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[VB2_MAX_PLANES];
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 	/*
@@ -314,8 +352,8 @@ struct vb2_ops {
 };
 
 struct vb2_buf_ops {
-	int (*init_buffer)(struct vb2_buffer *vb, unsigned int memory,
-		unsigned int type, unsigned int index, unsigned int planes);
+	int (*init_buffer)(struct vb2_buffer *vb, enum vb2_memory memory,
+		unsigned int index, unsigned int planes);
 	unsigned int (*get_index)(struct vb2_buffer *vb);
 	int (*set_plane_length)(struct vb2_buffer *vb, int plane,
 		unsigned int length);
@@ -332,10 +370,19 @@ struct vb2_buf_ops {
 	int (*is_last)(struct vb2_buffer *vb);
 };
 
+struct vb2_trace_ops {
+	void (*buf_done)(struct vb2_queue *q, struct vb2_buffer *vb);
+	void (*buf_queue)(struct vb2_queue *q, struct vb2_buffer *vb);
+	void (*qbuf)(struct vb2_queue *q, struct vb2_buffer *vb);
+	void (*dqbuf)(struct vb2_queue *q, struct vb2_buffer *vb);
+};
+
 /**
  * struct vb2_queue - a videobuf queue
  *
- * @type:	queue type (see V4L2_BUF_TYPE_* in linux/videodev2.h
+ * @vb2_type:	queue type (see enum vb2_buf_type avobe)
+ * @type:	queue type for backward compatibility with v4l2
+ *		(see V4L2_BUF_TYPE_* in linux/videodev2.h)
  * @io_modes:	supported io methods (see vb2_io_modes enum)
  * @fileio_read_once:		report EOF after reading the first buffer
  * @fileio_write_immediately:	queue buffer after each write() call
@@ -367,7 +414,8 @@ struct vb2_buf_ops {
  *		have been queued into the driver.
  *
  * @mmap_lock:	private mutex used when buffers are allocated/freed/mmapped
- * @memory:	current memory type used
+ * @vb2_memory:	current memory type used
+ * @memory:	memory type for backward compatibility with v4l2
  * @bufs:	videobuf buffer structures
  * @num_buffers: number of allocated/used buffers
  * @queued_list: list of buffers currently queued from userspace
@@ -392,6 +440,7 @@ struct vb2_buf_ops {
  */
 struct vb2_queue {
 	unsigned int			type;
+	enum vb2_buf_type		vb2_type;
 	unsigned int			io_modes;
 	unsigned			fileio_read_once:1;
 	unsigned			fileio_write_immediately:1;
@@ -403,6 +452,7 @@ struct vb2_queue {
 	const struct vb2_ops		*ops;
 	const struct vb2_mem_ops	*mem_ops;
 	const struct vb2_buf_ops	*buf_ops;
+	const struct vb2_trace_ops	*trace_ops;
 
 	void				*drv_priv;
 	unsigned int			buf_struct_size;
@@ -413,7 +463,8 @@ struct vb2_queue {
 /* private: internal use only */
 	struct mutex			mmap_lock;
 	unsigned int			memory;
-	struct vb2_buffer		*bufs[VIDEO_MAX_FRAME];
+	enum vb2_memory			vb2_memory;
+	struct vb2_buffer		*bufs[VB2_MAX_FRAME];
 	unsigned int			num_buffers;
 
 	struct list_head		queued_list;
@@ -424,8 +475,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[VB2_MAX_PLANES];
+	unsigned int			plane_sizes[VB2_MAX_PLANES];
 
 	unsigned int			streaming:1;
 	unsigned int			start_streaming_called:1;
@@ -475,6 +526,12 @@ extern int vb2_debug;
 	ret;								\
 })
 
+#define trace_op(q, op, args...)					\
+({ 									\
+	if(q && q->trace_ops && q->trace_ops->op)			\
+		q->trace_ops->op(args);					\
+})
+
 #define vb2_index(vb) (call_u32_bufop((vb)->vb2_queue, get_index, vb))
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -617,27 +674,27 @@ 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, unsigned int type,
+int vb2_core_querybuf(struct vb2_queue *q, enum vb2_buf_type type,
 		unsigned int index, void *pb);
-int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *count);
-int vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
+int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int *count);
+int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 		unsigned int *count, void *parg);
-int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int memory,
-		unsigned int type, unsigned int index, void *pb);
+int vb2_core_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
+		enum vb2_buf_type type, unsigned int index, void *pb);
 
 int __must_check vb2_core_queue_init(struct vb2_queue *q);
 
 void vb2_core_queue_release(struct vb2_queue *q);
 void vb2_queue_error(struct vb2_queue *q);
 
-int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory, unsigned int type,
+int vb2_core_qbuf(struct vb2_queue *q, enum vb2_memory memory, enum vb2_buf_type type,
 		unsigned int index, void *pb);
-int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb, bool nonblock);
-int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
+int vb2_core_dqbuf(struct vb2_queue *q, enum vb2_buf_type type, void *pb, bool nonblock);
+int vb2_core_expbuf(struct vb2_queue *q, enum vb2_buf_type type, unsigned int index,
 		unsigned int plane, unsigned int flags);
 
-int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
-int vb2_core_streamoff(struct vb2_queue *q, unsigned int type);
+int vb2_core_streamon(struct vb2_queue *q, enum vb2_buf_type type);
+int vb2_core_streamoff(struct vb2_queue *q, enum vb2_buf_type type);
 
 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
 #ifndef CONFIG_MMU
@@ -649,13 +706,13 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
 #endif
 
 /*
- * The following functions are for internal uses.
+ * The following functions are for videobuf2 internal use.
  */
 bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
 void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p);
 void __vb2_buf_dmabuf_put(struct vb2_buffer *vb);
 int __verify_memory_type(struct vb2_queue *q,
-		enum v4l2_memory memory, enum v4l2_buf_type type);
+		enum vb2_memory memory, enum vb2_buf_type type);
 
 /**
  * vb2_is_streaming() - return streaming status of the queue
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index 3f76e53..7460d0b 100644
--- a/include/media/videobuf2-v4l2.h
+++ b/include/media/videobuf2-v4l2.h
@@ -12,6 +12,7 @@
 #ifndef _MEDIA_VIDEOBUF2_V4L2_H
 #define _MEDIA_VIDEOBUF2_V4L2_H
 
+#include <linux/videodev2.h>
 #include <media/videobuf2-core.h>
 
 /**
@@ -42,13 +43,6 @@ struct vb2_v4l2_buffer {
 #define to_vb2_v4l2_buffer(vb) \
 	(container_of(vb, struct vb2_v4l2_buffer, vb2_buf))
 
-#define vb2_v4l2_index(vb)					\
-({								\
-	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);	\
-	unsigned int ret = vbuf->v4l2_buf.index;		\
-	ret;							\
-})
-
 int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
 
@@ -164,8 +158,8 @@ 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, enum v4l2_buf_type type);
+int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type type);
 int vb2_ioctl_expbuf(struct file *file, void *priv,
 	struct v4l2_exportbuffer *p);
 
-- 
1.7.9.5


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

* [RFC PATCH v2 5/5] media: videobuf2: Modify prefix for VB2 functions
  2015-07-31  8:44 [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Junghak Sung
                   ` (3 preceding siblings ...)
  2015-07-31  8:44 ` [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory Junghak Sung
@ 2015-07-31  8:44 ` Junghak Sung
  2015-08-10  8:31 ` [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Hans Verkuil
  5 siblings, 0 replies; 23+ messages in thread
From: Junghak Sung @ 2015-07-31  8:44 UTC (permalink / raw)
  To: linux-media, mchehab, hverkuil, laurent.pinchart, sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon, jh1009.sung

Replace prefix "vb2_" with "vb2_v4l2" for v4l2-specific functions.
And then, replace prefix "vb2_core_" with "vb2_" for vb2-core functions.
It can be done automatically with just running this shell script.

replace()
{
    str1=$1
    str2=$2
    dir=$3
    for file in $(find $dir -name *.h -o -name *.c -o -name Makefile)
    do
        echo $file
        sed "s/$str1/$str2/g" $file > $file.out
        mv $file.out $file
    done
}
replace "function_name_before" "function_name_after" "directory"

Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Acked-by: Inki Dae <inki.dae@samsung.com>
---
 drivers/input/touchscreen/sur40.c                  |    6 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c          |    4 +-
 drivers/media/pci/cobalt/cobalt-alsa-pcm.c         |    4 +-
 drivers/media/pci/cobalt/cobalt-v4l2.c             |    8 +-
 drivers/media/pci/cx23885/cx23885-417.c            |    2 +-
 drivers/media/pci/cx23885/cx23885-core.c           |    4 +-
 drivers/media/pci/cx23885/cx23885-dvb.c            |    2 +-
 drivers/media/pci/cx23885/cx23885-vbi.c            |    4 +-
 drivers/media/pci/cx23885/cx23885-video.c          |    8 +-
 drivers/media/pci/cx25821/cx25821-video.c          |    6 +-
 drivers/media/pci/cx88/cx88-blackbird.c            |    2 +-
 drivers/media/pci/cx88/cx88-dvb.c                  |    2 +-
 drivers/media/pci/cx88/cx88-mpeg.c                 |    4 +-
 drivers/media/pci/cx88/cx88-vbi.c                  |    4 +-
 drivers/media/pci/cx88/cx88-video.c                |    8 +-
 drivers/media/pci/dt3155/dt3155.c                  |    6 +-
 drivers/media/pci/saa7134/saa7134-core.c           |    2 +-
 drivers/media/pci/saa7134/saa7134-dvb.c            |    6 +-
 drivers/media/pci/saa7134/saa7134-empress.c        |    4 +-
 drivers/media/pci/saa7134/saa7134-ts.c             |    4 +-
 drivers/media/pci/saa7134/saa7134-vbi.c            |    4 +-
 drivers/media/pci/saa7134/saa7134-video.c          |   12 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   12 +-
 drivers/media/pci/solo6x10/solo6x10-v4l2.c         |    4 +-
 drivers/media/pci/sta2x11/sta2x11_vip.c            |   12 +-
 drivers/media/pci/tw68/tw68-video.c                |    6 +-
 drivers/media/platform/am437x/am437x-vpfe.c        |   10 +-
 drivers/media/platform/blackfin/bfin_capture.c     |    8 +-
 drivers/media/platform/coda/coda-bit.c             |   12 +-
 drivers/media/platform/coda/coda-common.c          |    8 +-
 drivers/media/platform/coda/coda-jpeg.c            |    2 +-
 drivers/media/platform/davinci/vpbe_display.c      |   10 +-
 drivers/media/platform/davinci/vpif_capture.c      |   10 +-
 drivers/media/platform/davinci/vpif_display.c      |   10 +-
 drivers/media/platform/exynos-gsc/gsc-m2m.c        |    6 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   10 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |    8 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |    8 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c       |    6 +-
 drivers/media/platform/m2m-deinterlace.c           |   10 +-
 drivers/media/platform/marvell-ccic/mcam-core.c    |    4 +-
 drivers/media/platform/mx2_emmaprp.c               |   10 +-
 drivers/media/platform/omap3isp/ispvideo.c         |   22 +--
 drivers/media/platform/s3c-camif/camif-capture.c   |   30 ++--
 drivers/media/platform/s5p-g2d/g2d.c               |    6 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c        |   18 +--
 drivers/media/platform/s5p-mfc/s5p_mfc.c           |   18 +--
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   42 ++---
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |   62 ++++----
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |    6 +-
 drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |    6 +-
 drivers/media/platform/s5p-tv/mixer_video.c        |   20 +--
 drivers/media/platform/sh_veu.c                    |   14 +-
 drivers/media/platform/sh_vou.c                    |    8 +-
 drivers/media/platform/soc_camera/atmel-isi.c      |   10 +-
 drivers/media/platform/soc_camera/mx2_camera.c     |   16 +-
 drivers/media/platform/soc_camera/mx3_camera.c     |   16 +-
 drivers/media/platform/soc_camera/rcar_vin.c       |   12 +-
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |   18 +--
 drivers/media/platform/soc_camera/soc_camera.c     |   22 +--
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c      |    8 +-
 drivers/media/platform/ti-vpe/vpe.c                |   10 +-
 drivers/media/platform/vim2m.c                     |   12 +-
 drivers/media/platform/vivid/vivid-core.c          |   10 +-
 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       |    8 +-
 drivers/media/platform/vivid/vivid-vid-cap.c       |    6 +-
 drivers/media/platform/vivid/vivid-vid-out.c       |    4 +-
 drivers/media/platform/vsp1/vsp1_video.c           |   10 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |    4 +-
 drivers/media/usb/airspy/airspy.c                  |    4 +-
 drivers/media/usb/au0828/au0828-vbi.c              |    8 +-
 drivers/media/usb/au0828/au0828-video.c            |   16 +-
 drivers/media/usb/em28xx/em28xx-vbi.c              |    8 +-
 drivers/media/usb/em28xx/em28xx-video.c            |   12 +-
 drivers/media/usb/go7007/go7007-v4l2.c             |    2 +-
 drivers/media/usb/hackrf/hackrf.c                  |    4 +-
 drivers/media/usb/msi2500/msi2500.c                |    4 +-
 drivers/media/usb/pwc/pwc-if.c                     |    2 +-
 drivers/media/usb/pwc/pwc-uncompress.c             |    4 +-
 drivers/media/usb/s2255/s2255drv.c                 |   10 +-
 drivers/media/usb/stk1160/stk1160-v4l.c            |    4 +-
 drivers/media/usb/stk1160/stk1160-video.c          |    2 +-
 drivers/media/usb/usbtv/usbtv-video.c              |   10 +-
 drivers/media/usb/uvc/uvc_queue.c                  |   32 ++--
 drivers/media/v4l2-core/v4l2-mem2mem.c             |   22 +--
 drivers/media/v4l2-core/videobuf2-core.c           |   74 ++++-----
 drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
 drivers/media/v4l2-core/videobuf2-v4l2.c           |  168 ++++++++++----------
 drivers/usb/gadget/function/uvc_queue.c            |   28 ++--
 include/media/videobuf2-core.h                     |   22 +--
 include/media/videobuf2-v4l2.h                     |   42 ++---
 93 files changed, 594 insertions(+), 594 deletions(-)

diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c
index d7ea662..1739808 100644
--- a/drivers/input/touchscreen/sur40.c
+++ b/drivers/input/touchscreen/sur40.c
@@ -672,13 +672,13 @@ static int sur40_buffer_prepare(struct vb2_buffer *vb)
 	struct sur40_state *sur40 = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long size = sur40_video_format.sizeimage;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dev_err(&sur40->usbdev->dev, "buffer too small (%lu < %lu)\n",
-			 vb2_plane_size(vb, 0), size);
+			 vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 	return 0;
 }
 
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 8d36149..51103cb 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -307,7 +307,7 @@ static void rtl2832_sdr_urb_complete(struct urb *urb)
 		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		len = rtl2832_sdr_convert_stream(dev, ptr, urb->transfer_buffer,
 				urb->actual_length);
-		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len);
+		vb2_v4l2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len);
 		v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
 		fbuf->vb.v4l2_buf.sequence = dev->sequence++;
 		vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE);
@@ -1419,7 +1419,7 @@ static int rtl2832_sdr_probe(struct platform_device *pdev)
 	dev->vb_queue.ops = &rtl2832_sdr_vb2_ops;
 	dev->vb_queue.mem_ops = &vb2_vmalloc_memops;
 	dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	ret = vb2_queue_init(&dev->vb_queue);
+	ret = vb2_v4l2_queue_init(&dev->vb_queue);
 	if (ret) {
 		dev_err(&pdev->dev, "Could not initialize vb2 queue\n");
 		goto err_kfree;
diff --git a/drivers/media/pci/cobalt/cobalt-alsa-pcm.c b/drivers/media/pci/cobalt/cobalt-alsa-pcm.c
index f0bdf10..7a40ab6 100644
--- a/drivers/media/pci/cobalt/cobalt-alsa-pcm.c
+++ b/drivers/media/pci/cobalt/cobalt-alsa-pcm.c
@@ -212,7 +212,7 @@ static int alsa_fnc(struct vb2_buffer *vb, void *priv)
 	cobalt_alsa_announce_pcm_data(s->alsa,
 			vb2_plane_vaddr(vb, 0),
 			8 * 4,
-			vb2_get_plane_payload(vb, 0) / (8 * 4));
+			vb2_v4l2_get_plane_payload(vb, 0) / (8 * 4));
 	return 0;
 }
 
@@ -421,7 +421,7 @@ static int alsa_pb_fnc(struct vb2_buffer *vb, void *priv)
 		cobalt_alsa_pb_pcm_data(s->alsa,
 				vb2_plane_vaddr(vb, 0),
 				8 * 4,
-				vb2_get_plane_payload(vb, 0) / (8 * 4));
+				vb2_v4l2_get_plane_payload(vb, 0) / (8 * 4));
 	return 0;
 }
 
diff --git a/drivers/media/pci/cobalt/cobalt-v4l2.c b/drivers/media/pci/cobalt/cobalt-v4l2.c
index 9756fd3..bca32e2 100644
--- a/drivers/media/pci/cobalt/cobalt-v4l2.c
+++ b/drivers/media/pci/cobalt/cobalt-v4l2.c
@@ -81,9 +81,9 @@ static int cobalt_buf_init(struct vb2_buffer *vb)
 	int ret;
 
 	size = s->stride * s->height;
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		cobalt_info("data will not fit into plane (%lu < %u)\n",
-					vb2_plane_size(vb, 0), size);
+					vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
 
@@ -114,7 +114,7 @@ static int cobalt_buf_prepare(struct vb2_buffer *vb)
 {
 	struct cobalt_stream *s = vb->vb2_queue->drv_priv;
 
-	vb2_set_plane_payload(vb, 0, s->stride * s->height);
+	vb2_v4l2_set_plane_payload(vb, 0, s->stride * s->height);
 	vb->v4l2_buf.field = V4L2_FIELD_NONE;
 	return 0;
 }
@@ -1229,7 +1229,7 @@ static int cobalt_node_register(struct cobalt *cobalt, int node)
 	vdev->queue = q;
 
 	video_set_drvdata(vdev, s);
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (!s->is_audio && ret == 0)
 		ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
 	else if (!s->is_dummy)
diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c
index 88a3afb..eecacf6 100644
--- a/drivers/media/pci/cx23885/cx23885-417.c
+++ b/drivers/media/pci/cx23885/cx23885-417.c
@@ -1554,7 +1554,7 @@ int cx23885_417_register(struct cx23885_dev *dev)
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &dev->lock;
 
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err < 0)
 		return err;
 	video_set_drvdata(dev->v4l_device, dev);
diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
index bbea734..0767d5f 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -1456,9 +1456,9 @@ int cx23885_buf_prepare(struct cx23885_buffer *buf, struct cx23885_tsport *port)
 	struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb.vb2_buf, 0);
 
 	dprintk(1, "%s: %p\n", __func__, buf);
-	if (vb2_plane_size(&buf->vb.vb2_buf, 0) < size)
+	if (vb2_v4l2_plane_size(&buf->vb.vb2_buf, 0) < size)
 		return -EINVAL;
-	vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
+	vb2_v4l2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
 
 	cx23885_risc_databuffer(dev->pci, &buf->risc,
 				sgt->sgl,
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index c4307ad..440a247 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -2395,7 +2395,7 @@ int cx23885_dvb_register(struct cx23885_tsport *port)
 		q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 		q->lock = &dev->lock;
 
-		err = vb2_queue_init(q);
+		err = vb2_v4l2_queue_init(q);
 		if (err < 0)
 			return err;
 	}
diff --git a/drivers/media/pci/cx23885/cx23885-vbi.c b/drivers/media/pci/cx23885/cx23885-vbi.c
index d1fd585..19b91cc 100644
--- a/drivers/media/pci/cx23885/cx23885-vbi.c
+++ b/drivers/media/pci/cx23885/cx23885-vbi.c
@@ -148,9 +148,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	if (dev->tvnorm & V4L2_STD_525_60)
 		lines = VBI_NTSC_LINE_COUNT;
 
-	if (vb2_plane_size(vb, 0) < lines * VBI_LINE_LENGTH * 2)
+	if (vb2_v4l2_plane_size(vb, 0) < lines * VBI_LINE_LENGTH * 2)
 		return -EINVAL;
-	vb2_set_plane_payload(vb, 0, lines * VBI_LINE_LENGTH * 2);
+	vb2_v4l2_set_plane_payload(vb, 0, lines * VBI_LINE_LENGTH * 2);
 
 	cx23885_risc_vbibuffer(dev->pci, &buf->risc,
 			 sgt->sgl,
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index d7c6729..c427cf8 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -339,9 +339,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 	buf->bpl = (dev->width * dev->fmt->depth) >> 3;
 
-	if (vb2_plane_size(vb, 0) < dev->height * buf->bpl)
+	if (vb2_v4l2_plane_size(vb, 0) < dev->height * buf->bpl)
 		return -EINVAL;
-	vb2_set_plane_payload(vb, 0, dev->height * buf->bpl);
+	vb2_v4l2_set_plane_payload(vb, 0, dev->height * buf->bpl);
 
 	switch (dev->field) {
 	case V4L2_FIELD_TOP:
@@ -1230,7 +1230,7 @@ int cx23885_video_register(struct cx23885_dev *dev)
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &dev->lock;
 
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err < 0)
 		goto fail_unreg;
 
@@ -1246,7 +1246,7 @@ int cx23885_video_register(struct cx23885_dev *dev)
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &dev->lock;
 
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err < 0)
 		goto fail_unreg;
 
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c
index 5e672f2..3e72b05 100644
--- a/drivers/media/pci/cx25821/cx25821-video.c
+++ b/drivers/media/pci/cx25821/cx25821-video.c
@@ -175,9 +175,9 @@ static int cx25821_buffer_prepare(struct vb2_buffer *vb)
 	else
 		buf->bpl = (chan->fmt->depth >> 3) * chan->width;
 
-	if (vb2_plane_size(vb, 0) < chan->height * buf->bpl)
+	if (vb2_v4l2_plane_size(vb, 0) < chan->height * buf->bpl)
 		return -EINVAL;
-	vb2_set_plane_payload(vb, 0, chan->height * buf->bpl);
+	vb2_v4l2_set_plane_payload(vb, 0, chan->height * buf->bpl);
 	buf->vb.v4l2_buf.field = chan->field;
 
 	if (chan->pixel_formats == PIXEL_FRMT_411) {
@@ -761,7 +761,7 @@ int cx25821_video_register(struct cx25821_dev *dev)
 		q->lock = &dev->lock;
 
 		if (!is_output) {
-			err = vb2_queue_init(q);
+			err = vb2_v4l2_queue_init(q);
 			if (err < 0)
 				goto fail_unreg;
 		}
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index 8b88913..3a06065 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -1184,7 +1184,7 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &core->lock;
 
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err < 0)
 		goto fail_core;
 
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index f048350..9c4f275 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -1793,7 +1793,7 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
 		q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 		q->lock = &core->lock;
 
-		err = vb2_queue_init(q);
+		err = vb2_v4l2_queue_init(q);
 		if (err < 0)
 			goto fail_probe;
 
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index a315cd6..91de60d 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -229,9 +229,9 @@ int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev,
 	struct cx88_riscmem *risc = &buf->risc;
 	int rc;
 
-	if (vb2_plane_size(&buf->vb.vb2_buf, 0) < size)
+	if (vb2_v4l2_plane_size(&buf->vb.vb2_buf, 0) < size)
 		return -EINVAL;
-	vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
+	vb2_v4l2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
 
 	rc = cx88_risc_databuffer(dev->pci, risc, sgt->sgl,
 			     dev->ts_packet_size, dev->ts_packet_count, 0);
diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c
index 2bdfbb9..629df46 100644
--- a/drivers/media/pci/cx88/cx88-vbi.c
+++ b/drivers/media/pci/cx88/cx88-vbi.c
@@ -137,9 +137,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	else
 		lines = VBI_LINE_PAL_COUNT;
 	size = lines * VBI_LINE_LENGTH * 2;
-	if (vb2_plane_size(vb, 0) < size)
+	if (vb2_v4l2_plane_size(vb, 0) < size)
 		return -EINVAL;
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	cx88_risc_buffer(dev->pci, &buf->risc, sgt->sgl,
 			 0, VBI_LINE_LENGTH * lines,
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index 4af3808..5a72a1c 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -452,9 +452,9 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 	buf->bpl = core->width * dev->fmt->depth >> 3;
 
-	if (vb2_plane_size(vb, 0) < core->height * buf->bpl)
+	if (vb2_v4l2_plane_size(vb, 0) < core->height * buf->bpl)
 		return -EINVAL;
-	vb2_set_plane_payload(vb, 0, core->height * buf->bpl);
+	vb2_v4l2_set_plane_payload(vb, 0, core->height * buf->bpl);
 
 	switch (core->field) {
 	case V4L2_FIELD_TOP:
@@ -1446,7 +1446,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &core->lock;
 
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err < 0)
 		goto fail_unreg;
 
@@ -1462,7 +1462,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &core->lock;
 
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err < 0)
 		goto fail_unreg;
 
diff --git a/drivers/media/pci/dt3155/dt3155.c b/drivers/media/pci/dt3155/dt3155.c
index 0aa45d0..1dc69e5 100644
--- a/drivers/media/pci/dt3155/dt3155.c
+++ b/drivers/media/pci/dt3155/dt3155.c
@@ -155,7 +155,7 @@ static int dt3155_buf_prepare(struct vb2_buffer *vb)
 {
 	struct dt3155_priv *pd = vb2_get_drv_priv(vb->vb2_queue);
 
-	vb2_set_plane_payload(vb, 0, pd->width * pd->height);
+	vb2_v4l2_set_plane_payload(vb, 0, pd->width * pd->height);
 	return 0;
 }
 
@@ -547,7 +547,7 @@ static int dt3155_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	pd->vidq.gfp_flags = GFP_DMA32;
 	pd->vidq.lock = &pd->mux; /* for locking v4l2_file_operations */
 	pd->vdev.queue = &pd->vidq;
-	err = vb2_queue_init(&pd->vidq);
+	err = vb2_v4l2_queue_init(&pd->vidq);
 	if (err < 0)
 		goto err_v4l2_dev_unreg;
 	pd->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
@@ -605,7 +605,7 @@ static void dt3155_remove(struct pci_dev *pdev)
 
 	video_unregister_device(&pd->vdev);
 	free_irq(pd->pdev->irq, pd);
-	vb2_queue_release(&pd->vidq);
+	vb2_v4l2_queue_release(&pd->vidq);
 	v4l2_device_unregister(&pd->v4l2_dev);
 	pci_iounmap(pdev, pd->regs);
 	pci_release_region(pdev, 0);
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index 7d76e59..c695e47 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -216,7 +216,7 @@ int saa7134_buffer_count(unsigned int size, unsigned int count)
 
 int saa7134_buffer_startpage(struct saa7134_buf *buf)
 {
-	return saa7134_buffer_pages(vb2_plane_size(&buf->vb2.vb2_buf, 0)) * buf->vb2.v4l2_buf.index;
+	return saa7134_buffer_pages(vb2_v4l2_plane_size(&buf->vb2.vb2_buf, 0)) * buf->vb2.v4l2_buf.index;
 }
 
 unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
diff --git a/drivers/media/pci/saa7134/saa7134-dvb.c b/drivers/media/pci/saa7134/saa7134-dvb.c
index 101ba87..37be45b 100644
--- a/drivers/media/pci/saa7134/saa7134-dvb.c
+++ b/drivers/media/pci/saa7134/saa7134-dvb.c
@@ -1238,7 +1238,7 @@ static int dvb_init(struct saa7134_dev *dev)
 	q->buf_struct_size = sizeof(struct saa7134_buf);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &dev->lock;
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret) {
 		vb2_dvb_dealloc_frontends(&dev->frontends);
 		return ret;
@@ -1901,7 +1901,7 @@ static int dvb_init(struct saa7134_dev *dev)
 
 detach_frontend:
 	vb2_dvb_dealloc_frontends(&dev->frontends);
-	vb2_queue_release(&fe0->dvb.dvbq);
+	vb2_v4l2_queue_release(&fe0->dvb.dvbq);
 	return -EINVAL;
 }
 
@@ -1942,7 +1942,7 @@ static int dvb_fini(struct saa7134_dev *dev)
 		}
 	}
 	vb2_dvb_unregister_bus(&dev->frontends);
-	vb2_queue_release(&fe0->dvb.dvbq);
+	vb2_v4l2_queue_release(&fe0->dvb.dvbq);
 	return 0;
 }
 
diff --git a/drivers/media/pci/saa7134/saa7134-empress.c b/drivers/media/pci/saa7134/saa7134-empress.c
index 56b932c..2085218 100644
--- a/drivers/media/pci/saa7134/saa7134-empress.c
+++ b/drivers/media/pci/saa7134/saa7134-empress.c
@@ -294,7 +294,7 @@ static int empress_init(struct saa7134_dev *dev)
 	q->buf_struct_size = sizeof(struct saa7134_buf);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &dev->lock;
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err)
 		return err;
 	dev->empress_dev->queue = q;
@@ -324,7 +324,7 @@ static int empress_fini(struct saa7134_dev *dev)
 		return 0;
 	flush_work(&dev->empress_workqueue);
 	video_unregister_device(dev->empress_dev);
-	vb2_queue_release(&dev->empress_vbq);
+	vb2_v4l2_queue_release(&dev->empress_vbq);
 	v4l2_ctrl_handler_free(&dev->empress_ctrl_handler);
 	dev->empress_dev = NULL;
 	return 0;
diff --git a/drivers/media/pci/saa7134/saa7134-ts.c b/drivers/media/pci/saa7134/saa7134-ts.c
index b19a00f..55ca3e1 100644
--- a/drivers/media/pci/saa7134/saa7134-ts.c
+++ b/drivers/media/pci/saa7134/saa7134-ts.c
@@ -105,10 +105,10 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb)
 	lines = dev->ts.nr_packets;
 
 	size = lines * llength;
-	if (vb2_plane_size(vb, 0) < size)
+	if (vb2_v4l2_plane_size(vb, 0) < size)
 		return -EINVAL;
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 	vbuf->v4l2_buf.field = dev->field;
 
 	return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents,
diff --git a/drivers/media/pci/saa7134/saa7134-vbi.c b/drivers/media/pci/saa7134/saa7134-vbi.c
index c3cdb89..2903e83 100644
--- a/drivers/media/pci/saa7134/saa7134-vbi.c
+++ b/drivers/media/pci/saa7134/saa7134-vbi.c
@@ -129,10 +129,10 @@ static int buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 	size = dev->vbi_hlen * dev->vbi_vlen * 2;
-	if (vb2_plane_size(vb, 0) < size)
+	if (vb2_v4l2_plane_size(vb, 0) < size)
 		return -EINVAL;
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents,
 				    saa7134_buffer_startpage(buf));
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 7ea9411..20821a7 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -894,10 +894,10 @@ static int buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 	size = (dev->width * dev->height * dev->fmt->depth) >> 3;
-	if (vb2_plane_size(vb, 0) < size)
+	if (vb2_v4l2_plane_size(vb, 0) < size)
 		return -EINVAL;
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 	vbuf->v4l2_buf.field = dev->field;
 
 	return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents,
@@ -2099,7 +2099,7 @@ int saa7134_video_init1(struct saa7134_dev *dev)
 	q->buf_struct_size = sizeof(struct saa7134_buf);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &dev->lock;
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret)
 		return ret;
 	saa7134_pgtable_alloc(dev->pci, &dev->video_q.pt);
@@ -2117,7 +2117,7 @@ int saa7134_video_init1(struct saa7134_dev *dev)
 	q->buf_struct_size = sizeof(struct saa7134_buf);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &dev->lock;
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret)
 		return ret;
 	saa7134_pgtable_alloc(dev->pci, &dev->vbi_q.pt);
@@ -2128,9 +2128,9 @@ int saa7134_video_init1(struct saa7134_dev *dev)
 void saa7134_video_fini(struct saa7134_dev *dev)
 {
 	/* free stuff */
-	vb2_queue_release(&dev->video_vbq);
+	vb2_v4l2_queue_release(&dev->video_vbq);
 	saa7134_pgtable_free(dev->pci, &dev->video_q.pt);
-	vb2_queue_release(&dev->vbi_vbq);
+	vb2_v4l2_queue_release(&dev->vbi_vbq);
 	saa7134_pgtable_free(dev->pci, &dev->vbi_q.pt);
 	v4l2_ctrl_handler_free(&dev->ctrl_handler);
 	if (card_has_radio(dev))
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
index 19dc488..06874a5 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
@@ -464,11 +464,11 @@ static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
 
 	vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
 
-	if (vb2_plane_size(&vb->vb2_buf, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len)
+	if (vb2_v4l2_plane_size(&vb->vb2_buf, 0) < vop_jpeg_size(vh) + solo_enc->jpeg_len)
 		return -EIO;
 
 	frame_size = ALIGN(vop_jpeg_size(vh) + solo_enc->jpeg_len, DMA_ALIGN);
-	vb2_set_plane_payload(&vb->vb2_buf, 0,
+	vb2_v4l2_set_plane_payload(&vb->vb2_buf, 0,
 			      vop_jpeg_size(vh) + solo_enc->jpeg_len);
 
 	return solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf,
@@ -485,7 +485,7 @@ static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
 	int frame_off, frame_size;
 	int skip = 0;
 
-	if (vb2_plane_size(&vb->vb2_buf, 0) < vop_mpeg_size(vh))
+	if (vb2_v4l2_plane_size(&vb->vb2_buf, 0) < vop_mpeg_size(vh))
 		return -EIO;
 
 	/* If this is a key frame, add extra header */
@@ -494,11 +494,11 @@ static int solo_fill_mpeg(struct solo_enc_dev *solo_enc,
 	if (!vop_type(vh)) {
 		skip = solo_enc->vop_len;
 		vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
-		vb2_set_plane_payload(&vb->vb2_buf, 0,
+		vb2_v4l2_set_plane_payload(&vb->vb2_buf, 0,
 				      vop_mpeg_size(vh) + solo_enc->vop_len);
 	} else {
 		vb->v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
-		vb2_set_plane_payload(&vb->vb2_buf, 0, vop_mpeg_size(vh));
+		vb2_v4l2_set_plane_payload(&vb->vb2_buf, 0, vop_mpeg_size(vh));
 	}
 
 	/* Now get the actual mpeg payload */
@@ -1298,7 +1298,7 @@ static struct solo_enc_dev *solo_enc_alloc(struct solo_dev *solo_dev,
 	solo_enc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	solo_enc->vidq.buf_struct_size = sizeof(struct solo_vb2_buf);
 	solo_enc->vidq.lock = &solo_enc->lock;
-	ret = vb2_queue_init(&solo_enc->vidq);
+	ret = vb2_v4l2_queue_init(&solo_enc->vidq);
 	if (ret)
 		goto hdl_free;
 	solo_update_mode(solo_enc);
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2.c b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
index 628d019..cbef85b 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2.c
@@ -220,7 +220,7 @@ static void solo_fillbuf(struct solo_dev *solo_dev,
 
 finish_buf:
 	if (!error) {
-		vb2_set_plane_payload(&vb->vb2_buf, 0,
+		vb2_v4l2_set_plane_payload(&vb->vb2_buf, 0,
 				      solo_vlines(solo_dev) * solo_bytesperline(solo_dev));
 		vb->v4l2_buf.sequence = solo_dev->sequence++;
 		v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
@@ -680,7 +680,7 @@ int solo_v4l2_init(struct solo_dev *solo_dev, unsigned nr)
 	solo_dev->vidq.gfp_flags = __GFP_DMA32;
 	solo_dev->vidq.buf_struct_size = sizeof(struct solo_vb2_buf);
 	solo_dev->vidq.lock = &solo_dev->lock;
-	ret = vb2_queue_init(&solo_dev->vidq);
+	ret = vb2_v4l2_queue_init(&solo_dev->vidq);
 	if (ret < 0)
 		goto fail;
 
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index a4dc2d5..b4fa408 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -303,13 +303,13 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	unsigned long size;
 
 	size = vip->format.sizeimage;
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		v4l2_err(&vip->v4l2_dev, "buffer too small (%lu < %lu)\n",
-			 vb2_plane_size(vb, 0), size);
+			 vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -870,7 +870,7 @@ static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
 	vip->vb_vidq.ops = &vip_video_qops;
 	vip->vb_vidq.mem_ops = &vb2_dma_contig_memops;
 	vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	err = vb2_queue_init(&vip->vb_vidq);
+	err = vb2_v4l2_queue_init(&vip->vb_vidq);
 	if (err)
 		return err;
 	INIT_LIST_HEAD(&vip->buffer_list);
@@ -1132,7 +1132,7 @@ release_buf:
 	sta2x11_vip_release_buffer(vip);
 	pci_disable_msi(pdev);
 unmap:
-	vb2_queue_release(&vip->vb_vidq);
+	vb2_v4l2_queue_release(&vip->vb_vidq);
 	pci_iounmap(pdev, vip->iomem);
 release:
 	pci_release_regions(pdev);
@@ -1175,7 +1175,7 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
 	video_unregister_device(&vip->video_dev);
 	free_irq(pdev->irq, vip);
 	pci_disable_msi(pdev);
-	vb2_queue_release(&vip->vb_vidq);
+	vb2_v4l2_queue_release(&vip->vb_vidq);
 	pci_iounmap(pdev, vip->iomem);
 	pci_release_regions(pdev);
 
diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c
index 82dbc9a..7d6995f 100644
--- a/drivers/media/pci/tw68/tw68-video.c
+++ b/drivers/media/pci/tw68/tw68-video.c
@@ -467,9 +467,9 @@ static int tw68_buf_prepare(struct vb2_buffer *vb)
 	unsigned size, bpl;
 
 	size = (dev->width * dev->height * dev->fmt->depth) >> 3;
-	if (vb2_plane_size(vb, 0) < size)
+	if (vb2_v4l2_plane_size(vb, 0) < size)
 		return -EINVAL;
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	bpl = (dev->width * dev->fmt->depth) >> 3;
 	switch (dev->field) {
@@ -983,7 +983,7 @@ int tw68_video_init2(struct tw68_dev *dev, int video_nr)
 	dev->vidq.buf_struct_size = sizeof(struct tw68_buf);
 	dev->vidq.lock = &dev->lock;
 	dev->vidq.min_buffers_needed = 2;
-	ret = vb2_queue_init(&dev->vidq);
+	ret = vb2_v4l2_queue_init(&dev->vidq);
 	if (ret)
 		return ret;
 	dev->vdev = tw68_video_template;
diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
index 794408b..64ab941 100644
--- a/drivers/media/platform/am437x/am437x-vpfe.c
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -1937,7 +1937,7 @@ static int vpfe_queue_setup(struct vb2_queue *vq,
  * vpfe_buffer_prepare :  callback function for buffer prepare
  * @vb: ptr to vb2_buffer
  *
- * This is the callback function for buffer prepare when vb2_qbuf()
+ * This is the callback function for buffer prepare when vb2_v4l2_qbuf()
  * function is called. The buffer is prepared and user space virtual address
  * or user address is converted into  physical address
  */
@@ -1946,9 +1946,9 @@ static int vpfe_buffer_prepare(struct vb2_buffer *vb)
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
 
-	vb2_set_plane_payload(vb, 0, vpfe->fmt.fmt.pix.sizeimage);
+	vb2_v4l2_set_plane_payload(vb, 0, vpfe->fmt.fmt.pix.sizeimage);
 
-	if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
+	if (vb2_v4l2_get_plane_payload(vb, 0) > vb2_v4l2_plane_size(vb, 0))
 		return -EINVAL;
 
 	vbuf->v4l2_buf.field = vpfe->fmt.fmt.pix.field;
@@ -2381,9 +2381,9 @@ static int vpfe_probe_complete(struct vpfe_device *vpfe)
 	q->lock = &vpfe->lock;
 	q->min_buffers_needed = 1;
 
-	err = vb2_queue_init(q);
+	err = vb2_v4l2_queue_init(q);
 	if (err) {
-		vpfe_err(vpfe, "vb2_queue_init() failed\n");
+		vpfe_err(vpfe, "vb2_v4l2_queue_init() failed\n");
 		vb2_dma_contig_cleanup_ctx(vpfe->alloc_ctx);
 		goto probe_out;
 	}
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index 1c87afe..543cf93 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -227,12 +227,12 @@ static int bcap_buffer_prepare(struct vb2_buffer *vb)
 	struct bcap_device *bcap_dev = vb2_get_drv_priv(vb->vb2_queue);
 	unsigned long size = bcap_dev->fmt.sizeimage;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		v4l2_err(&bcap_dev->v4l2_dev, "buffer too small (%lu < %lu)\n",
-				vb2_plane_size(vb, 0), size);
+				vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 	vbuf->v4l2_buf.field = bcap_dev->fmt.field;
 
 	return 0;
@@ -861,7 +861,7 @@ static int bcap_probe(struct platform_device *pdev)
 	q->lock = &bcap_dev->mutex;
 	q->min_buffers_needed = 1;
 
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret)
 		goto err_free_handler;
 
diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 1b5e9ae..af69cd0 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -181,7 +181,7 @@ static void coda_kfifo_sync_to_device_write(struct coda_ctx *ctx)
 static int coda_bitstream_queue(struct coda_ctx *ctx,
 				struct vb2_v4l2_buffer *src_buf)
 {
-	u32 src_size = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
+	u32 src_size = vb2_v4l2_get_plane_payload(&src_buf->vb2_buf, 0);
 	u32 n;
 
 	n = kfifo_in(&ctx->bitstream_fifo,
@@ -201,7 +201,7 @@ static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
 	int ret;
 
 	if (coda_get_bitstream_payload(ctx) +
-	    vb2_get_plane_payload(&src_buf->vb2_buf, 0) + 512 >= ctx->bitstream.size)
+	    vb2_v4l2_get_plane_payload(&src_buf->vb2_buf, 0) + 512 >= ctx->bitstream.size)
 		return false;
 
 	if (vb2_plane_vaddr(&src_buf->vb2_buf, 0) == NULL) {
@@ -490,7 +490,7 @@ static int coda_encode_header(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf,
 
 	coda_write(dev, vb2_dma_contig_plane_dma_addr(&buf->vb2_buf, 0),
 		   CODA_CMD_ENC_HEADER_BB_START);
-	bufsize = vb2_plane_size(&buf->vb2_buf, 0);
+	bufsize = vb2_v4l2_plane_size(&buf->vb2_buf, 0);
 	if (dev->devtype->product == CODA_960)
 		bufsize /= 1024;
 	coda_write(dev, bufsize, CODA_CMD_ENC_HEADER_BB_SIZE);
@@ -1333,10 +1333,10 @@ static void coda_finish_encode(struct coda_ctx *ctx)
 
 	/* Calculate bytesused field */
 	if (dst_buf->v4l2_buf.sequence == 0) {
-		vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+		vb2_v4l2_set_plane_payload(&dst_buf->vb2_buf, 0,
 				      wr_ptr - start_ptr + ctx->vpu_header_size[0] + ctx->vpu_header_size[1] + ctx->vpu_header_size[2]);
 	} else {
-		vb2_set_plane_payload(&dst_buf->vb2_buf, 0,
+		vb2_v4l2_set_plane_payload(&dst_buf->vb2_buf, 0,
 				      wr_ptr - start_ptr);
 	}
 
@@ -2045,7 +2045,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 			payload = width * height * 2;
 			break;
 		}
-		vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload);
+		vb2_v4l2_set_plane_payload(&dst_buf->vb2_buf, 0, payload);
 
 		coda_m2m_buf_done(ctx, dst_buf, ctx->frame_errors[display_idx] ?
 				  VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 10c4a9e..a27c8d5 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1161,10 +1161,10 @@ static int coda_buf_prepare(struct vb2_buffer *vb)
 
 	q_data = get_q_data(ctx, vb->vb2_queue->type);
 
-	if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
+	if (vb2_v4l2_plane_size(vb, 0) < q_data->sizeimage) {
 		v4l2_warn(&ctx->dev->v4l2_dev,
 			  "%s data will not fit into plane (%lu < %lu)\n",
-			  __func__, vb2_plane_size(vb, 0),
+			  __func__, vb2_v4l2_plane_size(vb, 0),
 			  (long)q_data->sizeimage);
 		return -EINVAL;
 	}
@@ -1190,7 +1190,7 @@ static void coda_buf_queue(struct vb2_buffer *vb)
 		 * For backwards compatibility, queuing an empty buffer marks
 		 * the stream end
 		 */
-		if (vb2_get_plane_payload(vb, 0) == 0)
+		if (vb2_v4l2_get_plane_payload(vb, 0) == 0)
 			coda_bit_stream_end_flag(ctx);
 		mutex_lock(&ctx->bitstream_mutex);
 		v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf);
@@ -1601,7 +1601,7 @@ static int coda_queue_init(struct coda_ctx *ctx, struct vb2_queue *vq)
 	 */
 	vq->allow_zero_bytesused = 1;
 
-	return vb2_queue_init(vq);
+	return vb2_v4l2_queue_init(vq);
 }
 
 int coda_encoder_queue_init(void *priv, struct vb2_queue *src_vq,
diff --git a/drivers/media/platform/coda/coda-jpeg.c b/drivers/media/platform/coda/coda-jpeg.c
index 0d09ffd..350f2ca 100644
--- a/drivers/media/platform/coda/coda-jpeg.c
+++ b/drivers/media/platform/coda/coda-jpeg.c
@@ -183,7 +183,7 @@ bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_v4l2_buffer *vb)
 	void *vaddr = vb2_plane_vaddr(&vb->vb2_buf, 0);
 	u16 soi = be16_to_cpup((__be16 *)vaddr);
 	u16 eoi = be16_to_cpup((__be16 *)(vaddr +
-					  vb2_get_plane_payload(&vb->vb2_buf, 0) - 2));
+					  vb2_v4l2_get_plane_payload(&vb->vb2_buf, 0) - 2));
 
 	return soi == SOI_MARKER && eoi == EOI_MARKER;
 }
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index c0703aa..b5012ab 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -196,7 +196,7 @@ static irqreturn_t venc_isr(int irq, void *arg)
 
 /*
  * vpbe_buffer_prepare()
- * This is the callback function called from vb2_qbuf() function
+ * This is the callback function called from vb2_v4l2_qbuf() function
  * the buffer is prepared and user space virtual address is converted into
  * physical address
  */
@@ -210,8 +210,8 @@ static int vpbe_buffer_prepare(struct vb2_buffer *vb)
 	v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
 				"vpbe_buffer_prepare\n");
 
-	vb2_set_plane_payload(vb, 0, layer->pix_fmt.sizeimage);
-	if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
+	vb2_v4l2_set_plane_payload(vb, 0, layer->pix_fmt.sizeimage);
+	if (vb2_v4l2_get_plane_payload(vb, 0) > vb2_v4l2_plane_size(vb, 0))
 		return -EINVAL;
 
 	addr = vb2_dma_contig_plane_dma_addr(vb, 0);
@@ -1448,9 +1448,9 @@ static int vpbe_display_probe(struct platform_device *pdev)
 		q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 		q->min_buffers_needed = 1;
 		q->lock = &disp_dev->dev[i]->opslock;
-		err = vb2_queue_init(q);
+		err = vb2_v4l2_queue_init(q);
 		if (err) {
-			v4l2_err(v4l2_dev, "vb2_queue_init() failed\n");
+			v4l2_err(v4l2_dev, "vb2_v4l2_queue_init() failed\n");
 			goto probe_out;
 		}
 
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index b583ff1..f76e1f5 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -66,7 +66,7 @@ static inline struct vpif_cap_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb)
  * vpif_buffer_prepare :  callback function for buffer prepare
  * @vb: ptr to vb2_buffer
  *
- * This is the callback function for buffer prepare when vb2_qbuf()
+ * This is the callback function for buffer prepare when vb2_v4l2_qbuf()
  * function is called. The buffer is prepared and user space virtual address
  * or user address is converted into  physical address
  */
@@ -82,8 +82,8 @@ static int vpif_buffer_prepare(struct vb2_buffer *vb)
 
 	common = &ch->common[VPIF_VIDEO_INDEX];
 
-	vb2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
-	if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
+	vb2_v4l2_set_plane_payload(vb, 0, common->fmt.fmt.pix.sizeimage);
+	if (vb2_v4l2_get_plane_payload(vb, 0) > vb2_v4l2_plane_size(vb, 0))
 		return -EINVAL;
 
 	vbuf->v4l2_buf.field = common->fmt.fmt.pix.field;
@@ -1373,9 +1373,9 @@ static int vpif_probe_complete(void)
 		q->min_buffers_needed = 1;
 		q->lock = &common->lock;
 
-		err = vb2_queue_init(q);
+		err = vb2_v4l2_queue_init(q);
 		if (err) {
-			vpif_err("vpif_capture: vb2_queue_init() failed\n");
+			vpif_err("vpif_capture: vb2_v4l2_queue_init() failed\n");
 			goto probe_out;
 		}
 
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index f7963bd..c5e18d7 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -62,7 +62,7 @@ static inline struct vpif_disp_buffer *to_vpif_buffer(struct vb2_v4l2_buffer *vb
  * vpif_buffer_prepare :  callback function for buffer prepare
  * @vb: ptr to vb2_buffer
  *
- * This is the callback function for buffer prepare when vb2_qbuf()
+ * This is the callback function for buffer prepare when vb2_v4l2_qbuf()
  * function is called. The buffer is prepared and user space virtual address
  * or user address is converted into  physical address
  */
@@ -73,8 +73,8 @@ static int vpif_buffer_prepare(struct vb2_v4l2_buffer *vb)
 
 	common = &ch->common[VPIF_VIDEO_INDEX];
 
-	vb2_set_plane_payload(&vb->vb2_buf, 0, common->fmt.fmt.pix.sizeimage);
-	if (vb2_get_plane_payload(&vb->vb2_buf, 0) > vb2_plane_size(&vb->vb2_buf, 0))
+	vb2_v4l2_set_plane_payload(&vb->vb2_buf, 0, common->fmt.fmt.pix.sizeimage);
+	if (vb2_v4l2_get_plane_payload(&vb->vb2_buf, 0) > vb2_v4l2_plane_size(&vb->vb2_buf, 0))
 		return -EINVAL;
 
 	vb->v4l2_buf.field = common->fmt.fmt.pix.field;
@@ -1189,9 +1189,9 @@ static int vpif_probe_complete(void)
 		q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 		q->min_buffers_needed = 1;
 		q->lock = &common->lock;
-		err = vb2_queue_init(q);
+		err = vb2_v4l2_queue_init(q);
 		if (err) {
-			vpif_err("vpif_display: vb2_queue_init() failed\n");
+			vpif_err("vpif_display: vb2_v4l2_queue_init() failed\n");
 			goto probe_out;
 		}
 
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 95df3a9..a1f691a 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -246,7 +246,7 @@ static int gsc_m2m_buf_prepare(struct vb2_buffer *vb)
 
 	if (!V4L2_TYPE_IS_OUTPUT(vb->vb2_queue->type)) {
 		for (i = 0; i < frame->fmt->num_planes; i++)
-			vb2_set_plane_payload(vb, i, frame->payload[i]);
+			vb2_v4l2_set_plane_payload(vb, i, frame->payload[i]);
 	}
 
 	return 0;
@@ -592,7 +592,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &ctx->gsc_dev->lock;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -606,7 +606,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->gsc_dev->lock;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 static int gsc_m2m_open(struct file *file)
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 01bb3d7..dbe4b9b 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -398,13 +398,13 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	for (i = 0; i < ctx->d_frame.fmt->memplanes; i++) {
 		unsigned long size = ctx->d_frame.payload[i];
 
-		if (vb2_plane_size(vb, i) < size) {
+		if (vb2_v4l2_plane_size(vb, i) < size) {
 			v4l2_err(&ctx->fimc_dev->vid_cap.ve.vdev,
 				 "User buffer too small (%ld < %ld)\n",
-				 vb2_plane_size(vb, i), size);
+				 vb2_v4l2_plane_size(vb, i), size);
 			return -EINVAL;
 		}
-		vb2_set_plane_payload(vb, i, size);
+		vb2_v4l2_set_plane_payload(vb, i, size);
 	}
 
 	return 0;
@@ -1475,7 +1475,7 @@ void fimc_sensor_notify(struct v4l2_subdev *sd, unsigned int notification,
 		if (!list_empty(&fimc->vid_cap.active_buf_q)) {
 			buf = list_entry(fimc->vid_cap.active_buf_q.next,
 					 struct fimc_vid_buffer, list);
-			vb2_set_plane_payload(&buf->vb.vb2_buf, 0,
+			vb2_v4l2_set_plane_payload(&buf->vb.vb2_buf, 0,
 					      *((u32 *)arg));
 		}
 		fimc_capture_irq_handler(fimc, 1);
@@ -1789,7 +1789,7 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &fimc->lock;
 
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret)
 		goto err_free_ctx;
 
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 2383724..95338e8 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -170,13 +170,13 @@ static int isp_video_capture_buffer_prepare(struct vb2_buffer *vb)
 	for (i = 0; i < video->format->memplanes; i++) {
 		unsigned long size = video->pixfmt.plane_fmt[i].sizeimage;
 
-		if (vb2_plane_size(vb, i) < size) {
+		if (vb2_v4l2_plane_size(vb, i) < size) {
 			v4l2_err(&video->ve.vdev,
 				 "User buffer too small (%ld < %ld)\n",
-				 vb2_plane_size(vb, i), size);
+				 vb2_v4l2_plane_size(vb, i), size);
 			return -EINVAL;
 		}
-		vb2_set_plane_payload(vb, i, size);
+		vb2_v4l2_set_plane_payload(vb, i, size);
 	}
 
 	/* Check if we get one of the already known buffers. */
@@ -602,7 +602,7 @@ int fimc_isp_video_device_register(struct fimc_isp *isp,
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &isp->video_lock;
 
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index e9aaee7..f217947 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -410,13 +410,13 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	for (i = 0; i < fimc->out_frame.fmt->memplanes; i++) {
 		unsigned long size = fimc->payload[i];
 
-		if (vb2_plane_size(vb, i) < size) {
+		if (vb2_v4l2_plane_size(vb, i) < size) {
 			v4l2_err(&fimc->ve.vdev,
 				 "User buffer too small (%ld < %ld)\n",
-				 vb2_plane_size(vb, i), size);
+				 vb2_v4l2_plane_size(vb, i), size);
 			return -EINVAL;
 		}
-		vb2_set_plane_payload(vb, i, size);
+		vb2_v4l2_set_plane_payload(vb, i, size);
 	}
 
 	return 0;
@@ -1320,7 +1320,7 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &fimc->lock;
 
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index 06d6436..21696a3 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -213,7 +213,7 @@ static int fimc_buf_prepare(struct vb2_buffer *vb)
 		return PTR_ERR(frame);
 
 	for (i = 0; i < frame->fmt->memplanes; i++)
-		vb2_set_plane_payload(vb, i, frame->payload[i]);
+		vb2_v4l2_set_plane_payload(vb, i, frame->payload[i]);
 
 	return 0;
 }
@@ -564,7 +564,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &ctx->fimc_dev->lock;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -577,7 +577,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->fimc_dev->lock;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 static int fimc_m2m_set_default_format(struct fimc_ctx *ctx)
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index e67f9d2..e2e4348 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -836,13 +836,13 @@ static int deinterlace_buf_prepare(struct vb2_buffer *vb)
 
 	q_data = get_q_data(vb->vb2_queue->type);
 
-	if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
+	if (vb2_v4l2_plane_size(vb, 0) < q_data->sizeimage) {
 		dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n",
-			__func__, vb2_plane_size(vb, 0), (long)q_data->sizeimage);
+			__func__, vb2_v4l2_plane_size(vb, 0), (long)q_data->sizeimage);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, q_data->sizeimage);
+	vb2_v4l2_set_plane_payload(vb, 0, q_data->sizeimage);
 
 	return 0;
 }
@@ -880,7 +880,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	q_data[V4L2_M2M_SRC].sizeimage = (640 * 480 * 3) / 2;
 	q_data[V4L2_M2M_SRC].field = V4L2_FIELD_SEQ_TB;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -897,7 +897,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	q_data[V4L2_M2M_DST].sizeimage = (640 * 480 * 3) / 2;
 	q_data[V4L2_M2M_SRC].field = V4L2_FIELD_INTERLACED_TB;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 /*
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index b3735a7..277d91c 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -227,7 +227,7 @@ static void mcam_buffer_done(struct mcam_camera *cam, int frame,
 	vbuf->v4l2_buf.sequence = cam->buf_seq[frame];
 	vbuf->v4l2_buf.field = V4L2_FIELD_NONE;
 	v4l2_get_timestamp(&vbuf->v4l2_buf.timestamp);
-	vb2_set_plane_payload(&vbuf->vb2_buf, 0, cam->pix_format.sizeimage);
+	vb2_v4l2_set_plane_payload(&vbuf->vb2_buf, 0, cam->pix_format.sizeimage);
 	vb2_buffer_done(&vbuf->vb2_buf, VB2_BUF_STATE_DONE);
 }
 
@@ -1305,7 +1305,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
 #endif
 		break;
 	}
-	return vb2_queue_init(vq);
+	return vb2_v4l2_queue_init(vq);
 }
 
 static void mcam_cleanup_vb2(struct mcam_camera *cam)
diff --git a/drivers/media/platform/mx2_emmaprp.c b/drivers/media/platform/mx2_emmaprp.c
index 269e1bc..832d1cb 100644
--- a/drivers/media/platform/mx2_emmaprp.c
+++ b/drivers/media/platform/mx2_emmaprp.c
@@ -726,15 +726,15 @@ static int emmaprp_buf_prepare(struct vb2_buffer *vb)
 
 	q_data = get_q_data(ctx, vb->vb2_queue->type);
 
-	if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
+	if (vb2_v4l2_plane_size(vb, 0) < q_data->sizeimage) {
 		dprintk(ctx->dev, "%s data will not fit into plane"
 				  "(%lu < %lu)\n", __func__,
-				  vb2_plane_size(vb, 0),
+				  vb2_v4l2_plane_size(vb, 0),
 				  (long)q_data->sizeimage);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, q_data->sizeimage);
+	vb2_v4l2_set_plane_payload(vb, 0, q_data->sizeimage);
 
 	return 0;
 }
@@ -767,7 +767,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->mem_ops = &vb2_dma_contig_memops;
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -779,7 +779,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->mem_ops = &vb2_dma_contig_memops;
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 /*
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 65f57a2..3526e8e 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -363,7 +363,7 @@ static int isp_video_buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, vfh->format.fmt.pix.sizeimage);
+	vb2_v4l2_set_plane_payload(vb, 0, vfh->format.fmt.pix.sizeimage);
 	buffer->dma = addr;
 
 	return 0;
@@ -826,7 +826,7 @@ isp_video_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *rb)
 	int ret;
 
 	mutex_lock(&video->queue_lock);
-	ret = vb2_reqbufs(&vfh->queue, rb);
+	ret = vb2_v4l2_reqbufs(&vfh->queue, rb);
 	mutex_unlock(&video->queue_lock);
 
 	return ret;
@@ -840,7 +840,7 @@ isp_video_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
 	int ret;
 
 	mutex_lock(&video->queue_lock);
-	ret = vb2_querybuf(&vfh->queue, b);
+	ret = vb2_v4l2_querybuf(&vfh->queue, b);
 	mutex_unlock(&video->queue_lock);
 
 	return ret;
@@ -854,7 +854,7 @@ isp_video_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
 	int ret;
 
 	mutex_lock(&video->queue_lock);
-	ret = vb2_qbuf(&vfh->queue, b);
+	ret = vb2_v4l2_qbuf(&vfh->queue, b);
 	mutex_unlock(&video->queue_lock);
 
 	return ret;
@@ -868,7 +868,7 @@ isp_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
 	int ret;
 
 	mutex_lock(&video->queue_lock);
-	ret = vb2_dqbuf(&vfh->queue, b, file->f_flags & O_NONBLOCK);
+	ret = vb2_v4l2_dqbuf(&vfh->queue, b, file->f_flags & O_NONBLOCK);
 	mutex_unlock(&video->queue_lock);
 
 	return ret;
@@ -1071,7 +1071,7 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	pipe->field = vfh->format.fmt.pix.field;
 
 	mutex_lock(&video->queue_lock);
-	ret = vb2_streamon(&vfh->queue, type);
+	ret = vb2_v4l2_streamon(&vfh->queue, type);
 	mutex_unlock(&video->queue_lock);
 	if (ret < 0)
 		goto err_check_format;
@@ -1096,7 +1096,7 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 
 err_set_stream:
 	mutex_lock(&video->queue_lock);
-	vb2_streamoff(&vfh->queue, type);
+	vb2_v4l2_streamoff(&vfh->queue, type);
 	mutex_unlock(&video->queue_lock);
 err_check_format:
 	media_entity_pipeline_stop(&video->video.entity);
@@ -1157,7 +1157,7 @@ isp_video_streamoff(struct file *file, void *fh, enum v4l2_buf_type type)
 	omap3isp_video_cancel_stream(video);
 
 	mutex_lock(&video->queue_lock);
-	vb2_streamoff(&vfh->queue, type);
+	vb2_v4l2_streamoff(&vfh->queue, type);
 	mutex_unlock(&video->queue_lock);
 	video->queue = NULL;
 	video->error = false;
@@ -1260,7 +1260,7 @@ static int isp_video_open(struct file *file)
 	queue->buf_struct_size = sizeof(struct isp_buffer);
 	queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
-	ret = vb2_queue_init(&handle->queue);
+	ret = vb2_v4l2_queue_init(&handle->queue);
 	if (ret < 0) {
 		omap3isp_put(video->isp);
 		goto done;
@@ -1292,7 +1292,7 @@ static int isp_video_release(struct file *file)
 	isp_video_streamoff(file, vfh, video->type);
 
 	mutex_lock(&video->queue_lock);
-	vb2_queue_release(&handle->queue);
+	vb2_v4l2_queue_release(&handle->queue);
 	mutex_unlock(&video->queue_lock);
 
 	omap3isp_pipeline_pm_use(&video->video.entity, 0);
@@ -1314,7 +1314,7 @@ static unsigned int isp_video_poll(struct file *file, poll_table *wait)
 	int ret;
 
 	mutex_lock(&video->queue_lock);
-	ret = vb2_poll(&vfh->queue, file, wait);
+	ret = vb2_v4l2_poll(&vfh->queue, file, wait);
 	mutex_unlock(&video->queue_lock);
 
 	return ret;
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index 8f4e9f4..20754a0 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -486,12 +486,12 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	if (vp->out_fmt == NULL)
 		return -EINVAL;
 
-	if (vb2_plane_size(vb, 0) < vp->payload) {
+	if (vb2_v4l2_plane_size(vb, 0) < vp->payload) {
 		v4l2_err(&vp->vdev, "buffer too small: %lu, required: %u\n",
-			 vb2_plane_size(vb, 0), vp->payload);
+			 vb2_v4l2_plane_size(vb, 0), vp->payload);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, vp->payload);
+	vb2_v4l2_set_plane_payload(vb, 0, vp->payload);
 
 	return 0;
 }
@@ -597,7 +597,7 @@ static int s3c_camif_close(struct file *file)
 
 	if (vp->owner == file->private_data) {
 		camif_stop_capture(vp);
-		vb2_queue_release(&vp->vb_queue);
+		vb2_v4l2_queue_release(&vp->vb_queue);
 		vp->owner = NULL;
 	}
 
@@ -621,7 +621,7 @@ static unsigned int s3c_camif_poll(struct file *file,
 	if (vp->owner && vp->owner != file->private_data)
 		ret = -EBUSY;
 	else
-		ret = vb2_poll(&vp->vb_queue, file, wait);
+		ret = vb2_v4l2_poll(&vp->vb_queue, file, wait);
 
 	mutex_unlock(&camif->lock);
 	return ret;
@@ -886,7 +886,7 @@ static int s3c_camif_streamon(struct file *file, void *priv,
 		return ret;
 	}
 
-	return vb2_streamon(&vp->vb_queue, type);
+	return vb2_v4l2_streamon(&vp->vb_queue, type);
 }
 
 static int s3c_camif_streamoff(struct file *file, void *priv,
@@ -904,7 +904,7 @@ static int s3c_camif_streamoff(struct file *file, void *priv,
 	if (vp->owner && vp->owner != priv)
 		return -EBUSY;
 
-	ret = vb2_streamoff(&vp->vb_queue, type);
+	ret = vb2_v4l2_streamoff(&vp->vb_queue, type);
 	if (ret == 0)
 		media_entity_pipeline_stop(&camif->sensor.sd->entity);
 	return ret;
@@ -927,13 +927,13 @@ static int s3c_camif_reqbufs(struct file *file, void *priv,
 	else
 		vp->owner = NULL;
 
-	ret = vb2_reqbufs(&vp->vb_queue, rb);
+	ret = vb2_v4l2_reqbufs(&vp->vb_queue, rb);
 	if (ret < 0)
 		return ret;
 
 	if (rb->count && rb->count < CAMIF_REQ_BUFS_MIN) {
 		rb->count = 0;
-		vb2_reqbufs(&vp->vb_queue, rb);
+		vb2_v4l2_reqbufs(&vp->vb_queue, rb);
 		ret = -ENOMEM;
 	}
 
@@ -948,7 +948,7 @@ static int s3c_camif_querybuf(struct file *file, void *priv,
 			      struct v4l2_buffer *buf)
 {
 	struct camif_vp *vp = video_drvdata(file);
-	return vb2_querybuf(&vp->vb_queue, buf);
+	return vb2_v4l2_querybuf(&vp->vb_queue, buf);
 }
 
 static int s3c_camif_qbuf(struct file *file, void *priv,
@@ -961,7 +961,7 @@ static int s3c_camif_qbuf(struct file *file, void *priv,
 	if (vp->owner && vp->owner != priv)
 		return -EBUSY;
 
-	return vb2_qbuf(&vp->vb_queue, buf);
+	return vb2_v4l2_qbuf(&vp->vb_queue, buf);
 }
 
 static int s3c_camif_dqbuf(struct file *file, void *priv,
@@ -974,7 +974,7 @@ static int s3c_camif_dqbuf(struct file *file, void *priv,
 	if (vp->owner && vp->owner != priv)
 		return -EBUSY;
 
-	return vb2_dqbuf(&vp->vb_queue, buf, file->f_flags & O_NONBLOCK);
+	return vb2_v4l2_dqbuf(&vp->vb_queue, buf, file->f_flags & O_NONBLOCK);
 }
 
 static int s3c_camif_create_bufs(struct file *file, void *priv,
@@ -987,7 +987,7 @@ static int s3c_camif_create_bufs(struct file *file, void *priv,
 		return -EBUSY;
 
 	create->count = max_t(u32, 1, create->count);
-	ret = vb2_create_bufs(&vp->vb_queue, create);
+	ret = vb2_v4l2_create_bufs(&vp->vb_queue, create);
 
 	if (!ret && vp->owner == NULL)
 		vp->owner = priv;
@@ -999,7 +999,7 @@ static int s3c_camif_prepare_buf(struct file *file, void *priv,
 				 struct v4l2_buffer *b)
 {
 	struct camif_vp *vp = video_drvdata(file);
-	return vb2_prepare_buf(&vp->vb_queue, b);
+	return vb2_v4l2_prepare_buf(&vp->vb_queue, b);
 }
 
 static int s3c_camif_g_selection(struct file *file, void *priv,
@@ -1157,7 +1157,7 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &vp->camif->lock;
 
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret)
 		goto err_vd_rel;
 
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 9fade63..e50df5b 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -128,7 +128,7 @@ static int g2d_buf_prepare(struct vb2_buffer *vb)
 
 	if (IS_ERR(f))
 		return PTR_ERR(f);
-	vb2_set_plane_payload(vb, 0, f->size);
+	vb2_v4l2_set_plane_payload(vb, 0, f->size);
 	return 0;
 }
 
@@ -161,7 +161,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &ctx->dev->mutex;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -174,7 +174,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->dev->mutex;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 static int g2d_s_ctrl(struct v4l2_ctrl *ctrl)
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 8fd178d..a9fccf5 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -2157,14 +2157,14 @@ static int s5p_jpeg_buf_prepare(struct vb2_buffer *vb)
 	q_data = get_q_data(ctx, vb->vb2_queue->type);
 	BUG_ON(q_data == NULL);
 
-	if (vb2_plane_size(vb, 0) < q_data->size) {
+	if (vb2_v4l2_plane_size(vb, 0) < q_data->size) {
 		pr_err("%s data will not fit into plane (%lu < %lu)\n",
-				__func__, vb2_plane_size(vb, 0),
+				__func__, vb2_v4l2_plane_size(vb, 0),
 				(long)q_data->size);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, q_data->size);
+	vb2_v4l2_set_plane_payload(vb, 0, q_data->size);
 
 	return 0;
 }
@@ -2180,7 +2180,7 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
 		ctx->hdr_parsed = s5p_jpeg_parse_hdr(&tmp,
 		     (unsigned long)vb2_plane_vaddr(vb, 0),
 		     min((unsigned long)ctx->out_q.size,
-			 vb2_get_plane_payload(vb, 0)), ctx);
+			 vb2_v4l2_get_plane_payload(vb, 0)), ctx);
 		if (!ctx->hdr_parsed) {
 			vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
 			return;
@@ -2240,7 +2240,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &ctx->jpeg->lock;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -2253,7 +2253,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->jpeg->lock;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 /*
@@ -2308,7 +2308,7 @@ static irqreturn_t s5p_jpeg_irq(int irq, void *dev_id)
 
 	v4l2_m2m_buf_done(src_buf, state);
 	if (curr_ctx->mode == S5P_JPEG_ENCODE)
-		vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size);
+		vb2_v4l2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size);
 	v4l2_m2m_buf_done(dst_buf, state);
 	v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx);
 
@@ -2365,7 +2365,7 @@ static irqreturn_t exynos4_jpeg_irq(int irq, void *priv)
 	if (jpeg->irq_ret == OK_ENC_OR_DEC) {
 		if (curr_ctx->mode == S5P_JPEG_ENCODE) {
 			payload_size = exynos4_jpeg_get_stream_size(jpeg->regs);
-			vb2_set_plane_payload(&dst_vb->vb2_buf, 0,
+			vb2_v4l2_set_plane_payload(&dst_vb->vb2_buf, 0,
 					      payload_size);
 		}
 		v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
@@ -2435,7 +2435,7 @@ static irqreturn_t exynos3250_jpeg_irq(int irq, void *dev_id)
 
 	v4l2_m2m_buf_done(src_buf, state);
 	if (curr_ctx->mode == S5P_JPEG_ENCODE)
-		vb2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size);
+		vb2_v4l2_set_plane_payload(&dst_buf->vb2_buf, 0, payload_size);
 	v4l2_m2m_buf_done(dst_buf, state);
 	v4l2_m2m_job_finish(jpeg->m2m_dev, curr_ctx->fh.m2m_ctx);
 
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 5baa069..125ad21 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -200,8 +200,8 @@ static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
 				     struct s5p_mfc_buf, list);
 		mfc_debug(2, "Cleaning up buffer: %d\n",
 					  dst_buf->b->v4l2_buf.index);
-		vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0, 0);
-		vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1, 0);
+		vb2_v4l2_set_plane_payload(&dst_buf->b->vb2_buf, 0, 0);
+		vb2_v4l2_set_plane_payload(&dst_buf->b->vb2_buf, 1, 0);
 		list_del(&dst_buf->list);
 		ctx->dst_queue_cnt--;
 		dst_buf->b->v4l2_buf.sequence = (ctx->sequence++);
@@ -308,9 +308,9 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
 			else
 				dst_buf->b->v4l2_buf.field =
 							V4L2_FIELD_INTERLACED;
-			vb2_set_plane_payload(&dst_buf->b->vb2_buf, 0,
+			vb2_v4l2_set_plane_payload(&dst_buf->b->vb2_buf, 0,
 					      ctx->luma_size);
-			vb2_set_plane_payload(&dst_buf->b->vb2_buf, 1,
+			vb2_v4l2_set_plane_payload(&dst_buf->b->vb2_buf, 1,
 					      ctx->chroma_size);
 			clear_bit(dst_buf->b->v4l2_buf.index,
 							&ctx->dec_dst_flag);
@@ -596,7 +596,7 @@ static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx,
 									list);
 		list_del(&mb_entry->list);
 		ctx->dst_queue_cnt--;
-		vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, 0);
+		vb2_v4l2_set_plane_payload(&mb_entry->b->vb2_buf, 0, 0);
 		vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
 	}
 	spin_unlock(&dev->irqlock);
@@ -828,7 +828,7 @@ static int s5p_mfc_open(struct file *file)
 	}
 	q->mem_ops = &vb2_dma_contig_memops;
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret) {
 		mfc_err("Failed to initialize videobuf2 queue(capture)\n");
 		goto err_queue_init;
@@ -858,7 +858,7 @@ static int s5p_mfc_open(struct file *file)
 	q->allow_zero_bytesused = 1;
 	q->mem_ops = &vb2_dma_contig_memops;
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret) {
 		mfc_err("Failed to initialize videobuf2 queue(output)\n");
 		goto err_queue_init;
@@ -903,8 +903,8 @@ static int s5p_mfc_release(struct file *file)
 	mfc_debug_enter();
 	mutex_lock(&dev->mfc_mutex);
 	s5p_mfc_clock_on();
-	vb2_queue_release(&ctx->vq_src);
-	vb2_queue_release(&ctx->vq_dst);
+	vb2_v4l2_queue_release(&ctx->vq_src);
+	vb2_v4l2_queue_release(&ctx->vq_dst);
 	/* Mark context as idle */
 	clear_work_bit_irqsave(ctx);
 	/* If instance was initialised and not yet freed,
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 1de804d..66ec058 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -471,7 +471,7 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
 
 	if (reqbufs->count == 0) {
 		mfc_debug(2, "Freeing buffers\n");
-		ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+		ret = vb2_v4l2_reqbufs(&ctx->vq_src, reqbufs);
 		if (ret)
 			goto out;
 		s5p_mfc_close_mfc_inst(dev, ctx);
@@ -488,14 +488,14 @@ static int reqbufs_output(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
 
 		mfc_debug(2, "Allocating %d buffers for OUTPUT queue\n",
 				reqbufs->count);
-		ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+		ret = vb2_v4l2_reqbufs(&ctx->vq_src, reqbufs);
 		if (ret)
 			goto out;
 
 		ret = s5p_mfc_open_mfc_inst(dev, ctx);
 		if (ret) {
 			reqbufs->count = 0;
-			vb2_reqbufs(&ctx->vq_src, reqbufs);
+			vb2_v4l2_reqbufs(&ctx->vq_src, reqbufs);
 			goto out;
 		}
 
@@ -520,7 +520,7 @@ static int reqbufs_capture(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
 
 	if (reqbufs->count == 0) {
 		mfc_debug(2, "Freeing buffers\n");
-		ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
+		ret = vb2_v4l2_reqbufs(&ctx->vq_dst, reqbufs);
 		if (ret)
 			goto out;
 		s5p_mfc_hw_call_void(dev->mfc_ops, release_codec_buffers, ctx);
@@ -529,7 +529,7 @@ static int reqbufs_capture(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
 		WARN_ON(ctx->dst_bufs_cnt != 0);
 		mfc_debug(2, "Allocating %d buffers for CAPTURE queue\n",
 				reqbufs->count);
-		ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
+		ret = vb2_v4l2_reqbufs(&ctx->vq_dst, reqbufs);
 		if (ret)
 			goto out;
 
@@ -540,7 +540,7 @@ static int reqbufs_capture(struct s5p_mfc_dev *dev, struct s5p_mfc_ctx *ctx,
 		if (ret) {
 			mfc_err("Failed to allocate decoding buffers\n");
 			reqbufs->count = 0;
-			vb2_reqbufs(&ctx->vq_dst, reqbufs);
+			vb2_v4l2_reqbufs(&ctx->vq_dst, reqbufs);
 			ret = -ENOMEM;
 			ctx->capture_state = QUEUE_FREE;
 			goto out;
@@ -602,10 +602,10 @@ static int vidioc_querybuf(struct file *file, void *priv,
 	mfc_debug(2, "State: %d, buf->type: %d\n", ctx->state, buf->type);
 	if (ctx->state == MFCINST_GOT_INST &&
 			buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-		ret = vb2_querybuf(&ctx->vq_src, buf);
+		ret = vb2_v4l2_querybuf(&ctx->vq_src, buf);
 	} else if (ctx->state == MFCINST_RUNNING &&
 			buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
-		ret = vb2_querybuf(&ctx->vq_dst, buf);
+		ret = vb2_v4l2_querybuf(&ctx->vq_dst, buf);
 		for (i = 0; i < buf->length; i++)
 			buf->m.planes[i].m.mem_offset += DST_QUEUE_OFF_BASE;
 	} else {
@@ -626,9 +626,9 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 		return -EIO;
 	}
 	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		return vb2_qbuf(&ctx->vq_src, buf);
+		return vb2_v4l2_qbuf(&ctx->vq_src, buf);
 	else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-		return vb2_qbuf(&ctx->vq_dst, buf);
+		return vb2_v4l2_qbuf(&ctx->vq_dst, buf);
 	return -EINVAL;
 }
 
@@ -646,9 +646,9 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 		return -EIO;
 	}
 	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		ret = vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
+		ret = vb2_v4l2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
 	else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
-		ret = vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
+		ret = vb2_v4l2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
 		if (ret == 0 && ctx->state == MFCINST_FINISHED &&
 				list_empty(&ctx->vq_dst.done_list))
 			v4l2_event_queue_fh(&ctx->fh, &ev);
@@ -665,9 +665,9 @@ static int vidioc_expbuf(struct file *file, void *priv,
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
 
 	if (eb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		return vb2_expbuf(&ctx->vq_src, eb);
+		return vb2_v4l2_expbuf(&ctx->vq_src, eb);
 	if (eb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-		return vb2_expbuf(&ctx->vq_dst, eb);
+		return vb2_v4l2_expbuf(&ctx->vq_dst, eb);
 	return -EINVAL;
 }
 
@@ -680,9 +680,9 @@ static int vidioc_streamon(struct file *file, void *priv,
 
 	mfc_debug_enter();
 	if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		ret = vb2_streamon(&ctx->vq_src, type);
+		ret = vb2_v4l2_streamon(&ctx->vq_src, type);
 	else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-		ret = vb2_streamon(&ctx->vq_dst, type);
+		ret = vb2_v4l2_streamon(&ctx->vq_dst, type);
 	mfc_debug_leave();
 	return ret;
 }
@@ -694,9 +694,9 @@ static int vidioc_streamoff(struct file *file, void *priv,
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
 
 	if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		return vb2_streamoff(&ctx->vq_src, type);
+		return vb2_v4l2_streamoff(&ctx->vq_src, type);
 	else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-		return vb2_streamoff(&ctx->vq_dst, type);
+		return vb2_v4l2_streamoff(&ctx->vq_dst, type);
 	return -EINVAL;
 }
 
@@ -960,8 +960,8 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 				return -EINVAL;
 			}
 		}
-		if (vb2_plane_size(vb, 0) < ctx->luma_size ||
-			vb2_plane_size(vb, 1) < ctx->chroma_size) {
+		if (vb2_v4l2_plane_size(vb, 0) < ctx->luma_size ||
+			vb2_v4l2_plane_size(vb, 1) < ctx->chroma_size) {
 			mfc_err("Plane buffer (CAPTURE) is too small\n");
 			return -EINVAL;
 		}
@@ -978,7 +978,7 @@ static int s5p_mfc_buf_init(struct vb2_buffer *vb)
 			mfc_err("Plane memory not allocated\n");
 			return -EINVAL;
 		}
-		if (vb2_plane_size(vb, 0) < ctx->dec_src_buf_size) {
+		if (vb2_v4l2_plane_size(vb, 0) < ctx->dec_src_buf_size) {
 			mfc_err("Plane buffer (OUTPUT) is too small\n");
 			return -EINVAL;
 		}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index 3b4b556..dad34cd 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -774,7 +774,7 @@ static int enc_pre_seq_start(struct s5p_mfc_ctx *ctx)
 	spin_lock_irqsave(&dev->irqlock, flags);
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
-	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_v4l2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
 			dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -796,7 +796,7 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
 					struct s5p_mfc_buf, list);
 			list_del(&dst_mb->list);
 			ctx->dst_queue_cnt--;
-			vb2_set_plane_payload(&dst_mb->b->vb2_buf, 0,
+			vb2_v4l2_set_plane_payload(&dst_mb->b->vb2_buf, 0,
 					      s5p_mfc_hw_call(dev->mfc_ops, get_enc_strm_size, dev));
 			vb2_buffer_done(&dst_mb->b->vb2_buf,
 					VB2_BUF_STATE_DONE);
@@ -840,7 +840,7 @@ static int enc_pre_frame_start(struct s5p_mfc_ctx *ctx)
 	spin_lock_irqsave(&dev->irqlock, flags);
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
-	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_v4l2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_hw_call_void(dev->mfc_ops, set_enc_stream_buffer, ctx, dst_addr,
 			dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -925,7 +925,7 @@ static int enc_post_frame_start(struct s5p_mfc_ctx *ctx)
 			mb_entry->b->v4l2_buf.flags |= V4L2_BUF_FLAG_BFRAME;
 			break;
 		}
-		vb2_set_plane_payload(&mb_entry->b->vb2_buf, 0, strm_size);
+		vb2_v4l2_set_plane_payload(&mb_entry->b->vb2_buf, 0, strm_size);
 		vb2_buffer_done(&mb_entry->b->vb2_buf, VB2_BUF_STATE_DONE);
 	}
 	spin_unlock_irqrestore(&dev->irqlock, flags);
@@ -1148,7 +1148,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
 		return -EINVAL;
 	if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
 		if (reqbufs->count == 0) {
-			ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
+			ret = vb2_v4l2_reqbufs(&ctx->vq_dst, reqbufs);
 			ctx->capture_state = QUEUE_FREE;
 			return ret;
 		}
@@ -1157,9 +1157,9 @@ static int vidioc_reqbufs(struct file *file, void *priv,
 							ctx->capture_state);
 			return -EINVAL;
 		}
-		ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
+		ret = vb2_v4l2_reqbufs(&ctx->vq_dst, reqbufs);
 		if (ret != 0) {
-			mfc_err("error in vb2_reqbufs() for E(D)\n");
+			mfc_err("error in vb2_v4l2_reqbufs() for E(D)\n");
 			return ret;
 		}
 		ctx->capture_state = QUEUE_BUFS_REQUESTED;
@@ -1169,13 +1169,13 @@ static int vidioc_reqbufs(struct file *file, void *priv,
 		if (ret) {
 			mfc_err("Failed to allocate encoding buffers\n");
 			reqbufs->count = 0;
-			ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
+			ret = vb2_v4l2_reqbufs(&ctx->vq_dst, reqbufs);
 			return -ENOMEM;
 		}
 	} else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
 		if (reqbufs->count == 0) {
 			mfc_debug(2, "Freeing buffers\n");
-			ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+			ret = vb2_v4l2_reqbufs(&ctx->vq_src, reqbufs);
 			s5p_mfc_hw_call_void(dev->mfc_ops, release_codec_buffers,
 					ctx);
 			ctx->output_state = QUEUE_FREE;
@@ -1199,9 +1199,9 @@ static int vidioc_reqbufs(struct file *file, void *priv,
 			}
 		}
 
-		ret = vb2_reqbufs(&ctx->vq_src, reqbufs);
+		ret = vb2_v4l2_reqbufs(&ctx->vq_src, reqbufs);
 		if (ret != 0) {
-			mfc_err("error in vb2_reqbufs() for E(S)\n");
+			mfc_err("error in vb2_v4l2_reqbufs() for E(S)\n");
 			return ret;
 		}
 		ctx->output_state = QUEUE_BUFS_REQUESTED;
@@ -1227,16 +1227,16 @@ static int vidioc_querybuf(struct file *file, void *priv,
 			mfc_err("invalid context state: %d\n", ctx->state);
 			return -EINVAL;
 		}
-		ret = vb2_querybuf(&ctx->vq_dst, buf);
+		ret = vb2_v4l2_querybuf(&ctx->vq_dst, buf);
 		if (ret != 0) {
-			mfc_err("error in vb2_querybuf() for E(D)\n");
+			mfc_err("error in vb2_v4l2_querybuf() for E(D)\n");
 			return ret;
 		}
 		buf->m.planes[0].m.mem_offset += DST_QUEUE_OFF_BASE;
 	} else if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-		ret = vb2_querybuf(&ctx->vq_src, buf);
+		ret = vb2_v4l2_querybuf(&ctx->vq_src, buf);
 		if (ret != 0) {
-			mfc_err("error in vb2_querybuf() for E(S)\n");
+			mfc_err("error in vb2_v4l2_querybuf() for E(S)\n");
 			return ret;
 		}
 	} else {
@@ -1260,9 +1260,9 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 			mfc_err("Call on QBUF after EOS command\n");
 			return -EIO;
 		}
-		return vb2_qbuf(&ctx->vq_src, buf);
+		return vb2_v4l2_qbuf(&ctx->vq_src, buf);
 	} else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
-		return vb2_qbuf(&ctx->vq_dst, buf);
+		return vb2_v4l2_qbuf(&ctx->vq_dst, buf);
 	}
 	return -EINVAL;
 }
@@ -1281,9 +1281,9 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 		return -EIO;
 	}
 	if (buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
-		ret = vb2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
+		ret = vb2_v4l2_dqbuf(&ctx->vq_src, buf, file->f_flags & O_NONBLOCK);
 	} else if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
-		ret = vb2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
+		ret = vb2_v4l2_dqbuf(&ctx->vq_dst, buf, file->f_flags & O_NONBLOCK);
 		if (ret == 0 && ctx->state == MFCINST_FINISHED
 					&& list_empty(&ctx->vq_dst.done_list))
 			v4l2_event_queue_fh(&ctx->fh, &ev);
@@ -1301,9 +1301,9 @@ static int vidioc_expbuf(struct file *file, void *priv,
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
 
 	if (eb->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		return vb2_expbuf(&ctx->vq_src, eb);
+		return vb2_v4l2_expbuf(&ctx->vq_src, eb);
 	if (eb->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-		return vb2_expbuf(&ctx->vq_dst, eb);
+		return vb2_v4l2_expbuf(&ctx->vq_dst, eb);
 	return -EINVAL;
 }
 
@@ -1314,9 +1314,9 @@ static int vidioc_streamon(struct file *file, void *priv,
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
 
 	if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		return vb2_streamon(&ctx->vq_src, type);
+		return vb2_v4l2_streamon(&ctx->vq_src, type);
 	else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-		return vb2_streamon(&ctx->vq_dst, type);
+		return vb2_v4l2_streamon(&ctx->vq_dst, type);
 	return -EINVAL;
 }
 
@@ -1327,9 +1327,9 @@ static int vidioc_streamoff(struct file *file, void *priv,
 	struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
 
 	if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
-		return vb2_streamoff(&ctx->vq_src, type);
+		return vb2_v4l2_streamoff(&ctx->vq_src, type);
 	else if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
-		return vb2_streamoff(&ctx->vq_dst, type);
+		return vb2_v4l2_streamoff(&ctx->vq_dst, type);
 	return -EINVAL;
 }
 
@@ -1916,8 +1916,8 @@ static int s5p_mfc_buf_prepare(struct vb2_buffer *vb)
 		if (ret < 0)
 			return ret;
 		mfc_debug(2, "plane size: %ld, dst size: %zu\n",
-			vb2_plane_size(vb, 0), ctx->enc_dst_buf_size);
-		if (vb2_plane_size(vb, 0) < ctx->enc_dst_buf_size) {
+			vb2_v4l2_plane_size(vb, 0), ctx->enc_dst_buf_size);
+		if (vb2_v4l2_plane_size(vb, 0) < ctx->enc_dst_buf_size) {
 			mfc_err("plane size is too small for capture\n");
 			return -EINVAL;
 		}
@@ -1926,11 +1926,11 @@ static int s5p_mfc_buf_prepare(struct vb2_buffer *vb)
 		if (ret < 0)
 			return ret;
 		mfc_debug(2, "plane size: %ld, luma size: %d\n",
-			vb2_plane_size(vb, 0), ctx->luma_size);
+			vb2_v4l2_plane_size(vb, 0), ctx->luma_size);
 		mfc_debug(2, "plane size: %ld, chroma size: %d\n",
-			vb2_plane_size(vb, 1), ctx->chroma_size);
-		if (vb2_plane_size(vb, 0) < ctx->luma_size ||
-		    vb2_plane_size(vb, 1) < ctx->chroma_size) {
+			vb2_v4l2_plane_size(vb, 1), ctx->chroma_size);
+		if (vb2_v4l2_plane_size(vb, 0) < ctx->luma_size ||
+		    vb2_v4l2_plane_size(vb, 1) < ctx->chroma_size) {
 			mfc_err("plane size is too small for output\n");
 			return -EINVAL;
 		}
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 13aff41..aa0cee4 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -1266,7 +1266,7 @@ static int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_mb->flags |= MFC_BUF_FLAG_USED;
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
-	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_v4l2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_set_enc_stream_buffer_v5(ctx, dst_addr, dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1308,7 +1308,7 @@ static void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
 	spin_lock_irqsave(&dev->irqlock, flags);
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
-	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_v4l2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_set_enc_stream_buffer_v5(ctx, dst_addr, dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1477,7 +1477,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->vb2_buf.num_planes; i++)
-			vb2_set_plane_payload(&b->b->vb2_buf, i, 0);
+			vb2_v4l2_set_plane_payload(&b->b->vb2_buf, i, 0);
 		vb2_buffer_done(&b->b->vb2_buf, 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 5c7f35a..3be8f16 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1615,7 +1615,7 @@ static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_mb->flags |= MFC_BUF_FLAG_USED;
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
-	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_v4l2_plane_size(&dst_mb->b->vb2_buf, 0);
 
 	s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
 
@@ -1658,7 +1658,7 @@ static inline void s5p_mfc_run_init_enc(struct s5p_mfc_ctx *ctx)
 
 	dst_mb = list_entry(ctx->dst_queue.next, struct s5p_mfc_buf, list);
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_mb->b->vb2_buf, 0);
-	dst_size = vb2_plane_size(&dst_mb->b->vb2_buf, 0);
+	dst_size = vb2_v4l2_plane_size(&dst_mb->b->vb2_buf, 0);
 	s5p_mfc_set_enc_stream_buffer_v6(ctx, dst_addr, dst_size);
 	spin_unlock_irqrestore(&dev->irqlock, flags);
 	dev->curr_ctx = ctx->num;
@@ -1835,7 +1835,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->vb2_buf.num_planes; i++)
-			vb2_set_plane_payload(&b->b->vb2_buf, i, 0);
+			vb2_v4l2_set_plane_payload(&b->b->vb2_buf, i, 0);
 		vb2_buffer_done(&b->b->vb2_buf, VB2_BUF_STATE_ERROR);
 		list_del(&b->list);
 	}
diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
index dc1c679..54f330f 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -691,7 +691,7 @@ static int mxr_reqbufs(struct file *file, void *priv,
 	struct mxr_layer *layer = video_drvdata(file);
 
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
-	return vb2_reqbufs(&layer->vb_queue, p);
+	return vb2_v4l2_reqbufs(&layer->vb_queue, p);
 }
 
 static int mxr_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
@@ -699,7 +699,7 @@ static int mxr_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
 	struct mxr_layer *layer = video_drvdata(file);
 
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
-	return vb2_querybuf(&layer->vb_queue, p);
+	return vb2_v4l2_querybuf(&layer->vb_queue, p);
 }
 
 static int mxr_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
@@ -707,7 +707,7 @@ static int mxr_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 	struct mxr_layer *layer = video_drvdata(file);
 
 	mxr_dbg(layer->mdev, "%s:%d(%d)\n", __func__, __LINE__, p->index);
-	return vb2_qbuf(&layer->vb_queue, p);
+	return vb2_v4l2_qbuf(&layer->vb_queue, p);
 }
 
 static int mxr_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
@@ -715,7 +715,7 @@ static int mxr_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 	struct mxr_layer *layer = video_drvdata(file);
 
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
-	return vb2_dqbuf(&layer->vb_queue, p, file->f_flags & O_NONBLOCK);
+	return vb2_v4l2_dqbuf(&layer->vb_queue, p, file->f_flags & O_NONBLOCK);
 }
 
 static int mxr_expbuf(struct file *file, void *priv,
@@ -724,7 +724,7 @@ static int mxr_expbuf(struct file *file, void *priv,
 	struct mxr_layer *layer = video_drvdata(file);
 
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
-	return vb2_expbuf(&layer->vb_queue, eb);
+	return vb2_v4l2_expbuf(&layer->vb_queue, eb);
 }
 
 static int mxr_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
@@ -732,7 +732,7 @@ static int mxr_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
 	struct mxr_layer *layer = video_drvdata(file);
 
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
-	return vb2_streamon(&layer->vb_queue, i);
+	return vb2_v4l2_streamon(&layer->vb_queue, i);
 }
 
 static int mxr_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
@@ -740,7 +740,7 @@ static int mxr_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 	struct mxr_layer *layer = video_drvdata(file);
 
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
-	return vb2_streamoff(&layer->vb_queue, i);
+	return vb2_v4l2_streamoff(&layer->vb_queue, i);
 }
 
 static const struct v4l2_ioctl_ops mxr_ioctl_ops = {
@@ -804,7 +804,7 @@ static int mxr_video_open(struct file *file)
 		goto fail_fh_open;
 	}
 
-	ret = vb2_queue_init(&layer->vb_queue);
+	ret = vb2_v4l2_queue_init(&layer->vb_queue);
 	if (ret != 0) {
 		mxr_err(mdev, "failed to initialize vb2 queue\n");
 		goto fail_power;
@@ -838,7 +838,7 @@ mxr_video_poll(struct file *file, struct poll_table_struct *wait)
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
 
 	mutex_lock(&layer->mutex);
-	res = vb2_poll(&layer->vb_queue, file, wait);
+	res = vb2_v4l2_poll(&layer->vb_queue, file, wait);
 	mutex_unlock(&layer->mutex);
 	return res;
 }
@@ -864,7 +864,7 @@ static int mxr_video_release(struct file *file)
 	mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
 	mutex_lock(&layer->mutex);
 	if (v4l2_fh_is_singular_file(file)) {
-		vb2_queue_release(&layer->vb_queue);
+		vb2_v4l2_queue_release(&layer->vb_queue);
 		mxr_power_put(layer->mdev);
 	}
 	v4l2_fh_release(file);
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
index 1affcae..08960f9 100644
--- a/drivers/media/platform/sh_veu.c
+++ b/drivers/media/platform/sh_veu.c
@@ -918,13 +918,13 @@ static int sh_veu_buf_prepare(struct vb2_buffer *vb)
 	sizeimage = vfmt->bytesperline * vfmt->frame.height *
 		vfmt->fmt->depth / vfmt->fmt->ydepth;
 
-	if (vb2_plane_size(vb, 0) < sizeimage) {
+	if (vb2_v4l2_plane_size(vb, 0) < sizeimage) {
 		dev_dbg(veu->dev, "%s data will not fit into plane (%lu < %u)\n",
-			__func__, vb2_plane_size(vb, 0), sizeimage);
+			__func__, vb2_v4l2_plane_size(vb, 0), sizeimage);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, sizeimage);
+	vb2_v4l2_set_plane_payload(vb, 0, sizeimage);
 
 	return 0;
 }
@@ -961,7 +961,7 @@ static int sh_veu_queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->mem_ops = &vb2_dma_contig_memops;
 	src_vq->lock = &veu->fop_lock;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret < 0)
 		return ret;
 
@@ -974,7 +974,7 @@ static int sh_veu_queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->mem_ops = &vb2_dma_contig_memops;
 	dst_vq->lock = &veu->fop_lock;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 		/* ========== File operations ========== */
@@ -1009,12 +1009,12 @@ static int sh_veu_release(struct file *file)
 
 	if (veu_file == veu->capture) {
 		veu->capture = NULL;
-		vb2_queue_release(v4l2_m2m_get_vq(veu->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE));
+		vb2_v4l2_queue_release(v4l2_m2m_get_vq(veu->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE));
 	}
 
 	if (veu_file == veu->output) {
 		veu->output = NULL;
-		vb2_queue_release(v4l2_m2m_get_vq(veu->m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT));
+		vb2_v4l2_queue_release(v4l2_m2m_get_vq(veu->m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT));
 	}
 
 	if (!veu->output && !veu->capture && veu->m2m_ctx) {
diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c
index fe5c8ab..d80f4c4 100644
--- a/drivers/media/platform/sh_vou.c
+++ b/drivers/media/platform/sh_vou.c
@@ -268,14 +268,14 @@ static int sh_vou_buf_prepare(struct vb2_buffer *vb)
 
 	dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		/* User buffer too small */
 		dev_warn(vou_dev->v4l2_dev.dev, "buffer too small (%lu < %u)\n",
-			 vb2_plane_size(vb, 0), size);
+			 vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 	return 0;
 }
 
@@ -1300,7 +1300,7 @@ static int sh_vou_probe(struct platform_device *pdev)
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->min_buffers_needed = 2;
 	q->lock = &vou_dev->fop_lock;
-	ret = vb2_queue_init(q);
+	ret = vb2_v4l2_queue_init(q);
 	if (ret)
 		goto einitctx;
 
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index 7268a2f..4107c48 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -288,13 +288,13 @@ static int buffer_prepare(struct vb2_buffer *vb)
 
 	size = icd->sizeimage;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dev_err(icd->parent, "%s data will not fit into plane (%lu < %lu)\n",
-				__func__, vb2_plane_size(vb, 0), size);
+				__func__, vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	if (!buf->p_dma_desc) {
 		if (list_empty(&isi->dma_desc_head)) {
@@ -481,7 +481,7 @@ static int isi_camera_init_videobuf(struct vb2_queue *q,
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &ici->host_lock;
 
-	return vb2_queue_init(q);
+	return vb2_v4l2_queue_init(q);
 }
 
 static int isi_camera_set_fmt(struct soc_camera_device *icd,
@@ -745,7 +745,7 @@ static unsigned int isi_camera_poll(struct file *file, poll_table *pt)
 {
 	struct soc_camera_device *icd = file->private_data;
 
-	return vb2_poll(&icd->vb2_vidq, file, pt);
+	return vb2_v4l2_poll(&icd->vb2_vidq, file, pt);
 }
 
 static int isi_camera_querycap(struct soc_camera_host *ici,
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index 57e8ad0..b425129 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -505,7 +505,7 @@ static int mx2_videobuf_prepare(struct vb2_buffer *vb)
 	int ret = 0;
 
 	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
-		vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
+		vb, vb2_plane_vaddr(vb, 0), vb2_v4l2_get_plane_payload(vb, 0));
 
 #ifdef DEBUG
 	/*
@@ -513,12 +513,12 @@ static int mx2_videobuf_prepare(struct vb2_buffer *vb)
 	 * the buffer with something
 	 */
 	memset((void *)vb2_plane_vaddr(vb, 0),
-	       0xaa, vb2_get_plane_payload(vb, 0));
+	       0xaa, vb2_v4l2_get_plane_payload(vb, 0));
 #endif
 
-	vb2_set_plane_payload(vb, 0, icd->sizeimage);
+	vb2_v4l2_set_plane_payload(vb, 0, icd->sizeimage);
 	if (vb2_plane_vaddr(vb, 0) &&
-	    vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
+	    vb2_v4l2_get_plane_payload(vb, 0) > vb2_v4l2_plane_size(vb, 0)) {
 		ret = -EINVAL;
 		goto out;
 	}
@@ -540,7 +540,7 @@ static void mx2_videobuf_queue(struct vb2_buffer *vb)
 	unsigned long flags;
 
 	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
-		vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
+		vb, vb2_plane_vaddr(vb, 0), vb2_v4l2_get_plane_payload(vb, 0));
 
 	spin_lock_irqsave(&pcdev->lock, flags);
 
@@ -794,7 +794,7 @@ static int mx2_camera_init_videobuf(struct vb2_queue *q,
 	q->buf_struct_size = sizeof(struct mx2_buffer);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
-	return vb2_queue_init(q);
+	return vb2_v4l2_queue_init(q);
 }
 
 #define MX2_BUS_FLAGS	(V4L2_MBUS_MASTER | \
@@ -1281,7 +1281,7 @@ static unsigned int mx2_camera_poll(struct file *file, poll_table *pt)
 {
 	struct soc_camera_device *icd = file->private_data;
 
-	return vb2_poll(&icd->vb2_vidq, file, pt);
+	return vb2_v4l2_poll(&icd->vb2_vidq, file, pt);
 }
 
 static struct soc_camera_host_ops mx2_soc_camera_host_ops = {
@@ -1346,7 +1346,7 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
 #endif
 		dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%p %lu\n", __func__, vb,
 				vb2_plane_vaddr(&vb->vb2_buf, 0),
-				vb2_get_plane_payload(&vb->vb2_buf, 0));
+				vb2_v4l2_get_plane_payload(&vb->vb2_buf, 0));
 
 		list_del_init(&buf->internal.queue);
 		v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index fa8849f..d2d14d8 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -272,9 +272,9 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
 
 	new_size = icd->sizeimage;
 
-	if (vb2_plane_size(vb, 0) < new_size) {
+	if (vb2_v4l2_plane_size(vb, 0) < new_size) {
 		dev_err(icd->parent, "Buffer #%d too small (%lu < %zu)\n",
-			vb->v4l2_buf.index, vb2_plane_size(vb, 0), new_size);
+			vb->v4l2_buf.index, vb2_v4l2_plane_size(vb, 0), new_size);
 		goto error;
 	}
 
@@ -296,7 +296,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
 		txd = buf->txd;
 	}
 
-	vb2_set_plane_payload(vb, 0, new_size);
+	vb2_v4l2_set_plane_payload(vb, 0, new_size);
 
 	/* This is the configuration of one sg-element */
 	video->out_pixel_fmt = fourcc_to_ipu_pix(host_fmt->fourcc);
@@ -325,7 +325,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
 #ifdef DEBUG
 	/* helps to see what DMA actually has written */
 	if (vb2_plane_vaddr(vb, 0))
-		memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0));
+		memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_v4l2_get_plane_payload(vb, 0));
 #endif
 
 	spin_lock_irq(&mx3_cam->lock);
@@ -387,7 +387,7 @@ static void mx3_videobuf_release(struct vb2_buffer *vb)
 
 	spin_unlock_irqrestore(&mx3_cam->lock, flags);
 
-	mx3_cam->buf_total -= vb2_plane_size(vb, 0);
+	mx3_cam->buf_total -= vb2_v4l2_plane_size(vb, 0);
 }
 
 static int mx3_videobuf_init(struct vb2_buffer *vb)
@@ -403,7 +403,7 @@ static int mx3_videobuf_init(struct vb2_buffer *vb)
 		INIT_LIST_HEAD(&buf->queue);
 		sg_init_table(&buf->sg, 1);
 
-		mx3_cam->buf_total += vb2_plane_size(vb, 0);
+		mx3_cam->buf_total += vb2_v4l2_plane_size(vb, 0);
 	}
 
 	return 0;
@@ -457,7 +457,7 @@ static int mx3_camera_init_videobuf(struct vb2_queue *q,
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &ici->host_lock;
 
-	return vb2_queue_init(q);
+	return vb2_v4l2_queue_init(q);
 }
 
 /* First part of ipu_csi_init_interface() */
@@ -978,7 +978,7 @@ static unsigned int mx3_camera_poll(struct file *file, poll_table *pt)
 {
 	struct soc_camera_device *icd = file->private_data;
 
-	return vb2_poll(&icd->vb2_vidq, file, pt);
+	return vb2_v4l2_poll(&icd->vb2_vidq, file, pt);
 }
 
 static int mx3_camera_querycap(struct soc_camera_host *ici,
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index c529d10..b81c649 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -769,16 +769,16 @@ static void rcar_vin_videobuf_queue(struct vb2_buffer *vb)
 
 	size = icd->sizeimage;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
-			vbuf->v4l2_buf.index, vb2_plane_size(vb, 0), size);
+			vbuf->v4l2_buf.index, vb2_v4l2_plane_size(vb, 0), size);
 		goto error;
 	}
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
-		vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
+		vb, vb2_plane_vaddr(vb, 0), vb2_v4l2_get_plane_payload(vb, 0));
 
 	spin_lock_irq(&priv->lock);
 
@@ -1776,7 +1776,7 @@ static unsigned int rcar_vin_poll(struct file *file, poll_table *pt)
 {
 	struct soc_camera_device *icd = file->private_data;
 
-	return vb2_poll(&icd->vb2_vidq, file, pt);
+	return vb2_v4l2_poll(&icd->vb2_vidq, file, pt);
 }
 
 static int rcar_vin_querycap(struct soc_camera_host *ici,
@@ -1803,7 +1803,7 @@ static int rcar_vin_init_videobuf2(struct vb2_queue *vq,
 	vq->timestamp_flags  = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	vq->lock = &ici->host_lock;
 
-	return vb2_queue_init(vq);
+	return vb2_v4l2_queue_init(vq);
 }
 
 static struct soc_camera_host_ops rcar_vin_host_ops = {
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 7335b79..f94cd5d 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -390,16 +390,16 @@ static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
 
 	size = icd->sizeimage;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
-			vb->v4l2_buf.index, vb2_plane_size(vb, 0), size);
+			vb->v4l2_buf.index, vb2_v4l2_plane_size(vb, 0), size);
 		goto error;
 	}
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
-		vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
+		vb, vb2_plane_vaddr(vb, 0), vb2_v4l2_get_plane_payload(vb, 0));
 
 #ifdef DEBUG
 	/*
@@ -407,7 +407,7 @@ static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
 	 * the buffer with something
 	 */
 	if (vb2_plane_vaddr(vb, 0))
-		memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0));
+		memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_v4l2_get_plane_payload(vb, 0));
 #endif
 
 	spin_lock_irq(&pcdev->lock);
@@ -453,7 +453,7 @@ static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
 	if (buf->queue.next)
 		list_del_init(&buf->queue);
 
-	pcdev->buf_total -= PAGE_ALIGN(vb2_plane_size(vb, 0));
+	pcdev->buf_total -= PAGE_ALIGN(vb2_v4l2_plane_size(vb, 0));
 	dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
 		pcdev->buf_total);
 
@@ -466,7 +466,7 @@ static int sh_mobile_ceu_videobuf_init(struct vb2_buffer *vb)
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	struct sh_mobile_ceu_dev *pcdev = ici->priv;
 
-	pcdev->buf_total += PAGE_ALIGN(vb2_plane_size(vb, 0));
+	pcdev->buf_total += PAGE_ALIGN(vb2_v4l2_plane_size(vb, 0));
 	dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
 		pcdev->buf_total);
 
@@ -1663,7 +1663,7 @@ static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt)
 {
 	struct soc_camera_device *icd = file->private_data;
 
-	return vb2_poll(&icd->vb2_vidq, file, pt);
+	return vb2_v4l2_poll(&icd->vb2_vidq, file, pt);
 }
 
 static int sh_mobile_ceu_querycap(struct soc_camera_host *ici,
@@ -1690,7 +1690,7 @@ static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q,
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	q->lock = &ici->host_lock;
 
-	return vb2_queue_init(q);
+	return vb2_v4l2_queue_init(q);
 }
 
 static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index 4595590..19ebc61 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -378,7 +378,7 @@ static int soc_camera_reqbufs(struct file *file, void *priv,
 
 		ret = ici->ops->reqbufs(icd, p);
 	} else {
-		ret = vb2_reqbufs(&icd->vb2_vidq, p);
+		ret = vb2_v4l2_reqbufs(&icd->vb2_vidq, p);
 	}
 
 	if (!ret && !icd->streamer)
@@ -398,7 +398,7 @@ static int soc_camera_querybuf(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		return videobuf_querybuf(&icd->vb_vidq, p);
 	else
-		return vb2_querybuf(&icd->vb2_vidq, p);
+		return vb2_v4l2_querybuf(&icd->vb2_vidq, p);
 }
 
 static int soc_camera_qbuf(struct file *file, void *priv,
@@ -415,7 +415,7 @@ static int soc_camera_qbuf(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		return videobuf_qbuf(&icd->vb_vidq, p);
 	else
-		return vb2_qbuf(&icd->vb2_vidq, p);
+		return vb2_v4l2_qbuf(&icd->vb2_vidq, p);
 }
 
 static int soc_camera_dqbuf(struct file *file, void *priv,
@@ -432,7 +432,7 @@ static int soc_camera_dqbuf(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		return videobuf_dqbuf(&icd->vb_vidq, p, file->f_flags & O_NONBLOCK);
 	else
-		return vb2_dqbuf(&icd->vb2_vidq, p, file->f_flags & O_NONBLOCK);
+		return vb2_v4l2_dqbuf(&icd->vb2_vidq, p, file->f_flags & O_NONBLOCK);
 }
 
 static int soc_camera_create_bufs(struct file *file, void *priv,
@@ -445,7 +445,7 @@ static int soc_camera_create_bufs(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		return -EINVAL;
 	else
-		return vb2_create_bufs(&icd->vb2_vidq, create);
+		return vb2_v4l2_create_bufs(&icd->vb2_vidq, create);
 }
 
 static int soc_camera_prepare_buf(struct file *file, void *priv,
@@ -458,7 +458,7 @@ static int soc_camera_prepare_buf(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		return -EINVAL;
 	else
-		return vb2_prepare_buf(&icd->vb2_vidq, b);
+		return vb2_v4l2_prepare_buf(&icd->vb2_vidq, b);
 }
 
 static int soc_camera_expbuf(struct file *file, void *priv,
@@ -474,7 +474,7 @@ static int soc_camera_expbuf(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		return -EINVAL;
 	else
-		return vb2_expbuf(&icd->vb2_vidq, p);
+		return vb2_v4l2_expbuf(&icd->vb2_vidq, p);
 }
 
 /* Always entered with .host_lock held */
@@ -786,7 +786,7 @@ static int soc_camera_close(struct file *file)
 		pm_runtime_disable(&icd->vdev->dev);
 
 		if (ici->ops->init_videobuf2)
-			vb2_queue_release(&icd->vb2_vidq);
+			vb2_v4l2_queue_release(&icd->vb2_vidq);
 		__soc_camera_power_off(icd);
 
 		soc_camera_remove_device(icd);
@@ -812,7 +812,7 @@ static ssize_t soc_camera_read(struct file *file, char __user *buf,
 	dev_dbg(icd->pdev, "read called, buf %p\n", buf);
 
 	if (ici->ops->init_videobuf2 && icd->vb2_vidq.io_modes & VB2_READ)
-		return vb2_read(&icd->vb2_vidq, buf, count, ppos,
+		return vb2_v4l2_read(&icd->vb2_vidq, buf, count, ppos,
 				file->f_flags & O_NONBLOCK);
 
 	dev_err(icd->pdev, "camera device read not implemented\n");
@@ -978,7 +978,7 @@ static int soc_camera_streamon(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		ret = videobuf_streamon(&icd->vb_vidq);
 	else
-		ret = vb2_streamon(&icd->vb2_vidq, i);
+		ret = vb2_v4l2_streamon(&icd->vb2_vidq, i);
 
 	if (!ret)
 		v4l2_subdev_call(sd, video, s_stream, 1);
@@ -1008,7 +1008,7 @@ static int soc_camera_streamoff(struct file *file, void *priv,
 	if (ici->ops->init_videobuf)
 		videobuf_streamoff(&icd->vb_vidq);
 	else
-		vb2_streamoff(&icd->vb2_vidq, i);
+		vb2_v4l2_streamoff(&icd->vb2_vidq, i);
 
 	v4l2_subdev_call(sd, video, s_stream, 0);
 
diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
index df61355..193904a 100644
--- a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
+++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
@@ -476,7 +476,7 @@ static int bdisp_buf_prepare(struct vb2_buffer *vb)
 	}
 
 	if (vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
-		vb2_set_plane_payload(vb, 0, frame->sizeimage);
+		vb2_v4l2_set_plane_payload(vb, 0, frame->sizeimage);
 
 	return 0;
 }
@@ -486,7 +486,7 @@ static void bdisp_buf_queue(struct vb2_buffer *vb)
 	struct bdisp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
 
 	/* return to V4L2 any 0-size buffer so it can be dequeued by user */
-	if (!vb2_get_plane_payload(vb, 0)) {
+	if (!vb2_v4l2_get_plane_payload(vb, 0)) {
 		dev_dbg(ctx->bdisp_dev->dev, "0 data buffer, skip it\n");
 		vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
 		return;
@@ -554,7 +554,7 @@ static int queue_init(void *priv,
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &ctx->bdisp_dev->lock;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -568,7 +568,7 @@ static int queue_init(void *priv,
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->bdisp_dev->lock;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 static int bdisp_open(struct file *file)
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index 6934a95..58c2ed3 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1845,17 +1845,17 @@ static int vpe_buf_prepare(struct vb2_buffer *vb)
 	}
 
 	for (i = 0; i < num_planes; i++) {
-		if (vb2_plane_size(vb, i) < q_data->sizeimage[i]) {
+		if (vb2_v4l2_plane_size(vb, i) < q_data->sizeimage[i]) {
 			vpe_err(ctx->dev,
 				"data will not fit into plane (%lu < %lu)\n",
-				vb2_plane_size(vb, i),
+				vb2_v4l2_plane_size(vb, i),
 				(long) q_data->sizeimage[i]);
 			return -EINVAL;
 		}
 	}
 
 	for (i = 0; i < num_planes; i++)
-		vb2_set_plane_payload(vb, i, q_data->sizeimage[i]);
+		vb2_v4l2_set_plane_payload(vb, i, q_data->sizeimage[i]);
 
 	return 0;
 }
@@ -1910,7 +1910,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &dev->dev_mutex;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -1924,7 +1924,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &dev->dev_mutex;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 static const struct v4l2_ctrl_config vpe_bufs_per_job = {
diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
index 7664319..1d3cc3d 100644
--- a/drivers/media/platform/vim2m.c
+++ b/drivers/media/platform/vim2m.c
@@ -221,7 +221,7 @@ static int device_process(struct vim2m_ctx *ctx,
 		return -EFAULT;
 	}
 
-	if (vb2_plane_size(&in_vb->vb2_buf, 0) > vb2_plane_size(&out_vb->vb2_buf, 0)) {
+	if (vb2_v4l2_plane_size(&in_vb->vb2_buf, 0) > vb2_v4l2_plane_size(&out_vb->vb2_buf, 0)) {
 		v4l2_err(&dev->v4l2_dev, "Output buffer is too small\n");
 		return -EINVAL;
 	}
@@ -763,13 +763,13 @@ static int vim2m_buf_prepare(struct vb2_buffer *vb)
 		}
 	}
 
-	if (vb2_plane_size(vb, 0) < q_data->sizeimage) {
+	if (vb2_v4l2_plane_size(vb, 0) < q_data->sizeimage) {
 		dprintk(ctx->dev, "%s data will not fit into plane (%lu < %lu)\n",
-				__func__, vb2_plane_size(vb, 0), (long)q_data->sizeimage);
+				__func__, vb2_v4l2_plane_size(vb, 0), (long)q_data->sizeimage);
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, q_data->sizeimage);
+	vb2_v4l2_set_plane_payload(vb, 0, q_data->sizeimage);
 
 	return 0;
 }
@@ -834,7 +834,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *ds
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &ctx->dev->dev_mutex;
 
-	ret = vb2_queue_init(src_vq);
+	ret = vb2_v4l2_queue_init(src_vq);
 	if (ret)
 		return ret;
 
@@ -847,7 +847,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *ds
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->dev->dev_mutex;
 
-	return vb2_queue_init(dst_vq);
+	return vb2_v4l2_queue_init(dst_vq);
 }
 
 static const struct v4l2_ctrl_config vim2m_ctrl_trans_time_msec = {
diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c
index a047b47..3811593 100644
--- a/drivers/media/platform/vivid/vivid-core.c
+++ b/drivers/media/platform/vivid/vivid-core.c
@@ -1040,7 +1040,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		q->min_buffers_needed = 2;
 		q->lock = &dev->mutex;
 
-		ret = vb2_queue_init(q);
+		ret = vb2_v4l2_queue_init(q);
 		if (ret)
 			goto unreg_dev;
 	}
@@ -1059,7 +1059,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		q->min_buffers_needed = 2;
 		q->lock = &dev->mutex;
 
-		ret = vb2_queue_init(q);
+		ret = vb2_v4l2_queue_init(q);
 		if (ret)
 			goto unreg_dev;
 	}
@@ -1078,7 +1078,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		q->min_buffers_needed = 2;
 		q->lock = &dev->mutex;
 
-		ret = vb2_queue_init(q);
+		ret = vb2_v4l2_queue_init(q);
 		if (ret)
 			goto unreg_dev;
 	}
@@ -1097,7 +1097,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		q->min_buffers_needed = 2;
 		q->lock = &dev->mutex;
 
-		ret = vb2_queue_init(q);
+		ret = vb2_v4l2_queue_init(q);
 		if (ret)
 			goto unreg_dev;
 	}
@@ -1115,7 +1115,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		q->min_buffers_needed = 8;
 		q->lock = &dev->mutex;
 
-		ret = vb2_queue_init(q);
+		ret = vb2_v4l2_queue_init(q);
 		if (ret)
 			goto unreg_dev;
 	}
diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.c b/drivers/media/platform/vivid/vivid-sdr-cap.c
index cf7f56c..fdcf7d2 100644
--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
+++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
@@ -235,12 +235,12 @@ static int sdr_cap_buf_prepare(struct vb2_buffer *vb)
 		dev->buf_prepare_error = false;
 		return -EINVAL;
 	}
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dprintk(dev, 1, "%s data will not fit into plane (%lu < %u)\n",
-				__func__, vb2_plane_size(vb, 0), size);
+				__func__, vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -495,7 +495,7 @@ void vivid_sdr_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 {
 	u8 *vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
 	unsigned long i;
-	unsigned long plane_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
+	unsigned long plane_size = vb2_v4l2_plane_size(&buf->vb.vb2_buf, 0);
 	s32 src_phase_step;
 	s32 mod_phase_step;
 	s32 fixp_i;
diff --git a/drivers/media/platform/vivid/vivid-vbi-cap.c b/drivers/media/platform/vivid/vivid-vbi-cap.c
index 26837e4..7a3b694 100644
--- a/drivers/media/platform/vivid/vivid-vbi-cap.c
+++ b/drivers/media/platform/vivid/vivid-vbi-cap.c
@@ -103,7 +103,7 @@ void vivid_raw_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *buf)
 
 	vivid_sliced_vbi_cap_fill(dev, buf->vb.v4l2_buf.sequence);
 
-	memset(vbuf, 0x10, vb2_plane_size(&buf->vb.vb2_buf, 0));
+	memset(vbuf, 0x10, vb2_v4l2_plane_size(&buf->vb.vb2_buf, 0));
 
 	if (!VIVID_INVALID_SIGNAL(dev->std_signal_mode))
 		vivid_vbi_gen_raw(&dev->vbi_gen, &vbi, vbuf);
@@ -124,7 +124,7 @@ void vivid_sliced_vbi_cap_process(struct vivid_dev *dev, struct vivid_buffer *bu
 
 	vivid_sliced_vbi_cap_fill(dev, buf->vb.v4l2_buf.sequence);
 
-	memset(vbuf, 0, vb2_plane_size(&buf->vb.vb2_buf, 0));
+	memset(vbuf, 0, vb2_v4l2_plane_size(&buf->vb.vb2_buf, 0));
 	if (!VIVID_INVALID_SIGNAL(dev->std_signal_mode)) {
 		unsigned i;
 
@@ -176,12 +176,12 @@ static int vbi_cap_buf_prepare(struct vb2_buffer *vb)
 		dev->buf_prepare_error = false;
 		return -EINVAL;
 	}
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dprintk(dev, 1, "%s data will not fit into plane (%lu < %u)\n",
-				__func__, vb2_plane_size(vb, 0), size);
+				__func__, vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
diff --git a/drivers/media/platform/vivid/vivid-vbi-out.c b/drivers/media/platform/vivid/vivid-vbi-out.c
index a51fc70..86580ea 100644
--- a/drivers/media/platform/vivid/vivid-vbi-out.c
+++ b/drivers/media/platform/vivid/vivid-vbi-out.c
@@ -67,12 +67,12 @@ static int vbi_out_buf_prepare(struct vb2_buffer *vb)
 		dev->buf_prepare_error = false;
 		return -EINVAL;
 	}
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dprintk(dev, 1, "%s data will not fit into plane (%lu < %u)\n",
-				__func__, vb2_plane_size(vb, 0), size);
+				__func__, vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -223,7 +223,7 @@ void vivid_sliced_vbi_out_process(struct vivid_dev *dev, struct vivid_buffer *bu
 {
 	struct v4l2_sliced_vbi_data *vbi = vb2_plane_vaddr(&buf->vb.vb2_buf,
 							   0);
-	unsigned elems = vb2_get_plane_payload(&buf->vb.vb2_buf, 0) / sizeof(*vbi);
+	unsigned elems = vb2_v4l2_get_plane_payload(&buf->vb.vb2_buf, 0) / sizeof(*vbi);
 
 	dev->vbi_out_have_cc[0] = false;
 	dev->vbi_out_have_cc[1] = false;
diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
index 3ffa410..bc876f8 100644
--- a/drivers/media/platform/vivid/vivid-vid-cap.c
+++ b/drivers/media/platform/vivid/vivid-vid-cap.c
@@ -193,13 +193,13 @@ static int vid_cap_buf_prepare(struct vb2_buffer *vb)
 		size = tpg_g_line_width(&dev->tpg, p) * dev->fmt_cap_rect.height +
 			dev->fmt_cap->data_offset[p];
 
-		if (vb2_plane_size(vb, p) < size) {
+		if (vb2_v4l2_plane_size(vb, p) < size) {
 			dprintk(dev, 1, "%s data will not fit into plane %u (%lu < %lu)\n",
-					__func__, p, vb2_plane_size(vb, p), size);
+					__func__, p, vb2_v4l2_plane_size(vb, p), size);
 			return -EINVAL;
 		}
 
-		vb2_set_plane_payload(vb, p, size);
+		vb2_v4l2_set_plane_payload(vb, p, size);
 		vbuf->v4l2_planes[p].data_offset = dev->fmt_cap->data_offset[p];
 	}
 
diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
index 9d3055c..72fc616 100644
--- a/drivers/media/platform/vivid/vivid-vid-out.c
+++ b/drivers/media/platform/vivid/vivid-vid-out.c
@@ -142,9 +142,9 @@ static int vid_out_buf_prepare(struct vb2_buffer *vb)
 		size = dev->bytesperline_out[p] * dev->fmt_out_rect.height +
 			vbuf->v4l2_planes[p].data_offset;
 
-		if (vb2_get_plane_payload(vb, p) < size) {
+		if (vb2_v4l2_get_plane_payload(vb, p) < size) {
 			dprintk(dev, 1, "%s the payload is too small for plane %u (%lu < %lu)\n",
-					__func__, p, vb2_get_plane_payload(vb, p), size);
+					__func__, p, vb2_v4l2_get_plane_payload(vb, p), size);
 			return -EINVAL;
 		}
 	}
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index ee47aaf..0ec2218 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -613,7 +613,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)
-		vb2_set_plane_payload(&done->buf.vb2_buf, i,
+		vb2_v4l2_set_plane_payload(&done->buf.vb2_buf, i,
 				      done->length[i]);
 	vb2_buffer_done(&done->buf.vb2_buf, VB2_BUF_STATE_DONE);
 
@@ -833,7 +833,7 @@ static int vsp1_video_buffer_prepare(struct vb2_buffer *vb)
 
 	for (i = 0; i < vb->num_planes; ++i) {
 		buf->addr[i] = vb2_dma_contig_plane_dma_addr(vb, i);
-		buf->length[i] = vb2_plane_size(vb, i);
+		buf->length[i] = vb2_v4l2_plane_size(vb, i);
 
 		if (buf->length[i] < format->plane_fmt[i].sizeimage)
 			return -EINVAL;
@@ -1098,7 +1098,7 @@ vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 		goto err_stop;
 
 	/* Start the queue. */
-	ret = vb2_streamon(&video->queue, type);
+	ret = vb2_v4l2_streamon(&video->queue, type);
 	if (ret < 0)
 		goto err_cleanup;
 
@@ -1164,7 +1164,7 @@ static int vsp1_video_release(struct file *file)
 
 	mutex_lock(&video->lock);
 	if (video->queue.owner == vfh) {
-		vb2_queue_release(&video->queue);
+		vb2_v4l2_queue_release(&video->queue);
 		video->queue.owner = NULL;
 	}
 	mutex_unlock(&video->lock);
@@ -1268,7 +1268,7 @@ int vsp1_video_init(struct vsp1_video *video, struct vsp1_entity *rwpf)
 	video->queue.ops = &vsp1_video_queue_qops;
 	video->queue.mem_ops = &vb2_dma_contig_memops;
 	video->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
-	ret = vb2_queue_init(&video->queue);
+	ret = vb2_v4l2_queue_init(&video->queue);
 	if (ret < 0) {
 		dev_err(video->vsp1->dev, "failed to initialize vb2 queue\n");
 		goto error;
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index d9dcd4b..57045d3 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -304,7 +304,7 @@ static void xvip_dma_complete(void *param)
 	buf->buf.v4l2_buf.field = V4L2_FIELD_NONE;
 	buf->buf.v4l2_buf.sequence = dma->sequence++;
 	v4l2_get_timestamp(&buf->buf.v4l2_buf.timestamp);
-	vb2_set_plane_payload(&buf->buf, 0, dma->format.sizeimage);
+	vb2_v4l2_set_plane_payload(&buf->buf, 0, dma->format.sizeimage);
 	vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE);
 }
 
@@ -720,7 +720,7 @@ int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma,
 	dma->queue.mem_ops = &vb2_dma_contig_memops;
 	dma->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
 				   | V4L2_BUF_FLAG_TSTAMP_SRC_EOF;
-	ret = vb2_queue_init(&dma->queue);
+	ret = vb2_v4l2_queue_init(&dma->queue);
 	if (ret < 0) {
 		dev_err(dma->xdev->dev, "failed to initialize VB2 queue\n");
 		goto error;
diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c
index 826687b..852da7c 100644
--- a/drivers/media/usb/airspy/airspy.c
+++ b/drivers/media/usb/airspy/airspy.c
@@ -313,7 +313,7 @@ static void airspy_urb_complete(struct urb *urb)
 		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		len = airspy_convert_stream(s, ptr, urb->transfer_buffer,
 				urb->actual_length);
-		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len);
+		vb2_v4l2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len);
 		v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
 		fbuf->vb.v4l2_buf.sequence = s->sequence++;
 		vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE);
@@ -1024,7 +1024,7 @@ static int airspy_probe(struct usb_interface *intf,
 	s->vb_queue.ops = &airspy_vb2_ops;
 	s->vb_queue.mem_ops = &vb2_vmalloc_memops;
 	s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	ret = vb2_queue_init(&s->vb_queue);
+	ret = vb2_v4l2_queue_init(&s->vb_queue);
 	if (ret) {
 		dev_err(s->dev, "Could not initialize vb2 queue\n");
 		goto err_free_mem;
diff --git a/drivers/media/usb/au0828/au0828-vbi.c b/drivers/media/usb/au0828/au0828-vbi.c
index c207c03..2e15ddd 100644
--- a/drivers/media/usb/au0828/au0828-vbi.c
+++ b/drivers/media/usb/au0828/au0828-vbi.c
@@ -57,12 +57,12 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 
 	size = dev->vbi_width * dev->vbi_height * 2;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		pr_err("%s data will not fit into plane (%lu < %lu)\n",
-			__func__, vb2_plane_size(vb, 0), size);
+			__func__, vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -77,7 +77,7 @@ vbi_buffer_queue(struct vb2_buffer *vb)
 	unsigned long flags = 0;
 
 	buf->mem = vb2_plane_vaddr(vb, 0);
-	buf->length = vb2_plane_size(vb, 0);
+	buf->length = vb2_v4l2_plane_size(vb, 0);
 
 	spin_lock_irqsave(&dev->slock, flags);
 	list_add_tail(&buf->list, &vbiq->active);
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index c73c627..36c694f 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -666,12 +666,12 @@ buffer_prepare(struct vb2_buffer *vb)
 
 	buf->length = dev->height * dev->bytesperline;
 
-	if (vb2_plane_size(vb, 0) < buf->length) {
+	if (vb2_v4l2_plane_size(vb, 0) < buf->length) {
 		pr_err("%s data will not fit into plane (%lu < %lu)\n",
-			__func__, vb2_plane_size(vb, 0), buf->length);
+			__func__, vb2_v4l2_plane_size(vb, 0), buf->length);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, buf->length);
+	vb2_v4l2_set_plane_payload(vb, 0, buf->length);
 	return 0;
 }
 
@@ -687,7 +687,7 @@ buffer_queue(struct vb2_buffer *vb)
 	unsigned long flags = 0;
 
 	buf->mem = vb2_plane_vaddr(vb, 0);
-	buf->length = vb2_plane_size(vb, 0);
+	buf->length = vb2_v4l2_plane_size(vb, 0);
 
 	spin_lock_irqsave(&dev->slock, flags);
 	list_add_tail(&buf->list, &vidq->active);
@@ -1717,7 +1717,7 @@ static int au0828_vb2_setup(struct au0828_dev *dev)
 	q->ops = &au0828_video_qops;
 	q->mem_ops = &vb2_vmalloc_memops;
 
-	rc = vb2_queue_init(q);
+	rc = vb2_v4l2_queue_init(q);
 	if (rc < 0)
 		return rc;
 
@@ -1731,7 +1731,7 @@ static int au0828_vb2_setup(struct au0828_dev *dev)
 	q->ops = &au0828_vbi_qops;
 	q->mem_ops = &vb2_vmalloc_memops;
 
-	rc = vb2_queue_init(q);
+	rc = vb2_v4l2_queue_init(q);
 	if (rc < 0)
 		return rc;
 
@@ -1861,8 +1861,8 @@ int au0828_analog_register(struct au0828_dev *dev,
 err_reg_vbi_dev:
 	video_unregister_device(&dev->vdev);
 err_reg_vdev:
-	vb2_queue_release(&dev->vb_vidq);
-	vb2_queue_release(&dev->vb_vbiq);
+	vb2_v4l2_queue_release(&dev->vb_vidq);
+	vb2_v4l2_queue_release(&dev->vb_vbiq);
 	return ret;
 }
 
diff --git a/drivers/media/usb/em28xx/em28xx-vbi.c b/drivers/media/usb/em28xx/em28xx-vbi.c
index 4007b44..6076f8f 100644
--- a/drivers/media/usb/em28xx/em28xx-vbi.c
+++ b/drivers/media/usb/em28xx/em28xx-vbi.c
@@ -68,12 +68,12 @@ static int vbi_buffer_prepare(struct vb2_buffer *vb)
 
 	size = v4l2->vbi_width * v4l2->vbi_height * 2;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		printk(KERN_INFO "%s data will not fit into plane (%lu < %lu)\n",
-		       __func__, vb2_plane_size(vb, 0), size);
+		       __func__, vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -88,7 +88,7 @@ vbi_buffer_queue(struct vb2_buffer *vb)
 	unsigned long flags = 0;
 
 	buf->mem = vb2_plane_vaddr(vb, 0);
-	buf->length = vb2_plane_size(vb, 0);
+	buf->length = vb2_v4l2_plane_size(vb, 0);
 
 	spin_lock_irqsave(&dev->slock, flags);
 	list_add_tail(&buf->list, &vbiq->active);
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index b34ff421..20b84eb 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -911,12 +911,12 @@ buffer_prepare(struct vb2_buffer *vb)
 
 	size = (v4l2->width * v4l2->height * v4l2->format->depth + 7) >> 3;
 
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		em28xx_videodbg("%s data will not fit into plane (%lu < %lu)\n",
-				__func__, vb2_plane_size(vb, 0), size);
+				__func__, vb2_v4l2_plane_size(vb, 0), size);
 		return -EINVAL;
 	}
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 
 	return 0;
 }
@@ -1054,7 +1054,7 @@ buffer_queue(struct vb2_buffer *vb)
 
 	em28xx_videodbg("%s\n", __func__);
 	buf->mem = vb2_plane_vaddr(vb, 0);
-	buf->length = vb2_plane_size(vb, 0);
+	buf->length = vb2_v4l2_plane_size(vb, 0);
 
 	spin_lock_irqsave(&dev->slock, flags);
 	list_add_tail(&buf->list, &vidq->active);
@@ -1087,7 +1087,7 @@ static int em28xx_vb2_setup(struct em28xx *dev)
 	q->ops = &em28xx_video_qops;
 	q->mem_ops = &vb2_vmalloc_memops;
 
-	rc = vb2_queue_init(q);
+	rc = vb2_v4l2_queue_init(q);
 	if (rc < 0)
 		return rc;
 
@@ -1101,7 +1101,7 @@ static int em28xx_vb2_setup(struct em28xx *dev)
 	q->ops = &em28xx_vbi_qops;
 	q->mem_ops = &vb2_vmalloc_memops;
 
-	rc = vb2_queue_init(q);
+	rc = vb2_v4l2_queue_init(q);
 	if (rc < 0)
 		return rc;
 
diff --git a/drivers/media/usb/go7007/go7007-v4l2.c b/drivers/media/usb/go7007/go7007-v4l2.c
index 8183a1d..7bb18da 100644
--- a/drivers/media/usb/go7007/go7007-v4l2.c
+++ b/drivers/media/usb/go7007/go7007-v4l2.c
@@ -1118,7 +1118,7 @@ int go7007_v4l2_init(struct go7007 *go)
 	go->vidq.buf_struct_size = sizeof(struct go7007_buffer);
 	go->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	go->vidq.lock = &go->queue_lock;
-	rv = vb2_queue_init(&go->vidq);
+	rv = vb2_v4l2_queue_init(&go->vidq);
 	if (rv)
 		return rv;
 	*vdev = go7007_template;
diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c
index c07b44f..f55a374 100644
--- a/drivers/media/usb/hackrf/hackrf.c
+++ b/drivers/media/usb/hackrf/hackrf.c
@@ -290,7 +290,7 @@ static void hackrf_urb_complete(struct urb *urb)
 		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		len = hackrf_convert_stream(dev, ptr, urb->transfer_buffer,
 				urb->actual_length);
-		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len);
+		vb2_v4l2_set_plane_payload(&fbuf->vb.vb2_buf, 0, len);
 		v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
 		fbuf->vb.v4l2_buf.sequence = dev->sequence++;
 		vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE);
@@ -1058,7 +1058,7 @@ static int hackrf_probe(struct usb_interface *intf,
 	dev->vb_queue.ops = &hackrf_vb2_ops;
 	dev->vb_queue.mem_ops = &vb2_vmalloc_memops;
 	dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	ret = vb2_queue_init(&dev->vb_queue);
+	ret = vb2_v4l2_queue_init(&dev->vb_queue);
 	if (ret) {
 		dev_err(dev->dev, "Could not initialize vb2 queue\n");
 		goto err_free_mem;
diff --git a/drivers/media/usb/msi2500/msi2500.c b/drivers/media/usb/msi2500/msi2500.c
index af4dd23..69b6066 100644
--- a/drivers/media/usb/msi2500/msi2500.c
+++ b/drivers/media/usb/msi2500/msi2500.c
@@ -433,7 +433,7 @@ static void msi2500_isoc_handler(struct urb *urb)
 		/* fill framebuffer */
 		ptr = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
 		flen = msi2500_convert_stream(dev, ptr, iso_buf, flen);
-		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, flen);
+		vb2_v4l2_set_plane_payload(&fbuf->vb.vb2_buf, 0, flen);
 		vb2_buffer_done(&fbuf->vb.vb2_buf, VB2_BUF_STATE_DONE);
 	}
 
@@ -1222,7 +1222,7 @@ static int msi2500_probe(struct usb_interface *intf,
 	dev->vb_queue.ops = &msi2500_vb2_ops;
 	dev->vb_queue.mem_ops = &vb2_vmalloc_memops;
 	dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	ret = vb2_queue_init(&dev->vb_queue);
+	ret = vb2_v4l2_queue_init(&dev->vb_queue);
 	if (ret) {
 		dev_err(dev->dev, "Could not initialize vb2 queue\n");
 		goto err_free_mem;
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 79e4ca2..17d5d33 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -1011,7 +1011,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
 	pdev->vb_queue.ops = &pwc_vb_queue_ops;
 	pdev->vb_queue.mem_ops = &vb2_vmalloc_memops;
 	pdev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	rc = vb2_queue_init(&pdev->vb_queue);
+	rc = vb2_v4l2_queue_init(&pdev->vb_queue);
 	if (rc < 0) {
 		PWC_ERROR("Oops, could not initialize vb2 queue.\n");
 		goto err_free_mem;
diff --git a/drivers/media/usb/pwc/pwc-uncompress.c b/drivers/media/usb/pwc/pwc-uncompress.c
index 58b5518..425b508 100644
--- a/drivers/media/usb/pwc/pwc-uncompress.c
+++ b/drivers/media/usb/pwc/pwc-uncompress.c
@@ -55,12 +55,12 @@ int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
 			 * determine this using the type of the webcam */
 		memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
 		memcpy(raw_frame+1, yuv, pdev->frame_size);
-		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
+		vb2_v4l2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
 				      pdev->frame_size + sizeof(struct pwc_raw_frame));
 		return 0;
 	}
 
-	vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
+	vb2_v4l2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
 			      pdev->width * pdev->height * 3 / 2);
 
 	if (pdev->vbandlength == 0) {
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 0d909a4..5bda74f 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -636,7 +636,7 @@ static void s2255_fillbuff(struct s2255_vc *vc,
 			break;
 		case V4L2_PIX_FMT_JPEG:
 		case V4L2_PIX_FMT_MJPEG:
-			vb2_set_plane_payload(&buf->vb.vb2_buf, 0,
+			vb2_v4l2_set_plane_payload(&buf->vb.vb2_buf, 0,
 					      jpgsize);
 			memcpy(vbuf, tmpbuf, jpgsize);
 			break;
@@ -692,12 +692,12 @@ static int buffer_prepare(struct vb2_buffer *vb)
 		return -EINVAL;
 	}
 	size = w * h * (vc->fmt->depth >> 3);
-	if (vb2_plane_size(vb, 0) < size) {
+	if (vb2_v4l2_plane_size(vb, 0) < size) {
 		dprintk(vc->dev, 4, "invalid buffer prepare\n");
 		return -EINVAL;
 	}
 
-	vb2_set_plane_payload(vb, 0, size);
+	vb2_v4l2_set_plane_payload(vb, 0, size);
 	return 0;
 }
 
@@ -1664,10 +1664,10 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
 		q->mem_ops = &vb2_vmalloc_memops;
 		q->ops = &s2255_video_qops;
 		q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-		ret = vb2_queue_init(q);
+		ret = vb2_v4l2_queue_init(q);
 		if (ret != 0) {
 			dev_err(&dev->udev->dev,
-				"%s vb2_queue_init 0x%x\n", __func__, ret);
+				"%s vb2_v4l2_queue_init 0x%x\n", __func__, ret);
 			break;
 		}
 		/* register video devices */
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index a7daa08..abcd14b 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -709,7 +709,7 @@ static void buffer_queue(struct vb2_buffer *vb)
 	} else {
 
 		buf->mem = vb2_plane_vaddr(vb, 0);
-		buf->length = vb2_plane_size(vb, 0);
+		buf->length = vb2_v4l2_plane_size(vb, 0);
 		buf->bytesused = 0;
 		buf->pos = 0;
 
@@ -801,7 +801,7 @@ int stk1160_vb2_setup(struct stk1160 *dev)
 	q->mem_ops = &vb2_vmalloc_memops;
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
-	rc = vb2_queue_init(q);
+	rc = vb2_v4l2_queue_init(q);
 	if (rc < 0)
 		return rc;
 
diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c
index ff1f327..fc705b6 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -101,7 +101,7 @@ void stk1160_buffer_done(struct stk1160 *dev)
 	buf->vb.v4l2_buf.bytesused = buf->bytesused;
 	v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
 
-	vb2_set_plane_payload(&buf->vb.vb2_buf, 0, buf->bytesused);
+	vb2_v4l2_set_plane_payload(&buf->vb.vb2_buf, 0, buf->bytesused);
 	vb2_buffer_done(&buf->vb.vb2_buf, 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 3e17802..1f75dcc 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -314,7 +314,7 @@ static void usbtv_image_chunk(struct usbtv *usbtv, __be32 *chunk)
 
 	/* Last chunk in a frame, signalling an end */
 	if (odd && chunk_no == usbtv->n_chunks-1) {
-		int size = vb2_plane_size(&buf->vb.vb2_buf, 0);
+		int size = vb2_v4l2_plane_size(&buf->vb.vb2_buf, 0);
 		enum vb2_buffer_state state = usbtv->chunks_done ==
 						usbtv->n_chunks ?
 						VB2_BUF_STATE_DONE :
@@ -323,7 +323,7 @@ static void usbtv_image_chunk(struct usbtv *usbtv, __be32 *chunk)
 		buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
 		buf->vb.v4l2_buf.sequence = usbtv->sequence++;
 		v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
-		vb2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
+		vb2_v4l2_set_plane_payload(&buf->vb.vb2_buf, 0, size);
 		vb2_buffer_done(&buf->vb.vb2_buf, state);
 		list_del(&buf->list);
 	}
@@ -664,7 +664,7 @@ static void usbtv_release(struct v4l2_device *v4l2_dev)
 	struct usbtv *usbtv = container_of(v4l2_dev, struct usbtv, v4l2_dev);
 
 	v4l2_device_unregister(&usbtv->v4l2_dev);
-	vb2_queue_release(&usbtv->vb2q);
+	vb2_v4l2_queue_release(&usbtv->vb2q);
 	kfree(usbtv);
 }
 
@@ -688,7 +688,7 @@ int usbtv_video_init(struct usbtv *usbtv)
 	usbtv->vb2q.mem_ops = &vb2_vmalloc_memops;
 	usbtv->vb2q.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 	usbtv->vb2q.lock = &usbtv->vb2q_lock;
-	ret = vb2_queue_init(&usbtv->vb2q);
+	ret = vb2_v4l2_queue_init(&usbtv->vb2q);
 	if (ret < 0) {
 		dev_warn(usbtv->dev, "Could not initialize videobuf2 queue\n");
 		return ret;
@@ -723,7 +723,7 @@ int usbtv_video_init(struct usbtv *usbtv)
 vdev_fail:
 	v4l2_device_unregister(&usbtv->v4l2_dev);
 v4l2_fail:
-	vb2_queue_release(&usbtv->vb2q);
+	vb2_v4l2_queue_release(&usbtv->vb2q);
 
 	return ret;
 }
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 2905123..ed96374 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -95,7 +95,7 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 	struct uvc_buffer *buf = container_of(vbuf, struct uvc_buffer, buf);
 
 	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
-	    vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
+	    vb2_v4l2_get_plane_payload(vb, 0) > vb2_v4l2_plane_size(vb, 0)) {
 		uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
 		return -EINVAL;
 	}
@@ -106,11 +106,11 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 	buf->state = UVC_BUF_STATE_QUEUED;
 	buf->error = 0;
 	buf->mem = vb2_plane_vaddr(vb, 0);
-	buf->length = vb2_plane_size(vb, 0);
+	buf->length = vb2_v4l2_plane_size(vb, 0);
 	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
 		buf->bytesused = 0;
 	else
-		buf->bytesused = vb2_get_plane_payload(vb, 0);
+		buf->bytesused = vb2_v4l2_get_plane_payload(vb, 0);
 
 	return 0;
 }
@@ -205,7 +205,7 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
 	queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
 		| V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
 	queue->queue.lock = &queue->mutex;
-	ret = vb2_queue_init(&queue->queue);
+	ret = vb2_v4l2_queue_init(&queue->queue);
 	if (ret)
 		return ret;
 
@@ -220,7 +220,7 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
 void uvc_queue_release(struct uvc_video_queue *queue)
 {
 	mutex_lock(&queue->mutex);
-	vb2_queue_release(&queue->queue);
+	vb2_v4l2_queue_release(&queue->queue);
 	mutex_unlock(&queue->mutex);
 }
 
@@ -234,7 +234,7 @@ int uvc_request_buffers(struct uvc_video_queue *queue,
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_reqbufs(&queue->queue, rb);
+	ret = vb2_v4l2_reqbufs(&queue->queue, rb);
 	mutex_unlock(&queue->mutex);
 
 	return ret ? ret : rb->count;
@@ -245,7 +245,7 @@ int uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_querybuf(&queue->queue, buf);
+	ret = vb2_v4l2_querybuf(&queue->queue, buf);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -257,7 +257,7 @@ int uvc_create_buffers(struct uvc_video_queue *queue,
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_create_bufs(&queue->queue, cb);
+	ret = vb2_v4l2_create_bufs(&queue->queue, cb);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -268,7 +268,7 @@ int uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_qbuf(&queue->queue, buf);
+	ret = vb2_v4l2_qbuf(&queue->queue, buf);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -280,7 +280,7 @@ int uvc_export_buffer(struct uvc_video_queue *queue,
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_expbuf(&queue->queue, exp);
+	ret = vb2_v4l2_expbuf(&queue->queue, exp);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -292,7 +292,7 @@ int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf,
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_dqbuf(&queue->queue, buf, nonblocking);
+	ret = vb2_v4l2_dqbuf(&queue->queue, buf, nonblocking);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -303,7 +303,7 @@ int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type)
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_streamon(&queue->queue, type);
+	ret = vb2_v4l2_streamon(&queue->queue, type);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -314,7 +314,7 @@ int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type)
 	int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_streamoff(&queue->queue, type);
+	ret = vb2_v4l2_streamoff(&queue->queue, type);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -339,7 +339,7 @@ unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
 	unsigned int ret;
 
 	mutex_lock(&queue->mutex);
-	ret = vb2_poll(&queue->queue, file, wait);
+	ret = vb2_v4l2_poll(&queue->queue, file, wait);
 	mutex_unlock(&queue->mutex);
 
 	return ret;
@@ -402,7 +402,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
 		buf->error = 0;
 		buf->state = UVC_BUF_STATE_QUEUED;
 		buf->bytesused = 0;
-		vb2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
+		vb2_v4l2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
 		return buf;
 	}
 
@@ -416,7 +416,7 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
 	spin_unlock_irqrestore(&queue->irqlock, flags);
 
 	buf->state = buf->error ? VB2_BUF_STATE_ERROR : UVC_BUF_STATE_DONE;
-	vb2_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
+	vb2_v4l2_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
 	vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
 
 	return nextbuf;
diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 8ea5de6..9e7434d 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -360,7 +360,7 @@ int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	int ret;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, reqbufs->type);
-	ret = vb2_reqbufs(vq, reqbufs);
+	ret = vb2_v4l2_reqbufs(vq, reqbufs);
 	/* If count == 0, then the owner has released all buffers and he
 	   is no longer owner of the queue. Otherwise we have an owner. */
 	if (ret == 0)
@@ -383,7 +383,7 @@ int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	unsigned int i;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
-	ret = vb2_querybuf(vq, buf);
+	ret = vb2_v4l2_querybuf(vq, buf);
 
 	/* Adjust MMAP memory offsets for the CAPTURE queue */
 	if (buf->memory == V4L2_MEMORY_MMAP && !V4L2_TYPE_IS_OUTPUT(vq->type)) {
@@ -411,7 +411,7 @@ int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	int ret;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
-	ret = vb2_qbuf(vq, buf);
+	ret = vb2_v4l2_qbuf(vq, buf);
 	if (!ret)
 		v4l2_m2m_try_schedule(m2m_ctx);
 
@@ -429,7 +429,7 @@ int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
-	return vb2_dqbuf(vq, buf, file->f_flags & O_NONBLOCK);
+	return vb2_v4l2_dqbuf(vq, buf, file->f_flags & O_NONBLOCK);
 }
 EXPORT_SYMBOL_GPL(v4l2_m2m_dqbuf);
 
@@ -444,7 +444,7 @@ int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	int ret;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
-	ret = vb2_prepare_buf(vq, buf);
+	ret = vb2_v4l2_prepare_buf(vq, buf);
 	if (!ret)
 		v4l2_m2m_try_schedule(m2m_ctx);
 
@@ -462,7 +462,7 @@ int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, create->format.type);
-	return vb2_create_bufs(vq, create);
+	return vb2_v4l2_create_bufs(vq, create);
 }
 EXPORT_SYMBOL_GPL(v4l2_m2m_create_bufs);
 
@@ -476,7 +476,7 @@ int v4l2_m2m_expbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	struct vb2_queue *vq;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, eb->type);
-	return vb2_expbuf(vq, eb);
+	return vb2_v4l2_expbuf(vq, eb);
 }
 EXPORT_SYMBOL_GPL(v4l2_m2m_expbuf);
 /**
@@ -489,7 +489,7 @@ int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	int ret;
 
 	vq = v4l2_m2m_get_vq(m2m_ctx, type);
-	ret = vb2_streamon(vq, type);
+	ret = vb2_v4l2_streamon(vq, type);
 	if (!ret)
 		v4l2_m2m_try_schedule(m2m_ctx);
 
@@ -512,7 +512,7 @@ int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 	v4l2_m2m_cancel_job(m2m_ctx);
 
 	q_ctx = get_queue_ctx(m2m_ctx, type);
-	ret = vb2_streamoff(&q_ctx->q, type);
+	ret = vb2_v4l2_streamoff(&q_ctx->q, type);
 	if (ret)
 		return ret;
 
@@ -761,8 +761,8 @@ void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx)
 	/* wait until the current context is dequeued from job_queue */
 	v4l2_m2m_cancel_job(m2m_ctx);
 
-	vb2_queue_release(&m2m_ctx->cap_q_ctx.q);
-	vb2_queue_release(&m2m_ctx->out_q_ctx.q);
+	vb2_v4l2_queue_release(&m2m_ctx->cap_q_ctx.q);
+	vb2_v4l2_queue_release(&m2m_ctx->out_q_ctx.q);
 
 	kfree(m2m_ctx);
 }
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 7888338..38632ea 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -432,7 +432,7 @@ static bool __buffers_in_use(struct vb2_queue *q)
 }
 
 /**
- * vb2_core_querybuf() - query video buffer information
+ * vb2_querybuf() - query video buffer information
  * @q:		videobuf queue
  * @type:	enum vb2_buf_type; buffer type (type == *_MPLANE for
  *		multiplanar buffers);
@@ -447,7 +447,7 @@ static bool __buffers_in_use(struct vb2_queue *q)
  * 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, enum vb2_buf_type type,
+int vb2_querybuf(struct vb2_queue *q, enum vb2_buf_type type,
 		unsigned int index, void *pb)
 {
 	struct vb2_buffer *vb;
@@ -469,7 +469,7 @@ int vb2_core_querybuf(struct vb2_queue *q, enum vb2_buf_type type,
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(vb2_core_querybuf);
+EXPORT_SYMBOL_GPL(vb2_querybuf);
 
 /**
  * __verify_userptr_ops() - verify that all memory operations required for
@@ -562,7 +562,7 @@ int __verify_memory_type(struct vb2_queue *q,
 EXPORT_SYMBOL_GPL(__verify_memory_type);
 
 /**
- * vb2_core_reqbufs() - Initiate streaming
+ * vb2_reqbufs() - Initiate streaming
  * @q:		videobuf2 queue
  * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
  *
@@ -578,13 +578,13 @@ EXPORT_SYMBOL_GPL(__verify_memory_type);
  *    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
+ * If the queue has been allocated previously (by a previous vb2_v4l2_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 vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
+int vb2_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 		unsigned int *count)
 {
 	unsigned int num_buffers, allocated_buffers, num_planes = 0;
@@ -699,10 +699,10 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_core_reqbufs);
+EXPORT_SYMBOL_GPL(vb2_reqbufs);
 
 /**
- * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs
+ * vb2_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
@@ -716,7 +716,7 @@ EXPORT_SYMBOL_GPL(vb2_core_reqbufs);
  * The return values from this function are intended to be directly returned
  * from vidioc_create_bufs handler in driver.
  */
-int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
+int vb2_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 		unsigned int *count, void *parg)
 {
 	unsigned int num_planes = 0, num_buffers, allocated_buffers;
@@ -797,7 +797,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_core_create_bufs);
+EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
 /**
  * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
@@ -979,7 +979,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
 }
 
 /**
- * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace to the kernel
+ * 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
@@ -993,7 +993,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
  * 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 vb2_memory memory,
+int vb2_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
 		enum vb2_buf_type type, unsigned int index, void *pb)
 {
 	struct vb2_buffer *vb;
@@ -1025,7 +1025,7 @@ int vb2_core_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
 	}
 	return ret;
 }
-EXPORT_SYMBOL_GPL(vb2_core_prepare_buf);
+EXPORT_SYMBOL_GPL(vb2_prepare_buf);
 
 /**
  * vb2_start_streaming() - Attempt to start streaming.
@@ -1090,7 +1090,7 @@ static int vb2_start_streaming(struct vb2_queue *q)
 	return ret;
 }
 
-int vb2_core_qbuf(struct vb2_queue *q, enum vb2_memory memory,
+int vb2_qbuf(struct vb2_queue *q, enum vb2_memory memory,
 		enum vb2_buf_type type, unsigned int index, void *pb)
 {
 	int ret = vb2_queue_or_prepare_buf(q, memory, type, index, pb, "qbuf");
@@ -1161,7 +1161,7 @@ int vb2_core_qbuf(struct vb2_queue *q, enum vb2_memory memory,
 	VB2_DEBUG(1, "qbuf of buffer %d succeeded\n", vb2_index(vb));
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_core_qbuf);
+EXPORT_SYMBOL_GPL(vb2_qbuf);
 
 /**
  * __vb2_wait_for_done_vb() - wait for a buffer to become available
@@ -1299,9 +1299,9 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q)
 EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
 
 /**
- * __vb2_dqbuf() - bring back the buffer to the DEQUEUED state
+ * __vb2_v4l2_dqbuf() - bring back the buffer to the DEQUEUED state
  */
-static void __vb2_dqbuf(struct vb2_buffer *vb)
+static void __vb2_v4l2_dqbuf(struct vb2_buffer *vb)
 {
 	struct vb2_queue *q = vb->vb2_queue;
 	unsigned int i;
@@ -1322,7 +1322,7 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
 		}
 }
 
-int vb2_core_dqbuf(struct vb2_queue *q, enum vb2_buf_type type, void *pb,
+int vb2_dqbuf(struct vb2_queue *q, enum vb2_buf_type type, void *pb,
 		bool nonblocking)
 {
 	struct vb2_buffer *vb = NULL;
@@ -1361,14 +1361,14 @@ int vb2_core_dqbuf(struct vb2_queue *q, enum vb2_buf_type type, void *pb,
 	if (!VB2_TYPE_IS_OUTPUT(q->vb2_type) && call_bufop(q, is_last, vb))
 		q->last_buffer_dequeued = true;
 	/* go back to dequeued state */
-	__vb2_dqbuf(vb);
+	__vb2_v4l2_dqbuf(vb);
 
 	VB2_DEBUG(1, "dqbuf of buffer %d, with state %d\n",
 			vb2_index(vb), vb->state);
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_core_dqbuf);
+EXPORT_SYMBOL_GPL(vb2_dqbuf);
 
 /**
  * __vb2_queue_cancel() - cancel and stop (pause) streaming
@@ -1423,9 +1423,9 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 	 * 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
+	 * __vb2_v4l2_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().
+	 * be changed, so we can't move the buf_finish() to __vb2_v4l2_dqbuf().
 	 */
 	for (i = 0; i < q->num_buffers; ++i) {
 		struct vb2_buffer *vb = q->bufs[i];
@@ -1434,11 +1434,11 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 			vb->state = VB2_BUF_STATE_PREPARED;
 			call_void_vb_qop(vb, buf_finish, vb);
 		}
-		__vb2_dqbuf(vb);
+		__vb2_v4l2_dqbuf(vb);
 	}
 }
 
-int vb2_core_streamon(struct vb2_queue *q, enum vb2_buf_type type)
+int vb2_streamon(struct vb2_queue *q, enum vb2_buf_type type)
 {
 	int ret;
 
@@ -1480,7 +1480,7 @@ int vb2_core_streamon(struct vb2_queue *q, enum vb2_buf_type type)
 	VB2_DEBUG(3, "successful\n");
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_core_streamon);
+EXPORT_SYMBOL_GPL(vb2_streamon);
 
 /**
  * vb2_queue_error() - signal a fatal error on the queue
@@ -1491,7 +1491,7 @@ EXPORT_SYMBOL_GPL(vb2_core_streamon);
  * 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
+ * vb2_v4l2_streamoff or vb2_v4l2_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.
  */
@@ -1503,7 +1503,7 @@ void vb2_queue_error(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(vb2_queue_error);
 
-int vb2_core_streamoff(struct vb2_queue *q, enum vb2_buf_type type)
+int vb2_streamoff(struct vb2_queue *q, enum vb2_buf_type type)
 {
 	if (type != q->vb2_type) {
 		VB2_DEBUG(1, "invalid stream type\n");
@@ -1526,7 +1526,7 @@ int vb2_core_streamoff(struct vb2_queue *q, enum vb2_buf_type type)
 	VB2_DEBUG(3, "successful\n");
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_core_streamoff);
+EXPORT_SYMBOL_GPL(vb2_streamoff);
 
 /**
  * __find_plane_by_offset() - find plane associated with the given offset off
@@ -1558,7 +1558,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
 }
 
 /**
- * vb2_core_expbuf() - Export a buffer as a file descriptor
+ * 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
@@ -1566,7 +1566,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off,
  * 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, enum vb2_buf_type type, unsigned int index,
+int vb2_expbuf(struct vb2_queue *q, enum vb2_buf_type type, unsigned int index,
 		unsigned int plane, unsigned int flags)
 {
 	struct vb2_buffer *vb = NULL;
@@ -1632,7 +1632,7 @@ int vb2_core_expbuf(struct vb2_queue *q, enum vb2_buf_type type, unsigned int in
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(vb2_core_expbuf);
+EXPORT_SYMBOL_GPL(vb2_expbuf);
 
 /**
  * vb2_mmap() - map video buffers into application address space
@@ -1755,7 +1755,7 @@ EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
 #endif
 
 /**
- * vb2_core_queue_init() - initialize a videobuf2 queue
+ * 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
@@ -1765,7 +1765,7 @@ EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
  * to the struct vb2_queue description in include/media/videobuf2-v4l2.h
  * for more information.
  */
-int vb2_core_queue_init(struct vb2_queue *q)
+int vb2_queue_init(struct vb2_queue *q)
 {
 	/*
 	 * Sanity check
@@ -1788,24 +1788,24 @@ int vb2_core_queue_init(struct vb2_queue *q)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_core_queue_init);
+EXPORT_SYMBOL_GPL(vb2_queue_init);
 
 /**
- * vb2_core_queue_release() - stop streaming, release the queue and free memory
+ * 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_core_queue_release(struct vb2_queue *q)
+void vb2_queue_release(struct vb2_queue *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_core_queue_release);
+EXPORT_SYMBOL_GPL(vb2_queue_release);
 
 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-dvb.c b/drivers/media/v4l2-core/videobuf2-dvb.c
index d092698..9c18843 100644
--- a/drivers/media/v4l2-core/videobuf2-dvb.c
+++ b/drivers/media/v4l2-core/videobuf2-dvb.c
@@ -32,7 +32,7 @@ static int dvb_fnc(struct vb2_buffer *vb, void *priv)
 	struct vb2_dvb *dvb = priv;
 
 	dvb_dmx_swfilter(&dvb->demux, vb2_plane_vaddr(vb, 0),
-				      vb2_get_plane_payload(vb, 0));
+				      vb2_v4l2_get_plane_payload(vb, 0));
 	return 0;
 }
 
diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
index 22dd19c..939d554 100644
--- a/drivers/media/v4l2-core/videobuf2-v4l2.c
+++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
@@ -795,7 +795,7 @@ const struct vb2_trace_ops vb2_v4l2_trace_ops = {
 };
 
 /**
- * vb2_querybuf() - query video buffer information
+ * vb2_v4l2_querybuf() - query video buffer information
  * @q:		videobuf queue
  * @b:		buffer struct passed from userspace to vidioc_querybuf handler
  *		in driver
@@ -807,35 +807,35 @@ const struct vb2_trace_ops vb2_v4l2_trace_ops = {
  * 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)
+int vb2_v4l2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	return vb2_core_querybuf(q, to_vb2_buf_type(b->type), b->index, b);
+	return vb2_querybuf(q, to_vb2_buf_type(b->type), b->index, b);
 }
-EXPORT_SYMBOL(vb2_querybuf);
+EXPORT_SYMBOL(vb2_v4l2_querybuf);
 
 /**
- * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory and
+ * vb2_v4l2_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_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
+int vb2_v4l2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 {
 	int ret = __verify_memory_type(q, to_vb2_memory(req->memory),
 			to_vb2_buf_type(req->type));
 	q->memory = req->memory;
-	return ret ? ret : vb2_core_reqbufs(q, to_vb2_memory(req->memory), &req->count);
+	return ret ? ret : vb2_reqbufs(q, to_vb2_memory(req->memory), &req->count);
 }
-EXPORT_SYMBOL_GPL(vb2_reqbufs);
+EXPORT_SYMBOL_GPL(vb2_v4l2_reqbufs);
 
 /**
- * vb2_create_bufs() - Wrapper for __create_bufs() that also verifies the
+ * vb2_v4l2_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 *cb)
+int vb2_v4l2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb)
 {
 	int ret = __verify_memory_type(q, to_vb2_memory(cb->memory),
 			to_vb2_buf_type(cb->format.type));
@@ -844,12 +844,12 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb)
 	if (cb->count == 0)
 		return ret != -EBUSY ? ret : 0;
 	q->memory = cb->memory;
-	return ret ? ret : vb2_core_create_bufs(q, to_vb2_memory(cb->memory), &cb->count, &cb->format);
+	return ret ? ret : vb2_create_bufs(q, to_vb2_memory(cb->memory), &cb->count, &cb->format);
 }
-EXPORT_SYMBOL_GPL(vb2_create_bufs);
+EXPORT_SYMBOL_GPL(vb2_v4l2_create_bufs);
 
 /**
- * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel
+ * vb2_v4l2_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
@@ -863,14 +863,14 @@ EXPORT_SYMBOL_GPL(vb2_create_bufs);
  * 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)
+int vb2_v4l2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-	return vb2_core_prepare_buf(q, to_vb2_memory(b->memory), to_vb2_buf_type(b->type), b->index, b);
+	return vb2_prepare_buf(q, to_vb2_memory(b->memory), to_vb2_buf_type(b->type), b->index, b);
 }
-EXPORT_SYMBOL_GPL(vb2_prepare_buf);
+EXPORT_SYMBOL_GPL(vb2_v4l2_prepare_buf);
 
 /**
- * vb2_qbuf() - Queue a buffer from userspace
+ * vb2_v4l2_qbuf() - Queue a buffer from userspace
  * @q:		videobuf2 queue
  * @b:		buffer structure passed from userspace to vidioc_qbuf handler
  *		in driver
@@ -886,19 +886,19 @@ EXPORT_SYMBOL_GPL(vb2_prepare_buf);
  * 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)
+int vb2_v4l2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
 	if (vb2_fileio_is_active(q)) {
 		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
 
-	return vb2_core_qbuf(q, to_vb2_memory(b->memory), to_vb2_buf_type(b->type), b->index, b);
+	return vb2_qbuf(q, to_vb2_memory(b->memory), to_vb2_buf_type(b->type), b->index, b);
 }
-EXPORT_SYMBOL_GPL(vb2_qbuf);
+EXPORT_SYMBOL_GPL(vb2_v4l2_qbuf);
 
 /**
- * vb2_dqbuf() - Dequeue a buffer to the userspace
+ * vb2_v4l2_dqbuf() - Dequeue a buffer to the userspace
  * @q:		videobuf2 queue
  * @b:		buffer structure passed from userspace to vidioc_dqbuf handler
  *		in driver
@@ -918,18 +918,18 @@ EXPORT_SYMBOL_GPL(vb2_qbuf);
  * The return values from this function are intended to be directly returned
  * from vidioc_dqbuf handler in driver.
  */
-int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
+int vb2_v4l2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
 	if (vb2_fileio_is_active(q)) {
 		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_core_dqbuf(q, to_vb2_buf_type(b->type), b, nonblocking);
+	return vb2_dqbuf(q, to_vb2_buf_type(b->type), b, nonblocking);
 }
-EXPORT_SYMBOL_GPL(vb2_dqbuf);
+EXPORT_SYMBOL_GPL(vb2_v4l2_dqbuf);
 
 /**
- * vb2_expbuf() - Export a buffer as a file descriptor
+ * vb2_v4l2_expbuf() - Export a buffer as a file descriptor
  * @q:		videobuf2 queue
  * @eb:		export buffer structure passed from userspace to vidioc_expbuf
  *		handler in driver
@@ -937,16 +937,16 @@ EXPORT_SYMBOL_GPL(vb2_dqbuf);
  * 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_v4l2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb)
 {
-	eb->fd = vb2_core_expbuf(q, to_vb2_buf_type(eb->type), eb->index, eb->plane, eb->flags);
+	eb->fd = vb2_expbuf(q, to_vb2_buf_type(eb->type), eb->index, eb->plane, eb->flags);
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(vb2_expbuf);
+EXPORT_SYMBOL_GPL(vb2_v4l2_expbuf);
 
 /**
- * vb2_streamon - start streaming
+ * vb2_v4l2_streamon - start streaming
  * @q:		videobuf2 queue
  * @type:	type argument passed from userspace to vidioc_streamon handler
  *
@@ -958,19 +958,19 @@ EXPORT_SYMBOL_GPL(vb2_expbuf);
  * 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_v4l2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
 {
 	if (vb2_fileio_is_active(q)) {
 		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
 
-	return vb2_core_streamon(q, to_vb2_buf_type(type));
+	return vb2_streamon(q, to_vb2_buf_type(type));
 }
-EXPORT_SYMBOL_GPL(vb2_streamon);
+EXPORT_SYMBOL_GPL(vb2_v4l2_streamon);
 
 /**
- * vb2_streamoff - stop streaming
+ * vb2_v4l2_streamoff - stop streaming
  * @q:		videobuf2 queue
  * @type:	type argument passed from userspace to vidioc_streamoff handler
  *
@@ -984,21 +984,21 @@ EXPORT_SYMBOL_GPL(vb2_streamon);
  * 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)
+int vb2_v4l2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
 {
 	if (vb2_fileio_is_active(q)) {
 		VB2_DEBUG(1, "file io in progress\n");
 		return -EBUSY;
 	}
-	return vb2_core_streamoff(q, to_vb2_buf_type(type));
+	return vb2_streamoff(q, to_vb2_buf_type(type));
 }
-EXPORT_SYMBOL_GPL(vb2_streamoff);
+EXPORT_SYMBOL_GPL(vb2_v4l2_streamoff);
 
 static int __vb2_init_fileio(struct vb2_queue *q, int read);
 static int __vb2_cleanup_fileio(struct vb2_queue *q);
 
 /**
- * vb2_poll() - implements poll userspace operation
+ * vb2_v4l2_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
@@ -1010,13 +1010,13 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q);
  * 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
+ * If the driver uses struct v4l2_fh, then vb2_v4l2_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)
+unsigned int vb2_v4l2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 {
 	struct video_device *vfd = video_devdata(file);
 	unsigned long req_events = poll_requested_events(wait);
@@ -1107,10 +1107,10 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
 	}
 	return res;
 }
-EXPORT_SYMBOL_GPL(vb2_poll);
+EXPORT_SYMBOL_GPL(vb2_v4l2_poll);
 
 /**
- * vb2_queue_init() - initialize a videobuf2 queue
+ * vb2_v4l2_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
@@ -1120,7 +1120,7 @@ EXPORT_SYMBOL_GPL(vb2_poll);
  * to the struct vb2_queue description in include/media/videobuf2-core.h
  * for more information.
  */
-int vb2_queue_init(struct vb2_queue *q)
+int vb2_v4l2_queue_init(struct vb2_queue *q)
 {
 	/*
 	 * Sanity check
@@ -1144,24 +1144,24 @@ int vb2_queue_init(struct vb2_queue *q)
 	q->trace_ops = &vb2_v4l2_trace_ops;
 	q->vb2_type = to_vb2_buf_type(q->type);
 
-	return vb2_core_queue_init(q);
+	return vb2_queue_init(q);
 }
-EXPORT_SYMBOL_GPL(vb2_queue_init);
+EXPORT_SYMBOL_GPL(vb2_v4l2_queue_init);
 
 /**
- * vb2_queue_release() - stop streaming, release the queue and free memory
+ * vb2_v4l2_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_v4l2_queue_release(struct vb2_queue *q)
 {
 	__vb2_cleanup_fileio(q);
-	vb2_core_queue_release(q);
+	vb2_queue_release(q);
 }
-EXPORT_SYMBOL_GPL(vb2_queue_release);
+EXPORT_SYMBOL_GPL(vb2_v4l2_queue_release);
 
 /**
  * struct vb2_fileio_buf - buffer context used by file io emulator
@@ -1268,7 +1268,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	fileio->req.memory = q->memory = V4L2_MEMORY_MMAP;
 	fileio->req.type = q->type;
 	q->fileio = fileio;
-	ret = vb2_core_reqbufs(q, to_vb2_memory(fileio->req.memory), &fileio->req.count);
+	ret = vb2_reqbufs(q, to_vb2_memory(fileio->req.memory), &fileio->req.count);
 	if (ret)
 		goto err_kfree;
 
@@ -1290,7 +1290,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 			ret = -EINVAL;
 			goto err_reqbufs;
 		}
-		fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
+		fileio->bufs[i].size = vb2_v4l2_plane_size(q->bufs[i], 0);
 	}
 
 	/*
@@ -1314,7 +1314,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 			}
 			b->memory = q->memory;
 			b->index = i;
-			ret = vb2_core_qbuf(q, q->vb2_memory, q->vb2_type, i, b);
+			ret = vb2_qbuf(q, q->vb2_memory, q->vb2_type, i, b);
 			if (ret)
 				goto err_reqbufs;
 			fileio->bufs[i].queued = 1;
@@ -1330,7 +1330,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 	/*
 	 * Start streaming.
 	 */
-	ret = vb2_core_streamon(q, q->vb2_type);
+	ret = vb2_streamon(q, q->vb2_type);
 	if (ret)
 		goto err_reqbufs;
 
@@ -1338,7 +1338,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
 
 err_reqbufs:
 	fileio->req.count = 0;
-	vb2_core_reqbufs(q, to_vb2_memory(fileio->req.memory), &fileio->req.count);
+	vb2_reqbufs(q, to_vb2_memory(fileio->req.memory), &fileio->req.count);
 
 err_kfree:
 	q->fileio = NULL;
@@ -1355,10 +1355,10 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q)
 	struct vb2_fileio_data *fileio = q->fileio;
 
 	if (fileio) {
-		vb2_core_streamoff(q, q->vb2_type);
+		vb2_streamoff(q, q->vb2_type);
 		q->fileio = NULL;
 		fileio->req.count = 0;
-		vb2_reqbufs(q, &fileio->req);
+		vb2_v4l2_reqbufs(q, &fileio->req);
 		kfree(fileio);
 		VB2_DEBUG(3, "file io emulator closed\n");
 	}
@@ -1414,7 +1414,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 	index = fileio->cur_index;
 	if (index >= q->num_buffers) {
 		/*
-		 * Call vb2_dqbuf to get buffer back.
+		 * Call vb2_v4l2_dqbuf to get buffer back.
 		 */
 		memset(&fileio->b, 0, sizeof(fileio->b));
 		fileio->b.type = q->type;
@@ -1424,8 +1424,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 			fileio->b.m.planes = &fileio->p;
 			fileio->b.length = 1;
 		}
-		ret = vb2_core_dqbuf(q, q->vb2_type, &fileio->b, nonblock);
-		VB2_DEBUG(5, "vb2_dqbuf result: %d\n", ret);
+		ret = vb2_dqbuf(q, q->vb2_type, &fileio->b, nonblock);
+		VB2_DEBUG(5, "vb2_v4l2_dqbuf result: %d\n", ret);
 		if (ret)
 			return ret;
 		fileio->dq_count += 1;
@@ -1438,8 +1438,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		 */
 		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_v4l2_get_plane_payload(q->bufs[index], 0)
+				 : vb2_v4l2_plane_size(q->bufs[index], 0);
 		/* Compensate for data_offset on read in the multiplanar case. */
 		if (is_multiplanar && read &&
 		    fileio->b.m.planes[0].data_offset < buf->size) {
@@ -1491,7 +1491,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		}
 
 		/*
-		 * Call vb2_qbuf and give buffer to the driver.
+		 * Call vb2_v4l2_qbuf and give buffer to the driver.
 		 */
 		memset(&fileio->b, 0, sizeof(fileio->b));
 		fileio->b.type = q->type;
@@ -1506,7 +1506,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		}
 		if (set_timestamp)
 			v4l2_get_timestamp(&fileio->b.timestamp);
-		ret = vb2_core_qbuf(q, q->vb2_memory, q->vb2_type, index,
+		ret = vb2_qbuf(q, q->vb2_memory, q->vb2_type, index,
 				&fileio->b);
 		VB2_DEBUG(5, "vb2_dbuf result: %d\n", ret);
 		if (ret)
@@ -1517,7 +1517,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 		 */
 		buf->pos = 0;
 		buf->queued = 1;
-		buf->size = vb2_plane_size(q->bufs[index], 0);
+		buf->size = vb2_v4l2_plane_size(q->bufs[index], 0);
 		fileio->q_count += 1;
 		/*
 		 * If we are queuing up buffers for the first time, then
@@ -1543,20 +1543,20 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_
 	return ret;
 }
 
-size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
+size_t vb2_v4l2_read(struct vb2_queue *q, char __user *data, size_t count,
 		loff_t *ppos, int nonblocking)
 {
 	return __vb2_perform_fileio(q, data, count, ppos, nonblocking, 1);
 }
-EXPORT_SYMBOL_GPL(vb2_read);
+EXPORT_SYMBOL_GPL(vb2_v4l2_read);
 
-size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count,
+size_t vb2_v4l2_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);
+EXPORT_SYMBOL_GPL(vb2_v4l2_write);
 
 struct vb2_threadio_data {
 	struct task_struct *thread;
@@ -1588,7 +1588,7 @@ static int vb2_thread(void *data)
 		struct vb2_buffer *vb;
 
 		/*
-		 * Call vb2_dqbuf to get buffer back.
+		 * Call vb2_v4l2_dqbuf to get buffer back.
 		 */
 		memset(&fileio->b, 0, sizeof(fileio->b));
 		fileio->b.type = q->type;
@@ -1599,9 +1599,9 @@ static int vb2_thread(void *data)
 		} else {
 			call_void_qop(q, wait_finish, q);
 			if (!threadio->stop)
-				ret = vb2_core_dqbuf(q, q->vb2_type, &fileio->b, 0);
+				ret = vb2_dqbuf(q, q->vb2_type, &fileio->b, 0);
 			call_void_qop(q, wait_prepare, q);
-			VB2_DEBUG(5, "file io: vb2_dqbuf result: %d\n", ret);
+			VB2_DEBUG(5, "file io: vb2_v4l2_dqbuf result: %d\n", ret);
 		}
 		if (ret || threadio->stop)
 			break;
@@ -1615,7 +1615,7 @@ static int vb2_thread(void *data)
 		if (set_timestamp)
 			v4l2_get_timestamp(&fileio->b.timestamp);
 		if (!threadio->stop)
-			ret = vb2_core_qbuf(q, q->vb2_memory,
+			ret = vb2_qbuf(q, q->vb2_memory,
 				q->vb2_type, fileio->b.index, &fileio->b);
 		call_void_qop(q, wait_prepare, q);
 		if (ret || threadio->stop)
@@ -1722,7 +1722,7 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv,
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
 	vdev->queue->memory = p->memory;
-	res = vb2_core_reqbufs(vdev->queue, to_vb2_memory(p->memory), &p->count);
+	res = vb2_reqbufs(vdev->queue, to_vb2_memory(p->memory), &p->count);
 	/* 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)
@@ -1748,7 +1748,7 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv,
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
 	vdev->queue->memory = p->memory;
-	res = vb2_core_create_bufs(vdev->queue, to_vb2_memory(p->memory),
+	res = vb2_create_bufs(vdev->queue, to_vb2_memory(p->memory),
 			&p->count, &p->format);
 	if (res == 0)
 		vdev->queue->owner = file->private_data;
@@ -1763,7 +1763,7 @@ int vb2_ioctl_prepare_buf(struct file *file, void *priv,
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_core_prepare_buf(vdev->queue, to_vb2_memory(p->memory),
+	return vb2_prepare_buf(vdev->queue, to_vb2_memory(p->memory),
 			to_vb2_buf_type(p->type), p->index, p);
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_prepare_buf);
@@ -1773,7 +1773,7 @@ int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
 	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);
+	return vb2_v4l2_querybuf(vdev->queue, p);
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_querybuf);
 
@@ -1783,7 +1783,7 @@ int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_qbuf(vdev->queue, p);
+	return vb2_v4l2_qbuf(vdev->queue, p);
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_qbuf);
 
@@ -1793,7 +1793,7 @@ int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_dqbuf(vdev->queue, p, file->f_flags & O_NONBLOCK);
+	return vb2_v4l2_dqbuf(vdev->queue, p, file->f_flags & O_NONBLOCK);
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_dqbuf);
 
@@ -1803,7 +1803,7 @@ int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type type)
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_streamon(vdev->queue, to_vb2_buf_type(type));
+	return vb2_v4l2_streamon(vdev->queue, to_vb2_buf_type(type));
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_streamon);
 
@@ -1813,7 +1813,7 @@ int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type type)
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_streamoff(vdev->queue, to_vb2_buf_type(type));
+	return vb2_v4l2_streamoff(vdev->queue, to_vb2_buf_type(type));
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_streamoff);
 
@@ -1823,7 +1823,7 @@ int vb2_ioctl_expbuf(struct file *file, void *priv, struct v4l2_exportbuffer *p)
 
 	if (vb2_queue_is_busy(vdev, file))
 		return -EBUSY;
-	return vb2_expbuf(vdev->queue, p);
+	return vb2_v4l2_expbuf(vdev->queue, p);
 }
 EXPORT_SYMBOL_GPL(vb2_ioctl_expbuf);
 
@@ -1844,7 +1844,7 @@ int _vb2_fop_release(struct file *file, struct mutex *lock)
 	if (lock)
 		mutex_lock(lock);
 	if (file->private_data == vdev->queue->owner) {
-		vb2_queue_release(vdev->queue);
+		vb2_v4l2_queue_release(vdev->queue);
 		vdev->queue->owner = NULL;
 	}
 	if (lock)
@@ -1875,7 +1875,7 @@ ssize_t vb2_fop_write(struct file *file, const char __user *buf,
 		return -ERESTARTSYS;
 	if (vb2_queue_is_busy(vdev, file))
 		goto exit;
-	err = vb2_write(vdev->queue, buf, count, ppos,
+	err = vb2_v4l2_write(vdev->queue, buf, count, ppos,
 		       file->f_flags & O_NONBLOCK);
 	if (vdev->queue->fileio)
 		vdev->queue->owner = file->private_data;
@@ -1899,7 +1899,7 @@ ssize_t vb2_fop_read(struct file *file, char __user *buf,
 		return -ERESTARTSYS;
 	if (vb2_queue_is_busy(vdev, file))
 		goto exit;
-	err = vb2_read(vdev->queue, buf, count, ppos,
+	err = vb2_v4l2_read(vdev->queue, buf, count, ppos,
 		       file->f_flags & O_NONBLOCK);
 	if (vdev->queue->fileio)
 		vdev->queue->owner = file->private_data;
@@ -1929,7 +1929,7 @@ unsigned int vb2_fop_poll(struct file *file, poll_table *wait)
 
 	fileio = q->fileio;
 
-	res = vb2_poll(vdev->queue, file, wait);
+	res = vb2_v4l2_poll(vdev->queue, file, wait);
 
 	/* If fileio was started, then we have a new queue owner. */
 	if (!fileio && q->fileio)
diff --git a/drivers/usb/gadget/function/uvc_queue.c b/drivers/usb/gadget/function/uvc_queue.c
index 264d76f..5b690c5 100644
--- a/drivers/usb/gadget/function/uvc_queue.c
+++ b/drivers/usb/gadget/function/uvc_queue.c
@@ -65,7 +65,7 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 	struct uvc_buffer *buf = container_of(vbuf, struct uvc_buffer, buf);
 
 	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
-	    vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
+	    vb2_v4l2_get_plane_payload(vb, 0) > vb2_v4l2_plane_size(vb, 0)) {
 		uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
 		return -EINVAL;
 	}
@@ -75,11 +75,11 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb)
 
 	buf->state = UVC_BUF_STATE_QUEUED;
 	buf->mem = vb2_plane_vaddr(vb, 0);
-	buf->length = vb2_plane_size(vb, 0);
+	buf->length = vb2_v4l2_plane_size(vb, 0);
 	if (vbuf->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
 		buf->bytesused = 0;
 	else
-		buf->bytesused = vb2_get_plane_payload(vb, 0);
+		buf->bytesused = vb2_v4l2_get_plane_payload(vb, 0);
 
 	return 0;
 }
@@ -128,7 +128,7 @@ int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
 	queue->queue.mem_ops = &vb2_vmalloc_memops;
 	queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
 				     | V4L2_BUF_FLAG_TSTAMP_SRC_EOF;
-	ret = vb2_queue_init(&queue->queue);
+	ret = vb2_v4l2_queue_init(&queue->queue);
 	if (ret)
 		return ret;
 
@@ -144,7 +144,7 @@ int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
  */
 void uvcg_free_buffers(struct uvc_video_queue *queue)
 {
-	vb2_queue_release(&queue->queue);
+	vb2_v4l2_queue_release(&queue->queue);
 }
 
 /*
@@ -155,14 +155,14 @@ int uvcg_alloc_buffers(struct uvc_video_queue *queue,
 {
 	int ret;
 
-	ret = vb2_reqbufs(&queue->queue, rb);
+	ret = vb2_v4l2_reqbufs(&queue->queue, rb);
 
 	return ret ? ret : rb->count;
 }
 
 int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
 {
-	return vb2_querybuf(&queue->queue, buf);
+	return vb2_v4l2_querybuf(&queue->queue, buf);
 }
 
 int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
@@ -170,7 +170,7 @@ int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
 	unsigned long flags;
 	int ret;
 
-	ret = vb2_qbuf(&queue->queue, buf);
+	ret = vb2_v4l2_qbuf(&queue->queue, buf);
 	if (ret < 0)
 		return ret;
 
@@ -188,7 +188,7 @@ int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf)
 int uvcg_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf,
 			int nonblocking)
 {
-	return vb2_dqbuf(&queue->queue, buf, nonblocking);
+	return vb2_v4l2_dqbuf(&queue->queue, buf, nonblocking);
 }
 
 /*
@@ -200,7 +200,7 @@ int uvcg_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf,
 unsigned int uvcg_queue_poll(struct uvc_video_queue *queue, struct file *file,
 			     poll_table *wait)
 {
-	return vb2_poll(&queue->queue, file, wait);
+	return vb2_v4l2_poll(&queue->queue, file, wait);
 }
 
 int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma)
@@ -280,14 +280,14 @@ int uvcg_queue_enable(struct uvc_video_queue *queue, int enable)
 	int ret = 0;
 
 	if (enable) {
-		ret = vb2_streamon(&queue->queue, queue->queue.type);
+		ret = vb2_v4l2_streamon(&queue->queue, queue->queue.type);
 		if (ret < 0)
 			return ret;
 
 		queue->sequence = 0;
 		queue->buf_used = 0;
 	} else {
-		ret = vb2_streamoff(&queue->queue, queue->queue.type);
+		ret = vb2_v4l2_streamoff(&queue->queue, queue->queue.type);
 		if (ret < 0)
 			return ret;
 
@@ -316,7 +316,7 @@ struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
 	if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
 	     buf->length != buf->bytesused) {
 		buf->state = UVC_BUF_STATE_QUEUED;
-		vb2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
+		vb2_v4l2_set_plane_payload(&buf->buf.vb2_buf, 0, 0);
 		return buf;
 	}
 
@@ -331,7 +331,7 @@ struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue,
 	buf->buf.v4l2_buf.sequence = queue->sequence++;
 	v4l2_get_timestamp(&buf->buf.v4l2_buf.timestamp);
 
-	vb2_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
+	vb2_v4l2_set_plane_payload(&buf->buf.vb2_buf, 0, buf->bytesused);
 	vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_DONE);
 
 	return nextbuf;
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 871fcc6..97cfa8a 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -674,27 +674,27 @@ 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 vb2_buf_type type,
+int vb2_querybuf(struct vb2_queue *q, enum vb2_buf_type type,
 		unsigned int index, void *pb);
-int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int *count);
-int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
+int vb2_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int *count);
+int vb2_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
 		unsigned int *count, void *parg);
-int vb2_core_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
+int vb2_prepare_buf(struct vb2_queue *q, enum vb2_memory memory,
 		enum vb2_buf_type type, unsigned int index, void *pb);
 
-int __must_check vb2_core_queue_init(struct vb2_queue *q);
+int __must_check vb2_queue_init(struct vb2_queue *q);
 
-void vb2_core_queue_release(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 vb2_memory memory, enum vb2_buf_type type,
+int vb2_qbuf(struct vb2_queue *q, enum vb2_memory memory, enum vb2_buf_type type,
 		unsigned int index, void *pb);
-int vb2_core_dqbuf(struct vb2_queue *q, enum vb2_buf_type type, void *pb, bool nonblock);
-int vb2_core_expbuf(struct vb2_queue *q, enum vb2_buf_type type, unsigned int index,
+int vb2_dqbuf(struct vb2_queue *q, enum vb2_buf_type type, void *pb, bool nonblock);
+int vb2_expbuf(struct vb2_queue *q, enum vb2_buf_type type, unsigned int index,
 		unsigned int plane, unsigned int flags);
 
-int vb2_core_streamon(struct vb2_queue *q, enum vb2_buf_type type);
-int vb2_core_streamoff(struct vb2_queue *q, enum vb2_buf_type type);
+int vb2_streamon(struct vb2_queue *q, enum vb2_buf_type type);
+int vb2_streamoff(struct vb2_queue *q, enum vb2_buf_type type);
 
 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma);
 #ifndef CONFIG_MMU
diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
index 7460d0b..65adb2d 100644
--- a/include/media/videobuf2-v4l2.h
+++ b/include/media/videobuf2-v4l2.h
@@ -28,7 +28,7 @@
  *			(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
+ *			should use the vb2_v4l2_set_plane_payload() function for that
  */
 struct vb2_v4l2_buffer {
 	struct vb2_buffer	vb2_buf;
@@ -43,25 +43,25 @@ struct vb2_v4l2_buffer {
 #define to_vb2_v4l2_buffer(vb) \
 	(container_of(vb, struct vb2_v4l2_buffer, vb2_buf))
 
-int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
-int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
+int vb2_v4l2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
+int vb2_v4l2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
 
-int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb);
-int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
+int vb2_v4l2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb);
+int vb2_v4l2_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);
-int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
-int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblock);
-int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
+int __must_check vb2_v4l2_queue_init(struct vb2_queue *q);
+void vb2_v4l2_queue_release(struct vb2_queue *q);
+int vb2_v4l2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
+int vb2_v4l2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblock);
+int vb2_v4l2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
 
-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_v4l2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
+int vb2_v4l2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
 
-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,
+unsigned int vb2_v4l2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
+size_t vb2_v4l2_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,
+size_t vb2_v4l2_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
@@ -94,12 +94,12 @@ int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
 int vb2_thread_stop(struct vb2_queue *q);
 
 /**
- * vb2_set_plane_payload() - set bytesused for the plane plane_no
+ * vb2_v4l2_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_buffer *vb,
+static inline void vb2_v4l2_set_plane_payload(struct vb2_buffer *vb,
 				 unsigned int plane_no, unsigned long size)
 {
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
@@ -109,12 +109,12 @@ static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
 }
 
 /**
- * vb2_get_plane_payload() - get bytesused for the plane plane_no
+ * vb2_v4l2_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_buffer *vb,
+static inline unsigned long vb2_v4l2_get_plane_payload(struct vb2_buffer *vb,
 				 unsigned int plane_no)
 {
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
@@ -125,12 +125,12 @@ static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
 }
 
 /**
- * vb2_plane_size() - return plane size in bytes
+ * vb2_v4l2_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_buffer *vb, unsigned int plane_no)
+vb2_v4l2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
 {
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 
-- 
1.7.9.5


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

* Re: [RFC PATCH v2 1/5] media: videobuf2: Rename videobuf2-core to videobuf2-v4l2
  2015-07-31  8:44 ` [RFC PATCH v2 1/5] media: videobuf2: Rename videobuf2-core to videobuf2-v4l2 Junghak Sung
@ 2015-08-10  8:06   ` Hans Verkuil
  0 siblings, 0 replies; 23+ messages in thread
From: Hans Verkuil @ 2015-08-10  8:06 UTC (permalink / raw)
  To: Junghak Sung, linux-media, mchehab, laurent.pinchart,
	sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Hi Junghak,

On 07/31/2015 10:44 AM, Junghak Sung wrote:
> Rename file name - from videobuf2-core.[ch] to videobuf2-v4l2.[ch]
> This renaming patch should be accompanied by the modifications for all device
> drivers that include this header file. It can be done with just running this
> shell script.
> 
> replace()
> {
> str1=$1
> str2=$2
> dir=$3
> for file in $(find $dir -name *.h -o -name *.c -o -name Makefile)
> do
>     echo $file
>     sed "s/$str1/$str2/g" $file > $file.out
>     mv $file.out $file
> done
> }
> replace "videobuf2-core" "videobuf2-v4l2" "include/media/"
> replace "videobuf2-core" "videobuf2-v4l2" "drivers/media/"
> 
> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> Acked-by: Inki Dae <inki.dae@samsung.com>

Rather than moving videobuf2-core.c to videobuf2-v4l2.c I would recommend to just
create a videobuf2-v4l2.h header that includes videobuf2-core.h and nothing else.

So this patch will move all drivers over to include the new videobuf2-v4l2.h header,
leaving everything else unchanged.

Then in patch 3 you can move code from videobuf2-core.c/h to videobuf2-v4l2.c/h. This
will make patch 3 easier to read for me since I can clearly see in the diff what
has been moved from -core.c/h to -v4l2.c/h.

Right now patch 3 shows what moved from -v4l2.c/h to -core.c/h, which is the wrong
way around. And makes patch 3 much larger than it needs to be since (unsurprisingly)
most code from v4l2.c/h moves back to core.c/h.

Regards,

	Hans

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

* Re: [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory
  2015-07-31  8:44 ` [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory Junghak Sung
@ 2015-08-10  8:22   ` Hans Verkuil
  2015-08-11  2:19     ` Junghak Sung
  2015-08-11 13:56     ` Laurent Pinchart
  0 siblings, 2 replies; 23+ messages in thread
From: Hans Verkuil @ 2015-08-10  8:22 UTC (permalink / raw)
  To: Junghak Sung, linux-media, mchehab, laurent.pinchart,
	sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

On 07/31/2015 10:44 AM, Junghak Sung wrote:
> Define enum vb2_buf_type and enum vb2_memory for videobuf2-core. This
> change requires translation functions that could covert v4l2-core stuffs
> to videobuf2-core stuffs in videobuf2-v4l2.c file.
> The v4l2-specific member variables(e.g. type, memory) remains in
> struct vb2_queue for backward compatibility and performance of type translation.
> 
> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> Acked-by: Inki Dae <inki.dae@samsung.com>
> ---
>  drivers/media/v4l2-core/videobuf2-core.c |  139 +++++++++++---------
>  drivers/media/v4l2-core/videobuf2-v4l2.c |  209 ++++++++++++++++++++----------
>  include/media/videobuf2-core.h           |   99 +++++++++++---
>  include/media/videobuf2-v4l2.h           |   12 +-
>  4 files changed, 299 insertions(+), 160 deletions(-)
> 

<snip>

> diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
> index 85527e9..22dd19c 100644
> --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
> +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
> @@ -30,8 +30,46 @@
>  #include <media/v4l2-common.h>
>  #include <media/videobuf2-v4l2.h>
>  
> +#define CREATE_TRACE_POINTS
>  #include <trace/events/v4l2.h>
>  
> +static const enum vb2_buf_type _tbl_buf_type[] = {
> +	[V4L2_BUF_TYPE_VIDEO_CAPTURE]		= VB2_BUF_TYPE_VIDEO_CAPTURE,
> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT]		= VB2_BUF_TYPE_VIDEO_OUTPUT,
> +	[V4L2_BUF_TYPE_VIDEO_OVERLAY]		= VB2_BUF_TYPE_VIDEO_OVERLAY,
> +	[V4L2_BUF_TYPE_VBI_CAPTURE]		= VB2_BUF_TYPE_VBI_CAPTURE,
> +	[V4L2_BUF_TYPE_VBI_OUTPUT]		= VB2_BUF_TYPE_VBI_OUTPUT,
> +	[V4L2_BUF_TYPE_SLICED_VBI_CAPTURE]	= VB2_BUF_TYPE_SLICED_VBI_CAPTURE,
> +	[V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]	= VB2_BUF_TYPE_SLICED_VBI_OUTPUT,
> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY]	= VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY,
> +	[V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE]	= VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE]	= VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
> +	[V4L2_BUF_TYPE_SDR_CAPTURE]		= VB2_BUF_TYPE_SDR_CAPTURE,
> +	[V4L2_BUF_TYPE_PRIVATE]			= VB2_BUF_TYPE_PRIVATE,
> +};
> +
> +static const enum vb2_memory _tbl_memory[] = {
> +	[V4L2_MEMORY_MMAP]	= VB2_MEMORY_MMAP,
> +	[V4L2_MEMORY_USERPTR]	= VB2_MEMORY_USERPTR,
> +	[V4L2_MEMORY_DMABUF]	= VB2_MEMORY_DMABUF,
> +};
> +
> +#define to_vb2_buf_type(type)					\
> +({								\
> +	enum vb2_buf_type ret = 0;				\
> +	if( type > 0 && type < ARRAY_SIZE(_tbl_buf_type) )	\
> +		ret = (_tbl_buf_type[type]);			\
> +	ret;							\
> +})
> +
> +#define to_vb2_memory(memory)					\
> +({								\
> +	enum vb2_memory ret = 0;				\
> +	if( memory > 0 && memory < ARRAY_SIZE(_tbl_memory) )	\
> +		ret = (_tbl_memory[memory]);			\
> +	ret;							\
> +})
> +

<snip>

> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> index dc405da..871fcc6 100644
> --- a/include/media/videobuf2-core.h
> +++ b/include/media/videobuf2-core.h
> @@ -15,9 +15,47 @@
>  #include <linux/mm_types.h>
>  #include <linux/mutex.h>
>  #include <linux/poll.h>
> -#include <linux/videodev2.h>
>  #include <linux/dma-buf.h>
>  
> +#define VB2_MAX_FRAME               32
> +#define VB2_MAX_PLANES               8
> +
> +enum vb2_buf_type {
> +	VB2_BUF_TYPE_UNKNOWN			= 0,
> +	VB2_BUF_TYPE_VIDEO_CAPTURE		= 1,
> +	VB2_BUF_TYPE_VIDEO_OUTPUT		= 2,
> +	VB2_BUF_TYPE_VIDEO_OVERLAY		= 3,
> +	VB2_BUF_TYPE_VBI_CAPTURE		= 4,
> +	VB2_BUF_TYPE_VBI_OUTPUT			= 5,
> +	VB2_BUF_TYPE_SLICED_VBI_CAPTURE		= 6,
> +	VB2_BUF_TYPE_SLICED_VBI_OUTPUT		= 7,
> +	VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY	= 8,
> +	VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	= 9,
> +	VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE	= 10,
> +	VB2_BUF_TYPE_SDR_CAPTURE		= 11,
> +	VB2_BUF_TYPE_DVB_CAPTURE		= 12,
> +	VB2_BUF_TYPE_PRIVATE			= 0x80,
> +};
> +
> +enum vb2_memory {
> +	VB2_MEMORY_UNKNOWN	= 0,
> +	VB2_MEMORY_MMAP		= 1,
> +	VB2_MEMORY_USERPTR	= 2,
> +	VB2_MEMORY_DMABUF	= 4,
> +};
> +
> +#define VB2_TYPE_IS_MULTIPLANAR(type)			\
> +	((type) == VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	\
> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
> +
> +#define VB2_TYPE_IS_OUTPUT(type)				\
> +	((type) == VB2_BUF_TYPE_VIDEO_OUTPUT			\
> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE		\
> +	 || (type) == VB2_BUF_TYPE_VIDEO_OVERLAY		\
> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY		\
> +	 || (type) == VB2_BUF_TYPE_VBI_OUTPUT			\
> +	 || (type) == VB2_BUF_TYPE_SLICED_VBI_OUTPUT)

You don't actually need to create vb2_buf_type: unless I am mistaken, all that the
vb2 core needs to know is if it is a capture or output queue and possibly (not
sure about that) if it is single or multiplanar. So add fields to the vb2_queue struct
for that information and leave the buf_type to the v4l2 specific header and code.

You also don't need the _tbl_memory[] array. All you need to do is to check in
videobuf2-v4l2.c that VB2_MEMORY* equals the V4L2_MEMORY_* defines and generate
a #error if not:

#if VB2_MEMORY_MMAP != V4L2_MEMORY_MMAP || VB2_MEMORY_....
#error VB2_MEMORY_* != V4L2_MEMORY_*!
#endif

Regards,

	Hans

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

* Re: [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use
  2015-07-31  8:44 [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Junghak Sung
                   ` (4 preceding siblings ...)
  2015-07-31  8:44 ` [RFC PATCH v2 5/5] media: videobuf2: Modify prefix for VB2 functions Junghak Sung
@ 2015-08-10  8:31 ` Hans Verkuil
  2015-08-10  9:32   ` Mauro Carvalho Chehab
  5 siblings, 1 reply; 23+ messages in thread
From: Hans Verkuil @ 2015-08-10  8:31 UTC (permalink / raw)
  To: Junghak Sung, linux-media, mchehab, laurent.pinchart,
	sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Hi Jungsak,

On 07/31/2015 10:44 AM, Junghak Sung wrote:
> Hello everybody,
> 
> This is the 2nd round for refactoring Videobuf2(a.k.a VB2).
> The purpose of this patch series is to separate existing VB2 framework
> into core part and V4L2 specific part. So that not only V4L2 but also other
> frameworks can use them to manage buffer and utilize queue.
> 
> 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.
> 
> We have a plan for this work as follows:
> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2.
>    Of course, this change will not affect other v4l2-based
>    device drivers. This patch series corresponds to this step.
> 
> 2. Add and implement new APIs for DVB streaming I/O.
>    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.
> 
> This patch series is the first step for it.
> The previous version of this patch series can be found at [1].
> 
> [1] RFC PATCH v1 - http://www.spinics.net/lists/linux-media/msg90688.html

This v2 looks much better, but, as per my comment to patch 1/5, it needs a bit
more work before I can do a really good review. I think things will be much
clearer once patch 3 shows the code moving from core.c/h to v4l2.c/h instead
of the other way around. That shouldn't be too difficult.

Regards,

	Hans

> 
> Changes since v1:
> 1. Divide patch set into more pieces
> v1 was not reviewed normally because the 2/3 patch is failed to send to mailing
> list with size problem - over 300kb. So I have divided the patch set into five
> pieces and refined them neatly, which was pointed by Hans.
> 
> 2. Add shell scripts for renaming patch
> In case of renaming patch, shell scripts are included inside the body of the
> patches by Mauro's advice. 1/5 and 5/5 patches include these scripts, which can
> be used by reviewers or maintainers to regenerate big patch file if something
> goes wrong during patch apply.
> 
> 3. Remove dependency on v4l2 from videobuf2
> In previous patch set, videobuf2-core uses v4l2-specific stuff as it is.
> e.g. enum v4l2_buf_type and enum v4l2_memory. That prevented other frameworks
> from using videobuf2 independently and made them forced to include
> v4l2-specific stuff.
> In this version, these dependent stuffs are replaced with VB2 own stuffs.
> e.g. enum vb2_buf_type and enum vb2_memory. So, v4l2-specific header file isn't
> required to use videobuf2 in other modules. Please, note that videobuf2 stuffs
> will be translated to v4l2-specific stuffs in videobuf2-v4l2.c file for
> backward compatibility.
> 
> 4. Unify duplicated definitions
> VB2_DEBUG() is newly defined in videobuf2-core header file in order to unify
> duplicated macro functions that invoke callback functions implemented in vb2
> backends - i.e., videobuf2-vmalloc and videobuf2-dma-sg - and queue relevant
> callbacks of device drivers.
> In previous patch set, these macro functions were defined
> in both videobuf2-core.c and videobuf2-v4l2.c.
> 
> This patch series is base on media_tree.git [2] by Mauro & Hans's request.
> And I applied this patches to my own git [3] which can be helpful to review.
> My test boards are ubuntu PC(Intel i7-3770) and odroid-xu3(exynos5422). And
> basic oprerations, e.g. reqbuf, querybuf, qbuf, dqbuf, are tested with
> v4l-utils. But, more tests for the all ioctls will be required on many other
> targets.
> 
> [2] media_tree.git - http://git.linuxtv.org/cgit.cgi/media_tree.git/
> [3] jsung/dvb-vb2.git - http://git.linuxtv.org/cgit.cgi/jsung/dvb-vb2.git/
> 
> Any suggestions and comments are welcome.
> 
> Regards,
> Junghak
> 
> Junghak Sung (5):
>   media: videobuf2: Rename videobuf2-core to videobuf2-v4l2
>   media: videobuf2: Restructurng struct vb2_buffer for common use.
>   media: videobuf2: Divide videobuf2-core into 2 parts
>   media: videobuf2: Define vb2_buf_type and vb2_memory
>   media: videobuf2: Modify prefix for VB2 functions
> 
>  drivers/input/touchscreen/sur40.c                  |   23 +-
>  drivers/media/dvb-frontends/rtl2832_sdr.c          |   19 +-
>  drivers/media/pci/cobalt/cobalt-alsa-pcm.c         |    4 +-
>  drivers/media/pci/cobalt/cobalt-v4l2.c             |    8 +-
>  drivers/media/pci/cx23885/cx23885-417.c            |   15 +-
>  drivers/media/pci/cx23885/cx23885-core.c           |   10 +-
>  drivers/media/pci/cx23885/cx23885-dvb.c            |   13 +-
>  drivers/media/pci/cx23885/cx23885-vbi.c            |   17 +-
>  drivers/media/pci/cx23885/cx23885-video.c          |   23 +-
>  drivers/media/pci/cx23885/cx23885.h                |    2 +-
>  drivers/media/pci/cx25821/cx25821-video.c          |   22 +-
>  drivers/media/pci/cx25821/cx25821.h                |    3 +-
>  drivers/media/pci/cx88/cx88-blackbird.c            |   17 +-
>  drivers/media/pci/cx88/cx88-core.c                 |    2 +-
>  drivers/media/pci/cx88/cx88-dvb.c                  |   15 +-
>  drivers/media/pci/cx88/cx88-mpeg.c                 |    8 +-
>  drivers/media/pci/cx88/cx88-vbi.c                  |   17 +-
>  drivers/media/pci/cx88/cx88-video.c                |   21 +-
>  drivers/media/pci/cx88/cx88.h                      |    2 +-
>  drivers/media/pci/dt3155/dt3155.c                  |   23 +-
>  drivers/media/pci/dt3155/dt3155.h                  |    2 +-
>  drivers/media/pci/saa7134/saa7134-core.c           |    9 +-
>  drivers/media/pci/saa7134/saa7134-dvb.c            |    6 +-
>  drivers/media/pci/saa7134/saa7134-empress.c        |    4 +-
>  drivers/media/pci/saa7134/saa7134-ts.c             |   30 +-
>  drivers/media/pci/saa7134/saa7134-vbi.c            |   24 +-
>  drivers/media/pci/saa7134/saa7134-video.c          |   43 +-
>  drivers/media/pci/saa7134/saa7134.h                |    9 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   35 +-
>  drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   20 +-
>  drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
>  drivers/media/pci/sta2x11/sta2x11_vip.c            |   35 +-
>  drivers/media/pci/tw68/tw68-video.c                |   22 +-
>  drivers/media/pci/tw68/tw68.h                      |    2 +-
>  drivers/media/platform/am437x/am437x-vpfe.c        |   40 +-
>  drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
>  drivers/media/platform/blackfin/bfin_capture.c     |   42 +-
>  drivers/media/platform/coda/coda-bit.c             |   62 +-
>  drivers/media/platform/coda/coda-common.c          |   30 +-
>  drivers/media/platform/coda/coda-jpeg.c            |    6 +-
>  drivers/media/platform/coda/coda.h                 |    6 +-
>  drivers/media/platform/coda/trace.h                |    2 +-
>  drivers/media/platform/davinci/vpbe_display.c      |   16 +-
>  drivers/media/platform/davinci/vpif_capture.c      |   43 +-
>  drivers/media/platform/davinci/vpif_capture.h      |    2 +-
>  drivers/media/platform/davinci/vpif_display.c      |   49 +-
>  drivers/media/platform/davinci/vpif_display.h      |    2 +-
>  drivers/media/platform/exynos-gsc/gsc-core.c       |   10 +-
>  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   |   30 +-
>  drivers/media/platform/exynos4-is/fimc-core.c      |   12 +-
>  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 |   22 +-
>  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       |   18 +-
>  drivers/media/platform/m2m-deinterlace.c           |   26 +-
>  drivers/media/platform/marvell-ccic/mcam-core.c    |   40 +-
>  drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
>  drivers/media/platform/mx2_emmaprp.c               |   25 +-
>  drivers/media/platform/omap3isp/ispvideo.c         |   47 +-
>  drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
>  drivers/media/platform/s3c-camif/camif-capture.c   |   49 +-
>  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               |   22 +-
>  drivers/media/platform/s5p-jpeg/jpeg-core.c        |   57 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc.c           |   42 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   63 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |  120 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |   28 +-
>  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |   28 +-
>  drivers/media/platform/s5p-tv/mixer.h              |    4 +-
>  drivers/media/platform/s5p-tv/mixer_grp_layer.c    |    2 +-
>  drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
>  drivers/media/platform/s5p-tv/mixer_video.c        |   33 +-
>  drivers/media/platform/s5p-tv/mixer_vp_layer.c     |    5 +-
>  drivers/media/platform/sh_veu.c                    |   38 +-
>  drivers/media/platform/sh_vou.c                    |    8 +-
>  drivers/media/platform/soc_camera/atmel-isi.c      |   32 +-
>  drivers/media/platform/soc_camera/mx2_camera.c     |   44 +-
>  drivers/media/platform/soc_camera/mx3_camera.c     |   39 +-
>  drivers/media/platform/soc_camera/rcar_vin.c       |   38 +-
>  .../platform/soc_camera/sh_mobile_ceu_camera.c     |   49 +-
>  drivers/media/platform/soc_camera/soc_camera.c     |   24 +-
>  drivers/media/platform/sti/bdisp/bdisp-v4l2.c      |    8 +-
>  drivers/media/platform/ti-vpe/vpe.c                |   39 +-
>  drivers/media/platform/vim2m.c                     |   39 +-
>  drivers/media/platform/vivid/vivid-core.c          |   10 +-
>  drivers/media/platform/vivid/vivid-core.h          |    4 +-
>  drivers/media/platform/vivid/vivid-kthread-cap.c   |   20 +-
>  drivers/media/platform/vivid/vivid-kthread-out.c   |   14 +-
>  drivers/media/platform/vivid/vivid-sdr-cap.c       |   24 +-
>  drivers/media/platform/vivid/vivid-vbi-cap.c       |   23 +-
>  drivers/media/platform/vivid/vivid-vbi-out.c       |   19 +-
>  drivers/media/platform/vivid/vivid-vid-cap.c       |   25 +-
>  drivers/media/platform/vivid/vivid-vid-out.c       |   20 +-
>  drivers/media/platform/vsp1/vsp1_video.c           |   26 +-
>  drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
>  drivers/media/platform/xilinx/xilinx-dma.c         |    6 +-
>  drivers/media/platform/xilinx/xilinx-dma.h         |    2 +-
>  drivers/media/usb/airspy/airspy.c                  |   22 +-
>  drivers/media/usb/au0828/au0828-vbi.c              |   15 +-
>  drivers/media/usb/au0828/au0828-video.c            |   55 +-
>  drivers/media/usb/au0828/au0828.h                  |    3 +-
>  drivers/media/usb/em28xx/em28xx-vbi.c              |   17 +-
>  drivers/media/usb/em28xx/em28xx-video.c            |   33 +-
>  drivers/media/usb/em28xx/em28xx.h                  |    3 +-
>  drivers/media/usb/go7007/go7007-driver.c           |    4 +-
>  drivers/media/usb/go7007/go7007-priv.h             |    4 +-
>  drivers/media/usb/go7007/go7007-v4l2.c             |   20 +-
>  drivers/media/usb/hackrf/hackrf.c                  |   20 +-
>  drivers/media/usb/msi2500/msi2500.c                |   23 +-
>  drivers/media/usb/pwc/pwc-if.c                     |   28 +-
>  drivers/media/usb/pwc/pwc-uncompress.c             |    8 +-
>  drivers/media/usb/pwc/pwc.h                        |    3 +-
>  drivers/media/usb/s2255/s2255drv.c                 |   26 +-
>  drivers/media/usb/stk1160/stk1160-v4l.c            |   17 +-
>  drivers/media/usb/stk1160/stk1160-video.c          |    4 +-
>  drivers/media/usb/stk1160/stk1160.h                |    4 +-
>  drivers/media/usb/usbtv/usbtv-video.c              |   24 +-
>  drivers/media/usb/usbtv/usbtv.h                    |    3 +-
>  drivers/media/usb/uvc/uvc_queue.c                  |   56 +-
>  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             |   30 +-
>  drivers/media/v4l2-core/videobuf2-core.c           | 2393 +++-----------------
>  drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
>  drivers/media/v4l2-core/videobuf2-v4l2.c           | 1970 ++++++++++++++++
>  drivers/usb/gadget/function/uvc_queue.c            |   46 +-
>  drivers/usb/gadget/function/uvc_queue.h            |    4 +-
>  include/media/soc_camera.h                         |    2 +-
>  include/media/v4l2-mem2mem.h                       |   10 +-
>  include/media/videobuf2-core.h                     |  430 ++--
>  include/media/videobuf2-dvb.h                      |    2 +-
>  include/media/videobuf2-v4l2.h                     |  186 ++
>  include/trace/events/v4l2.h                        |   38 +-
>  143 files changed, 4185 insertions(+), 3462 deletions(-)
>  create mode 100644 drivers/media/v4l2-core/videobuf2-v4l2.c
>  create mode 100644 include/media/videobuf2-v4l2.h
> 


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

* Re: [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use
  2015-08-10  8:31 ` [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Hans Verkuil
@ 2015-08-10  9:32   ` Mauro Carvalho Chehab
  2015-08-10 10:11     ` Hans Verkuil
  0 siblings, 1 reply; 23+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-10  9:32 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Junghak Sung, linux-media, laurent.pinchart, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Em Mon, 10 Aug 2015 10:31:03 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> Hi Jungsak,
> 
> On 07/31/2015 10:44 AM, Junghak Sung wrote:
> > Hello everybody,
> > 
> > This is the 2nd round for refactoring Videobuf2(a.k.a VB2).
> > The purpose of this patch series is to separate existing VB2 framework
> > into core part and V4L2 specific part. So that not only V4L2 but also other
> > frameworks can use them to manage buffer and utilize queue.
> > 
> > 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.
> > 
> > We have a plan for this work as follows:
> > 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2.
> >    Of course, this change will not affect other v4l2-based
> >    device drivers. This patch series corresponds to this step.
> > 
> > 2. Add and implement new APIs for DVB streaming I/O.
> >    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.
> > 
> > This patch series is the first step for it.
> > The previous version of this patch series can be found at [1].
> > 
> > [1] RFC PATCH v1 - http://www.spinics.net/lists/linux-media/msg90688.html
> 
> This v2 looks much better, but, as per my comment to patch 1/5, it needs a bit
> more work before I can do a really good review. I think things will be much
> clearer once patch 3 shows the code moving from core.c/h to v4l2.c/h instead
> of the other way around. That shouldn't be too difficult.

Hans,

I suggested Junkhak to do that. On his previous patchset, he did what
you're suggestiong, e. g moving things from vb2-core into vb2-v4l2, and
that resulted on patches big enough to not be catched by vger.

Also, IMHO, it is cleared this way, as we can see what parts of VB2 will
actually be shared, as there are lots of things that won't be shared:
overlay, userptr, multiplanar.

Regards,
Mauro

> 
> Regards,
> 
> 	Hans
> 
> > 
> > Changes since v1:
> > 1. Divide patch set into more pieces
> > v1 was not reviewed normally because the 2/3 patch is failed to send to mailing
> > list with size problem - over 300kb. So I have divided the patch set into five
> > pieces and refined them neatly, which was pointed by Hans.
> > 
> > 2. Add shell scripts for renaming patch
> > In case of renaming patch, shell scripts are included inside the body of the
> > patches by Mauro's advice. 1/5 and 5/5 patches include these scripts, which can
> > be used by reviewers or maintainers to regenerate big patch file if something
> > goes wrong during patch apply.
> > 
> > 3. Remove dependency on v4l2 from videobuf2
> > In previous patch set, videobuf2-core uses v4l2-specific stuff as it is.
> > e.g. enum v4l2_buf_type and enum v4l2_memory. That prevented other frameworks
> > from using videobuf2 independently and made them forced to include
> > v4l2-specific stuff.
> > In this version, these dependent stuffs are replaced with VB2 own stuffs.
> > e.g. enum vb2_buf_type and enum vb2_memory. So, v4l2-specific header file isn't
> > required to use videobuf2 in other modules. Please, note that videobuf2 stuffs
> > will be translated to v4l2-specific stuffs in videobuf2-v4l2.c file for
> > backward compatibility.
> > 
> > 4. Unify duplicated definitions
> > VB2_DEBUG() is newly defined in videobuf2-core header file in order to unify
> > duplicated macro functions that invoke callback functions implemented in vb2
> > backends - i.e., videobuf2-vmalloc and videobuf2-dma-sg - and queue relevant
> > callbacks of device drivers.
> > In previous patch set, these macro functions were defined
> > in both videobuf2-core.c and videobuf2-v4l2.c.
> > 
> > This patch series is base on media_tree.git [2] by Mauro & Hans's request.
> > And I applied this patches to my own git [3] which can be helpful to review.
> > My test boards are ubuntu PC(Intel i7-3770) and odroid-xu3(exynos5422). And
> > basic oprerations, e.g. reqbuf, querybuf, qbuf, dqbuf, are tested with
> > v4l-utils. But, more tests for the all ioctls will be required on many other
> > targets.
> > 
> > [2] media_tree.git - http://git.linuxtv.org/cgit.cgi/media_tree.git/
> > [3] jsung/dvb-vb2.git - http://git.linuxtv.org/cgit.cgi/jsung/dvb-vb2.git/
> > 
> > Any suggestions and comments are welcome.
> > 
> > Regards,
> > Junghak
> > 
> > Junghak Sung (5):
> >   media: videobuf2: Rename videobuf2-core to videobuf2-v4l2
> >   media: videobuf2: Restructurng struct vb2_buffer for common use.
> >   media: videobuf2: Divide videobuf2-core into 2 parts
> >   media: videobuf2: Define vb2_buf_type and vb2_memory
> >   media: videobuf2: Modify prefix for VB2 functions
> > 
> >  drivers/input/touchscreen/sur40.c                  |   23 +-
> >  drivers/media/dvb-frontends/rtl2832_sdr.c          |   19 +-
> >  drivers/media/pci/cobalt/cobalt-alsa-pcm.c         |    4 +-
> >  drivers/media/pci/cobalt/cobalt-v4l2.c             |    8 +-
> >  drivers/media/pci/cx23885/cx23885-417.c            |   15 +-
> >  drivers/media/pci/cx23885/cx23885-core.c           |   10 +-
> >  drivers/media/pci/cx23885/cx23885-dvb.c            |   13 +-
> >  drivers/media/pci/cx23885/cx23885-vbi.c            |   17 +-
> >  drivers/media/pci/cx23885/cx23885-video.c          |   23 +-
> >  drivers/media/pci/cx23885/cx23885.h                |    2 +-
> >  drivers/media/pci/cx25821/cx25821-video.c          |   22 +-
> >  drivers/media/pci/cx25821/cx25821.h                |    3 +-
> >  drivers/media/pci/cx88/cx88-blackbird.c            |   17 +-
> >  drivers/media/pci/cx88/cx88-core.c                 |    2 +-
> >  drivers/media/pci/cx88/cx88-dvb.c                  |   15 +-
> >  drivers/media/pci/cx88/cx88-mpeg.c                 |    8 +-
> >  drivers/media/pci/cx88/cx88-vbi.c                  |   17 +-
> >  drivers/media/pci/cx88/cx88-video.c                |   21 +-
> >  drivers/media/pci/cx88/cx88.h                      |    2 +-
> >  drivers/media/pci/dt3155/dt3155.c                  |   23 +-
> >  drivers/media/pci/dt3155/dt3155.h                  |    2 +-
> >  drivers/media/pci/saa7134/saa7134-core.c           |    9 +-
> >  drivers/media/pci/saa7134/saa7134-dvb.c            |    6 +-
> >  drivers/media/pci/saa7134/saa7134-empress.c        |    4 +-
> >  drivers/media/pci/saa7134/saa7134-ts.c             |   30 +-
> >  drivers/media/pci/saa7134/saa7134-vbi.c            |   24 +-
> >  drivers/media/pci/saa7134/saa7134-video.c          |   43 +-
> >  drivers/media/pci/saa7134/saa7134.h                |    9 +-
> >  drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c     |   35 +-
> >  drivers/media/pci/solo6x10/solo6x10-v4l2.c         |   20 +-
> >  drivers/media/pci/solo6x10/solo6x10.h              |    4 +-
> >  drivers/media/pci/sta2x11/sta2x11_vip.c            |   35 +-
> >  drivers/media/pci/tw68/tw68-video.c                |   22 +-
> >  drivers/media/pci/tw68/tw68.h                      |    2 +-
> >  drivers/media/platform/am437x/am437x-vpfe.c        |   40 +-
> >  drivers/media/platform/am437x/am437x-vpfe.h        |    2 +-
> >  drivers/media/platform/blackfin/bfin_capture.c     |   42 +-
> >  drivers/media/platform/coda/coda-bit.c             |   62 +-
> >  drivers/media/platform/coda/coda-common.c          |   30 +-
> >  drivers/media/platform/coda/coda-jpeg.c            |    6 +-
> >  drivers/media/platform/coda/coda.h                 |    6 +-
> >  drivers/media/platform/coda/trace.h                |    2 +-
> >  drivers/media/platform/davinci/vpbe_display.c      |   16 +-
> >  drivers/media/platform/davinci/vpif_capture.c      |   43 +-
> >  drivers/media/platform/davinci/vpif_capture.h      |    2 +-
> >  drivers/media/platform/davinci/vpif_display.c      |   49 +-
> >  drivers/media/platform/davinci/vpif_display.h      |    2 +-
> >  drivers/media/platform/exynos-gsc/gsc-core.c       |   10 +-
> >  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   |   30 +-
> >  drivers/media/platform/exynos4-is/fimc-core.c      |   12 +-
> >  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 |   22 +-
> >  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       |   18 +-
> >  drivers/media/platform/m2m-deinterlace.c           |   26 +-
> >  drivers/media/platform/marvell-ccic/mcam-core.c    |   40 +-
> >  drivers/media/platform/marvell-ccic/mcam-core.h    |    2 +-
> >  drivers/media/platform/mx2_emmaprp.c               |   25 +-
> >  drivers/media/platform/omap3isp/ispvideo.c         |   47 +-
> >  drivers/media/platform/omap3isp/ispvideo.h         |    4 +-
> >  drivers/media/platform/s3c-camif/camif-capture.c   |   49 +-
> >  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               |   22 +-
> >  drivers/media/platform/s5p-jpeg/jpeg-core.c        |   57 +-
> >  drivers/media/platform/s5p-mfc/s5p_mfc.c           |   42 +-
> >  drivers/media/platform/s5p-mfc/s5p_mfc_common.h    |    4 +-
> >  drivers/media/platform/s5p-mfc/s5p_mfc_dec.c       |   63 +-
> >  drivers/media/platform/s5p-mfc/s5p_mfc_enc.c       |  120 +-
> >  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c    |   28 +-
> >  drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c    |   28 +-
> >  drivers/media/platform/s5p-tv/mixer.h              |    4 +-
> >  drivers/media/platform/s5p-tv/mixer_grp_layer.c    |    2 +-
> >  drivers/media/platform/s5p-tv/mixer_reg.c          |    2 +-
> >  drivers/media/platform/s5p-tv/mixer_video.c        |   33 +-
> >  drivers/media/platform/s5p-tv/mixer_vp_layer.c     |    5 +-
> >  drivers/media/platform/sh_veu.c                    |   38 +-
> >  drivers/media/platform/sh_vou.c                    |    8 +-
> >  drivers/media/platform/soc_camera/atmel-isi.c      |   32 +-
> >  drivers/media/platform/soc_camera/mx2_camera.c     |   44 +-
> >  drivers/media/platform/soc_camera/mx3_camera.c     |   39 +-
> >  drivers/media/platform/soc_camera/rcar_vin.c       |   38 +-
> >  .../platform/soc_camera/sh_mobile_ceu_camera.c     |   49 +-
> >  drivers/media/platform/soc_camera/soc_camera.c     |   24 +-
> >  drivers/media/platform/sti/bdisp/bdisp-v4l2.c      |    8 +-
> >  drivers/media/platform/ti-vpe/vpe.c                |   39 +-
> >  drivers/media/platform/vim2m.c                     |   39 +-
> >  drivers/media/platform/vivid/vivid-core.c          |   10 +-
> >  drivers/media/platform/vivid/vivid-core.h          |    4 +-
> >  drivers/media/platform/vivid/vivid-kthread-cap.c   |   20 +-
> >  drivers/media/platform/vivid/vivid-kthread-out.c   |   14 +-
> >  drivers/media/platform/vivid/vivid-sdr-cap.c       |   24 +-
> >  drivers/media/platform/vivid/vivid-vbi-cap.c       |   23 +-
> >  drivers/media/platform/vivid/vivid-vbi-out.c       |   19 +-
> >  drivers/media/platform/vivid/vivid-vid-cap.c       |   25 +-
> >  drivers/media/platform/vivid/vivid-vid-out.c       |   20 +-
> >  drivers/media/platform/vsp1/vsp1_video.c           |   26 +-
> >  drivers/media/platform/vsp1/vsp1_video.h           |    6 +-
> >  drivers/media/platform/xilinx/xilinx-dma.c         |    6 +-
> >  drivers/media/platform/xilinx/xilinx-dma.h         |    2 +-
> >  drivers/media/usb/airspy/airspy.c                  |   22 +-
> >  drivers/media/usb/au0828/au0828-vbi.c              |   15 +-
> >  drivers/media/usb/au0828/au0828-video.c            |   55 +-
> >  drivers/media/usb/au0828/au0828.h                  |    3 +-
> >  drivers/media/usb/em28xx/em28xx-vbi.c              |   17 +-
> >  drivers/media/usb/em28xx/em28xx-video.c            |   33 +-
> >  drivers/media/usb/em28xx/em28xx.h                  |    3 +-
> >  drivers/media/usb/go7007/go7007-driver.c           |    4 +-
> >  drivers/media/usb/go7007/go7007-priv.h             |    4 +-
> >  drivers/media/usb/go7007/go7007-v4l2.c             |   20 +-
> >  drivers/media/usb/hackrf/hackrf.c                  |   20 +-
> >  drivers/media/usb/msi2500/msi2500.c                |   23 +-
> >  drivers/media/usb/pwc/pwc-if.c                     |   28 +-
> >  drivers/media/usb/pwc/pwc-uncompress.c             |    8 +-
> >  drivers/media/usb/pwc/pwc.h                        |    3 +-
> >  drivers/media/usb/s2255/s2255drv.c                 |   26 +-
> >  drivers/media/usb/stk1160/stk1160-v4l.c            |   17 +-
> >  drivers/media/usb/stk1160/stk1160-video.c          |    4 +-
> >  drivers/media/usb/stk1160/stk1160.h                |    4 +-
> >  drivers/media/usb/usbtv/usbtv-video.c              |   24 +-
> >  drivers/media/usb/usbtv/usbtv.h                    |    3 +-
> >  drivers/media/usb/uvc/uvc_queue.c                  |   56 +-
> >  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             |   30 +-
> >  drivers/media/v4l2-core/videobuf2-core.c           | 2393 +++-----------------
> >  drivers/media/v4l2-core/videobuf2-dvb.c            |    2 +-
> >  drivers/media/v4l2-core/videobuf2-v4l2.c           | 1970 ++++++++++++++++
> >  drivers/usb/gadget/function/uvc_queue.c            |   46 +-
> >  drivers/usb/gadget/function/uvc_queue.h            |    4 +-
> >  include/media/soc_camera.h                         |    2 +-
> >  include/media/v4l2-mem2mem.h                       |   10 +-
> >  include/media/videobuf2-core.h                     |  430 ++--
> >  include/media/videobuf2-dvb.h                      |    2 +-
> >  include/media/videobuf2-v4l2.h                     |  186 ++
> >  include/trace/events/v4l2.h                        |   38 +-
> >  143 files changed, 4185 insertions(+), 3462 deletions(-)
> >  create mode 100644 drivers/media/v4l2-core/videobuf2-v4l2.c
> >  create mode 100644 include/media/videobuf2-v4l2.h
> > 
> 

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

* Re: [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use
  2015-08-10  9:32   ` Mauro Carvalho Chehab
@ 2015-08-10 10:11     ` Hans Verkuil
  2015-08-10 10:49       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 23+ messages in thread
From: Hans Verkuil @ 2015-08-10 10:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Junghak Sung, linux-media, laurent.pinchart, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

On 08/10/2015 11:32 AM, Mauro Carvalho Chehab wrote:
> Em Mon, 10 Aug 2015 10:31:03 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
>> Hi Jungsak,
>>
>> On 07/31/2015 10:44 AM, Junghak Sung wrote:
>>> Hello everybody,
>>>
>>> This is the 2nd round for refactoring Videobuf2(a.k.a VB2).
>>> The purpose of this patch series is to separate existing VB2 framework
>>> into core part and V4L2 specific part. So that not only V4L2 but also other
>>> frameworks can use them to manage buffer and utilize queue.
>>>
>>> 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.
>>>
>>> We have a plan for this work as follows:
>>> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2.
>>>    Of course, this change will not affect other v4l2-based
>>>    device drivers. This patch series corresponds to this step.
>>>
>>> 2. Add and implement new APIs for DVB streaming I/O.
>>>    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.
>>>
>>> This patch series is the first step for it.
>>> The previous version of this patch series can be found at [1].
>>>
>>> [1] RFC PATCH v1 - http://www.spinics.net/lists/linux-media/msg90688.html
>>
>> This v2 looks much better, but, as per my comment to patch 1/5, it needs a bit
>> more work before I can do a really good review. I think things will be much
>> clearer once patch 3 shows the code moving from core.c/h to v4l2.c/h instead
>> of the other way around. That shouldn't be too difficult.
> 
> Hans,
> 
> I suggested Junkhak to do that. On his previous patchset, he did what
> you're suggestiong, e. g moving things from vb2-core into vb2-v4l2, and
> that resulted on patches big enough to not be catched by vger.

Actually, that wasn't the reason why the patches became so big. I just
reorganized the patch series as I suggested above (pretty easy to do) and
the size of patch 3 went down.

> Also, IMHO, it is cleared this way, as we can see what parts of VB2 will
> actually be shared, as there are lots of things that won't be shared:
> overlay, userptr, multiplanar.

That's why I prefer to see what moves *out* from the core.

To be honest, it depends on what your preference is.

Junghak, just leave the patch as-is. However, for v3 you should run
checkpatch.pl over the diff since it complained about various things.

Regards,

	Hans

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

* Re: [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use
  2015-08-10 10:11     ` Hans Verkuil
@ 2015-08-10 10:49       ` Mauro Carvalho Chehab
  2015-08-10 11:44         ` Hans Verkuil
  0 siblings, 1 reply; 23+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-10 10:49 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Junghak Sung, linux-media, laurent.pinchart, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Em Mon, 10 Aug 2015 12:11:39 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 08/10/2015 11:32 AM, Mauro Carvalho Chehab wrote:
> > Em Mon, 10 Aug 2015 10:31:03 +0200
> > Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> > 
> >> Hi Jungsak,
> >>
> >> On 07/31/2015 10:44 AM, Junghak Sung wrote:
> >>> Hello everybody,
> >>>
> >>> This is the 2nd round for refactoring Videobuf2(a.k.a VB2).
> >>> The purpose of this patch series is to separate existing VB2 framework
> >>> into core part and V4L2 specific part. So that not only V4L2 but also other
> >>> frameworks can use them to manage buffer and utilize queue.
> >>>
> >>> 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.
> >>>
> >>> We have a plan for this work as follows:
> >>> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2.
> >>>    Of course, this change will not affect other v4l2-based
> >>>    device drivers. This patch series corresponds to this step.
> >>>
> >>> 2. Add and implement new APIs for DVB streaming I/O.
> >>>    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.
> >>>
> >>> This patch series is the first step for it.
> >>> The previous version of this patch series can be found at [1].
> >>>
> >>> [1] RFC PATCH v1 - http://www.spinics.net/lists/linux-media/msg90688.html
> >>
> >> This v2 looks much better, but, as per my comment to patch 1/5, it needs a bit
> >> more work before I can do a really good review. I think things will be much
> >> clearer once patch 3 shows the code moving from core.c/h to v4l2.c/h instead
> >> of the other way around. That shouldn't be too difficult.
> > 
> > Hans,
> > 
> > I suggested Junkhak to do that. On his previous patchset, he did what
> > you're suggestiong, e. g moving things from vb2-core into vb2-v4l2, and
> > that resulted on patches big enough to not be catched by vger.
> 
> Actually, that wasn't the reason why the patches became so big. I just
> reorganized the patch series as I suggested above (pretty easy to do) and
> the size of patch 3 went down.

Ah, ok.

> > Also, IMHO, it is cleared this way, as we can see what parts of VB2 will
> > actually be shared, as there are lots of things that won't be shared:
> > overlay, userptr, multiplanar.
> 
> That's why I prefer to see what moves *out* from the core.
> 
> To be honest, it depends on what your preference is.

Yeah. I actually prefer to see what will be shared, because the
non-shared code won't have changes (except for minor kABI things),
while the shared code will be more affected :)

> Junghak, just leave the patch as-is. However, for v3 you should run
> checkpatch.pl over the diff since it complained about various things.

There are two things here:

1) on patches that just move things around, we should not
run checkpatch, as otherwise it would be a nightmare for
review. Ok, as we're doing a remanufacturing, it is a good
idea to run checkpatch at the end and see what should be fixed
(or do it before), but this is out of the scope of the manufacturing.
I can do that myself when applying the series.

2) For all other patches that are adding/changing the code, then
Junghak should run checkpatch and fix (most) stuff complained there.

Regards,
Mauro

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

* Re: [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use
  2015-08-10 10:49       ` Mauro Carvalho Chehab
@ 2015-08-10 11:44         ` Hans Verkuil
  2015-08-11  1:37           ` Junghak Sung
  0 siblings, 1 reply; 23+ messages in thread
From: Hans Verkuil @ 2015-08-10 11:44 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Junghak Sung, linux-media, laurent.pinchart, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

On 08/10/2015 12:49 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 10 Aug 2015 12:11:39 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
>> On 08/10/2015 11:32 AM, Mauro Carvalho Chehab wrote:
>>> Em Mon, 10 Aug 2015 10:31:03 +0200
>>> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
>>>
>>>> Hi Jungsak,
>>>>
>>>> On 07/31/2015 10:44 AM, Junghak Sung wrote:
>>>>> Hello everybody,
>>>>>
>>>>> This is the 2nd round for refactoring Videobuf2(a.k.a VB2).
>>>>> The purpose of this patch series is to separate existing VB2 framework
>>>>> into core part and V4L2 specific part. So that not only V4L2 but also other
>>>>> frameworks can use them to manage buffer and utilize queue.
>>>>>
>>>>> 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.
>>>>>
>>>>> We have a plan for this work as follows:
>>>>> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2.
>>>>>    Of course, this change will not affect other v4l2-based
>>>>>    device drivers. This patch series corresponds to this step.
>>>>>
>>>>> 2. Add and implement new APIs for DVB streaming I/O.
>>>>>    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.
>>>>>
>>>>> This patch series is the first step for it.
>>>>> The previous version of this patch series can be found at [1].
>>>>>
>>>>> [1] RFC PATCH v1 - http://www.spinics.net/lists/linux-media/msg90688.html
>>>>
>>>> This v2 looks much better, but, as per my comment to patch 1/5, it needs a bit
>>>> more work before I can do a really good review. I think things will be much
>>>> clearer once patch 3 shows the code moving from core.c/h to v4l2.c/h instead
>>>> of the other way around. That shouldn't be too difficult.
>>>
>>> Hans,
>>>
>>> I suggested Junkhak to do that. On his previous patchset, he did what
>>> you're suggestiong, e. g moving things from vb2-core into vb2-v4l2, and
>>> that resulted on patches big enough to not be catched by vger.
>>
>> Actually, that wasn't the reason why the patches became so big. I just
>> reorganized the patch series as I suggested above (pretty easy to do) and
>> the size of patch 3 went down.
> 
> Ah, ok.
> 
>>> Also, IMHO, it is cleared this way, as we can see what parts of VB2 will
>>> actually be shared, as there are lots of things that won't be shared:
>>> overlay, userptr, multiplanar.
>>
>> That's why I prefer to see what moves *out* from the core.
>>
>> To be honest, it depends on what your preference is.
> 
> Yeah. I actually prefer to see what will be shared, because the
> non-shared code won't have changes (except for minor kABI things),
> while the shared code will be more affected :)
> 
>> Junghak, just leave the patch as-is. However, for v3 you should run
>> checkpatch.pl over the diff since it complained about various things.
> 
> There are two things here:
> 
> 1) on patches that just move things around, we should not
> run checkpatch, as otherwise it would be a nightmare for
> review. Ok, as we're doing a remanufacturing, it is a good
> idea to run checkpatch at the end and see what should be fixed
> (or do it before), but this is out of the scope of the manufacturing.
> I can do that myself when applying the series.

It was actually complaining about new code.

	Hans

> 
> 2) For all other patches that are adding/changing the code, then
> Junghak should run checkpatch and fix (most) stuff complained there.
> 
> Regards,
> Mauro
> 


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

* Re: [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts
  2015-07-31  8:44 ` [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts Junghak Sung
@ 2015-08-10 12:07   ` Hans Verkuil
  2015-08-10 12:55     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 23+ messages in thread
From: Hans Verkuil @ 2015-08-10 12:07 UTC (permalink / raw)
  To: Junghak Sung, linux-media, mchehab, laurent.pinchart,
	sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Hi Junghak,

I'm reviewing the header changes since I think there are several improvements
that can be done that will make things more logical and will simplify the code.

My comments below are a mix of suggestions for improvement and brainstorming.

Feel free to ask for clarification if something is not clear.

On 07/31/2015 10:44 AM, Junghak Sung wrote:
> Divide videobuf2-core into core part and v4l2-specific part
>  - core part: videobuf2 core related with buffer management & memory allocation
>  - v4l2-specific part: v4l2-specific stuff
> 
> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> Acked-by: Inki Dae <inki.dae@samsung.com>
> ---

<snip>

> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
> new file mode 100644
> index 0000000..dc405da
> --- /dev/null
> +++ b/include/media/videobuf2-core.h
> @@ -0,0 +1,724 @@
> +/*
> + * videobuf2-core.h - Video Buffer 2 Core Framework
> + *
> + * Copyright (C) 2010 Samsung Electronics
> + *
> + * Author: Pawel Osciak <pawel@osciak.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation.
> + */
> +#ifndef _MEDIA_VIDEOBUF2_CORE_H
> +#define _MEDIA_VIDEOBUF2_CORE_H
> +
> +#include <linux/mm_types.h>
> +#include <linux/mutex.h>
> +#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_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 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
> +};
> +
> +/**
> + * 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 void *parg,
> +			   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_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_buffer *vb);
> +};
> +
> +struct vb2_buf_ops {
> +	int (*init_buffer)(struct vb2_buffer *vb, unsigned int memory,
> +		unsigned int type, unsigned int index, unsigned int planes);
> +	unsigned int (*get_index)(struct vb2_buffer *vb);
> +	int (*set_plane_length)(struct vb2_buffer *vb, int plane,
> +		unsigned int length);
> +	unsigned int (*get_plane_length)(struct vb2_buffer *vb, int plane);
> +	int (*set_plane_offset)(struct vb2_buffer *vb, int plane,
> +		unsigned int offset);
> +	unsigned int (*get_plane_offset)(struct vb2_buffer *vb, int plane);
> +	int (*verify_planes)(struct vb2_buffer *vb, void *pb);
> +	int (*fill_buffer)(struct vb2_buffer *vb, void *pb);
> +	int (*fill_vb2_buffer)(struct vb2_buffer *vb, const void *pb,
> +		void *planes);
> +	int (*prepare_buffer)(struct vb2_buffer *vb, void *pb);
> +	int (*set_timestamp)(struct vb2_buffer *vb, void *pb);
> +	int (*is_last)(struct vb2_buffer *vb);
> +};

I think a lot of these ops are unnecessary. The index, length and offset/userptr/fd
fields should be part of the core structs. These are always needed so you don't want
to have to call ops for them. The fill_buffer and fill_vb2_buffer ops will take care
of filling in those fields in the core struct.

I am actually wondering about whether vb2_v4l2_buffer should have a struct v4l2_buffer
field at all: after moving index, length and offset to the vb2_buffer/vb2_plane
structs the only v4l2-specific things are type, flags, field, timestamp, timecode
and sequence. It might be better to just add these directly to the vb2_v4l2_buffer
as fields, rather than reusing the v4l2_buffer struct. Basically v4l2_buffer and
v4l2_plane are only used in the public API, internally we can use more efficient
data structures.

Instead of adding a verify_planes op I would make vb2_queue_or_prepare_buf() a
public function instead of static and call it from videobuf2-v4l2.c.

It is also called from within __vb2_get_done_vb(), but actually that's unnecessary
since this is checked already before the buffer is queued/prepared. So it can never
fails in __vb2_get_done_vb().

The prepare_buffer op can be removed as well. All that's needed is a small public
vb2_core_prepare_buf function that checks vb2_fileio_is_active(q) and whether
vb->state != VB2_BUF_STATE_DEQUEUED, everything else is part of videobuf2-v4l2.c.

I'm not sure about set_timestamp and is_last at this moment. I'll look at that
again in v3.

I noticed that __qbuf_mmap/userptr/dmabuf are all in -v4l2.c. That's a bad sign:
those are some of the most complex vb2 functions and they really belong in the
core since you'll need it for DVB as well. As suggested above, by moving the index,
length and offset/userptr/fd data to the core structs these functions can all be
moved back into core.c as far as I can see.

It is good to remember that today the v4l2_buffer struct is used in the vb2
core because vb2 is only used with v4l2, so why duplicate v4l2_buffer fields
in the vb2 core structs? But if we want to reuse it for other subsystems, then
the vb2 core structs should contain all the core buffer information. This avoids
the need for a lot of the ops that you added and makes it possible to keep the
__qbuf_mmap/userptr/dmabuf in the core code as well.

Adding these fields to the vb2 core structs is something that can be done first,
before splitting up core.c into core.c and v4l2.c.

> +
> +/**
> + * 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)
> + * @fileio_read_once:		report EOF after reading the first buffer
> + * @fileio_write_immediately:	queue buffer after each write() call
> + * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
> + * @lock:	pointer to a mutex that protects the vb2_queue struct. The
> + *		driver can set this to a mutex to let the vb2 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
> + *		in case of v4l2.
> + * @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.
> + * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
> + *		last decoded buffer was already dequeued. Set for capture queues
> + *		when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
> + * @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 {
> +	unsigned int			type;
> +	unsigned int			io_modes;
> +	unsigned			fileio_read_once:1;
> +	unsigned			fileio_write_immediately:1;
> +	unsigned			allow_zero_bytesused:1;
> +
> +	struct mutex			*lock;
> +	void				*owner;
> +
> +	const struct vb2_ops		*ops;
> +	const struct vb2_mem_ops	*mem_ops;
> +	const struct vb2_buf_ops	*buf_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;
> +	unsigned int			memory;
> +	struct vb2_buffer		*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;
> +	unsigned int			last_buffer_dequeued: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
> +};
> +
> +extern int vb2_debug;
> +
> +#define VB2_DEBUG(level, fmt, arg...)					 \
> +	do {								 \
> +		if (vb2_debug >= level)					 \
> +			pr_info("vb2-core: %s: " fmt, __func__, ## arg); \
> +	} while (0)

Hmm, this causes a lot of unnecessary changes because of the dprintk to
VB2_DEBUG renaming.

Also, this is really not something that drivers using this are interested
in. Why not create a videobuf2-internal.h that is used by videobuf2-v4l2.c?

> +
> +#define call_bufop(q, op, args...)					\
> +({ 									\
> +	int ret = 0;							\
> +									\
> +	if(q && q->buf_ops && q->buf_ops->op)				\
> +		ret = q->buf_ops->op(args);				\
> +	ret;								\
> +})
> +
> +#define call_u32_bufop(q, op, args...)					\
> +({ 									\
> +	unsigned int ret = 0;						\
> +									\
> +	if(q && q->buf_ops && q->buf_ops->op)				\
> +		ret = q->buf_ops->op(args);				\
> +	ret;								\
> +})
> +
> +#define vb2_index(vb) (call_u32_bufop((vb)->vb2_queue, get_index, vb))
> +
> +#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)						\
> +	VB2_DEBUG(2, "call_memop(%p, %d, %s)%s\n",			\
> +		(vb)->vb2_queue, vb2_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)							\
> +	VB2_DEBUG(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...)					\
> +	VB2_DEBUG(2, "call_vb_qop(%p, %d, %s)%s\n",			\
> +		(vb)->vb2_queue, vb2_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

Such a header is also a good place to put all these defines above. That will
clean things up.

Actually anything that is not needed by drivers can go in there.

> +
> +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_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, unsigned int type,
> +		unsigned int index, void *pb);
> +int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *count);
> +int vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
> +		unsigned int *count, void *parg);
> +int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int memory,
> +		unsigned int type, unsigned int index, void *pb);
> +
> +int __must_check vb2_core_queue_init(struct vb2_queue *q);
> +
> +void vb2_core_queue_release(struct vb2_queue *q);
> +void vb2_queue_error(struct vb2_queue *q);
> +
> +int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory, unsigned int type,
> +		unsigned int index, void *pb);
> +int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb, bool nonblock);
> +int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
> +		unsigned int plane, unsigned int flags);
> +
> +int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
> +int vb2_core_streamoff(struct vb2_queue *q, unsigned int 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
> +
> +/*
> + * The following functions are for internal uses.
> + */
> +bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
> +void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p);
> +void __vb2_buf_dmabuf_put(struct vb2_buffer *vb);
> +int __verify_memory_type(struct vb2_queue *q,
> +		enum v4l2_memory memory, enum v4l2_buf_type type);
> +
> +/**
> + * 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;
> +}
> +
> +/**
> + * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue
> + * @q:		videobuf queue
> + */
> +static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
> +{
> +	q->last_buffer_dequeued = false;
> +}
> +
> +#endif /* _MEDIA_VIDEOBUF2_CORE_H */

<snip>

> diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
> index 76500f4..3f76e53 100644
> --- a/include/media/videobuf2-v4l2.h
> +++ b/include/media/videobuf2-v4l2.h
> @@ -12,212 +12,11 @@
>  #ifndef _MEDIA_VIDEOBUF2_V4L2_H
>  #define _MEDIA_VIDEOBUF2_V4L2_H
>  
> -#include <linux/mm_types.h>
> -#include <linux/mutex.h>
> -#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_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 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
> + * @vb2_buf:		videobuf2
>   * @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
> @@ -237,266 +36,34 @@ struct vb2_v4l2_buffer {
>  };
>  
>  /**
> - * 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_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_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)
> - * @fileio_read_once:		report EOF after reading the first buffer
> - * @fileio_write_immediately:	queue buffer after each write() call
> - * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
> - * @lock:	pointer to a mutex that protects the vb2_queue struct. The
> - *		driver can set this to a mutex to let the vb2 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.
> - * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
> - *		last decoded buffer was already dequeued. Set for capture queues
> - *		when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
> - * @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			fileio_read_once:1;
> -	unsigned			fileio_write_immediately:1;
> -	unsigned			allow_zero_bytesused:1;
> -
> -	struct mutex			*lock;
> -	struct v4l2_fh			*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;
> -	struct vb2_buffer		*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;
> -	unsigned int			last_buffer_dequeued: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
> -};
> -
> -/**
>   * to_vb2_v4l2_buffer() - cast to struct vb2_v4l2_buffer *
>   * @vb:		struct vb2_buffer *vb
>   */
>  #define to_vb2_v4l2_buffer(vb) \
>  	(container_of(vb, struct vb2_v4l2_buffer, vb2_buf))
>  
> -#define vb2_v4l2_index(vb)						\
> +#define vb2_v4l2_index(vb)					\
>  ({								\
>  	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);	\
> -	int ret = vbuf->v4l2_buf.index;				\
> +	unsigned int ret = vbuf->v4l2_buf.index;		\
>  	ret;							\
>  })
>  
> -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_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_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_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb);
>  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_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblock);
>  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);
> @@ -533,52 +100,6 @@ int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
>  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
> @@ -624,24 +145,6 @@ vb2_plane_size(struct vb2_buffer *vb, 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;
> -}
> -
> -/**
> - * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue
> - * @q:		videobuf queue
> - */
> -static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
> -{
> -	q->last_buffer_dequeued = false;
> -}
> -
>  /*
>   * 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,

Regards,

	Hans

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

* Re: [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts
  2015-08-10 12:07   ` Hans Verkuil
@ 2015-08-10 12:55     ` Mauro Carvalho Chehab
  2015-08-10 13:38       ` Hans Verkuil
  0 siblings, 1 reply; 23+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-10 12:55 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Junghak Sung, linux-media, laurent.pinchart, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Em Mon, 10 Aug 2015 14:07:21 +0200
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> Hi Junghak,
> 
> I'm reviewing the header changes since I think there are several improvements
> that can be done that will make things more logical and will simplify the code.
> 
> My comments below are a mix of suggestions for improvement and brainstorming.
> 
> Feel free to ask for clarification if something is not clear.
> 
> On 07/31/2015 10:44 AM, Junghak Sung wrote:
> > Divide videobuf2-core into core part and v4l2-specific part
> >  - core part: videobuf2 core related with buffer management & memory allocation
> >  - v4l2-specific part: v4l2-specific stuff
> > 
> > Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> > Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
> > Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> > Acked-by: Inki Dae <inki.dae@samsung.com>
> > ---
> 
> <snip>

...

> I noticed that __qbuf_mmap/userptr/dmabuf are all in -v4l2.c. That's a bad sign:
> those are some of the most complex vb2 functions and they really belong in the
> core since you'll need it for DVB as well. As suggested above, by moving the index,
> length and offset/userptr/fd data to the core structs these functions can all be
> moved back into core.c as far as I can see.

Well, that will depend on how the DVB implementation will actually be.

Currently, VB2 has lot of V4L2-dependent code on it, with lots of V4L2
structs from videodev2.h that are there.

Well, if we want the core to be re-used, it should not include videodev2.h
anymore. Also, it should not assume that all non-V4L2 cores would use
exactly the same logic for the userspace API.

In the DVB case, it makes no sense to have anything similar to OVERLAY
there. I also can't see any usage for USERPTR at DVB neither, as either
MMAP or DMABUF should fulfill all userspace needs I'm aware of.

Also, the meta data for the DVB upcoming ioctls for MMAP/DMABUF aren't
yet proposed. They can be very different than the ones inside the V4L2
ioctls.

So, I guess it is better for now to keep those API-dependent stuff at 
VB2-v4l2 and, once the DVB code (and the corresponding API bits) are
written, revisit it and then move the common code to the VB2 core.

> It is good to remember that today the v4l2_buffer struct is used in the vb2
> core because vb2 is only used with v4l2, so why duplicate v4l2_buffer fields
> in the vb2 core structs? 

We should not have any v4l2_* struct inside VB2 core, as the DVB core
should not be dependent on the V4L2 structs. So, everything that it is
V4L2-specific should be inside the VB2-v4l2. The reverse is also true:
we should not pollute the VB2 core with DVB-specific data structures.
So, all VB2-specific struct should be at VB2-dvb.

> But if we want to reuse it for other subsystems, then
> the vb2 core structs should contain all the core buffer information. This avoids
> the need for a lot of the ops that you added and makes it possible to keep the
> __qbuf_mmap/userptr/dmabuf in the core code as well.
> 
> Adding these fields to the vb2 core structs is something that can be done first,
> before splitting up core.c into core.c and v4l2.c.

I'm afraid that we'll lose the big picture if we try to put the
API-dependent parts at the core before adding a non-V4L2 usage on VB2.

We can always simplify the code latter, but IMHO we should focus first
on adding the new functionality (support for DVB). Afterwards, we'll have
a better view on what API-dependent code could be shared.

> 
> > +
> > +/**
> > + * 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)
> > + * @fileio_read_once:		report EOF after reading the first buffer
> > + * @fileio_write_immediately:	queue buffer after each write() call
> > + * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
> > + * @lock:	pointer to a mutex that protects the vb2_queue struct. The
> > + *		driver can set this to a mutex to let the vb2 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
> > + *		in case of v4l2.
> > + * @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.
> > + * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
> > + *		last decoded buffer was already dequeued. Set for capture queues
> > + *		when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
> > + * @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 {
> > +	unsigned int			type;
> > +	unsigned int			io_modes;
> > +	unsigned			fileio_read_once:1;
> > +	unsigned			fileio_write_immediately:1;
> > +	unsigned			allow_zero_bytesused:1;
> > +
> > +	struct mutex			*lock;
> > +	void				*owner;
> > +
> > +	const struct vb2_ops		*ops;
> > +	const struct vb2_mem_ops	*mem_ops;
> > +	const struct vb2_buf_ops	*buf_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;
> > +	unsigned int			memory;
> > +	struct vb2_buffer		*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;
> > +	unsigned int			last_buffer_dequeued: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
> > +};
> > +
> > +extern int vb2_debug;
> > +
> > +#define VB2_DEBUG(level, fmt, arg...)					 \
> > +	do {								 \
> > +		if (vb2_debug >= level)					 \
> > +			pr_info("vb2-core: %s: " fmt, __func__, ## arg); \
> > +	} while (0)
> 
> Hmm, this causes a lot of unnecessary changes because of the dprintk to
> VB2_DEBUG renaming.
> 
> Also, this is really not something that drivers using this are interested
> in. Why not create a videobuf2-internal.h that is used by videobuf2-v4l2.c?
> 
> > +
> > +#define call_bufop(q, op, args...)					\
> > +({ 									\
> > +	int ret = 0;							\
> > +									\
> > +	if(q && q->buf_ops && q->buf_ops->op)				\
> > +		ret = q->buf_ops->op(args);				\
> > +	ret;								\
> > +})
> > +
> > +#define call_u32_bufop(q, op, args...)					\
> > +({ 									\
> > +	unsigned int ret = 0;						\
> > +									\
> > +	if(q && q->buf_ops && q->buf_ops->op)				\
> > +		ret = q->buf_ops->op(args);				\
> > +	ret;								\
> > +})
> > +
> > +#define vb2_index(vb) (call_u32_bufop((vb)->vb2_queue, get_index, vb))
> > +
> > +#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)						\
> > +	VB2_DEBUG(2, "call_memop(%p, %d, %s)%s\n",			\
> > +		(vb)->vb2_queue, vb2_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)							\
> > +	VB2_DEBUG(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...)					\
> > +	VB2_DEBUG(2, "call_vb_qop(%p, %d, %s)%s\n",			\
> > +		(vb)->vb2_queue, vb2_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
> 
> Such a header is also a good place to put all these defines above. That will
> clean things up.
> 
> Actually anything that is not needed by drivers can go in there.
> 
> > +
> > +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_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, unsigned int type,
> > +		unsigned int index, void *pb);
> > +int vb2_core_reqbufs(struct vb2_queue *q, unsigned int memory, unsigned int *count);
> > +int vb2_core_create_bufs(struct vb2_queue *q, unsigned int memory,
> > +		unsigned int *count, void *parg);
> > +int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int memory,
> > +		unsigned int type, unsigned int index, void *pb);
> > +
> > +int __must_check vb2_core_queue_init(struct vb2_queue *q);
> > +
> > +void vb2_core_queue_release(struct vb2_queue *q);
> > +void vb2_queue_error(struct vb2_queue *q);
> > +
> > +int vb2_core_qbuf(struct vb2_queue *q, unsigned int memory, unsigned int type,
> > +		unsigned int index, void *pb);
> > +int vb2_core_dqbuf(struct vb2_queue *q, unsigned int type, void *pb, bool nonblock);
> > +int vb2_core_expbuf(struct vb2_queue *q, unsigned int type, unsigned int index,
> > +		unsigned int plane, unsigned int flags);
> > +
> > +int vb2_core_streamon(struct vb2_queue *q, unsigned int type);
> > +int vb2_core_streamoff(struct vb2_queue *q, unsigned int 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
> > +
> > +/*
> > + * The following functions are for internal uses.
> > + */
> > +bool __buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb);
> > +void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p);
> > +void __vb2_buf_dmabuf_put(struct vb2_buffer *vb);
> > +int __verify_memory_type(struct vb2_queue *q,
> > +		enum v4l2_memory memory, enum v4l2_buf_type type);
> > +
> > +/**
> > + * 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;
> > +}
> > +
> > +/**
> > + * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue
> > + * @q:		videobuf queue
> > + */
> > +static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
> > +{
> > +	q->last_buffer_dequeued = false;
> > +}
> > +
> > +#endif /* _MEDIA_VIDEOBUF2_CORE_H */
> 
> <snip>
> 
> > diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h
> > index 76500f4..3f76e53 100644
> > --- a/include/media/videobuf2-v4l2.h
> > +++ b/include/media/videobuf2-v4l2.h
> > @@ -12,212 +12,11 @@
> >  #ifndef _MEDIA_VIDEOBUF2_V4L2_H
> >  #define _MEDIA_VIDEOBUF2_V4L2_H
> >  
> > -#include <linux/mm_types.h>
> > -#include <linux/mutex.h>
> > -#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_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 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
> > + * @vb2_buf:		videobuf2
> >   * @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
> > @@ -237,266 +36,34 @@ struct vb2_v4l2_buffer {
> >  };
> >  
> >  /**
> > - * 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_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_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)
> > - * @fileio_read_once:		report EOF after reading the first buffer
> > - * @fileio_write_immediately:	queue buffer after each write() call
> > - * @allow_zero_bytesused:	allow bytesused == 0 to be passed to the driver
> > - * @lock:	pointer to a mutex that protects the vb2_queue struct. The
> > - *		driver can set this to a mutex to let the vb2 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.
> > - * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the
> > - *		last decoded buffer was already dequeued. Set for capture queues
> > - *		when a buffer with the V4L2_BUF_FLAG_LAST is dequeued.
> > - * @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			fileio_read_once:1;
> > -	unsigned			fileio_write_immediately:1;
> > -	unsigned			allow_zero_bytesused:1;
> > -
> > -	struct mutex			*lock;
> > -	struct v4l2_fh			*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;
> > -	struct vb2_buffer		*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;
> > -	unsigned int			last_buffer_dequeued: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
> > -};
> > -
> > -/**
> >   * to_vb2_v4l2_buffer() - cast to struct vb2_v4l2_buffer *
> >   * @vb:		struct vb2_buffer *vb
> >   */
> >  #define to_vb2_v4l2_buffer(vb) \
> >  	(container_of(vb, struct vb2_v4l2_buffer, vb2_buf))
> >  
> > -#define vb2_v4l2_index(vb)						\
> > +#define vb2_v4l2_index(vb)					\
> >  ({								\
> >  	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);	\
> > -	int ret = vbuf->v4l2_buf.index;				\
> > +	unsigned int ret = vbuf->v4l2_buf.index;		\
> >  	ret;							\
> >  })
> >  
> > -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_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_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_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *cb);
> >  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_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblock);
> >  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);
> > @@ -533,52 +100,6 @@ int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv,
> >  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
> > @@ -624,24 +145,6 @@ vb2_plane_size(struct vb2_buffer *vb, 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;
> > -}
> > -
> > -/**
> > - * vb2_clear_last_buffer_dequeued() - clear last buffer dequeued flag of queue
> > - * @q:		videobuf queue
> > - */
> > -static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q)
> > -{
> > -	q->last_buffer_dequeued = false;
> > -}
> > -
> >  /*
> >   * 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,
> 
> Regards,
> 
> 	Hans

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

* Re: [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts
  2015-08-10 12:55     ` Mauro Carvalho Chehab
@ 2015-08-10 13:38       ` Hans Verkuil
  2015-08-11 13:51         ` Laurent Pinchart
  0 siblings, 1 reply; 23+ messages in thread
From: Hans Verkuil @ 2015-08-10 13:38 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Junghak Sung, linux-media, laurent.pinchart, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

On 08/10/2015 02:55 PM, Mauro Carvalho Chehab wrote:
> Em Mon, 10 Aug 2015 14:07:21 +0200
> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
> 
>> Hi Junghak,
>>
>> I'm reviewing the header changes since I think there are several improvements
>> that can be done that will make things more logical and will simplify the code.
>>
>> My comments below are a mix of suggestions for improvement and brainstorming.
>>
>> Feel free to ask for clarification if something is not clear.
>>
>> On 07/31/2015 10:44 AM, Junghak Sung wrote:
>>> Divide videobuf2-core into core part and v4l2-specific part
>>>  - core part: videobuf2 core related with buffer management & memory allocation
>>>  - v4l2-specific part: v4l2-specific stuff
>>>
>>> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>>> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
>>> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
>>> Acked-by: Inki Dae <inki.dae@samsung.com>
>>> ---
>>
>> <snip>
> 
> ...
> 
>> I noticed that __qbuf_mmap/userptr/dmabuf are all in -v4l2.c. That's a bad sign:
>> those are some of the most complex vb2 functions and they really belong in the
>> core since you'll need it for DVB as well. As suggested above, by moving the index,
>> length and offset/userptr/fd data to the core structs these functions can all be
>> moved back into core.c as far as I can see.
> 
> Well, that will depend on how the DVB implementation will actually be.
> 
> Currently, VB2 has lot of V4L2-dependent code on it, with lots of V4L2
> structs from videodev2.h that are there.
> 
> Well, if we want the core to be re-used, it should not include videodev2.h
> anymore. Also, it should not assume that all non-V4L2 cores would use
> exactly the same logic for the userspace API.

Agreed.

> In the DVB case, it makes no sense to have anything similar to OVERLAY
> there.

VB2 doesn't support overlay at all, so that's no problem.

> I also can't see any usage for USERPTR at DVB neither, as either
> MMAP or DMABUF should fulfill all userspace needs I'm aware of.

While USERPTR isn't needed for DVB, the actual handling of such buffers
is completely independent of the API. I think it is from an architecture
point-of-view a really bad idea if anyone other than the vb2 core would
call the memops. So yes, the core would have code that is not needed by
DVB, but it still is something that belongs to the core in my view. Anything
else is very ugly.

> 
> Also, the meta data for the DVB upcoming ioctls for MMAP/DMABUF aren't
> yet proposed. They can be very different than the ones inside the V4L2
> ioctls.

Well, it's pretty much constrained by mmap() and the dma-buf API. I.e. an
offset for for mmap and a fd for dmabuf. You don't have a choice here.

> 
> So, I guess it is better for now to keep those API-dependent stuff at 
> VB2-v4l2 and, once the DVB code (and the corresponding API bits) are
> written, revisit it and then move the common code to the VB2 core.

I strongly disagree with that. Having API-dependent code calling memops
defeats the purpose. There is nothing wrong with having a vb2 core that
supports e.g. USERPTR and dma-buf as long as that core is API-independent.

But there is a lot wrong if the API-dependent code is bypassing the vb2 core
code to call low-level memops.

>> It is good to remember that today the v4l2_buffer struct is used in the vb2
>> core because vb2 is only used with v4l2, so why duplicate v4l2_buffer fields
>> in the vb2 core structs? 
> 
> We should not have any v4l2_* struct inside VB2 core, as the DVB core
> should not be dependent on the V4L2 structs. So, everything that it is
> V4L2-specific should be inside the VB2-v4l2. The reverse is also true:
> we should not pollute the VB2 core with DVB-specific data structures.

I never said anything else. I was talking about what's used today and why
it is the way it is now.

> So, all VB2-specific struct should be at VB2-dvb.
> 
>> But if we want to reuse it for other subsystems, then
>> the vb2 core structs should contain all the core buffer information. This avoids
>> the need for a lot of the ops that you added and makes it possible to keep the
>> __qbuf_mmap/userptr/dmabuf in the core code as well.
>>
>> Adding these fields to the vb2 core structs is something that can be done first,
>> before splitting up core.c into core.c and v4l2.c.
> 
> I'm afraid that we'll lose the big picture if we try to put the
> API-dependent parts at the core before adding a non-V4L2 usage on VB2.
> 
> We can always simplify the code latter, but IMHO we should focus first
> on adding the new functionality (support for DVB). Afterwards, we'll have
> a better view on what API-dependent code could be shared.

This is core code. I must be able to follow all the changes and right now
I can't. So simplifications like this should be done first before the split.
It will makes things much easier to follow.

The whole goal of a vb2 core is that it:

1) does not use any v4l2/dvb/whatever subsystem specific structs or includes.
2) deals with *all* the buffer memory handling. This is the most complex part, and
   that's what really belongs here. So memops being called from API-dependent code
   is wrong and I'll NACK that.
3) does all the ringbuffer handling etc.

The split will be much more obvious and logical if things like index, length,
offset/userptr/fd are added to the vb2 core structs. We could have done that
when we created vb2 since it's obviously essential core buffer information, but we
had the v4l2_buffer struct anyway so there was no real need to do so. But now there
is.

Regards,

	Hans

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

* Re: [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use
  2015-08-10 11:44         ` Hans Verkuil
@ 2015-08-11  1:37           ` Junghak Sung
  0 siblings, 0 replies; 23+ messages in thread
From: Junghak Sung @ 2015-08-11  1:37 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab
  Cc: linux-media, laurent.pinchart, sakari.ailus, pawel, inki.dae,
	sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon


Hi, Hans and Mauro.

First of all, thank you for your reviews.

On 08/10/2015 08:44 PM, Hans Verkuil wrote:
> On 08/10/2015 12:49 PM, Mauro Carvalho Chehab wrote:
>> Em Mon, 10 Aug 2015 12:11:39 +0200
>> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
>>
>>> On 08/10/2015 11:32 AM, Mauro Carvalho Chehab wrote:
>>>> Em Mon, 10 Aug 2015 10:31:03 +0200
>>>> Hans Verkuil <hverkuil@xs4all.nl> escreveu:
>>>>
>>>>> Hi Jungsak,
>>>>>
>>>>> On 07/31/2015 10:44 AM, Junghak Sung wrote:
>>>>>> Hello everybody,
>>>>>>
>>>>>> This is the 2nd round for refactoring Videobuf2(a.k.a VB2).
>>>>>> The purpose of this patch series is to separate existing VB2 framework
>>>>>> into core part and V4L2 specific part. So that not only V4L2 but also other
>>>>>> frameworks can use them to manage buffer and utilize queue.
>>>>>>
>>>>>> 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.
>>>>>>
>>>>>> We have a plan for this work as follows:
>>>>>> 1. Separate existing VB2 framework into three parts - VB2 common, VB2-v4l2.
>>>>>>     Of course, this change will not affect other v4l2-based
>>>>>>     device drivers. This patch series corresponds to this step.
>>>>>>
>>>>>> 2. Add and implement new APIs for DVB streaming I/O.
>>>>>>     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.
>>>>>>
>>>>>> This patch series is the first step for it.
>>>>>> The previous version of this patch series can be found at [1].
>>>>>>
>>>>>> [1] RFC PATCH v1 - http://www.spinics.net/lists/linux-media/msg90688.html
>>>>>
>>>>> This v2 looks much better, but, as per my comment to patch 1/5, it needs a bit
>>>>> more work before I can do a really good review. I think things will be much
>>>>> clearer once patch 3 shows the code moving from core.c/h to v4l2.c/h instead
>>>>> of the other way around. That shouldn't be too difficult.
>>>>
>>>> Hans,
>>>>
>>>> I suggested Junkhak to do that. On his previous patchset, he did what
>>>> you're suggestiong, e. g moving things from vb2-core into vb2-v4l2, and
>>>> that resulted on patches big enough to not be catched by vger.
>>>
>>> Actually, that wasn't the reason why the patches became so big. I just
>>> reorganized the patch series as I suggested above (pretty easy to do) and
>>> the size of patch 3 went down.

Considering only size of the patch, it is better to move from vb2-v4l2 
to vb2-core as this patch. Because the file size of videobuf2-v4l2.c 
(56k) is bigger that videobuf2-core.c (50k). :P

>>
>> Ah, ok.
>>
>>>> Also, IMHO, it is cleared this way, as we can see what parts of VB2 will
>>>> actually be shared, as there are lots of things that won't be shared:
>>>> overlay, userptr, multiplanar.
>>>
>>> That's why I prefer to see what moves *out* from the core.
>>>
>>> To be honest, it depends on what your preference is.
>>
>> Yeah. I actually prefer to see what will be shared, because the
>> non-shared code won't have changes (except for minor kABI things),
>> while the shared code will be more affected :)
>>

As Mauro said, I focus on what code can be shared. In other words,
what code is NOT dependent on V4L2 and what code is really necessary for 
vb2-core even though it is depend on V4l2. And then, those codes
are moved from vb2-v4l2 to vb2-core.

>>> Junghak, just leave the patch as-is. However, for v3 you should run
>>> checkpatch.pl over the diff since it complained about various things.
>>
>> There are two things here:
>>
>> 1) on patches that just move things around, we should not
>> run checkpatch, as otherwise it would be a nightmare for
>> review. Ok, as we're doing a remanufacturing, it is a good
>> idea to run checkpatch at the end and see what should be fixed
>> (or do it before), but this is out of the scope of the manufacturing.
>> I can do that myself when applying the series.
>
> It was actually complaining about new code.
>
> 	Hans
>
>>
>> 2) For all other patches that are adding/changing the code, then
>> Junghak should run checkpatch and fix (most) stuff complained there.

Ok. for v3, I will run checkpatch for added/changed code.

>>
>> Regards,
>> Mauro
>>
>
> --
> 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] 23+ messages in thread

* Re: [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory
  2015-08-10  8:22   ` Hans Verkuil
@ 2015-08-11  2:19     ` Junghak Sung
  2015-08-11  6:32       ` Hans Verkuil
  2015-08-11 13:56     ` Laurent Pinchart
  1 sibling, 1 reply; 23+ messages in thread
From: Junghak Sung @ 2015-08-11  2:19 UTC (permalink / raw)
  To: Hans Verkuil, linux-media, mchehab, laurent.pinchart,
	sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon


Hi Hans,

On 08/10/2015 05:22 PM, Hans Verkuil wrote:
> On 07/31/2015 10:44 AM, Junghak Sung wrote:
>> Define enum vb2_buf_type and enum vb2_memory for videobuf2-core. This
>> change requires translation functions that could covert v4l2-core stuffs
>> to videobuf2-core stuffs in videobuf2-v4l2.c file.
>> The v4l2-specific member variables(e.g. type, memory) remains in
>> struct vb2_queue for backward compatibility and performance of type translation.
>>
>> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
>> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
>> Acked-by: Inki Dae <inki.dae@samsung.com>
>> ---
>>   drivers/media/v4l2-core/videobuf2-core.c |  139 +++++++++++---------
>>   drivers/media/v4l2-core/videobuf2-v4l2.c |  209 ++++++++++++++++++++----------
>>   include/media/videobuf2-core.h           |   99 +++++++++++---
>>   include/media/videobuf2-v4l2.h           |   12 +-
>>   4 files changed, 299 insertions(+), 160 deletions(-)
>>
>
> <snip>
>
>> diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
>> index 85527e9..22dd19c 100644
>> --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
>> +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
>> @@ -30,8 +30,46 @@
>>   #include <media/v4l2-common.h>
>>   #include <media/videobuf2-v4l2.h>
>>
>> +#define CREATE_TRACE_POINTS
>>   #include <trace/events/v4l2.h>
>>
>> +static const enum vb2_buf_type _tbl_buf_type[] = {
>> +	[V4L2_BUF_TYPE_VIDEO_CAPTURE]		= VB2_BUF_TYPE_VIDEO_CAPTURE,
>> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT]		= VB2_BUF_TYPE_VIDEO_OUTPUT,
>> +	[V4L2_BUF_TYPE_VIDEO_OVERLAY]		= VB2_BUF_TYPE_VIDEO_OVERLAY,
>> +	[V4L2_BUF_TYPE_VBI_CAPTURE]		= VB2_BUF_TYPE_VBI_CAPTURE,
>> +	[V4L2_BUF_TYPE_VBI_OUTPUT]		= VB2_BUF_TYPE_VBI_OUTPUT,
>> +	[V4L2_BUF_TYPE_SLICED_VBI_CAPTURE]	= VB2_BUF_TYPE_SLICED_VBI_CAPTURE,
>> +	[V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]	= VB2_BUF_TYPE_SLICED_VBI_OUTPUT,
>> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY]	= VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY,
>> +	[V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE]	= VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
>> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE]	= VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
>> +	[V4L2_BUF_TYPE_SDR_CAPTURE]		= VB2_BUF_TYPE_SDR_CAPTURE,
>> +	[V4L2_BUF_TYPE_PRIVATE]			= VB2_BUF_TYPE_PRIVATE,
>> +};
>> +
>> +static const enum vb2_memory _tbl_memory[] = {
>> +	[V4L2_MEMORY_MMAP]	= VB2_MEMORY_MMAP,
>> +	[V4L2_MEMORY_USERPTR]	= VB2_MEMORY_USERPTR,
>> +	[V4L2_MEMORY_DMABUF]	= VB2_MEMORY_DMABUF,
>> +};
>> +
>> +#define to_vb2_buf_type(type)					\
>> +({								\
>> +	enum vb2_buf_type ret = 0;				\
>> +	if( type > 0 && type < ARRAY_SIZE(_tbl_buf_type) )	\
>> +		ret = (_tbl_buf_type[type]);			\
>> +	ret;							\
>> +})
>> +
>> +#define to_vb2_memory(memory)					\
>> +({								\
>> +	enum vb2_memory ret = 0;				\
>> +	if( memory > 0 && memory < ARRAY_SIZE(_tbl_memory) )	\
>> +		ret = (_tbl_memory[memory]);			\
>> +	ret;							\
>> +})
>> +
>
> <snip>
>
>> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
>> index dc405da..871fcc6 100644
>> --- a/include/media/videobuf2-core.h
>> +++ b/include/media/videobuf2-core.h
>> @@ -15,9 +15,47 @@
>>   #include <linux/mm_types.h>
>>   #include <linux/mutex.h>
>>   #include <linux/poll.h>
>> -#include <linux/videodev2.h>
>>   #include <linux/dma-buf.h>
>>
>> +#define VB2_MAX_FRAME               32
>> +#define VB2_MAX_PLANES               8
>> +
>> +enum vb2_buf_type {
>> +	VB2_BUF_TYPE_UNKNOWN			= 0,
>> +	VB2_BUF_TYPE_VIDEO_CAPTURE		= 1,
>> +	VB2_BUF_TYPE_VIDEO_OUTPUT		= 2,
>> +	VB2_BUF_TYPE_VIDEO_OVERLAY		= 3,
>> +	VB2_BUF_TYPE_VBI_CAPTURE		= 4,
>> +	VB2_BUF_TYPE_VBI_OUTPUT			= 5,
>> +	VB2_BUF_TYPE_SLICED_VBI_CAPTURE		= 6,
>> +	VB2_BUF_TYPE_SLICED_VBI_OUTPUT		= 7,
>> +	VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY	= 8,
>> +	VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	= 9,
>> +	VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE	= 10,
>> +	VB2_BUF_TYPE_SDR_CAPTURE		= 11,
>> +	VB2_BUF_TYPE_DVB_CAPTURE		= 12,
>> +	VB2_BUF_TYPE_PRIVATE			= 0x80,
>> +};
>> +
>> +enum vb2_memory {
>> +	VB2_MEMORY_UNKNOWN	= 0,
>> +	VB2_MEMORY_MMAP		= 1,
>> +	VB2_MEMORY_USERPTR	= 2,
>> +	VB2_MEMORY_DMABUF	= 4,
>> +};
>> +
>> +#define VB2_TYPE_IS_MULTIPLANAR(type)			\
>> +	((type) == VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	\
>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
>> +
>> +#define VB2_TYPE_IS_OUTPUT(type)				\
>> +	((type) == VB2_BUF_TYPE_VIDEO_OUTPUT			\
>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE		\
>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OVERLAY		\
>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY		\
>> +	 || (type) == VB2_BUF_TYPE_VBI_OUTPUT			\
>> +	 || (type) == VB2_BUF_TYPE_SLICED_VBI_OUTPUT)
>
> You don't actually need to create vb2_buf_type: unless I am mistaken, all that the
> vb2 core needs to know is if it is a capture or output queue and possibly (not
> sure about that) if it is single or multiplanar. So add fields to the vb2_queue struct
> for that information and leave the buf_type to the v4l2 specific header and code.
>
Good idea. As your comment, the vb2_buf_type is used only for checking 
if the buffer is a capture or output type in the videobuf2-core.c.
But, I think it is better to add .is_output() to vb2_buf_ops in struct
vb2_queue rather than add a fields.

> You also don't need the _tbl_memory[] array. All you need to do is to check in
> videobuf2-v4l2.c that VB2_MEMORY* equals the V4L2_MEMORY_* defines and generate
> a #error if not:
>
> #if VB2_MEMORY_MMAP != V4L2_MEMORY_MMAP || VB2_MEMORY_....
> #error VB2_MEMORY_* != V4L2_MEMORY_*!
> #endif

Good idea, too. For v3, I will rework as your guide.

>
> Regards,
>
> 	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] 23+ messages in thread

* Re: [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory
  2015-08-11  2:19     ` Junghak Sung
@ 2015-08-11  6:32       ` Hans Verkuil
  0 siblings, 0 replies; 23+ messages in thread
From: Hans Verkuil @ 2015-08-11  6:32 UTC (permalink / raw)
  To: Junghak Sung, linux-media, mchehab, laurent.pinchart,
	sakari.ailus, pawel
  Cc: inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

On 08/11/2015 04:19 AM, Junghak Sung wrote:
> 
> Hi Hans,
> 
> On 08/10/2015 05:22 PM, Hans Verkuil wrote:
>> On 07/31/2015 10:44 AM, Junghak Sung wrote:
>>> Define enum vb2_buf_type and enum vb2_memory for videobuf2-core. This
>>> change requires translation functions that could covert v4l2-core stuffs
>>> to videobuf2-core stuffs in videobuf2-v4l2.c file.
>>> The v4l2-specific member variables(e.g. type, memory) remains in
>>> struct vb2_queue for backward compatibility and performance of type translation.
>>>
>>> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
>>> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
>>> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
>>> Acked-by: Inki Dae <inki.dae@samsung.com>
>>> ---
>>>   drivers/media/v4l2-core/videobuf2-core.c |  139 +++++++++++---------
>>>   drivers/media/v4l2-core/videobuf2-v4l2.c |  209 ++++++++++++++++++++----------
>>>   include/media/videobuf2-core.h           |   99 +++++++++++---
>>>   include/media/videobuf2-v4l2.h           |   12 +-
>>>   4 files changed, 299 insertions(+), 160 deletions(-)
>>>
>>
>> <snip>
>>
>>> diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c
>>> index 85527e9..22dd19c 100644
>>> --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
>>> +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
>>> @@ -30,8 +30,46 @@
>>>   #include <media/v4l2-common.h>
>>>   #include <media/videobuf2-v4l2.h>
>>>
>>> +#define CREATE_TRACE_POINTS
>>>   #include <trace/events/v4l2.h>
>>>
>>> +static const enum vb2_buf_type _tbl_buf_type[] = {
>>> +	[V4L2_BUF_TYPE_VIDEO_CAPTURE]		= VB2_BUF_TYPE_VIDEO_CAPTURE,
>>> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT]		= VB2_BUF_TYPE_VIDEO_OUTPUT,
>>> +	[V4L2_BUF_TYPE_VIDEO_OVERLAY]		= VB2_BUF_TYPE_VIDEO_OVERLAY,
>>> +	[V4L2_BUF_TYPE_VBI_CAPTURE]		= VB2_BUF_TYPE_VBI_CAPTURE,
>>> +	[V4L2_BUF_TYPE_VBI_OUTPUT]		= VB2_BUF_TYPE_VBI_OUTPUT,
>>> +	[V4L2_BUF_TYPE_SLICED_VBI_CAPTURE]	= VB2_BUF_TYPE_SLICED_VBI_CAPTURE,
>>> +	[V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]	= VB2_BUF_TYPE_SLICED_VBI_OUTPUT,
>>> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY]	= VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY,
>>> +	[V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE]	= VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
>>> +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE]	= VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
>>> +	[V4L2_BUF_TYPE_SDR_CAPTURE]		= VB2_BUF_TYPE_SDR_CAPTURE,
>>> +	[V4L2_BUF_TYPE_PRIVATE]			= VB2_BUF_TYPE_PRIVATE,
>>> +};
>>> +
>>> +static const enum vb2_memory _tbl_memory[] = {
>>> +	[V4L2_MEMORY_MMAP]	= VB2_MEMORY_MMAP,
>>> +	[V4L2_MEMORY_USERPTR]	= VB2_MEMORY_USERPTR,
>>> +	[V4L2_MEMORY_DMABUF]	= VB2_MEMORY_DMABUF,
>>> +};
>>> +
>>> +#define to_vb2_buf_type(type)					\
>>> +({								\
>>> +	enum vb2_buf_type ret = 0;				\
>>> +	if( type > 0 && type < ARRAY_SIZE(_tbl_buf_type) )	\
>>> +		ret = (_tbl_buf_type[type]);			\
>>> +	ret;							\
>>> +})
>>> +
>>> +#define to_vb2_memory(memory)					\
>>> +({								\
>>> +	enum vb2_memory ret = 0;				\
>>> +	if( memory > 0 && memory < ARRAY_SIZE(_tbl_memory) )	\
>>> +		ret = (_tbl_memory[memory]);			\
>>> +	ret;							\
>>> +})
>>> +
>>
>> <snip>
>>
>>> diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
>>> index dc405da..871fcc6 100644
>>> --- a/include/media/videobuf2-core.h
>>> +++ b/include/media/videobuf2-core.h
>>> @@ -15,9 +15,47 @@
>>>   #include <linux/mm_types.h>
>>>   #include <linux/mutex.h>
>>>   #include <linux/poll.h>
>>> -#include <linux/videodev2.h>
>>>   #include <linux/dma-buf.h>
>>>
>>> +#define VB2_MAX_FRAME               32
>>> +#define VB2_MAX_PLANES               8
>>> +
>>> +enum vb2_buf_type {
>>> +	VB2_BUF_TYPE_UNKNOWN			= 0,
>>> +	VB2_BUF_TYPE_VIDEO_CAPTURE		= 1,
>>> +	VB2_BUF_TYPE_VIDEO_OUTPUT		= 2,
>>> +	VB2_BUF_TYPE_VIDEO_OVERLAY		= 3,
>>> +	VB2_BUF_TYPE_VBI_CAPTURE		= 4,
>>> +	VB2_BUF_TYPE_VBI_OUTPUT			= 5,
>>> +	VB2_BUF_TYPE_SLICED_VBI_CAPTURE		= 6,
>>> +	VB2_BUF_TYPE_SLICED_VBI_OUTPUT		= 7,
>>> +	VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY	= 8,
>>> +	VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	= 9,
>>> +	VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE	= 10,
>>> +	VB2_BUF_TYPE_SDR_CAPTURE		= 11,
>>> +	VB2_BUF_TYPE_DVB_CAPTURE		= 12,
>>> +	VB2_BUF_TYPE_PRIVATE			= 0x80,
>>> +};
>>> +
>>> +enum vb2_memory {
>>> +	VB2_MEMORY_UNKNOWN	= 0,
>>> +	VB2_MEMORY_MMAP		= 1,
>>> +	VB2_MEMORY_USERPTR	= 2,
>>> +	VB2_MEMORY_DMABUF	= 4,
>>> +};
>>> +
>>> +#define VB2_TYPE_IS_MULTIPLANAR(type)			\
>>> +	((type) == VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	\
>>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
>>> +
>>> +#define VB2_TYPE_IS_OUTPUT(type)				\
>>> +	((type) == VB2_BUF_TYPE_VIDEO_OUTPUT			\
>>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE		\
>>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OVERLAY		\
>>> +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY		\
>>> +	 || (type) == VB2_BUF_TYPE_VBI_OUTPUT			\
>>> +	 || (type) == VB2_BUF_TYPE_SLICED_VBI_OUTPUT)
>>
>> You don't actually need to create vb2_buf_type: unless I am mistaken, all that the
>> vb2 core needs to know is if it is a capture or output queue and possibly (not
>> sure about that) if it is single or multiplanar. So add fields to the vb2_queue struct
>> for that information and leave the buf_type to the v4l2 specific header and code.
>>
> Good idea. As your comment, the vb2_buf_type is used only for checking 
> if the buffer is a capture or output type in the videobuf2-core.c.
> But, I think it is better to add .is_output() to vb2_buf_ops in struct
> vb2_queue rather than add a fields.

Please just add a field. Callbacks are always harder to review and debug since you
have to lookup what the callbacks do.

It is much cleaner if you just add a field to the vb2 core for this.

Regards,

	Hans

> 
>> You also don't need the _tbl_memory[] array. All you need to do is to check in
>> videobuf2-v4l2.c that VB2_MEMORY* equals the V4L2_MEMORY_* defines and generate
>> a #error if not:
>>
>> #if VB2_MEMORY_MMAP != V4L2_MEMORY_MMAP || VB2_MEMORY_....
>> #error VB2_MEMORY_* != V4L2_MEMORY_*!
>> #endif
> 
> Good idea, too. For v3, I will rework as your guide.
> 
>>
>> Regards,
>>
>> 	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] 23+ messages in thread

* Re: [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts
  2015-08-10 13:38       ` Hans Verkuil
@ 2015-08-11 13:51         ` Laurent Pinchart
  0 siblings, 0 replies; 23+ messages in thread
From: Laurent Pinchart @ 2015-08-11 13:51 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Mauro Carvalho Chehab, Junghak Sung, linux-media, sakari.ailus,
	pawel, inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee,
	rany.kwon

Hello,

On Monday 10 August 2015 15:38:48 Hans Verkuil wrote:
> On 08/10/2015 02:55 PM, Mauro Carvalho Chehab wrote:
> > Em Mon, 10 Aug 2015 14:07:21 +0200 Hans Verkuil escreveu:
> >> Hi Junghak,
> >> 
> >> I'm reviewing the header changes since I think there are several
> >> improvements that can be done that will make things more logical and
> >> will simplify the code.
> >> 
> >> My comments below are a mix of suggestions for improvement and
> >> brainstorming.
> >> 
> >> Feel free to ask for clarification if something is not clear.
> >> 
> >> On 07/31/2015 10:44 AM, Junghak Sung wrote:
> >>> Divide videobuf2-core into core part and v4l2-specific part
> >>> 
> >>>  - core part: videobuf2 core related with buffer management & memory
> >>>  allocation - v4l2-specific part: v4l2-specific stuff
> >>> 
> >>> Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> >>> Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
> >>> Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> >>> Acked-by: Inki Dae <inki.dae@samsung.com>
> >>> ---
> >> 
> >> <snip>
> > 
> > ...
> > 
> >> I noticed that __qbuf_mmap/userptr/dmabuf are all in -v4l2.c. That's a
> >> bad sign: those are some of the most complex vb2 functions and they
> >> really belong in the core since you'll need it for DVB as well. As
> >> suggested above, by moving the index, length and offset/userptr/fd data
> >> to the core structs these functions can all be moved back into core.c as
> >> far as I can see.
> > 
> > Well, that will depend on how the DVB implementation will actually be.
> > 
> > Currently, VB2 has lot of V4L2-dependent code on it, with lots of V4L2
> > structs from videodev2.h that are there.
> > 
> > Well, if we want the core to be re-used, it should not include videodev2.h
> > anymore. Also, it should not assume that all non-V4L2 cores would use
> > exactly the same logic for the userspace API.
> 
> Agreed.
> 
> > In the DVB case, it makes no sense to have anything similar to OVERLAY
> > there.
> 
> VB2 doesn't support overlay at all, so that's no problem.
> 
> > I also can't see any usage for USERPTR at DVB neither, as either
> > MMAP or DMABUF should fulfill all userspace needs I'm aware of.
> 
> While USERPTR isn't needed for DVB, the actual handling of such buffers
> is completely independent of the API. I think it is from an architecture
> point-of-view a really bad idea if anyone other than the vb2 core would
> call the memops. So yes, the core would have code that is not needed by
> DVB, but it still is something that belongs to the core in my view. Anything
> else is very ugly.

I agree, USERPTR handling belongs to the core as that's not dependent on V4L2. 
However, I'd make USERPTR usage not recommended for new drivers/subsystems 
(that's a polite way to say "don't even think about using it" :-)) as DMABUF 
should support the USERPTR use cases nowadays, and USERPTR wobbly as DMA to 
userspace memory isn't officially supported on all architectures.

> > Also, the meta data for the DVB upcoming ioctls for MMAP/DMABUF aren't
> > yet proposed. They can be very different than the ones inside the V4L2
> > ioctls.
> 
> Well, it's pretty much constrained by mmap() and the dma-buf API. I.e. an
> offset for for mmap and a fd for dmabuf. You don't have a choice here.
> 
> > So, I guess it is better for now to keep those API-dependent stuff at
> > VB2-v4l2 and, once the DVB code (and the corresponding API bits) are
> > written, revisit it and then move the common code to the VB2 core.
> 
> I strongly disagree with that. Having API-dependent code calling memops
> defeats the purpose. There is nothing wrong with having a vb2 core that
> supports e.g. USERPTR and dma-buf as long as that core is API-independent.
> 
> But there is a lot wrong if the API-dependent code is bypassing the vb2 core
> code to call low-level memops.
> 
> >> It is good to remember that today the v4l2_buffer struct is used in the
> >> vb2 core because vb2 is only used with v4l2, so why duplicate v4l2_buffer
> >> fields in the vb2 core structs?
> > 
> > We should not have any v4l2_* struct inside VB2 core, as the DVB core
> > should not be dependent on the V4L2 structs. So, everything that it is
> > V4L2-specific should be inside the VB2-v4l2. The reverse is also true:
> > we should not pollute the VB2 core with DVB-specific data structures.
> 
> I never said anything else. I was talking about what's used today and why
> it is the way it is now.
> 
> > So, all VB2-specific struct should be at VB2-dvb.
> > 
> >> But if we want to reuse it for other subsystems, then
> >> the vb2 core structs should contain all the core buffer information. This
> >> avoids the need for a lot of the ops that you added and makes it
> >> possible to keep the __qbuf_mmap/userptr/dmabuf in the core code as
> >> well.
> >> 
> >> Adding these fields to the vb2 core structs is something that can be done
> >> first, before splitting up core.c into core.c and v4l2.c.
> > 
> > I'm afraid that we'll lose the big picture if we try to put the
> > API-dependent parts at the core before adding a non-V4L2 usage on VB2.
> > 
> > We can always simplify the code latter, but IMHO we should focus first
> > on adding the new functionality (support for DVB). Afterwards, we'll have
> > a better view on what API-dependent code could be shared.
> 
> This is core code. I must be able to follow all the changes and right now
> I can't. So simplifications like this should be done first before the split.
> It will makes things much easier to follow.
> 
> The whole goal of a vb2 core is that it:
> 
> 1) does not use any v4l2/dvb/whatever subsystem specific structs or
> includes. 2) deals with *all* the buffer memory handling. This is the most
> complex part, and that's what really belongs here. So memops being called
> from API-dependent code is wrong and I'll NACK that.
> 3) does all the ringbuffer handling etc.

For what it's worth, I have the same view for the vb2 core goals.

> The split will be much more obvious and logical if things like index,
> length, offset/userptr/fd are added to the vb2 core structs. We could have
> done that when we created vb2 since it's obviously essential core buffer
> information, but we had the v4l2_buffer struct anyway so there was no real
> need to do so. But now there is.

-- 
Regards,

Laurent Pinchart


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

* Re: [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory
  2015-08-10  8:22   ` Hans Verkuil
  2015-08-11  2:19     ` Junghak Sung
@ 2015-08-11 13:56     ` Laurent Pinchart
  2015-08-11 13:59       ` Hans Verkuil
  1 sibling, 1 reply; 23+ messages in thread
From: Laurent Pinchart @ 2015-08-11 13:56 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Junghak Sung, linux-media, mchehab, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Hello,

On Monday 10 August 2015 10:22:12 Hans Verkuil wrote:
> On 07/31/2015 10:44 AM, Junghak Sung wrote:
> > Define enum vb2_buf_type and enum vb2_memory for videobuf2-core. This
> > change requires translation functions that could covert v4l2-core stuffs
> > to videobuf2-core stuffs in videobuf2-v4l2.c file.
> > The v4l2-specific member variables(e.g. type, memory) remains in
> > struct vb2_queue for backward compatibility and performance of type
> > translation.
> > 
> > Signed-off-by: Junghak Sung <jh1009.sung@samsung.com>
> > Signed-off-by: Geunyoung Kim <nenggun.kim@samsung.com>
> > Acked-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> > Acked-by: Inki Dae <inki.dae@samsung.com>
> > ---
> > 
> >  drivers/media/v4l2-core/videobuf2-core.c |  139 +++++++++++---------
> >  drivers/media/v4l2-core/videobuf2-v4l2.c |  209 ++++++++++++++++++-------
> >  include/media/videobuf2-core.h           |   99 +++++++++++---
> >  include/media/videobuf2-v4l2.h           |   12 +-
> >  4 files changed, 299 insertions(+), 160 deletions(-)
> 
> <snip>
> 
> > diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c
> > b/drivers/media/v4l2-core/videobuf2-v4l2.c index 85527e9..22dd19c 100644
> > --- a/drivers/media/v4l2-core/videobuf2-v4l2.c
> > +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c
> > @@ -30,8 +30,46 @@
> > 
> >  #include <media/v4l2-common.h>
> >  #include <media/videobuf2-v4l2.h>
> > 
> > +#define CREATE_TRACE_POINTS
> > 
> >  #include <trace/events/v4l2.h>
> > 
> > +static const enum vb2_buf_type _tbl_buf_type[] = {
> > +	[V4L2_BUF_TYPE_VIDEO_CAPTURE]		= VB2_BUF_TYPE_VIDEO_CAPTURE,
> > +	[V4L2_BUF_TYPE_VIDEO_OUTPUT]		= VB2_BUF_TYPE_VIDEO_OUTPUT,
> > +	[V4L2_BUF_TYPE_VIDEO_OVERLAY]		= VB2_BUF_TYPE_VIDEO_OVERLAY,
> > +	[V4L2_BUF_TYPE_VBI_CAPTURE]		= VB2_BUF_TYPE_VBI_CAPTURE,
> > +	[V4L2_BUF_TYPE_VBI_OUTPUT]		= VB2_BUF_TYPE_VBI_OUTPUT,
> > +	[V4L2_BUF_TYPE_SLICED_VBI_CAPTURE]	= 
VB2_BUF_TYPE_SLICED_VBI_CAPTURE,
> > +	[V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]	= VB2_BUF_TYPE_SLICED_VBI_OUTPUT,
> > +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY]	=
> > VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY,
> > +	[V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE]	=
> > VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
> > +	[V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE]	= 
VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
> > +	[V4L2_BUF_TYPE_SDR_CAPTURE]		= VB2_BUF_TYPE_SDR_CAPTURE,
> > +	[V4L2_BUF_TYPE_PRIVATE]			= VB2_BUF_TYPE_PRIVATE,
> > +};
> > +
> > +static const enum vb2_memory _tbl_memory[] = {
> > +	[V4L2_MEMORY_MMAP]	= VB2_MEMORY_MMAP,
> > +	[V4L2_MEMORY_USERPTR]	= VB2_MEMORY_USERPTR,
> > +	[V4L2_MEMORY_DMABUF]	= VB2_MEMORY_DMABUF,
> > +};
> > +
> > +#define to_vb2_buf_type(type)					\
> > +({								\
> > +	enum vb2_buf_type ret = 0;				\
> > +	if( type > 0 && type < ARRAY_SIZE(_tbl_buf_type) )	\
> > +		ret = (_tbl_buf_type[type]);			\
> > +	ret;							\
> > +})
> > +
> > +#define to_vb2_memory(memory)					\
> > +({								\
> > +	enum vb2_memory ret = 0;				\
> > +	if( memory > 0 && memory < ARRAY_SIZE(_tbl_memory) )	\
> > +		ret = (_tbl_memory[memory]);			\
> > +	ret;							\
> > +})
> > +
> 
> <snip>
> 
> > diff --git a/include/media/videobuf2-core.h
> > b/include/media/videobuf2-core.h index dc405da..871fcc6 100644
> > --- a/include/media/videobuf2-core.h
> > +++ b/include/media/videobuf2-core.h
> > @@ -15,9 +15,47 @@
> > 
> >  #include <linux/mm_types.h>
> >  #include <linux/mutex.h>
> >  #include <linux/poll.h>
> > 
> > -#include <linux/videodev2.h>
> > 
> >  #include <linux/dma-buf.h>
> > 
> > +#define VB2_MAX_FRAME               32
> > +#define VB2_MAX_PLANES               8
> > +
> > +enum vb2_buf_type {
> > +	VB2_BUF_TYPE_UNKNOWN			= 0,
> > +	VB2_BUF_TYPE_VIDEO_CAPTURE		= 1,
> > +	VB2_BUF_TYPE_VIDEO_OUTPUT		= 2,
> > +	VB2_BUF_TYPE_VIDEO_OVERLAY		= 3,
> > +	VB2_BUF_TYPE_VBI_CAPTURE		= 4,
> > +	VB2_BUF_TYPE_VBI_OUTPUT			= 5,
> > +	VB2_BUF_TYPE_SLICED_VBI_CAPTURE		= 6,
> > +	VB2_BUF_TYPE_SLICED_VBI_OUTPUT		= 7,
> > +	VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY	= 8,
> > +	VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	= 9,
> > +	VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE	= 10,
> > +	VB2_BUF_TYPE_SDR_CAPTURE		= 11,
> > +	VB2_BUF_TYPE_DVB_CAPTURE		= 12,
> > +	VB2_BUF_TYPE_PRIVATE			= 0x80,
> > +};
> > +
> > +enum vb2_memory {
> > +	VB2_MEMORY_UNKNOWN	= 0,
> > +	VB2_MEMORY_MMAP		= 1,
> > +	VB2_MEMORY_USERPTR	= 2,
> > +	VB2_MEMORY_DMABUF	= 4,
> > +};
> > +
> > +#define VB2_TYPE_IS_MULTIPLANAR(type)			\
> > +	((type) == VB2_BUF_TYPE_VIDEO_CAPTURE_MPLANE	\
> > +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
> > +
> > +#define VB2_TYPE_IS_OUTPUT(type)				\
> > +	((type) == VB2_BUF_TYPE_VIDEO_OUTPUT			\
> > +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_MPLANE		\
> > +	 || (type) == VB2_BUF_TYPE_VIDEO_OVERLAY		\
> > +	 || (type) == VB2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY		\
> > +	 || (type) == VB2_BUF_TYPE_VBI_OUTPUT			\
> > +	 || (type) == VB2_BUF_TYPE_SLICED_VBI_OUTPUT)
> 
> You don't actually need to create vb2_buf_type: unless I am mistaken, all
> that the vb2 core needs to know is if it is a capture or output queue and
> possibly (not sure about that) if it is single or multiplanar. So add
> fields to the vb2_queue struct for that information and leave the buf_type
> to the v4l2 specific header and code.
> 
> You also don't need the _tbl_memory[] array. All you need to do is to check
> in videobuf2-v4l2.c that VB2_MEMORY* equals the V4L2_MEMORY_* defines and
> generate a #error if not:
> 
> #if VB2_MEMORY_MMAP != V4L2_MEMORY_MMAP || VB2_MEMORY_....
> #error VB2_MEMORY_* != V4L2_MEMORY_*!
> #endif

Hijacking this e-mail thread a bit, would it make sense for the new vb2-core 
to support different memory allocation for different planes ? I'm foreseeing 
use cases for buffers that bundle image data with meta-data, where image data 
should be captured to a dma-buf imported buffer, but meta-data doesn't need to 
be shared. In that case it wouldn't be easy for userspace to find a dma-buf 
provider for the meta-data buffers in order to import all planes. Being able 
to use dma-buf import for the image plane(s) and mmap for the meta-data plane 
would be easier.

-- 
Regards,

Laurent Pinchart


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

* Re: [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory
  2015-08-11 13:56     ` Laurent Pinchart
@ 2015-08-11 13:59       ` Hans Verkuil
  2015-08-11 14:04         ` Laurent Pinchart
  0 siblings, 1 reply; 23+ messages in thread
From: Hans Verkuil @ 2015-08-11 13:59 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Junghak Sung, linux-media, mchehab, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

On 08/11/15 15:56, Laurent Pinchart wrote:
> 
> Hijacking this e-mail thread a bit, would it make sense for the new vb2-core 
> to support different memory allocation for different planes ? I'm foreseeing 
> use cases for buffers that bundle image data with meta-data, where image data 
> should be captured to a dma-buf imported buffer, but meta-data doesn't need to 
> be shared. In that case it wouldn't be easy for userspace to find a dma-buf 
> provider for the meta-data buffers in order to import all planes. Being able 
> to use dma-buf import for the image plane(s) and mmap for the meta-data plane 
> would be easier.

Yes, that would make sense, but I'd postpone that until someone actually needs
it.

The biggest hurdle would be how to adapt the V4L2 API to this, and not the actual
vb2 core code.

Regards,

	Hans

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

* Re: [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory
  2015-08-11 13:59       ` Hans Verkuil
@ 2015-08-11 14:04         ` Laurent Pinchart
  0 siblings, 0 replies; 23+ messages in thread
From: Laurent Pinchart @ 2015-08-11 14:04 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Junghak Sung, linux-media, mchehab, sakari.ailus, pawel,
	inki.dae, sw0312.kim, nenggun.kim, sangbae90.lee, rany.kwon

Hi Hans,

On Tuesday 11 August 2015 15:59:35 Hans Verkuil wrote:
> On 08/11/15 15:56, Laurent Pinchart wrote:
> > Hijacking this e-mail thread a bit, would it make sense for the new
> > vb2-core to support different memory allocation for different planes ?
> > I'm foreseeing use cases for buffers that bundle image data with
> > meta-data, where image data should be captured to a dma-buf imported
> > buffer, but meta-data doesn't need to be shared. In that case it wouldn't
> > be easy for userspace to find a dma-buf provider for the meta-data
> > buffers in order to import all planes. Being able to use dma-buf import
> > for the image plane(s) and mmap for the meta-data plane would be easier.
> 
> Yes, that would make sense, but I'd postpone that until someone actually
> needs it.

I might need it soon. Looks like my cunning plan to let someone else implement 
it failed ;-)

> The biggest hurdle would be how to adapt the V4L2 API to this, and not the
> actual vb2 core code.

Changes will be needed in both, but I agree that in-kernel changes should be 
less of a hassle.

-- 
Regards,

Laurent Pinchart


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

end of thread, other threads:[~2015-08-11 14:03 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-31  8:44 [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Junghak Sung
2015-07-31  8:44 ` [RFC PATCH v2 1/5] media: videobuf2: Rename videobuf2-core to videobuf2-v4l2 Junghak Sung
2015-08-10  8:06   ` Hans Verkuil
2015-07-31  8:44 ` [RFC PATCH v2 2/5] media: videobuf2: Restructurng struct vb2_buffer for common use Junghak Sung
2015-07-31  8:44 ` [RFC PATCH v2 3/5] media: videobuf2: Divide videobuf2-core into 2 parts Junghak Sung
2015-08-10 12:07   ` Hans Verkuil
2015-08-10 12:55     ` Mauro Carvalho Chehab
2015-08-10 13:38       ` Hans Verkuil
2015-08-11 13:51         ` Laurent Pinchart
2015-07-31  8:44 ` [RFC PATCH v2 4/5] media: videobuf2: Define vb2_buf_type and vb2_memory Junghak Sung
2015-08-10  8:22   ` Hans Verkuil
2015-08-11  2:19     ` Junghak Sung
2015-08-11  6:32       ` Hans Verkuil
2015-08-11 13:56     ` Laurent Pinchart
2015-08-11 13:59       ` Hans Verkuil
2015-08-11 14:04         ` Laurent Pinchart
2015-07-31  8:44 ` [RFC PATCH v2 5/5] media: videobuf2: Modify prefix for VB2 functions Junghak Sung
2015-08-10  8:31 ` [RFC PATCH v2 0/5] Refactoring Videobuf2 for common use Hans Verkuil
2015-08-10  9:32   ` Mauro Carvalho Chehab
2015-08-10 10:11     ` Hans Verkuil
2015-08-10 10:49       ` Mauro Carvalho Chehab
2015-08-10 11:44         ` Hans Verkuil
2015-08-11  1:37           ` Junghak Sung

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).