xref: /OK3568_Linux_fs/kernel/Documentation/gpu/drm-uapi.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. Copyright 2020 DisplayLink (UK) Ltd.
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun===================
4*4882a593SmuzhiyunUserland interfaces
5*4882a593Smuzhiyun===================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThe DRM core exports several interfaces to applications, generally
8*4882a593Smuzhiyunintended to be used through corresponding libdrm wrapper functions. In
9*4882a593Smuzhiyunaddition, drivers export device-specific interfaces for use by userspace
10*4882a593Smuzhiyundrivers & device-aware applications through ioctls and sysfs files.
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunExternal interfaces include: memory mapping, context management, DMA
13*4882a593Smuzhiyunoperations, AGP management, vblank control, fence management, memory
14*4882a593Smuzhiyunmanagement, and output management.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunCover generic ioctls and sysfs layout here. We only need high-level
17*4882a593Smuzhiyuninfo, since man pages should cover the rest.
18*4882a593Smuzhiyun
19*4882a593Smuzhiyunlibdrm Device Lookup
20*4882a593Smuzhiyun====================
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
23*4882a593Smuzhiyun   :doc: getunique and setversion story
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun.. _drm_primary_node:
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunPrimary Nodes, DRM Master and Authentication
29*4882a593Smuzhiyun============================================
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_auth.c
32*4882a593Smuzhiyun   :doc: master and authentication
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_auth.c
35*4882a593Smuzhiyun   :export:
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun.. kernel-doc:: include/drm/drm_auth.h
38*4882a593Smuzhiyun   :internal:
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunOpen-Source Userspace Requirements
41*4882a593Smuzhiyun==================================
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunThe DRM subsystem has stricter requirements than most other kernel subsystems on
44*4882a593Smuzhiyunwhat the userspace side for new uAPI needs to look like. This section here
45*4882a593Smuzhiyunexplains what exactly those requirements are, and why they exist.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunThe short summary is that any addition of DRM uAPI requires corresponding
48*4882a593Smuzhiyunopen-sourced userspace patches, and those patches must be reviewed and ready for
49*4882a593Smuzhiyunmerging into a suitable and canonical upstream project.
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunGFX devices (both display and render/GPU side) are really complex bits of
52*4882a593Smuzhiyunhardware, with userspace and kernel by necessity having to work together really
53*4882a593Smuzhiyunclosely.  The interfaces, for rendering and modesetting, must be extremely wide
54*4882a593Smuzhiyunand flexible, and therefore it is almost always impossible to precisely define
55*4882a593Smuzhiyunthem for every possible corner case. This in turn makes it really practically
56*4882a593Smuzhiyuninfeasible to differentiate between behaviour that's required by userspace, and
57*4882a593Smuzhiyunwhich must not be changed to avoid regressions, and behaviour which is only an
58*4882a593Smuzhiyunaccidental artifact of the current implementation.
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunWithout access to the full source code of all userspace users that means it
61*4882a593Smuzhiyunbecomes impossible to change the implementation details, since userspace could
62*4882a593Smuzhiyundepend upon the accidental behaviour of the current implementation in minute
63*4882a593Smuzhiyundetails. And debugging such regressions without access to source code is pretty
64*4882a593Smuzhiyunmuch impossible. As a consequence this means:
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun- The Linux kernel's "no regression" policy holds in practice only for
67*4882a593Smuzhiyun  open-source userspace of the DRM subsystem. DRM developers are perfectly fine
68*4882a593Smuzhiyun  if closed-source blob drivers in userspace use the same uAPI as the open
69*4882a593Smuzhiyun  drivers, but they must do so in the exact same way as the open drivers.
70*4882a593Smuzhiyun  Creative (ab)use of the interfaces will, and in the past routinely has, lead
71*4882a593Smuzhiyun  to breakage.
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun- Any new userspace interface must have an open-source implementation as
74*4882a593Smuzhiyun  demonstration vehicle.
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunThe other reason for requiring open-source userspace is uAPI review. Since the
77*4882a593Smuzhiyunkernel and userspace parts of a GFX stack must work together so closely, code
78*4882a593Smuzhiyunreview can only assess whether a new interface achieves its goals by looking at
79*4882a593Smuzhiyunboth sides. Making sure that the interface indeed covers the use-case fully
80*4882a593Smuzhiyunleads to a few additional requirements:
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun- The open-source userspace must not be a toy/test application, but the real
83*4882a593Smuzhiyun  thing. Specifically it needs to handle all the usual error and corner cases.
84*4882a593Smuzhiyun  These are often the places where new uAPI falls apart and hence essential to
85*4882a593Smuzhiyun  assess the fitness of a proposed interface.
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun- The userspace side must be fully reviewed and tested to the standards of that
88*4882a593Smuzhiyun  userspace project. For e.g. mesa this means piglit testcases and review on the
89*4882a593Smuzhiyun  mailing list. This is again to ensure that the new interface actually gets the
90*4882a593Smuzhiyun  job done.  The userspace-side reviewer should also provide an Acked-by on the
91*4882a593Smuzhiyun  kernel uAPI patch indicating that they believe the proposed uAPI is sound and
92*4882a593Smuzhiyun  sufficiently documented and validated for userspace's consumption.
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun- The userspace patches must be against the canonical upstream, not some vendor
95*4882a593Smuzhiyun  fork. This is to make sure that no one cheats on the review and testing
96*4882a593Smuzhiyun  requirements by doing a quick fork.
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun- The kernel patch can only be merged after all the above requirements are met,
99*4882a593Smuzhiyun  but it **must** be merged to either drm-next or drm-misc-next **before** the
100*4882a593Smuzhiyun  userspace patches land. uAPI always flows from the kernel, doing things the
101*4882a593Smuzhiyun  other way round risks divergence of the uAPI definitions and header files.
102*4882a593Smuzhiyun
103*4882a593SmuzhiyunThese are fairly steep requirements, but have grown out from years of shared
104*4882a593Smuzhiyunpain and experience with uAPI added hastily, and almost always regretted about
105*4882a593Smuzhiyunjust as fast. GFX devices change really fast, requiring a paradigm shift and
106*4882a593Smuzhiyunentire new set of uAPI interfaces every few years at least. Together with the
107*4882a593SmuzhiyunLinux kernel's guarantee to keep existing userspace running for 10+ years this
108*4882a593Smuzhiyunis already rather painful for the DRM subsystem, with multiple different uAPIs
109*4882a593Smuzhiyunfor the same thing co-existing. If we add a few more complete mistakes into the
110*4882a593Smuzhiyunmix every year it would be entirely unmanageable.
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun.. _drm_render_node:
113*4882a593Smuzhiyun
114*4882a593SmuzhiyunRender nodes
115*4882a593Smuzhiyun============
116*4882a593Smuzhiyun
117*4882a593SmuzhiyunDRM core provides multiple character-devices for user-space to use.
118*4882a593SmuzhiyunDepending on which device is opened, user-space can perform a different
119*4882a593Smuzhiyunset of operations (mainly ioctls). The primary node is always created
120*4882a593Smuzhiyunand called card<num>. Additionally, a currently unused control node,
121*4882a593Smuzhiyuncalled controlD<num> is also created. The primary node provides all
122*4882a593Smuzhiyunlegacy operations and historically was the only interface used by
123*4882a593Smuzhiyunuserspace. With KMS, the control node was introduced. However, the
124*4882a593Smuzhiyunplanned KMS control interface has never been written and so the control
125*4882a593Smuzhiyunnode stays unused to date.
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunWith the increased use of offscreen renderers and GPGPU applications,
128*4882a593Smuzhiyunclients no longer require running compositors or graphics servers to
129*4882a593Smuzhiyunmake use of a GPU. But the DRM API required unprivileged clients to
130*4882a593Smuzhiyunauthenticate to a DRM-Master prior to getting GPU access. To avoid this
131*4882a593Smuzhiyunstep and to grant clients GPU access without authenticating, render
132*4882a593Smuzhiyunnodes were introduced. Render nodes solely serve render clients, that
133*4882a593Smuzhiyunis, no modesetting or privileged ioctls can be issued on render nodes.
134*4882a593SmuzhiyunOnly non-global rendering commands are allowed. If a driver supports
135*4882a593Smuzhiyunrender nodes, it must advertise it via the DRIVER_RENDER DRM driver
136*4882a593Smuzhiyuncapability. If not supported, the primary node must be used for render
137*4882a593Smuzhiyunclients together with the legacy drmAuth authentication procedure.
138*4882a593Smuzhiyun
139*4882a593SmuzhiyunIf a driver advertises render node support, DRM core will create a
140*4882a593Smuzhiyunseparate render node called renderD<num>. There will be one render node
141*4882a593Smuzhiyunper device. No ioctls except PRIME-related ioctls will be allowed on
142*4882a593Smuzhiyunthis node. Especially GEM_OPEN will be explicitly prohibited. Render
143*4882a593Smuzhiyunnodes are designed to avoid the buffer-leaks, which occur if clients
144*4882a593Smuzhiyunguess the flink names or mmap offsets on the legacy interface.
145*4882a593SmuzhiyunAdditionally to this basic interface, drivers must mark their
146*4882a593Smuzhiyundriver-dependent render-only ioctls as DRM_RENDER_ALLOW so render
147*4882a593Smuzhiyunclients can use them. Driver authors must be careful not to allow any
148*4882a593Smuzhiyunprivileged ioctls on render nodes.
149*4882a593Smuzhiyun
150*4882a593SmuzhiyunWith render nodes, user-space can now control access to the render node
151*4882a593Smuzhiyunvia basic file-system access-modes. A running graphics server which
152*4882a593Smuzhiyunauthenticates clients on the privileged primary/legacy node is no longer
153*4882a593Smuzhiyunrequired. Instead, a client can open the render node and is immediately
154*4882a593Smuzhiyungranted GPU access. Communication between clients (or servers) is done
155*4882a593Smuzhiyunvia PRIME. FLINK from render node to legacy node is not supported. New
156*4882a593Smuzhiyunclients must not use the insecure FLINK interface.
157*4882a593Smuzhiyun
158*4882a593SmuzhiyunBesides dropping all modeset/global ioctls, render nodes also drop the
159*4882a593SmuzhiyunDRM-Master concept. There is no reason to associate render clients with
160*4882a593Smuzhiyuna DRM-Master as they are independent of any graphics server. Besides,
161*4882a593Smuzhiyunthey must work without any running master, anyway. Drivers must be able
162*4882a593Smuzhiyunto run without a master object if they support render nodes. If, on the
163*4882a593Smuzhiyunother hand, a driver requires shared state between clients which is
164*4882a593Smuzhiyunvisible to user-space and accessible beyond open-file boundaries, they
165*4882a593Smuzhiyuncannot support render nodes.
166*4882a593Smuzhiyun
167*4882a593SmuzhiyunDevice Hot-Unplug
168*4882a593Smuzhiyun=================
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun.. note::
171*4882a593Smuzhiyun   The following is the plan. Implementation is not there yet
172*4882a593Smuzhiyun   (2020 May).
173*4882a593Smuzhiyun
174*4882a593SmuzhiyunGraphics devices (display and/or render) may be connected via USB (e.g.
175*4882a593Smuzhiyundisplay adapters or docking stations) or Thunderbolt (e.g. eGPU). An end
176*4882a593Smuzhiyunuser is able to hot-unplug this kind of devices while they are being
177*4882a593Smuzhiyunused, and expects that the very least the machine does not crash. Any
178*4882a593Smuzhiyundamage from hot-unplugging a DRM device needs to be limited as much as
179*4882a593Smuzhiyunpossible and userspace must be given the chance to handle it if it wants
180*4882a593Smuzhiyunto. Ideally, unplugging a DRM device still lets a desktop continue to
181*4882a593Smuzhiyunrun, but that is going to need explicit support throughout the whole
182*4882a593Smuzhiyungraphics stack: from kernel and userspace drivers, through display
183*4882a593Smuzhiyunservers, via window system protocols, and in applications and libraries.
184*4882a593Smuzhiyun
185*4882a593SmuzhiyunOther scenarios that should lead to the same are: unrecoverable GPU
186*4882a593Smuzhiyuncrash, PCI device disappearing off the bus, or forced unbind of a driver
187*4882a593Smuzhiyunfrom the physical device.
188*4882a593Smuzhiyun
189*4882a593SmuzhiyunIn other words, from userspace perspective everything needs to keep on
190*4882a593Smuzhiyunworking more or less, until userspace stops using the disappeared DRM
191*4882a593Smuzhiyundevice and closes it completely. Userspace will learn of the device
192*4882a593Smuzhiyundisappearance from the device removed uevent, ioctls returning ENODEV
193*4882a593Smuzhiyun(or driver-specific ioctls returning driver-specific things), or open()
194*4882a593Smuzhiyunreturning ENXIO.
195*4882a593Smuzhiyun
196*4882a593SmuzhiyunOnly after userspace has closed all relevant DRM device and dmabuf file
197*4882a593Smuzhiyundescriptors and removed all mmaps, the DRM driver can tear down its
198*4882a593Smuzhiyuninstance for the device that no longer exists. If the same physical
199*4882a593Smuzhiyundevice somehow comes back in the mean time, it shall be a new DRM
200*4882a593Smuzhiyundevice.
201*4882a593Smuzhiyun
202*4882a593SmuzhiyunSimilar to PIDs, chardev minor numbers are not recycled immediately. A
203*4882a593Smuzhiyunnew DRM device always picks the next free minor number compared to the
204*4882a593Smuzhiyunprevious one allocated, and wraps around when minor numbers are
205*4882a593Smuzhiyunexhausted.
206*4882a593Smuzhiyun
207*4882a593SmuzhiyunThe goal raises at least the following requirements for the kernel and
208*4882a593Smuzhiyundrivers.
209*4882a593Smuzhiyun
210*4882a593SmuzhiyunRequirements for KMS UAPI
211*4882a593Smuzhiyun-------------------------
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun- KMS connectors must change their status to disconnected.
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun- Legacy modesets and pageflips, and atomic commits, both real and
216*4882a593Smuzhiyun  TEST_ONLY, and any other ioctls either fail with ENODEV or fake
217*4882a593Smuzhiyun  success.
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun- Pending non-blocking KMS operations deliver the DRM events userspace
220*4882a593Smuzhiyun  is expecting. This applies also to ioctls that faked success.
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun- open() on a device node whose underlying device has disappeared will
223*4882a593Smuzhiyun  fail with ENXIO.
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun- Attempting to create a DRM lease on a disappeared DRM device will
226*4882a593Smuzhiyun  fail with ENODEV. Existing DRM leases remain and work as listed
227*4882a593Smuzhiyun  above.
228*4882a593Smuzhiyun
229*4882a593SmuzhiyunRequirements for Render and Cross-Device UAPI
230*4882a593Smuzhiyun---------------------------------------------
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun- All GPU jobs that can no longer run must have their fences
233*4882a593Smuzhiyun  force-signalled to avoid inflicting hangs on userspace.
234*4882a593Smuzhiyun  The associated error code is ENODEV.
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun- Some userspace APIs already define what should happen when the device
237*4882a593Smuzhiyun  disappears (OpenGL, GL ES: `GL_KHR_robustness`_; `Vulkan`_:
238*4882a593Smuzhiyun  VK_ERROR_DEVICE_LOST; etc.). DRM drivers are free to implement this
239*4882a593Smuzhiyun  behaviour the way they see best, e.g. returning failures in
240*4882a593Smuzhiyun  driver-specific ioctls and handling those in userspace drivers, or
241*4882a593Smuzhiyun  rely on uevents, and so on.
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun- dmabuf which point to memory that has disappeared will either fail to
244*4882a593Smuzhiyun  import with ENODEV or continue to be successfully imported if it would
245*4882a593Smuzhiyun  have succeeded before the disappearance. See also about memory maps
246*4882a593Smuzhiyun  below for already imported dmabufs.
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun- Attempting to import a dmabuf to a disappeared device will either fail
249*4882a593Smuzhiyun  with ENODEV or succeed if it would have succeeded without the
250*4882a593Smuzhiyun  disappearance.
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun- open() on a device node whose underlying device has disappeared will
253*4882a593Smuzhiyun  fail with ENXIO.
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun.. _GL_KHR_robustness: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_robustness.txt
256*4882a593Smuzhiyun.. _Vulkan: https://www.khronos.org/vulkan/
257*4882a593Smuzhiyun
258*4882a593SmuzhiyunRequirements for Memory Maps
259*4882a593Smuzhiyun----------------------------
260*4882a593Smuzhiyun
261*4882a593SmuzhiyunMemory maps have further requirements that apply to both existing maps
262*4882a593Smuzhiyunand maps created after the device has disappeared. If the underlying
263*4882a593Smuzhiyunmemory disappears, the map is created or modified such that reads and
264*4882a593Smuzhiyunwrites will still complete successfully but the result is undefined.
265*4882a593SmuzhiyunThis applies to both userspace mmap()'d memory and memory pointed to by
266*4882a593Smuzhiyundmabuf which might be mapped to other devices (cross-device dmabuf
267*4882a593Smuzhiyunimports).
268*4882a593Smuzhiyun
269*4882a593SmuzhiyunRaising SIGBUS is not an option, because userspace cannot realistically
270*4882a593Smuzhiyunhandle it. Signal handlers are global, which makes them extremely
271*4882a593Smuzhiyundifficult to use correctly from libraries like those that Mesa produces.
272*4882a593SmuzhiyunSignal handlers are not composable, you can't have different handlers
273*4882a593Smuzhiyunfor GPU1 and GPU2 from different vendors, and a third handler for
274*4882a593Smuzhiyunmmapped regular files. Threads cause additional pain with signal
275*4882a593Smuzhiyunhandling as well.
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun.. _drm_driver_ioctl:
278*4882a593Smuzhiyun
279*4882a593SmuzhiyunIOCTL Support on Device Nodes
280*4882a593Smuzhiyun=============================
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
283*4882a593Smuzhiyun   :doc: driver specific ioctls
284*4882a593Smuzhiyun
285*4882a593SmuzhiyunRecommended IOCTL Return Values
286*4882a593Smuzhiyun-------------------------------
287*4882a593Smuzhiyun
288*4882a593SmuzhiyunIn theory a driver's IOCTL callback is only allowed to return very few error
289*4882a593Smuzhiyuncodes. In practice it's good to abuse a few more. This section documents common
290*4882a593Smuzhiyunpractice within the DRM subsystem:
291*4882a593Smuzhiyun
292*4882a593SmuzhiyunENOENT:
293*4882a593Smuzhiyun        Strictly this should only be used when a file doesn't exist e.g. when
294*4882a593Smuzhiyun        calling the open() syscall. We reuse that to signal any kind of object
295*4882a593Smuzhiyun        lookup failure, e.g. for unknown GEM buffer object handles, unknown KMS
296*4882a593Smuzhiyun        object handles and similar cases.
297*4882a593Smuzhiyun
298*4882a593SmuzhiyunENOSPC:
299*4882a593Smuzhiyun        Some drivers use this to differentiate "out of kernel memory" from "out
300*4882a593Smuzhiyun        of VRAM". Sometimes also applies to other limited gpu resources used for
301*4882a593Smuzhiyun        rendering (e.g. when you have a special limited compression buffer).
302*4882a593Smuzhiyun        Sometimes resource allocation/reservation issues in command submission
303*4882a593Smuzhiyun        IOCTLs are also signalled through EDEADLK.
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun        Simply running out of kernel/system memory is signalled through ENOMEM.
306*4882a593Smuzhiyun
307*4882a593SmuzhiyunEPERM/EACCES:
308*4882a593Smuzhiyun        Returned for an operation that is valid, but needs more privileges.
309*4882a593Smuzhiyun        E.g. root-only or much more common, DRM master-only operations return
310*4882a593Smuzhiyun        this when called by unpriviledged clients. There's no clear
311*4882a593Smuzhiyun        difference between EACCES and EPERM.
312*4882a593Smuzhiyun
313*4882a593SmuzhiyunENODEV:
314*4882a593Smuzhiyun        The device is not present anymore or is not yet fully initialized.
315*4882a593Smuzhiyun
316*4882a593SmuzhiyunEOPNOTSUPP:
317*4882a593Smuzhiyun        Feature (like PRIME, modesetting, GEM) is not supported by the driver.
318*4882a593Smuzhiyun
319*4882a593SmuzhiyunENXIO:
320*4882a593Smuzhiyun        Remote failure, either a hardware transaction (like i2c), but also used
321*4882a593Smuzhiyun        when the exporting driver of a shared dma-buf or fence doesn't support a
322*4882a593Smuzhiyun        feature needed.
323*4882a593Smuzhiyun
324*4882a593SmuzhiyunEINTR:
325*4882a593Smuzhiyun        DRM drivers assume that userspace restarts all IOCTLs. Any DRM IOCTL can
326*4882a593Smuzhiyun        return EINTR and in such a case should be restarted with the IOCTL
327*4882a593Smuzhiyun        parameters left unchanged.
328*4882a593Smuzhiyun
329*4882a593SmuzhiyunEIO:
330*4882a593Smuzhiyun        The GPU died and couldn't be resurrected through a reset. Modesetting
331*4882a593Smuzhiyun        hardware failures are signalled through the "link status" connector
332*4882a593Smuzhiyun        property.
333*4882a593Smuzhiyun
334*4882a593SmuzhiyunEINVAL:
335*4882a593Smuzhiyun        Catch-all for anything that is an invalid argument combination which
336*4882a593Smuzhiyun        cannot work.
337*4882a593Smuzhiyun
338*4882a593SmuzhiyunIOCTL also use other error codes like ETIME, EFAULT, EBUSY, ENOTTY but their
339*4882a593Smuzhiyunusage is in line with the common meanings. The above list tries to just document
340*4882a593SmuzhiyunDRM specific patterns. Note that ENOTTY has the slightly unintuitive meaning of
341*4882a593Smuzhiyun"this IOCTL does not exist", and is used exactly as such in DRM.
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun.. kernel-doc:: include/drm/drm_ioctl.h
344*4882a593Smuzhiyun   :internal:
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
347*4882a593Smuzhiyun   :export:
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_ioc32.c
350*4882a593Smuzhiyun   :export:
351*4882a593Smuzhiyun
352*4882a593SmuzhiyunTesting and validation
353*4882a593Smuzhiyun======================
354*4882a593Smuzhiyun
355*4882a593SmuzhiyunTesting Requirements for userspace API
356*4882a593Smuzhiyun--------------------------------------
357*4882a593Smuzhiyun
358*4882a593SmuzhiyunNew cross-driver userspace interface extensions, like new IOCTL, new KMS
359*4882a593Smuzhiyunproperties, new files in sysfs or anything else that constitutes an API change
360*4882a593Smuzhiyunshould have driver-agnostic testcases in IGT for that feature, if such a test
361*4882a593Smuzhiyuncan be reasonably made using IGT for the target hardware.
362*4882a593Smuzhiyun
363*4882a593SmuzhiyunValidating changes with IGT
364*4882a593Smuzhiyun---------------------------
365*4882a593Smuzhiyun
366*4882a593SmuzhiyunThere's a collection of tests that aims to cover the whole functionality of
367*4882a593SmuzhiyunDRM drivers and that can be used to check that changes to DRM drivers or the
368*4882a593Smuzhiyuncore don't regress existing functionality. This test suite is called IGT and
369*4882a593Smuzhiyunits code and instructions to build and run can be found in
370*4882a593Smuzhiyunhttps://gitlab.freedesktop.org/drm/igt-gpu-tools/.
371*4882a593Smuzhiyun
372*4882a593SmuzhiyunUsing VKMS to test DRM API
373*4882a593Smuzhiyun--------------------------
374*4882a593Smuzhiyun
375*4882a593SmuzhiyunVKMS is a software-only model of a KMS driver that is useful for testing
376*4882a593Smuzhiyunand for running compositors. VKMS aims to enable a virtual display without
377*4882a593Smuzhiyunthe need for a hardware display capability. These characteristics made VKMS
378*4882a593Smuzhiyuna perfect tool for validating the DRM core behavior and also support the
379*4882a593Smuzhiyuncompositor developer. VKMS makes it possible to test DRM functions in a
380*4882a593Smuzhiyunvirtual machine without display, simplifying the validation of some of the
381*4882a593Smuzhiyuncore changes.
382*4882a593Smuzhiyun
383*4882a593SmuzhiyunTo Validate changes in DRM API with VKMS, start setting the kernel: make
384*4882a593Smuzhiyunsure to enable VKMS module; compile the kernel with the VKMS enabled and
385*4882a593Smuzhiyuninstall it in the target machine. VKMS can be run in a Virtual Machine
386*4882a593Smuzhiyun(QEMU, virtme or similar). It's recommended the use of KVM with the minimum
387*4882a593Smuzhiyunof 1GB of RAM and four cores.
388*4882a593Smuzhiyun
389*4882a593SmuzhiyunIt's possible to run the IGT-tests in a VM in two ways:
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun	1. Use IGT inside a VM
392*4882a593Smuzhiyun	2. Use IGT from the host machine and write the results in a shared directory.
393*4882a593Smuzhiyun
394*4882a593SmuzhiyunAs follow, there is an example of using a VM with a shared directory with
395*4882a593Smuzhiyunthe host machine to run igt-tests. As an example it's used virtme::
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun	$ virtme-run --rwdir /path/for/shared_dir --kdir=path/for/kernel/directory --mods=auto
398*4882a593Smuzhiyun
399*4882a593SmuzhiyunRun the igt-tests in the guest machine, as example it's ran the 'kms_flip'
400*4882a593Smuzhiyuntests::
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun	$ /path/for/igt-gpu-tools/scripts/run-tests.sh -p -s -t "kms_flip.*" -v
403*4882a593Smuzhiyun
404*4882a593SmuzhiyunIn this example, instead of build the igt_runner, Piglit is used
405*4882a593Smuzhiyun(-p option); it's created html summary of the tests results and it's saved
406*4882a593Smuzhiyunin the folder "igt-gpu-tools/results"; it's executed only the igt-tests
407*4882a593Smuzhiyunmatching the -t option.
408*4882a593Smuzhiyun
409*4882a593SmuzhiyunDisplay CRC Support
410*4882a593Smuzhiyun-------------------
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
413*4882a593Smuzhiyun   :doc: CRC ABI
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
416*4882a593Smuzhiyun   :export:
417*4882a593Smuzhiyun
418*4882a593SmuzhiyunDebugfs Support
419*4882a593Smuzhiyun---------------
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun.. kernel-doc:: include/drm/drm_debugfs.h
422*4882a593Smuzhiyun   :internal:
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_debugfs.c
425*4882a593Smuzhiyun   :export:
426*4882a593Smuzhiyun
427*4882a593SmuzhiyunSysfs Support
428*4882a593Smuzhiyun=============
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c
431*4882a593Smuzhiyun   :doc: overview
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c
434*4882a593Smuzhiyun   :export:
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun
437*4882a593SmuzhiyunVBlank event handling
438*4882a593Smuzhiyun=====================
439*4882a593Smuzhiyun
440*4882a593SmuzhiyunThe DRM core exposes two vertical blank related ioctls:
441*4882a593Smuzhiyun
442*4882a593SmuzhiyunDRM_IOCTL_WAIT_VBLANK
443*4882a593Smuzhiyun    This takes a struct drm_wait_vblank structure as its argument, and
444*4882a593Smuzhiyun    it is used to block or request a signal when a specified vblank
445*4882a593Smuzhiyun    event occurs.
446*4882a593Smuzhiyun
447*4882a593SmuzhiyunDRM_IOCTL_MODESET_CTL
448*4882a593Smuzhiyun    This was only used for user-mode-settind drivers around modesetting
449*4882a593Smuzhiyun    changes to allow the kernel to update the vblank interrupt after
450*4882a593Smuzhiyun    mode setting, since on many devices the vertical blank counter is
451*4882a593Smuzhiyun    reset to 0 at some point during modeset. Modern drivers should not
452*4882a593Smuzhiyun    call this any more since with kernel mode setting it is a no-op.
453*4882a593Smuzhiyun
454*4882a593SmuzhiyunUserspace API Structures
455*4882a593Smuzhiyun========================
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun.. kernel-doc:: include/uapi/drm/drm_mode.h
458*4882a593Smuzhiyun   :doc: overview
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun.. kernel-doc:: include/uapi/drm/drm_mode.h
461*4882a593Smuzhiyun   :internal:
462