blob: 906d1532efada60e2191c2383e1ef29d6d8268c9 [file] [log] [blame]
Daniel Vetter868c97a2016-12-09 19:53:05 +01001Buffer Sharing and Synchronization
2==================================
3
4The dma-buf subsystem provides the framework for sharing buffers for
5hardware (DMA) access across multiple device drivers and subsystems, and
6for synchronizing asynchronous hardware access.
7
8This is used, for example, by drm "prime" multi-GPU support, but is of
9course not limited to GPU use cases.
10
11The three main components of this are: (1) dma-buf, representing a
12sg_table and exposed to userspace as a file descriptor to allow passing
13between devices, (2) fence, which provides a mechanism to signal when
14one device as finished access, and (3) reservation, which manages the
15shared or exclusive fence(s) associated with the buffer.
16
17Shared DMA Buffers
18------------------
19
Daniel Vetter2904a8c2016-12-09 19:53:07 +010020This document serves as a guide to device-driver writers on what is the dma-buf
21buffer sharing API, how to use it for exporting and using shared buffers.
22
23Any device driver which wishes to be a part of DMA buffer sharing, can do so as
24either the 'exporter' of buffers, or the 'user' or 'importer' of buffers.
25
26Say a driver A wants to use buffers created by driver B, then we call B as the
27exporter, and A as buffer-user/importer.
28
29The exporter
30
31 - implements and manages operations in :c:type:`struct dma_buf_ops
32 <dma_buf_ops>` for the buffer,
33 - allows other users to share the buffer by using dma_buf sharing APIs,
34 - manages the details of buffer allocation, wrapped int a :c:type:`struct
35 dma_buf <dma_buf>`,
36 - decides about the actual backing storage where this allocation happens,
37 - and takes care of any migration of scatterlist - for all (shared) users of
38 this buffer.
39
40The buffer-user
41
42 - is one of (many) sharing users of the buffer.
43 - doesn't need to worry about how the buffer is allocated, or where.
44 - and needs a mechanism to get access to the scatterlist that makes up this
45 buffer in memory, mapped into its own address space, so it can access the
46 same area of memory. This interface is provided by :c:type:`struct
47 dma_buf_attachment <dma_buf_attachment>`.
48
49Basic Operation and Device DMA Access
50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
52.. kernel-doc:: drivers/dma-buf/dma-buf.c
53 :doc: dma buf device access
54
55Kernel Functions and Structures Reference
56~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57
Daniel Vetter868c97a2016-12-09 19:53:05 +010058.. kernel-doc:: drivers/dma-buf/dma-buf.c
59 :export:
60
61.. kernel-doc:: include/linux/dma-buf.h
62 :internal:
63
64Reservation Objects
65-------------------
66
67.. kernel-doc:: drivers/dma-buf/reservation.c
68 :doc: Reservation Object Overview
69
70.. kernel-doc:: drivers/dma-buf/reservation.c
71 :export:
72
73.. kernel-doc:: include/linux/reservation.h
74 :internal:
75
76DMA Fences
77----------
78
79.. kernel-doc:: drivers/dma-buf/dma-fence.c
80 :export:
81
82.. kernel-doc:: include/linux/dma-fence.h
83 :internal:
84
85Seqno Hardware Fences
86~~~~~~~~~~~~~~~~~~~~~
87
88.. kernel-doc:: drivers/dma-buf/seqno-fence.c
89 :export:
90
91.. kernel-doc:: include/linux/seqno-fence.h
92 :internal:
93
94DMA Fence Array
95~~~~~~~~~~~~~~~
96
97.. kernel-doc:: drivers/dma-buf/dma-fence-array.c
98 :export:
99
100.. kernel-doc:: include/linux/dma-fence-array.h
101 :internal:
102
103DMA Fence uABI/Sync File
104~~~~~~~~~~~~~~~~~~~~~~~~
105
106.. kernel-doc:: drivers/dma-buf/sync_file.c
107 :export:
108
109.. kernel-doc:: include/linux/sync_file.h
110 :internal:
111