1cfb9b89fSPekka Paalanen.. Copyright 2020 DisplayLink (UK) Ltd. 2cfb9b89fSPekka Paalanen 322554020SJani Nikula=================== 4ca00c2b9SJani NikulaUserland interfaces 5ca00c2b9SJani Nikula=================== 6ca00c2b9SJani Nikula 7ca00c2b9SJani NikulaThe DRM core exports several interfaces to applications, generally 8ca00c2b9SJani Nikulaintended to be used through corresponding libdrm wrapper functions. In 9ca00c2b9SJani Nikulaaddition, drivers export device-specific interfaces for use by userspace 10ca00c2b9SJani Nikuladrivers & device-aware applications through ioctls and sysfs files. 11ca00c2b9SJani Nikula 12ca00c2b9SJani NikulaExternal interfaces include: memory mapping, context management, DMA 13ca00c2b9SJani Nikulaoperations, AGP management, vblank control, fence management, memory 14ca00c2b9SJani Nikulamanagement, and output management. 15ca00c2b9SJani Nikula 16ca00c2b9SJani NikulaCover generic ioctls and sysfs layout here. We only need high-level 17ca00c2b9SJani Nikulainfo, since man pages should cover the rest. 18ca00c2b9SJani Nikula 19a3257256SDaniel Vetterlibdrm Device Lookup 20a3257256SDaniel Vetter==================== 21a3257256SDaniel Vetter 22a3257256SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 23a3257256SDaniel Vetter :doc: getunique and setversion story 24a3257256SDaniel Vetter 253b96a0b1SDaniel Vetter 26b93658f8SDaniel Vetter.. _drm_primary_node: 27b93658f8SDaniel Vetter 283b96a0b1SDaniel VetterPrimary Nodes, DRM Master and Authentication 293b96a0b1SDaniel Vetter============================================ 303b96a0b1SDaniel Vetter 313b96a0b1SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_auth.c 323b96a0b1SDaniel Vetter :doc: master and authentication 333b96a0b1SDaniel Vetter 343b96a0b1SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_auth.c 353b96a0b1SDaniel Vetter :export: 363b96a0b1SDaniel Vetter 373b96a0b1SDaniel Vetter.. kernel-doc:: include/drm/drm_auth.h 383b96a0b1SDaniel Vetter :internal: 393b96a0b1SDaniel Vetter 40d793b8f7SDesmond Cheong Zhi Xi 41d793b8f7SDesmond Cheong Zhi Xi.. _drm_leasing: 42d793b8f7SDesmond Cheong Zhi Xi 43d793b8f7SDesmond Cheong Zhi XiDRM Display Resource Leasing 44d793b8f7SDesmond Cheong Zhi Xi============================ 45d793b8f7SDesmond Cheong Zhi Xi 46d793b8f7SDesmond Cheong Zhi Xi.. kernel-doc:: drivers/gpu/drm/drm_lease.c 47d793b8f7SDesmond Cheong Zhi Xi :doc: drm leasing 48d793b8f7SDesmond Cheong Zhi Xi 49bcb32b69SDaniel VetterOpen-Source Userspace Requirements 50bcb32b69SDaniel Vetter================================== 51bcb32b69SDaniel Vetter 520d42204fSDaniel VetterThe DRM subsystem has stricter requirements than most other kernel subsystems on 530d42204fSDaniel Vetterwhat the userspace side for new uAPI needs to look like. This section here 540d42204fSDaniel Vetterexplains what exactly those requirements are, and why they exist. 550d42204fSDaniel Vetter 560d42204fSDaniel VetterThe short summary is that any addition of DRM uAPI requires corresponding 570d42204fSDaniel Vetteropen-sourced userspace patches, and those patches must be reviewed and ready for 580d42204fSDaniel Vettermerging into a suitable and canonical upstream project. 590d42204fSDaniel Vetter 600d42204fSDaniel VetterGFX devices (both display and render/GPU side) are really complex bits of 610d42204fSDaniel Vetterhardware, with userspace and kernel by necessity having to work together really 620d42204fSDaniel Vetterclosely. The interfaces, for rendering and modesetting, must be extremely wide 630d42204fSDaniel Vetterand flexible, and therefore it is almost always impossible to precisely define 640d42204fSDaniel Vetterthem for every possible corner case. This in turn makes it really practically 650d42204fSDaniel Vetterinfeasible to differentiate between behaviour that's required by userspace, and 660d42204fSDaniel Vetterwhich must not be changed to avoid regressions, and behaviour which is only an 670d42204fSDaniel Vetteraccidental artifact of the current implementation. 680d42204fSDaniel Vetter 690d42204fSDaniel VetterWithout access to the full source code of all userspace users that means it 700d42204fSDaniel Vetterbecomes impossible to change the implementation details, since userspace could 710d42204fSDaniel Vetterdepend upon the accidental behaviour of the current implementation in minute 720d42204fSDaniel Vetterdetails. And debugging such regressions without access to source code is pretty 730d42204fSDaniel Vettermuch impossible. As a consequence this means: 740d42204fSDaniel Vetter 750d42204fSDaniel Vetter- The Linux kernel's "no regression" policy holds in practice only for 760d42204fSDaniel Vetter open-source userspace of the DRM subsystem. DRM developers are perfectly fine 770d42204fSDaniel Vetter if closed-source blob drivers in userspace use the same uAPI as the open 780d42204fSDaniel Vetter drivers, but they must do so in the exact same way as the open drivers. 790d42204fSDaniel Vetter Creative (ab)use of the interfaces will, and in the past routinely has, lead 800d42204fSDaniel Vetter to breakage. 810d42204fSDaniel Vetter 820d42204fSDaniel Vetter- Any new userspace interface must have an open-source implementation as 830d42204fSDaniel Vetter demonstration vehicle. 840d42204fSDaniel Vetter 850d42204fSDaniel VetterThe other reason for requiring open-source userspace is uAPI review. Since the 860d42204fSDaniel Vetterkernel and userspace parts of a GFX stack must work together so closely, code 870d42204fSDaniel Vetterreview can only assess whether a new interface achieves its goals by looking at 880d42204fSDaniel Vetterboth sides. Making sure that the interface indeed covers the use-case fully 890d42204fSDaniel Vetterleads to a few additional requirements: 900d42204fSDaniel Vetter 910d42204fSDaniel Vetter- The open-source userspace must not be a toy/test application, but the real 920d42204fSDaniel Vetter thing. Specifically it needs to handle all the usual error and corner cases. 930d42204fSDaniel Vetter These are often the places where new uAPI falls apart and hence essential to 940d42204fSDaniel Vetter assess the fitness of a proposed interface. 950d42204fSDaniel Vetter 960d42204fSDaniel Vetter- The userspace side must be fully reviewed and tested to the standards of that 970d42204fSDaniel Vetter userspace project. For e.g. mesa this means piglit testcases and review on the 980d42204fSDaniel Vetter mailing list. This is again to ensure that the new interface actually gets the 99e33df4caSDaniel Vetter job done. The userspace-side reviewer should also provide an Acked-by on the 100e33df4caSDaniel Vetter kernel uAPI patch indicating that they believe the proposed uAPI is sound and 101e33df4caSDaniel Vetter sufficiently documented and validated for userspace's consumption. 1020d42204fSDaniel Vetter 1030d42204fSDaniel Vetter- The userspace patches must be against the canonical upstream, not some vendor 1040d42204fSDaniel Vetter fork. This is to make sure that no one cheats on the review and testing 1050d42204fSDaniel Vetter requirements by doing a quick fork. 1060d42204fSDaniel Vetter 1070d42204fSDaniel Vetter- The kernel patch can only be merged after all the above requirements are met, 1083d42fca0SEric Anholt but it **must** be merged to either drm-next or drm-misc-next **before** the 1093d42fca0SEric Anholt userspace patches land. uAPI always flows from the kernel, doing things the 1103d42fca0SEric Anholt other way round risks divergence of the uAPI definitions and header files. 1110d42204fSDaniel Vetter 1120d42204fSDaniel VetterThese are fairly steep requirements, but have grown out from years of shared 1130d42204fSDaniel Vetterpain and experience with uAPI added hastily, and almost always regretted about 1140d42204fSDaniel Vetterjust as fast. GFX devices change really fast, requiring a paradigm shift and 1150d42204fSDaniel Vetterentire new set of uAPI interfaces every few years at least. Together with the 1160d42204fSDaniel VetterLinux kernel's guarantee to keep existing userspace running for 10+ years this 1170d42204fSDaniel Vetteris already rather painful for the DRM subsystem, with multiple different uAPIs 1180d42204fSDaniel Vetterfor the same thing co-existing. If we add a few more complete mistakes into the 1190d42204fSDaniel Vettermix every year it would be entirely unmanageable. 1200d42204fSDaniel Vetter 121b93658f8SDaniel Vetter.. _drm_render_node: 122b93658f8SDaniel Vetter 123ca00c2b9SJani NikulaRender nodes 12422554020SJani Nikula============ 125ca00c2b9SJani Nikula 126ca00c2b9SJani NikulaDRM core provides multiple character-devices for user-space to use. 127ca00c2b9SJani NikulaDepending on which device is opened, user-space can perform a different 128ca00c2b9SJani Nikulaset of operations (mainly ioctls). The primary node is always created 129ca00c2b9SJani Nikulaand called card<num>. Additionally, a currently unused control node, 130ca00c2b9SJani Nikulacalled controlD<num> is also created. The primary node provides all 131ca00c2b9SJani Nikulalegacy operations and historically was the only interface used by 132ca00c2b9SJani Nikulauserspace. With KMS, the control node was introduced. However, the 133ca00c2b9SJani Nikulaplanned KMS control interface has never been written and so the control 134ca00c2b9SJani Nikulanode stays unused to date. 135ca00c2b9SJani Nikula 136ca00c2b9SJani NikulaWith the increased use of offscreen renderers and GPGPU applications, 137ca00c2b9SJani Nikulaclients no longer require running compositors or graphics servers to 138ca00c2b9SJani Nikulamake use of a GPU. But the DRM API required unprivileged clients to 139ca00c2b9SJani Nikulaauthenticate to a DRM-Master prior to getting GPU access. To avoid this 140ca00c2b9SJani Nikulastep and to grant clients GPU access without authenticating, render 141ca00c2b9SJani Nikulanodes were introduced. Render nodes solely serve render clients, that 142ca00c2b9SJani Nikulais, no modesetting or privileged ioctls can be issued on render nodes. 143ca00c2b9SJani NikulaOnly non-global rendering commands are allowed. If a driver supports 144ca00c2b9SJani Nikularender nodes, it must advertise it via the DRIVER_RENDER DRM driver 145ca00c2b9SJani Nikulacapability. If not supported, the primary node must be used for render 146ca00c2b9SJani Nikulaclients together with the legacy drmAuth authentication procedure. 147ca00c2b9SJani Nikula 148ca00c2b9SJani NikulaIf a driver advertises render node support, DRM core will create a 149ca00c2b9SJani Nikulaseparate render node called renderD<num>. There will be one render node 150ca00c2b9SJani Nikulaper device. No ioctls except PRIME-related ioctls will be allowed on 151*aa457ff1SJeffrey Hugothis node. Especially GEM_OPEN will be explicitly prohibited. For a 152*aa457ff1SJeffrey Hugocomplete list of driver-independent ioctls that can be used on render 153*aa457ff1SJeffrey Hugonodes, see the ioctls marked DRM_RENDER_ALLOW in drm_ioctl.c Render 154ca00c2b9SJani Nikulanodes are designed to avoid the buffer-leaks, which occur if clients 155ca00c2b9SJani Nikulaguess the flink names or mmap offsets on the legacy interface. 156ca00c2b9SJani NikulaAdditionally to this basic interface, drivers must mark their 157ca00c2b9SJani Nikuladriver-dependent render-only ioctls as DRM_RENDER_ALLOW so render 158ca00c2b9SJani Nikulaclients can use them. Driver authors must be careful not to allow any 159ca00c2b9SJani Nikulaprivileged ioctls on render nodes. 160ca00c2b9SJani Nikula 161ca00c2b9SJani NikulaWith render nodes, user-space can now control access to the render node 162ca00c2b9SJani Nikulavia basic file-system access-modes. A running graphics server which 163ca00c2b9SJani Nikulaauthenticates clients on the privileged primary/legacy node is no longer 164ca00c2b9SJani Nikularequired. Instead, a client can open the render node and is immediately 165ca00c2b9SJani Nikulagranted GPU access. Communication between clients (or servers) is done 166ca00c2b9SJani Nikulavia PRIME. FLINK from render node to legacy node is not supported. New 167ca00c2b9SJani Nikulaclients must not use the insecure FLINK interface. 168ca00c2b9SJani Nikula 169ca00c2b9SJani NikulaBesides dropping all modeset/global ioctls, render nodes also drop the 170ca00c2b9SJani NikulaDRM-Master concept. There is no reason to associate render clients with 171ca00c2b9SJani Nikulaa DRM-Master as they are independent of any graphics server. Besides, 172ca00c2b9SJani Nikulathey must work without any running master, anyway. Drivers must be able 173ca00c2b9SJani Nikulato run without a master object if they support render nodes. If, on the 174ca00c2b9SJani Nikulaother hand, a driver requires shared state between clients which is 175ca00c2b9SJani Nikulavisible to user-space and accessible beyond open-file boundaries, they 176ca00c2b9SJani Nikulacannot support render nodes. 177ca00c2b9SJani Nikula 178cfb9b89fSPekka PaalanenDevice Hot-Unplug 179cfb9b89fSPekka Paalanen================= 180cfb9b89fSPekka Paalanen 181cfb9b89fSPekka Paalanen.. note:: 182cfb9b89fSPekka Paalanen The following is the plan. Implementation is not there yet 183cfb9b89fSPekka Paalanen (2020 May). 184cfb9b89fSPekka Paalanen 185cfb9b89fSPekka PaalanenGraphics devices (display and/or render) may be connected via USB (e.g. 186cfb9b89fSPekka Paalanendisplay adapters or docking stations) or Thunderbolt (e.g. eGPU). An end 187cfb9b89fSPekka Paalanenuser is able to hot-unplug this kind of devices while they are being 188cfb9b89fSPekka Paalanenused, and expects that the very least the machine does not crash. Any 189cfb9b89fSPekka Paalanendamage from hot-unplugging a DRM device needs to be limited as much as 190cfb9b89fSPekka Paalanenpossible and userspace must be given the chance to handle it if it wants 191cfb9b89fSPekka Paalanento. Ideally, unplugging a DRM device still lets a desktop continue to 192cfb9b89fSPekka Paalanenrun, but that is going to need explicit support throughout the whole 193cfb9b89fSPekka Paalanengraphics stack: from kernel and userspace drivers, through display 194cfb9b89fSPekka Paalanenservers, via window system protocols, and in applications and libraries. 195cfb9b89fSPekka Paalanen 196cfb9b89fSPekka PaalanenOther scenarios that should lead to the same are: unrecoverable GPU 197cfb9b89fSPekka Paalanencrash, PCI device disappearing off the bus, or forced unbind of a driver 198cfb9b89fSPekka Paalanenfrom the physical device. 199cfb9b89fSPekka Paalanen 200cfb9b89fSPekka PaalanenIn other words, from userspace perspective everything needs to keep on 201cfb9b89fSPekka Paalanenworking more or less, until userspace stops using the disappeared DRM 202cfb9b89fSPekka Paalanendevice and closes it completely. Userspace will learn of the device 203cfb9b89fSPekka Paalanendisappearance from the device removed uevent, ioctls returning ENODEV 204cfb9b89fSPekka Paalanen(or driver-specific ioctls returning driver-specific things), or open() 205cfb9b89fSPekka Paalanenreturning ENXIO. 206cfb9b89fSPekka Paalanen 207cfb9b89fSPekka PaalanenOnly after userspace has closed all relevant DRM device and dmabuf file 208cfb9b89fSPekka Paalanendescriptors and removed all mmaps, the DRM driver can tear down its 209cfb9b89fSPekka Paalaneninstance for the device that no longer exists. If the same physical 210cfb9b89fSPekka Paalanendevice somehow comes back in the mean time, it shall be a new DRM 211cfb9b89fSPekka Paalanendevice. 212cfb9b89fSPekka Paalanen 213cfb9b89fSPekka PaalanenSimilar to PIDs, chardev minor numbers are not recycled immediately. A 214cfb9b89fSPekka Paalanennew DRM device always picks the next free minor number compared to the 215cfb9b89fSPekka Paalanenprevious one allocated, and wraps around when minor numbers are 216cfb9b89fSPekka Paalanenexhausted. 217cfb9b89fSPekka Paalanen 218cfb9b89fSPekka PaalanenThe goal raises at least the following requirements for the kernel and 219cfb9b89fSPekka Paalanendrivers. 220cfb9b89fSPekka Paalanen 221cfb9b89fSPekka PaalanenRequirements for KMS UAPI 222cfb9b89fSPekka Paalanen------------------------- 223cfb9b89fSPekka Paalanen 224cfb9b89fSPekka Paalanen- KMS connectors must change their status to disconnected. 225cfb9b89fSPekka Paalanen 226cfb9b89fSPekka Paalanen- Legacy modesets and pageflips, and atomic commits, both real and 227cfb9b89fSPekka Paalanen TEST_ONLY, and any other ioctls either fail with ENODEV or fake 228cfb9b89fSPekka Paalanen success. 229cfb9b89fSPekka Paalanen 230cfb9b89fSPekka Paalanen- Pending non-blocking KMS operations deliver the DRM events userspace 231cfb9b89fSPekka Paalanen is expecting. This applies also to ioctls that faked success. 232cfb9b89fSPekka Paalanen 233cfb9b89fSPekka Paalanen- open() on a device node whose underlying device has disappeared will 234cfb9b89fSPekka Paalanen fail with ENXIO. 235cfb9b89fSPekka Paalanen 236cfb9b89fSPekka Paalanen- Attempting to create a DRM lease on a disappeared DRM device will 237cfb9b89fSPekka Paalanen fail with ENODEV. Existing DRM leases remain and work as listed 238cfb9b89fSPekka Paalanen above. 239cfb9b89fSPekka Paalanen 240cfb9b89fSPekka PaalanenRequirements for Render and Cross-Device UAPI 241cfb9b89fSPekka Paalanen--------------------------------------------- 242cfb9b89fSPekka Paalanen 243cfb9b89fSPekka Paalanen- All GPU jobs that can no longer run must have their fences 244cfb9b89fSPekka Paalanen force-signalled to avoid inflicting hangs on userspace. 245cfb9b89fSPekka Paalanen The associated error code is ENODEV. 246cfb9b89fSPekka Paalanen 247cfb9b89fSPekka Paalanen- Some userspace APIs already define what should happen when the device 248cfb9b89fSPekka Paalanen disappears (OpenGL, GL ES: `GL_KHR_robustness`_; `Vulkan`_: 249cfb9b89fSPekka Paalanen VK_ERROR_DEVICE_LOST; etc.). DRM drivers are free to implement this 250cfb9b89fSPekka Paalanen behaviour the way they see best, e.g. returning failures in 251cfb9b89fSPekka Paalanen driver-specific ioctls and handling those in userspace drivers, or 252cfb9b89fSPekka Paalanen rely on uevents, and so on. 253cfb9b89fSPekka Paalanen 254cfb9b89fSPekka Paalanen- dmabuf which point to memory that has disappeared will either fail to 255cfb9b89fSPekka Paalanen import with ENODEV or continue to be successfully imported if it would 256cfb9b89fSPekka Paalanen have succeeded before the disappearance. See also about memory maps 257cfb9b89fSPekka Paalanen below for already imported dmabufs. 258cfb9b89fSPekka Paalanen 259cfb9b89fSPekka Paalanen- Attempting to import a dmabuf to a disappeared device will either fail 260cfb9b89fSPekka Paalanen with ENODEV or succeed if it would have succeeded without the 261cfb9b89fSPekka Paalanen disappearance. 262cfb9b89fSPekka Paalanen 263cfb9b89fSPekka Paalanen- open() on a device node whose underlying device has disappeared will 264cfb9b89fSPekka Paalanen fail with ENXIO. 265cfb9b89fSPekka Paalanen 266cfb9b89fSPekka Paalanen.. _GL_KHR_robustness: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_robustness.txt 267cfb9b89fSPekka Paalanen.. _Vulkan: https://www.khronos.org/vulkan/ 268cfb9b89fSPekka Paalanen 269cfb9b89fSPekka PaalanenRequirements for Memory Maps 270cfb9b89fSPekka Paalanen---------------------------- 271cfb9b89fSPekka Paalanen 272cfb9b89fSPekka PaalanenMemory maps have further requirements that apply to both existing maps 273cfb9b89fSPekka Paalanenand maps created after the device has disappeared. If the underlying 274cfb9b89fSPekka Paalanenmemory disappears, the map is created or modified such that reads and 275cfb9b89fSPekka Paalanenwrites will still complete successfully but the result is undefined. 276cfb9b89fSPekka PaalanenThis applies to both userspace mmap()'d memory and memory pointed to by 277cfb9b89fSPekka Paalanendmabuf which might be mapped to other devices (cross-device dmabuf 278cfb9b89fSPekka Paalanenimports). 279cfb9b89fSPekka Paalanen 280cfb9b89fSPekka PaalanenRaising SIGBUS is not an option, because userspace cannot realistically 281cfb9b89fSPekka Paalanenhandle it. Signal handlers are global, which makes them extremely 282cfb9b89fSPekka Paalanendifficult to use correctly from libraries like those that Mesa produces. 283cfb9b89fSPekka PaalanenSignal handlers are not composable, you can't have different handlers 284cfb9b89fSPekka Paalanenfor GPU1 and GPU2 from different vendors, and a third handler for 285cfb9b89fSPekka Paalanenmmapped regular files. Threads cause additional pain with signal 286cfb9b89fSPekka Paalanenhandling as well. 287cfb9b89fSPekka Paalanen 288bb2eaba6SDaniel Vetter.. _drm_driver_ioctl: 289bb2eaba6SDaniel Vetter 2902640981fSDaniel VetterIOCTL Support on Device Nodes 2912640981fSDaniel Vetter============================= 2922640981fSDaniel Vetter 2932640981fSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 2942640981fSDaniel Vetter :doc: driver specific ioctls 2952640981fSDaniel Vetter 296371cadd8SDaniel VetterRecommended IOCTL Return Values 297371cadd8SDaniel Vetter------------------------------- 298371cadd8SDaniel Vetter 299371cadd8SDaniel VetterIn theory a driver's IOCTL callback is only allowed to return very few error 300371cadd8SDaniel Vettercodes. In practice it's good to abuse a few more. This section documents common 301371cadd8SDaniel Vetterpractice within the DRM subsystem: 302371cadd8SDaniel Vetter 303371cadd8SDaniel VetterENOENT: 304371cadd8SDaniel Vetter Strictly this should only be used when a file doesn't exist e.g. when 305371cadd8SDaniel Vetter calling the open() syscall. We reuse that to signal any kind of object 306371cadd8SDaniel Vetter lookup failure, e.g. for unknown GEM buffer object handles, unknown KMS 307371cadd8SDaniel Vetter object handles and similar cases. 308371cadd8SDaniel Vetter 309371cadd8SDaniel VetterENOSPC: 310371cadd8SDaniel Vetter Some drivers use this to differentiate "out of kernel memory" from "out 311371cadd8SDaniel Vetter of VRAM". Sometimes also applies to other limited gpu resources used for 312371cadd8SDaniel Vetter rendering (e.g. when you have a special limited compression buffer). 313371cadd8SDaniel Vetter Sometimes resource allocation/reservation issues in command submission 314371cadd8SDaniel Vetter IOCTLs are also signalled through EDEADLK. 315371cadd8SDaniel Vetter 316371cadd8SDaniel Vetter Simply running out of kernel/system memory is signalled through ENOMEM. 317371cadd8SDaniel Vetter 318cba8087dSColin Ian KingEPERM/EACCES: 319371cadd8SDaniel Vetter Returned for an operation that is valid, but needs more privileges. 320371cadd8SDaniel Vetter E.g. root-only or much more common, DRM master-only operations return 321bde952f9SRandy Dunlap this when called by unpriviledged clients. There's no clear 322cba8087dSColin Ian King difference between EACCES and EPERM. 323371cadd8SDaniel Vetter 324371cadd8SDaniel VetterENODEV: 325cfb9b89fSPekka Paalanen The device is not present anymore or is not yet fully initialized. 3269edb6a0bSDaniel Vetter 3279edb6a0bSDaniel VetterEOPNOTSUPP: 328371cadd8SDaniel Vetter Feature (like PRIME, modesetting, GEM) is not supported by the driver. 329371cadd8SDaniel Vetter 330371cadd8SDaniel VetterENXIO: 331371cadd8SDaniel Vetter Remote failure, either a hardware transaction (like i2c), but also used 332371cadd8SDaniel Vetter when the exporting driver of a shared dma-buf or fence doesn't support a 333371cadd8SDaniel Vetter feature needed. 334371cadd8SDaniel Vetter 335371cadd8SDaniel VetterEINTR: 336371cadd8SDaniel Vetter DRM drivers assume that userspace restarts all IOCTLs. Any DRM IOCTL can 337371cadd8SDaniel Vetter return EINTR and in such a case should be restarted with the IOCTL 338371cadd8SDaniel Vetter parameters left unchanged. 339371cadd8SDaniel Vetter 340371cadd8SDaniel VetterEIO: 341371cadd8SDaniel Vetter The GPU died and couldn't be resurrected through a reset. Modesetting 342371cadd8SDaniel Vetter hardware failures are signalled through the "link status" connector 343371cadd8SDaniel Vetter property. 344371cadd8SDaniel Vetter 345371cadd8SDaniel VetterEINVAL: 346371cadd8SDaniel Vetter Catch-all for anything that is an invalid argument combination which 347371cadd8SDaniel Vetter cannot work. 348371cadd8SDaniel Vetter 349371cadd8SDaniel VetterIOCTL also use other error codes like ETIME, EFAULT, EBUSY, ENOTTY but their 350371cadd8SDaniel Vetterusage is in line with the common meanings. The above list tries to just document 351371cadd8SDaniel VetterDRM specific patterns. Note that ENOTTY has the slightly unintuitive meaning of 352371cadd8SDaniel Vetter"this IOCTL does not exist", and is used exactly as such in DRM. 353371cadd8SDaniel Vetter 3542640981fSDaniel Vetter.. kernel-doc:: include/drm/drm_ioctl.h 3552640981fSDaniel Vetter :internal: 3562640981fSDaniel Vetter 3572640981fSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 3582640981fSDaniel Vetter :export: 3592640981fSDaniel Vetter 3602640981fSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_ioc32.c 3612640981fSDaniel Vetter :export: 362a8182863SDaniel Vetter 363a8182863SDaniel VetterTesting and validation 364a8182863SDaniel Vetter====================== 365a8182863SDaniel Vetter 366badfa5beSDaniel VetterTesting Requirements for userspace API 367badfa5beSDaniel Vetter-------------------------------------- 368badfa5beSDaniel Vetter 369badfa5beSDaniel VetterNew cross-driver userspace interface extensions, like new IOCTL, new KMS 370badfa5beSDaniel Vetterproperties, new files in sysfs or anything else that constitutes an API change 371badfa5beSDaniel Vettershould have driver-agnostic testcases in IGT for that feature, if such a test 372badfa5beSDaniel Vettercan be reasonably made using IGT for the target hardware. 373badfa5beSDaniel Vetter 37475ac4953STomeu VizosoValidating changes with IGT 375a8182863SDaniel Vetter--------------------------- 37675ac4953STomeu Vizoso 37775ac4953STomeu VizosoThere's a collection of tests that aims to cover the whole functionality of 37875ac4953STomeu VizosoDRM drivers and that can be used to check that changes to DRM drivers or the 37975ac4953STomeu Vizosocore don't regress existing functionality. This test suite is called IGT and 3808a537de0SLeandro Ribeiroits code and instructions to build and run can be found in 3818a537de0SLeandro Ribeirohttps://gitlab.freedesktop.org/drm/igt-gpu-tools/. 38275ac4953STomeu Vizoso 3836f91f44dSGabriela BittencourtUsing VKMS to test DRM API 3846f91f44dSGabriela Bittencourt-------------------------- 3856f91f44dSGabriela Bittencourt 3866f91f44dSGabriela BittencourtVKMS is a software-only model of a KMS driver that is useful for testing 3876f91f44dSGabriela Bittencourtand for running compositors. VKMS aims to enable a virtual display without 3886f91f44dSGabriela Bittencourtthe need for a hardware display capability. These characteristics made VKMS 3896f91f44dSGabriela Bittencourta perfect tool for validating the DRM core behavior and also support the 3906f91f44dSGabriela Bittencourtcompositor developer. VKMS makes it possible to test DRM functions in a 3916f91f44dSGabriela Bittencourtvirtual machine without display, simplifying the validation of some of the 3926f91f44dSGabriela Bittencourtcore changes. 3936f91f44dSGabriela Bittencourt 3946f91f44dSGabriela BittencourtTo Validate changes in DRM API with VKMS, start setting the kernel: make 3956f91f44dSGabriela Bittencourtsure to enable VKMS module; compile the kernel with the VKMS enabled and 3966f91f44dSGabriela Bittencourtinstall it in the target machine. VKMS can be run in a Virtual Machine 3976f91f44dSGabriela Bittencourt(QEMU, virtme or similar). It's recommended the use of KVM with the minimum 3986f91f44dSGabriela Bittencourtof 1GB of RAM and four cores. 3996f91f44dSGabriela Bittencourt 4006f91f44dSGabriela BittencourtIt's possible to run the IGT-tests in a VM in two ways: 4016f91f44dSGabriela Bittencourt 4026f91f44dSGabriela Bittencourt 1. Use IGT inside a VM 4036f91f44dSGabriela Bittencourt 2. Use IGT from the host machine and write the results in a shared directory. 4046f91f44dSGabriela Bittencourt 4056f91f44dSGabriela BittencourtFollowing is an example of using a VM with a shared directory with 4066f91f44dSGabriela Bittencourtthe host machine to run igt-tests. This example uses virtme:: 4076f91f44dSGabriela Bittencourt 4086f91f44dSGabriela Bittencourt $ virtme-run --rwdir /path/for/shared_dir --kdir=path/for/kernel/directory --mods=auto 4096f91f44dSGabriela Bittencourt 4106f91f44dSGabriela BittencourtRun the igt-tests in the guest machine. This example runs the 'kms_flip' 4116f91f44dSGabriela Bittencourttests:: 4126f91f44dSGabriela Bittencourt 4136f91f44dSGabriela Bittencourt $ /path/for/igt-gpu-tools/scripts/run-tests.sh -p -s -t "kms_flip.*" -v 4146f91f44dSGabriela Bittencourt 4156f91f44dSGabriela BittencourtIn this example, instead of building the igt_runner, Piglit is used 4166f91f44dSGabriela Bittencourt(-p option). It creates an HTML summary of the test results and saves 4176f91f44dSGabriela Bittencourtthem in the folder "igt-gpu-tools/results". It executes only the igt-tests 4186f91f44dSGabriela Bittencourtmatching the -t option. 4196f91f44dSGabriela Bittencourt 420a8182863SDaniel VetterDisplay CRC Support 421a8182863SDaniel Vetter------------------- 422a8182863SDaniel Vetter 423a8182863SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c 424a8182863SDaniel Vetter :doc: CRC ABI 425a8182863SDaniel Vetter 426760f71e7SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c 427760f71e7SDaniel Vetter :export: 428760f71e7SDaniel Vetter 4290cad7f71SDaniel VetterDebugfs Support 4300cad7f71SDaniel Vetter--------------- 4310cad7f71SDaniel Vetter 4320cad7f71SDaniel Vetter.. kernel-doc:: include/drm/drm_debugfs.h 4330cad7f71SDaniel Vetter :internal: 4340cad7f71SDaniel Vetter 4350cad7f71SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_debugfs.c 4360cad7f71SDaniel Vetter :export: 4370cad7f71SDaniel Vetter 438e2271704SDaniel VetterSysfs Support 439e2271704SDaniel Vetter============= 440e2271704SDaniel Vetter 441e2271704SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c 442e2271704SDaniel Vetter :doc: overview 443e2271704SDaniel Vetter 444e2271704SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c 445e2271704SDaniel Vetter :export: 446e2271704SDaniel Vetter 447e2271704SDaniel Vetter 448ca00c2b9SJani NikulaVBlank event handling 44922554020SJani Nikula===================== 450ca00c2b9SJani Nikula 451ca00c2b9SJani NikulaThe DRM core exposes two vertical blank related ioctls: 452ca00c2b9SJani Nikula 453ca00c2b9SJani NikulaDRM_IOCTL_WAIT_VBLANK 454ca00c2b9SJani Nikula This takes a struct drm_wait_vblank structure as its argument, and 455ca00c2b9SJani Nikula it is used to block or request a signal when a specified vblank 456ca00c2b9SJani Nikula event occurs. 457ca00c2b9SJani Nikula 458ca00c2b9SJani NikulaDRM_IOCTL_MODESET_CTL 459ca00c2b9SJani Nikula This was only used for user-mode-settind drivers around modesetting 460ca00c2b9SJani Nikula changes to allow the kernel to update the vblank interrupt after 461ca00c2b9SJani Nikula mode setting, since on many devices the vertical blank counter is 462ca00c2b9SJani Nikula reset to 0 at some point during modeset. Modern drivers should not 463ca00c2b9SJani Nikula call this any more since with kernel mode setting it is a no-op. 464309aa926SUma Shankar 465309aa926SUma ShankarUserspace API Structures 466309aa926SUma Shankar======================== 467309aa926SUma Shankar 468309aa926SUma Shankar.. kernel-doc:: include/uapi/drm/drm_mode.h 469309aa926SUma Shankar :doc: overview 470309aa926SUma Shankar 47126594678SLeandro Ribeiro.. _crtc_index: 47226594678SLeandro Ribeiro 47326594678SLeandro RibeiroCRTC index 47426594678SLeandro Ribeiro---------- 47526594678SLeandro Ribeiro 47626594678SLeandro RibeiroCRTC's have both an object ID and an index, and they are not the same thing. 47726594678SLeandro RibeiroThe index is used in cases where a densely packed identifier for a CRTC is 47826594678SLeandro Ribeironeeded, for instance a bitmask of CRTC's. The member possible_crtcs of struct 47926594678SLeandro Ribeirodrm_mode_get_plane is an example. 48026594678SLeandro Ribeiro 48126594678SLeandro RibeiroDRM_IOCTL_MODE_GETRESOURCES populates a structure with an array of CRTC ID's, 48226594678SLeandro Ribeiroand the CRTC index is its position in this array. 48326594678SLeandro Ribeiro 484cf9a4be4SSimon Ser.. kernel-doc:: include/uapi/drm/drm.h 485cf9a4be4SSimon Ser :internal: 486cf9a4be4SSimon Ser 487309aa926SUma Shankar.. kernel-doc:: include/uapi/drm/drm_mode.h 488309aa926SUma Shankar :internal: 489