162306a36Sopenharmony_ci.. Copyright 2020 DisplayLink (UK) Ltd. 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci=================== 462306a36Sopenharmony_ciUserland interfaces 562306a36Sopenharmony_ci=================== 662306a36Sopenharmony_ci 762306a36Sopenharmony_ciThe DRM core exports several interfaces to applications, generally 862306a36Sopenharmony_ciintended to be used through corresponding libdrm wrapper functions. In 962306a36Sopenharmony_ciaddition, drivers export device-specific interfaces for use by userspace 1062306a36Sopenharmony_cidrivers & device-aware applications through ioctls and sysfs files. 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciExternal interfaces include: memory mapping, context management, DMA 1362306a36Sopenharmony_cioperations, AGP management, vblank control, fence management, memory 1462306a36Sopenharmony_cimanagement, and output management. 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciCover generic ioctls and sysfs layout here. We only need high-level 1762306a36Sopenharmony_ciinfo, since man pages should cover the rest. 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cilibdrm Device Lookup 2062306a36Sopenharmony_ci==================== 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 2362306a36Sopenharmony_ci :doc: getunique and setversion story 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci.. _drm_primary_node: 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciPrimary Nodes, DRM Master and Authentication 2962306a36Sopenharmony_ci============================================ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_auth.c 3262306a36Sopenharmony_ci :doc: master and authentication 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_auth.c 3562306a36Sopenharmony_ci :export: 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci.. kernel-doc:: include/drm/drm_auth.h 3862306a36Sopenharmony_ci :internal: 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci.. _drm_leasing: 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ciDRM Display Resource Leasing 4462306a36Sopenharmony_ci============================ 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_lease.c 4762306a36Sopenharmony_ci :doc: drm leasing 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciOpen-Source Userspace Requirements 5062306a36Sopenharmony_ci================================== 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ciThe DRM subsystem has stricter requirements than most other kernel subsystems on 5362306a36Sopenharmony_ciwhat the userspace side for new uAPI needs to look like. This section here 5462306a36Sopenharmony_ciexplains what exactly those requirements are, and why they exist. 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciThe short summary is that any addition of DRM uAPI requires corresponding 5762306a36Sopenharmony_ciopen-sourced userspace patches, and those patches must be reviewed and ready for 5862306a36Sopenharmony_cimerging into a suitable and canonical upstream project. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ciGFX devices (both display and render/GPU side) are really complex bits of 6162306a36Sopenharmony_cihardware, with userspace and kernel by necessity having to work together really 6262306a36Sopenharmony_ciclosely. The interfaces, for rendering and modesetting, must be extremely wide 6362306a36Sopenharmony_ciand flexible, and therefore it is almost always impossible to precisely define 6462306a36Sopenharmony_cithem for every possible corner case. This in turn makes it really practically 6562306a36Sopenharmony_ciinfeasible to differentiate between behaviour that's required by userspace, and 6662306a36Sopenharmony_ciwhich must not be changed to avoid regressions, and behaviour which is only an 6762306a36Sopenharmony_ciaccidental artifact of the current implementation. 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ciWithout access to the full source code of all userspace users that means it 7062306a36Sopenharmony_cibecomes impossible to change the implementation details, since userspace could 7162306a36Sopenharmony_cidepend upon the accidental behaviour of the current implementation in minute 7262306a36Sopenharmony_cidetails. And debugging such regressions without access to source code is pretty 7362306a36Sopenharmony_cimuch impossible. As a consequence this means: 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci- The Linux kernel's "no regression" policy holds in practice only for 7662306a36Sopenharmony_ci open-source userspace of the DRM subsystem. DRM developers are perfectly fine 7762306a36Sopenharmony_ci if closed-source blob drivers in userspace use the same uAPI as the open 7862306a36Sopenharmony_ci drivers, but they must do so in the exact same way as the open drivers. 7962306a36Sopenharmony_ci Creative (ab)use of the interfaces will, and in the past routinely has, lead 8062306a36Sopenharmony_ci to breakage. 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci- Any new userspace interface must have an open-source implementation as 8362306a36Sopenharmony_ci demonstration vehicle. 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ciThe other reason for requiring open-source userspace is uAPI review. Since the 8662306a36Sopenharmony_cikernel and userspace parts of a GFX stack must work together so closely, code 8762306a36Sopenharmony_cireview can only assess whether a new interface achieves its goals by looking at 8862306a36Sopenharmony_ciboth sides. Making sure that the interface indeed covers the use-case fully 8962306a36Sopenharmony_cileads to a few additional requirements: 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci- The open-source userspace must not be a toy/test application, but the real 9262306a36Sopenharmony_ci thing. Specifically it needs to handle all the usual error and corner cases. 9362306a36Sopenharmony_ci These are often the places where new uAPI falls apart and hence essential to 9462306a36Sopenharmony_ci assess the fitness of a proposed interface. 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci- The userspace side must be fully reviewed and tested to the standards of that 9762306a36Sopenharmony_ci userspace project. For e.g. mesa this means piglit testcases and review on the 9862306a36Sopenharmony_ci mailing list. This is again to ensure that the new interface actually gets the 9962306a36Sopenharmony_ci job done. The userspace-side reviewer should also provide an Acked-by on the 10062306a36Sopenharmony_ci kernel uAPI patch indicating that they believe the proposed uAPI is sound and 10162306a36Sopenharmony_ci sufficiently documented and validated for userspace's consumption. 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci- The userspace patches must be against the canonical upstream, not some vendor 10462306a36Sopenharmony_ci fork. This is to make sure that no one cheats on the review and testing 10562306a36Sopenharmony_ci requirements by doing a quick fork. 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci- The kernel patch can only be merged after all the above requirements are met, 10862306a36Sopenharmony_ci but it **must** be merged to either drm-next or drm-misc-next **before** the 10962306a36Sopenharmony_ci userspace patches land. uAPI always flows from the kernel, doing things the 11062306a36Sopenharmony_ci other way round risks divergence of the uAPI definitions and header files. 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ciThese are fairly steep requirements, but have grown out from years of shared 11362306a36Sopenharmony_cipain and experience with uAPI added hastily, and almost always regretted about 11462306a36Sopenharmony_cijust as fast. GFX devices change really fast, requiring a paradigm shift and 11562306a36Sopenharmony_cientire new set of uAPI interfaces every few years at least. Together with the 11662306a36Sopenharmony_ciLinux kernel's guarantee to keep existing userspace running for 10+ years this 11762306a36Sopenharmony_ciis already rather painful for the DRM subsystem, with multiple different uAPIs 11862306a36Sopenharmony_cifor the same thing co-existing. If we add a few more complete mistakes into the 11962306a36Sopenharmony_cimix every year it would be entirely unmanageable. 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci.. _drm_render_node: 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ciRender nodes 12462306a36Sopenharmony_ci============ 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ciDRM core provides multiple character-devices for user-space to use. 12762306a36Sopenharmony_ciDepending on which device is opened, user-space can perform a different 12862306a36Sopenharmony_ciset of operations (mainly ioctls). The primary node is always created 12962306a36Sopenharmony_ciand called card<num>. Additionally, a currently unused control node, 13062306a36Sopenharmony_cicalled controlD<num> is also created. The primary node provides all 13162306a36Sopenharmony_cilegacy operations and historically was the only interface used by 13262306a36Sopenharmony_ciuserspace. With KMS, the control node was introduced. However, the 13362306a36Sopenharmony_ciplanned KMS control interface has never been written and so the control 13462306a36Sopenharmony_cinode stays unused to date. 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ciWith the increased use of offscreen renderers and GPGPU applications, 13762306a36Sopenharmony_ciclients no longer require running compositors or graphics servers to 13862306a36Sopenharmony_cimake use of a GPU. But the DRM API required unprivileged clients to 13962306a36Sopenharmony_ciauthenticate to a DRM-Master prior to getting GPU access. To avoid this 14062306a36Sopenharmony_cistep and to grant clients GPU access without authenticating, render 14162306a36Sopenharmony_cinodes were introduced. Render nodes solely serve render clients, that 14262306a36Sopenharmony_ciis, no modesetting or privileged ioctls can be issued on render nodes. 14362306a36Sopenharmony_ciOnly non-global rendering commands are allowed. If a driver supports 14462306a36Sopenharmony_cirender nodes, it must advertise it via the DRIVER_RENDER DRM driver 14562306a36Sopenharmony_cicapability. If not supported, the primary node must be used for render 14662306a36Sopenharmony_ciclients together with the legacy drmAuth authentication procedure. 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ciIf a driver advertises render node support, DRM core will create a 14962306a36Sopenharmony_ciseparate render node called renderD<num>. There will be one render node 15062306a36Sopenharmony_ciper device. No ioctls except PRIME-related ioctls will be allowed on 15162306a36Sopenharmony_cithis node. Especially GEM_OPEN will be explicitly prohibited. For a 15262306a36Sopenharmony_cicomplete list of driver-independent ioctls that can be used on render 15362306a36Sopenharmony_cinodes, see the ioctls marked DRM_RENDER_ALLOW in drm_ioctl.c Render 15462306a36Sopenharmony_cinodes are designed to avoid the buffer-leaks, which occur if clients 15562306a36Sopenharmony_ciguess the flink names or mmap offsets on the legacy interface. 15662306a36Sopenharmony_ciAdditionally to this basic interface, drivers must mark their 15762306a36Sopenharmony_cidriver-dependent render-only ioctls as DRM_RENDER_ALLOW so render 15862306a36Sopenharmony_ciclients can use them. Driver authors must be careful not to allow any 15962306a36Sopenharmony_ciprivileged ioctls on render nodes. 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ciWith render nodes, user-space can now control access to the render node 16262306a36Sopenharmony_civia basic file-system access-modes. A running graphics server which 16362306a36Sopenharmony_ciauthenticates clients on the privileged primary/legacy node is no longer 16462306a36Sopenharmony_cirequired. Instead, a client can open the render node and is immediately 16562306a36Sopenharmony_cigranted GPU access. Communication between clients (or servers) is done 16662306a36Sopenharmony_civia PRIME. FLINK from render node to legacy node is not supported. New 16762306a36Sopenharmony_ciclients must not use the insecure FLINK interface. 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ciBesides dropping all modeset/global ioctls, render nodes also drop the 17062306a36Sopenharmony_ciDRM-Master concept. There is no reason to associate render clients with 17162306a36Sopenharmony_cia DRM-Master as they are independent of any graphics server. Besides, 17262306a36Sopenharmony_cithey must work without any running master, anyway. Drivers must be able 17362306a36Sopenharmony_cito run without a master object if they support render nodes. If, on the 17462306a36Sopenharmony_ciother hand, a driver requires shared state between clients which is 17562306a36Sopenharmony_civisible to user-space and accessible beyond open-file boundaries, they 17662306a36Sopenharmony_cicannot support render nodes. 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ciDevice Hot-Unplug 17962306a36Sopenharmony_ci================= 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci.. note:: 18262306a36Sopenharmony_ci The following is the plan. Implementation is not there yet 18362306a36Sopenharmony_ci (2020 May). 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ciGraphics devices (display and/or render) may be connected via USB (e.g. 18662306a36Sopenharmony_cidisplay adapters or docking stations) or Thunderbolt (e.g. eGPU). An end 18762306a36Sopenharmony_ciuser is able to hot-unplug this kind of devices while they are being 18862306a36Sopenharmony_ciused, and expects that the very least the machine does not crash. Any 18962306a36Sopenharmony_cidamage from hot-unplugging a DRM device needs to be limited as much as 19062306a36Sopenharmony_cipossible and userspace must be given the chance to handle it if it wants 19162306a36Sopenharmony_cito. Ideally, unplugging a DRM device still lets a desktop continue to 19262306a36Sopenharmony_cirun, but that is going to need explicit support throughout the whole 19362306a36Sopenharmony_cigraphics stack: from kernel and userspace drivers, through display 19462306a36Sopenharmony_ciservers, via window system protocols, and in applications and libraries. 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ciOther scenarios that should lead to the same are: unrecoverable GPU 19762306a36Sopenharmony_cicrash, PCI device disappearing off the bus, or forced unbind of a driver 19862306a36Sopenharmony_cifrom the physical device. 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ciIn other words, from userspace perspective everything needs to keep on 20162306a36Sopenharmony_ciworking more or less, until userspace stops using the disappeared DRM 20262306a36Sopenharmony_cidevice and closes it completely. Userspace will learn of the device 20362306a36Sopenharmony_cidisappearance from the device removed uevent, ioctls returning ENODEV 20462306a36Sopenharmony_ci(or driver-specific ioctls returning driver-specific things), or open() 20562306a36Sopenharmony_cireturning ENXIO. 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ciOnly after userspace has closed all relevant DRM device and dmabuf file 20862306a36Sopenharmony_cidescriptors and removed all mmaps, the DRM driver can tear down its 20962306a36Sopenharmony_ciinstance for the device that no longer exists. If the same physical 21062306a36Sopenharmony_cidevice somehow comes back in the mean time, it shall be a new DRM 21162306a36Sopenharmony_cidevice. 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ciSimilar to PIDs, chardev minor numbers are not recycled immediately. A 21462306a36Sopenharmony_cinew DRM device always picks the next free minor number compared to the 21562306a36Sopenharmony_ciprevious one allocated, and wraps around when minor numbers are 21662306a36Sopenharmony_ciexhausted. 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ciThe goal raises at least the following requirements for the kernel and 21962306a36Sopenharmony_cidrivers. 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ciRequirements for KMS UAPI 22262306a36Sopenharmony_ci------------------------- 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci- KMS connectors must change their status to disconnected. 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci- Legacy modesets and pageflips, and atomic commits, both real and 22762306a36Sopenharmony_ci TEST_ONLY, and any other ioctls either fail with ENODEV or fake 22862306a36Sopenharmony_ci success. 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci- Pending non-blocking KMS operations deliver the DRM events userspace 23162306a36Sopenharmony_ci is expecting. This applies also to ioctls that faked success. 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci- open() on a device node whose underlying device has disappeared will 23462306a36Sopenharmony_ci fail with ENXIO. 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci- Attempting to create a DRM lease on a disappeared DRM device will 23762306a36Sopenharmony_ci fail with ENODEV. Existing DRM leases remain and work as listed 23862306a36Sopenharmony_ci above. 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ciRequirements for Render and Cross-Device UAPI 24162306a36Sopenharmony_ci--------------------------------------------- 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci- All GPU jobs that can no longer run must have their fences 24462306a36Sopenharmony_ci force-signalled to avoid inflicting hangs on userspace. 24562306a36Sopenharmony_ci The associated error code is ENODEV. 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci- Some userspace APIs already define what should happen when the device 24862306a36Sopenharmony_ci disappears (OpenGL, GL ES: `GL_KHR_robustness`_; `Vulkan`_: 24962306a36Sopenharmony_ci VK_ERROR_DEVICE_LOST; etc.). DRM drivers are free to implement this 25062306a36Sopenharmony_ci behaviour the way they see best, e.g. returning failures in 25162306a36Sopenharmony_ci driver-specific ioctls and handling those in userspace drivers, or 25262306a36Sopenharmony_ci rely on uevents, and so on. 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci- dmabuf which point to memory that has disappeared will either fail to 25562306a36Sopenharmony_ci import with ENODEV or continue to be successfully imported if it would 25662306a36Sopenharmony_ci have succeeded before the disappearance. See also about memory maps 25762306a36Sopenharmony_ci below for already imported dmabufs. 25862306a36Sopenharmony_ci 25962306a36Sopenharmony_ci- Attempting to import a dmabuf to a disappeared device will either fail 26062306a36Sopenharmony_ci with ENODEV or succeed if it would have succeeded without the 26162306a36Sopenharmony_ci disappearance. 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ci- open() on a device node whose underlying device has disappeared will 26462306a36Sopenharmony_ci fail with ENXIO. 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci.. _GL_KHR_robustness: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_robustness.txt 26762306a36Sopenharmony_ci.. _Vulkan: https://www.khronos.org/vulkan/ 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ciRequirements for Memory Maps 27062306a36Sopenharmony_ci---------------------------- 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ciMemory maps have further requirements that apply to both existing maps 27362306a36Sopenharmony_ciand maps created after the device has disappeared. If the underlying 27462306a36Sopenharmony_cimemory disappears, the map is created or modified such that reads and 27562306a36Sopenharmony_ciwrites will still complete successfully but the result is undefined. 27662306a36Sopenharmony_ciThis applies to both userspace mmap()'d memory and memory pointed to by 27762306a36Sopenharmony_cidmabuf which might be mapped to other devices (cross-device dmabuf 27862306a36Sopenharmony_ciimports). 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ciRaising SIGBUS is not an option, because userspace cannot realistically 28162306a36Sopenharmony_cihandle it. Signal handlers are global, which makes them extremely 28262306a36Sopenharmony_cidifficult to use correctly from libraries like those that Mesa produces. 28362306a36Sopenharmony_ciSignal handlers are not composable, you can't have different handlers 28462306a36Sopenharmony_cifor GPU1 and GPU2 from different vendors, and a third handler for 28562306a36Sopenharmony_cimmapped regular files. Threads cause additional pain with signal 28662306a36Sopenharmony_cihandling as well. 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci.. _drm_driver_ioctl: 28962306a36Sopenharmony_ci 29062306a36Sopenharmony_ciIOCTL Support on Device Nodes 29162306a36Sopenharmony_ci============================= 29262306a36Sopenharmony_ci 29362306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 29462306a36Sopenharmony_ci :doc: driver specific ioctls 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ciRecommended IOCTL Return Values 29762306a36Sopenharmony_ci------------------------------- 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ciIn theory a driver's IOCTL callback is only allowed to return very few error 30062306a36Sopenharmony_cicodes. In practice it's good to abuse a few more. This section documents common 30162306a36Sopenharmony_cipractice within the DRM subsystem: 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ciENOENT: 30462306a36Sopenharmony_ci Strictly this should only be used when a file doesn't exist e.g. when 30562306a36Sopenharmony_ci calling the open() syscall. We reuse that to signal any kind of object 30662306a36Sopenharmony_ci lookup failure, e.g. for unknown GEM buffer object handles, unknown KMS 30762306a36Sopenharmony_ci object handles and similar cases. 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ciENOSPC: 31062306a36Sopenharmony_ci Some drivers use this to differentiate "out of kernel memory" from "out 31162306a36Sopenharmony_ci of VRAM". Sometimes also applies to other limited gpu resources used for 31262306a36Sopenharmony_ci rendering (e.g. when you have a special limited compression buffer). 31362306a36Sopenharmony_ci Sometimes resource allocation/reservation issues in command submission 31462306a36Sopenharmony_ci IOCTLs are also signalled through EDEADLK. 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_ci Simply running out of kernel/system memory is signalled through ENOMEM. 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ciEPERM/EACCES: 31962306a36Sopenharmony_ci Returned for an operation that is valid, but needs more privileges. 32062306a36Sopenharmony_ci E.g. root-only or much more common, DRM master-only operations return 32162306a36Sopenharmony_ci this when called by unpriviledged clients. There's no clear 32262306a36Sopenharmony_ci difference between EACCES and EPERM. 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ciENODEV: 32562306a36Sopenharmony_ci The device is not present anymore or is not yet fully initialized. 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ciEOPNOTSUPP: 32862306a36Sopenharmony_ci Feature (like PRIME, modesetting, GEM) is not supported by the driver. 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ciENXIO: 33162306a36Sopenharmony_ci Remote failure, either a hardware transaction (like i2c), but also used 33262306a36Sopenharmony_ci when the exporting driver of a shared dma-buf or fence doesn't support a 33362306a36Sopenharmony_ci feature needed. 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ciEINTR: 33662306a36Sopenharmony_ci DRM drivers assume that userspace restarts all IOCTLs. Any DRM IOCTL can 33762306a36Sopenharmony_ci return EINTR and in such a case should be restarted with the IOCTL 33862306a36Sopenharmony_ci parameters left unchanged. 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ciEIO: 34162306a36Sopenharmony_ci The GPU died and couldn't be resurrected through a reset. Modesetting 34262306a36Sopenharmony_ci hardware failures are signalled through the "link status" connector 34362306a36Sopenharmony_ci property. 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ciEINVAL: 34662306a36Sopenharmony_ci Catch-all for anything that is an invalid argument combination which 34762306a36Sopenharmony_ci cannot work. 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ciIOCTL also use other error codes like ETIME, EFAULT, EBUSY, ENOTTY but their 35062306a36Sopenharmony_ciusage is in line with the common meanings. The above list tries to just document 35162306a36Sopenharmony_ciDRM specific patterns. Note that ENOTTY has the slightly unintuitive meaning of 35262306a36Sopenharmony_ci"this IOCTL does not exist", and is used exactly as such in DRM. 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci.. kernel-doc:: include/drm/drm_ioctl.h 35562306a36Sopenharmony_ci :internal: 35662306a36Sopenharmony_ci 35762306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 35862306a36Sopenharmony_ci :export: 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioc32.c 36162306a36Sopenharmony_ci :export: 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ciTesting and validation 36462306a36Sopenharmony_ci====================== 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_ciTesting Requirements for userspace API 36762306a36Sopenharmony_ci-------------------------------------- 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ciNew cross-driver userspace interface extensions, like new IOCTL, new KMS 37062306a36Sopenharmony_ciproperties, new files in sysfs or anything else that constitutes an API change 37162306a36Sopenharmony_cishould have driver-agnostic testcases in IGT for that feature, if such a test 37262306a36Sopenharmony_cican be reasonably made using IGT for the target hardware. 37362306a36Sopenharmony_ci 37462306a36Sopenharmony_ciValidating changes with IGT 37562306a36Sopenharmony_ci--------------------------- 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_ciThere's a collection of tests that aims to cover the whole functionality of 37862306a36Sopenharmony_ciDRM drivers and that can be used to check that changes to DRM drivers or the 37962306a36Sopenharmony_cicore don't regress existing functionality. This test suite is called IGT and 38062306a36Sopenharmony_ciits code and instructions to build and run can be found in 38162306a36Sopenharmony_cihttps://gitlab.freedesktop.org/drm/igt-gpu-tools/. 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ciUsing VKMS to test DRM API 38462306a36Sopenharmony_ci-------------------------- 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_ciVKMS is a software-only model of a KMS driver that is useful for testing 38762306a36Sopenharmony_ciand for running compositors. VKMS aims to enable a virtual display without 38862306a36Sopenharmony_cithe need for a hardware display capability. These characteristics made VKMS 38962306a36Sopenharmony_cia perfect tool for validating the DRM core behavior and also support the 39062306a36Sopenharmony_cicompositor developer. VKMS makes it possible to test DRM functions in a 39162306a36Sopenharmony_civirtual machine without display, simplifying the validation of some of the 39262306a36Sopenharmony_cicore changes. 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ciTo Validate changes in DRM API with VKMS, start setting the kernel: make 39562306a36Sopenharmony_cisure to enable VKMS module; compile the kernel with the VKMS enabled and 39662306a36Sopenharmony_ciinstall it in the target machine. VKMS can be run in a Virtual Machine 39762306a36Sopenharmony_ci(QEMU, virtme or similar). It's recommended the use of KVM with the minimum 39862306a36Sopenharmony_ciof 1GB of RAM and four cores. 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_ciIt's possible to run the IGT-tests in a VM in two ways: 40162306a36Sopenharmony_ci 40262306a36Sopenharmony_ci 1. Use IGT inside a VM 40362306a36Sopenharmony_ci 2. Use IGT from the host machine and write the results in a shared directory. 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ciFollowing is an example of using a VM with a shared directory with 40662306a36Sopenharmony_cithe host machine to run igt-tests. This example uses virtme:: 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ci $ virtme-run --rwdir /path/for/shared_dir --kdir=path/for/kernel/directory --mods=auto 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ciRun the igt-tests in the guest machine. This example runs the 'kms_flip' 41162306a36Sopenharmony_citests:: 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci $ /path/for/igt-gpu-tools/scripts/run-tests.sh -p -s -t "kms_flip.*" -v 41462306a36Sopenharmony_ci 41562306a36Sopenharmony_ciIn this example, instead of building the igt_runner, Piglit is used 41662306a36Sopenharmony_ci(-p option). It creates an HTML summary of the test results and saves 41762306a36Sopenharmony_cithem in the folder "igt-gpu-tools/results". It executes only the igt-tests 41862306a36Sopenharmony_cimatching the -t option. 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_ciDisplay CRC Support 42162306a36Sopenharmony_ci------------------- 42262306a36Sopenharmony_ci 42362306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c 42462306a36Sopenharmony_ci :doc: CRC ABI 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c 42762306a36Sopenharmony_ci :export: 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ciDebugfs Support 43062306a36Sopenharmony_ci--------------- 43162306a36Sopenharmony_ci 43262306a36Sopenharmony_ci.. kernel-doc:: include/drm/drm_debugfs.h 43362306a36Sopenharmony_ci :internal: 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_debugfs.c 43662306a36Sopenharmony_ci :export: 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_ciSysfs Support 43962306a36Sopenharmony_ci============= 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c 44262306a36Sopenharmony_ci :doc: overview 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c 44562306a36Sopenharmony_ci :export: 44662306a36Sopenharmony_ci 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ciVBlank event handling 44962306a36Sopenharmony_ci===================== 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ciThe DRM core exposes two vertical blank related ioctls: 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ciDRM_IOCTL_WAIT_VBLANK 45462306a36Sopenharmony_ci This takes a struct drm_wait_vblank structure as its argument, and 45562306a36Sopenharmony_ci it is used to block or request a signal when a specified vblank 45662306a36Sopenharmony_ci event occurs. 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ciDRM_IOCTL_MODESET_CTL 45962306a36Sopenharmony_ci This was only used for user-mode-settind drivers around modesetting 46062306a36Sopenharmony_ci changes to allow the kernel to update the vblank interrupt after 46162306a36Sopenharmony_ci mode setting, since on many devices the vertical blank counter is 46262306a36Sopenharmony_ci reset to 0 at some point during modeset. Modern drivers should not 46362306a36Sopenharmony_ci call this any more since with kernel mode setting it is a no-op. 46462306a36Sopenharmony_ci 46562306a36Sopenharmony_ciUserspace API Structures 46662306a36Sopenharmony_ci======================== 46762306a36Sopenharmony_ci 46862306a36Sopenharmony_ci.. kernel-doc:: include/uapi/drm/drm_mode.h 46962306a36Sopenharmony_ci :doc: overview 47062306a36Sopenharmony_ci 47162306a36Sopenharmony_ci.. _crtc_index: 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ciCRTC index 47462306a36Sopenharmony_ci---------- 47562306a36Sopenharmony_ci 47662306a36Sopenharmony_ciCRTC's have both an object ID and an index, and they are not the same thing. 47762306a36Sopenharmony_ciThe index is used in cases where a densely packed identifier for a CRTC is 47862306a36Sopenharmony_cineeded, for instance a bitmask of CRTC's. The member possible_crtcs of struct 47962306a36Sopenharmony_cidrm_mode_get_plane is an example. 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ciDRM_IOCTL_MODE_GETRESOURCES populates a structure with an array of CRTC ID's, 48262306a36Sopenharmony_ciand the CRTC index is its position in this array. 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_ci.. kernel-doc:: include/uapi/drm/drm.h 48562306a36Sopenharmony_ci :internal: 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci.. kernel-doc:: include/uapi/drm/drm_mode.h 48862306a36Sopenharmony_ci :internal: 489