Lines Matching refs:to
8 This document serves as a guide to device-driver writers on what is the dma-buf
9 buffer sharing API, how to use it for exporting and using shared buffers.
11 Any device driver which wishes to be a part of DMA buffer sharing, can do so as
14 Say a driver A wants to use buffers created by driver B, then we call B as the
19 - allows other users to share the buffer by using dma_buf sharing APIs,
27 - doesn't need to worry about how the buffer is allocated, or where.
28 - needs a mechanism to get access to the scatterlist that makes up this buffer
37 1. Exporter announces that it wishes to export a buffer
39 passes it around to potential buffer-users based on use case
40 3. Each buffer-user 'connects' itself to the buffer
41 4. When needed, buffer-user requests access to the buffer from exporter
42 5. When finished with its use, the buffer-user notifies end-of-DMA to exporter
49 The buffer exporter announces its wish to export a buffer. In this, it
60 returns a pointer to the same. It also associates an anonymous file with this
61 buffer, so it can be exported. On failure to allocate the dma_buf object,
64 'exp_name' in struct dma_buf_export_info is the name of exporter - to
65 facilitate information while debugging. It is set to KBUILD_MODNAME by
66 default, so exporters don't have to provide a specific name, if they don't
67 wish to.
73 2. Userspace gets a handle to pass around to potential buffer-users
75 Userspace entity requests for a file-descriptor (fd) which is a handle to the
85 3. Each buffer-user 'connects' itself to the buffer
87 Each buffer-user now gets a reference to the buffer, using the fd passed to
93 This API will return a reference to the dma_buf, and increment refcount for
96 After this, the buffer-user needs to attach its device with the buffer, which
97 helps the exporter to know of device buffer constraints.
103 This API returns reference to an attachment structure, which is then used
107 The dma-buf sharing framework does the bookkeeping bits related to managing
108 the list of all attachments to a buffer.
110 Until this stage, the buffer-exporter has the option to choose not to actually
112 to request use of buffer for allocation.
115 4. When needed, buffer-user requests access to the buffer
117 Whenever a buffer-user wants to use the buffer for any DMA, it asks for
118 access to the buffer using dma_buf_map_attachment API. At least one attach to
125 This is a wrapper to dma_buf->ops->map_dma_buf operation, which hides the
136 If this is being called for the first time, the exporter can now choose to
141 Based on enum dma_data_direction, it might be possible to have multiple users
143 that the exporter might wish to make available to buffer-users.
148 5. When finished, the buffer-user notifies end-of-DMA to exporter
150 Once the DMA for the current buffer-user is over, it signals 'end-of-DMA' to
157 This is a wrapper to dma_buf->ops->unmap_dma_buf() operation, which hides the
184 - Then, the buffer-user returns the buffer reference to exporter.
192 operation related to this fd is called. It calls the dmabuf->ops->release()
197 The attach-detach calls allow the exporter to figure out backing-storage
203 to allow just-in-time backing of storage, and migration mid-way through a
210 another new buffer-user intends to attach itself to this buffer, it might
219 exporter could potentially move the buffer to the stricter backing-storage,
224 buffer-user device as requested, dma_buf_attach() would return an error to
228 If the exporter chooses not to allow an attach() operation once a
231 Kernel cpu access to a dma-buf buffer object
234 The motivation to allow cpu access from the kernel to a dma-buf object from the
236 - fallback operations, e.g. if the devices is connected to a usb bus and the
237 kernel needs to shuffle the data around first before sending it away.
241 opengl drivers that expect to still use all the existing upload/download
244 Access to a dma_buf from the kernel context involves three steps:
255 context, it needs to notify the exporter of the access that is about to
263 This allows the exporter to ensure that the memory is actually available for
264 cpu access - the exporter might need to allocate or swap-in and pin the
265 backing storage. The exporter also needs to ensure that cpu access is
267 direction can be used by the exporter to optimize the cache flushing, i.e.
269 write) might return stale or even bogus data (e.g. when the exporter needs to
270 copy the data to temporary storage).
277 an api similar to kmap. Accessing a dma_buf is done in aligned chunks of
278 PAGE_SIZE size. Before accessing a chunk it needs to be mapped, which returns
279 a pointer in kernel virtual address space. Afterwards the chunk needs to be
281 and unmapped, i.e. the importer does not need to call begin_cpu_access again
290 the callback) is allowed to block when using these.
301 undefined. If the range is not PAGE_SIZE aligned, kmap needs to succeed on
305 Note that these calls need to always succeed. The exporter needs to complete
317 runs out of vmalloc space. Fallback to kmap should be implemented. Note that
326 it needs to announce this to the exporter (to facilitate cache flushing and
339 Being able to mmap an export dma-buf buffer object has 2 main use-cases:
347 the need to handle this specially in userspace frameworks for buffer sharing
348 it's ideal if the dma_buf fd itself can be used to access the backing storage
352 rather similar to dma-buf from a userspace consumer side with using fds as
353 handles, too). So it's beneficial to support this in a similar fashion on
354 dma-buf to have a good transition path for existing Android userspace.
360 Similar to the motivation for kernel cpu access it is again important that
364 X, and other drivers is huge, and reworking them to use a different way to
369 subsystems shows that no driver seems to do any nefarious thing like syncing
372 adding interfaces to intercept pagefaults and allow pte shootdowns would
379 If the importing subsystem simply provides a special-purpose mmap call to set
387 exporter hence does not need to duplicate this check.
390 userspace, the exporter needs to set up a coherent mapping. If that's not
391 possible, it needs to fake coherency by manually shooting down ptes when
393 dma_buf files share the same anon inode, hence the exporter needs to replace
399 If the above shootdown dance turns out to be too expensive in certain
406 Synchronization is an orthogonal issue to sharing the backing storage of a
408 mentioned here because many people seem to want something like this, but if
413 Other Interfaces Exposed to Userspace on the dma-buf FD
417 with offset=0 and whence=SEEK_END|SEEK_SET. SEEK_SET is supported to allow
422 cases. Userspace can use this to detect support for discovering the dma-buf
431 - In order to avoid fd leaks on exec, the FD_CLOEXEC flag must be set
434 access to buffers, via the leaked fd, to which it should otherwise
443 To avoid this problem, userspace must have a way to request O_CLOEXEC
445 the exporting driver to create a dmabuf fd must provide a way to let
446 userspace control setting of O_CLOEXEC flag passed in to dma_buf_fd().
448 - If an exporter needs to manually flush caches and hence needs to fake
449 coherency for mmap support, it needs to be able to zap all the ptes pointing
451 with the struct file stored in vma->vm_file to do that with the function
455 Hence exporters need to setup their own file (and address_space) association