18c2ecf20Sopenharmony_ci.. Copyright 2020 DisplayLink (UK) Ltd.
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci===================
48c2ecf20Sopenharmony_ciUserland interfaces
58c2ecf20Sopenharmony_ci===================
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciThe DRM core exports several interfaces to applications, generally
88c2ecf20Sopenharmony_ciintended to be used through corresponding libdrm wrapper functions. In
98c2ecf20Sopenharmony_ciaddition, drivers export device-specific interfaces for use by userspace
108c2ecf20Sopenharmony_cidrivers & device-aware applications through ioctls and sysfs files.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciExternal interfaces include: memory mapping, context management, DMA
138c2ecf20Sopenharmony_cioperations, AGP management, vblank control, fence management, memory
148c2ecf20Sopenharmony_cimanagement, and output management.
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ciCover generic ioctls and sysfs layout here. We only need high-level
178c2ecf20Sopenharmony_ciinfo, since man pages should cover the rest.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cilibdrm Device Lookup
208c2ecf20Sopenharmony_ci====================
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
238c2ecf20Sopenharmony_ci   :doc: getunique and setversion story
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci.. _drm_primary_node:
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciPrimary Nodes, DRM Master and Authentication
298c2ecf20Sopenharmony_ci============================================
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_auth.c
328c2ecf20Sopenharmony_ci   :doc: master and authentication
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_auth.c
358c2ecf20Sopenharmony_ci   :export:
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci.. kernel-doc:: include/drm/drm_auth.h
388c2ecf20Sopenharmony_ci   :internal:
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciOpen-Source Userspace Requirements
418c2ecf20Sopenharmony_ci==================================
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThe DRM subsystem has stricter requirements than most other kernel subsystems on
448c2ecf20Sopenharmony_ciwhat the userspace side for new uAPI needs to look like. This section here
458c2ecf20Sopenharmony_ciexplains what exactly those requirements are, and why they exist.
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciThe short summary is that any addition of DRM uAPI requires corresponding
488c2ecf20Sopenharmony_ciopen-sourced userspace patches, and those patches must be reviewed and ready for
498c2ecf20Sopenharmony_cimerging into a suitable and canonical upstream project.
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ciGFX devices (both display and render/GPU side) are really complex bits of
528c2ecf20Sopenharmony_cihardware, with userspace and kernel by necessity having to work together really
538c2ecf20Sopenharmony_ciclosely.  The interfaces, for rendering and modesetting, must be extremely wide
548c2ecf20Sopenharmony_ciand flexible, and therefore it is almost always impossible to precisely define
558c2ecf20Sopenharmony_cithem for every possible corner case. This in turn makes it really practically
568c2ecf20Sopenharmony_ciinfeasible to differentiate between behaviour that's required by userspace, and
578c2ecf20Sopenharmony_ciwhich must not be changed to avoid regressions, and behaviour which is only an
588c2ecf20Sopenharmony_ciaccidental artifact of the current implementation.
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciWithout access to the full source code of all userspace users that means it
618c2ecf20Sopenharmony_cibecomes impossible to change the implementation details, since userspace could
628c2ecf20Sopenharmony_cidepend upon the accidental behaviour of the current implementation in minute
638c2ecf20Sopenharmony_cidetails. And debugging such regressions without access to source code is pretty
648c2ecf20Sopenharmony_cimuch impossible. As a consequence this means:
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci- The Linux kernel's "no regression" policy holds in practice only for
678c2ecf20Sopenharmony_ci  open-source userspace of the DRM subsystem. DRM developers are perfectly fine
688c2ecf20Sopenharmony_ci  if closed-source blob drivers in userspace use the same uAPI as the open
698c2ecf20Sopenharmony_ci  drivers, but they must do so in the exact same way as the open drivers.
708c2ecf20Sopenharmony_ci  Creative (ab)use of the interfaces will, and in the past routinely has, lead
718c2ecf20Sopenharmony_ci  to breakage.
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci- Any new userspace interface must have an open-source implementation as
748c2ecf20Sopenharmony_ci  demonstration vehicle.
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ciThe other reason for requiring open-source userspace is uAPI review. Since the
778c2ecf20Sopenharmony_cikernel and userspace parts of a GFX stack must work together so closely, code
788c2ecf20Sopenharmony_cireview can only assess whether a new interface achieves its goals by looking at
798c2ecf20Sopenharmony_ciboth sides. Making sure that the interface indeed covers the use-case fully
808c2ecf20Sopenharmony_cileads to a few additional requirements:
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci- The open-source userspace must not be a toy/test application, but the real
838c2ecf20Sopenharmony_ci  thing. Specifically it needs to handle all the usual error and corner cases.
848c2ecf20Sopenharmony_ci  These are often the places where new uAPI falls apart and hence essential to
858c2ecf20Sopenharmony_ci  assess the fitness of a proposed interface.
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci- The userspace side must be fully reviewed and tested to the standards of that
888c2ecf20Sopenharmony_ci  userspace project. For e.g. mesa this means piglit testcases and review on the
898c2ecf20Sopenharmony_ci  mailing list. This is again to ensure that the new interface actually gets the
908c2ecf20Sopenharmony_ci  job done.  The userspace-side reviewer should also provide an Acked-by on the
918c2ecf20Sopenharmony_ci  kernel uAPI patch indicating that they believe the proposed uAPI is sound and
928c2ecf20Sopenharmony_ci  sufficiently documented and validated for userspace's consumption.
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci- The userspace patches must be against the canonical upstream, not some vendor
958c2ecf20Sopenharmony_ci  fork. This is to make sure that no one cheats on the review and testing
968c2ecf20Sopenharmony_ci  requirements by doing a quick fork.
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci- The kernel patch can only be merged after all the above requirements are met,
998c2ecf20Sopenharmony_ci  but it **must** be merged to either drm-next or drm-misc-next **before** the
1008c2ecf20Sopenharmony_ci  userspace patches land. uAPI always flows from the kernel, doing things the
1018c2ecf20Sopenharmony_ci  other way round risks divergence of the uAPI definitions and header files.
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ciThese are fairly steep requirements, but have grown out from years of shared
1048c2ecf20Sopenharmony_cipain and experience with uAPI added hastily, and almost always regretted about
1058c2ecf20Sopenharmony_cijust as fast. GFX devices change really fast, requiring a paradigm shift and
1068c2ecf20Sopenharmony_cientire new set of uAPI interfaces every few years at least. Together with the
1078c2ecf20Sopenharmony_ciLinux kernel's guarantee to keep existing userspace running for 10+ years this
1088c2ecf20Sopenharmony_ciis already rather painful for the DRM subsystem, with multiple different uAPIs
1098c2ecf20Sopenharmony_cifor the same thing co-existing. If we add a few more complete mistakes into the
1108c2ecf20Sopenharmony_cimix every year it would be entirely unmanageable.
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci.. _drm_render_node:
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ciRender nodes
1158c2ecf20Sopenharmony_ci============
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ciDRM core provides multiple character-devices for user-space to use.
1188c2ecf20Sopenharmony_ciDepending on which device is opened, user-space can perform a different
1198c2ecf20Sopenharmony_ciset of operations (mainly ioctls). The primary node is always created
1208c2ecf20Sopenharmony_ciand called card<num>. Additionally, a currently unused control node,
1218c2ecf20Sopenharmony_cicalled controlD<num> is also created. The primary node provides all
1228c2ecf20Sopenharmony_cilegacy operations and historically was the only interface used by
1238c2ecf20Sopenharmony_ciuserspace. With KMS, the control node was introduced. However, the
1248c2ecf20Sopenharmony_ciplanned KMS control interface has never been written and so the control
1258c2ecf20Sopenharmony_cinode stays unused to date.
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciWith the increased use of offscreen renderers and GPGPU applications,
1288c2ecf20Sopenharmony_ciclients no longer require running compositors or graphics servers to
1298c2ecf20Sopenharmony_cimake use of a GPU. But the DRM API required unprivileged clients to
1308c2ecf20Sopenharmony_ciauthenticate to a DRM-Master prior to getting GPU access. To avoid this
1318c2ecf20Sopenharmony_cistep and to grant clients GPU access without authenticating, render
1328c2ecf20Sopenharmony_cinodes were introduced. Render nodes solely serve render clients, that
1338c2ecf20Sopenharmony_ciis, no modesetting or privileged ioctls can be issued on render nodes.
1348c2ecf20Sopenharmony_ciOnly non-global rendering commands are allowed. If a driver supports
1358c2ecf20Sopenharmony_cirender nodes, it must advertise it via the DRIVER_RENDER DRM driver
1368c2ecf20Sopenharmony_cicapability. If not supported, the primary node must be used for render
1378c2ecf20Sopenharmony_ciclients together with the legacy drmAuth authentication procedure.
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciIf a driver advertises render node support, DRM core will create a
1408c2ecf20Sopenharmony_ciseparate render node called renderD<num>. There will be one render node
1418c2ecf20Sopenharmony_ciper device. No ioctls except PRIME-related ioctls will be allowed on
1428c2ecf20Sopenharmony_cithis node. Especially GEM_OPEN will be explicitly prohibited. Render
1438c2ecf20Sopenharmony_cinodes are designed to avoid the buffer-leaks, which occur if clients
1448c2ecf20Sopenharmony_ciguess the flink names or mmap offsets on the legacy interface.
1458c2ecf20Sopenharmony_ciAdditionally to this basic interface, drivers must mark their
1468c2ecf20Sopenharmony_cidriver-dependent render-only ioctls as DRM_RENDER_ALLOW so render
1478c2ecf20Sopenharmony_ciclients can use them. Driver authors must be careful not to allow any
1488c2ecf20Sopenharmony_ciprivileged ioctls on render nodes.
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciWith render nodes, user-space can now control access to the render node
1518c2ecf20Sopenharmony_civia basic file-system access-modes. A running graphics server which
1528c2ecf20Sopenharmony_ciauthenticates clients on the privileged primary/legacy node is no longer
1538c2ecf20Sopenharmony_cirequired. Instead, a client can open the render node and is immediately
1548c2ecf20Sopenharmony_cigranted GPU access. Communication between clients (or servers) is done
1558c2ecf20Sopenharmony_civia PRIME. FLINK from render node to legacy node is not supported. New
1568c2ecf20Sopenharmony_ciclients must not use the insecure FLINK interface.
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciBesides dropping all modeset/global ioctls, render nodes also drop the
1598c2ecf20Sopenharmony_ciDRM-Master concept. There is no reason to associate render clients with
1608c2ecf20Sopenharmony_cia DRM-Master as they are independent of any graphics server. Besides,
1618c2ecf20Sopenharmony_cithey must work without any running master, anyway. Drivers must be able
1628c2ecf20Sopenharmony_cito run without a master object if they support render nodes. If, on the
1638c2ecf20Sopenharmony_ciother hand, a driver requires shared state between clients which is
1648c2ecf20Sopenharmony_civisible to user-space and accessible beyond open-file boundaries, they
1658c2ecf20Sopenharmony_cicannot support render nodes.
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ciDevice Hot-Unplug
1688c2ecf20Sopenharmony_ci=================
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci.. note::
1718c2ecf20Sopenharmony_ci   The following is the plan. Implementation is not there yet
1728c2ecf20Sopenharmony_ci   (2020 May).
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ciGraphics devices (display and/or render) may be connected via USB (e.g.
1758c2ecf20Sopenharmony_cidisplay adapters or docking stations) or Thunderbolt (e.g. eGPU). An end
1768c2ecf20Sopenharmony_ciuser is able to hot-unplug this kind of devices while they are being
1778c2ecf20Sopenharmony_ciused, and expects that the very least the machine does not crash. Any
1788c2ecf20Sopenharmony_cidamage from hot-unplugging a DRM device needs to be limited as much as
1798c2ecf20Sopenharmony_cipossible and userspace must be given the chance to handle it if it wants
1808c2ecf20Sopenharmony_cito. Ideally, unplugging a DRM device still lets a desktop continue to
1818c2ecf20Sopenharmony_cirun, but that is going to need explicit support throughout the whole
1828c2ecf20Sopenharmony_cigraphics stack: from kernel and userspace drivers, through display
1838c2ecf20Sopenharmony_ciservers, via window system protocols, and in applications and libraries.
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ciOther scenarios that should lead to the same are: unrecoverable GPU
1868c2ecf20Sopenharmony_cicrash, PCI device disappearing off the bus, or forced unbind of a driver
1878c2ecf20Sopenharmony_cifrom the physical device.
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ciIn other words, from userspace perspective everything needs to keep on
1908c2ecf20Sopenharmony_ciworking more or less, until userspace stops using the disappeared DRM
1918c2ecf20Sopenharmony_cidevice and closes it completely. Userspace will learn of the device
1928c2ecf20Sopenharmony_cidisappearance from the device removed uevent, ioctls returning ENODEV
1938c2ecf20Sopenharmony_ci(or driver-specific ioctls returning driver-specific things), or open()
1948c2ecf20Sopenharmony_cireturning ENXIO.
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ciOnly after userspace has closed all relevant DRM device and dmabuf file
1978c2ecf20Sopenharmony_cidescriptors and removed all mmaps, the DRM driver can tear down its
1988c2ecf20Sopenharmony_ciinstance for the device that no longer exists. If the same physical
1998c2ecf20Sopenharmony_cidevice somehow comes back in the mean time, it shall be a new DRM
2008c2ecf20Sopenharmony_cidevice.
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ciSimilar to PIDs, chardev minor numbers are not recycled immediately. A
2038c2ecf20Sopenharmony_cinew DRM device always picks the next free minor number compared to the
2048c2ecf20Sopenharmony_ciprevious one allocated, and wraps around when minor numbers are
2058c2ecf20Sopenharmony_ciexhausted.
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ciThe goal raises at least the following requirements for the kernel and
2088c2ecf20Sopenharmony_cidrivers.
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ciRequirements for KMS UAPI
2118c2ecf20Sopenharmony_ci-------------------------
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci- KMS connectors must change their status to disconnected.
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci- Legacy modesets and pageflips, and atomic commits, both real and
2168c2ecf20Sopenharmony_ci  TEST_ONLY, and any other ioctls either fail with ENODEV or fake
2178c2ecf20Sopenharmony_ci  success.
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci- Pending non-blocking KMS operations deliver the DRM events userspace
2208c2ecf20Sopenharmony_ci  is expecting. This applies also to ioctls that faked success.
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci- open() on a device node whose underlying device has disappeared will
2238c2ecf20Sopenharmony_ci  fail with ENXIO.
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci- Attempting to create a DRM lease on a disappeared DRM device will
2268c2ecf20Sopenharmony_ci  fail with ENODEV. Existing DRM leases remain and work as listed
2278c2ecf20Sopenharmony_ci  above.
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ciRequirements for Render and Cross-Device UAPI
2308c2ecf20Sopenharmony_ci---------------------------------------------
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci- All GPU jobs that can no longer run must have their fences
2338c2ecf20Sopenharmony_ci  force-signalled to avoid inflicting hangs on userspace.
2348c2ecf20Sopenharmony_ci  The associated error code is ENODEV.
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci- Some userspace APIs already define what should happen when the device
2378c2ecf20Sopenharmony_ci  disappears (OpenGL, GL ES: `GL_KHR_robustness`_; `Vulkan`_:
2388c2ecf20Sopenharmony_ci  VK_ERROR_DEVICE_LOST; etc.). DRM drivers are free to implement this
2398c2ecf20Sopenharmony_ci  behaviour the way they see best, e.g. returning failures in
2408c2ecf20Sopenharmony_ci  driver-specific ioctls and handling those in userspace drivers, or
2418c2ecf20Sopenharmony_ci  rely on uevents, and so on.
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci- dmabuf which point to memory that has disappeared will either fail to
2448c2ecf20Sopenharmony_ci  import with ENODEV or continue to be successfully imported if it would
2458c2ecf20Sopenharmony_ci  have succeeded before the disappearance. See also about memory maps
2468c2ecf20Sopenharmony_ci  below for already imported dmabufs.
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci- Attempting to import a dmabuf to a disappeared device will either fail
2498c2ecf20Sopenharmony_ci  with ENODEV or succeed if it would have succeeded without the
2508c2ecf20Sopenharmony_ci  disappearance.
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci- open() on a device node whose underlying device has disappeared will
2538c2ecf20Sopenharmony_ci  fail with ENXIO.
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci.. _GL_KHR_robustness: https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_robustness.txt
2568c2ecf20Sopenharmony_ci.. _Vulkan: https://www.khronos.org/vulkan/
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ciRequirements for Memory Maps
2598c2ecf20Sopenharmony_ci----------------------------
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ciMemory maps have further requirements that apply to both existing maps
2628c2ecf20Sopenharmony_ciand maps created after the device has disappeared. If the underlying
2638c2ecf20Sopenharmony_cimemory disappears, the map is created or modified such that reads and
2648c2ecf20Sopenharmony_ciwrites will still complete successfully but the result is undefined.
2658c2ecf20Sopenharmony_ciThis applies to both userspace mmap()'d memory and memory pointed to by
2668c2ecf20Sopenharmony_cidmabuf which might be mapped to other devices (cross-device dmabuf
2678c2ecf20Sopenharmony_ciimports).
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ciRaising SIGBUS is not an option, because userspace cannot realistically
2708c2ecf20Sopenharmony_cihandle it. Signal handlers are global, which makes them extremely
2718c2ecf20Sopenharmony_cidifficult to use correctly from libraries like those that Mesa produces.
2728c2ecf20Sopenharmony_ciSignal handlers are not composable, you can't have different handlers
2738c2ecf20Sopenharmony_cifor GPU1 and GPU2 from different vendors, and a third handler for
2748c2ecf20Sopenharmony_cimmapped regular files. Threads cause additional pain with signal
2758c2ecf20Sopenharmony_cihandling as well.
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci.. _drm_driver_ioctl:
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ciIOCTL Support on Device Nodes
2808c2ecf20Sopenharmony_ci=============================
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
2838c2ecf20Sopenharmony_ci   :doc: driver specific ioctls
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ciRecommended IOCTL Return Values
2868c2ecf20Sopenharmony_ci-------------------------------
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ciIn theory a driver's IOCTL callback is only allowed to return very few error
2898c2ecf20Sopenharmony_cicodes. In practice it's good to abuse a few more. This section documents common
2908c2ecf20Sopenharmony_cipractice within the DRM subsystem:
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ciENOENT:
2938c2ecf20Sopenharmony_ci        Strictly this should only be used when a file doesn't exist e.g. when
2948c2ecf20Sopenharmony_ci        calling the open() syscall. We reuse that to signal any kind of object
2958c2ecf20Sopenharmony_ci        lookup failure, e.g. for unknown GEM buffer object handles, unknown KMS
2968c2ecf20Sopenharmony_ci        object handles and similar cases.
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ciENOSPC:
2998c2ecf20Sopenharmony_ci        Some drivers use this to differentiate "out of kernel memory" from "out
3008c2ecf20Sopenharmony_ci        of VRAM". Sometimes also applies to other limited gpu resources used for
3018c2ecf20Sopenharmony_ci        rendering (e.g. when you have a special limited compression buffer).
3028c2ecf20Sopenharmony_ci        Sometimes resource allocation/reservation issues in command submission
3038c2ecf20Sopenharmony_ci        IOCTLs are also signalled through EDEADLK.
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci        Simply running out of kernel/system memory is signalled through ENOMEM.
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ciEPERM/EACCES:
3088c2ecf20Sopenharmony_ci        Returned for an operation that is valid, but needs more privileges.
3098c2ecf20Sopenharmony_ci        E.g. root-only or much more common, DRM master-only operations return
3108c2ecf20Sopenharmony_ci        this when called by unpriviledged clients. There's no clear
3118c2ecf20Sopenharmony_ci        difference between EACCES and EPERM.
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ciENODEV:
3148c2ecf20Sopenharmony_ci        The device is not present anymore or is not yet fully initialized.
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ciEOPNOTSUPP:
3178c2ecf20Sopenharmony_ci        Feature (like PRIME, modesetting, GEM) is not supported by the driver.
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ciENXIO:
3208c2ecf20Sopenharmony_ci        Remote failure, either a hardware transaction (like i2c), but also used
3218c2ecf20Sopenharmony_ci        when the exporting driver of a shared dma-buf or fence doesn't support a
3228c2ecf20Sopenharmony_ci        feature needed.
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ciEINTR:
3258c2ecf20Sopenharmony_ci        DRM drivers assume that userspace restarts all IOCTLs. Any DRM IOCTL can
3268c2ecf20Sopenharmony_ci        return EINTR and in such a case should be restarted with the IOCTL
3278c2ecf20Sopenharmony_ci        parameters left unchanged.
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ciEIO:
3308c2ecf20Sopenharmony_ci        The GPU died and couldn't be resurrected through a reset. Modesetting
3318c2ecf20Sopenharmony_ci        hardware failures are signalled through the "link status" connector
3328c2ecf20Sopenharmony_ci        property.
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ciEINVAL:
3358c2ecf20Sopenharmony_ci        Catch-all for anything that is an invalid argument combination which
3368c2ecf20Sopenharmony_ci        cannot work.
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ciIOCTL also use other error codes like ETIME, EFAULT, EBUSY, ENOTTY but their
3398c2ecf20Sopenharmony_ciusage is in line with the common meanings. The above list tries to just document
3408c2ecf20Sopenharmony_ciDRM specific patterns. Note that ENOTTY has the slightly unintuitive meaning of
3418c2ecf20Sopenharmony_ci"this IOCTL does not exist", and is used exactly as such in DRM.
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci.. kernel-doc:: include/drm/drm_ioctl.h
3448c2ecf20Sopenharmony_ci   :internal:
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
3478c2ecf20Sopenharmony_ci   :export:
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_ioc32.c
3508c2ecf20Sopenharmony_ci   :export:
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ciTesting and validation
3538c2ecf20Sopenharmony_ci======================
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ciTesting Requirements for userspace API
3568c2ecf20Sopenharmony_ci--------------------------------------
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ciNew cross-driver userspace interface extensions, like new IOCTL, new KMS
3598c2ecf20Sopenharmony_ciproperties, new files in sysfs or anything else that constitutes an API change
3608c2ecf20Sopenharmony_cishould have driver-agnostic testcases in IGT for that feature, if such a test
3618c2ecf20Sopenharmony_cican be reasonably made using IGT for the target hardware.
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ciValidating changes with IGT
3648c2ecf20Sopenharmony_ci---------------------------
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ciThere's a collection of tests that aims to cover the whole functionality of
3678c2ecf20Sopenharmony_ciDRM drivers and that can be used to check that changes to DRM drivers or the
3688c2ecf20Sopenharmony_cicore don't regress existing functionality. This test suite is called IGT and
3698c2ecf20Sopenharmony_ciits code and instructions to build and run can be found in
3708c2ecf20Sopenharmony_cihttps://gitlab.freedesktop.org/drm/igt-gpu-tools/.
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ciUsing VKMS to test DRM API
3738c2ecf20Sopenharmony_ci--------------------------
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ciVKMS is a software-only model of a KMS driver that is useful for testing
3768c2ecf20Sopenharmony_ciand for running compositors. VKMS aims to enable a virtual display without
3778c2ecf20Sopenharmony_cithe need for a hardware display capability. These characteristics made VKMS
3788c2ecf20Sopenharmony_cia perfect tool for validating the DRM core behavior and also support the
3798c2ecf20Sopenharmony_cicompositor developer. VKMS makes it possible to test DRM functions in a
3808c2ecf20Sopenharmony_civirtual machine without display, simplifying the validation of some of the
3818c2ecf20Sopenharmony_cicore changes.
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ciTo Validate changes in DRM API with VKMS, start setting the kernel: make
3848c2ecf20Sopenharmony_cisure to enable VKMS module; compile the kernel with the VKMS enabled and
3858c2ecf20Sopenharmony_ciinstall it in the target machine. VKMS can be run in a Virtual Machine
3868c2ecf20Sopenharmony_ci(QEMU, virtme or similar). It's recommended the use of KVM with the minimum
3878c2ecf20Sopenharmony_ciof 1GB of RAM and four cores.
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ciIt's possible to run the IGT-tests in a VM in two ways:
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	1. Use IGT inside a VM
3928c2ecf20Sopenharmony_ci	2. Use IGT from the host machine and write the results in a shared directory.
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ciAs follow, there is an example of using a VM with a shared directory with
3958c2ecf20Sopenharmony_cithe host machine to run igt-tests. As an example it's used virtme::
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	$ virtme-run --rwdir /path/for/shared_dir --kdir=path/for/kernel/directory --mods=auto
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ciRun the igt-tests in the guest machine, as example it's ran the 'kms_flip'
4008c2ecf20Sopenharmony_citests::
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	$ /path/for/igt-gpu-tools/scripts/run-tests.sh -p -s -t "kms_flip.*" -v
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ciIn this example, instead of build the igt_runner, Piglit is used
4058c2ecf20Sopenharmony_ci(-p option); it's created html summary of the tests results and it's saved
4068c2ecf20Sopenharmony_ciin the folder "igt-gpu-tools/results"; it's executed only the igt-tests
4078c2ecf20Sopenharmony_cimatching the -t option.
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ciDisplay CRC Support
4108c2ecf20Sopenharmony_ci-------------------
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
4138c2ecf20Sopenharmony_ci   :doc: CRC ABI
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_debugfs_crc.c
4168c2ecf20Sopenharmony_ci   :export:
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ciDebugfs Support
4198c2ecf20Sopenharmony_ci---------------
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci.. kernel-doc:: include/drm/drm_debugfs.h
4228c2ecf20Sopenharmony_ci   :internal:
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_debugfs.c
4258c2ecf20Sopenharmony_ci   :export:
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ciSysfs Support
4288c2ecf20Sopenharmony_ci=============
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c
4318c2ecf20Sopenharmony_ci   :doc: overview
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/drm_sysfs.c
4348c2ecf20Sopenharmony_ci   :export:
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ciVBlank event handling
4388c2ecf20Sopenharmony_ci=====================
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ciThe DRM core exposes two vertical blank related ioctls:
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ciDRM_IOCTL_WAIT_VBLANK
4438c2ecf20Sopenharmony_ci    This takes a struct drm_wait_vblank structure as its argument, and
4448c2ecf20Sopenharmony_ci    it is used to block or request a signal when a specified vblank
4458c2ecf20Sopenharmony_ci    event occurs.
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ciDRM_IOCTL_MODESET_CTL
4488c2ecf20Sopenharmony_ci    This was only used for user-mode-settind drivers around modesetting
4498c2ecf20Sopenharmony_ci    changes to allow the kernel to update the vblank interrupt after
4508c2ecf20Sopenharmony_ci    mode setting, since on many devices the vertical blank counter is
4518c2ecf20Sopenharmony_ci    reset to 0 at some point during modeset. Modern drivers should not
4528c2ecf20Sopenharmony_ci    call this any more since with kernel mode setting it is a no-op.
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ciUserspace API Structures
4558c2ecf20Sopenharmony_ci========================
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci.. kernel-doc:: include/uapi/drm/drm_mode.h
4588c2ecf20Sopenharmony_ci   :doc: overview
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci.. kernel-doc:: include/uapi/drm/drm_mode.h
4618c2ecf20Sopenharmony_ci   :internal:
462