1 .. Copyright 2020 DisplayLink (UK) Ltd. 2 3 =================== 4 Userland interfaces 5 =================== 6 7 The DRM core exports several interfaces to app 8 intended to be used through corresponding libd 9 addition, drivers export device-specific inter 10 drivers & device-aware applications through io 11 12 External interfaces include: memory mapping, c 13 operations, AGP management, vblank control, fe 14 management, and output management. 15 16 Cover generic ioctls and sysfs layout here. We 17 info, since man pages should cover the rest. 18 19 libdrm Device Lookup 20 ==================== 21 22 .. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 23 :doc: getunique and setversion story 24 25 26 .. _drm_primary_node: 27 28 Primary Nodes, DRM Master and Authentication 29 ============================================ 30 31 .. kernel-doc:: drivers/gpu/drm/drm_auth.c 32 :doc: master and authentication 33 34 .. kernel-doc:: drivers/gpu/drm/drm_auth.c 35 :export: 36 37 .. kernel-doc:: include/drm/drm_auth.h 38 :internal: 39 40 41 .. _drm_leasing: 42 43 DRM Display Resource Leasing 44 ============================ 45 46 .. kernel-doc:: drivers/gpu/drm/drm_lease.c 47 :doc: drm leasing 48 49 Open-Source Userspace Requirements 50 ================================== 51 52 The DRM subsystem has stricter requirements th 53 what the userspace side for new uAPI needs to 54 explains what exactly those requirements are, 55 56 The short summary is that any addition of DRM 57 open-sourced userspace patches, and those patc 58 merging into a suitable and canonical upstream 59 60 GFX devices (both display and render/GPU side) 61 hardware, with userspace and kernel by necessi 62 closely. The interfaces, for rendering and mo 63 and flexible, and therefore it is almost alway 64 them for every possible corner case. This in t 65 infeasible to differentiate between behaviour 66 which must not be changed to avoid regressions 67 accidental artifact of the current implementat 68 69 Without access to the full source code of all 70 becomes impossible to change the implementatio 71 depend upon the accidental behaviour of the cu 72 details. And debugging such regressions withou 73 much impossible. As a consequence this means: 74 75 - The Linux kernel's "no regression" policy ho 76 open-source userspace of the DRM subsystem. 77 if closed-source blob drivers in userspace u 78 drivers, but they must do so in the exact sa 79 Creative (ab)use of the interfaces will, and 80 to breakage. 81 82 - Any new userspace interface must have an ope 83 demonstration vehicle. 84 85 The other reason for requiring open-source use 86 kernel and userspace parts of a GFX stack must 87 review can only assess whether a new interface 88 both sides. Making sure that the interface ind 89 leads to a few additional requirements: 90 91 - The open-source userspace must not be a toy/ 92 thing. Specifically it needs to handle all t 93 These are often the places where new uAPI fa 94 assess the fitness of a proposed interface. 95 96 - The userspace side must be fully reviewed an 97 userspace project. For e.g. mesa this means 98 mailing list. This is again to ensure that t 99 job done. The userspace-side reviewer shoul 100 kernel uAPI patch indicating that they belie 101 sufficiently documented and validated for us 102 103 - The userspace patches must be against the ca 104 fork. This is to make sure that no one cheat 105 requirements by doing a quick fork. 106 107 - The kernel patch can only be merged after al 108 but it **must** be merged to either drm-next 109 userspace patches land. uAPI always flows fr 110 other way round risks divergence of the uAPI 111 112 These are fairly steep requirements, but have 113 pain and experience with uAPI added hastily, a 114 just as fast. GFX devices change really fast, 115 entire new set of uAPI interfaces every few ye 116 Linux kernel's guarantee to keep existing user 117 is already rather painful for the DRM subsyste 118 for the same thing co-existing. If we add a fe 119 mix every year it would be entirely unmanageab 120 121 .. _drm_render_node: 122 123 Render nodes 124 ============ 125 126 DRM core provides multiple character-devices f 127 Depending on which device is opened, user-spac 128 set of operations (mainly ioctls). The primary 129 and called card<num>. Additionally, a currentl 130 called controlD<num> is also created. The prim 131 legacy operations and historically was the onl 132 userspace. With KMS, the control node was intr 133 planned KMS control interface has never been w 134 node stays unused to date. 135 136 With the increased use of offscreen renderers 137 clients no longer require running compositors 138 make use of a GPU. But the DRM API required un 139 authenticate to a DRM-Master prior to getting 140 step and to grant clients GPU access without a 141 nodes were introduced. Render nodes solely ser 142 is, no modesetting or privileged ioctls can be 143 Only non-global rendering commands are allowed 144 render nodes, it must advertise it via the DRI 145 capability. If not supported, the primary node 146 clients together with the legacy drmAuth authe 147 148 If a driver advertises render node support, DR 149 separate render node called renderD<num>. Ther 150 per device. No ioctls except PRIME-related ioc 151 this node. Especially GEM_OPEN will be explici 152 complete list of driver-independent ioctls tha 153 nodes, see the ioctls marked DRM_RENDER_ALLOW 154 nodes are designed to avoid the buffer-leaks, 155 guess the flink names or mmap offsets on the l 156 Additionally to this basic interface, drivers 157 driver-dependent render-only ioctls as DRM_REN 158 clients can use them. Driver authors must be c 159 privileged ioctls on render nodes. 160 161 With render nodes, user-space can now control 162 via basic file-system access-modes. A running 163 authenticates clients on the privileged primar 164 required. Instead, a client can open the rende 165 granted GPU access. Communication between clie 166 via PRIME. FLINK from render node to legacy no 167 clients must not use the insecure FLINK interf 168 169 Besides dropping all modeset/global ioctls, re 170 DRM-Master concept. There is no reason to asso 171 a DRM-Master as they are independent of any gr 172 they must work without any running master, any 173 to run without a master object if they support 174 other hand, a driver requires shared state bet 175 visible to user-space and accessible beyond op 176 cannot support render nodes. 177 178 Device Hot-Unplug 179 ================= 180 181 .. note:: 182 The following is the plan. Implementation i 183 (2020 May). 184 185 Graphics devices (display and/or render) may b 186 display adapters or docking stations) or Thund 187 user is able to hot-unplug this kind of device 188 used, and expects that the very least the mach 189 damage from hot-unplugging a DRM device needs 190 possible and userspace must be given the chanc 191 to. Ideally, unplugging a DRM device still let 192 run, but that is going to need explicit suppor 193 graphics stack: from kernel and userspace driv 194 servers, via window system protocols, and in a 195 196 Other scenarios that should lead to the same a 197 crash, PCI device disappearing off the bus, or 198 from the physical device. 199 200 In other words, from userspace perspective eve 201 working more or less, until userspace stops us 202 device and closes it completely. Userspace wil 203 disappearance from the device removed uevent, 204 (or driver-specific ioctls returning driver-sp 205 returning ENXIO. 206 207 Only after userspace has closed all relevant D 208 descriptors and removed all mmaps, the DRM dri 209 instance for the device that no longer exists. 210 device somehow comes back in the mean time, it 211 device. 212 213 Similar to PIDs, chardev minor numbers are not 214 new DRM device always picks the next free mino 215 previous one allocated, and wraps around when 216 exhausted. 217 218 The goal raises at least the following require 219 drivers. 220 221 Requirements for KMS UAPI 222 ------------------------- 223 224 - KMS connectors must change their status to d 225 226 - Legacy modesets and pageflips, and atomic co 227 TEST_ONLY, and any other ioctls either fail 228 success. 229 230 - Pending non-blocking KMS operations deliver 231 is expecting. This applies also to ioctls th 232 233 - open() on a device node whose underlying dev 234 fail with ENXIO. 235 236 - Attempting to create a DRM lease on a disapp 237 fail with ENODEV. Existing DRM leases remain 238 above. 239 240 Requirements for Render and Cross-Device UAPI 241 --------------------------------------------- 242 243 - All GPU jobs that can no longer run must hav 244 force-signalled to avoid inflicting hangs on 245 The associated error code is ENODEV. 246 247 - Some userspace APIs already define what shou 248 disappears (OpenGL, GL ES: `GL_KHR_robustnes 249 VK_ERROR_DEVICE_LOST; etc.). DRM drivers are 250 behaviour the way they see best, e.g. return 251 driver-specific ioctls and handling those in 252 rely on uevents, and so on. 253 254 - dmabuf which point to memory that has disapp 255 import with ENODEV or continue to be success 256 have succeeded before the disappearance. See 257 below for already imported dmabufs. 258 259 - Attempting to import a dmabuf to a disappear 260 with ENODEV or succeed if it would have succ 261 disappearance. 262 263 - open() on a device node whose underlying dev 264 fail with ENXIO. 265 266 .. _GL_KHR_robustness: https://www.khronos.org 267 .. _Vulkan: https://www.khronos.org/vulkan/ 268 269 Requirements for Memory Maps 270 ---------------------------- 271 272 Memory maps have further requirements that app 273 and maps created after the device has disappea 274 memory disappears, the map is created or modif 275 writes will still complete successfully but th 276 This applies to both userspace mmap()'d memory 277 dmabuf which might be mapped to other devices 278 imports). 279 280 Raising SIGBUS is not an option, because users 281 handle it. Signal handlers are global, which m 282 difficult to use correctly from libraries like 283 Signal handlers are not composable, you can't 284 for GPU1 and GPU2 from different vendors, and 285 mmapped regular files. Threads cause additiona 286 handling as well. 287 288 Device reset 289 ============ 290 291 The GPU stack is really complex and is prone t 292 faulty applications and everything in between 293 require resetting the device in order to make 294 section describes the expectations for DRM and 295 device resets and how to propagate the reset s 296 297 Device resets can not be disabled without tain 298 hanging the entire kernel through shrinkers/mm 299 device resets is to propagate the message to t 300 special policy for blocking guilty application 301 debugging a hung GPU context require hardware 302 a GPU context while it's stopped. 303 304 Kernel Mode Driver 305 ------------------ 306 307 The KMD is responsible for checking if the dev 308 it as needed. Usually a hang is detected when 309 should keep track of resets, because userspace 310 reset status for a specific context. This is n 311 the stack that a reset has happened. Currently 312 driver separately, with no common DRM interfac 313 integrated at DRM scheduler to provide a commo 314 reset, KMD should reject new command submissio 315 316 User Mode Driver 317 ---------------- 318 319 After command submission, UMD should check if 320 rejected. After a reset, KMD should reject sub 321 ioctl to the KMD to check the reset status, an 322 if the UMD requires it. After detecting a rese 323 it to the application using the appropriate AP 324 section below about robustness. 325 326 Robustness 327 ---------- 328 329 The only way to try to keep a graphical API co 330 it complies with the robustness aspects of the 331 332 Graphical APIs provide ways to applications to 333 there is no guarantee that the app will use su 334 userspace that doesn't support robust interfac 335 OpenGL context or API without any robustness s 336 robustness handling entirely to the userspace 337 community consensus on what the userspace driv 338 since all reasonable approaches have some clea 339 340 OpenGL 341 ~~~~~~ 342 343 Apps using OpenGL should use the available rob 344 extension ``GL_ARB_robustness`` (or ``GL_EXT_r 345 interface tells if a reset has happened, and i 346 considered lost and the app proceeds by creati 347 on what to do to if robustness is not in use. 348 349 Vulkan 350 ~~~~~~ 351 352 Apps using Vulkan should check for ``VK_ERROR_ 353 This error code means, among other things, tha 354 it needs to recreate the contexts to keep goin 355 356 Reporting causes of resets 357 -------------------------- 358 359 Apart from propagating the reset through the s 360 really useful for driver developers to learn m 361 the first place. DRM devices should make use o 362 information about the reset, so this informati 363 reports. 364 365 .. _drm_driver_ioctl: 366 367 IOCTL Support on Device Nodes 368 ============================= 369 370 .. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 371 :doc: driver specific ioctls 372 373 Recommended IOCTL Return Values 374 ------------------------------- 375 376 In theory a driver's IOCTL callback is only al 377 codes. In practice it's good to abuse a few mo 378 practice within the DRM subsystem: 379 380 ENOENT: 381 Strictly this should only be used when 382 calling the open() syscall. We reuse t 383 lookup failure, e.g. for unknown GEM b 384 object handles and similar cases. 385 386 ENOSPC: 387 Some drivers use this to differentiate 388 of VRAM". Sometimes also applies to ot 389 rendering (e.g. when you have a specia 390 Sometimes resource allocation/reservat 391 IOCTLs are also signalled through EDEA 392 393 Simply running out of kernel/system me 394 395 EPERM/EACCES: 396 Returned for an operation that is vali 397 E.g. root-only or much more common, DR 398 this when called by unpriviledged clie 399 difference between EACCES and EPERM. 400 401 ENODEV: 402 The device is not present anymore or i 403 404 EOPNOTSUPP: 405 Feature (like PRIME, modesetting, GEM) 406 407 ENXIO: 408 Remote failure, either a hardware tran 409 when the exporting driver of a shared 410 feature needed. 411 412 EINTR: 413 DRM drivers assume that userspace rest 414 return EINTR and in such a case should 415 parameters left unchanged. 416 417 EIO: 418 The GPU died and couldn't be resurrect 419 hardware failures are signalled throug 420 property. 421 422 EINVAL: 423 Catch-all for anything that is an inva 424 cannot work. 425 426 IOCTL also use other error codes like ETIME, E 427 usage is in line with the common meanings. The 428 DRM specific patterns. Note that ENOTTY has th 429 "this IOCTL does not exist", and is used exact 430 431 .. kernel-doc:: include/drm/drm_ioctl.h 432 :internal: 433 434 .. kernel-doc:: drivers/gpu/drm/drm_ioctl.c 435 :export: 436 437 .. kernel-doc:: drivers/gpu/drm/drm_ioc32.c 438 :export: 439 440 Testing and validation 441 ====================== 442 443 Testing Requirements for userspace API 444 -------------------------------------- 445 446 New cross-driver userspace interface extension 447 properties, new files in sysfs or anything els 448 should have driver-agnostic testcases in IGT f 449 can be reasonably made using IGT for the targe 450 451 Validating changes with IGT 452 --------------------------- 453 454 There's a collection of tests that aims to cov 455 DRM drivers and that can be used to check that 456 core don't regress existing functionality. Thi 457 its code and instructions to build and run can 458 https://gitlab.freedesktop.org/drm/igt-gpu-too 459 460 Using VKMS to test DRM API 461 -------------------------- 462 463 VKMS is a software-only model of a KMS driver 464 and for running compositors. VKMS aims to enab 465 the need for a hardware display capability. Th 466 a perfect tool for validating the DRM core beh 467 compositor developer. VKMS makes it possible t 468 virtual machine without display, simplifying t 469 core changes. 470 471 To Validate changes in DRM API with VKMS, star 472 sure to enable VKMS module; compile the kernel 473 install it in the target machine. VKMS can be 474 (QEMU, virtme or similar). It's recommended th 475 of 1GB of RAM and four cores. 476 477 It's possible to run the IGT-tests in a VM in 478 479 1. Use IGT inside a VM 480 2. Use IGT from the host machine and w 481 482 Following is an example of using a VM with a s 483 the host machine to run igt-tests. This exampl 484 485 $ virtme-run --rwdir /path/for/shared_ 486 487 Run the igt-tests in the guest machine. This e 488 tests:: 489 490 $ /path/for/igt-gpu-tools/scripts/run- 491 492 In this example, instead of building the igt_r 493 (-p option). It creates an HTML summary of the 494 them in the folder "igt-gpu-tools/results". It 495 matching the -t option. 496 497 Display CRC Support 498 ------------------- 499 500 .. kernel-doc:: drivers/gpu/drm/drm_debugfs_cr 501 :doc: CRC ABI 502 503 .. kernel-doc:: drivers/gpu/drm/drm_debugfs_cr 504 :export: 505 506 Debugfs Support 507 --------------- 508 509 .. kernel-doc:: include/drm/drm_debugfs.h 510 :internal: 511 512 .. kernel-doc:: drivers/gpu/drm/drm_debugfs.c 513 :export: 514 515 Sysfs Support 516 ============= 517 518 .. kernel-doc:: drivers/gpu/drm/drm_sysfs.c 519 :doc: overview 520 521 .. kernel-doc:: drivers/gpu/drm/drm_sysfs.c 522 :export: 523 524 525 VBlank event handling 526 ===================== 527 528 The DRM core exposes two vertical blank relate 529 530 :c:macro:`DRM_IOCTL_WAIT_VBLANK` 531 This takes a struct drm_wait_vblank struct 532 it is used to block or request a signal wh 533 event occurs. 534 535 :c:macro:`DRM_IOCTL_MODESET_CTL` 536 This was only used for user-mode-settind d 537 changes to allow the kernel to update the 538 mode setting, since on many devices the ve 539 reset to 0 at some point during modeset. M 540 call this any more since with kernel mode 541 542 Userspace API Structures 543 ======================== 544 545 .. kernel-doc:: include/uapi/drm/drm_mode.h 546 :doc: overview 547 548 .. _crtc_index: 549 550 CRTC index 551 ---------- 552 553 CRTC's have both an object ID and an index, an 554 The index is used in cases where a densely pac 555 needed, for instance a bitmask of CRTC's. The 556 drm_mode_get_plane is an example. 557 558 :c:macro:`DRM_IOCTL_MODE_GETRESOURCES` populat 559 CRTC ID's, and the CRTC index is its position 560 561 .. kernel-doc:: include/uapi/drm/drm.h 562 :internal: 563 564 .. kernel-doc:: include/uapi/drm/drm_mode.h 565 :internal: 566 567 568 dma-buf interoperability 569 ======================== 570 571 Please see Documentation/userspace-api/dma-buf 572 information on how dma-buf is integrated and e
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.