1<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>struct vb2_mem_ops</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Device Drivers"><link rel="up" href="mediadev.html#id-1.8.2" title="Video2Linux devices"><link rel="prev" href="API-struct-v4l2-subdev-pad-ops.html" title="struct v4l2_subdev_pad_ops"><link rel="next" href="API-struct-vb2-plane.html" title="struct vb2_plane"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">struct vb2_mem_ops</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-struct-v4l2-subdev-pad-ops.html">Prev</a> </td><th width="60%" align="center">Video2Linux devices</th><td width="20%" align="right"> <a accesskey="n" href="API-struct-vb2-plane.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-struct-vb2-mem-ops"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>struct vb2_mem_ops — 
2  memory handling/memory allocator operations
3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="programlisting">
4struct vb2_mem_ops {
5  void *(* alloc) (void *alloc_ctx, unsigned long size,enum dma_data_direction dma_dir,gfp_t gfp_flags);
6  void (* put) (void *buf_priv);
7  struct dma_buf *(* get_dmabuf) (void *buf_priv, unsigned long flags);
8  void *(* get_userptr) (void *alloc_ctx, unsigned long vaddr,unsigned long size,enum dma_data_direction dma_dir);
9  void (* put_userptr) (void *buf_priv);
10  void (* prepare) (void *buf_priv);
11  void (* finish) (void *buf_priv);
12  void *(* attach_dmabuf) (void *alloc_ctx, struct dma_buf *dbuf,unsigned long size,enum dma_data_direction dma_dir);
13  void (* detach_dmabuf) (void *buf_priv);
14  int (* map_dmabuf) (void *buf_priv);
15  void (* unmap_dmabuf) (void *buf_priv);
16  void *(* vaddr) (void *buf_priv);
17  void *(* cookie) (void *buf_priv);
18  unsigned int	(* num_users) (void *buf_priv);
19  int (* mmap) (void *buf_priv, struct vm_area_struct *vma);
20};  </pre></div><div class="refsect1"><a name="id-1.8.2.88.5"></a><h2>Members</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term">alloc</span></dt><dd><p>
21allocate video memory and, optionally, allocator private data,
22return NULL on failure or a pointer to allocator private,
23per-buffer data on success; the returned private structure
24will then be passed as buf_priv argument to other ops in this
25structure. Additional gfp_flags to use when allocating the
26are also passed to this operation. These flags are from the
27gfp_flags field of vb2_queue.
28      </p></dd><dt><span class="term">put</span></dt><dd><p>
29inform the allocator that the buffer will no longer be used;
30usually will result in the allocator freeing the buffer (if
31no other users of this buffer are present); the buf_priv
32argument is the allocator private per-buffer structure
33previously returned from the alloc callback.
34      </p></dd><dt><span class="term">get_dmabuf</span></dt><dd><p>
35acquire userspace memory for a hardware operation; used for
36DMABUF memory types.
37      </p></dd><dt><span class="term">get_userptr</span></dt><dd><p>
38acquire userspace memory for a hardware operation; used for
39USERPTR memory types; vaddr is the address passed to the
40videobuf layer when queuing a video buffer of USERPTR type;
41should return an allocator private per-buffer structure
42associated with the buffer on success, NULL on failure;
43the returned private structure will then be passed as buf_priv
44argument to other ops in this structure.
45      </p></dd><dt><span class="term">put_userptr</span></dt><dd><p>
46inform the allocator that a USERPTR buffer will no longer
47be used.
48      </p></dd><dt><span class="term">prepare</span></dt><dd><p>
49called every time the buffer is passed from userspace to the
50driver, useful for cache synchronisation, optional.
51      </p></dd><dt><span class="term">finish</span></dt><dd><p>
52called every time the buffer is passed back from the driver
53to the userspace, also optional.
54      </p></dd><dt><span class="term">attach_dmabuf</span></dt><dd><p>
55attach a shared struct dma_buf for a hardware operation;
56used for DMABUF memory types; alloc_ctx is the alloc context
57dbuf is the shared dma_buf; returns NULL on failure;
58allocator private per-buffer structure on success;
59this needs to be used for further accesses to the buffer.
60      </p></dd><dt><span class="term">detach_dmabuf</span></dt><dd><p>
61inform the exporter of the buffer that the current DMABUF
62buffer is no longer used; the buf_priv argument is the
63allocator private per-buffer structure previously returned
64from the attach_dmabuf callback.
65      </p></dd><dt><span class="term">map_dmabuf</span></dt><dd><p>
66request for access to the dmabuf from allocator; the allocator
67of dmabuf is informed that this driver is going to use the
68dmabuf.
69      </p></dd><dt><span class="term">unmap_dmabuf</span></dt><dd><p>
70releases access control to the dmabuf - allocator is notified
71that this driver is done using the dmabuf for now.
72      </p></dd><dt><span class="term">vaddr</span></dt><dd><p>
73return a kernel virtual address to a given memory buffer
74associated with the passed private structure or NULL if no
75such mapping exists.
76      </p></dd><dt><span class="term">cookie</span></dt><dd><p>
77return allocator specific cookie for a given memory buffer
78associated with the passed private structure or NULL if not
79available.
80      </p></dd><dt><span class="term">num_users</span></dt><dd><p>
81return the current number of users of a memory buffer;
82return 1 if the videobuf layer (or actually the driver using
83it) is the only user.
84      </p></dd><dt><span class="term">mmap</span></dt><dd><p>
85setup a userspace mapping for a given memory buffer under
86the provided virtual memory region.
87      </p></dd></dl></div></div><div class="refsect1"><a name="id-1.8.2.88.6"></a><h2>Required ops for USERPTR types</h2><p>
88   get_userptr, put_userptr.
89</p></div><div class="refsect1"><a name="id-1.8.2.88.7"></a><h2>Required ops for MMAP types</h2><p>
90   alloc, put, num_users, mmap.
91   Required ops for read/write access types: alloc, put, num_users, vaddr.
92</p></div><div class="refsect1"><a name="id-1.8.2.88.8"></a><h2>Required ops for DMABUF types</h2><p>
93   attach_dmabuf, detach_dmabuf, map_dmabuf,
94   unmap_dmabuf.
95</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-struct-v4l2-subdev-pad-ops.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="mediadev.html#id-1.8.2">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-struct-vb2-plane.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">struct v4l2_subdev_pad_ops</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">struct vb2_plane</span></td></tr></table></div></body></html>
96