]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - Documentation/gpu/drm-uapi.rst
drm: update todo.rst
[thirdparty/kernel/stable.git] / Documentation / gpu / drm-uapi.rst
CommitLineData
22554020 1===================
ca00c2b9
JN
2Userland interfaces
3===================
4
5The DRM core exports several interfaces to applications, generally
6intended to be used through corresponding libdrm wrapper functions. In
7addition, drivers export device-specific interfaces for use by userspace
8drivers & device-aware applications through ioctls and sysfs files.
9
10External interfaces include: memory mapping, context management, DMA
11operations, AGP management, vblank control, fence management, memory
12management, and output management.
13
14Cover generic ioctls and sysfs layout here. We only need high-level
15info, since man pages should cover the rest.
16
a3257256
SV
17libdrm Device Lookup
18====================
19
20.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
21 :doc: getunique and setversion story
22
3b96a0b1 23
b93658f8
SV
24.. _drm_primary_node:
25
3b96a0b1
SV
26Primary Nodes, DRM Master and Authentication
27============================================
28
29.. kernel-doc:: drivers/gpu/drm/drm_auth.c
30 :doc: master and authentication
31
32.. kernel-doc:: drivers/gpu/drm/drm_auth.c
33 :export:
34
35.. kernel-doc:: include/drm/drm_auth.h
36 :internal:
37
bcb32b69
SV
38Open-Source Userspace Requirements
39==================================
40
0d42204f
SV
41The DRM subsystem has stricter requirements than most other kernel subsystems on
42what the userspace side for new uAPI needs to look like. This section here
43explains what exactly those requirements are, and why they exist.
44
45The short summary is that any addition of DRM uAPI requires corresponding
46open-sourced userspace patches, and those patches must be reviewed and ready for
47merging into a suitable and canonical upstream project.
48
49GFX devices (both display and render/GPU side) are really complex bits of
50hardware, with userspace and kernel by necessity having to work together really
51closely. The interfaces, for rendering and modesetting, must be extremely wide
52and flexible, and therefore it is almost always impossible to precisely define
53them for every possible corner case. This in turn makes it really practically
54infeasible to differentiate between behaviour that's required by userspace, and
55which must not be changed to avoid regressions, and behaviour which is only an
56accidental artifact of the current implementation.
57
58Without access to the full source code of all userspace users that means it
59becomes impossible to change the implementation details, since userspace could
60depend upon the accidental behaviour of the current implementation in minute
61details. And debugging such regressions without access to source code is pretty
62much impossible. As a consequence this means:
63
64- The Linux kernel's "no regression" policy holds in practice only for
65 open-source userspace of the DRM subsystem. DRM developers are perfectly fine
66 if closed-source blob drivers in userspace use the same uAPI as the open
67 drivers, but they must do so in the exact same way as the open drivers.
68 Creative (ab)use of the interfaces will, and in the past routinely has, lead
69 to breakage.
70
71- Any new userspace interface must have an open-source implementation as
72 demonstration vehicle.
73
74The other reason for requiring open-source userspace is uAPI review. Since the
75kernel and userspace parts of a GFX stack must work together so closely, code
76review can only assess whether a new interface achieves its goals by looking at
77both sides. Making sure that the interface indeed covers the use-case fully
78leads to a few additional requirements:
79
80- The open-source userspace must not be a toy/test application, but the real
81 thing. Specifically it needs to handle all the usual error and corner cases.
82 These are often the places where new uAPI falls apart and hence essential to
83 assess the fitness of a proposed interface.
84
85- The userspace side must be fully reviewed and tested to the standards of that
86 userspace project. For e.g. mesa this means piglit testcases and review on the
87 mailing list. This is again to ensure that the new interface actually gets the
88 job done.
89
90- The userspace patches must be against the canonical upstream, not some vendor
91 fork. This is to make sure that no one cheats on the review and testing
92 requirements by doing a quick fork.
93
94- The kernel patch can only be merged after all the above requirements are met,
95 but it **must** be merged **before** the userspace patches land. uAPI always flows
96 from the kernel, doing things the other way round risks divergence of the uAPI
97 definitions and header files.
98
99These are fairly steep requirements, but have grown out from years of shared
100pain and experience with uAPI added hastily, and almost always regretted about
101just as fast. GFX devices change really fast, requiring a paradigm shift and
102entire new set of uAPI interfaces every few years at least. Together with the
103Linux kernel's guarantee to keep existing userspace running for 10+ years this
104is already rather painful for the DRM subsystem, with multiple different uAPIs
105for the same thing co-existing. If we add a few more complete mistakes into the
106mix every year it would be entirely unmanageable.
107
b93658f8
SV
108.. _drm_render_node:
109
ca00c2b9 110Render nodes
22554020 111============
ca00c2b9
JN
112
113DRM core provides multiple character-devices for user-space to use.
114Depending on which device is opened, user-space can perform a different
115set of operations (mainly ioctls). The primary node is always created
116and called card<num>. Additionally, a currently unused control node,
117called controlD<num> is also created. The primary node provides all
118legacy operations and historically was the only interface used by
119userspace. With KMS, the control node was introduced. However, the
120planned KMS control interface has never been written and so the control
121node stays unused to date.
122
123With the increased use of offscreen renderers and GPGPU applications,
124clients no longer require running compositors or graphics servers to
125make use of a GPU. But the DRM API required unprivileged clients to
126authenticate to a DRM-Master prior to getting GPU access. To avoid this
127step and to grant clients GPU access without authenticating, render
128nodes were introduced. Render nodes solely serve render clients, that
129is, no modesetting or privileged ioctls can be issued on render nodes.
130Only non-global rendering commands are allowed. If a driver supports
131render nodes, it must advertise it via the DRIVER_RENDER DRM driver
132capability. If not supported, the primary node must be used for render
133clients together with the legacy drmAuth authentication procedure.
134
135If a driver advertises render node support, DRM core will create a
136separate render node called renderD<num>. There will be one render node
137per device. No ioctls except PRIME-related ioctls will be allowed on
138this node. Especially GEM_OPEN will be explicitly prohibited. Render
139nodes are designed to avoid the buffer-leaks, which occur if clients
140guess the flink names or mmap offsets on the legacy interface.
141Additionally to this basic interface, drivers must mark their
142driver-dependent render-only ioctls as DRM_RENDER_ALLOW so render
143clients can use them. Driver authors must be careful not to allow any
144privileged ioctls on render nodes.
145
146With render nodes, user-space can now control access to the render node
147via basic file-system access-modes. A running graphics server which
148authenticates clients on the privileged primary/legacy node is no longer
149required. Instead, a client can open the render node and is immediately
150granted GPU access. Communication between clients (or servers) is done
151via PRIME. FLINK from render node to legacy node is not supported. New
152clients must not use the insecure FLINK interface.
153
154Besides dropping all modeset/global ioctls, render nodes also drop the
155DRM-Master concept. There is no reason to associate render clients with
156a DRM-Master as they are independent of any graphics server. Besides,
157they must work without any running master, anyway. Drivers must be able
158to run without a master object if they support render nodes. If, on the
159other hand, a driver requires shared state between clients which is
160visible to user-space and accessible beyond open-file boundaries, they
161cannot support render nodes.
162
a8182863
SV
163
164Testing and validation
165======================
166
75ac4953 167Validating changes with IGT
a8182863 168---------------------------
75ac4953
TV
169
170There's a collection of tests that aims to cover the whole functionality of
171DRM drivers and that can be used to check that changes to DRM drivers or the
172core don't regress existing functionality. This test suite is called IGT and
173its code can be found in https://cgit.freedesktop.org/drm/igt-gpu-tools/.
174
175To build IGT, start by installing its build dependencies. In Debian-based
176systems::
177
178 # apt-get build-dep intel-gpu-tools
179
180And in Fedora-based systems::
181
182 # dnf builddep intel-gpu-tools
183
184Then clone the repository::
185
186 $ git clone git://anongit.freedesktop.org/drm/igt-gpu-tools
187
188Configure the build system and start the build::
189
190 $ cd igt-gpu-tools && ./autogen.sh && make -j6
191
192Download the piglit dependency::
193
194 $ ./scripts/run-tests.sh -d
195
196And run the tests::
197
198 $ ./scripts/run-tests.sh -t kms -t core -s
199
200run-tests.sh is a wrapper around piglit that will execute the tests matching
201the -t options. A report in HTML format will be available in
202./results/html/index.html. Results can be compared with piglit.
203
a8182863
SV
204Display CRC Support
205-------------------
206
207.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
208 :doc: CRC ABI
209
760f71e7
SV
210.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
211 :export:
212
0cad7f71
SV
213Debugfs Support
214---------------
215
216.. kernel-doc:: include/drm/drm_debugfs.h
217 :internal:
218
219.. kernel-doc:: drivers/gpu/drm/drm_debugfs.c
220 :export:
221
ca00c2b9 222VBlank event handling
22554020 223=====================
ca00c2b9
JN
224
225The DRM core exposes two vertical blank related ioctls:
226
227DRM_IOCTL_WAIT_VBLANK
228 This takes a struct drm_wait_vblank structure as its argument, and
229 it is used to block or request a signal when a specified vblank
230 event occurs.
231
232DRM_IOCTL_MODESET_CTL
233 This was only used for user-mode-settind drivers around modesetting
234 changes to allow the kernel to update the vblank interrupt after
235 mode setting, since on many devices the vertical blank counter is
236 reset to 0 at some point during modeset. Modern drivers should not
237 call this any more since with kernel mode setting it is a no-op.