Skip to content

RFC vb2: Handle user cache hints, allow drivers to choose cache coherency

Sakari Ailus dri-devel linux-media 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 RFC Latest18 patches 8 repliesIn review
  2. v3 RFC14 patches 0 repliesSuperseded

Changes in v4 from the cover letter

- Document V4L2_BUF_FLAG_NO_CACHE_SYNC flag behaviour for QBUF and DQBUF for CAPTURE and OUTPUT buffers.

- Set queue dma_attrs DMA_ATTR_NON_CONSISTENT flag for omap3isp.

- Put dma_sgt in vb2_dc_buf in order to avoid allocating and releasing it separately. It's generally needed anyway.

- Buffer preparation DMA direction is generally DMA_TO_DEVICE for both CAPTURE and OUTPUT buffers: V4L2 does not guarantee that the user space could not write to capture buffers as well.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/18vb2: Rename confusingly named internal buffer preparation functionsdrivers/media/v4l2-core/videobuf2-core.c+9 -90 replies
2/18vb2: Move buffer cache synchronisation to prepare from queuedrivers/media/v4l2-core/videobuf2-core.c+12 -80 replies
3/18vb2: Move cache synchronisation from buffer done to dqbuf handlerdrivers/media/v4l2-core/videobuf2-core.c+4 -51 reply
4/18v4l: Unify cache management hint buffer flagsDocumentation/media/uapi/v4l/buffer.rst Documentation/media/uapi/v4l/vidioc-prepare-buf.rst include/trace/events/v4l2.h +1 more+17 -220 replies
5/18vb2: Anticipate queue specific DMA attributes for USERPTR buffersdrivers/media/v4l2-core/videobuf2-core.c drivers/media/v4l2-core/videobuf2-dma-contig.c drivers/media/v4l2-core/videobuf2-dma-sg.c +2 more+9 -50 replies
6/18vb2: dma-contig: Assign DMA attrs for a buffer unconditionallydrivers/media/v4l2-core/videobuf2-dma-contig.c+1 -20 replies
7/18vb2: dma-contig: Remove redundant sgt_base fielddrivers/media/v4l2-core/videobuf2-dma-contig.c+13 -121 reply
8/18vb2: dma-contig: Don't warn on failure in obtaining scatterlistdrivers/media/v4l2-core/videobuf2-dma-contig.c+2 -40 replies
9/18vb2: dma-contig: Allocate sgt as part of struct vb2_dc_bufdrivers/media/v4l2-core/videobuf2-dma-contig.c+32 -510 replies
10/18vb2: dma-contig: Fix DMA attribute and cache managementdrivers/media/v4l2-core/videobuf2-dma-contig.c+72 -222 replies
11/18vb2: dma-contig: Add WARN_ON_ONCE() to check for potential bugsdrivers/media/v4l2-core/videobuf2-dma-contig.c+4 -40 replies
12/18vb2: dma-sg: Let drivers decide DMA attrs of MMAP and USERPTR bufsdrivers/media/v4l2-core/videobuf2-dma-sg.c+62 -190 replies
13/18vb2: Don't sync cache for a buffer if so requesteddrivers/media/v4l2-core/videobuf2-core.c drivers/media/v4l2-core/videobuf2-v4l2.c include/media/videobuf2-core.h+97 -412 replies
14/18vb2: Improve struct vb2_mem_ops documentation; alloc and put are for MMAPinclude/media/videobuf2-core.h+10 -100 replies
15/18vb2: Dma direction is always DMA_TO_DEVICE in buffer preparationdrivers/media/v4l2-core/videobuf2-dma-contig.c drivers/media/v4l2-core/videobuf2-dma-sg.c+2 -20 replies
16/18vb2: Do sync plane cache only for CAPTURE buffers in finish memopdrivers/media/v4l2-core/videobuf2-dma-contig.c drivers/media/v4l2-core/videobuf2-dma-sg.c+6 -40 replies
17/18docs-rst: Document precise V4L2_BUF_FLAG_NO_CACHE_SYNC flag behaviourDocumentation/media/uapi/v4l/buffer.rst+21 -00 replies
18/18v4l: Use non-consistent DMA mappings for hardware that deserves itdrivers/media/platform/omap3isp/ispvideo.c+1 -00 replies

Reviews trailers per patch

9 of 18 patches have a Reviewed-by or Acked-by.

PatchHans VerkuilLaurent Pinchart
1/18A-b R-b
2/18A-b
3/18A-b
4/18A-b
5/18
6/18
7/18A-b
8/18A-b R-b
9/18
10/18
11/18A-b
12/18
13/18A-b
14/18A-b R-b
15/18
16/18
17/18
18/18

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [RFC v4 00/18] vb2: Handle user cache hints, allow drivers to choose cache coherency

Hello,

This is a rebased and partially reworked version of the vb2 cache hints support patch series posted by first myself, then Laurent and then myself again.

I'm still posting this as RFC primarily because more testing and driver changes will be needed. In particular, a lot of platform drivers assume non-coherent memory but are not properly labelled as such.

Please see the end of the message for detailed changes.

This set unifies the cache coherency hint flags and corrects cache management in videobuf2 dma-contig and dma-sg memtype implementation. The support for non-coherent memory is completed: support for MMAP buffers is added and begin_cpu_access and end_cpu_access functions are added to DMA ops.

Comments are welcome.

changes since RFC v3:

- Document V4L2_BUF_FLAG_NO_CACHE_SYNC flag behaviour for QBUF and DQBUF for CAPTURE and OUTPUT buffers.

- Set queue dma_attrs DMA_ATTR_NON_CONSISTENT flag for omap3isp.

- Put dma_sgt in vb2_dc_buf in order to avoid allocating and releasing it separately. It's generally needed anyway.

- Buffer preparation DMA direction is generally DMA_TO_DEVICE for both CAPTURE and OUTPUT buffers: V4L2 does not guarantee that the user space could not write to capture buffers as well.

Documentation/DMA-API.txt:

- Before reading values that have been written by DMA from the device (use the DMA_FROM_DEVICE direction)
- After writing values that will be written to the device using DMA (use the DMA_TO_DEVICE) direction
- before *and* after handing memory to the device if the memory is DMA_BIDIRECTIONAL

Cache maintenance can also be skipped for OUTPUT buffers in buffer finish as the hardware did not write to the buffer.

changes since RFC v2:

- Nicer looking tests for the need for syncing.

- Also set DMA attributes for USERPTR buffers.

- Unconditionally assign buf->attrs for MMAP buffers.

- Don't call vb2_dc_get_base_sgt() until buf->dev is set.

- Provide {begin,end}_cpu_access() dmabuf ops for cache management.

- Make similar changes to dma-sg memops to support DMA attributes.

Sakari Ailus (13):
vb2: Rename confusingly named internal buffer preparation functions
vb2: Move buffer cache synchronisation to prepare from queue
vb2: Move cache synchronisation from buffer done to dqbuf handler
v4l: Unify cache management hint buffer flags
vb2: Anticipate queue specific DMA attributes for USERPTR buffers
vb2: dma-contig: Assign DMA attrs for a buffer unconditionally
vb2: dma-contig: Remove redundant sgt_base field
vb2: dma-contig: Don't warn on failure in obtaining scatterlist
vb2: dma-contig: Move vb2_dc_get_base_sgt() up
vb2: dma-contig: Fix DMA attribute and cache management
vb2: dma-contig: Add WARN_ON_ONCE() to check for potential bugs
vb2: dma-sg: Let drivers decide DMA attrs of MMAP and USERPTR bufs
vb2: Improve struct vb2_mem_ops documentation; alloc and put are for
MMAP

Samu Onkalo (1):
vb2: Don't sync cache for a buffer if so requested

 Documentation/media/uapi/v4l/buffer.rst            |  24 ++--
 .../media/uapi/v4l/vidioc-prepare-buf.rst          |   5 +-
 drivers/media/v4l2-core/videobuf2-core.c           | 129 ++++++++++++++-------
 drivers/media/v4l2-core/videobuf2-dma-contig.c     | 120 ++++++++++++-------
 drivers/media/v4l2-core/videobuf2-dma-sg.c         |  47 ++++++--
 drivers/media/v4l2-core/videobuf2-v4l2.c           |  14 ++-
 drivers/media/v4l2-core/videobuf2-vmalloc.c        |   3 +-
 include/media/videobuf2-core.h                     |  46 +++++---
 include/trace/events/v4l2.h                        |   3 +-
 include/uapi/linux/videodev2.h                     |   7 +-
 10 files changed, 263 insertions(+), 135 deletions(-)
Signature · 43 lines
Regards,
Sakari



Sakari Ailus (17):
  vb2: Rename confusingly named internal buffer preparation functions
  vb2: Move buffer cache synchronisation to prepare from queue
  vb2: Move cache synchronisation from buffer done to dqbuf handler
  v4l: Unify cache management hint buffer flags
  vb2: Anticipate queue specific DMA attributes for USERPTR buffers
  vb2: dma-contig: Assign DMA attrs for a buffer unconditionally
  vb2: dma-contig: Remove redundant sgt_base field
  vb2: dma-contig: Don't warn on failure in obtaining scatterlist
  vb2: dma-contig: Allocate sgt as part of struct vb2_dc_buf
  vb2: dma-contig: Fix DMA attribute and cache management
  vb2: dma-contig: Add WARN_ON_ONCE() to check for potential bugs
  vb2: dma-sg: Let drivers decide DMA attrs of MMAP and USERPTR bufs
  vb2: Improve struct vb2_mem_ops documentation; alloc and put are for
    MMAP
  vb2: Dma direction is always DMA_TO_DEVICE in buffer preparation
  vb2: Do sync plane cache only for CAPTURE buffers in finish memop
  docs-rst: Document precise V4L2_BUF_FLAG_NO_CACHE_SYNC flag behaviour
  v4l: Use non-consistent DMA mappings for hardware that deserves it

Samu Onkalo (1):
  vb2: Don't sync cache for a buffer if so requested

 Documentation/media/uapi/v4l/buffer.rst            |  45 +++--
 .../media/uapi/v4l/vidioc-prepare-buf.rst          |   5 +-
 drivers/media/platform/omap3isp/ispvideo.c         |   1 +
 drivers/media/v4l2-core/videobuf2-core.c           | 122 ++++++++-----
 drivers/media/v4l2-core/videobuf2-dma-contig.c     | 191 ++++++++++++---------
 drivers/media/v4l2-core/videobuf2-dma-sg.c         |  85 ++++++---
 drivers/media/v4l2-core/videobuf2-v4l2.c           |  14 +-
 drivers/media/v4l2-core/videobuf2-vmalloc.c        |   3 +-
 include/media/videobuf2-core.h                     |  46 +++--
 include/trace/events/v4l2.h                        |   3 +-
 include/uapi/linux/videodev2.h                     |   7 +-
 11 files changed, 338 insertions(+), 184 deletions(-)

-- 
2.7.4