at v3.16-rc7 3945 lines 166 kB view raw
1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> 4 5<book id="drmDevelopersGuide"> 6 <bookinfo> 7 <title>Linux DRM Developer's Guide</title> 8 9 <authorgroup> 10 <author> 11 <firstname>Jesse</firstname> 12 <surname>Barnes</surname> 13 <contrib>Initial version</contrib> 14 <affiliation> 15 <orgname>Intel Corporation</orgname> 16 <address> 17 <email>jesse.barnes@intel.com</email> 18 </address> 19 </affiliation> 20 </author> 21 <author> 22 <firstname>Laurent</firstname> 23 <surname>Pinchart</surname> 24 <contrib>Driver internals</contrib> 25 <affiliation> 26 <orgname>Ideas on board SPRL</orgname> 27 <address> 28 <email>laurent.pinchart@ideasonboard.com</email> 29 </address> 30 </affiliation> 31 </author> 32 <author> 33 <firstname>Daniel</firstname> 34 <surname>Vetter</surname> 35 <contrib>Contributions all over the place</contrib> 36 <affiliation> 37 <orgname>Intel Corporation</orgname> 38 <address> 39 <email>daniel.vetter@ffwll.ch</email> 40 </address> 41 </affiliation> 42 </author> 43 </authorgroup> 44 45 <copyright> 46 <year>2008-2009</year> 47 <year>2013-2014</year> 48 <holder>Intel Corporation</holder> 49 </copyright> 50 <copyright> 51 <year>2012</year> 52 <holder>Laurent Pinchart</holder> 53 </copyright> 54 55 <legalnotice> 56 <para> 57 The contents of this file may be used under the terms of the GNU 58 General Public License version 2 (the "GPL") as distributed in 59 the kernel source COPYING file. 60 </para> 61 </legalnotice> 62 63 <revhistory> 64 <!-- Put document revisions here, newest first. --> 65 <revision> 66 <revnumber>1.0</revnumber> 67 <date>2012-07-13</date> 68 <authorinitials>LP</authorinitials> 69 <revremark>Added extensive documentation about driver internals. 70 </revremark> 71 </revision> 72 </revhistory> 73 </bookinfo> 74 75<toc></toc> 76 77<part id="drmCore"> 78 <title>DRM Core</title> 79 <partintro> 80 <para> 81 This first part of the DRM Developer's Guide documents core DRM code, 82 helper libraries for writing drivers and generic userspace interfaces 83 exposed by DRM drivers. 84 </para> 85 </partintro> 86 87 <chapter id="drmIntroduction"> 88 <title>Introduction</title> 89 <para> 90 The Linux DRM layer contains code intended to support the needs 91 of complex graphics devices, usually containing programmable 92 pipelines well suited to 3D graphics acceleration. Graphics 93 drivers in the kernel may make use of DRM functions to make 94 tasks like memory management, interrupt handling and DMA easier, 95 and provide a uniform interface to applications. 96 </para> 97 <para> 98 A note on versions: this guide covers features found in the DRM 99 tree, including the TTM memory manager, output configuration and 100 mode setting, and the new vblank internals, in addition to all 101 the regular features found in current kernels. 102 </para> 103 <para> 104 [Insert diagram of typical DRM stack here] 105 </para> 106 </chapter> 107 108 <!-- Internals --> 109 110 <chapter id="drmInternals"> 111 <title>DRM Internals</title> 112 <para> 113 This chapter documents DRM internals relevant to driver authors 114 and developers working to add support for the latest features to 115 existing drivers. 116 </para> 117 <para> 118 First, we go over some typical driver initialization 119 requirements, like setting up command buffers, creating an 120 initial output configuration, and initializing core services. 121 Subsequent sections cover core internals in more detail, 122 providing implementation notes and examples. 123 </para> 124 <para> 125 The DRM layer provides several services to graphics drivers, 126 many of them driven by the application interfaces it provides 127 through libdrm, the library that wraps most of the DRM ioctls. 128 These include vblank event handling, memory 129 management, output management, framebuffer management, command 130 submission &amp; fencing, suspend/resume support, and DMA 131 services. 132 </para> 133 134 <!-- Internals: driver init --> 135 136 <sect1> 137 <title>Driver Initialization</title> 138 <para> 139 At the core of every DRM driver is a <structname>drm_driver</structname> 140 structure. Drivers typically statically initialize a drm_driver structure, 141 and then pass it to one of the <function>drm_*_init()</function> functions 142 to register it with the DRM subsystem. 143 </para> 144 <para> 145 Newer drivers that no longer require a <structname>drm_bus</structname> 146 structure can alternatively use the low-level device initialization and 147 registration functions such as <function>drm_dev_alloc()</function> and 148 <function>drm_dev_register()</function> directly. 149 </para> 150 <para> 151 The <structname>drm_driver</structname> structure contains static 152 information that describes the driver and features it supports, and 153 pointers to methods that the DRM core will call to implement the DRM API. 154 We will first go through the <structname>drm_driver</structname> static 155 information fields, and will then describe individual operations in 156 details as they get used in later sections. 157 </para> 158 <sect2> 159 <title>Driver Information</title> 160 <sect3> 161 <title>Driver Features</title> 162 <para> 163 Drivers inform the DRM core about their requirements and supported 164 features by setting appropriate flags in the 165 <structfield>driver_features</structfield> field. Since those flags 166 influence the DRM core behaviour since registration time, most of them 167 must be set to registering the <structname>drm_driver</structname> 168 instance. 169 </para> 170 <synopsis>u32 driver_features;</synopsis> 171 <variablelist> 172 <title>Driver Feature Flags</title> 173 <varlistentry> 174 <term>DRIVER_USE_AGP</term> 175 <listitem><para> 176 Driver uses AGP interface, the DRM core will manage AGP resources. 177 </para></listitem> 178 </varlistentry> 179 <varlistentry> 180 <term>DRIVER_REQUIRE_AGP</term> 181 <listitem><para> 182 Driver needs AGP interface to function. AGP initialization failure 183 will become a fatal error. 184 </para></listitem> 185 </varlistentry> 186 <varlistentry> 187 <term>DRIVER_PCI_DMA</term> 188 <listitem><para> 189 Driver is capable of PCI DMA, mapping of PCI DMA buffers to 190 userspace will be enabled. Deprecated. 191 </para></listitem> 192 </varlistentry> 193 <varlistentry> 194 <term>DRIVER_SG</term> 195 <listitem><para> 196 Driver can perform scatter/gather DMA, allocation and mapping of 197 scatter/gather buffers will be enabled. Deprecated. 198 </para></listitem> 199 </varlistentry> 200 <varlistentry> 201 <term>DRIVER_HAVE_DMA</term> 202 <listitem><para> 203 Driver supports DMA, the userspace DMA API will be supported. 204 Deprecated. 205 </para></listitem> 206 </varlistentry> 207 <varlistentry> 208 <term>DRIVER_HAVE_IRQ</term><term>DRIVER_IRQ_SHARED</term> 209 <listitem><para> 210 DRIVER_HAVE_IRQ indicates whether the driver has an IRQ handler 211 managed by the DRM Core. The core will support simple IRQ handler 212 installation when the flag is set. The installation process is 213 described in <xref linkend="drm-irq-registration"/>.</para> 214 <para>DRIVER_IRQ_SHARED indicates whether the device &amp; handler 215 support shared IRQs (note that this is required of PCI drivers). 216 </para></listitem> 217 </varlistentry> 218 <varlistentry> 219 <term>DRIVER_GEM</term> 220 <listitem><para> 221 Driver use the GEM memory manager. 222 </para></listitem> 223 </varlistentry> 224 <varlistentry> 225 <term>DRIVER_MODESET</term> 226 <listitem><para> 227 Driver supports mode setting interfaces (KMS). 228 </para></listitem> 229 </varlistentry> 230 <varlistentry> 231 <term>DRIVER_PRIME</term> 232 <listitem><para> 233 Driver implements DRM PRIME buffer sharing. 234 </para></listitem> 235 </varlistentry> 236 <varlistentry> 237 <term>DRIVER_RENDER</term> 238 <listitem><para> 239 Driver supports dedicated render nodes. 240 </para></listitem> 241 </varlistentry> 242 </variablelist> 243 </sect3> 244 <sect3> 245 <title>Major, Minor and Patchlevel</title> 246 <synopsis>int major; 247int minor; 248int patchlevel;</synopsis> 249 <para> 250 The DRM core identifies driver versions by a major, minor and patch 251 level triplet. The information is printed to the kernel log at 252 initialization time and passed to userspace through the 253 DRM_IOCTL_VERSION ioctl. 254 </para> 255 <para> 256 The major and minor numbers are also used to verify the requested driver 257 API version passed to DRM_IOCTL_SET_VERSION. When the driver API changes 258 between minor versions, applications can call DRM_IOCTL_SET_VERSION to 259 select a specific version of the API. If the requested major isn't equal 260 to the driver major, or the requested minor is larger than the driver 261 minor, the DRM_IOCTL_SET_VERSION call will return an error. Otherwise 262 the driver's set_version() method will be called with the requested 263 version. 264 </para> 265 </sect3> 266 <sect3> 267 <title>Name, Description and Date</title> 268 <synopsis>char *name; 269char *desc; 270char *date;</synopsis> 271 <para> 272 The driver name is printed to the kernel log at initialization time, 273 used for IRQ registration and passed to userspace through 274 DRM_IOCTL_VERSION. 275 </para> 276 <para> 277 The driver description is a purely informative string passed to 278 userspace through the DRM_IOCTL_VERSION ioctl and otherwise unused by 279 the kernel. 280 </para> 281 <para> 282 The driver date, formatted as YYYYMMDD, is meant to identify the date of 283 the latest modification to the driver. However, as most drivers fail to 284 update it, its value is mostly useless. The DRM core prints it to the 285 kernel log at initialization time and passes it to userspace through the 286 DRM_IOCTL_VERSION ioctl. 287 </para> 288 </sect3> 289 </sect2> 290 <sect2> 291 <title>Device Registration</title> 292 <para> 293 A number of functions are provided to help with device registration. 294 The functions deal with PCI, USB and platform devices, respectively. 295 </para> 296!Edrivers/gpu/drm/drm_pci.c 297!Edrivers/gpu/drm/drm_usb.c 298!Edrivers/gpu/drm/drm_platform.c 299 <para> 300 New drivers that no longer rely on the services provided by the 301 <structname>drm_bus</structname> structure can call the low-level 302 device registration functions directly. The 303 <function>drm_dev_alloc()</function> function can be used to allocate 304 and initialize a new <structname>drm_device</structname> structure. 305 Drivers will typically want to perform some additional setup on this 306 structure, such as allocating driver-specific data and storing a 307 pointer to it in the DRM device's <structfield>dev_private</structfield> 308 field. Drivers should also set the device's unique name using the 309 <function>drm_dev_set_unique()</function> function. After it has been 310 set up a device can be registered with the DRM subsystem by calling 311 <function>drm_dev_register()</function>. This will cause the device to 312 be exposed to userspace and will call the driver's 313 <structfield>.load()</structfield> implementation. When a device is 314 removed, the DRM device can safely be unregistered and freed by calling 315 <function>drm_dev_unregister()</function> followed by a call to 316 <function>drm_dev_unref()</function>. 317 </para> 318!Edrivers/gpu/drm/drm_stub.c 319 </sect2> 320 <sect2> 321 <title>Driver Load</title> 322 <para> 323 The <methodname>load</methodname> method is the driver and device 324 initialization entry point. The method is responsible for allocating and 325 initializing driver private data, performing resource allocation and 326 mapping (e.g. acquiring 327 clocks, mapping registers or allocating command buffers), initializing 328 the memory manager (<xref linkend="drm-memory-management"/>), installing 329 the IRQ handler (<xref linkend="drm-irq-registration"/>), setting up 330 vertical blanking handling (<xref linkend="drm-vertical-blank"/>), mode 331 setting (<xref linkend="drm-mode-setting"/>) and initial output 332 configuration (<xref linkend="drm-kms-init"/>). 333 </para> 334 <note><para> 335 If compatibility is a concern (e.g. with drivers converted over from 336 User Mode Setting to Kernel Mode Setting), care must be taken to prevent 337 device initialization and control that is incompatible with currently 338 active userspace drivers. For instance, if user level mode setting 339 drivers are in use, it would be problematic to perform output discovery 340 &amp; configuration at load time. Likewise, if user-level drivers 341 unaware of memory management are in use, memory management and command 342 buffer setup may need to be omitted. These requirements are 343 driver-specific, and care needs to be taken to keep both old and new 344 applications and libraries working. 345 </para></note> 346 <synopsis>int (*load) (struct drm_device *, unsigned long flags);</synopsis> 347 <para> 348 The method takes two arguments, a pointer to the newly created 349 <structname>drm_device</structname> and flags. The flags are used to 350 pass the <structfield>driver_data</structfield> field of the device id 351 corresponding to the device passed to <function>drm_*_init()</function>. 352 Only PCI devices currently use this, USB and platform DRM drivers have 353 their <methodname>load</methodname> method called with flags to 0. 354 </para> 355 <sect3> 356 <title>Driver Private Data</title> 357 <para> 358 The driver private hangs off the main 359 <structname>drm_device</structname> structure and can be used for 360 tracking various device-specific bits of information, like register 361 offsets, command buffer status, register state for suspend/resume, etc. 362 At load time, a driver may simply allocate one and set 363 <structname>drm_device</structname>.<structfield>dev_priv</structfield> 364 appropriately; it should be freed and 365 <structname>drm_device</structname>.<structfield>dev_priv</structfield> 366 set to NULL when the driver is unloaded. 367 </para> 368 </sect3> 369 <sect3 id="drm-irq-registration"> 370 <title>IRQ Registration</title> 371 <para> 372 The DRM core tries to facilitate IRQ handler registration and 373 unregistration by providing <function>drm_irq_install</function> and 374 <function>drm_irq_uninstall</function> functions. Those functions only 375 support a single interrupt per device, devices that use more than one 376 IRQs need to be handled manually. 377 </para> 378 <sect4> 379 <title>Managed IRQ Registration</title> 380 <para> 381 <function>drm_irq_install</function> starts by calling the 382 <methodname>irq_preinstall</methodname> driver operation. The operation 383 is optional and must make sure that the interrupt will not get fired by 384 clearing all pending interrupt flags or disabling the interrupt. 385 </para> 386 <para> 387 The passed-in IRQ will then be requested by a call to 388 <function>request_irq</function>. If the DRIVER_IRQ_SHARED driver 389 feature flag is set, a shared (IRQF_SHARED) IRQ handler will be 390 requested. 391 </para> 392 <para> 393 The IRQ handler function must be provided as the mandatory irq_handler 394 driver operation. It will get passed directly to 395 <function>request_irq</function> and thus has the same prototype as all 396 IRQ handlers. It will get called with a pointer to the DRM device as the 397 second argument. 398 </para> 399 <para> 400 Finally the function calls the optional 401 <methodname>irq_postinstall</methodname> driver operation. The operation 402 usually enables interrupts (excluding the vblank interrupt, which is 403 enabled separately), but drivers may choose to enable/disable interrupts 404 at a different time. 405 </para> 406 <para> 407 <function>drm_irq_uninstall</function> is similarly used to uninstall an 408 IRQ handler. It starts by waking up all processes waiting on a vblank 409 interrupt to make sure they don't hang, and then calls the optional 410 <methodname>irq_uninstall</methodname> driver operation. The operation 411 must disable all hardware interrupts. Finally the function frees the IRQ 412 by calling <function>free_irq</function>. 413 </para> 414 </sect4> 415 <sect4> 416 <title>Manual IRQ Registration</title> 417 <para> 418 Drivers that require multiple interrupt handlers can't use the managed 419 IRQ registration functions. In that case IRQs must be registered and 420 unregistered manually (usually with the <function>request_irq</function> 421 and <function>free_irq</function> functions, or their devm_* equivalent). 422 </para> 423 <para> 424 When manually registering IRQs, drivers must not set the DRIVER_HAVE_IRQ 425 driver feature flag, and must not provide the 426 <methodname>irq_handler</methodname> driver operation. They must set the 427 <structname>drm_device</structname> <structfield>irq_enabled</structfield> 428 field to 1 upon registration of the IRQs, and clear it to 0 after 429 unregistering the IRQs. 430 </para> 431 </sect4> 432 </sect3> 433 <sect3> 434 <title>Memory Manager Initialization</title> 435 <para> 436 Every DRM driver requires a memory manager which must be initialized at 437 load time. DRM currently contains two memory managers, the Translation 438 Table Manager (TTM) and the Graphics Execution Manager (GEM). 439 This document describes the use of the GEM memory manager only. See 440 <xref linkend="drm-memory-management"/> for details. 441 </para> 442 </sect3> 443 <sect3> 444 <title>Miscellaneous Device Configuration</title> 445 <para> 446 Another task that may be necessary for PCI devices during configuration 447 is mapping the video BIOS. On many devices, the VBIOS describes device 448 configuration, LCD panel timings (if any), and contains flags indicating 449 device state. Mapping the BIOS can be done using the pci_map_rom() call, 450 a convenience function that takes care of mapping the actual ROM, 451 whether it has been shadowed into memory (typically at address 0xc0000) 452 or exists on the PCI device in the ROM BAR. Note that after the ROM has 453 been mapped and any necessary information has been extracted, it should 454 be unmapped; on many devices, the ROM address decoder is shared with 455 other BARs, so leaving it mapped could cause undesired behaviour like 456 hangs or memory corruption. 457 <!--!Fdrivers/pci/rom.c pci_map_rom--> 458 </para> 459 </sect3> 460 </sect2> 461 </sect1> 462 463 <!-- Internals: memory management --> 464 465 <sect1 id="drm-memory-management"> 466 <title>Memory management</title> 467 <para> 468 Modern Linux systems require large amount of graphics memory to store 469 frame buffers, textures, vertices and other graphics-related data. Given 470 the very dynamic nature of many of that data, managing graphics memory 471 efficiently is thus crucial for the graphics stack and plays a central 472 role in the DRM infrastructure. 473 </para> 474 <para> 475 The DRM core includes two memory managers, namely Translation Table Maps 476 (TTM) and Graphics Execution Manager (GEM). TTM was the first DRM memory 477 manager to be developed and tried to be a one-size-fits-them all 478 solution. It provides a single userspace API to accommodate the need of 479 all hardware, supporting both Unified Memory Architecture (UMA) devices 480 and devices with dedicated video RAM (i.e. most discrete video cards). 481 This resulted in a large, complex piece of code that turned out to be 482 hard to use for driver development. 483 </para> 484 <para> 485 GEM started as an Intel-sponsored project in reaction to TTM's 486 complexity. Its design philosophy is completely different: instead of 487 providing a solution to every graphics memory-related problems, GEM 488 identified common code between drivers and created a support library to 489 share it. GEM has simpler initialization and execution requirements than 490 TTM, but has no video RAM management capabilities and is thus limited to 491 UMA devices. 492 </para> 493 <sect2> 494 <title>The Translation Table Manager (TTM)</title> 495 <para> 496 TTM design background and information belongs here. 497 </para> 498 <sect3> 499 <title>TTM initialization</title> 500 <warning><para>This section is outdated.</para></warning> 501 <para> 502 Drivers wishing to support TTM must fill out a drm_bo_driver 503 structure. The structure contains several fields with function 504 pointers for initializing the TTM, allocating and freeing memory, 505 waiting for command completion and fence synchronization, and memory 506 migration. See the radeon_ttm.c file for an example of usage. 507 </para> 508 <para> 509 The ttm_global_reference structure is made up of several fields: 510 </para> 511 <programlisting> 512 struct ttm_global_reference { 513 enum ttm_global_types global_type; 514 size_t size; 515 void *object; 516 int (*init) (struct ttm_global_reference *); 517 void (*release) (struct ttm_global_reference *); 518 }; 519 </programlisting> 520 <para> 521 There should be one global reference structure for your memory 522 manager as a whole, and there will be others for each object 523 created by the memory manager at runtime. Your global TTM should 524 have a type of TTM_GLOBAL_TTM_MEM. The size field for the global 525 object should be sizeof(struct ttm_mem_global), and the init and 526 release hooks should point at your driver-specific init and 527 release routines, which probably eventually call 528 ttm_mem_global_init and ttm_mem_global_release, respectively. 529 </para> 530 <para> 531 Once your global TTM accounting structure is set up and initialized 532 by calling ttm_global_item_ref() on it, 533 you need to create a buffer object TTM to 534 provide a pool for buffer object allocation by clients and the 535 kernel itself. The type of this object should be TTM_GLOBAL_TTM_BO, 536 and its size should be sizeof(struct ttm_bo_global). Again, 537 driver-specific init and release functions may be provided, 538 likely eventually calling ttm_bo_global_init() and 539 ttm_bo_global_release(), respectively. Also, like the previous 540 object, ttm_global_item_ref() is used to create an initial reference 541 count for the TTM, which will call your initialization function. 542 </para> 543 </sect3> 544 </sect2> 545 <sect2 id="drm-gem"> 546 <title>The Graphics Execution Manager (GEM)</title> 547 <para> 548 The GEM design approach has resulted in a memory manager that doesn't 549 provide full coverage of all (or even all common) use cases in its 550 userspace or kernel API. GEM exposes a set of standard memory-related 551 operations to userspace and a set of helper functions to drivers, and let 552 drivers implement hardware-specific operations with their own private API. 553 </para> 554 <para> 555 The GEM userspace API is described in the 556 <ulink url="http://lwn.net/Articles/283798/"><citetitle>GEM - the Graphics 557 Execution Manager</citetitle></ulink> article on LWN. While slightly 558 outdated, the document provides a good overview of the GEM API principles. 559 Buffer allocation and read and write operations, described as part of the 560 common GEM API, are currently implemented using driver-specific ioctls. 561 </para> 562 <para> 563 GEM is data-agnostic. It manages abstract buffer objects without knowing 564 what individual buffers contain. APIs that require knowledge of buffer 565 contents or purpose, such as buffer allocation or synchronization 566 primitives, are thus outside of the scope of GEM and must be implemented 567 using driver-specific ioctls. 568 </para> 569 <para> 570 On a fundamental level, GEM involves several operations: 571 <itemizedlist> 572 <listitem>Memory allocation and freeing</listitem> 573 <listitem>Command execution</listitem> 574 <listitem>Aperture management at command execution time</listitem> 575 </itemizedlist> 576 Buffer object allocation is relatively straightforward and largely 577 provided by Linux's shmem layer, which provides memory to back each 578 object. 579 </para> 580 <para> 581 Device-specific operations, such as command execution, pinning, buffer 582 read &amp; write, mapping, and domain ownership transfers are left to 583 driver-specific ioctls. 584 </para> 585 <sect3> 586 <title>GEM Initialization</title> 587 <para> 588 Drivers that use GEM must set the DRIVER_GEM bit in the struct 589 <structname>drm_driver</structname> 590 <structfield>driver_features</structfield> field. The DRM core will 591 then automatically initialize the GEM core before calling the 592 <methodname>load</methodname> operation. Behind the scene, this will 593 create a DRM Memory Manager object which provides an address space 594 pool for object allocation. 595 </para> 596 <para> 597 In a KMS configuration, drivers need to allocate and initialize a 598 command ring buffer following core GEM initialization if required by 599 the hardware. UMA devices usually have what is called a "stolen" 600 memory region, which provides space for the initial framebuffer and 601 large, contiguous memory regions required by the device. This space is 602 typically not managed by GEM, and must be initialized separately into 603 its own DRM MM object. 604 </para> 605 </sect3> 606 <sect3> 607 <title>GEM Objects Creation</title> 608 <para> 609 GEM splits creation of GEM objects and allocation of the memory that 610 backs them in two distinct operations. 611 </para> 612 <para> 613 GEM objects are represented by an instance of struct 614 <structname>drm_gem_object</structname>. Drivers usually need to extend 615 GEM objects with private information and thus create a driver-specific 616 GEM object structure type that embeds an instance of struct 617 <structname>drm_gem_object</structname>. 618 </para> 619 <para> 620 To create a GEM object, a driver allocates memory for an instance of its 621 specific GEM object type and initializes the embedded struct 622 <structname>drm_gem_object</structname> with a call to 623 <function>drm_gem_object_init</function>. The function takes a pointer to 624 the DRM device, a pointer to the GEM object and the buffer object size 625 in bytes. 626 </para> 627 <para> 628 GEM uses shmem to allocate anonymous pageable memory. 629 <function>drm_gem_object_init</function> will create an shmfs file of 630 the requested size and store it into the struct 631 <structname>drm_gem_object</structname> <structfield>filp</structfield> 632 field. The memory is used as either main storage for the object when the 633 graphics hardware uses system memory directly or as a backing store 634 otherwise. 635 </para> 636 <para> 637 Drivers are responsible for the actual physical pages allocation by 638 calling <function>shmem_read_mapping_page_gfp</function> for each page. 639 Note that they can decide to allocate pages when initializing the GEM 640 object, or to delay allocation until the memory is needed (for instance 641 when a page fault occurs as a result of a userspace memory access or 642 when the driver needs to start a DMA transfer involving the memory). 643 </para> 644 <para> 645 Anonymous pageable memory allocation is not always desired, for instance 646 when the hardware requires physically contiguous system memory as is 647 often the case in embedded devices. Drivers can create GEM objects with 648 no shmfs backing (called private GEM objects) by initializing them with 649 a call to <function>drm_gem_private_object_init</function> instead of 650 <function>drm_gem_object_init</function>. Storage for private GEM 651 objects must be managed by drivers. 652 </para> 653 <para> 654 Drivers that do not need to extend GEM objects with private information 655 can call the <function>drm_gem_object_alloc</function> function to 656 allocate and initialize a struct <structname>drm_gem_object</structname> 657 instance. The GEM core will call the optional driver 658 <methodname>gem_init_object</methodname> operation after initializing 659 the GEM object with <function>drm_gem_object_init</function>. 660 <synopsis>int (*gem_init_object) (struct drm_gem_object *obj);</synopsis> 661 </para> 662 <para> 663 No alloc-and-init function exists for private GEM objects. 664 </para> 665 </sect3> 666 <sect3> 667 <title>GEM Objects Lifetime</title> 668 <para> 669 All GEM objects are reference-counted by the GEM core. References can be 670 acquired and release by <function>calling drm_gem_object_reference</function> 671 and <function>drm_gem_object_unreference</function> respectively. The 672 caller must hold the <structname>drm_device</structname> 673 <structfield>struct_mutex</structfield> lock. As a convenience, GEM 674 provides the <function>drm_gem_object_reference_unlocked</function> and 675 <function>drm_gem_object_unreference_unlocked</function> functions that 676 can be called without holding the lock. 677 </para> 678 <para> 679 When the last reference to a GEM object is released the GEM core calls 680 the <structname>drm_driver</structname> 681 <methodname>gem_free_object</methodname> operation. That operation is 682 mandatory for GEM-enabled drivers and must free the GEM object and all 683 associated resources. 684 </para> 685 <para> 686 <synopsis>void (*gem_free_object) (struct drm_gem_object *obj);</synopsis> 687 Drivers are responsible for freeing all GEM object resources, including 688 the resources created by the GEM core. If an mmap offset has been 689 created for the object (in which case 690 <structname>drm_gem_object</structname>::<structfield>map_list</structfield>::<structfield>map</structfield> 691 is not NULL) it must be freed by a call to 692 <function>drm_gem_free_mmap_offset</function>. The shmfs backing store 693 must be released by calling <function>drm_gem_object_release</function> 694 (that function can safely be called if no shmfs backing store has been 695 created). 696 </para> 697 </sect3> 698 <sect3> 699 <title>GEM Objects Naming</title> 700 <para> 701 Communication between userspace and the kernel refers to GEM objects 702 using local handles, global names or, more recently, file descriptors. 703 All of those are 32-bit integer values; the usual Linux kernel limits 704 apply to the file descriptors. 705 </para> 706 <para> 707 GEM handles are local to a DRM file. Applications get a handle to a GEM 708 object through a driver-specific ioctl, and can use that handle to refer 709 to the GEM object in other standard or driver-specific ioctls. Closing a 710 DRM file handle frees all its GEM handles and dereferences the 711 associated GEM objects. 712 </para> 713 <para> 714 To create a handle for a GEM object drivers call 715 <function>drm_gem_handle_create</function>. The function takes a pointer 716 to the DRM file and the GEM object and returns a locally unique handle. 717 When the handle is no longer needed drivers delete it with a call to 718 <function>drm_gem_handle_delete</function>. Finally the GEM object 719 associated with a handle can be retrieved by a call to 720 <function>drm_gem_object_lookup</function>. 721 </para> 722 <para> 723 Handles don't take ownership of GEM objects, they only take a reference 724 to the object that will be dropped when the handle is destroyed. To 725 avoid leaking GEM objects, drivers must make sure they drop the 726 reference(s) they own (such as the initial reference taken at object 727 creation time) as appropriate, without any special consideration for the 728 handle. For example, in the particular case of combined GEM object and 729 handle creation in the implementation of the 730 <methodname>dumb_create</methodname> operation, drivers must drop the 731 initial reference to the GEM object before returning the handle. 732 </para> 733 <para> 734 GEM names are similar in purpose to handles but are not local to DRM 735 files. They can be passed between processes to reference a GEM object 736 globally. Names can't be used directly to refer to objects in the DRM 737 API, applications must convert handles to names and names to handles 738 using the DRM_IOCTL_GEM_FLINK and DRM_IOCTL_GEM_OPEN ioctls 739 respectively. The conversion is handled by the DRM core without any 740 driver-specific support. 741 </para> 742 <para> 743 GEM also supports buffer sharing with dma-buf file descriptors through 744 PRIME. GEM-based drivers must use the provided helpers functions to 745 implement the exporting and importing correctly. See <xref linkend="drm-prime-support" />. 746 Since sharing file descriptors is inherently more secure than the 747 easily guessable and global GEM names it is the preferred buffer 748 sharing mechanism. Sharing buffers through GEM names is only supported 749 for legacy userspace. Furthermore PRIME also allows cross-device 750 buffer sharing since it is based on dma-bufs. 751 </para> 752 </sect3> 753 <sect3 id="drm-gem-objects-mapping"> 754 <title>GEM Objects Mapping</title> 755 <para> 756 Because mapping operations are fairly heavyweight GEM favours 757 read/write-like access to buffers, implemented through driver-specific 758 ioctls, over mapping buffers to userspace. However, when random access 759 to the buffer is needed (to perform software rendering for instance), 760 direct access to the object can be more efficient. 761 </para> 762 <para> 763 The mmap system call can't be used directly to map GEM objects, as they 764 don't have their own file handle. Two alternative methods currently 765 co-exist to map GEM objects to userspace. The first method uses a 766 driver-specific ioctl to perform the mapping operation, calling 767 <function>do_mmap</function> under the hood. This is often considered 768 dubious, seems to be discouraged for new GEM-enabled drivers, and will 769 thus not be described here. 770 </para> 771 <para> 772 The second method uses the mmap system call on the DRM file handle. 773 <synopsis>void *mmap(void *addr, size_t length, int prot, int flags, int fd, 774 off_t offset);</synopsis> 775 DRM identifies the GEM object to be mapped by a fake offset passed 776 through the mmap offset argument. Prior to being mapped, a GEM object 777 must thus be associated with a fake offset. To do so, drivers must call 778 <function>drm_gem_create_mmap_offset</function> on the object. The 779 function allocates a fake offset range from a pool and stores the 780 offset divided by PAGE_SIZE in 781 <literal>obj-&gt;map_list.hash.key</literal>. Care must be taken not to 782 call <function>drm_gem_create_mmap_offset</function> if a fake offset 783 has already been allocated for the object. This can be tested by 784 <literal>obj-&gt;map_list.map</literal> being non-NULL. 785 </para> 786 <para> 787 Once allocated, the fake offset value 788 (<literal>obj-&gt;map_list.hash.key &lt;&lt; PAGE_SHIFT</literal>) 789 must be passed to the application in a driver-specific way and can then 790 be used as the mmap offset argument. 791 </para> 792 <para> 793 The GEM core provides a helper method <function>drm_gem_mmap</function> 794 to handle object mapping. The method can be set directly as the mmap 795 file operation handler. It will look up the GEM object based on the 796 offset value and set the VMA operations to the 797 <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield> 798 field. Note that <function>drm_gem_mmap</function> doesn't map memory to 799 userspace, but relies on the driver-provided fault handler to map pages 800 individually. 801 </para> 802 <para> 803 To use <function>drm_gem_mmap</function>, drivers must fill the struct 804 <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield> 805 field with a pointer to VM operations. 806 </para> 807 <para> 808 <synopsis>struct vm_operations_struct *gem_vm_ops 809 810 struct vm_operations_struct { 811 void (*open)(struct vm_area_struct * area); 812 void (*close)(struct vm_area_struct * area); 813 int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf); 814 };</synopsis> 815 </para> 816 <para> 817 The <methodname>open</methodname> and <methodname>close</methodname> 818 operations must update the GEM object reference count. Drivers can use 819 the <function>drm_gem_vm_open</function> and 820 <function>drm_gem_vm_close</function> helper functions directly as open 821 and close handlers. 822 </para> 823 <para> 824 The fault operation handler is responsible for mapping individual pages 825 to userspace when a page fault occurs. Depending on the memory 826 allocation scheme, drivers can allocate pages at fault time, or can 827 decide to allocate memory for the GEM object at the time the object is 828 created. 829 </para> 830 <para> 831 Drivers that want to map the GEM object upfront instead of handling page 832 faults can implement their own mmap file operation handler. 833 </para> 834 </sect3> 835 <sect3> 836 <title>Memory Coherency</title> 837 <para> 838 When mapped to the device or used in a command buffer, backing pages 839 for an object are flushed to memory and marked write combined so as to 840 be coherent with the GPU. Likewise, if the CPU accesses an object 841 after the GPU has finished rendering to the object, then the object 842 must be made coherent with the CPU's view of memory, usually involving 843 GPU cache flushing of various kinds. This core CPU&lt;-&gt;GPU 844 coherency management is provided by a device-specific ioctl, which 845 evaluates an object's current domain and performs any necessary 846 flushing or synchronization to put the object into the desired 847 coherency domain (note that the object may be busy, i.e. an active 848 render target; in that case, setting the domain blocks the client and 849 waits for rendering to complete before performing any necessary 850 flushing operations). 851 </para> 852 </sect3> 853 <sect3> 854 <title>Command Execution</title> 855 <para> 856 Perhaps the most important GEM function for GPU devices is providing a 857 command execution interface to clients. Client programs construct 858 command buffers containing references to previously allocated memory 859 objects, and then submit them to GEM. At that point, GEM takes care to 860 bind all the objects into the GTT, execute the buffer, and provide 861 necessary synchronization between clients accessing the same buffers. 862 This often involves evicting some objects from the GTT and re-binding 863 others (a fairly expensive operation), and providing relocation 864 support which hides fixed GTT offsets from clients. Clients must take 865 care not to submit command buffers that reference more objects than 866 can fit in the GTT; otherwise, GEM will reject them and no rendering 867 will occur. Similarly, if several objects in the buffer require fence 868 registers to be allocated for correct rendering (e.g. 2D blits on 869 pre-965 chips), care must be taken not to require more fence registers 870 than are available to the client. Such resource management should be 871 abstracted from the client in libdrm. 872 </para> 873 </sect3> 874 <sect3> 875 <title>GEM Function Reference</title> 876!Edrivers/gpu/drm/drm_gem.c 877 </sect3> 878 </sect2> 879 <sect2> 880 <title>VMA Offset Manager</title> 881!Pdrivers/gpu/drm/drm_vma_manager.c vma offset manager 882!Edrivers/gpu/drm/drm_vma_manager.c 883!Iinclude/drm/drm_vma_manager.h 884 </sect2> 885 <sect2 id="drm-prime-support"> 886 <title>PRIME Buffer Sharing</title> 887 <para> 888 PRIME is the cross device buffer sharing framework in drm, originally 889 created for the OPTIMUS range of multi-gpu platforms. To userspace 890 PRIME buffers are dma-buf based file descriptors. 891 </para> 892 <sect3> 893 <title>Overview and Driver Interface</title> 894 <para> 895 Similar to GEM global names, PRIME file descriptors are 896 also used to share buffer objects across processes. They offer 897 additional security: as file descriptors must be explicitly sent over 898 UNIX domain sockets to be shared between applications, they can't be 899 guessed like the globally unique GEM names. 900 </para> 901 <para> 902 Drivers that support the PRIME 903 API must set the DRIVER_PRIME bit in the struct 904 <structname>drm_driver</structname> 905 <structfield>driver_features</structfield> field, and implement the 906 <methodname>prime_handle_to_fd</methodname> and 907 <methodname>prime_fd_to_handle</methodname> operations. 908 </para> 909 <para> 910 <synopsis>int (*prime_handle_to_fd)(struct drm_device *dev, 911 struct drm_file *file_priv, uint32_t handle, 912 uint32_t flags, int *prime_fd); 913int (*prime_fd_to_handle)(struct drm_device *dev, 914 struct drm_file *file_priv, int prime_fd, 915 uint32_t *handle);</synopsis> 916 Those two operations convert a handle to a PRIME file descriptor and 917 vice versa. Drivers must use the kernel dma-buf buffer sharing framework 918 to manage the PRIME file descriptors. Similar to the mode setting 919 API PRIME is agnostic to the underlying buffer object manager, as 920 long as handles are 32bit unsigned integers. 921 </para> 922 <para> 923 While non-GEM drivers must implement the operations themselves, GEM 924 drivers must use the <function>drm_gem_prime_handle_to_fd</function> 925 and <function>drm_gem_prime_fd_to_handle</function> helper functions. 926 Those helpers rely on the driver 927 <methodname>gem_prime_export</methodname> and 928 <methodname>gem_prime_import</methodname> operations to create a dma-buf 929 instance from a GEM object (dma-buf exporter role) and to create a GEM 930 object from a dma-buf instance (dma-buf importer role). 931 </para> 932 <para> 933 <synopsis>struct dma_buf * (*gem_prime_export)(struct drm_device *dev, 934 struct drm_gem_object *obj, 935 int flags); 936struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev, 937 struct dma_buf *dma_buf);</synopsis> 938 These two operations are mandatory for GEM drivers that support 939 PRIME. 940 </para> 941 </sect3> 942 <sect3> 943 <title>PRIME Helper Functions</title> 944!Pdrivers/gpu/drm/drm_prime.c PRIME Helpers 945 </sect3> 946 </sect2> 947 <sect2> 948 <title>PRIME Function References</title> 949!Edrivers/gpu/drm/drm_prime.c 950 </sect2> 951 <sect2> 952 <title>DRM MM Range Allocator</title> 953 <sect3> 954 <title>Overview</title> 955!Pdrivers/gpu/drm/drm_mm.c Overview 956 </sect3> 957 <sect3> 958 <title>LRU Scan/Eviction Support</title> 959!Pdrivers/gpu/drm/drm_mm.c lru scan roaster 960 </sect3> 961 </sect2> 962 <sect2> 963 <title>DRM MM Range Allocator Function References</title> 964!Edrivers/gpu/drm/drm_mm.c 965!Iinclude/drm/drm_mm.h 966 </sect2> 967 </sect1> 968 969 <!-- Internals: mode setting --> 970 971 <sect1 id="drm-mode-setting"> 972 <title>Mode Setting</title> 973 <para> 974 Drivers must initialize the mode setting core by calling 975 <function>drm_mode_config_init</function> on the DRM device. The function 976 initializes the <structname>drm_device</structname> 977 <structfield>mode_config</structfield> field and never fails. Once done, 978 mode configuration must be setup by initializing the following fields. 979 </para> 980 <itemizedlist> 981 <listitem> 982 <synopsis>int min_width, min_height; 983int max_width, max_height;</synopsis> 984 <para> 985 Minimum and maximum width and height of the frame buffers in pixel 986 units. 987 </para> 988 </listitem> 989 <listitem> 990 <synopsis>struct drm_mode_config_funcs *funcs;</synopsis> 991 <para>Mode setting functions.</para> 992 </listitem> 993 </itemizedlist> 994 <sect2> 995 <title>Display Modes Function Reference</title> 996!Iinclude/drm/drm_modes.h 997!Edrivers/gpu/drm/drm_modes.c 998 </sect2> 999 <sect2> 1000 <title>Frame Buffer Creation</title> 1001 <synopsis>struct drm_framebuffer *(*fb_create)(struct drm_device *dev, 1002 struct drm_file *file_priv, 1003 struct drm_mode_fb_cmd2 *mode_cmd);</synopsis> 1004 <para> 1005 Frame buffers are abstract memory objects that provide a source of 1006 pixels to scanout to a CRTC. Applications explicitly request the 1007 creation of frame buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls and 1008 receive an opaque handle that can be passed to the KMS CRTC control, 1009 plane configuration and page flip functions. 1010 </para> 1011 <para> 1012 Frame buffers rely on the underneath memory manager for low-level memory 1013 operations. When creating a frame buffer applications pass a memory 1014 handle (or a list of memory handles for multi-planar formats) through 1015 the <parameter>drm_mode_fb_cmd2</parameter> argument. For drivers using 1016 GEM as their userspace buffer management interface this would be a GEM 1017 handle. Drivers are however free to use their own backing storage object 1018 handles, e.g. vmwgfx directly exposes special TTM handles to userspace 1019 and so expects TTM handles in the create ioctl and not GEM handles. 1020 </para> 1021 <para> 1022 Drivers must first validate the requested frame buffer parameters passed 1023 through the mode_cmd argument. In particular this is where invalid 1024 sizes, pixel formats or pitches can be caught. 1025 </para> 1026 <para> 1027 If the parameters are deemed valid, drivers then create, initialize and 1028 return an instance of struct <structname>drm_framebuffer</structname>. 1029 If desired the instance can be embedded in a larger driver-specific 1030 structure. Drivers must fill its <structfield>width</structfield>, 1031 <structfield>height</structfield>, <structfield>pitches</structfield>, 1032 <structfield>offsets</structfield>, <structfield>depth</structfield>, 1033 <structfield>bits_per_pixel</structfield> and 1034 <structfield>pixel_format</structfield> fields from the values passed 1035 through the <parameter>drm_mode_fb_cmd2</parameter> argument. They 1036 should call the <function>drm_helper_mode_fill_fb_struct</function> 1037 helper function to do so. 1038 </para> 1039 1040 <para> 1041 The initialization of the new framebuffer instance is finalized with a 1042 call to <function>drm_framebuffer_init</function> which takes a pointer 1043 to DRM frame buffer operations (struct 1044 <structname>drm_framebuffer_funcs</structname>). Note that this function 1045 publishes the framebuffer and so from this point on it can be accessed 1046 concurrently from other threads. Hence it must be the last step in the 1047 driver's framebuffer initialization sequence. Frame buffer operations 1048 are 1049 <itemizedlist> 1050 <listitem> 1051 <synopsis>int (*create_handle)(struct drm_framebuffer *fb, 1052 struct drm_file *file_priv, unsigned int *handle);</synopsis> 1053 <para> 1054 Create a handle to the frame buffer underlying memory object. If 1055 the frame buffer uses a multi-plane format, the handle will 1056 reference the memory object associated with the first plane. 1057 </para> 1058 <para> 1059 Drivers call <function>drm_gem_handle_create</function> to create 1060 the handle. 1061 </para> 1062 </listitem> 1063 <listitem> 1064 <synopsis>void (*destroy)(struct drm_framebuffer *framebuffer);</synopsis> 1065 <para> 1066 Destroy the frame buffer object and frees all associated 1067 resources. Drivers must call 1068 <function>drm_framebuffer_cleanup</function> to free resources 1069 allocated by the DRM core for the frame buffer object, and must 1070 make sure to unreference all memory objects associated with the 1071 frame buffer. Handles created by the 1072 <methodname>create_handle</methodname> operation are released by 1073 the DRM core. 1074 </para> 1075 </listitem> 1076 <listitem> 1077 <synopsis>int (*dirty)(struct drm_framebuffer *framebuffer, 1078 struct drm_file *file_priv, unsigned flags, unsigned color, 1079 struct drm_clip_rect *clips, unsigned num_clips);</synopsis> 1080 <para> 1081 This optional operation notifies the driver that a region of the 1082 frame buffer has changed in response to a DRM_IOCTL_MODE_DIRTYFB 1083 ioctl call. 1084 </para> 1085 </listitem> 1086 </itemizedlist> 1087 </para> 1088 <para> 1089 The lifetime of a drm framebuffer is controlled with a reference count, 1090 drivers can grab additional references with 1091 <function>drm_framebuffer_reference</function>and drop them 1092 again with <function>drm_framebuffer_unreference</function>. For 1093 driver-private framebuffers for which the last reference is never 1094 dropped (e.g. for the fbdev framebuffer when the struct 1095 <structname>drm_framebuffer</structname> is embedded into the fbdev 1096 helper struct) drivers can manually clean up a framebuffer at module 1097 unload time with 1098 <function>drm_framebuffer_unregister_private</function>. 1099 </para> 1100 </sect2> 1101 <sect2> 1102 <title>Dumb Buffer Objects</title> 1103 <para> 1104 The KMS API doesn't standardize backing storage object creation and 1105 leaves it to driver-specific ioctls. Furthermore actually creating a 1106 buffer object even for GEM-based drivers is done through a 1107 driver-specific ioctl - GEM only has a common userspace interface for 1108 sharing and destroying objects. While not an issue for full-fledged 1109 graphics stacks that include device-specific userspace components (in 1110 libdrm for instance), this limit makes DRM-based early boot graphics 1111 unnecessarily complex. 1112 </para> 1113 <para> 1114 Dumb objects partly alleviate the problem by providing a standard 1115 API to create dumb buffers suitable for scanout, which can then be used 1116 to create KMS frame buffers. 1117 </para> 1118 <para> 1119 To support dumb objects drivers must implement the 1120 <methodname>dumb_create</methodname>, 1121 <methodname>dumb_destroy</methodname> and 1122 <methodname>dumb_map_offset</methodname> operations. 1123 </para> 1124 <itemizedlist> 1125 <listitem> 1126 <synopsis>int (*dumb_create)(struct drm_file *file_priv, struct drm_device *dev, 1127 struct drm_mode_create_dumb *args);</synopsis> 1128 <para> 1129 The <methodname>dumb_create</methodname> operation creates a driver 1130 object (GEM or TTM handle) suitable for scanout based on the 1131 width, height and depth from the struct 1132 <structname>drm_mode_create_dumb</structname> argument. It fills the 1133 argument's <structfield>handle</structfield>, 1134 <structfield>pitch</structfield> and <structfield>size</structfield> 1135 fields with a handle for the newly created object and its line 1136 pitch and size in bytes. 1137 </para> 1138 </listitem> 1139 <listitem> 1140 <synopsis>int (*dumb_destroy)(struct drm_file *file_priv, struct drm_device *dev, 1141 uint32_t handle);</synopsis> 1142 <para> 1143 The <methodname>dumb_destroy</methodname> operation destroys a dumb 1144 object created by <methodname>dumb_create</methodname>. 1145 </para> 1146 </listitem> 1147 <listitem> 1148 <synopsis>int (*dumb_map_offset)(struct drm_file *file_priv, struct drm_device *dev, 1149 uint32_t handle, uint64_t *offset);</synopsis> 1150 <para> 1151 The <methodname>dumb_map_offset</methodname> operation associates an 1152 mmap fake offset with the object given by the handle and returns 1153 it. Drivers must use the 1154 <function>drm_gem_create_mmap_offset</function> function to 1155 associate the fake offset as described in 1156 <xref linkend="drm-gem-objects-mapping"/>. 1157 </para> 1158 </listitem> 1159 </itemizedlist> 1160 <para> 1161 Note that dumb objects may not be used for gpu acceleration, as has been 1162 attempted on some ARM embedded platforms. Such drivers really must have 1163 a hardware-specific ioctl to allocate suitable buffer objects. 1164 </para> 1165 </sect2> 1166 <sect2> 1167 <title>Output Polling</title> 1168 <synopsis>void (*output_poll_changed)(struct drm_device *dev);</synopsis> 1169 <para> 1170 This operation notifies the driver that the status of one or more 1171 connectors has changed. Drivers that use the fb helper can just call the 1172 <function>drm_fb_helper_hotplug_event</function> function to handle this 1173 operation. 1174 </para> 1175 </sect2> 1176 <sect2> 1177 <title>Locking</title> 1178 <para> 1179 Beside some lookup structures with their own locking (which is hidden 1180 behind the interface functions) most of the modeset state is protected 1181 by the <code>dev-&lt;mode_config.lock</code> mutex and additionally 1182 per-crtc locks to allow cursor updates, pageflips and similar operations 1183 to occur concurrently with background tasks like output detection. 1184 Operations which cross domains like a full modeset always grab all 1185 locks. Drivers there need to protect resources shared between crtcs with 1186 additional locking. They also need to be careful to always grab the 1187 relevant crtc locks if a modset functions touches crtc state, e.g. for 1188 load detection (which does only grab the <code>mode_config.lock</code> 1189 to allow concurrent screen updates on live crtcs). 1190 </para> 1191 </sect2> 1192 </sect1> 1193 1194 <!-- Internals: kms initialization and cleanup --> 1195 1196 <sect1 id="drm-kms-init"> 1197 <title>KMS Initialization and Cleanup</title> 1198 <para> 1199 A KMS device is abstracted and exposed as a set of planes, CRTCs, encoders 1200 and connectors. KMS drivers must thus create and initialize all those 1201 objects at load time after initializing mode setting. 1202 </para> 1203 <sect2> 1204 <title>CRTCs (struct <structname>drm_crtc</structname>)</title> 1205 <para> 1206 A CRTC is an abstraction representing a part of the chip that contains a 1207 pointer to a scanout buffer. Therefore, the number of CRTCs available 1208 determines how many independent scanout buffers can be active at any 1209 given time. The CRTC structure contains several fields to support this: 1210 a pointer to some video memory (abstracted as a frame buffer object), a 1211 display mode, and an (x, y) offset into the video memory to support 1212 panning or configurations where one piece of video memory spans multiple 1213 CRTCs. 1214 </para> 1215 <sect3> 1216 <title>CRTC Initialization</title> 1217 <para> 1218 A KMS device must create and register at least one struct 1219 <structname>drm_crtc</structname> instance. The instance is allocated 1220 and zeroed by the driver, possibly as part of a larger structure, and 1221 registered with a call to <function>drm_crtc_init</function> with a 1222 pointer to CRTC functions. 1223 </para> 1224 </sect3> 1225 <sect3 id="drm-kms-crtcops"> 1226 <title>CRTC Operations</title> 1227 <sect4> 1228 <title>Set Configuration</title> 1229 <synopsis>int (*set_config)(struct drm_mode_set *set);</synopsis> 1230 <para> 1231 Apply a new CRTC configuration to the device. The configuration 1232 specifies a CRTC, a frame buffer to scan out from, a (x,y) position in 1233 the frame buffer, a display mode and an array of connectors to drive 1234 with the CRTC if possible. 1235 </para> 1236 <para> 1237 If the frame buffer specified in the configuration is NULL, the driver 1238 must detach all encoders connected to the CRTC and all connectors 1239 attached to those encoders and disable them. 1240 </para> 1241 <para> 1242 This operation is called with the mode config lock held. 1243 </para> 1244 <note><para> 1245 Note that the drm core has no notion of restoring the mode setting 1246 state after resume, since all resume handling is in the full 1247 responsibility of the driver. The common mode setting helper library 1248 though provides a helper which can be used for this: 1249 <function>drm_helper_resume_force_mode</function>. 1250 </para></note> 1251 </sect4> 1252 <sect4> 1253 <title>Page Flipping</title> 1254 <synopsis>int (*page_flip)(struct drm_crtc *crtc, struct drm_framebuffer *fb, 1255 struct drm_pending_vblank_event *event);</synopsis> 1256 <para> 1257 Schedule a page flip to the given frame buffer for the CRTC. This 1258 operation is called with the mode config mutex held. 1259 </para> 1260 <para> 1261 Page flipping is a synchronization mechanism that replaces the frame 1262 buffer being scanned out by the CRTC with a new frame buffer during 1263 vertical blanking, avoiding tearing. When an application requests a page 1264 flip the DRM core verifies that the new frame buffer is large enough to 1265 be scanned out by the CRTC in the currently configured mode and then 1266 calls the CRTC <methodname>page_flip</methodname> operation with a 1267 pointer to the new frame buffer. 1268 </para> 1269 <para> 1270 The <methodname>page_flip</methodname> operation schedules a page flip. 1271 Once any pending rendering targeting the new frame buffer has 1272 completed, the CRTC will be reprogrammed to display that frame buffer 1273 after the next vertical refresh. The operation must return immediately 1274 without waiting for rendering or page flip to complete and must block 1275 any new rendering to the frame buffer until the page flip completes. 1276 </para> 1277 <para> 1278 If a page flip can be successfully scheduled the driver must set the 1279 <code>drm_crtc-&lt;fb</code> field to the new framebuffer pointed to 1280 by <code>fb</code>. This is important so that the reference counting 1281 on framebuffers stays balanced. 1282 </para> 1283 <para> 1284 If a page flip is already pending, the 1285 <methodname>page_flip</methodname> operation must return 1286 -<errorname>EBUSY</errorname>. 1287 </para> 1288 <para> 1289 To synchronize page flip to vertical blanking the driver will likely 1290 need to enable vertical blanking interrupts. It should call 1291 <function>drm_vblank_get</function> for that purpose, and call 1292 <function>drm_vblank_put</function> after the page flip completes. 1293 </para> 1294 <para> 1295 If the application has requested to be notified when page flip completes 1296 the <methodname>page_flip</methodname> operation will be called with a 1297 non-NULL <parameter>event</parameter> argument pointing to a 1298 <structname>drm_pending_vblank_event</structname> instance. Upon page 1299 flip completion the driver must call <methodname>drm_send_vblank_event</methodname> 1300 to fill in the event and send to wake up any waiting processes. 1301 This can be performed with 1302 <programlisting><![CDATA[ 1303 spin_lock_irqsave(&dev->event_lock, flags); 1304 ... 1305 drm_send_vblank_event(dev, pipe, event); 1306 spin_unlock_irqrestore(&dev->event_lock, flags); 1307 ]]></programlisting> 1308 </para> 1309 <note><para> 1310 FIXME: Could drivers that don't need to wait for rendering to complete 1311 just add the event to <literal>dev-&gt;vblank_event_list</literal> and 1312 let the DRM core handle everything, as for "normal" vertical blanking 1313 events? 1314 </para></note> 1315 <para> 1316 While waiting for the page flip to complete, the 1317 <literal>event-&gt;base.link</literal> list head can be used freely by 1318 the driver to store the pending event in a driver-specific list. 1319 </para> 1320 <para> 1321 If the file handle is closed before the event is signaled, drivers must 1322 take care to destroy the event in their 1323 <methodname>preclose</methodname> operation (and, if needed, call 1324 <function>drm_vblank_put</function>). 1325 </para> 1326 </sect4> 1327 <sect4> 1328 <title>Miscellaneous</title> 1329 <itemizedlist> 1330 <listitem> 1331 <synopsis>void (*set_property)(struct drm_crtc *crtc, 1332 struct drm_property *property, uint64_t value);</synopsis> 1333 <para> 1334 Set the value of the given CRTC property to 1335 <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/> 1336 for more information about properties. 1337 </para> 1338 </listitem> 1339 <listitem> 1340 <synopsis>void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 1341 uint32_t start, uint32_t size);</synopsis> 1342 <para> 1343 Apply a gamma table to the device. The operation is optional. 1344 </para> 1345 </listitem> 1346 <listitem> 1347 <synopsis>void (*destroy)(struct drm_crtc *crtc);</synopsis> 1348 <para> 1349 Destroy the CRTC when not needed anymore. See 1350 <xref linkend="drm-kms-init"/>. 1351 </para> 1352 </listitem> 1353 </itemizedlist> 1354 </sect4> 1355 </sect3> 1356 </sect2> 1357 <sect2> 1358 <title>Planes (struct <structname>drm_plane</structname>)</title> 1359 <para> 1360 A plane represents an image source that can be blended with or overlayed 1361 on top of a CRTC during the scanout process. Planes are associated with 1362 a frame buffer to crop a portion of the image memory (source) and 1363 optionally scale it to a destination size. The result is then blended 1364 with or overlayed on top of a CRTC. 1365 </para> 1366 <para> 1367 The DRM core recognizes three types of planes: 1368 <itemizedlist> 1369 <listitem> 1370 DRM_PLANE_TYPE_PRIMARY represents a "main" plane for a CRTC. Primary 1371 planes are the planes operated upon by by CRTC modesetting and flipping 1372 operations described in <xref linkend="drm-kms-crtcops"/>. 1373 </listitem> 1374 <listitem> 1375 DRM_PLANE_TYPE_CURSOR represents a "cursor" plane for a CRTC. Cursor 1376 planes are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and 1377 DRM_IOCTL_MODE_CURSOR2 ioctls. 1378 </listitem> 1379 <listitem> 1380 DRM_PLANE_TYPE_OVERLAY represents all non-primary, non-cursor planes. 1381 Some drivers refer to these types of planes as "sprites" internally. 1382 </listitem> 1383 </itemizedlist> 1384 For compatibility with legacy userspace, only overlay planes are made 1385 available to userspace by default. Userspace clients may set the 1386 DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that 1387 they wish to receive a universal plane list containing all plane types. 1388 </para> 1389 <sect3> 1390 <title>Plane Initialization</title> 1391 <para> 1392 To create a plane, a KMS drivers allocates and 1393 zeroes an instances of struct <structname>drm_plane</structname> 1394 (possibly as part of a larger structure) and registers it with a call 1395 to <function>drm_universal_plane_init</function>. The function takes a bitmask 1396 of the CRTCs that can be associated with the plane, a pointer to the 1397 plane functions, a list of format supported formats, and the type of 1398 plane (primary, cursor, or overlay) being initialized. 1399 </para> 1400 <para> 1401 Cursor and overlay planes are optional. All drivers should provide 1402 one primary plane per CRTC (although this requirement may change in 1403 the future); drivers that do not wish to provide special handling for 1404 primary planes may make use of the helper functions described in 1405 <xref linkend="drm-kms-planehelpers"/> to create and register a 1406 primary plane with standard capabilities. 1407 </para> 1408 </sect3> 1409 <sect3> 1410 <title>Plane Operations</title> 1411 <itemizedlist> 1412 <listitem> 1413 <synopsis>int (*update_plane)(struct drm_plane *plane, struct drm_crtc *crtc, 1414 struct drm_framebuffer *fb, int crtc_x, int crtc_y, 1415 unsigned int crtc_w, unsigned int crtc_h, 1416 uint32_t src_x, uint32_t src_y, 1417 uint32_t src_w, uint32_t src_h);</synopsis> 1418 <para> 1419 Enable and configure the plane to use the given CRTC and frame buffer. 1420 </para> 1421 <para> 1422 The source rectangle in frame buffer memory coordinates is given by 1423 the <parameter>src_x</parameter>, <parameter>src_y</parameter>, 1424 <parameter>src_w</parameter> and <parameter>src_h</parameter> 1425 parameters (as 16.16 fixed point values). Devices that don't support 1426 subpixel plane coordinates can ignore the fractional part. 1427 </para> 1428 <para> 1429 The destination rectangle in CRTC coordinates is given by the 1430 <parameter>crtc_x</parameter>, <parameter>crtc_y</parameter>, 1431 <parameter>crtc_w</parameter> and <parameter>crtc_h</parameter> 1432 parameters (as integer values). Devices scale the source rectangle to 1433 the destination rectangle. If scaling is not supported, and the source 1434 rectangle size doesn't match the destination rectangle size, the 1435 driver must return a -<errorname>EINVAL</errorname> error. 1436 </para> 1437 </listitem> 1438 <listitem> 1439 <synopsis>int (*disable_plane)(struct drm_plane *plane);</synopsis> 1440 <para> 1441 Disable the plane. The DRM core calls this method in response to a 1442 DRM_IOCTL_MODE_SETPLANE ioctl call with the frame buffer ID set to 0. 1443 Disabled planes must not be processed by the CRTC. 1444 </para> 1445 </listitem> 1446 <listitem> 1447 <synopsis>void (*destroy)(struct drm_plane *plane);</synopsis> 1448 <para> 1449 Destroy the plane when not needed anymore. See 1450 <xref linkend="drm-kms-init"/>. 1451 </para> 1452 </listitem> 1453 </itemizedlist> 1454 </sect3> 1455 </sect2> 1456 <sect2> 1457 <title>Encoders (struct <structname>drm_encoder</structname>)</title> 1458 <para> 1459 An encoder takes pixel data from a CRTC and converts it to a format 1460 suitable for any attached connectors. On some devices, it may be 1461 possible to have a CRTC send data to more than one encoder. In that 1462 case, both encoders would receive data from the same scanout buffer, 1463 resulting in a "cloned" display configuration across the connectors 1464 attached to each encoder. 1465 </para> 1466 <sect3> 1467 <title>Encoder Initialization</title> 1468 <para> 1469 As for CRTCs, a KMS driver must create, initialize and register at 1470 least one struct <structname>drm_encoder</structname> instance. The 1471 instance is allocated and zeroed by the driver, possibly as part of a 1472 larger structure. 1473 </para> 1474 <para> 1475 Drivers must initialize the struct <structname>drm_encoder</structname> 1476 <structfield>possible_crtcs</structfield> and 1477 <structfield>possible_clones</structfield> fields before registering the 1478 encoder. Both fields are bitmasks of respectively the CRTCs that the 1479 encoder can be connected to, and sibling encoders candidate for cloning. 1480 </para> 1481 <para> 1482 After being initialized, the encoder must be registered with a call to 1483 <function>drm_encoder_init</function>. The function takes a pointer to 1484 the encoder functions and an encoder type. Supported types are 1485 <itemizedlist> 1486 <listitem> 1487 DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A 1488 </listitem> 1489 <listitem> 1490 DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort 1491 </listitem> 1492 <listitem> 1493 DRM_MODE_ENCODER_LVDS for display panels 1494 </listitem> 1495 <listitem> 1496 DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video, Component, 1497 SCART) 1498 </listitem> 1499 <listitem> 1500 DRM_MODE_ENCODER_VIRTUAL for virtual machine displays 1501 </listitem> 1502 </itemizedlist> 1503 </para> 1504 <para> 1505 Encoders must be attached to a CRTC to be used. DRM drivers leave 1506 encoders unattached at initialization time. Applications (or the fbdev 1507 compatibility layer when implemented) are responsible for attaching the 1508 encoders they want to use to a CRTC. 1509 </para> 1510 </sect3> 1511 <sect3> 1512 <title>Encoder Operations</title> 1513 <itemizedlist> 1514 <listitem> 1515 <synopsis>void (*destroy)(struct drm_encoder *encoder);</synopsis> 1516 <para> 1517 Called to destroy the encoder when not needed anymore. See 1518 <xref linkend="drm-kms-init"/>. 1519 </para> 1520 </listitem> 1521 <listitem> 1522 <synopsis>void (*set_property)(struct drm_plane *plane, 1523 struct drm_property *property, uint64_t value);</synopsis> 1524 <para> 1525 Set the value of the given plane property to 1526 <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/> 1527 for more information about properties. 1528 </para> 1529 </listitem> 1530 </itemizedlist> 1531 </sect3> 1532 </sect2> 1533 <sect2> 1534 <title>Connectors (struct <structname>drm_connector</structname>)</title> 1535 <para> 1536 A connector is the final destination for pixel data on a device, and 1537 usually connects directly to an external display device like a monitor 1538 or laptop panel. A connector can only be attached to one encoder at a 1539 time. The connector is also the structure where information about the 1540 attached display is kept, so it contains fields for display data, EDID 1541 data, DPMS &amp; connection status, and information about modes 1542 supported on the attached displays. 1543 </para> 1544 <sect3> 1545 <title>Connector Initialization</title> 1546 <para> 1547 Finally a KMS driver must create, initialize, register and attach at 1548 least one struct <structname>drm_connector</structname> instance. The 1549 instance is created as other KMS objects and initialized by setting the 1550 following fields. 1551 </para> 1552 <variablelist> 1553 <varlistentry> 1554 <term><structfield>interlace_allowed</structfield></term> 1555 <listitem><para> 1556 Whether the connector can handle interlaced modes. 1557 </para></listitem> 1558 </varlistentry> 1559 <varlistentry> 1560 <term><structfield>doublescan_allowed</structfield></term> 1561 <listitem><para> 1562 Whether the connector can handle doublescan. 1563 </para></listitem> 1564 </varlistentry> 1565 <varlistentry> 1566 <term><structfield>display_info 1567 </structfield></term> 1568 <listitem><para> 1569 Display information is filled from EDID information when a display 1570 is detected. For non hot-pluggable displays such as flat panels in 1571 embedded systems, the driver should initialize the 1572 <structfield>display_info</structfield>.<structfield>width_mm</structfield> 1573 and 1574 <structfield>display_info</structfield>.<structfield>height_mm</structfield> 1575 fields with the physical size of the display. 1576 </para></listitem> 1577 </varlistentry> 1578 <varlistentry> 1579 <term id="drm-kms-connector-polled"><structfield>polled</structfield></term> 1580 <listitem><para> 1581 Connector polling mode, a combination of 1582 <variablelist> 1583 <varlistentry> 1584 <term>DRM_CONNECTOR_POLL_HPD</term> 1585 <listitem><para> 1586 The connector generates hotplug events and doesn't need to be 1587 periodically polled. The CONNECT and DISCONNECT flags must not 1588 be set together with the HPD flag. 1589 </para></listitem> 1590 </varlistentry> 1591 <varlistentry> 1592 <term>DRM_CONNECTOR_POLL_CONNECT</term> 1593 <listitem><para> 1594 Periodically poll the connector for connection. 1595 </para></listitem> 1596 </varlistentry> 1597 <varlistentry> 1598 <term>DRM_CONNECTOR_POLL_DISCONNECT</term> 1599 <listitem><para> 1600 Periodically poll the connector for disconnection. 1601 </para></listitem> 1602 </varlistentry> 1603 </variablelist> 1604 Set to 0 for connectors that don't support connection status 1605 discovery. 1606 </para></listitem> 1607 </varlistentry> 1608 </variablelist> 1609 <para> 1610 The connector is then registered with a call to 1611 <function>drm_connector_init</function> with a pointer to the connector 1612 functions and a connector type, and exposed through sysfs with a call to 1613 <function>drm_sysfs_connector_add</function>. 1614 </para> 1615 <para> 1616 Supported connector types are 1617 <itemizedlist> 1618 <listitem>DRM_MODE_CONNECTOR_VGA</listitem> 1619 <listitem>DRM_MODE_CONNECTOR_DVII</listitem> 1620 <listitem>DRM_MODE_CONNECTOR_DVID</listitem> 1621 <listitem>DRM_MODE_CONNECTOR_DVIA</listitem> 1622 <listitem>DRM_MODE_CONNECTOR_Composite</listitem> 1623 <listitem>DRM_MODE_CONNECTOR_SVIDEO</listitem> 1624 <listitem>DRM_MODE_CONNECTOR_LVDS</listitem> 1625 <listitem>DRM_MODE_CONNECTOR_Component</listitem> 1626 <listitem>DRM_MODE_CONNECTOR_9PinDIN</listitem> 1627 <listitem>DRM_MODE_CONNECTOR_DisplayPort</listitem> 1628 <listitem>DRM_MODE_CONNECTOR_HDMIA</listitem> 1629 <listitem>DRM_MODE_CONNECTOR_HDMIB</listitem> 1630 <listitem>DRM_MODE_CONNECTOR_TV</listitem> 1631 <listitem>DRM_MODE_CONNECTOR_eDP</listitem> 1632 <listitem>DRM_MODE_CONNECTOR_VIRTUAL</listitem> 1633 </itemizedlist> 1634 </para> 1635 <para> 1636 Connectors must be attached to an encoder to be used. For devices that 1637 map connectors to encoders 1:1, the connector should be attached at 1638 initialization time with a call to 1639 <function>drm_mode_connector_attach_encoder</function>. The driver must 1640 also set the <structname>drm_connector</structname> 1641 <structfield>encoder</structfield> field to point to the attached 1642 encoder. 1643 </para> 1644 <para> 1645 Finally, drivers must initialize the connectors state change detection 1646 with a call to <function>drm_kms_helper_poll_init</function>. If at 1647 least one connector is pollable but can't generate hotplug interrupts 1648 (indicated by the DRM_CONNECTOR_POLL_CONNECT and 1649 DRM_CONNECTOR_POLL_DISCONNECT connector flags), a delayed work will 1650 automatically be queued to periodically poll for changes. Connectors 1651 that can generate hotplug interrupts must be marked with the 1652 DRM_CONNECTOR_POLL_HPD flag instead, and their interrupt handler must 1653 call <function>drm_helper_hpd_irq_event</function>. The function will 1654 queue a delayed work to check the state of all connectors, but no 1655 periodic polling will be done. 1656 </para> 1657 </sect3> 1658 <sect3> 1659 <title>Connector Operations</title> 1660 <note><para> 1661 Unless otherwise state, all operations are mandatory. 1662 </para></note> 1663 <sect4> 1664 <title>DPMS</title> 1665 <synopsis>void (*dpms)(struct drm_connector *connector, int mode);</synopsis> 1666 <para> 1667 The DPMS operation sets the power state of a connector. The mode 1668 argument is one of 1669 <itemizedlist> 1670 <listitem><para>DRM_MODE_DPMS_ON</para></listitem> 1671 <listitem><para>DRM_MODE_DPMS_STANDBY</para></listitem> 1672 <listitem><para>DRM_MODE_DPMS_SUSPEND</para></listitem> 1673 <listitem><para>DRM_MODE_DPMS_OFF</para></listitem> 1674 </itemizedlist> 1675 </para> 1676 <para> 1677 In all but DPMS_ON mode the encoder to which the connector is attached 1678 should put the display in low-power mode by driving its signals 1679 appropriately. If more than one connector is attached to the encoder 1680 care should be taken not to change the power state of other displays as 1681 a side effect. Low-power mode should be propagated to the encoders and 1682 CRTCs when all related connectors are put in low-power mode. 1683 </para> 1684 </sect4> 1685 <sect4> 1686 <title>Modes</title> 1687 <synopsis>int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, 1688 uint32_t max_height);</synopsis> 1689 <para> 1690 Fill the mode list with all supported modes for the connector. If the 1691 <parameter>max_width</parameter> and <parameter>max_height</parameter> 1692 arguments are non-zero, the implementation must ignore all modes wider 1693 than <parameter>max_width</parameter> or higher than 1694 <parameter>max_height</parameter>. 1695 </para> 1696 <para> 1697 The connector must also fill in this operation its 1698 <structfield>display_info</structfield> 1699 <structfield>width_mm</structfield> and 1700 <structfield>height_mm</structfield> fields with the connected display 1701 physical size in millimeters. The fields should be set to 0 if the value 1702 isn't known or is not applicable (for instance for projector devices). 1703 </para> 1704 </sect4> 1705 <sect4> 1706 <title>Connection Status</title> 1707 <para> 1708 The connection status is updated through polling or hotplug events when 1709 supported (see <xref linkend="drm-kms-connector-polled"/>). The status 1710 value is reported to userspace through ioctls and must not be used 1711 inside the driver, as it only gets initialized by a call to 1712 <function>drm_mode_getconnector</function> from userspace. 1713 </para> 1714 <synopsis>enum drm_connector_status (*detect)(struct drm_connector *connector, 1715 bool force);</synopsis> 1716 <para> 1717 Check to see if anything is attached to the connector. The 1718 <parameter>force</parameter> parameter is set to false whilst polling or 1719 to true when checking the connector due to user request. 1720 <parameter>force</parameter> can be used by the driver to avoid 1721 expensive, destructive operations during automated probing. 1722 </para> 1723 <para> 1724 Return connector_status_connected if something is connected to the 1725 connector, connector_status_disconnected if nothing is connected and 1726 connector_status_unknown if the connection state isn't known. 1727 </para> 1728 <para> 1729 Drivers should only return connector_status_connected if the connection 1730 status has really been probed as connected. Connectors that can't detect 1731 the connection status, or failed connection status probes, should return 1732 connector_status_unknown. 1733 </para> 1734 </sect4> 1735 <sect4> 1736 <title>Miscellaneous</title> 1737 <itemizedlist> 1738 <listitem> 1739 <synopsis>void (*set_property)(struct drm_connector *connector, 1740 struct drm_property *property, uint64_t value);</synopsis> 1741 <para> 1742 Set the value of the given connector property to 1743 <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/> 1744 for more information about properties. 1745 </para> 1746 </listitem> 1747 <listitem> 1748 <synopsis>void (*destroy)(struct drm_connector *connector);</synopsis> 1749 <para> 1750 Destroy the connector when not needed anymore. See 1751 <xref linkend="drm-kms-init"/>. 1752 </para> 1753 </listitem> 1754 </itemizedlist> 1755 </sect4> 1756 </sect3> 1757 </sect2> 1758 <sect2> 1759 <title>Cleanup</title> 1760 <para> 1761 The DRM core manages its objects' lifetime. When an object is not needed 1762 anymore the core calls its destroy function, which must clean up and 1763 free every resource allocated for the object. Every 1764 <function>drm_*_init</function> call must be matched with a 1765 corresponding <function>drm_*_cleanup</function> call to cleanup CRTCs 1766 (<function>drm_crtc_cleanup</function>), planes 1767 (<function>drm_plane_cleanup</function>), encoders 1768 (<function>drm_encoder_cleanup</function>) and connectors 1769 (<function>drm_connector_cleanup</function>). Furthermore, connectors 1770 that have been added to sysfs must be removed by a call to 1771 <function>drm_sysfs_connector_remove</function> before calling 1772 <function>drm_connector_cleanup</function>. 1773 </para> 1774 <para> 1775 Connectors state change detection must be cleanup up with a call to 1776 <function>drm_kms_helper_poll_fini</function>. 1777 </para> 1778 </sect2> 1779 <sect2> 1780 <title>Output discovery and initialization example</title> 1781 <programlisting><![CDATA[ 1782void intel_crt_init(struct drm_device *dev) 1783{ 1784 struct drm_connector *connector; 1785 struct intel_output *intel_output; 1786 1787 intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL); 1788 if (!intel_output) 1789 return; 1790 1791 connector = &intel_output->base; 1792 drm_connector_init(dev, &intel_output->base, 1793 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA); 1794 1795 drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs, 1796 DRM_MODE_ENCODER_DAC); 1797 1798 drm_mode_connector_attach_encoder(&intel_output->base, 1799 &intel_output->enc); 1800 1801 /* Set up the DDC bus. */ 1802 intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A"); 1803 if (!intel_output->ddc_bus) { 1804 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration " 1805 "failed.\n"); 1806 return; 1807 } 1808 1809 intel_output->type = INTEL_OUTPUT_ANALOG; 1810 connector->interlace_allowed = 0; 1811 connector->doublescan_allowed = 0; 1812 1813 drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs); 1814 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); 1815 1816 drm_sysfs_connector_add(connector); 1817}]]></programlisting> 1818 <para> 1819 In the example above (taken from the i915 driver), a CRTC, connector and 1820 encoder combination is created. A device-specific i2c bus is also 1821 created for fetching EDID data and performing monitor detection. Once 1822 the process is complete, the new connector is registered with sysfs to 1823 make its properties available to applications. 1824 </para> 1825 </sect2> 1826 <sect2> 1827 <title>KMS API Functions</title> 1828!Edrivers/gpu/drm/drm_crtc.c 1829 </sect2> 1830 <sect2> 1831 <title>KMS Locking</title> 1832!Pdrivers/gpu/drm/drm_modeset_lock.c kms locking 1833!Iinclude/drm/drm_modeset_lock.h 1834!Edrivers/gpu/drm/drm_modeset_lock.c 1835 </sect2> 1836 </sect1> 1837 1838 <!-- Internals: kms helper functions --> 1839 1840 <sect1> 1841 <title>Mode Setting Helper Functions</title> 1842 <para> 1843 The plane, CRTC, encoder and connector functions provided by the drivers 1844 implement the DRM API. They're called by the DRM core and ioctl handlers 1845 to handle device state changes and configuration request. As implementing 1846 those functions often requires logic not specific to drivers, mid-layer 1847 helper functions are available to avoid duplicating boilerplate code. 1848 </para> 1849 <para> 1850 The DRM core contains one mid-layer implementation. The mid-layer provides 1851 implementations of several plane, CRTC, encoder and connector functions 1852 (called from the top of the mid-layer) that pre-process requests and call 1853 lower-level functions provided by the driver (at the bottom of the 1854 mid-layer). For instance, the 1855 <function>drm_crtc_helper_set_config</function> function can be used to 1856 fill the struct <structname>drm_crtc_funcs</structname> 1857 <structfield>set_config</structfield> field. When called, it will split 1858 the <methodname>set_config</methodname> operation in smaller, simpler 1859 operations and call the driver to handle them. 1860 </para> 1861 <para> 1862 To use the mid-layer, drivers call <function>drm_crtc_helper_add</function>, 1863 <function>drm_encoder_helper_add</function> and 1864 <function>drm_connector_helper_add</function> functions to install their 1865 mid-layer bottom operations handlers, and fill the 1866 <structname>drm_crtc_funcs</structname>, 1867 <structname>drm_encoder_funcs</structname> and 1868 <structname>drm_connector_funcs</structname> structures with pointers to 1869 the mid-layer top API functions. Installing the mid-layer bottom operation 1870 handlers is best done right after registering the corresponding KMS object. 1871 </para> 1872 <para> 1873 The mid-layer is not split between CRTC, encoder and connector operations. 1874 To use it, a driver must provide bottom functions for all of the three KMS 1875 entities. 1876 </para> 1877 <sect2> 1878 <title>Helper Functions</title> 1879 <itemizedlist> 1880 <listitem> 1881 <synopsis>int drm_crtc_helper_set_config(struct drm_mode_set *set);</synopsis> 1882 <para> 1883 The <function>drm_crtc_helper_set_config</function> helper function 1884 is a CRTC <methodname>set_config</methodname> implementation. It 1885 first tries to locate the best encoder for each connector by calling 1886 the connector <methodname>best_encoder</methodname> helper 1887 operation. 1888 </para> 1889 <para> 1890 After locating the appropriate encoders, the helper function will 1891 call the <methodname>mode_fixup</methodname> encoder and CRTC helper 1892 operations to adjust the requested mode, or reject it completely in 1893 which case an error will be returned to the application. If the new 1894 configuration after mode adjustment is identical to the current 1895 configuration the helper function will return without performing any 1896 other operation. 1897 </para> 1898 <para> 1899 If the adjusted mode is identical to the current mode but changes to 1900 the frame buffer need to be applied, the 1901 <function>drm_crtc_helper_set_config</function> function will call 1902 the CRTC <methodname>mode_set_base</methodname> helper operation. If 1903 the adjusted mode differs from the current mode, or if the 1904 <methodname>mode_set_base</methodname> helper operation is not 1905 provided, the helper function performs a full mode set sequence by 1906 calling the <methodname>prepare</methodname>, 1907 <methodname>mode_set</methodname> and 1908 <methodname>commit</methodname> CRTC and encoder helper operations, 1909 in that order. 1910 </para> 1911 </listitem> 1912 <listitem> 1913 <synopsis>void drm_helper_connector_dpms(struct drm_connector *connector, int mode);</synopsis> 1914 <para> 1915 The <function>drm_helper_connector_dpms</function> helper function 1916 is a connector <methodname>dpms</methodname> implementation that 1917 tracks power state of connectors. To use the function, drivers must 1918 provide <methodname>dpms</methodname> helper operations for CRTCs 1919 and encoders to apply the DPMS state to the device. 1920 </para> 1921 <para> 1922 The mid-layer doesn't track the power state of CRTCs and encoders. 1923 The <methodname>dpms</methodname> helper operations can thus be 1924 called with a mode identical to the currently active mode. 1925 </para> 1926 </listitem> 1927 <listitem> 1928 <synopsis>int drm_helper_probe_single_connector_modes(struct drm_connector *connector, 1929 uint32_t maxX, uint32_t maxY);</synopsis> 1930 <para> 1931 The <function>drm_helper_probe_single_connector_modes</function> helper 1932 function is a connector <methodname>fill_modes</methodname> 1933 implementation that updates the connection status for the connector 1934 and then retrieves a list of modes by calling the connector 1935 <methodname>get_modes</methodname> helper operation. 1936 </para> 1937 <para> 1938 The function filters out modes larger than 1939 <parameter>max_width</parameter> and <parameter>max_height</parameter> 1940 if specified. It then calls the optional connector 1941 <methodname>mode_valid</methodname> helper operation for each mode in 1942 the probed list to check whether the mode is valid for the connector. 1943 </para> 1944 </listitem> 1945 </itemizedlist> 1946 </sect2> 1947 <sect2> 1948 <title>CRTC Helper Operations</title> 1949 <itemizedlist> 1950 <listitem id="drm-helper-crtc-mode-fixup"> 1951 <synopsis>bool (*mode_fixup)(struct drm_crtc *crtc, 1952 const struct drm_display_mode *mode, 1953 struct drm_display_mode *adjusted_mode);</synopsis> 1954 <para> 1955 Let CRTCs adjust the requested mode or reject it completely. This 1956 operation returns true if the mode is accepted (possibly after being 1957 adjusted) or false if it is rejected. 1958 </para> 1959 <para> 1960 The <methodname>mode_fixup</methodname> operation should reject the 1961 mode if it can't reasonably use it. The definition of "reasonable" 1962 is currently fuzzy in this context. One possible behaviour would be 1963 to set the adjusted mode to the panel timings when a fixed-mode 1964 panel is used with hardware capable of scaling. Another behaviour 1965 would be to accept any input mode and adjust it to the closest mode 1966 supported by the hardware (FIXME: This needs to be clarified). 1967 </para> 1968 </listitem> 1969 <listitem> 1970 <synopsis>int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, 1971 struct drm_framebuffer *old_fb)</synopsis> 1972 <para> 1973 Move the CRTC on the current frame buffer (stored in 1974 <literal>crtc-&gt;fb</literal>) to position (x,y). Any of the frame 1975 buffer, x position or y position may have been modified. 1976 </para> 1977 <para> 1978 This helper operation is optional. If not provided, the 1979 <function>drm_crtc_helper_set_config</function> function will fall 1980 back to the <methodname>mode_set</methodname> helper operation. 1981 </para> 1982 <note><para> 1983 FIXME: Why are x and y passed as arguments, as they can be accessed 1984 through <literal>crtc-&gt;x</literal> and 1985 <literal>crtc-&gt;y</literal>? 1986 </para></note> 1987 </listitem> 1988 <listitem> 1989 <synopsis>void (*prepare)(struct drm_crtc *crtc);</synopsis> 1990 <para> 1991 Prepare the CRTC for mode setting. This operation is called after 1992 validating the requested mode. Drivers use it to perform 1993 device-specific operations required before setting the new mode. 1994 </para> 1995 </listitem> 1996 <listitem> 1997 <synopsis>int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode, 1998 struct drm_display_mode *adjusted_mode, int x, int y, 1999 struct drm_framebuffer *old_fb);</synopsis> 2000 <para> 2001 Set a new mode, position and frame buffer. Depending on the device 2002 requirements, the mode can be stored internally by the driver and 2003 applied in the <methodname>commit</methodname> operation, or 2004 programmed to the hardware immediately. 2005 </para> 2006 <para> 2007 The <methodname>mode_set</methodname> operation returns 0 on success 2008 or a negative error code if an error occurs. 2009 </para> 2010 </listitem> 2011 <listitem> 2012 <synopsis>void (*commit)(struct drm_crtc *crtc);</synopsis> 2013 <para> 2014 Commit a mode. This operation is called after setting the new mode. 2015 Upon return the device must use the new mode and be fully 2016 operational. 2017 </para> 2018 </listitem> 2019 </itemizedlist> 2020 </sect2> 2021 <sect2> 2022 <title>Encoder Helper Operations</title> 2023 <itemizedlist> 2024 <listitem> 2025 <synopsis>bool (*mode_fixup)(struct drm_encoder *encoder, 2026 const struct drm_display_mode *mode, 2027 struct drm_display_mode *adjusted_mode);</synopsis> 2028 <para> 2029 Let encoders adjust the requested mode or reject it completely. This 2030 operation returns true if the mode is accepted (possibly after being 2031 adjusted) or false if it is rejected. See the 2032 <link linkend="drm-helper-crtc-mode-fixup">mode_fixup CRTC helper 2033 operation</link> for an explanation of the allowed adjustments. 2034 </para> 2035 </listitem> 2036 <listitem> 2037 <synopsis>void (*prepare)(struct drm_encoder *encoder);</synopsis> 2038 <para> 2039 Prepare the encoder for mode setting. This operation is called after 2040 validating the requested mode. Drivers use it to perform 2041 device-specific operations required before setting the new mode. 2042 </para> 2043 </listitem> 2044 <listitem> 2045 <synopsis>void (*mode_set)(struct drm_encoder *encoder, 2046 struct drm_display_mode *mode, 2047 struct drm_display_mode *adjusted_mode);</synopsis> 2048 <para> 2049 Set a new mode. Depending on the device requirements, the mode can 2050 be stored internally by the driver and applied in the 2051 <methodname>commit</methodname> operation, or programmed to the 2052 hardware immediately. 2053 </para> 2054 </listitem> 2055 <listitem> 2056 <synopsis>void (*commit)(struct drm_encoder *encoder);</synopsis> 2057 <para> 2058 Commit a mode. This operation is called after setting the new mode. 2059 Upon return the device must use the new mode and be fully 2060 operational. 2061 </para> 2062 </listitem> 2063 </itemizedlist> 2064 </sect2> 2065 <sect2> 2066 <title>Connector Helper Operations</title> 2067 <itemizedlist> 2068 <listitem> 2069 <synopsis>struct drm_encoder *(*best_encoder)(struct drm_connector *connector);</synopsis> 2070 <para> 2071 Return a pointer to the best encoder for the connecter. Device that 2072 map connectors to encoders 1:1 simply return the pointer to the 2073 associated encoder. This operation is mandatory. 2074 </para> 2075 </listitem> 2076 <listitem> 2077 <synopsis>int (*get_modes)(struct drm_connector *connector);</synopsis> 2078 <para> 2079 Fill the connector's <structfield>probed_modes</structfield> list 2080 by parsing EDID data with <function>drm_add_edid_modes</function> or 2081 calling <function>drm_mode_probed_add</function> directly for every 2082 supported mode and return the number of modes it has detected. This 2083 operation is mandatory. 2084 </para> 2085 <para> 2086 When adding modes manually the driver creates each mode with a call to 2087 <function>drm_mode_create</function> and must fill the following fields. 2088 <itemizedlist> 2089 <listitem> 2090 <synopsis>__u32 type;</synopsis> 2091 <para> 2092 Mode type bitmask, a combination of 2093 <variablelist> 2094 <varlistentry> 2095 <term>DRM_MODE_TYPE_BUILTIN</term> 2096 <listitem><para>not used?</para></listitem> 2097 </varlistentry> 2098 <varlistentry> 2099 <term>DRM_MODE_TYPE_CLOCK_C</term> 2100 <listitem><para>not used?</para></listitem> 2101 </varlistentry> 2102 <varlistentry> 2103 <term>DRM_MODE_TYPE_CRTC_C</term> 2104 <listitem><para>not used?</para></listitem> 2105 </varlistentry> 2106 <varlistentry> 2107 <term> 2108 DRM_MODE_TYPE_PREFERRED - The preferred mode for the connector 2109 </term> 2110 <listitem> 2111 <para>not used?</para> 2112 </listitem> 2113 </varlistentry> 2114 <varlistentry> 2115 <term>DRM_MODE_TYPE_DEFAULT</term> 2116 <listitem><para>not used?</para></listitem> 2117 </varlistentry> 2118 <varlistentry> 2119 <term>DRM_MODE_TYPE_USERDEF</term> 2120 <listitem><para>not used?</para></listitem> 2121 </varlistentry> 2122 <varlistentry> 2123 <term>DRM_MODE_TYPE_DRIVER</term> 2124 <listitem> 2125 <para> 2126 The mode has been created by the driver (as opposed to 2127 to user-created modes). 2128 </para> 2129 </listitem> 2130 </varlistentry> 2131 </variablelist> 2132 Drivers must set the DRM_MODE_TYPE_DRIVER bit for all modes they 2133 create, and set the DRM_MODE_TYPE_PREFERRED bit for the preferred 2134 mode. 2135 </para> 2136 </listitem> 2137 <listitem> 2138 <synopsis>__u32 clock;</synopsis> 2139 <para>Pixel clock frequency in kHz unit</para> 2140 </listitem> 2141 <listitem> 2142 <synopsis>__u16 hdisplay, hsync_start, hsync_end, htotal; 2143 __u16 vdisplay, vsync_start, vsync_end, vtotal;</synopsis> 2144 <para>Horizontal and vertical timing information</para> 2145 <screen><![CDATA[ 2146 Active Front Sync Back 2147 Region Porch Porch 2148 <-----------------------><----------------><-------------><--------------> 2149 2150 //////////////////////| 2151 ////////////////////// | 2152 ////////////////////// |.................. ................ 2153 _______________ 2154 2155 <----- [hv]display -----> 2156 <------------- [hv]sync_start ------------> 2157 <--------------------- [hv]sync_end ---------------------> 2158 <-------------------------------- [hv]total -----------------------------> 2159]]></screen> 2160 </listitem> 2161 <listitem> 2162 <synopsis>__u16 hskew; 2163 __u16 vscan;</synopsis> 2164 <para>Unknown</para> 2165 </listitem> 2166 <listitem> 2167 <synopsis>__u32 flags;</synopsis> 2168 <para> 2169 Mode flags, a combination of 2170 <variablelist> 2171 <varlistentry> 2172 <term>DRM_MODE_FLAG_PHSYNC</term> 2173 <listitem><para> 2174 Horizontal sync is active high 2175 </para></listitem> 2176 </varlistentry> 2177 <varlistentry> 2178 <term>DRM_MODE_FLAG_NHSYNC</term> 2179 <listitem><para> 2180 Horizontal sync is active low 2181 </para></listitem> 2182 </varlistentry> 2183 <varlistentry> 2184 <term>DRM_MODE_FLAG_PVSYNC</term> 2185 <listitem><para> 2186 Vertical sync is active high 2187 </para></listitem> 2188 </varlistentry> 2189 <varlistentry> 2190 <term>DRM_MODE_FLAG_NVSYNC</term> 2191 <listitem><para> 2192 Vertical sync is active low 2193 </para></listitem> 2194 </varlistentry> 2195 <varlistentry> 2196 <term>DRM_MODE_FLAG_INTERLACE</term> 2197 <listitem><para> 2198 Mode is interlaced 2199 </para></listitem> 2200 </varlistentry> 2201 <varlistentry> 2202 <term>DRM_MODE_FLAG_DBLSCAN</term> 2203 <listitem><para> 2204 Mode uses doublescan 2205 </para></listitem> 2206 </varlistentry> 2207 <varlistentry> 2208 <term>DRM_MODE_FLAG_CSYNC</term> 2209 <listitem><para> 2210 Mode uses composite sync 2211 </para></listitem> 2212 </varlistentry> 2213 <varlistentry> 2214 <term>DRM_MODE_FLAG_PCSYNC</term> 2215 <listitem><para> 2216 Composite sync is active high 2217 </para></listitem> 2218 </varlistentry> 2219 <varlistentry> 2220 <term>DRM_MODE_FLAG_NCSYNC</term> 2221 <listitem><para> 2222 Composite sync is active low 2223 </para></listitem> 2224 </varlistentry> 2225 <varlistentry> 2226 <term>DRM_MODE_FLAG_HSKEW</term> 2227 <listitem><para> 2228 hskew provided (not used?) 2229 </para></listitem> 2230 </varlistentry> 2231 <varlistentry> 2232 <term>DRM_MODE_FLAG_BCAST</term> 2233 <listitem><para> 2234 not used? 2235 </para></listitem> 2236 </varlistentry> 2237 <varlistentry> 2238 <term>DRM_MODE_FLAG_PIXMUX</term> 2239 <listitem><para> 2240 not used? 2241 </para></listitem> 2242 </varlistentry> 2243 <varlistentry> 2244 <term>DRM_MODE_FLAG_DBLCLK</term> 2245 <listitem><para> 2246 not used? 2247 </para></listitem> 2248 </varlistentry> 2249 <varlistentry> 2250 <term>DRM_MODE_FLAG_CLKDIV2</term> 2251 <listitem><para> 2252 ? 2253 </para></listitem> 2254 </varlistentry> 2255 </variablelist> 2256 </para> 2257 <para> 2258 Note that modes marked with the INTERLACE or DBLSCAN flags will be 2259 filtered out by 2260 <function>drm_helper_probe_single_connector_modes</function> if 2261 the connector's <structfield>interlace_allowed</structfield> or 2262 <structfield>doublescan_allowed</structfield> field is set to 0. 2263 </para> 2264 </listitem> 2265 <listitem> 2266 <synopsis>char name[DRM_DISPLAY_MODE_LEN];</synopsis> 2267 <para> 2268 Mode name. The driver must call 2269 <function>drm_mode_set_name</function> to fill the mode name from 2270 <structfield>hdisplay</structfield>, 2271 <structfield>vdisplay</structfield> and interlace flag after 2272 filling the corresponding fields. 2273 </para> 2274 </listitem> 2275 </itemizedlist> 2276 </para> 2277 <para> 2278 The <structfield>vrefresh</structfield> value is computed by 2279 <function>drm_helper_probe_single_connector_modes</function>. 2280 </para> 2281 <para> 2282 When parsing EDID data, <function>drm_add_edid_modes</function> fill the 2283 connector <structfield>display_info</structfield> 2284 <structfield>width_mm</structfield> and 2285 <structfield>height_mm</structfield> fields. When creating modes 2286 manually the <methodname>get_modes</methodname> helper operation must 2287 set the <structfield>display_info</structfield> 2288 <structfield>width_mm</structfield> and 2289 <structfield>height_mm</structfield> fields if they haven't been set 2290 already (for instance at initialization time when a fixed-size panel is 2291 attached to the connector). The mode <structfield>width_mm</structfield> 2292 and <structfield>height_mm</structfield> fields are only used internally 2293 during EDID parsing and should not be set when creating modes manually. 2294 </para> 2295 </listitem> 2296 <listitem> 2297 <synopsis>int (*mode_valid)(struct drm_connector *connector, 2298 struct drm_display_mode *mode);</synopsis> 2299 <para> 2300 Verify whether a mode is valid for the connector. Return MODE_OK for 2301 supported modes and one of the enum drm_mode_status values (MODE_*) 2302 for unsupported modes. This operation is optional. 2303 </para> 2304 <para> 2305 As the mode rejection reason is currently not used beside for 2306 immediately removing the unsupported mode, an implementation can 2307 return MODE_BAD regardless of the exact reason why the mode is not 2308 valid. 2309 </para> 2310 <note><para> 2311 Note that the <methodname>mode_valid</methodname> helper operation is 2312 only called for modes detected by the device, and 2313 <emphasis>not</emphasis> for modes set by the user through the CRTC 2314 <methodname>set_config</methodname> operation. 2315 </para></note> 2316 </listitem> 2317 </itemizedlist> 2318 </sect2> 2319 <sect2> 2320 <title>Modeset Helper Functions Reference</title> 2321!Edrivers/gpu/drm/drm_crtc_helper.c 2322 </sect2> 2323 <sect2> 2324 <title>Output Probing Helper Functions Reference</title> 2325!Pdrivers/gpu/drm/drm_probe_helper.c output probing helper overview 2326!Edrivers/gpu/drm/drm_probe_helper.c 2327 </sect2> 2328 <sect2> 2329 <title>fbdev Helper Functions Reference</title> 2330!Pdrivers/gpu/drm/drm_fb_helper.c fbdev helpers 2331!Edrivers/gpu/drm/drm_fb_helper.c 2332!Iinclude/drm/drm_fb_helper.h 2333 </sect2> 2334 <sect2> 2335 <title>Display Port Helper Functions Reference</title> 2336!Pdrivers/gpu/drm/drm_dp_helper.c dp helpers 2337!Iinclude/drm/drm_dp_helper.h 2338!Edrivers/gpu/drm/drm_dp_helper.c 2339 </sect2> 2340 <sect2> 2341 <title>EDID Helper Functions Reference</title> 2342!Edrivers/gpu/drm/drm_edid.c 2343 </sect2> 2344 <sect2> 2345 <title>Rectangle Utilities Reference</title> 2346!Pinclude/drm/drm_rect.h rect utils 2347!Iinclude/drm/drm_rect.h 2348!Edrivers/gpu/drm/drm_rect.c 2349 </sect2> 2350 <sect2> 2351 <title>Flip-work Helper Reference</title> 2352!Pinclude/drm/drm_flip_work.h flip utils 2353!Iinclude/drm/drm_flip_work.h 2354!Edrivers/gpu/drm/drm_flip_work.c 2355 </sect2> 2356 <sect2> 2357 <title>HDMI Infoframes Helper Reference</title> 2358 <para> 2359 Strictly speaking this is not a DRM helper library but generally useable 2360 by any driver interfacing with HDMI outputs like v4l or alsa drivers. 2361 But it nicely fits into the overall topic of mode setting helper 2362 libraries and hence is also included here. 2363 </para> 2364!Iinclude/linux/hdmi.h 2365!Edrivers/video/hdmi.c 2366 </sect2> 2367 <sect2> 2368 <title id="drm-kms-planehelpers">Plane Helper Reference</title> 2369!Edrivers/gpu/drm/drm_plane_helper.c Plane Helpers 2370 </sect2> 2371 </sect1> 2372 2373 <!-- Internals: kms properties --> 2374 2375 <sect1 id="drm-kms-properties"> 2376 <title>KMS Properties</title> 2377 <para> 2378 Drivers may need to expose additional parameters to applications than 2379 those described in the previous sections. KMS supports attaching 2380 properties to CRTCs, connectors and planes and offers a userspace API to 2381 list, get and set the property values. 2382 </para> 2383 <para> 2384 Properties are identified by a name that uniquely defines the property 2385 purpose, and store an associated value. For all property types except blob 2386 properties the value is a 64-bit unsigned integer. 2387 </para> 2388 <para> 2389 KMS differentiates between properties and property instances. Drivers 2390 first create properties and then create and associate individual instances 2391 of those properties to objects. A property can be instantiated multiple 2392 times and associated with different objects. Values are stored in property 2393 instances, and all other property information are stored in the property 2394 and shared between all instances of the property. 2395 </para> 2396 <para> 2397 Every property is created with a type that influences how the KMS core 2398 handles the property. Supported property types are 2399 <variablelist> 2400 <varlistentry> 2401 <term>DRM_MODE_PROP_RANGE</term> 2402 <listitem><para>Range properties report their minimum and maximum 2403 admissible values. The KMS core verifies that values set by 2404 application fit in that range.</para></listitem> 2405 </varlistentry> 2406 <varlistentry> 2407 <term>DRM_MODE_PROP_ENUM</term> 2408 <listitem><para>Enumerated properties take a numerical value that 2409 ranges from 0 to the number of enumerated values defined by the 2410 property minus one, and associate a free-formed string name to each 2411 value. Applications can retrieve the list of defined value-name pairs 2412 and use the numerical value to get and set property instance values. 2413 </para></listitem> 2414 </varlistentry> 2415 <varlistentry> 2416 <term>DRM_MODE_PROP_BITMASK</term> 2417 <listitem><para>Bitmask properties are enumeration properties that 2418 additionally restrict all enumerated values to the 0..63 range. 2419 Bitmask property instance values combine one or more of the 2420 enumerated bits defined by the property.</para></listitem> 2421 </varlistentry> 2422 <varlistentry> 2423 <term>DRM_MODE_PROP_BLOB</term> 2424 <listitem><para>Blob properties store a binary blob without any format 2425 restriction. The binary blobs are created as KMS standalone objects, 2426 and blob property instance values store the ID of their associated 2427 blob object.</para> 2428 <para>Blob properties are only used for the connector EDID property 2429 and cannot be created by drivers.</para></listitem> 2430 </varlistentry> 2431 </variablelist> 2432 </para> 2433 <para> 2434 To create a property drivers call one of the following functions depending 2435 on the property type. All property creation functions take property flags 2436 and name, as well as type-specific arguments. 2437 <itemizedlist> 2438 <listitem> 2439 <synopsis>struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, 2440 const char *name, 2441 uint64_t min, uint64_t max);</synopsis> 2442 <para>Create a range property with the given minimum and maximum 2443 values.</para> 2444 </listitem> 2445 <listitem> 2446 <synopsis>struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, 2447 const char *name, 2448 const struct drm_prop_enum_list *props, 2449 int num_values);</synopsis> 2450 <para>Create an enumerated property. The <parameter>props</parameter> 2451 argument points to an array of <parameter>num_values</parameter> 2452 value-name pairs.</para> 2453 </listitem> 2454 <listitem> 2455 <synopsis>struct drm_property *drm_property_create_bitmask(struct drm_device *dev, 2456 int flags, const char *name, 2457 const struct drm_prop_enum_list *props, 2458 int num_values);</synopsis> 2459 <para>Create a bitmask property. The <parameter>props</parameter> 2460 argument points to an array of <parameter>num_values</parameter> 2461 value-name pairs.</para> 2462 </listitem> 2463 </itemizedlist> 2464 </para> 2465 <para> 2466 Properties can additionally be created as immutable, in which case they 2467 will be read-only for applications but can be modified by the driver. To 2468 create an immutable property drivers must set the DRM_MODE_PROP_IMMUTABLE 2469 flag at property creation time. 2470 </para> 2471 <para> 2472 When no array of value-name pairs is readily available at property 2473 creation time for enumerated or range properties, drivers can create 2474 the property using the <function>drm_property_create</function> function 2475 and manually add enumeration value-name pairs by calling the 2476 <function>drm_property_add_enum</function> function. Care must be taken to 2477 properly specify the property type through the <parameter>flags</parameter> 2478 argument. 2479 </para> 2480 <para> 2481 After creating properties drivers can attach property instances to CRTC, 2482 connector and plane objects by calling the 2483 <function>drm_object_attach_property</function>. The function takes a 2484 pointer to the target object, a pointer to the previously created property 2485 and an initial instance value. 2486 </para> 2487 <sect2> 2488 <title>Existing KMS Properties</title> 2489 <para> 2490 The following table gives description of drm properties exposed by various 2491 modules/drivers. 2492 </para> 2493 <table border="1" cellpadding="0" cellspacing="0"> 2494 <tbody> 2495 <tr style="font-weight: bold;"> 2496 <td valign="top" >Owner Module/Drivers</td> 2497 <td valign="top" >Group</td> 2498 <td valign="top" >Property Name</td> 2499 <td valign="top" >Type</td> 2500 <td valign="top" >Property Values</td> 2501 <td valign="top" >Object attached</td> 2502 <td valign="top" >Description/Restrictions</td> 2503 </tr> 2504 <tr> 2505 <td rowspan="20" valign="top" >DRM</td> 2506 <td rowspan="2" valign="top" >Generic</td> 2507 <td valign="top" >“EDID”</td> 2508 <td valign="top" >BLOB | IMMUTABLE</td> 2509 <td valign="top" >0</td> 2510 <td valign="top" >Connector</td> 2511 <td valign="top" >Contains id of edid blob ptr object.</td> 2512 </tr> 2513 <tr> 2514 <td valign="top" >“DPMS”</td> 2515 <td valign="top" >ENUM</td> 2516 <td valign="top" >{ “On”, “Standby”, “Suspend”, “Off” }</td> 2517 <td valign="top" >Connector</td> 2518 <td valign="top" >Contains DPMS operation mode value.</td> 2519 </tr> 2520 <tr> 2521 <td rowspan="1" valign="top" >Plane</td> 2522 <td valign="top" >“type”</td> 2523 <td valign="top" >ENUM | IMMUTABLE</td> 2524 <td valign="top" >{ "Overlay", "Primary", "Cursor" }</td> 2525 <td valign="top" >Plane</td> 2526 <td valign="top" >Plane type</td> 2527 </tr> 2528 <tr> 2529 <td rowspan="2" valign="top" >DVI-I</td> 2530 <td valign="top" >“subconnector”</td> 2531 <td valign="top" >ENUM</td> 2532 <td valign="top" >{ “Unknown”, “DVI-D”, “DVI-A” }</td> 2533 <td valign="top" >Connector</td> 2534 <td valign="top" >TBD</td> 2535 </tr> 2536 <tr> 2537 <td valign="top" >“select subconnector”</td> 2538 <td valign="top" >ENUM</td> 2539 <td valign="top" >{ “Automatic”, “DVI-D”, “DVI-A” }</td> 2540 <td valign="top" >Connector</td> 2541 <td valign="top" >TBD</td> 2542 </tr> 2543 <tr> 2544 <td rowspan="13" valign="top" >TV</td> 2545 <td valign="top" >“subconnector”</td> 2546 <td valign="top" >ENUM</td> 2547 <td valign="top" >{ "Unknown", "Composite", "SVIDEO", "Component", "SCART" }</td> 2548 <td valign="top" >Connector</td> 2549 <td valign="top" >TBD</td> 2550 </tr> 2551 <tr> 2552 <td valign="top" >“select subconnector”</td> 2553 <td valign="top" >ENUM</td> 2554 <td valign="top" >{ "Automatic", "Composite", "SVIDEO", "Component", "SCART" }</td> 2555 <td valign="top" >Connector</td> 2556 <td valign="top" >TBD</td> 2557 </tr> 2558 <tr> 2559 <td valign="top" >“mode”</td> 2560 <td valign="top" >ENUM</td> 2561 <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td> 2562 <td valign="top" >Connector</td> 2563 <td valign="top" >TBD</td> 2564 </tr> 2565 <tr> 2566 <td valign="top" >“left margin”</td> 2567 <td valign="top" >RANGE</td> 2568 <td valign="top" >Min=0, Max=100</td> 2569 <td valign="top" >Connector</td> 2570 <td valign="top" >TBD</td> 2571 </tr> 2572 <tr> 2573 <td valign="top" >“right margin”</td> 2574 <td valign="top" >RANGE</td> 2575 <td valign="top" >Min=0, Max=100</td> 2576 <td valign="top" >Connector</td> 2577 <td valign="top" >TBD</td> 2578 </tr> 2579 <tr> 2580 <td valign="top" >“top margin”</td> 2581 <td valign="top" >RANGE</td> 2582 <td valign="top" >Min=0, Max=100</td> 2583 <td valign="top" >Connector</td> 2584 <td valign="top" >TBD</td> 2585 </tr> 2586 <tr> 2587 <td valign="top" >“bottom margin”</td> 2588 <td valign="top" >RANGE</td> 2589 <td valign="top" >Min=0, Max=100</td> 2590 <td valign="top" >Connector</td> 2591 <td valign="top" >TBD</td> 2592 </tr> 2593 <tr> 2594 <td valign="top" >“brightness”</td> 2595 <td valign="top" >RANGE</td> 2596 <td valign="top" >Min=0, Max=100</td> 2597 <td valign="top" >Connector</td> 2598 <td valign="top" >TBD</td> 2599 </tr> 2600 <tr> 2601 <td valign="top" >“contrast”</td> 2602 <td valign="top" >RANGE</td> 2603 <td valign="top" >Min=0, Max=100</td> 2604 <td valign="top" >Connector</td> 2605 <td valign="top" >TBD</td> 2606 </tr> 2607 <tr> 2608 <td valign="top" >“flicker reduction”</td> 2609 <td valign="top" >RANGE</td> 2610 <td valign="top" >Min=0, Max=100</td> 2611 <td valign="top" >Connector</td> 2612 <td valign="top" >TBD</td> 2613 </tr> 2614 <tr> 2615 <td valign="top" >“overscan”</td> 2616 <td valign="top" >RANGE</td> 2617 <td valign="top" >Min=0, Max=100</td> 2618 <td valign="top" >Connector</td> 2619 <td valign="top" >TBD</td> 2620 </tr> 2621 <tr> 2622 <td valign="top" >“saturation”</td> 2623 <td valign="top" >RANGE</td> 2624 <td valign="top" >Min=0, Max=100</td> 2625 <td valign="top" >Connector</td> 2626 <td valign="top" >TBD</td> 2627 </tr> 2628 <tr> 2629 <td valign="top" >“hue”</td> 2630 <td valign="top" >RANGE</td> 2631 <td valign="top" >Min=0, Max=100</td> 2632 <td valign="top" >Connector</td> 2633 <td valign="top" >TBD</td> 2634 </tr> 2635 <tr> 2636 <td rowspan="2" valign="top" >Optional</td> 2637 <td valign="top" >“scaling mode”</td> 2638 <td valign="top" >ENUM</td> 2639 <td valign="top" >{ "None", "Full", "Center", "Full aspect" }</td> 2640 <td valign="top" >Connector</td> 2641 <td valign="top" >TBD</td> 2642 </tr> 2643 <tr> 2644 <td valign="top" >“dirty”</td> 2645 <td valign="top" >ENUM | IMMUTABLE</td> 2646 <td valign="top" >{ "Off", "On", "Annotate" }</td> 2647 <td valign="top" >Connector</td> 2648 <td valign="top" >TBD</td> 2649 </tr> 2650 <tr> 2651 <td rowspan="21" valign="top" >i915</td> 2652 <td rowspan="3" valign="top" >Generic</td> 2653 <td valign="top" >"Broadcast RGB"</td> 2654 <td valign="top" >ENUM</td> 2655 <td valign="top" >{ "Automatic", "Full", "Limited 16:235" }</td> 2656 <td valign="top" >Connector</td> 2657 <td valign="top" >TBD</td> 2658 </tr> 2659 <tr> 2660 <td valign="top" >“audio”</td> 2661 <td valign="top" >ENUM</td> 2662 <td valign="top" >{ "force-dvi", "off", "auto", "on" }</td> 2663 <td valign="top" >Connector</td> 2664 <td valign="top" >TBD</td> 2665 </tr> 2666 <tr> 2667 <td valign="top" >Standard name as in DRM</td> 2668 <td valign="top" >Standard type as in DRM</td> 2669 <td valign="top" >Standard value as in DRM</td> 2670 <td valign="top" >Standard Object as in DRM</td> 2671 <td valign="top" >TBD</td> 2672 </tr> 2673 <tr> 2674 <td rowspan="17" valign="top" >SDVO-TV</td> 2675 <td valign="top" >“mode”</td> 2676 <td valign="top" >ENUM</td> 2677 <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td> 2678 <td valign="top" >Connector</td> 2679 <td valign="top" >TBD</td> 2680 </tr> 2681 <tr> 2682 <td valign="top" >"left_margin"</td> 2683 <td valign="top" >RANGE</td> 2684 <td valign="top" >Min=0, Max= SDVO dependent</td> 2685 <td valign="top" >Connector</td> 2686 <td valign="top" >TBD</td> 2687 </tr> 2688 <tr> 2689 <td valign="top" >"right_margin"</td> 2690 <td valign="top" >RANGE</td> 2691 <td valign="top" >Min=0, Max= SDVO dependent</td> 2692 <td valign="top" >Connector</td> 2693 <td valign="top" >TBD</td> 2694 </tr> 2695 <tr> 2696 <td valign="top" >"top_margin"</td> 2697 <td valign="top" >RANGE</td> 2698 <td valign="top" >Min=0, Max= SDVO dependent</td> 2699 <td valign="top" >Connector</td> 2700 <td valign="top" >TBD</td> 2701 </tr> 2702 <tr> 2703 <td valign="top" >"bottom_margin"</td> 2704 <td valign="top" >RANGE</td> 2705 <td valign="top" >Min=0, Max= SDVO dependent</td> 2706 <td valign="top" >Connector</td> 2707 <td valign="top" >TBD</td> 2708 </tr> 2709 <tr> 2710 <td valign="top" >“hpos”</td> 2711 <td valign="top" >RANGE</td> 2712 <td valign="top" >Min=0, Max= SDVO dependent</td> 2713 <td valign="top" >Connector</td> 2714 <td valign="top" >TBD</td> 2715 </tr> 2716 <tr> 2717 <td valign="top" >“vpos”</td> 2718 <td valign="top" >RANGE</td> 2719 <td valign="top" >Min=0, Max= SDVO dependent</td> 2720 <td valign="top" >Connector</td> 2721 <td valign="top" >TBD</td> 2722 </tr> 2723 <tr> 2724 <td valign="top" >“contrast”</td> 2725 <td valign="top" >RANGE</td> 2726 <td valign="top" >Min=0, Max= SDVO dependent</td> 2727 <td valign="top" >Connector</td> 2728 <td valign="top" >TBD</td> 2729 </tr> 2730 <tr> 2731 <td valign="top" >“saturation”</td> 2732 <td valign="top" >RANGE</td> 2733 <td valign="top" >Min=0, Max= SDVO dependent</td> 2734 <td valign="top" >Connector</td> 2735 <td valign="top" >TBD</td> 2736 </tr> 2737 <tr> 2738 <td valign="top" >“hue”</td> 2739 <td valign="top" >RANGE</td> 2740 <td valign="top" >Min=0, Max= SDVO dependent</td> 2741 <td valign="top" >Connector</td> 2742 <td valign="top" >TBD</td> 2743 </tr> 2744 <tr> 2745 <td valign="top" >“sharpness”</td> 2746 <td valign="top" >RANGE</td> 2747 <td valign="top" >Min=0, Max= SDVO dependent</td> 2748 <td valign="top" >Connector</td> 2749 <td valign="top" >TBD</td> 2750 </tr> 2751 <tr> 2752 <td valign="top" >“flicker_filter”</td> 2753 <td valign="top" >RANGE</td> 2754 <td valign="top" >Min=0, Max= SDVO dependent</td> 2755 <td valign="top" >Connector</td> 2756 <td valign="top" >TBD</td> 2757 </tr> 2758 <tr> 2759 <td valign="top" >“flicker_filter_adaptive”</td> 2760 <td valign="top" >RANGE</td> 2761 <td valign="top" >Min=0, Max= SDVO dependent</td> 2762 <td valign="top" >Connector</td> 2763 <td valign="top" >TBD</td> 2764 </tr> 2765 <tr> 2766 <td valign="top" >“flicker_filter_2d”</td> 2767 <td valign="top" >RANGE</td> 2768 <td valign="top" >Min=0, Max= SDVO dependent</td> 2769 <td valign="top" >Connector</td> 2770 <td valign="top" >TBD</td> 2771 </tr> 2772 <tr> 2773 <td valign="top" >“tv_chroma_filter”</td> 2774 <td valign="top" >RANGE</td> 2775 <td valign="top" >Min=0, Max= SDVO dependent</td> 2776 <td valign="top" >Connector</td> 2777 <td valign="top" >TBD</td> 2778 </tr> 2779 <tr> 2780 <td valign="top" >“tv_luma_filter”</td> 2781 <td valign="top" >RANGE</td> 2782 <td valign="top" >Min=0, Max= SDVO dependent</td> 2783 <td valign="top" >Connector</td> 2784 <td valign="top" >TBD</td> 2785 </tr> 2786 <tr> 2787 <td valign="top" >“dot_crawl”</td> 2788 <td valign="top" >RANGE</td> 2789 <td valign="top" >Min=0, Max=1</td> 2790 <td valign="top" >Connector</td> 2791 <td valign="top" >TBD</td> 2792 </tr> 2793 <tr> 2794 <td valign="top" >SDVO-TV/LVDS</td> 2795 <td valign="top" >“brightness”</td> 2796 <td valign="top" >RANGE</td> 2797 <td valign="top" >Min=0, Max= SDVO dependent</td> 2798 <td valign="top" >Connector</td> 2799 <td valign="top" >TBD</td> 2800 </tr> 2801 <tr> 2802 <td rowspan="3" valign="top" >CDV gma-500</td> 2803 <td rowspan="3" valign="top" >Generic</td> 2804 <td valign="top" >"Broadcast RGB"</td> 2805 <td valign="top" >ENUM</td> 2806 <td valign="top" >{ “Full”, “Limited 16:235” }</td> 2807 <td valign="top" >Connector</td> 2808 <td valign="top" >TBD</td> 2809 </tr> 2810 <tr> 2811 <td valign="top" >"Broadcast RGB"</td> 2812 <td valign="top" >ENUM</td> 2813 <td valign="top" >{ “off”, “auto”, “on” }</td> 2814 <td valign="top" >Connector</td> 2815 <td valign="top" >TBD</td> 2816 </tr> 2817 <tr> 2818 <td valign="top" >Standard name as in DRM</td> 2819 <td valign="top" >Standard type as in DRM</td> 2820 <td valign="top" >Standard value as in DRM</td> 2821 <td valign="top" >Standard Object as in DRM</td> 2822 <td valign="top" >TBD</td> 2823 </tr> 2824 <tr> 2825 <td rowspan="20" valign="top" >Poulsbo</td> 2826 <td rowspan="2" valign="top" >Generic</td> 2827 <td valign="top" >“backlight”</td> 2828 <td valign="top" >RANGE</td> 2829 <td valign="top" >Min=0, Max=100</td> 2830 <td valign="top" >Connector</td> 2831 <td valign="top" >TBD</td> 2832 </tr> 2833 <tr> 2834 <td valign="top" >Standard name as in DRM</td> 2835 <td valign="top" >Standard type as in DRM</td> 2836 <td valign="top" >Standard value as in DRM</td> 2837 <td valign="top" >Standard Object as in DRM</td> 2838 <td valign="top" >TBD</td> 2839 </tr> 2840 <tr> 2841 <td rowspan="17" valign="top" >SDVO-TV</td> 2842 <td valign="top" >“mode”</td> 2843 <td valign="top" >ENUM</td> 2844 <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td> 2845 <td valign="top" >Connector</td> 2846 <td valign="top" >TBD</td> 2847 </tr> 2848 <tr> 2849 <td valign="top" >"left_margin"</td> 2850 <td valign="top" >RANGE</td> 2851 <td valign="top" >Min=0, Max= SDVO dependent</td> 2852 <td valign="top" >Connector</td> 2853 <td valign="top" >TBD</td> 2854 </tr> 2855 <tr> 2856 <td valign="top" >"right_margin"</td> 2857 <td valign="top" >RANGE</td> 2858 <td valign="top" >Min=0, Max= SDVO dependent</td> 2859 <td valign="top" >Connector</td> 2860 <td valign="top" >TBD</td> 2861 </tr> 2862 <tr> 2863 <td valign="top" >"top_margin"</td> 2864 <td valign="top" >RANGE</td> 2865 <td valign="top" >Min=0, Max= SDVO dependent</td> 2866 <td valign="top" >Connector</td> 2867 <td valign="top" >TBD</td> 2868 </tr> 2869 <tr> 2870 <td valign="top" >"bottom_margin"</td> 2871 <td valign="top" >RANGE</td> 2872 <td valign="top" >Min=0, Max= SDVO dependent</td> 2873 <td valign="top" >Connector</td> 2874 <td valign="top" >TBD</td> 2875 </tr> 2876 <tr> 2877 <td valign="top" >“hpos”</td> 2878 <td valign="top" >RANGE</td> 2879 <td valign="top" >Min=0, Max= SDVO dependent</td> 2880 <td valign="top" >Connector</td> 2881 <td valign="top" >TBD</td> 2882 </tr> 2883 <tr> 2884 <td valign="top" >“vpos”</td> 2885 <td valign="top" >RANGE</td> 2886 <td valign="top" >Min=0, Max= SDVO dependent</td> 2887 <td valign="top" >Connector</td> 2888 <td valign="top" >TBD</td> 2889 </tr> 2890 <tr> 2891 <td valign="top" >“contrast”</td> 2892 <td valign="top" >RANGE</td> 2893 <td valign="top" >Min=0, Max= SDVO dependent</td> 2894 <td valign="top" >Connector</td> 2895 <td valign="top" >TBD</td> 2896 </tr> 2897 <tr> 2898 <td valign="top" >“saturation”</td> 2899 <td valign="top" >RANGE</td> 2900 <td valign="top" >Min=0, Max= SDVO dependent</td> 2901 <td valign="top" >Connector</td> 2902 <td valign="top" >TBD</td> 2903 </tr> 2904 <tr> 2905 <td valign="top" >“hue”</td> 2906 <td valign="top" >RANGE</td> 2907 <td valign="top" >Min=0, Max= SDVO dependent</td> 2908 <td valign="top" >Connector</td> 2909 <td valign="top" >TBD</td> 2910 </tr> 2911 <tr> 2912 <td valign="top" >“sharpness”</td> 2913 <td valign="top" >RANGE</td> 2914 <td valign="top" >Min=0, Max= SDVO dependent</td> 2915 <td valign="top" >Connector</td> 2916 <td valign="top" >TBD</td> 2917 </tr> 2918 <tr> 2919 <td valign="top" >“flicker_filter”</td> 2920 <td valign="top" >RANGE</td> 2921 <td valign="top" >Min=0, Max= SDVO dependent</td> 2922 <td valign="top" >Connector</td> 2923 <td valign="top" >TBD</td> 2924 </tr> 2925 <tr> 2926 <td valign="top" >“flicker_filter_adaptive”</td> 2927 <td valign="top" >RANGE</td> 2928 <td valign="top" >Min=0, Max= SDVO dependent</td> 2929 <td valign="top" >Connector</td> 2930 <td valign="top" >TBD</td> 2931 </tr> 2932 <tr> 2933 <td valign="top" >“flicker_filter_2d”</td> 2934 <td valign="top" >RANGE</td> 2935 <td valign="top" >Min=0, Max= SDVO dependent</td> 2936 <td valign="top" >Connector</td> 2937 <td valign="top" >TBD</td> 2938 </tr> 2939 <tr> 2940 <td valign="top" >“tv_chroma_filter”</td> 2941 <td valign="top" >RANGE</td> 2942 <td valign="top" >Min=0, Max= SDVO dependent</td> 2943 <td valign="top" >Connector</td> 2944 <td valign="top" >TBD</td> 2945 </tr> 2946 <tr> 2947 <td valign="top" >“tv_luma_filter”</td> 2948 <td valign="top" >RANGE</td> 2949 <td valign="top" >Min=0, Max= SDVO dependent</td> 2950 <td valign="top" >Connector</td> 2951 <td valign="top" >TBD</td> 2952 </tr> 2953 <tr> 2954 <td valign="top" >“dot_crawl”</td> 2955 <td valign="top" >RANGE</td> 2956 <td valign="top" >Min=0, Max=1</td> 2957 <td valign="top" >Connector</td> 2958 <td valign="top" >TBD</td> 2959 </tr> 2960 <tr> 2961 <td valign="top" >SDVO-TV/LVDS</td> 2962 <td valign="top" >“brightness”</td> 2963 <td valign="top" >RANGE</td> 2964 <td valign="top" >Min=0, Max= SDVO dependent</td> 2965 <td valign="top" >Connector</td> 2966 <td valign="top" >TBD</td> 2967 </tr> 2968 <tr> 2969 <td rowspan="11" valign="top" >armada</td> 2970 <td rowspan="2" valign="top" >CRTC</td> 2971 <td valign="top" >"CSC_YUV"</td> 2972 <td valign="top" >ENUM</td> 2973 <td valign="top" >{ "Auto" , "CCIR601", "CCIR709" }</td> 2974 <td valign="top" >CRTC</td> 2975 <td valign="top" >TBD</td> 2976 </tr> 2977 <tr> 2978 <td valign="top" >"CSC_RGB"</td> 2979 <td valign="top" >ENUM</td> 2980 <td valign="top" >{ "Auto", "Computer system", "Studio" }</td> 2981 <td valign="top" >CRTC</td> 2982 <td valign="top" >TBD</td> 2983 </tr> 2984 <tr> 2985 <td rowspan="9" valign="top" >Overlay</td> 2986 <td valign="top" >"colorkey"</td> 2987 <td valign="top" >RANGE</td> 2988 <td valign="top" >Min=0, Max=0xffffff</td> 2989 <td valign="top" >Plane</td> 2990 <td valign="top" >TBD</td> 2991 </tr> 2992 <tr> 2993 <td valign="top" >"colorkey_min"</td> 2994 <td valign="top" >RANGE</td> 2995 <td valign="top" >Min=0, Max=0xffffff</td> 2996 <td valign="top" >Plane</td> 2997 <td valign="top" >TBD</td> 2998 </tr> 2999 <tr> 3000 <td valign="top" >"colorkey_max"</td> 3001 <td valign="top" >RANGE</td> 3002 <td valign="top" >Min=0, Max=0xffffff</td> 3003 <td valign="top" >Plane</td> 3004 <td valign="top" >TBD</td> 3005 </tr> 3006 <tr> 3007 <td valign="top" >"colorkey_val"</td> 3008 <td valign="top" >RANGE</td> 3009 <td valign="top" >Min=0, Max=0xffffff</td> 3010 <td valign="top" >Plane</td> 3011 <td valign="top" >TBD</td> 3012 </tr> 3013 <tr> 3014 <td valign="top" >"colorkey_alpha"</td> 3015 <td valign="top" >RANGE</td> 3016 <td valign="top" >Min=0, Max=0xffffff</td> 3017 <td valign="top" >Plane</td> 3018 <td valign="top" >TBD</td> 3019 </tr> 3020 <tr> 3021 <td valign="top" >"colorkey_mode"</td> 3022 <td valign="top" >ENUM</td> 3023 <td valign="top" >{ "disabled", "Y component", "U component" 3024 , "V component", "RGB", “R component", "G component", "B component" }</td> 3025 <td valign="top" >Plane</td> 3026 <td valign="top" >TBD</td> 3027 </tr> 3028 <tr> 3029 <td valign="top" >"brightness"</td> 3030 <td valign="top" >RANGE</td> 3031 <td valign="top" >Min=0, Max=256 + 255</td> 3032 <td valign="top" >Plane</td> 3033 <td valign="top" >TBD</td> 3034 </tr> 3035 <tr> 3036 <td valign="top" >"contrast"</td> 3037 <td valign="top" >RANGE</td> 3038 <td valign="top" >Min=0, Max=0x7fff</td> 3039 <td valign="top" >Plane</td> 3040 <td valign="top" >TBD</td> 3041 </tr> 3042 <tr> 3043 <td valign="top" >"saturation"</td> 3044 <td valign="top" >RANGE</td> 3045 <td valign="top" >Min=0, Max=0x7fff</td> 3046 <td valign="top" >Plane</td> 3047 <td valign="top" >TBD</td> 3048 </tr> 3049 <tr> 3050 <td rowspan="2" valign="top" >exynos</td> 3051 <td valign="top" >CRTC</td> 3052 <td valign="top" >“mode”</td> 3053 <td valign="top" >ENUM</td> 3054 <td valign="top" >{ "normal", "blank" }</td> 3055 <td valign="top" >CRTC</td> 3056 <td valign="top" >TBD</td> 3057 </tr> 3058 <tr> 3059 <td valign="top" >Overlay</td> 3060 <td valign="top" >“zpos”</td> 3061 <td valign="top" >RANGE</td> 3062 <td valign="top" >Min=0, Max=MAX_PLANE-1</td> 3063 <td valign="top" >Plane</td> 3064 <td valign="top" >TBD</td> 3065 </tr> 3066 <tr> 3067 <td rowspan="3" valign="top" >i2c/ch7006_drv</td> 3068 <td valign="top" >Generic</td> 3069 <td valign="top" >“scale”</td> 3070 <td valign="top" >RANGE</td> 3071 <td valign="top" >Min=0, Max=2</td> 3072 <td valign="top" >Connector</td> 3073 <td valign="top" >TBD</td> 3074 </tr> 3075 <tr> 3076 <td rowspan="2" valign="top" >TV</td> 3077 <td valign="top" >Standard names as in DRM</td> 3078 <td valign="top" >Standard types as in DRM</td> 3079 <td valign="top" >Standard Values as in DRM</td> 3080 <td valign="top" >Standard object as in DRM</td> 3081 <td valign="top" >TBD</td> 3082 </tr> 3083 <tr> 3084 <td valign="top" >“mode”</td> 3085 <td valign="top" >ENUM</td> 3086 <td valign="top" >{ "PAL", "PAL-M","PAL-N"}, ”PAL-Nc" 3087 , "PAL-60", "NTSC-M", "NTSC-J" }</td> 3088 <td valign="top" >Connector</td> 3089 <td valign="top" >TBD</td> 3090 </tr> 3091 <tr> 3092 <td rowspan="16" valign="top" >nouveau</td> 3093 <td rowspan="6" valign="top" >NV10 Overlay</td> 3094 <td valign="top" >"colorkey"</td> 3095 <td valign="top" >RANGE</td> 3096 <td valign="top" >Min=0, Max=0x01ffffff</td> 3097 <td valign="top" >Plane</td> 3098 <td valign="top" >TBD</td> 3099 </tr> 3100 <tr> 3101 <td valign="top" >“contrast”</td> 3102 <td valign="top" >RANGE</td> 3103 <td valign="top" >Min=0, Max=8192-1</td> 3104 <td valign="top" >Plane</td> 3105 <td valign="top" >TBD</td> 3106 </tr> 3107 <tr> 3108 <td valign="top" >“brightness”</td> 3109 <td valign="top" >RANGE</td> 3110 <td valign="top" >Min=0, Max=1024</td> 3111 <td valign="top" >Plane</td> 3112 <td valign="top" >TBD</td> 3113 </tr> 3114 <tr> 3115 <td valign="top" >“hue”</td> 3116 <td valign="top" >RANGE</td> 3117 <td valign="top" >Min=0, Max=359</td> 3118 <td valign="top" >Plane</td> 3119 <td valign="top" >TBD</td> 3120 </tr> 3121 <tr> 3122 <td valign="top" >“saturation”</td> 3123 <td valign="top" >RANGE</td> 3124 <td valign="top" >Min=0, Max=8192-1</td> 3125 <td valign="top" >Plane</td> 3126 <td valign="top" >TBD</td> 3127 </tr> 3128 <tr> 3129 <td valign="top" >“iturbt_709”</td> 3130 <td valign="top" >RANGE</td> 3131 <td valign="top" >Min=0, Max=1</td> 3132 <td valign="top" >Plane</td> 3133 <td valign="top" >TBD</td> 3134 </tr> 3135 <tr> 3136 <td rowspan="2" valign="top" >Nv04 Overlay</td> 3137 <td valign="top" >“colorkey”</td> 3138 <td valign="top" >RANGE</td> 3139 <td valign="top" >Min=0, Max=0x01ffffff</td> 3140 <td valign="top" >Plane</td> 3141 <td valign="top" >TBD</td> 3142 </tr> 3143 <tr> 3144 <td valign="top" >“brightness”</td> 3145 <td valign="top" >RANGE</td> 3146 <td valign="top" >Min=0, Max=1024</td> 3147 <td valign="top" >Plane</td> 3148 <td valign="top" >TBD</td> 3149 </tr> 3150 <tr> 3151 <td rowspan="7" valign="top" >Display</td> 3152 <td valign="top" >“dithering mode”</td> 3153 <td valign="top" >ENUM</td> 3154 <td valign="top" >{ "auto", "off", "on" }</td> 3155 <td valign="top" >Connector</td> 3156 <td valign="top" >TBD</td> 3157 </tr> 3158 <tr> 3159 <td valign="top" >“dithering depth”</td> 3160 <td valign="top" >ENUM</td> 3161 <td valign="top" >{ "auto", "off", "on", "static 2x2", "dynamic 2x2", "temporal" }</td> 3162 <td valign="top" >Connector</td> 3163 <td valign="top" >TBD</td> 3164 </tr> 3165 <tr> 3166 <td valign="top" >“underscan”</td> 3167 <td valign="top" >ENUM</td> 3168 <td valign="top" >{ "auto", "6 bpc", "8 bpc" }</td> 3169 <td valign="top" >Connector</td> 3170 <td valign="top" >TBD</td> 3171 </tr> 3172 <tr> 3173 <td valign="top" >“underscan hborder”</td> 3174 <td valign="top" >RANGE</td> 3175 <td valign="top" >Min=0, Max=128</td> 3176 <td valign="top" >Connector</td> 3177 <td valign="top" >TBD</td> 3178 </tr> 3179 <tr> 3180 <td valign="top" >“underscan vborder”</td> 3181 <td valign="top" >RANGE</td> 3182 <td valign="top" >Min=0, Max=128</td> 3183 <td valign="top" >Connector</td> 3184 <td valign="top" >TBD</td> 3185 </tr> 3186 <tr> 3187 <td valign="top" >“vibrant hue”</td> 3188 <td valign="top" >RANGE</td> 3189 <td valign="top" >Min=0, Max=180</td> 3190 <td valign="top" >Connector</td> 3191 <td valign="top" >TBD</td> 3192 </tr> 3193 <tr> 3194 <td valign="top" >“color vibrance”</td> 3195 <td valign="top" >RANGE</td> 3196 <td valign="top" >Min=0, Max=200</td> 3197 <td valign="top" >Connector</td> 3198 <td valign="top" >TBD</td> 3199 </tr> 3200 <tr> 3201 <td valign="top" >Generic</td> 3202 <td valign="top" >Standard name as in DRM</td> 3203 <td valign="top" >Standard type as in DRM</td> 3204 <td valign="top" >Standard value as in DRM</td> 3205 <td valign="top" >Standard Object as in DRM</td> 3206 <td valign="top" >TBD</td> 3207 </tr> 3208 <tr> 3209 <td rowspan="2" valign="top" >omap</td> 3210 <td rowspan="2" valign="top" >Generic</td> 3211 <td valign="top" >“rotation”</td> 3212 <td valign="top" >BITMASK</td> 3213 <td valign="top" >{ 0, "rotate-0" }, 3214 { 1, "rotate-90" }, 3215 { 2, "rotate-180" }, 3216 { 3, "rotate-270" }, 3217 { 4, "reflect-x" }, 3218 { 5, "reflect-y" }</td> 3219 <td valign="top" >CRTC, Plane</td> 3220 <td valign="top" >TBD</td> 3221 </tr> 3222 <tr> 3223 <td valign="top" >“zorder”</td> 3224 <td valign="top" >RANGE</td> 3225 <td valign="top" >Min=0, Max=3</td> 3226 <td valign="top" >CRTC, Plane</td> 3227 <td valign="top" >TBD</td> 3228 </tr> 3229 <tr> 3230 <td valign="top" >qxl</td> 3231 <td valign="top" >Generic</td> 3232 <td valign="top" >“hotplug_mode_update"</td> 3233 <td valign="top" >RANGE</td> 3234 <td valign="top" >Min=0, Max=1</td> 3235 <td valign="top" >Connector</td> 3236 <td valign="top" >TBD</td> 3237 </tr> 3238 <tr> 3239 <td rowspan="10" valign="top" >radeon</td> 3240 <td valign="top" >DVI-I</td> 3241 <td valign="top" >“coherent”</td> 3242 <td valign="top" >RANGE</td> 3243 <td valign="top" >Min=0, Max=1</td> 3244 <td valign="top" >Connector</td> 3245 <td valign="top" >TBD</td> 3246 </tr> 3247 <tr> 3248 <td valign="top" >DAC enable load detect</td> 3249 <td valign="top" >“load detection”</td> 3250 <td valign="top" >RANGE</td> 3251 <td valign="top" >Min=0, Max=1</td> 3252 <td valign="top" >Connector</td> 3253 <td valign="top" >TBD</td> 3254 </tr> 3255 <tr> 3256 <td valign="top" >TV Standard</td> 3257 <td valign="top" >"tv standard"</td> 3258 <td valign="top" >ENUM</td> 3259 <td valign="top" >{ "ntsc", "pal", "pal-m", "pal-60", "ntsc-j" 3260 , "scart-pal", "pal-cn", "secam" }</td> 3261 <td valign="top" >Connector</td> 3262 <td valign="top" >TBD</td> 3263 </tr> 3264 <tr> 3265 <td valign="top" >legacy TMDS PLL detect</td> 3266 <td valign="top" >"tmds_pll"</td> 3267 <td valign="top" >ENUM</td> 3268 <td valign="top" >{ "driver", "bios" }</td> 3269 <td valign="top" >-</td> 3270 <td valign="top" >TBD</td> 3271 </tr> 3272 <tr> 3273 <td rowspan="3" valign="top" >Underscan</td> 3274 <td valign="top" >"underscan"</td> 3275 <td valign="top" >ENUM</td> 3276 <td valign="top" >{ "off", "on", "auto" }</td> 3277 <td valign="top" >Connector</td> 3278 <td valign="top" >TBD</td> 3279 </tr> 3280 <tr> 3281 <td valign="top" >"underscan hborder"</td> 3282 <td valign="top" >RANGE</td> 3283 <td valign="top" >Min=0, Max=128</td> 3284 <td valign="top" >Connector</td> 3285 <td valign="top" >TBD</td> 3286 </tr> 3287 <tr> 3288 <td valign="top" >"underscan vborder"</td> 3289 <td valign="top" >RANGE</td> 3290 <td valign="top" >Min=0, Max=128</td> 3291 <td valign="top" >Connector</td> 3292 <td valign="top" >TBD</td> 3293 </tr> 3294 <tr> 3295 <td valign="top" >Audio</td> 3296 <td valign="top" >“audio”</td> 3297 <td valign="top" >ENUM</td> 3298 <td valign="top" >{ "off", "on", "auto" }</td> 3299 <td valign="top" >Connector</td> 3300 <td valign="top" >TBD</td> 3301 </tr> 3302 <tr> 3303 <td valign="top" >FMT Dithering</td> 3304 <td valign="top" >“dither”</td> 3305 <td valign="top" >ENUM</td> 3306 <td valign="top" >{ "off", "on" }</td> 3307 <td valign="top" >Connector</td> 3308 <td valign="top" >TBD</td> 3309 </tr> 3310 <tr> 3311 <td valign="top" >Generic</td> 3312 <td valign="top" >Standard name as in DRM</td> 3313 <td valign="top" >Standard type as in DRM</td> 3314 <td valign="top" >Standard value as in DRM</td> 3315 <td valign="top" >Standard Object as in DRM</td> 3316 <td valign="top" >TBD</td> 3317 </tr> 3318 <tr> 3319 <td rowspan="3" valign="top" >rcar-du</td> 3320 <td rowspan="3" valign="top" >Generic</td> 3321 <td valign="top" >"alpha"</td> 3322 <td valign="top" >RANGE</td> 3323 <td valign="top" >Min=0, Max=255</td> 3324 <td valign="top" >Plane</td> 3325 <td valign="top" >TBD</td> 3326 </tr> 3327 <tr> 3328 <td valign="top" >"colorkey"</td> 3329 <td valign="top" >RANGE</td> 3330 <td valign="top" >Min=0, Max=0x01ffffff</td> 3331 <td valign="top" >Plane</td> 3332 <td valign="top" >TBD</td> 3333 </tr> 3334 <tr> 3335 <td valign="top" >"zpos"</td> 3336 <td valign="top" >RANGE</td> 3337 <td valign="top" >Min=1, Max=7</td> 3338 <td valign="top" >Plane</td> 3339 <td valign="top" >TBD</td> 3340 </tr> 3341 </tbody> 3342 </table> 3343 </sect2> 3344 </sect1> 3345 3346 <!-- Internals: vertical blanking --> 3347 3348 <sect1 id="drm-vertical-blank"> 3349 <title>Vertical Blanking</title> 3350 <para> 3351 Vertical blanking plays a major role in graphics rendering. To achieve 3352 tear-free display, users must synchronize page flips and/or rendering to 3353 vertical blanking. The DRM API offers ioctls to perform page flips 3354 synchronized to vertical blanking and wait for vertical blanking. 3355 </para> 3356 <para> 3357 The DRM core handles most of the vertical blanking management logic, which 3358 involves filtering out spurious interrupts, keeping race-free blanking 3359 counters, coping with counter wrap-around and resets and keeping use 3360 counts. It relies on the driver to generate vertical blanking interrupts 3361 and optionally provide a hardware vertical blanking counter. Drivers must 3362 implement the following operations. 3363 </para> 3364 <itemizedlist> 3365 <listitem> 3366 <synopsis>int (*enable_vblank) (struct drm_device *dev, int crtc); 3367void (*disable_vblank) (struct drm_device *dev, int crtc);</synopsis> 3368 <para> 3369 Enable or disable vertical blanking interrupts for the given CRTC. 3370 </para> 3371 </listitem> 3372 <listitem> 3373 <synopsis>u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);</synopsis> 3374 <para> 3375 Retrieve the value of the vertical blanking counter for the given 3376 CRTC. If the hardware maintains a vertical blanking counter its value 3377 should be returned. Otherwise drivers can use the 3378 <function>drm_vblank_count</function> helper function to handle this 3379 operation. 3380 </para> 3381 </listitem> 3382 </itemizedlist> 3383 <para> 3384 Drivers must initialize the vertical blanking handling core with a call to 3385 <function>drm_vblank_init</function> in their 3386 <methodname>load</methodname> operation. The function will set the struct 3387 <structname>drm_device</structname> 3388 <structfield>vblank_disable_allowed</structfield> field to 0. This will 3389 keep vertical blanking interrupts enabled permanently until the first mode 3390 set operation, where <structfield>vblank_disable_allowed</structfield> is 3391 set to 1. The reason behind this is not clear. Drivers can set the field 3392 to 1 after <function>calling drm_vblank_init</function> to make vertical 3393 blanking interrupts dynamically managed from the beginning. 3394 </para> 3395 <para> 3396 Vertical blanking interrupts can be enabled by the DRM core or by drivers 3397 themselves (for instance to handle page flipping operations). The DRM core 3398 maintains a vertical blanking use count to ensure that the interrupts are 3399 not disabled while a user still needs them. To increment the use count, 3400 drivers call <function>drm_vblank_get</function>. Upon return vertical 3401 blanking interrupts are guaranteed to be enabled. 3402 </para> 3403 <para> 3404 To decrement the use count drivers call 3405 <function>drm_vblank_put</function>. Only when the use count drops to zero 3406 will the DRM core disable the vertical blanking interrupts after a delay 3407 by scheduling a timer. The delay is accessible through the vblankoffdelay 3408 module parameter or the <varname>drm_vblank_offdelay</varname> global 3409 variable and expressed in milliseconds. Its default value is 5000 ms. 3410 </para> 3411 <para> 3412 When a vertical blanking interrupt occurs drivers only need to call the 3413 <function>drm_handle_vblank</function> function to account for the 3414 interrupt. 3415 </para> 3416 <para> 3417 Resources allocated by <function>drm_vblank_init</function> must be freed 3418 with a call to <function>drm_vblank_cleanup</function> in the driver 3419 <methodname>unload</methodname> operation handler. 3420 </para> 3421 <sect2> 3422 <title>Vertical Blanking and Interrupt Handling Functions Reference</title> 3423!Edrivers/gpu/drm/drm_irq.c 3424 </sect2> 3425 </sect1> 3426 3427 <!-- Internals: open/close, file operations and ioctls --> 3428 3429 <sect1> 3430 <title>Open/Close, File Operations and IOCTLs</title> 3431 <sect2> 3432 <title>Open and Close</title> 3433 <synopsis>int (*firstopen) (struct drm_device *); 3434void (*lastclose) (struct drm_device *); 3435int (*open) (struct drm_device *, struct drm_file *); 3436void (*preclose) (struct drm_device *, struct drm_file *); 3437void (*postclose) (struct drm_device *, struct drm_file *);</synopsis> 3438 <abstract>Open and close handlers. None of those methods are mandatory. 3439 </abstract> 3440 <para> 3441 The <methodname>firstopen</methodname> method is called by the DRM core 3442 for legacy UMS (User Mode Setting) drivers only when an application 3443 opens a device that has no other opened file handle. UMS drivers can 3444 implement it to acquire device resources. KMS drivers can't use the 3445 method and must acquire resources in the <methodname>load</methodname> 3446 method instead. 3447 </para> 3448 <para> 3449 Similarly the <methodname>lastclose</methodname> method is called when 3450 the last application holding a file handle opened on the device closes 3451 it, for both UMS and KMS drivers. Additionally, the method is also 3452 called at module unload time or, for hot-pluggable devices, when the 3453 device is unplugged. The <methodname>firstopen</methodname> and 3454 <methodname>lastclose</methodname> calls can thus be unbalanced. 3455 </para> 3456 <para> 3457 The <methodname>open</methodname> method is called every time the device 3458 is opened by an application. Drivers can allocate per-file private data 3459 in this method and store them in the struct 3460 <structname>drm_file</structname> <structfield>driver_priv</structfield> 3461 field. Note that the <methodname>open</methodname> method is called 3462 before <methodname>firstopen</methodname>. 3463 </para> 3464 <para> 3465 The close operation is split into <methodname>preclose</methodname> and 3466 <methodname>postclose</methodname> methods. Drivers must stop and 3467 cleanup all per-file operations in the <methodname>preclose</methodname> 3468 method. For instance pending vertical blanking and page flip events must 3469 be cancelled. No per-file operation is allowed on the file handle after 3470 returning from the <methodname>preclose</methodname> method. 3471 </para> 3472 <para> 3473 Finally the <methodname>postclose</methodname> method is called as the 3474 last step of the close operation, right before calling the 3475 <methodname>lastclose</methodname> method if no other open file handle 3476 exists for the device. Drivers that have allocated per-file private data 3477 in the <methodname>open</methodname> method should free it here. 3478 </para> 3479 <para> 3480 The <methodname>lastclose</methodname> method should restore CRTC and 3481 plane properties to default value, so that a subsequent open of the 3482 device will not inherit state from the previous user. It can also be 3483 used to execute delayed power switching state changes, e.g. in 3484 conjunction with the vga-switcheroo infrastructure. Beyond that KMS 3485 drivers should not do any further cleanup. Only legacy UMS drivers might 3486 need to clean up device state so that the vga console or an independent 3487 fbdev driver could take over. 3488 </para> 3489 </sect2> 3490 <sect2> 3491 <title>File Operations</title> 3492 <synopsis>const struct file_operations *fops</synopsis> 3493 <abstract>File operations for the DRM device node.</abstract> 3494 <para> 3495 Drivers must define the file operations structure that forms the DRM 3496 userspace API entry point, even though most of those operations are 3497 implemented in the DRM core. The <methodname>open</methodname>, 3498 <methodname>release</methodname> and <methodname>ioctl</methodname> 3499 operations are handled by 3500 <programlisting> 3501 .owner = THIS_MODULE, 3502 .open = drm_open, 3503 .release = drm_release, 3504 .unlocked_ioctl = drm_ioctl, 3505 #ifdef CONFIG_COMPAT 3506 .compat_ioctl = drm_compat_ioctl, 3507 #endif 3508 </programlisting> 3509 </para> 3510 <para> 3511 Drivers that implement private ioctls that requires 32/64bit 3512 compatibility support must provide their own 3513 <methodname>compat_ioctl</methodname> handler that processes private 3514 ioctls and calls <function>drm_compat_ioctl</function> for core ioctls. 3515 </para> 3516 <para> 3517 The <methodname>read</methodname> and <methodname>poll</methodname> 3518 operations provide support for reading DRM events and polling them. They 3519 are implemented by 3520 <programlisting> 3521 .poll = drm_poll, 3522 .read = drm_read, 3523 .llseek = no_llseek, 3524 </programlisting> 3525 </para> 3526 <para> 3527 The memory mapping implementation varies depending on how the driver 3528 manages memory. Pre-GEM drivers will use <function>drm_mmap</function>, 3529 while GEM-aware drivers will use <function>drm_gem_mmap</function>. See 3530 <xref linkend="drm-gem"/>. 3531 <programlisting> 3532 .mmap = drm_gem_mmap, 3533 </programlisting> 3534 </para> 3535 <para> 3536 No other file operation is supported by the DRM API. 3537 </para> 3538 </sect2> 3539 <sect2> 3540 <title>IOCTLs</title> 3541 <synopsis>struct drm_ioctl_desc *ioctls; 3542int num_ioctls;</synopsis> 3543 <abstract>Driver-specific ioctls descriptors table.</abstract> 3544 <para> 3545 Driver-specific ioctls numbers start at DRM_COMMAND_BASE. The ioctls 3546 descriptors table is indexed by the ioctl number offset from the base 3547 value. Drivers can use the DRM_IOCTL_DEF_DRV() macro to initialize the 3548 table entries. 3549 </para> 3550 <para> 3551 <programlisting>DRM_IOCTL_DEF_DRV(ioctl, func, flags)</programlisting> 3552 <para> 3553 <parameter>ioctl</parameter> is the ioctl name. Drivers must define 3554 the DRM_##ioctl and DRM_IOCTL_##ioctl macros to the ioctl number 3555 offset from DRM_COMMAND_BASE and the ioctl number respectively. The 3556 first macro is private to the device while the second must be exposed 3557 to userspace in a public header. 3558 </para> 3559 <para> 3560 <parameter>func</parameter> is a pointer to the ioctl handler function 3561 compatible with the <type>drm_ioctl_t</type> type. 3562 <programlisting>typedef int drm_ioctl_t(struct drm_device *dev, void *data, 3563 struct drm_file *file_priv);</programlisting> 3564 </para> 3565 <para> 3566 <parameter>flags</parameter> is a bitmask combination of the following 3567 values. It restricts how the ioctl is allowed to be called. 3568 <itemizedlist> 3569 <listitem><para> 3570 DRM_AUTH - Only authenticated callers allowed 3571 </para></listitem> 3572 <listitem><para> 3573 DRM_MASTER - The ioctl can only be called on the master file 3574 handle 3575 </para></listitem> 3576 <listitem><para> 3577 DRM_ROOT_ONLY - Only callers with the SYSADMIN capability allowed 3578 </para></listitem> 3579 <listitem><para> 3580 DRM_CONTROL_ALLOW - The ioctl can only be called on a control 3581 device 3582 </para></listitem> 3583 <listitem><para> 3584 DRM_UNLOCKED - The ioctl handler will be called without locking 3585 the DRM global mutex 3586 </para></listitem> 3587 </itemizedlist> 3588 </para> 3589 </para> 3590 </sect2> 3591 </sect1> 3592 <sect1> 3593 <title>Legacy Support Code</title> 3594 <para> 3595 The section very briefly covers some of the old legacy support code which 3596 is only used by old DRM drivers which have done a so-called shadow-attach 3597 to the underlying device instead of registering as a real driver. This 3598 also includes some of the old generic buffer management and command 3599 submission code. Do not use any of this in new and modern drivers. 3600 </para> 3601 3602 <sect2> 3603 <title>Legacy Suspend/Resume</title> 3604 <para> 3605 The DRM core provides some suspend/resume code, but drivers wanting full 3606 suspend/resume support should provide save() and restore() functions. 3607 These are called at suspend, hibernate, or resume time, and should perform 3608 any state save or restore required by your device across suspend or 3609 hibernate states. 3610 </para> 3611 <synopsis>int (*suspend) (struct drm_device *, pm_message_t state); 3612 int (*resume) (struct drm_device *);</synopsis> 3613 <para> 3614 Those are legacy suspend and resume methods which 3615 <emphasis>only</emphasis> work with the legacy shadow-attach driver 3616 registration functions. New driver should use the power management 3617 interface provided by their bus type (usually through 3618 the struct <structname>device_driver</structname> dev_pm_ops) and set 3619 these methods to NULL. 3620 </para> 3621 </sect2> 3622 3623 <sect2> 3624 <title>Legacy DMA Services</title> 3625 <para> 3626 This should cover how DMA mapping etc. is supported by the core. 3627 These functions are deprecated and should not be used. 3628 </para> 3629 </sect2> 3630 </sect1> 3631 </chapter> 3632 3633<!-- TODO 3634 3635- Add a glossary 3636- Document the struct_mutex catch-all lock 3637- Document connector properties 3638 3639- Why is the load method optional? 3640- What are drivers supposed to set the initial display state to, and how? 3641 Connector's DPMS states are not initialized and are thus equal to 3642 DRM_MODE_DPMS_ON. The fbcon compatibility layer calls 3643 drm_helper_disable_unused_functions(), which disables unused encoders and 3644 CRTCs, but doesn't touch the connectors' DPMS state, and 3645 drm_helper_connector_dpms() in reaction to fbdev blanking events. Do drivers 3646 that don't implement (or just don't use) fbcon compatibility need to call 3647 those functions themselves? 3648- KMS drivers must call drm_vblank_pre_modeset() and drm_vblank_post_modeset() 3649 around mode setting. Should this be done in the DRM core? 3650- vblank_disable_allowed is set to 1 in the first drm_vblank_post_modeset() 3651 call and never set back to 0. It seems to be safe to permanently set it to 1 3652 in drm_vblank_init() for KMS driver, and it might be safe for UMS drivers as 3653 well. This should be investigated. 3654- crtc and connector .save and .restore operations are only used internally in 3655 drivers, should they be removed from the core? 3656- encoder mid-layer .save and .restore operations are only used internally in 3657 drivers, should they be removed from the core? 3658- encoder mid-layer .detect operation is only used internally in drivers, 3659 should it be removed from the core? 3660--> 3661 3662 <!-- External interfaces --> 3663 3664 <chapter id="drmExternals"> 3665 <title>Userland interfaces</title> 3666 <para> 3667 The DRM core exports several interfaces to applications, 3668 generally intended to be used through corresponding libdrm 3669 wrapper functions. In addition, drivers export device-specific 3670 interfaces for use by userspace drivers &amp; device-aware 3671 applications through ioctls and sysfs files. 3672 </para> 3673 <para> 3674 External interfaces include: memory mapping, context management, 3675 DMA operations, AGP management, vblank control, fence 3676 management, memory management, and output management. 3677 </para> 3678 <para> 3679 Cover generic ioctls and sysfs layout here. We only need high-level 3680 info, since man pages should cover the rest. 3681 </para> 3682 3683 <!-- External: render nodes --> 3684 3685 <sect1> 3686 <title>Render nodes</title> 3687 <para> 3688 DRM core provides multiple character-devices for user-space to use. 3689 Depending on which device is opened, user-space can perform a different 3690 set of operations (mainly ioctls). The primary node is always created 3691 and called card&lt;num&gt;. Additionally, a currently 3692 unused control node, called controlD&lt;num&gt; is also 3693 created. The primary node provides all legacy operations and 3694 historically was the only interface used by userspace. With KMS, the 3695 control node was introduced. However, the planned KMS control interface 3696 has never been written and so the control node stays unused to date. 3697 </para> 3698 <para> 3699 With the increased use of offscreen renderers and GPGPU applications, 3700 clients no longer require running compositors or graphics servers to 3701 make use of a GPU. But the DRM API required unprivileged clients to 3702 authenticate to a DRM-Master prior to getting GPU access. To avoid this 3703 step and to grant clients GPU access without authenticating, render 3704 nodes were introduced. Render nodes solely serve render clients, that 3705 is, no modesetting or privileged ioctls can be issued on render nodes. 3706 Only non-global rendering commands are allowed. If a driver supports 3707 render nodes, it must advertise it via the DRIVER_RENDER 3708 DRM driver capability. If not supported, the primary node must be used 3709 for render clients together with the legacy drmAuth authentication 3710 procedure. 3711 </para> 3712 <para> 3713 If a driver advertises render node support, DRM core will create a 3714 separate render node called renderD&lt;num&gt;. There will 3715 be one render node per device. No ioctls except PRIME-related ioctls 3716 will be allowed on this node. Especially GEM_OPEN will be 3717 explicitly prohibited. Render nodes are designed to avoid the 3718 buffer-leaks, which occur if clients guess the flink names or mmap 3719 offsets on the legacy interface. Additionally to this basic interface, 3720 drivers must mark their driver-dependent render-only ioctls as 3721 DRM_RENDER_ALLOW so render clients can use them. Driver 3722 authors must be careful not to allow any privileged ioctls on render 3723 nodes. 3724 </para> 3725 <para> 3726 With render nodes, user-space can now control access to the render node 3727 via basic file-system access-modes. A running graphics server which 3728 authenticates clients on the privileged primary/legacy node is no longer 3729 required. Instead, a client can open the render node and is immediately 3730 granted GPU access. Communication between clients (or servers) is done 3731 via PRIME. FLINK from render node to legacy node is not supported. New 3732 clients must not use the insecure FLINK interface. 3733 </para> 3734 <para> 3735 Besides dropping all modeset/global ioctls, render nodes also drop the 3736 DRM-Master concept. There is no reason to associate render clients with 3737 a DRM-Master as they are independent of any graphics server. Besides, 3738 they must work without any running master, anyway. 3739 Drivers must be able to run without a master object if they support 3740 render nodes. If, on the other hand, a driver requires shared state 3741 between clients which is visible to user-space and accessible beyond 3742 open-file boundaries, they cannot support render nodes. 3743 </para> 3744 </sect1> 3745 3746 <!-- External: vblank handling --> 3747 3748 <sect1> 3749 <title>VBlank event handling</title> 3750 <para> 3751 The DRM core exposes two vertical blank related ioctls: 3752 <variablelist> 3753 <varlistentry> 3754 <term>DRM_IOCTL_WAIT_VBLANK</term> 3755 <listitem> 3756 <para> 3757 This takes a struct drm_wait_vblank structure as its argument, 3758 and it is used to block or request a signal when a specified 3759 vblank event occurs. 3760 </para> 3761 </listitem> 3762 </varlistentry> 3763 <varlistentry> 3764 <term>DRM_IOCTL_MODESET_CTL</term> 3765 <listitem> 3766 <para> 3767 This was only used for user-mode-settind drivers around 3768 modesetting changes to allow the kernel to update the vblank 3769 interrupt after mode setting, since on many devices the vertical 3770 blank counter is reset to 0 at some point during modeset. Modern 3771 drivers should not call this any more since with kernel mode 3772 setting it is a no-op. 3773 </para> 3774 </listitem> 3775 </varlistentry> 3776 </variablelist> 3777 </para> 3778 </sect1> 3779 3780 </chapter> 3781</part> 3782<part id="drmDrivers"> 3783 <title>DRM Drivers</title> 3784 3785 <partintro> 3786 <para> 3787 This second part of the DRM Developer's Guide documents driver code, 3788 implementation details and also all the driver-specific userspace 3789 interfaces. Especially since all hardware-acceleration interfaces to 3790 userspace are driver specific for efficiency and other reasons these 3791 interfaces can be rather substantial. Hence every driver has its own 3792 chapter. 3793 </para> 3794 </partintro> 3795 3796 <chapter id="drmI915"> 3797 <title>drm/i915 Intel GFX Driver</title> 3798 <para> 3799 The drm/i915 driver supports all (with the exception of some very early 3800 models) integrated GFX chipsets with both Intel display and rendering 3801 blocks. This excludes a set of SoC platforms with an SGX rendering unit, 3802 those have basic support through the gma500 drm driver. 3803 </para> 3804 <sect1> 3805 <title>Display Hardware Handling</title> 3806 <para> 3807 This section covers everything related to the display hardware including 3808 the mode setting infrastructure, plane, sprite and cursor handling and 3809 display, output probing and related topics. 3810 </para> 3811 <sect2> 3812 <title>Mode Setting Infrastructure</title> 3813 <para> 3814 The i915 driver is thus far the only DRM driver which doesn't use the 3815 common DRM helper code to implement mode setting sequences. Thus it 3816 has its own tailor-made infrastructure for executing a display 3817 configuration change. 3818 </para> 3819 </sect2> 3820 <sect2> 3821 <title>Plane Configuration</title> 3822 <para> 3823 This section covers plane configuration and composition with the 3824 primary plane, sprites, cursors and overlays. This includes the 3825 infrastructure to do atomic vsync'ed updates of all this state and 3826 also tightly coupled topics like watermark setup and computation, 3827 framebuffer compression and panel self refresh. 3828 </para> 3829 </sect2> 3830 <sect2> 3831 <title>Output Probing</title> 3832 <para> 3833 This section covers output probing and related infrastructure like the 3834 hotplug interrupt storm detection and mitigation code. Note that the 3835 i915 driver still uses most of the common DRM helper code for output 3836 probing, so those sections fully apply. 3837 </para> 3838 </sect2> 3839 <sect2> 3840 <title>DPIO</title> 3841!Pdrivers/gpu/drm/i915/i915_reg.h DPIO 3842 <table id="dpiox2"> 3843 <title>Dual channel PHY (VLV/CHV)</title> 3844 <tgroup cols="8"> 3845 <colspec colname="c0" /> 3846 <colspec colname="c1" /> 3847 <colspec colname="c2" /> 3848 <colspec colname="c3" /> 3849 <colspec colname="c4" /> 3850 <colspec colname="c5" /> 3851 <colspec colname="c6" /> 3852 <colspec colname="c7" /> 3853 <spanspec spanname="ch0" namest="c0" nameend="c3" /> 3854 <spanspec spanname="ch1" namest="c4" nameend="c7" /> 3855 <spanspec spanname="ch0pcs01" namest="c0" nameend="c1" /> 3856 <spanspec spanname="ch0pcs23" namest="c2" nameend="c3" /> 3857 <spanspec spanname="ch1pcs01" namest="c4" nameend="c5" /> 3858 <spanspec spanname="ch1pcs23" namest="c6" nameend="c7" /> 3859 <thead> 3860 <row> 3861 <entry spanname="ch0">CH0</entry> 3862 <entry spanname="ch1">CH1</entry> 3863 </row> 3864 </thead> 3865 <tbody valign="top" align="center"> 3866 <row> 3867 <entry spanname="ch0">CMN/PLL/REF</entry> 3868 <entry spanname="ch1">CMN/PLL/REF</entry> 3869 </row> 3870 <row> 3871 <entry spanname="ch0pcs01">PCS01</entry> 3872 <entry spanname="ch0pcs23">PCS23</entry> 3873 <entry spanname="ch1pcs01">PCS01</entry> 3874 <entry spanname="ch1pcs23">PCS23</entry> 3875 </row> 3876 <row> 3877 <entry>TX0</entry> 3878 <entry>TX1</entry> 3879 <entry>TX2</entry> 3880 <entry>TX3</entry> 3881 <entry>TX0</entry> 3882 <entry>TX1</entry> 3883 <entry>TX2</entry> 3884 <entry>TX3</entry> 3885 </row> 3886 <row> 3887 <entry spanname="ch0">DDI0</entry> 3888 <entry spanname="ch1">DDI1</entry> 3889 </row> 3890 </tbody> 3891 </tgroup> 3892 </table> 3893 <table id="dpiox1"> 3894 <title>Single channel PHY (CHV)</title> 3895 <tgroup cols="4"> 3896 <colspec colname="c0" /> 3897 <colspec colname="c1" /> 3898 <colspec colname="c2" /> 3899 <colspec colname="c3" /> 3900 <spanspec spanname="ch0" namest="c0" nameend="c3" /> 3901 <spanspec spanname="ch0pcs01" namest="c0" nameend="c1" /> 3902 <spanspec spanname="ch0pcs23" namest="c2" nameend="c3" /> 3903 <thead> 3904 <row> 3905 <entry spanname="ch0">CH0</entry> 3906 </row> 3907 </thead> 3908 <tbody valign="top" align="center"> 3909 <row> 3910 <entry spanname="ch0">CMN/PLL/REF</entry> 3911 </row> 3912 <row> 3913 <entry spanname="ch0pcs01">PCS01</entry> 3914 <entry spanname="ch0pcs23">PCS23</entry> 3915 </row> 3916 <row> 3917 <entry>TX0</entry> 3918 <entry>TX1</entry> 3919 <entry>TX2</entry> 3920 <entry>TX3</entry> 3921 </row> 3922 <row> 3923 <entry spanname="ch0">DDI2</entry> 3924 </row> 3925 </tbody> 3926 </tgroup> 3927 </table> 3928 </sect2> 3929 </sect1> 3930 3931 <sect1> 3932 <title>Memory Management and Command Submission</title> 3933 <para> 3934 This sections covers all things related to the GEM implementation in the 3935 i915 driver. 3936 </para> 3937 <sect2> 3938 <title>Batchbuffer Parsing</title> 3939!Pdrivers/gpu/drm/i915/i915_cmd_parser.c batch buffer command parser 3940!Idrivers/gpu/drm/i915/i915_cmd_parser.c 3941 </sect2> 3942 </sect1> 3943 </chapter> 3944</part> 3945</book>