Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 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 | |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 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> |
Daniel Vetter | 3a05700 | 2014-01-22 22:38:57 +0100 | [diff] [blame] | 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> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 43 | </authorgroup> |
| 44 | |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 45 | <copyright> |
| 46 | <year>2008-2009</year> |
Daniel Vetter | 3a05700 | 2014-01-22 22:38:57 +0100 | [diff] [blame] | 47 | <year>2013-2014</year> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 48 | <holder>Intel Corporation</holder> |
Daniel Vetter | 3a05700 | 2014-01-22 22:38:57 +0100 | [diff] [blame] | 49 | </copyright> |
| 50 | <copyright> |
| 51 | <year>2012</year> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 52 | <holder>Laurent Pinchart</holder> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 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> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 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> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 73 | </bookinfo> |
| 74 | |
| 75 | <toc></toc> |
| 76 | |
Daniel Vetter | 3519f70 | 2014-01-22 12:21:16 +0100 | [diff] [blame] | 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 writting drivers and generic userspace interfaces |
| 83 | exposed by DRM drivers. |
| 84 | </para> |
| 85 | </partintro> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 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 |
Michael Witten | f11aca0 | 2011-08-25 17:21:31 +0000 | [diff] [blame] | 93 | drivers in the kernel may make use of DRM functions to make |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 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> |
Michael Witten | a78f678 | 2011-08-25 17:18:08 +0000 | [diff] [blame] | 118 | First, we go over some typical driver initialization |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 119 | requirements, like setting up command buffers, creating an |
| 120 | initial output configuration, and initializing core services. |
Michael Witten | a78f678 | 2011-08-25 17:18:08 +0000 | [diff] [blame] | 121 | Subsequent sections cover core internals in more detail, |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 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 & fencing, suspend/resume support, and DMA |
| 131 | services. |
| 132 | </para> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 133 | |
| 134 | <!-- Internals: driver init --> |
| 135 | |
| 136 | <sect1> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 137 | <title>Driver Initialization</title> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 138 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 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. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 143 | </para> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 144 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 145 | The <structname>drm_driver</structname> structure contains static |
| 146 | information that describes the driver and features it supports, and |
| 147 | pointers to methods that the DRM core will call to implement the DRM API. |
| 148 | We will first go through the <structname>drm_driver</structname> static |
| 149 | information fields, and will then describe individual operations in |
| 150 | details as they get used in later sections. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 151 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 152 | <sect2> |
| 153 | <title>Driver Information</title> |
| 154 | <sect3> |
| 155 | <title>Driver Features</title> |
| 156 | <para> |
| 157 | Drivers inform the DRM core about their requirements and supported |
| 158 | features by setting appropriate flags in the |
| 159 | <structfield>driver_features</structfield> field. Since those flags |
| 160 | influence the DRM core behaviour since registration time, most of them |
| 161 | must be set to registering the <structname>drm_driver</structname> |
| 162 | instance. |
| 163 | </para> |
| 164 | <synopsis>u32 driver_features;</synopsis> |
| 165 | <variablelist> |
| 166 | <title>Driver Feature Flags</title> |
| 167 | <varlistentry> |
| 168 | <term>DRIVER_USE_AGP</term> |
| 169 | <listitem><para> |
| 170 | Driver uses AGP interface, the DRM core will manage AGP resources. |
| 171 | </para></listitem> |
| 172 | </varlistentry> |
| 173 | <varlistentry> |
| 174 | <term>DRIVER_REQUIRE_AGP</term> |
| 175 | <listitem><para> |
| 176 | Driver needs AGP interface to function. AGP initialization failure |
| 177 | will become a fatal error. |
| 178 | </para></listitem> |
| 179 | </varlistentry> |
| 180 | <varlistentry> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 181 | <term>DRIVER_PCI_DMA</term> |
| 182 | <listitem><para> |
| 183 | Driver is capable of PCI DMA, mapping of PCI DMA buffers to |
| 184 | userspace will be enabled. Deprecated. |
| 185 | </para></listitem> |
| 186 | </varlistentry> |
| 187 | <varlistentry> |
| 188 | <term>DRIVER_SG</term> |
| 189 | <listitem><para> |
| 190 | Driver can perform scatter/gather DMA, allocation and mapping of |
| 191 | scatter/gather buffers will be enabled. Deprecated. |
| 192 | </para></listitem> |
| 193 | </varlistentry> |
| 194 | <varlistentry> |
| 195 | <term>DRIVER_HAVE_DMA</term> |
| 196 | <listitem><para> |
| 197 | Driver supports DMA, the userspace DMA API will be supported. |
| 198 | Deprecated. |
| 199 | </para></listitem> |
| 200 | </varlistentry> |
| 201 | <varlistentry> |
| 202 | <term>DRIVER_HAVE_IRQ</term><term>DRIVER_IRQ_SHARED</term> |
| 203 | <listitem><para> |
Laurent Pinchart | 02b6298 | 2013-06-22 14:10:59 +0200 | [diff] [blame] | 204 | DRIVER_HAVE_IRQ indicates whether the driver has an IRQ handler |
| 205 | managed by the DRM Core. The core will support simple IRQ handler |
| 206 | installation when the flag is set. The installation process is |
| 207 | described in <xref linkend="drm-irq-registration"/>.</para> |
| 208 | <para>DRIVER_IRQ_SHARED indicates whether the device & handler |
| 209 | support shared IRQs (note that this is required of PCI drivers). |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 210 | </para></listitem> |
| 211 | </varlistentry> |
| 212 | <varlistentry> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 213 | <term>DRIVER_GEM</term> |
| 214 | <listitem><para> |
| 215 | Driver use the GEM memory manager. |
| 216 | </para></listitem> |
| 217 | </varlistentry> |
| 218 | <varlistentry> |
| 219 | <term>DRIVER_MODESET</term> |
| 220 | <listitem><para> |
| 221 | Driver supports mode setting interfaces (KMS). |
| 222 | </para></listitem> |
| 223 | </varlistentry> |
| 224 | <varlistentry> |
| 225 | <term>DRIVER_PRIME</term> |
| 226 | <listitem><para> |
| 227 | Driver implements DRM PRIME buffer sharing. |
| 228 | </para></listitem> |
| 229 | </varlistentry> |
David Herrmann | 1793126 | 2013-08-25 18:29:00 +0200 | [diff] [blame] | 230 | <varlistentry> |
| 231 | <term>DRIVER_RENDER</term> |
| 232 | <listitem><para> |
| 233 | Driver supports dedicated render nodes. |
| 234 | </para></listitem> |
| 235 | </varlistentry> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 236 | </variablelist> |
| 237 | </sect3> |
| 238 | <sect3> |
| 239 | <title>Major, Minor and Patchlevel</title> |
| 240 | <synopsis>int major; |
| 241 | int minor; |
| 242 | int patchlevel;</synopsis> |
| 243 | <para> |
| 244 | The DRM core identifies driver versions by a major, minor and patch |
| 245 | level triplet. The information is printed to the kernel log at |
| 246 | initialization time and passed to userspace through the |
| 247 | DRM_IOCTL_VERSION ioctl. |
| 248 | </para> |
| 249 | <para> |
| 250 | The major and minor numbers are also used to verify the requested driver |
| 251 | API version passed to DRM_IOCTL_SET_VERSION. When the driver API changes |
| 252 | between minor versions, applications can call DRM_IOCTL_SET_VERSION to |
| 253 | select a specific version of the API. If the requested major isn't equal |
| 254 | to the driver major, or the requested minor is larger than the driver |
| 255 | minor, the DRM_IOCTL_SET_VERSION call will return an error. Otherwise |
| 256 | the driver's set_version() method will be called with the requested |
| 257 | version. |
| 258 | </para> |
| 259 | </sect3> |
| 260 | <sect3> |
| 261 | <title>Name, Description and Date</title> |
| 262 | <synopsis>char *name; |
| 263 | char *desc; |
| 264 | char *date;</synopsis> |
| 265 | <para> |
| 266 | The driver name is printed to the kernel log at initialization time, |
| 267 | used for IRQ registration and passed to userspace through |
| 268 | DRM_IOCTL_VERSION. |
| 269 | </para> |
| 270 | <para> |
| 271 | The driver description is a purely informative string passed to |
| 272 | userspace through the DRM_IOCTL_VERSION ioctl and otherwise unused by |
| 273 | the kernel. |
| 274 | </para> |
| 275 | <para> |
| 276 | The driver date, formatted as YYYYMMDD, is meant to identify the date of |
| 277 | the latest modification to the driver. However, as most drivers fail to |
| 278 | update it, its value is mostly useless. The DRM core prints it to the |
| 279 | kernel log at initialization time and passes it to userspace through the |
| 280 | DRM_IOCTL_VERSION ioctl. |
| 281 | </para> |
| 282 | </sect3> |
| 283 | </sect2> |
| 284 | <sect2> |
| 285 | <title>Driver Load</title> |
| 286 | <para> |
| 287 | The <methodname>load</methodname> method is the driver and device |
| 288 | initialization entry point. The method is responsible for allocating and |
Daniel Vetter | e1f8ebd | 2014-01-22 16:32:47 +0100 | [diff] [blame] | 289 | initializing driver private data, performing resource allocation and |
| 290 | mapping (e.g. acquiring |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 291 | clocks, mapping registers or allocating command buffers), initializing |
| 292 | the memory manager (<xref linkend="drm-memory-management"/>), installing |
| 293 | the IRQ handler (<xref linkend="drm-irq-registration"/>), setting up |
| 294 | vertical blanking handling (<xref linkend="drm-vertical-blank"/>), mode |
| 295 | setting (<xref linkend="drm-mode-setting"/>) and initial output |
| 296 | configuration (<xref linkend="drm-kms-init"/>). |
| 297 | </para> |
| 298 | <note><para> |
| 299 | If compatibility is a concern (e.g. with drivers converted over from |
| 300 | User Mode Setting to Kernel Mode Setting), care must be taken to prevent |
| 301 | device initialization and control that is incompatible with currently |
| 302 | active userspace drivers. For instance, if user level mode setting |
| 303 | drivers are in use, it would be problematic to perform output discovery |
| 304 | & configuration at load time. Likewise, if user-level drivers |
| 305 | unaware of memory management are in use, memory management and command |
| 306 | buffer setup may need to be omitted. These requirements are |
| 307 | driver-specific, and care needs to be taken to keep both old and new |
| 308 | applications and libraries working. |
| 309 | </para></note> |
| 310 | <synopsis>int (*load) (struct drm_device *, unsigned long flags);</synopsis> |
| 311 | <para> |
| 312 | The method takes two arguments, a pointer to the newly created |
| 313 | <structname>drm_device</structname> and flags. The flags are used to |
| 314 | pass the <structfield>driver_data</structfield> field of the device id |
| 315 | corresponding to the device passed to <function>drm_*_init()</function>. |
| 316 | Only PCI devices currently use this, USB and platform DRM drivers have |
| 317 | their <methodname>load</methodname> method called with flags to 0. |
| 318 | </para> |
| 319 | <sect3> |
Daniel Vetter | e1f8ebd | 2014-01-22 16:32:47 +0100 | [diff] [blame] | 320 | <title>Driver Private Data</title> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 321 | <para> |
| 322 | The driver private hangs off the main |
| 323 | <structname>drm_device</structname> structure and can be used for |
| 324 | tracking various device-specific bits of information, like register |
| 325 | offsets, command buffer status, register state for suspend/resume, etc. |
| 326 | At load time, a driver may simply allocate one and set |
| 327 | <structname>drm_device</structname>.<structfield>dev_priv</structfield> |
| 328 | appropriately; it should be freed and |
| 329 | <structname>drm_device</structname>.<structfield>dev_priv</structfield> |
| 330 | set to NULL when the driver is unloaded. |
| 331 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 332 | </sect3> |
| 333 | <sect3 id="drm-irq-registration"> |
| 334 | <title>IRQ Registration</title> |
| 335 | <para> |
| 336 | The DRM core tries to facilitate IRQ handler registration and |
| 337 | unregistration by providing <function>drm_irq_install</function> and |
| 338 | <function>drm_irq_uninstall</function> functions. Those functions only |
Laurent Pinchart | 02b6298 | 2013-06-22 14:10:59 +0200 | [diff] [blame] | 339 | support a single interrupt per device, devices that use more than one |
| 340 | IRQs need to be handled manually. |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 341 | </para> |
Laurent Pinchart | 02b6298 | 2013-06-22 14:10:59 +0200 | [diff] [blame] | 342 | <sect4> |
| 343 | <title>Managed IRQ Registration</title> |
| 344 | <para> |
| 345 | Both the <function>drm_irq_install</function> and |
| 346 | <function>drm_irq_uninstall</function> functions get the device IRQ by |
| 347 | calling <function>drm_dev_to_irq</function>. This inline function will |
| 348 | call a bus-specific operation to retrieve the IRQ number. For platform |
| 349 | devices, <function>platform_get_irq</function>(..., 0) is used to |
| 350 | retrieve the IRQ number. |
| 351 | </para> |
| 352 | <para> |
| 353 | <function>drm_irq_install</function> starts by calling the |
| 354 | <methodname>irq_preinstall</methodname> driver operation. The operation |
| 355 | is optional and must make sure that the interrupt will not get fired by |
| 356 | clearing all pending interrupt flags or disabling the interrupt. |
| 357 | </para> |
| 358 | <para> |
| 359 | The IRQ will then be requested by a call to |
| 360 | <function>request_irq</function>. If the DRIVER_IRQ_SHARED driver |
| 361 | feature flag is set, a shared (IRQF_SHARED) IRQ handler will be |
| 362 | requested. |
| 363 | </para> |
| 364 | <para> |
| 365 | The IRQ handler function must be provided as the mandatory irq_handler |
| 366 | driver operation. It will get passed directly to |
| 367 | <function>request_irq</function> and thus has the same prototype as all |
| 368 | IRQ handlers. It will get called with a pointer to the DRM device as the |
| 369 | second argument. |
| 370 | </para> |
| 371 | <para> |
| 372 | Finally the function calls the optional |
| 373 | <methodname>irq_postinstall</methodname> driver operation. The operation |
| 374 | usually enables interrupts (excluding the vblank interrupt, which is |
| 375 | enabled separately), but drivers may choose to enable/disable interrupts |
| 376 | at a different time. |
| 377 | </para> |
| 378 | <para> |
| 379 | <function>drm_irq_uninstall</function> is similarly used to uninstall an |
| 380 | IRQ handler. It starts by waking up all processes waiting on a vblank |
| 381 | interrupt to make sure they don't hang, and then calls the optional |
| 382 | <methodname>irq_uninstall</methodname> driver operation. The operation |
| 383 | must disable all hardware interrupts. Finally the function frees the IRQ |
| 384 | by calling <function>free_irq</function>. |
| 385 | </para> |
| 386 | </sect4> |
| 387 | <sect4> |
| 388 | <title>Manual IRQ Registration</title> |
| 389 | <para> |
| 390 | Drivers that require multiple interrupt handlers can't use the managed |
| 391 | IRQ registration functions. In that case IRQs must be registered and |
| 392 | unregistered manually (usually with the <function>request_irq</function> |
| 393 | and <function>free_irq</function> functions, or their devm_* equivalent). |
| 394 | </para> |
| 395 | <para> |
| 396 | When manually registering IRQs, drivers must not set the DRIVER_HAVE_IRQ |
| 397 | driver feature flag, and must not provide the |
| 398 | <methodname>irq_handler</methodname> driver operation. They must set the |
| 399 | <structname>drm_device</structname> <structfield>irq_enabled</structfield> |
| 400 | field to 1 upon registration of the IRQs, and clear it to 0 after |
| 401 | unregistering the IRQs. |
| 402 | </para> |
| 403 | </sect4> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 404 | </sect3> |
| 405 | <sect3> |
| 406 | <title>Memory Manager Initialization</title> |
| 407 | <para> |
| 408 | Every DRM driver requires a memory manager which must be initialized at |
| 409 | load time. DRM currently contains two memory managers, the Translation |
| 410 | Table Manager (TTM) and the Graphics Execution Manager (GEM). |
| 411 | This document describes the use of the GEM memory manager only. See |
| 412 | <xref linkend="drm-memory-management"/> for details. |
| 413 | </para> |
| 414 | </sect3> |
| 415 | <sect3> |
| 416 | <title>Miscellaneous Device Configuration</title> |
| 417 | <para> |
| 418 | Another task that may be necessary for PCI devices during configuration |
| 419 | is mapping the video BIOS. On many devices, the VBIOS describes device |
| 420 | configuration, LCD panel timings (if any), and contains flags indicating |
| 421 | device state. Mapping the BIOS can be done using the pci_map_rom() call, |
| 422 | a convenience function that takes care of mapping the actual ROM, |
| 423 | whether it has been shadowed into memory (typically at address 0xc0000) |
| 424 | or exists on the PCI device in the ROM BAR. Note that after the ROM has |
| 425 | been mapped and any necessary information has been extracted, it should |
| 426 | be unmapped; on many devices, the ROM address decoder is shared with |
| 427 | other BARs, so leaving it mapped could cause undesired behaviour like |
| 428 | hangs or memory corruption. |
| 429 | <!--!Fdrivers/pci/rom.c pci_map_rom--> |
| 430 | </para> |
| 431 | </sect3> |
| 432 | </sect2> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 433 | </sect1> |
| 434 | |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 435 | <!-- Internals: memory management --> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 436 | |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 437 | <sect1 id="drm-memory-management"> |
| 438 | <title>Memory management</title> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 439 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 440 | Modern Linux systems require large amount of graphics memory to store |
| 441 | frame buffers, textures, vertices and other graphics-related data. Given |
| 442 | the very dynamic nature of many of that data, managing graphics memory |
| 443 | efficiently is thus crucial for the graphics stack and plays a central |
| 444 | role in the DRM infrastructure. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 445 | </para> |
| 446 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 447 | The DRM core includes two memory managers, namely Translation Table Maps |
| 448 | (TTM) and Graphics Execution Manager (GEM). TTM was the first DRM memory |
| 449 | manager to be developed and tried to be a one-size-fits-them all |
Anatol Pomozov | f884ab1 | 2013-05-08 16:56:16 -0700 | [diff] [blame] | 450 | solution. It provides a single userspace API to accommodate the need of |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 451 | all hardware, supporting both Unified Memory Architecture (UMA) devices |
| 452 | and devices with dedicated video RAM (i.e. most discrete video cards). |
| 453 | This resulted in a large, complex piece of code that turned out to be |
| 454 | hard to use for driver development. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 455 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 456 | <para> |
| 457 | GEM started as an Intel-sponsored project in reaction to TTM's |
| 458 | complexity. Its design philosophy is completely different: instead of |
| 459 | providing a solution to every graphics memory-related problems, GEM |
| 460 | identified common code between drivers and created a support library to |
| 461 | share it. GEM has simpler initialization and execution requirements than |
| 462 | TTM, but has no video RAM management capabitilies and is thus limited to |
| 463 | UMA devices. |
| 464 | </para> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 465 | <sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 466 | <title>The Translation Table Manager (TTM)</title> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 467 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 468 | TTM design background and information belongs here. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 469 | </para> |
| 470 | <sect3> |
| 471 | <title>TTM initialization</title> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 472 | <warning><para>This section is outdated.</para></warning> |
| 473 | <para> |
| 474 | Drivers wishing to support TTM must fill out a drm_bo_driver |
| 475 | structure. The structure contains several fields with function |
| 476 | pointers for initializing the TTM, allocating and freeing memory, |
| 477 | waiting for command completion and fence synchronization, and memory |
| 478 | migration. See the radeon_ttm.c file for an example of usage. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 479 | </para> |
| 480 | <para> |
| 481 | The ttm_global_reference structure is made up of several fields: |
| 482 | </para> |
| 483 | <programlisting> |
| 484 | struct ttm_global_reference { |
| 485 | enum ttm_global_types global_type; |
| 486 | size_t size; |
| 487 | void *object; |
| 488 | int (*init) (struct ttm_global_reference *); |
| 489 | void (*release) (struct ttm_global_reference *); |
| 490 | }; |
| 491 | </programlisting> |
| 492 | <para> |
| 493 | There should be one global reference structure for your memory |
| 494 | manager as a whole, and there will be others for each object |
| 495 | created by the memory manager at runtime. Your global TTM should |
| 496 | have a type of TTM_GLOBAL_TTM_MEM. The size field for the global |
| 497 | object should be sizeof(struct ttm_mem_global), and the init and |
Michael Witten | a5294e0 | 2011-08-29 18:05:52 +0000 | [diff] [blame] | 498 | release hooks should point at your driver-specific init and |
Michael Witten | a78f678 | 2011-08-25 17:18:08 +0000 | [diff] [blame] | 499 | release routines, which probably eventually call |
Michael Witten | 005d7f4 | 2011-08-25 19:02:52 +0000 | [diff] [blame] | 500 | ttm_mem_global_init and ttm_mem_global_release, respectively. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 501 | </para> |
| 502 | <para> |
| 503 | Once your global TTM accounting structure is set up and initialized |
Michael Witten | ae63d79 | 2011-08-25 19:19:18 +0000 | [diff] [blame] | 504 | by calling ttm_global_item_ref() on it, |
Michael Witten | 1c86de2 | 2011-08-25 19:14:26 +0000 | [diff] [blame] | 505 | you need to create a buffer object TTM to |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 506 | provide a pool for buffer object allocation by clients and the |
| 507 | kernel itself. The type of this object should be TTM_GLOBAL_TTM_BO, |
| 508 | and its size should be sizeof(struct ttm_bo_global). Again, |
Michael Witten | a5294e0 | 2011-08-29 18:05:52 +0000 | [diff] [blame] | 509 | driver-specific init and release functions may be provided, |
Michael Witten | ae63d79 | 2011-08-25 19:19:18 +0000 | [diff] [blame] | 510 | likely eventually calling ttm_bo_global_init() and |
| 511 | ttm_bo_global_release(), respectively. Also, like the previous |
| 512 | object, ttm_global_item_ref() is used to create an initial reference |
Nicolas Kaiser | ce04cc0 | 2010-05-28 07:33:49 +0200 | [diff] [blame] | 513 | count for the TTM, which will call your initialization function. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 514 | </para> |
| 515 | </sect3> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 516 | </sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 517 | <sect2 id="drm-gem"> |
| 518 | <title>The Graphics Execution Manager (GEM)</title> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 519 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 520 | The GEM design approach has resulted in a memory manager that doesn't |
| 521 | provide full coverage of all (or even all common) use cases in its |
| 522 | userspace or kernel API. GEM exposes a set of standard memory-related |
| 523 | operations to userspace and a set of helper functions to drivers, and let |
| 524 | drivers implement hardware-specific operations with their own private API. |
| 525 | </para> |
| 526 | <para> |
| 527 | The GEM userspace API is described in the |
| 528 | <ulink url="http://lwn.net/Articles/283798/"><citetitle>GEM - the Graphics |
| 529 | Execution Manager</citetitle></ulink> article on LWN. While slightly |
| 530 | outdated, the document provides a good overview of the GEM API principles. |
| 531 | Buffer allocation and read and write operations, described as part of the |
| 532 | common GEM API, are currently implemented using driver-specific ioctls. |
| 533 | </para> |
| 534 | <para> |
| 535 | GEM is data-agnostic. It manages abstract buffer objects without knowing |
| 536 | what individual buffers contain. APIs that require knowledge of buffer |
| 537 | contents or purpose, such as buffer allocation or synchronization |
| 538 | primitives, are thus outside of the scope of GEM and must be implemented |
| 539 | using driver-specific ioctls. |
| 540 | </para> |
| 541 | <para> |
| 542 | On a fundamental level, GEM involves several operations: |
Michael Witten | 327d6fb | 2011-08-25 20:18:14 +0000 | [diff] [blame] | 543 | <itemizedlist> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 544 | <listitem>Memory allocation and freeing</listitem> |
| 545 | <listitem>Command execution</listitem> |
| 546 | <listitem>Aperture management at command execution time</listitem> |
Michael Witten | 327d6fb | 2011-08-25 20:18:14 +0000 | [diff] [blame] | 547 | </itemizedlist> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 548 | Buffer object allocation is relatively straightforward and largely |
| 549 | provided by Linux's shmem layer, which provides memory to back each |
| 550 | object. |
| 551 | </para> |
| 552 | <para> |
| 553 | Device-specific operations, such as command execution, pinning, buffer |
| 554 | read & write, mapping, and domain ownership transfers are left to |
| 555 | driver-specific ioctls. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 556 | </para> |
| 557 | <sect3> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 558 | <title>GEM Initialization</title> |
| 559 | <para> |
| 560 | Drivers that use GEM must set the DRIVER_GEM bit in the struct |
| 561 | <structname>drm_driver</structname> |
| 562 | <structfield>driver_features</structfield> field. The DRM core will |
| 563 | then automatically initialize the GEM core before calling the |
| 564 | <methodname>load</methodname> operation. Behind the scene, this will |
| 565 | create a DRM Memory Manager object which provides an address space |
| 566 | pool for object allocation. |
| 567 | </para> |
| 568 | <para> |
| 569 | In a KMS configuration, drivers need to allocate and initialize a |
| 570 | command ring buffer following core GEM initialization if required by |
| 571 | the hardware. UMA devices usually have what is called a "stolen" |
| 572 | memory region, which provides space for the initial framebuffer and |
| 573 | large, contiguous memory regions required by the device. This space is |
| 574 | typically not managed by GEM, and must be initialized separately into |
| 575 | its own DRM MM object. |
| 576 | </para> |
| 577 | </sect3> |
| 578 | <sect3> |
| 579 | <title>GEM Objects Creation</title> |
| 580 | <para> |
| 581 | GEM splits creation of GEM objects and allocation of the memory that |
| 582 | backs them in two distinct operations. |
| 583 | </para> |
| 584 | <para> |
| 585 | GEM objects are represented by an instance of struct |
| 586 | <structname>drm_gem_object</structname>. Drivers usually need to extend |
| 587 | GEM objects with private information and thus create a driver-specific |
| 588 | GEM object structure type that embeds an instance of struct |
| 589 | <structname>drm_gem_object</structname>. |
| 590 | </para> |
| 591 | <para> |
| 592 | To create a GEM object, a driver allocates memory for an instance of its |
| 593 | specific GEM object type and initializes the embedded struct |
| 594 | <structname>drm_gem_object</structname> with a call to |
| 595 | <function>drm_gem_object_init</function>. The function takes a pointer to |
| 596 | the DRM device, a pointer to the GEM object and the buffer object size |
| 597 | in bytes. |
| 598 | </para> |
| 599 | <para> |
| 600 | GEM uses shmem to allocate anonymous pageable memory. |
| 601 | <function>drm_gem_object_init</function> will create an shmfs file of |
| 602 | the requested size and store it into the struct |
| 603 | <structname>drm_gem_object</structname> <structfield>filp</structfield> |
| 604 | field. The memory is used as either main storage for the object when the |
| 605 | graphics hardware uses system memory directly or as a backing store |
| 606 | otherwise. |
| 607 | </para> |
| 608 | <para> |
| 609 | Drivers are responsible for the actual physical pages allocation by |
| 610 | calling <function>shmem_read_mapping_page_gfp</function> for each page. |
| 611 | Note that they can decide to allocate pages when initializing the GEM |
| 612 | object, or to delay allocation until the memory is needed (for instance |
| 613 | when a page fault occurs as a result of a userspace memory access or |
| 614 | when the driver needs to start a DMA transfer involving the memory). |
| 615 | </para> |
| 616 | <para> |
| 617 | Anonymous pageable memory allocation is not always desired, for instance |
| 618 | when the hardware requires physically contiguous system memory as is |
| 619 | often the case in embedded devices. Drivers can create GEM objects with |
| 620 | no shmfs backing (called private GEM objects) by initializing them with |
| 621 | a call to <function>drm_gem_private_object_init</function> instead of |
| 622 | <function>drm_gem_object_init</function>. Storage for private GEM |
| 623 | objects must be managed by drivers. |
| 624 | </para> |
| 625 | <para> |
| 626 | Drivers that do not need to extend GEM objects with private information |
| 627 | can call the <function>drm_gem_object_alloc</function> function to |
| 628 | allocate and initialize a struct <structname>drm_gem_object</structname> |
| 629 | instance. The GEM core will call the optional driver |
| 630 | <methodname>gem_init_object</methodname> operation after initializing |
| 631 | the GEM object with <function>drm_gem_object_init</function>. |
| 632 | <synopsis>int (*gem_init_object) (struct drm_gem_object *obj);</synopsis> |
| 633 | </para> |
| 634 | <para> |
| 635 | No alloc-and-init function exists for private GEM objects. |
| 636 | </para> |
| 637 | </sect3> |
| 638 | <sect3> |
| 639 | <title>GEM Objects Lifetime</title> |
| 640 | <para> |
| 641 | All GEM objects are reference-counted by the GEM core. References can be |
| 642 | acquired and release by <function>calling drm_gem_object_reference</function> |
| 643 | and <function>drm_gem_object_unreference</function> respectively. The |
| 644 | caller must hold the <structname>drm_device</structname> |
| 645 | <structfield>struct_mutex</structfield> lock. As a convenience, GEM |
| 646 | provides the <function>drm_gem_object_reference_unlocked</function> and |
| 647 | <function>drm_gem_object_unreference_unlocked</function> functions that |
| 648 | can be called without holding the lock. |
| 649 | </para> |
| 650 | <para> |
| 651 | When the last reference to a GEM object is released the GEM core calls |
| 652 | the <structname>drm_driver</structname> |
| 653 | <methodname>gem_free_object</methodname> operation. That operation is |
| 654 | mandatory for GEM-enabled drivers and must free the GEM object and all |
| 655 | associated resources. |
| 656 | </para> |
| 657 | <para> |
| 658 | <synopsis>void (*gem_free_object) (struct drm_gem_object *obj);</synopsis> |
| 659 | Drivers are responsible for freeing all GEM object resources, including |
| 660 | the resources created by the GEM core. If an mmap offset has been |
| 661 | created for the object (in which case |
| 662 | <structname>drm_gem_object</structname>::<structfield>map_list</structfield>::<structfield>map</structfield> |
| 663 | is not NULL) it must be freed by a call to |
| 664 | <function>drm_gem_free_mmap_offset</function>. The shmfs backing store |
| 665 | must be released by calling <function>drm_gem_object_release</function> |
| 666 | (that function can safely be called if no shmfs backing store has been |
| 667 | created). |
| 668 | </para> |
| 669 | </sect3> |
| 670 | <sect3> |
| 671 | <title>GEM Objects Naming</title> |
| 672 | <para> |
| 673 | Communication between userspace and the kernel refers to GEM objects |
| 674 | using local handles, global names or, more recently, file descriptors. |
| 675 | All of those are 32-bit integer values; the usual Linux kernel limits |
| 676 | apply to the file descriptors. |
| 677 | </para> |
| 678 | <para> |
| 679 | GEM handles are local to a DRM file. Applications get a handle to a GEM |
| 680 | object through a driver-specific ioctl, and can use that handle to refer |
| 681 | to the GEM object in other standard or driver-specific ioctls. Closing a |
| 682 | DRM file handle frees all its GEM handles and dereferences the |
| 683 | associated GEM objects. |
| 684 | </para> |
| 685 | <para> |
| 686 | To create a handle for a GEM object drivers call |
| 687 | <function>drm_gem_handle_create</function>. The function takes a pointer |
| 688 | to the DRM file and the GEM object and returns a locally unique handle. |
| 689 | When the handle is no longer needed drivers delete it with a call to |
| 690 | <function>drm_gem_handle_delete</function>. Finally the GEM object |
| 691 | associated with a handle can be retrieved by a call to |
| 692 | <function>drm_gem_object_lookup</function>. |
| 693 | </para> |
| 694 | <para> |
| 695 | Handles don't take ownership of GEM objects, they only take a reference |
| 696 | to the object that will be dropped when the handle is destroyed. To |
| 697 | avoid leaking GEM objects, drivers must make sure they drop the |
| 698 | reference(s) they own (such as the initial reference taken at object |
| 699 | creation time) as appropriate, without any special consideration for the |
| 700 | handle. For example, in the particular case of combined GEM object and |
| 701 | handle creation in the implementation of the |
| 702 | <methodname>dumb_create</methodname> operation, drivers must drop the |
| 703 | initial reference to the GEM object before returning the handle. |
| 704 | </para> |
| 705 | <para> |
| 706 | GEM names are similar in purpose to handles but are not local to DRM |
| 707 | files. They can be passed between processes to reference a GEM object |
| 708 | globally. Names can't be used directly to refer to objects in the DRM |
| 709 | API, applications must convert handles to names and names to handles |
| 710 | using the DRM_IOCTL_GEM_FLINK and DRM_IOCTL_GEM_OPEN ioctls |
| 711 | respectively. The conversion is handled by the DRM core without any |
| 712 | driver-specific support. |
| 713 | </para> |
Daniel Vetter | 251261d | 2014-01-22 18:46:33 +0100 | [diff] [blame] | 714 | <para> |
| 715 | GEM also supports buffer sharing with dma-buf file descriptors through |
| 716 | PRIME. GEM-based drivers must use the provided helpers functions to |
| 717 | implement the exporting and importing correctly. See <xref linkend="drm-prime-support" />. |
| 718 | Since sharing file descriptors is inherently more secure than the |
| 719 | easily guessable and global GEM names it is the preferred buffer |
| 720 | sharing mechanism. Sharing buffers through GEM names is only supported |
| 721 | for legacy userspace. Furthermore PRIME also allows cross-device |
| 722 | buffer sharing since it is based on dma-bufs. |
| 723 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 724 | </sect3> |
| 725 | <sect3 id="drm-gem-objects-mapping"> |
| 726 | <title>GEM Objects Mapping</title> |
| 727 | <para> |
| 728 | Because mapping operations are fairly heavyweight GEM favours |
| 729 | read/write-like access to buffers, implemented through driver-specific |
| 730 | ioctls, over mapping buffers to userspace. However, when random access |
| 731 | to the buffer is needed (to perform software rendering for instance), |
| 732 | direct access to the object can be more efficient. |
| 733 | </para> |
| 734 | <para> |
| 735 | The mmap system call can't be used directly to map GEM objects, as they |
| 736 | don't have their own file handle. Two alternative methods currently |
| 737 | co-exist to map GEM objects to userspace. The first method uses a |
| 738 | driver-specific ioctl to perform the mapping operation, calling |
| 739 | <function>do_mmap</function> under the hood. This is often considered |
| 740 | dubious, seems to be discouraged for new GEM-enabled drivers, and will |
| 741 | thus not be described here. |
| 742 | </para> |
| 743 | <para> |
| 744 | The second method uses the mmap system call on the DRM file handle. |
| 745 | <synopsis>void *mmap(void *addr, size_t length, int prot, int flags, int fd, |
| 746 | off_t offset);</synopsis> |
| 747 | DRM identifies the GEM object to be mapped by a fake offset passed |
| 748 | through the mmap offset argument. Prior to being mapped, a GEM object |
| 749 | must thus be associated with a fake offset. To do so, drivers must call |
| 750 | <function>drm_gem_create_mmap_offset</function> on the object. The |
| 751 | function allocates a fake offset range from a pool and stores the |
| 752 | offset divided by PAGE_SIZE in |
| 753 | <literal>obj->map_list.hash.key</literal>. Care must be taken not to |
| 754 | call <function>drm_gem_create_mmap_offset</function> if a fake offset |
| 755 | has already been allocated for the object. This can be tested by |
| 756 | <literal>obj->map_list.map</literal> being non-NULL. |
| 757 | </para> |
| 758 | <para> |
| 759 | Once allocated, the fake offset value |
| 760 | (<literal>obj->map_list.hash.key << PAGE_SHIFT</literal>) |
| 761 | must be passed to the application in a driver-specific way and can then |
| 762 | be used as the mmap offset argument. |
| 763 | </para> |
| 764 | <para> |
| 765 | The GEM core provides a helper method <function>drm_gem_mmap</function> |
| 766 | to handle object mapping. The method can be set directly as the mmap |
| 767 | file operation handler. It will look up the GEM object based on the |
| 768 | offset value and set the VMA operations to the |
| 769 | <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield> |
| 770 | field. Note that <function>drm_gem_mmap</function> doesn't map memory to |
| 771 | userspace, but relies on the driver-provided fault handler to map pages |
| 772 | individually. |
| 773 | </para> |
| 774 | <para> |
| 775 | To use <function>drm_gem_mmap</function>, drivers must fill the struct |
| 776 | <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield> |
| 777 | field with a pointer to VM operations. |
| 778 | </para> |
| 779 | <para> |
| 780 | <synopsis>struct vm_operations_struct *gem_vm_ops |
| 781 | |
| 782 | struct vm_operations_struct { |
| 783 | void (*open)(struct vm_area_struct * area); |
| 784 | void (*close)(struct vm_area_struct * area); |
| 785 | int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf); |
| 786 | };</synopsis> |
| 787 | </para> |
| 788 | <para> |
| 789 | The <methodname>open</methodname> and <methodname>close</methodname> |
| 790 | operations must update the GEM object reference count. Drivers can use |
| 791 | the <function>drm_gem_vm_open</function> and |
| 792 | <function>drm_gem_vm_close</function> helper functions directly as open |
| 793 | and close handlers. |
| 794 | </para> |
| 795 | <para> |
| 796 | The fault operation handler is responsible for mapping individual pages |
| 797 | to userspace when a page fault occurs. Depending on the memory |
| 798 | allocation scheme, drivers can allocate pages at fault time, or can |
| 799 | decide to allocate memory for the GEM object at the time the object is |
| 800 | created. |
| 801 | </para> |
| 802 | <para> |
| 803 | Drivers that want to map the GEM object upfront instead of handling page |
| 804 | faults can implement their own mmap file operation handler. |
| 805 | </para> |
| 806 | </sect3> |
| 807 | <sect3> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 808 | <title>Memory Coherency</title> |
| 809 | <para> |
| 810 | When mapped to the device or used in a command buffer, backing pages |
| 811 | for an object are flushed to memory and marked write combined so as to |
| 812 | be coherent with the GPU. Likewise, if the CPU accesses an object |
| 813 | after the GPU has finished rendering to the object, then the object |
| 814 | must be made coherent with the CPU's view of memory, usually involving |
| 815 | GPU cache flushing of various kinds. This core CPU<->GPU |
| 816 | coherency management is provided by a device-specific ioctl, which |
| 817 | evaluates an object's current domain and performs any necessary |
| 818 | flushing or synchronization to put the object into the desired |
| 819 | coherency domain (note that the object may be busy, i.e. an active |
| 820 | render target; in that case, setting the domain blocks the client and |
| 821 | waits for rendering to complete before performing any necessary |
| 822 | flushing operations). |
| 823 | </para> |
| 824 | </sect3> |
| 825 | <sect3> |
| 826 | <title>Command Execution</title> |
| 827 | <para> |
| 828 | Perhaps the most important GEM function for GPU devices is providing a |
| 829 | command execution interface to clients. Client programs construct |
| 830 | command buffers containing references to previously allocated memory |
| 831 | objects, and then submit them to GEM. At that point, GEM takes care to |
| 832 | bind all the objects into the GTT, execute the buffer, and provide |
| 833 | necessary synchronization between clients accessing the same buffers. |
| 834 | This often involves evicting some objects from the GTT and re-binding |
| 835 | others (a fairly expensive operation), and providing relocation |
| 836 | support which hides fixed GTT offsets from clients. Clients must take |
| 837 | care not to submit command buffers that reference more objects than |
| 838 | can fit in the GTT; otherwise, GEM will reject them and no rendering |
| 839 | will occur. Similarly, if several objects in the buffer require fence |
| 840 | registers to be allocated for correct rendering (e.g. 2D blits on |
| 841 | pre-965 chips), care must be taken not to require more fence registers |
| 842 | than are available to the client. Such resource management should be |
| 843 | abstracted from the client in libdrm. |
| 844 | </para> |
| 845 | </sect3> |
Daniel Vetter | 251261d | 2014-01-22 18:46:33 +0100 | [diff] [blame] | 846 | <sect3> |
Daniel Vetter | 89d61fc | 2014-01-21 12:39:00 +0100 | [diff] [blame] | 847 | <title>GEM Function Reference</title> |
| 848 | !Edrivers/gpu/drm/drm_gem.c |
Daniel Vetter | 251261d | 2014-01-22 18:46:33 +0100 | [diff] [blame] | 849 | </sect3> |
Daniel Vetter | 89d61fc | 2014-01-21 12:39:00 +0100 | [diff] [blame] | 850 | </sect2> |
Daniel Vetter | 4c5acf3 | 2014-01-22 12:28:42 +0100 | [diff] [blame] | 851 | <sect2> |
| 852 | <title>VMA Offset Manager</title> |
| 853 | !Pdrivers/gpu/drm/drm_vma_manager.c vma offset manager |
| 854 | !Edrivers/gpu/drm/drm_vma_manager.c |
| 855 | !Iinclude/drm/drm_vma_manager.h |
| 856 | </sect2> |
Daniel Vetter | 251261d | 2014-01-22 18:46:33 +0100 | [diff] [blame] | 857 | <sect2 id="drm-prime-support"> |
| 858 | <title>PRIME Buffer Sharing</title> |
| 859 | <para> |
| 860 | PRIME is the cross device buffer sharing framework in drm, originally |
| 861 | created for the OPTIMUS range of multi-gpu platforms. To userspace |
| 862 | PRIME buffers are dma-buf based file descriptors. |
| 863 | </para> |
| 864 | <sect3> |
| 865 | <title>Overview and Driver Interface</title> |
| 866 | <para> |
| 867 | Similar to GEM global names, PRIME file descriptors are |
| 868 | also used to share buffer objects across processes. They offer |
| 869 | additional security: as file descriptors must be explicitly sent over |
| 870 | UNIX domain sockets to be shared between applications, they can't be |
| 871 | guessed like the globally unique GEM names. |
| 872 | </para> |
| 873 | <para> |
| 874 | Drivers that support the PRIME |
| 875 | API must set the DRIVER_PRIME bit in the struct |
| 876 | <structname>drm_driver</structname> |
| 877 | <structfield>driver_features</structfield> field, and implement the |
| 878 | <methodname>prime_handle_to_fd</methodname> and |
| 879 | <methodname>prime_fd_to_handle</methodname> operations. |
| 880 | </para> |
| 881 | <para> |
| 882 | <synopsis>int (*prime_handle_to_fd)(struct drm_device *dev, |
| 883 | struct drm_file *file_priv, uint32_t handle, |
| 884 | uint32_t flags, int *prime_fd); |
| 885 | int (*prime_fd_to_handle)(struct drm_device *dev, |
| 886 | struct drm_file *file_priv, int prime_fd, |
| 887 | uint32_t *handle);</synopsis> |
| 888 | Those two operations convert a handle to a PRIME file descriptor and |
| 889 | vice versa. Drivers must use the kernel dma-buf buffer sharing framework |
| 890 | to manage the PRIME file descriptors. Similar to the mode setting |
| 891 | API PRIME is agnostic to the underlying buffer object manager, as |
| 892 | long as handles are 32bit unsinged integers. |
| 893 | </para> |
| 894 | <para> |
| 895 | While non-GEM drivers must implement the operations themselves, GEM |
| 896 | drivers must use the <function>drm_gem_prime_handle_to_fd</function> |
| 897 | and <function>drm_gem_prime_fd_to_handle</function> helper functions. |
| 898 | Those helpers rely on the driver |
| 899 | <methodname>gem_prime_export</methodname> and |
| 900 | <methodname>gem_prime_import</methodname> operations to create a dma-buf |
| 901 | instance from a GEM object (dma-buf exporter role) and to create a GEM |
| 902 | object from a dma-buf instance (dma-buf importer role). |
| 903 | </para> |
| 904 | <para> |
| 905 | <synopsis>struct dma_buf * (*gem_prime_export)(struct drm_device *dev, |
| 906 | struct drm_gem_object *obj, |
| 907 | int flags); |
| 908 | struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev, |
| 909 | struct dma_buf *dma_buf);</synopsis> |
| 910 | These two operations are mandatory for GEM drivers that support |
| 911 | PRIME. |
| 912 | </para> |
| 913 | </sect3> |
| 914 | <sect3> |
Daniel Vetter | 39cc344 | 2014-01-22 19:16:30 +0100 | [diff] [blame] | 915 | <title>PRIME Helper Functions</title> |
Daniel Vetter | 251261d | 2014-01-22 18:46:33 +0100 | [diff] [blame] | 916 | !Pdrivers/gpu/drm/drm_prime.c PRIME Helpers |
| 917 | </sect3> |
| 918 | </sect2> |
Daniel Vetter | 39cc344 | 2014-01-22 19:16:30 +0100 | [diff] [blame] | 919 | <sect2> |
| 920 | <title>PRIME Function References</title> |
| 921 | !Edrivers/gpu/drm/drm_prime.c |
| 922 | </sect2> |
Daniel Vetter | 93110be | 2014-01-23 00:31:48 +0100 | [diff] [blame] | 923 | <sect2> |
| 924 | <title>DRM MM Range Allocator</title> |
| 925 | <sect3> |
| 926 | <title>Overview</title> |
| 927 | !Pdrivers/gpu/drm/drm_mm.c Overview |
| 928 | </sect3> |
| 929 | <sect3> |
| 930 | <title>LRU Scan/Eviction Support</title> |
| 931 | !Pdrivers/gpu/drm/drm_mm.c lru scan roaster |
| 932 | </sect3> |
| 933 | </sect2> |
Daniel Vetter | e18c041 | 2014-01-23 00:39:13 +0100 | [diff] [blame] | 934 | <sect2> |
| 935 | <title>DRM MM Range Allocator Function References</title> |
| 936 | !Edrivers/gpu/drm/drm_mm.c |
| 937 | !Iinclude/drm/drm_mm.h |
| 938 | </sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 939 | </sect1> |
| 940 | |
| 941 | <!-- Internals: mode setting --> |
| 942 | |
| 943 | <sect1 id="drm-mode-setting"> |
| 944 | <title>Mode Setting</title> |
| 945 | <para> |
| 946 | Drivers must initialize the mode setting core by calling |
| 947 | <function>drm_mode_config_init</function> on the DRM device. The function |
| 948 | initializes the <structname>drm_device</structname> |
| 949 | <structfield>mode_config</structfield> field and never fails. Once done, |
| 950 | mode configuration must be setup by initializing the following fields. |
| 951 | </para> |
| 952 | <itemizedlist> |
| 953 | <listitem> |
| 954 | <synopsis>int min_width, min_height; |
| 955 | int max_width, max_height;</synopsis> |
| 956 | <para> |
| 957 | Minimum and maximum width and height of the frame buffers in pixel |
| 958 | units. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 959 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 960 | </listitem> |
| 961 | <listitem> |
| 962 | <synopsis>struct drm_mode_config_funcs *funcs;</synopsis> |
| 963 | <para>Mode setting functions.</para> |
| 964 | </listitem> |
| 965 | </itemizedlist> |
| 966 | <sect2> |
Daniel Vetter | 3ec0db8 | 2014-01-23 15:06:15 +0100 | [diff] [blame] | 967 | <title>Display Modes Function Reference</title> |
Daniel Vetter | f5aabb9 | 2014-01-23 20:05:00 +0100 | [diff] [blame] | 968 | !Iinclude/drm/drm_modes.h |
Daniel Vetter | 3ec0db8 | 2014-01-23 15:06:15 +0100 | [diff] [blame] | 969 | !Edrivers/gpu/drm/drm_modes.c |
| 970 | </sect2> |
| 971 | <sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 972 | <title>Frame Buffer Creation</title> |
| 973 | <synopsis>struct drm_framebuffer *(*fb_create)(struct drm_device *dev, |
| 974 | struct drm_file *file_priv, |
| 975 | struct drm_mode_fb_cmd2 *mode_cmd);</synopsis> |
| 976 | <para> |
| 977 | Frame buffers are abstract memory objects that provide a source of |
| 978 | pixels to scanout to a CRTC. Applications explicitly request the |
| 979 | creation of frame buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls and |
| 980 | receive an opaque handle that can be passed to the KMS CRTC control, |
| 981 | plane configuration and page flip functions. |
| 982 | </para> |
| 983 | <para> |
| 984 | Frame buffers rely on the underneath memory manager for low-level memory |
| 985 | operations. When creating a frame buffer applications pass a memory |
| 986 | handle (or a list of memory handles for multi-planar formats) through |
Daniel Vetter | 065a502 | 2014-01-21 12:01:41 +0100 | [diff] [blame] | 987 | the <parameter>drm_mode_fb_cmd2</parameter> argument. For drivers using |
| 988 | GEM as their userspace buffer management interface this would be a GEM |
| 989 | handle. Drivers are however free to use their own backing storage object |
| 990 | handles, e.g. vmwgfx directly exposes special TTM handles to userspace |
| 991 | and so expects TTM handles in the create ioctl and not GEM handles. |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 992 | </para> |
| 993 | <para> |
| 994 | Drivers must first validate the requested frame buffer parameters passed |
| 995 | through the mode_cmd argument. In particular this is where invalid |
| 996 | sizes, pixel formats or pitches can be caught. |
| 997 | </para> |
| 998 | <para> |
| 999 | If the parameters are deemed valid, drivers then create, initialize and |
| 1000 | return an instance of struct <structname>drm_framebuffer</structname>. |
| 1001 | If desired the instance can be embedded in a larger driver-specific |
Daniel Vetter | 5d7a951 | 2013-01-04 22:31:20 +0100 | [diff] [blame] | 1002 | structure. Drivers must fill its <structfield>width</structfield>, |
| 1003 | <structfield>height</structfield>, <structfield>pitches</structfield>, |
| 1004 | <structfield>offsets</structfield>, <structfield>depth</structfield>, |
| 1005 | <structfield>bits_per_pixel</structfield> and |
| 1006 | <structfield>pixel_format</structfield> fields from the values passed |
| 1007 | through the <parameter>drm_mode_fb_cmd2</parameter> argument. They |
| 1008 | should call the <function>drm_helper_mode_fill_fb_struct</function> |
| 1009 | helper function to do so. |
| 1010 | </para> |
| 1011 | |
| 1012 | <para> |
Daniel Vetter | 065a502 | 2014-01-21 12:01:41 +0100 | [diff] [blame] | 1013 | The initialization of the new framebuffer instance is finalized with a |
Daniel Vetter | 5d7a951 | 2013-01-04 22:31:20 +0100 | [diff] [blame] | 1014 | call to <function>drm_framebuffer_init</function> which takes a pointer |
| 1015 | to DRM frame buffer operations (struct |
| 1016 | <structname>drm_framebuffer_funcs</structname>). Note that this function |
| 1017 | publishes the framebuffer and so from this point on it can be accessed |
| 1018 | concurrently from other threads. Hence it must be the last step in the |
| 1019 | driver's framebuffer initialization sequence. Frame buffer operations |
| 1020 | are |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1021 | <itemizedlist> |
| 1022 | <listitem> |
| 1023 | <synopsis>int (*create_handle)(struct drm_framebuffer *fb, |
| 1024 | struct drm_file *file_priv, unsigned int *handle);</synopsis> |
| 1025 | <para> |
| 1026 | Create a handle to the frame buffer underlying memory object. If |
| 1027 | the frame buffer uses a multi-plane format, the handle will |
| 1028 | reference the memory object associated with the first plane. |
| 1029 | </para> |
| 1030 | <para> |
| 1031 | Drivers call <function>drm_gem_handle_create</function> to create |
| 1032 | the handle. |
| 1033 | </para> |
| 1034 | </listitem> |
| 1035 | <listitem> |
| 1036 | <synopsis>void (*destroy)(struct drm_framebuffer *framebuffer);</synopsis> |
| 1037 | <para> |
| 1038 | Destroy the frame buffer object and frees all associated |
| 1039 | resources. Drivers must call |
| 1040 | <function>drm_framebuffer_cleanup</function> to free resources |
| 1041 | allocated by the DRM core for the frame buffer object, and must |
| 1042 | make sure to unreference all memory objects associated with the |
| 1043 | frame buffer. Handles created by the |
| 1044 | <methodname>create_handle</methodname> operation are released by |
| 1045 | the DRM core. |
| 1046 | </para> |
| 1047 | </listitem> |
| 1048 | <listitem> |
| 1049 | <synopsis>int (*dirty)(struct drm_framebuffer *framebuffer, |
| 1050 | struct drm_file *file_priv, unsigned flags, unsigned color, |
| 1051 | struct drm_clip_rect *clips, unsigned num_clips);</synopsis> |
| 1052 | <para> |
| 1053 | This optional operation notifies the driver that a region of the |
| 1054 | frame buffer has changed in response to a DRM_IOCTL_MODE_DIRTYFB |
| 1055 | ioctl call. |
| 1056 | </para> |
| 1057 | </listitem> |
| 1058 | </itemizedlist> |
| 1059 | </para> |
| 1060 | <para> |
Daniel Vetter | 5d7a951 | 2013-01-04 22:31:20 +0100 | [diff] [blame] | 1061 | The lifetime of a drm framebuffer is controlled with a reference count, |
| 1062 | drivers can grab additional references with |
Daniel Vetter | 9ee984a | 2014-01-23 21:57:37 +0100 | [diff] [blame] | 1063 | <function>drm_framebuffer_reference</function>and drop them |
Daniel Vetter | 5d7a951 | 2013-01-04 22:31:20 +0100 | [diff] [blame] | 1064 | again with <function>drm_framebuffer_unreference</function>. For |
| 1065 | driver-private framebuffers for which the last reference is never |
| 1066 | dropped (e.g. for the fbdev framebuffer when the struct |
| 1067 | <structname>drm_framebuffer</structname> is embedded into the fbdev |
| 1068 | helper struct) drivers can manually clean up a framebuffer at module |
| 1069 | unload time with |
| 1070 | <function>drm_framebuffer_unregister_private</function>. |
Daniel Vetter | 9ee984a | 2014-01-23 21:57:37 +0100 | [diff] [blame] | 1071 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1072 | </sect2> |
| 1073 | <sect2> |
Daniel Vetter | 065a502 | 2014-01-21 12:01:41 +0100 | [diff] [blame] | 1074 | <title>Dumb Buffer Objects</title> |
| 1075 | <para> |
| 1076 | The KMS API doesn't standardize backing storage object creation and |
| 1077 | leaves it to driver-specific ioctls. Furthermore actually creating a |
| 1078 | buffer object even for GEM-based drivers is done through a |
| 1079 | driver-specific ioctl - GEM only has a common userspace interface for |
| 1080 | sharing and destroying objects. While not an issue for full-fledged |
| 1081 | graphics stacks that include device-specific userspace components (in |
| 1082 | libdrm for instance), this limit makes DRM-based early boot graphics |
| 1083 | unnecessarily complex. |
| 1084 | </para> |
| 1085 | <para> |
| 1086 | Dumb objects partly alleviate the problem by providing a standard |
| 1087 | API to create dumb buffers suitable for scanout, which can then be used |
| 1088 | to create KMS frame buffers. |
| 1089 | </para> |
| 1090 | <para> |
| 1091 | To support dumb objects drivers must implement the |
| 1092 | <methodname>dumb_create</methodname>, |
| 1093 | <methodname>dumb_destroy</methodname> and |
| 1094 | <methodname>dumb_map_offset</methodname> operations. |
| 1095 | </para> |
| 1096 | <itemizedlist> |
| 1097 | <listitem> |
| 1098 | <synopsis>int (*dumb_create)(struct drm_file *file_priv, struct drm_device *dev, |
| 1099 | struct drm_mode_create_dumb *args);</synopsis> |
| 1100 | <para> |
| 1101 | The <methodname>dumb_create</methodname> operation creates a driver |
| 1102 | object (GEM or TTM handle) suitable for scanout based on the |
| 1103 | width, height and depth from the struct |
| 1104 | <structname>drm_mode_create_dumb</structname> argument. It fills the |
| 1105 | argument's <structfield>handle</structfield>, |
| 1106 | <structfield>pitch</structfield> and <structfield>size</structfield> |
| 1107 | fields with a handle for the newly created object and its line |
| 1108 | pitch and size in bytes. |
| 1109 | </para> |
| 1110 | </listitem> |
| 1111 | <listitem> |
| 1112 | <synopsis>int (*dumb_destroy)(struct drm_file *file_priv, struct drm_device *dev, |
| 1113 | uint32_t handle);</synopsis> |
| 1114 | <para> |
| 1115 | The <methodname>dumb_destroy</methodname> operation destroys a dumb |
| 1116 | object created by <methodname>dumb_create</methodname>. |
| 1117 | </para> |
| 1118 | </listitem> |
| 1119 | <listitem> |
| 1120 | <synopsis>int (*dumb_map_offset)(struct drm_file *file_priv, struct drm_device *dev, |
| 1121 | uint32_t handle, uint64_t *offset);</synopsis> |
| 1122 | <para> |
| 1123 | The <methodname>dumb_map_offset</methodname> operation associates an |
| 1124 | mmap fake offset with the object given by the handle and returns |
| 1125 | it. Drivers must use the |
| 1126 | <function>drm_gem_create_mmap_offset</function> function to |
| 1127 | associate the fake offset as described in |
| 1128 | <xref linkend="drm-gem-objects-mapping"/>. |
| 1129 | </para> |
| 1130 | </listitem> |
| 1131 | </itemizedlist> |
| 1132 | <para> |
| 1133 | Note that dumb objects may not be used for gpu acceleration, as has been |
| 1134 | attempted on some ARM embedded platforms. Such drivers really must have |
| 1135 | a hardware-specific ioctl to allocate suitable buffer objects. |
| 1136 | </para> |
| 1137 | </sect2> |
| 1138 | <sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1139 | <title>Output Polling</title> |
| 1140 | <synopsis>void (*output_poll_changed)(struct drm_device *dev);</synopsis> |
| 1141 | <para> |
| 1142 | This operation notifies the driver that the status of one or more |
| 1143 | connectors has changed. Drivers that use the fb helper can just call the |
| 1144 | <function>drm_fb_helper_hotplug_event</function> function to handle this |
| 1145 | operation. |
| 1146 | </para> |
| 1147 | </sect2> |
Daniel Vetter | 5d7a951 | 2013-01-04 22:31:20 +0100 | [diff] [blame] | 1148 | <sect2> |
| 1149 | <title>Locking</title> |
| 1150 | <para> |
| 1151 | Beside some lookup structures with their own locking (which is hidden |
| 1152 | behind the interface functions) most of the modeset state is protected |
| 1153 | by the <code>dev-<mode_config.lock</code> mutex and additionally |
| 1154 | per-crtc locks to allow cursor updates, pageflips and similar operations |
| 1155 | to occur concurrently with background tasks like output detection. |
| 1156 | Operations which cross domains like a full modeset always grab all |
| 1157 | locks. Drivers there need to protect resources shared between crtcs with |
| 1158 | additional locking. They also need to be careful to always grab the |
| 1159 | relevant crtc locks if a modset functions touches crtc state, e.g. for |
| 1160 | load detection (which does only grab the <code>mode_config.lock</code> |
| 1161 | to allow concurrent screen updates on live crtcs). |
| 1162 | </para> |
| 1163 | </sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1164 | </sect1> |
| 1165 | |
| 1166 | <!-- Internals: kms initialization and cleanup --> |
| 1167 | |
| 1168 | <sect1 id="drm-kms-init"> |
| 1169 | <title>KMS Initialization and Cleanup</title> |
| 1170 | <para> |
| 1171 | A KMS device is abstracted and exposed as a set of planes, CRTCs, encoders |
| 1172 | and connectors. KMS drivers must thus create and initialize all those |
| 1173 | objects at load time after initializing mode setting. |
| 1174 | </para> |
| 1175 | <sect2> |
| 1176 | <title>CRTCs (struct <structname>drm_crtc</structname>)</title> |
| 1177 | <para> |
| 1178 | A CRTC is an abstraction representing a part of the chip that contains a |
| 1179 | pointer to a scanout buffer. Therefore, the number of CRTCs available |
| 1180 | determines how many independent scanout buffers can be active at any |
| 1181 | given time. The CRTC structure contains several fields to support this: |
| 1182 | a pointer to some video memory (abstracted as a frame buffer object), a |
| 1183 | display mode, and an (x, y) offset into the video memory to support |
| 1184 | panning or configurations where one piece of video memory spans multiple |
| 1185 | CRTCs. |
| 1186 | </para> |
| 1187 | <sect3> |
| 1188 | <title>CRTC Initialization</title> |
| 1189 | <para> |
| 1190 | A KMS device must create and register at least one struct |
| 1191 | <structname>drm_crtc</structname> instance. The instance is allocated |
| 1192 | and zeroed by the driver, possibly as part of a larger structure, and |
| 1193 | registered with a call to <function>drm_crtc_init</function> with a |
| 1194 | pointer to CRTC functions. |
| 1195 | </para> |
| 1196 | </sect3> |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 1197 | <sect3 id="drm-kms-crtcops"> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1198 | <title>CRTC Operations</title> |
| 1199 | <sect4> |
| 1200 | <title>Set Configuration</title> |
| 1201 | <synopsis>int (*set_config)(struct drm_mode_set *set);</synopsis> |
| 1202 | <para> |
| 1203 | Apply a new CRTC configuration to the device. The configuration |
| 1204 | specifies a CRTC, a frame buffer to scan out from, a (x,y) position in |
| 1205 | the frame buffer, a display mode and an array of connectors to drive |
| 1206 | with the CRTC if possible. |
| 1207 | </para> |
| 1208 | <para> |
| 1209 | If the frame buffer specified in the configuration is NULL, the driver |
| 1210 | must detach all encoders connected to the CRTC and all connectors |
| 1211 | attached to those encoders and disable them. |
| 1212 | </para> |
| 1213 | <para> |
| 1214 | This operation is called with the mode config lock held. |
| 1215 | </para> |
| 1216 | <note><para> |
Daniel Vetter | aa4cd91 | 2014-01-22 16:42:02 +0100 | [diff] [blame] | 1217 | Note that the drm core has no notion of restoring the mode setting |
| 1218 | state after resume, since all resume handling is in the full |
| 1219 | responsibility of the driver. The common mode setting helper library |
| 1220 | though provides a helper which can be used for this: |
| 1221 | <function>drm_helper_resume_force_mode</function>. |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1222 | </para></note> |
| 1223 | </sect4> |
| 1224 | <sect4> |
| 1225 | <title>Page Flipping</title> |
| 1226 | <synopsis>int (*page_flip)(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 1227 | struct drm_pending_vblank_event *event);</synopsis> |
| 1228 | <para> |
| 1229 | Schedule a page flip to the given frame buffer for the CRTC. This |
| 1230 | operation is called with the mode config mutex held. |
| 1231 | </para> |
| 1232 | <para> |
| 1233 | Page flipping is a synchronization mechanism that replaces the frame |
| 1234 | buffer being scanned out by the CRTC with a new frame buffer during |
| 1235 | vertical blanking, avoiding tearing. When an application requests a page |
| 1236 | flip the DRM core verifies that the new frame buffer is large enough to |
| 1237 | be scanned out by the CRTC in the currently configured mode and then |
| 1238 | calls the CRTC <methodname>page_flip</methodname> operation with a |
| 1239 | pointer to the new frame buffer. |
| 1240 | </para> |
| 1241 | <para> |
| 1242 | The <methodname>page_flip</methodname> operation schedules a page flip. |
Anatol Pomozov | f884ab1 | 2013-05-08 16:56:16 -0700 | [diff] [blame] | 1243 | Once any pending rendering targeting the new frame buffer has |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1244 | completed, the CRTC will be reprogrammed to display that frame buffer |
| 1245 | after the next vertical refresh. The operation must return immediately |
| 1246 | without waiting for rendering or page flip to complete and must block |
| 1247 | any new rendering to the frame buffer until the page flip completes. |
| 1248 | </para> |
| 1249 | <para> |
Thierry Reding | 8cf1e98 | 2013-02-13 16:08:33 +0100 | [diff] [blame] | 1250 | If a page flip can be successfully scheduled the driver must set the |
| 1251 | <code>drm_crtc-<fb</code> field to the new framebuffer pointed to |
| 1252 | by <code>fb</code>. This is important so that the reference counting |
| 1253 | on framebuffers stays balanced. |
| 1254 | </para> |
| 1255 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1256 | If a page flip is already pending, the |
| 1257 | <methodname>page_flip</methodname> operation must return |
| 1258 | -<errorname>EBUSY</errorname>. |
| 1259 | </para> |
| 1260 | <para> |
| 1261 | To synchronize page flip to vertical blanking the driver will likely |
| 1262 | need to enable vertical blanking interrupts. It should call |
| 1263 | <function>drm_vblank_get</function> for that purpose, and call |
| 1264 | <function>drm_vblank_put</function> after the page flip completes. |
| 1265 | </para> |
| 1266 | <para> |
| 1267 | If the application has requested to be notified when page flip completes |
| 1268 | the <methodname>page_flip</methodname> operation will be called with a |
| 1269 | non-NULL <parameter>event</parameter> argument pointing to a |
| 1270 | <structname>drm_pending_vblank_event</structname> instance. Upon page |
Rob Clark | c6eefa1 | 2012-10-16 22:48:40 +0000 | [diff] [blame] | 1271 | flip completion the driver must call <methodname>drm_send_vblank_event</methodname> |
| 1272 | to fill in the event and send to wake up any waiting processes. |
| 1273 | This can be performed with |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1274 | <programlisting><![CDATA[ |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1275 | spin_lock_irqsave(&dev->event_lock, flags); |
Rob Clark | c6eefa1 | 2012-10-16 22:48:40 +0000 | [diff] [blame] | 1276 | ... |
| 1277 | drm_send_vblank_event(dev, pipe, event); |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1278 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1279 | ]]></programlisting> |
| 1280 | </para> |
| 1281 | <note><para> |
| 1282 | FIXME: Could drivers that don't need to wait for rendering to complete |
| 1283 | just add the event to <literal>dev->vblank_event_list</literal> and |
| 1284 | let the DRM core handle everything, as for "normal" vertical blanking |
| 1285 | events? |
| 1286 | </para></note> |
| 1287 | <para> |
| 1288 | While waiting for the page flip to complete, the |
| 1289 | <literal>event->base.link</literal> list head can be used freely by |
| 1290 | the driver to store the pending event in a driver-specific list. |
| 1291 | </para> |
| 1292 | <para> |
| 1293 | If the file handle is closed before the event is signaled, drivers must |
| 1294 | take care to destroy the event in their |
| 1295 | <methodname>preclose</methodname> operation (and, if needed, call |
| 1296 | <function>drm_vblank_put</function>). |
| 1297 | </para> |
| 1298 | </sect4> |
| 1299 | <sect4> |
| 1300 | <title>Miscellaneous</title> |
| 1301 | <itemizedlist> |
| 1302 | <listitem> |
Laurent Pinchart | 421cda3 | 2013-06-22 16:10:30 +0200 | [diff] [blame] | 1303 | <synopsis>void (*set_property)(struct drm_crtc *crtc, |
| 1304 | struct drm_property *property, uint64_t value);</synopsis> |
| 1305 | <para> |
| 1306 | Set the value of the given CRTC property to |
| 1307 | <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/> |
| 1308 | for more information about properties. |
| 1309 | </para> |
| 1310 | </listitem> |
| 1311 | <listitem> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1312 | <synopsis>void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
| 1313 | uint32_t start, uint32_t size);</synopsis> |
| 1314 | <para> |
| 1315 | Apply a gamma table to the device. The operation is optional. |
| 1316 | </para> |
| 1317 | </listitem> |
| 1318 | <listitem> |
| 1319 | <synopsis>void (*destroy)(struct drm_crtc *crtc);</synopsis> |
| 1320 | <para> |
| 1321 | Destroy the CRTC when not needed anymore. See |
| 1322 | <xref linkend="drm-kms-init"/>. |
| 1323 | </para> |
| 1324 | </listitem> |
| 1325 | </itemizedlist> |
| 1326 | </sect4> |
| 1327 | </sect3> |
| 1328 | </sect2> |
| 1329 | <sect2> |
| 1330 | <title>Planes (struct <structname>drm_plane</structname>)</title> |
| 1331 | <para> |
| 1332 | A plane represents an image source that can be blended with or overlayed |
| 1333 | on top of a CRTC during the scanout process. Planes are associated with |
| 1334 | a frame buffer to crop a portion of the image memory (source) and |
| 1335 | optionally scale it to a destination size. The result is then blended |
| 1336 | with or overlayed on top of a CRTC. |
| 1337 | </para> |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 1338 | <para> |
| 1339 | The DRM core recognizes three types of planes: |
| 1340 | <itemizedlist> |
| 1341 | <listitem> |
| 1342 | DRM_PLANE_TYPE_PRIMARY represents a "main" plane for a CRTC. Primary |
| 1343 | planes are the planes operated upon by by CRTC modesetting and flipping |
| 1344 | operations described in <xref linkend="drm-kms-crtcops"/>. |
| 1345 | </listitem> |
| 1346 | <listitem> |
| 1347 | DRM_PLANE_TYPE_CURSOR represents a "cursor" plane for a CRTC. Cursor |
| 1348 | planes are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and |
| 1349 | DRM_IOCTL_MODE_CURSOR2 ioctls. |
| 1350 | </listitem> |
| 1351 | <listitem> |
| 1352 | DRM_PLANE_TYPE_OVERLAY represents all non-primary, non-cursor planes. |
| 1353 | Some drivers refer to these types of planes as "sprites" internally. |
| 1354 | </listitem> |
| 1355 | </itemizedlist> |
| 1356 | For compatibility with legacy userspace, only overlay planes are made |
| 1357 | available to userspace by default. Userspace clients may set the |
| 1358 | DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that |
| 1359 | they wish to receive a universal plane list containing all plane types. |
| 1360 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1361 | <sect3> |
| 1362 | <title>Plane Initialization</title> |
| 1363 | <para> |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 1364 | To create a plane, a KMS drivers allocates and |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1365 | zeroes an instances of struct <structname>drm_plane</structname> |
| 1366 | (possibly as part of a larger structure) and registers it with a call |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 1367 | to <function>drm_universal_plane_init</function>. The function takes a bitmask |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1368 | of the CRTCs that can be associated with the plane, a pointer to the |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 1369 | plane functions, a list of format supported formats, and the type of |
| 1370 | plane (primary, cursor, or overlay) being initialized. |
| 1371 | </para> |
| 1372 | <para> |
| 1373 | Cursor and overlay planes are optional. All drivers should provide |
| 1374 | one primary plane per CRTC (although this requirement may change in |
| 1375 | the future); drivers that do not wish to provide special handling for |
| 1376 | primary planes may make use of the helper functions described in |
| 1377 | <xref linkend="drm-kms-planehelpers"/> to create and register a |
| 1378 | primary plane with standard capabilities. |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1379 | </para> |
| 1380 | </sect3> |
| 1381 | <sect3> |
| 1382 | <title>Plane Operations</title> |
| 1383 | <itemizedlist> |
| 1384 | <listitem> |
| 1385 | <synopsis>int (*update_plane)(struct drm_plane *plane, struct drm_crtc *crtc, |
| 1386 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 1387 | unsigned int crtc_w, unsigned int crtc_h, |
| 1388 | uint32_t src_x, uint32_t src_y, |
| 1389 | uint32_t src_w, uint32_t src_h);</synopsis> |
| 1390 | <para> |
| 1391 | Enable and configure the plane to use the given CRTC and frame buffer. |
| 1392 | </para> |
| 1393 | <para> |
| 1394 | The source rectangle in frame buffer memory coordinates is given by |
| 1395 | the <parameter>src_x</parameter>, <parameter>src_y</parameter>, |
| 1396 | <parameter>src_w</parameter> and <parameter>src_h</parameter> |
| 1397 | parameters (as 16.16 fixed point values). Devices that don't support |
| 1398 | subpixel plane coordinates can ignore the fractional part. |
| 1399 | </para> |
| 1400 | <para> |
| 1401 | The destination rectangle in CRTC coordinates is given by the |
| 1402 | <parameter>crtc_x</parameter>, <parameter>crtc_y</parameter>, |
| 1403 | <parameter>crtc_w</parameter> and <parameter>crtc_h</parameter> |
| 1404 | parameters (as integer values). Devices scale the source rectangle to |
| 1405 | the destination rectangle. If scaling is not supported, and the source |
| 1406 | rectangle size doesn't match the destination rectangle size, the |
| 1407 | driver must return a -<errorname>EINVAL</errorname> error. |
| 1408 | </para> |
| 1409 | </listitem> |
| 1410 | <listitem> |
| 1411 | <synopsis>int (*disable_plane)(struct drm_plane *plane);</synopsis> |
| 1412 | <para> |
| 1413 | Disable the plane. The DRM core calls this method in response to a |
| 1414 | DRM_IOCTL_MODE_SETPLANE ioctl call with the frame buffer ID set to 0. |
| 1415 | Disabled planes must not be processed by the CRTC. |
| 1416 | </para> |
| 1417 | </listitem> |
| 1418 | <listitem> |
| 1419 | <synopsis>void (*destroy)(struct drm_plane *plane);</synopsis> |
| 1420 | <para> |
| 1421 | Destroy the plane when not needed anymore. See |
| 1422 | <xref linkend="drm-kms-init"/>. |
| 1423 | </para> |
| 1424 | </listitem> |
| 1425 | </itemizedlist> |
| 1426 | </sect3> |
| 1427 | </sect2> |
| 1428 | <sect2> |
| 1429 | <title>Encoders (struct <structname>drm_encoder</structname>)</title> |
| 1430 | <para> |
| 1431 | An encoder takes pixel data from a CRTC and converts it to a format |
| 1432 | suitable for any attached connectors. On some devices, it may be |
| 1433 | possible to have a CRTC send data to more than one encoder. In that |
| 1434 | case, both encoders would receive data from the same scanout buffer, |
| 1435 | resulting in a "cloned" display configuration across the connectors |
| 1436 | attached to each encoder. |
| 1437 | </para> |
| 1438 | <sect3> |
| 1439 | <title>Encoder Initialization</title> |
| 1440 | <para> |
| 1441 | As for CRTCs, a KMS driver must create, initialize and register at |
| 1442 | least one struct <structname>drm_encoder</structname> instance. The |
| 1443 | instance is allocated and zeroed by the driver, possibly as part of a |
| 1444 | larger structure. |
| 1445 | </para> |
| 1446 | <para> |
| 1447 | Drivers must initialize the struct <structname>drm_encoder</structname> |
| 1448 | <structfield>possible_crtcs</structfield> and |
| 1449 | <structfield>possible_clones</structfield> fields before registering the |
| 1450 | encoder. Both fields are bitmasks of respectively the CRTCs that the |
| 1451 | encoder can be connected to, and sibling encoders candidate for cloning. |
| 1452 | </para> |
| 1453 | <para> |
| 1454 | After being initialized, the encoder must be registered with a call to |
| 1455 | <function>drm_encoder_init</function>. The function takes a pointer to |
| 1456 | the encoder functions and an encoder type. Supported types are |
| 1457 | <itemizedlist> |
| 1458 | <listitem> |
| 1459 | DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A |
| 1460 | </listitem> |
| 1461 | <listitem> |
| 1462 | DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort |
| 1463 | </listitem> |
| 1464 | <listitem> |
| 1465 | DRM_MODE_ENCODER_LVDS for display panels |
| 1466 | </listitem> |
| 1467 | <listitem> |
| 1468 | DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video, Component, |
| 1469 | SCART) |
| 1470 | </listitem> |
| 1471 | <listitem> |
| 1472 | DRM_MODE_ENCODER_VIRTUAL for virtual machine displays |
| 1473 | </listitem> |
| 1474 | </itemizedlist> |
| 1475 | </para> |
| 1476 | <para> |
| 1477 | Encoders must be attached to a CRTC to be used. DRM drivers leave |
| 1478 | encoders unattached at initialization time. Applications (or the fbdev |
| 1479 | compatibility layer when implemented) are responsible for attaching the |
| 1480 | encoders they want to use to a CRTC. |
| 1481 | </para> |
| 1482 | </sect3> |
| 1483 | <sect3> |
| 1484 | <title>Encoder Operations</title> |
| 1485 | <itemizedlist> |
| 1486 | <listitem> |
| 1487 | <synopsis>void (*destroy)(struct drm_encoder *encoder);</synopsis> |
| 1488 | <para> |
| 1489 | Called to destroy the encoder when not needed anymore. See |
| 1490 | <xref linkend="drm-kms-init"/>. |
| 1491 | </para> |
| 1492 | </listitem> |
Laurent Pinchart | 421cda3 | 2013-06-22 16:10:30 +0200 | [diff] [blame] | 1493 | <listitem> |
| 1494 | <synopsis>void (*set_property)(struct drm_plane *plane, |
| 1495 | struct drm_property *property, uint64_t value);</synopsis> |
| 1496 | <para> |
| 1497 | Set the value of the given plane property to |
| 1498 | <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/> |
| 1499 | for more information about properties. |
| 1500 | </para> |
| 1501 | </listitem> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1502 | </itemizedlist> |
| 1503 | </sect3> |
| 1504 | </sect2> |
| 1505 | <sect2> |
| 1506 | <title>Connectors (struct <structname>drm_connector</structname>)</title> |
| 1507 | <para> |
| 1508 | A connector is the final destination for pixel data on a device, and |
| 1509 | usually connects directly to an external display device like a monitor |
| 1510 | or laptop panel. A connector can only be attached to one encoder at a |
| 1511 | time. The connector is also the structure where information about the |
| 1512 | attached display is kept, so it contains fields for display data, EDID |
| 1513 | data, DPMS & connection status, and information about modes |
| 1514 | supported on the attached displays. |
| 1515 | </para> |
| 1516 | <sect3> |
| 1517 | <title>Connector Initialization</title> |
| 1518 | <para> |
| 1519 | Finally a KMS driver must create, initialize, register and attach at |
| 1520 | least one struct <structname>drm_connector</structname> instance. The |
| 1521 | instance is created as other KMS objects and initialized by setting the |
| 1522 | following fields. |
| 1523 | </para> |
| 1524 | <variablelist> |
| 1525 | <varlistentry> |
| 1526 | <term><structfield>interlace_allowed</structfield></term> |
| 1527 | <listitem><para> |
| 1528 | Whether the connector can handle interlaced modes. |
| 1529 | </para></listitem> |
| 1530 | </varlistentry> |
| 1531 | <varlistentry> |
| 1532 | <term><structfield>doublescan_allowed</structfield></term> |
| 1533 | <listitem><para> |
| 1534 | Whether the connector can handle doublescan. |
| 1535 | </para></listitem> |
| 1536 | </varlistentry> |
| 1537 | <varlistentry> |
| 1538 | <term><structfield>display_info |
| 1539 | </structfield></term> |
| 1540 | <listitem><para> |
| 1541 | Display information is filled from EDID information when a display |
| 1542 | is detected. For non hot-pluggable displays such as flat panels in |
| 1543 | embedded systems, the driver should initialize the |
| 1544 | <structfield>display_info</structfield>.<structfield>width_mm</structfield> |
| 1545 | and |
| 1546 | <structfield>display_info</structfield>.<structfield>height_mm</structfield> |
| 1547 | fields with the physical size of the display. |
| 1548 | </para></listitem> |
| 1549 | </varlistentry> |
| 1550 | <varlistentry> |
| 1551 | <term id="drm-kms-connector-polled"><structfield>polled</structfield></term> |
| 1552 | <listitem><para> |
| 1553 | Connector polling mode, a combination of |
| 1554 | <variablelist> |
| 1555 | <varlistentry> |
| 1556 | <term>DRM_CONNECTOR_POLL_HPD</term> |
| 1557 | <listitem><para> |
| 1558 | The connector generates hotplug events and doesn't need to be |
| 1559 | periodically polled. The CONNECT and DISCONNECT flags must not |
| 1560 | be set together with the HPD flag. |
| 1561 | </para></listitem> |
| 1562 | </varlistentry> |
| 1563 | <varlistentry> |
| 1564 | <term>DRM_CONNECTOR_POLL_CONNECT</term> |
| 1565 | <listitem><para> |
| 1566 | Periodically poll the connector for connection. |
| 1567 | </para></listitem> |
| 1568 | </varlistentry> |
| 1569 | <varlistentry> |
| 1570 | <term>DRM_CONNECTOR_POLL_DISCONNECT</term> |
| 1571 | <listitem><para> |
| 1572 | Periodically poll the connector for disconnection. |
| 1573 | </para></listitem> |
| 1574 | </varlistentry> |
| 1575 | </variablelist> |
| 1576 | Set to 0 for connectors that don't support connection status |
| 1577 | discovery. |
| 1578 | </para></listitem> |
| 1579 | </varlistentry> |
| 1580 | </variablelist> |
| 1581 | <para> |
| 1582 | The connector is then registered with a call to |
| 1583 | <function>drm_connector_init</function> with a pointer to the connector |
| 1584 | functions and a connector type, and exposed through sysfs with a call to |
| 1585 | <function>drm_sysfs_connector_add</function>. |
| 1586 | </para> |
| 1587 | <para> |
| 1588 | Supported connector types are |
| 1589 | <itemizedlist> |
| 1590 | <listitem>DRM_MODE_CONNECTOR_VGA</listitem> |
| 1591 | <listitem>DRM_MODE_CONNECTOR_DVII</listitem> |
| 1592 | <listitem>DRM_MODE_CONNECTOR_DVID</listitem> |
| 1593 | <listitem>DRM_MODE_CONNECTOR_DVIA</listitem> |
| 1594 | <listitem>DRM_MODE_CONNECTOR_Composite</listitem> |
| 1595 | <listitem>DRM_MODE_CONNECTOR_SVIDEO</listitem> |
| 1596 | <listitem>DRM_MODE_CONNECTOR_LVDS</listitem> |
| 1597 | <listitem>DRM_MODE_CONNECTOR_Component</listitem> |
| 1598 | <listitem>DRM_MODE_CONNECTOR_9PinDIN</listitem> |
| 1599 | <listitem>DRM_MODE_CONNECTOR_DisplayPort</listitem> |
| 1600 | <listitem>DRM_MODE_CONNECTOR_HDMIA</listitem> |
| 1601 | <listitem>DRM_MODE_CONNECTOR_HDMIB</listitem> |
| 1602 | <listitem>DRM_MODE_CONNECTOR_TV</listitem> |
| 1603 | <listitem>DRM_MODE_CONNECTOR_eDP</listitem> |
| 1604 | <listitem>DRM_MODE_CONNECTOR_VIRTUAL</listitem> |
| 1605 | </itemizedlist> |
| 1606 | </para> |
| 1607 | <para> |
| 1608 | Connectors must be attached to an encoder to be used. For devices that |
| 1609 | map connectors to encoders 1:1, the connector should be attached at |
| 1610 | initialization time with a call to |
| 1611 | <function>drm_mode_connector_attach_encoder</function>. The driver must |
| 1612 | also set the <structname>drm_connector</structname> |
| 1613 | <structfield>encoder</structfield> field to point to the attached |
| 1614 | encoder. |
| 1615 | </para> |
| 1616 | <para> |
| 1617 | Finally, drivers must initialize the connectors state change detection |
| 1618 | with a call to <function>drm_kms_helper_poll_init</function>. If at |
| 1619 | least one connector is pollable but can't generate hotplug interrupts |
| 1620 | (indicated by the DRM_CONNECTOR_POLL_CONNECT and |
| 1621 | DRM_CONNECTOR_POLL_DISCONNECT connector flags), a delayed work will |
| 1622 | automatically be queued to periodically poll for changes. Connectors |
| 1623 | that can generate hotplug interrupts must be marked with the |
| 1624 | DRM_CONNECTOR_POLL_HPD flag instead, and their interrupt handler must |
| 1625 | call <function>drm_helper_hpd_irq_event</function>. The function will |
| 1626 | queue a delayed work to check the state of all connectors, but no |
| 1627 | periodic polling will be done. |
| 1628 | </para> |
| 1629 | </sect3> |
| 1630 | <sect3> |
| 1631 | <title>Connector Operations</title> |
| 1632 | <note><para> |
| 1633 | Unless otherwise state, all operations are mandatory. |
| 1634 | </para></note> |
| 1635 | <sect4> |
| 1636 | <title>DPMS</title> |
| 1637 | <synopsis>void (*dpms)(struct drm_connector *connector, int mode);</synopsis> |
| 1638 | <para> |
| 1639 | The DPMS operation sets the power state of a connector. The mode |
| 1640 | argument is one of |
| 1641 | <itemizedlist> |
| 1642 | <listitem><para>DRM_MODE_DPMS_ON</para></listitem> |
| 1643 | <listitem><para>DRM_MODE_DPMS_STANDBY</para></listitem> |
| 1644 | <listitem><para>DRM_MODE_DPMS_SUSPEND</para></listitem> |
| 1645 | <listitem><para>DRM_MODE_DPMS_OFF</para></listitem> |
| 1646 | </itemizedlist> |
| 1647 | </para> |
| 1648 | <para> |
| 1649 | In all but DPMS_ON mode the encoder to which the connector is attached |
| 1650 | should put the display in low-power mode by driving its signals |
| 1651 | appropriately. If more than one connector is attached to the encoder |
| 1652 | care should be taken not to change the power state of other displays as |
| 1653 | a side effect. Low-power mode should be propagated to the encoders and |
| 1654 | CRTCs when all related connectors are put in low-power mode. |
| 1655 | </para> |
| 1656 | </sect4> |
| 1657 | <sect4> |
| 1658 | <title>Modes</title> |
| 1659 | <synopsis>int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, |
| 1660 | uint32_t max_height);</synopsis> |
| 1661 | <para> |
| 1662 | Fill the mode list with all supported modes for the connector. If the |
| 1663 | <parameter>max_width</parameter> and <parameter>max_height</parameter> |
| 1664 | arguments are non-zero, the implementation must ignore all modes wider |
| 1665 | than <parameter>max_width</parameter> or higher than |
| 1666 | <parameter>max_height</parameter>. |
| 1667 | </para> |
| 1668 | <para> |
| 1669 | The connector must also fill in this operation its |
| 1670 | <structfield>display_info</structfield> |
| 1671 | <structfield>width_mm</structfield> and |
| 1672 | <structfield>height_mm</structfield> fields with the connected display |
| 1673 | physical size in millimeters. The fields should be set to 0 if the value |
| 1674 | isn't known or is not applicable (for instance for projector devices). |
| 1675 | </para> |
| 1676 | </sect4> |
| 1677 | <sect4> |
| 1678 | <title>Connection Status</title> |
| 1679 | <para> |
| 1680 | The connection status is updated through polling or hotplug events when |
| 1681 | supported (see <xref linkend="drm-kms-connector-polled"/>). The status |
| 1682 | value is reported to userspace through ioctls and must not be used |
| 1683 | inside the driver, as it only gets initialized by a call to |
| 1684 | <function>drm_mode_getconnector</function> from userspace. |
| 1685 | </para> |
| 1686 | <synopsis>enum drm_connector_status (*detect)(struct drm_connector *connector, |
| 1687 | bool force);</synopsis> |
| 1688 | <para> |
| 1689 | Check to see if anything is attached to the connector. The |
| 1690 | <parameter>force</parameter> parameter is set to false whilst polling or |
| 1691 | to true when checking the connector due to user request. |
| 1692 | <parameter>force</parameter> can be used by the driver to avoid |
| 1693 | expensive, destructive operations during automated probing. |
| 1694 | </para> |
| 1695 | <para> |
| 1696 | Return connector_status_connected if something is connected to the |
| 1697 | connector, connector_status_disconnected if nothing is connected and |
| 1698 | connector_status_unknown if the connection state isn't known. |
| 1699 | </para> |
| 1700 | <para> |
| 1701 | Drivers should only return connector_status_connected if the connection |
| 1702 | status has really been probed as connected. Connectors that can't detect |
| 1703 | the connection status, or failed connection status probes, should return |
| 1704 | connector_status_unknown. |
| 1705 | </para> |
| 1706 | </sect4> |
| 1707 | <sect4> |
| 1708 | <title>Miscellaneous</title> |
| 1709 | <itemizedlist> |
| 1710 | <listitem> |
Laurent Pinchart | 421cda3 | 2013-06-22 16:10:30 +0200 | [diff] [blame] | 1711 | <synopsis>void (*set_property)(struct drm_connector *connector, |
| 1712 | struct drm_property *property, uint64_t value);</synopsis> |
| 1713 | <para> |
| 1714 | Set the value of the given connector property to |
| 1715 | <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/> |
| 1716 | for more information about properties. |
| 1717 | </para> |
| 1718 | </listitem> |
| 1719 | <listitem> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1720 | <synopsis>void (*destroy)(struct drm_connector *connector);</synopsis> |
| 1721 | <para> |
| 1722 | Destroy the connector when not needed anymore. See |
| 1723 | <xref linkend="drm-kms-init"/>. |
| 1724 | </para> |
| 1725 | </listitem> |
| 1726 | </itemizedlist> |
| 1727 | </sect4> |
| 1728 | </sect3> |
| 1729 | </sect2> |
| 1730 | <sect2> |
| 1731 | <title>Cleanup</title> |
| 1732 | <para> |
| 1733 | The DRM core manages its objects' lifetime. When an object is not needed |
| 1734 | anymore the core calls its destroy function, which must clean up and |
| 1735 | free every resource allocated for the object. Every |
| 1736 | <function>drm_*_init</function> call must be matched with a |
| 1737 | corresponding <function>drm_*_cleanup</function> call to cleanup CRTCs |
| 1738 | (<function>drm_crtc_cleanup</function>), planes |
| 1739 | (<function>drm_plane_cleanup</function>), encoders |
| 1740 | (<function>drm_encoder_cleanup</function>) and connectors |
| 1741 | (<function>drm_connector_cleanup</function>). Furthermore, connectors |
| 1742 | that have been added to sysfs must be removed by a call to |
| 1743 | <function>drm_sysfs_connector_remove</function> before calling |
| 1744 | <function>drm_connector_cleanup</function>. |
| 1745 | </para> |
| 1746 | <para> |
| 1747 | Connectors state change detection must be cleanup up with a call to |
| 1748 | <function>drm_kms_helper_poll_fini</function>. |
| 1749 | </para> |
| 1750 | </sect2> |
| 1751 | <sect2> |
| 1752 | <title>Output discovery and initialization example</title> |
| 1753 | <programlisting><![CDATA[ |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 1754 | void intel_crt_init(struct drm_device *dev) |
| 1755 | { |
| 1756 | struct drm_connector *connector; |
| 1757 | struct intel_output *intel_output; |
| 1758 | |
| 1759 | intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL); |
| 1760 | if (!intel_output) |
| 1761 | return; |
| 1762 | |
| 1763 | connector = &intel_output->base; |
| 1764 | drm_connector_init(dev, &intel_output->base, |
| 1765 | &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA); |
| 1766 | |
| 1767 | drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs, |
| 1768 | DRM_MODE_ENCODER_DAC); |
| 1769 | |
| 1770 | drm_mode_connector_attach_encoder(&intel_output->base, |
| 1771 | &intel_output->enc); |
| 1772 | |
| 1773 | /* Set up the DDC bus. */ |
| 1774 | intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A"); |
| 1775 | if (!intel_output->ddc_bus) { |
| 1776 | dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration " |
| 1777 | "failed.\n"); |
| 1778 | return; |
| 1779 | } |
| 1780 | |
| 1781 | intel_output->type = INTEL_OUTPUT_ANALOG; |
| 1782 | connector->interlace_allowed = 0; |
| 1783 | connector->doublescan_allowed = 0; |
| 1784 | |
| 1785 | drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs); |
| 1786 | drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); |
| 1787 | |
| 1788 | drm_sysfs_connector_add(connector); |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1789 | }]]></programlisting> |
| 1790 | <para> |
| 1791 | In the example above (taken from the i915 driver), a CRTC, connector and |
| 1792 | encoder combination is created. A device-specific i2c bus is also |
| 1793 | created for fetching EDID data and performing monitor detection. Once |
| 1794 | the process is complete, the new connector is registered with sysfs to |
| 1795 | make its properties available to applications. |
| 1796 | </para> |
| 1797 | </sect2> |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1798 | <sect2> |
| 1799 | <title>KMS API Functions</title> |
| 1800 | !Edrivers/gpu/drm/drm_crtc.c |
| 1801 | </sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1802 | </sect1> |
| 1803 | |
Daniel Vetter | e4949f2 | 2012-11-01 14:45:15 +0100 | [diff] [blame] | 1804 | <!-- Internals: kms helper functions --> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1805 | |
| 1806 | <sect1> |
Daniel Vetter | e4949f2 | 2012-11-01 14:45:15 +0100 | [diff] [blame] | 1807 | <title>Mode Setting Helper Functions</title> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1808 | <para> |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 1809 | The plane, CRTC, encoder and connector functions provided by the drivers |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1810 | implement the DRM API. They're called by the DRM core and ioctl handlers |
| 1811 | to handle device state changes and configuration request. As implementing |
| 1812 | those functions often requires logic not specific to drivers, mid-layer |
| 1813 | helper functions are available to avoid duplicating boilerplate code. |
| 1814 | </para> |
| 1815 | <para> |
| 1816 | The DRM core contains one mid-layer implementation. The mid-layer provides |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 1817 | implementations of several plane, CRTC, encoder and connector functions |
| 1818 | (called from the top of the mid-layer) that pre-process requests and call |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1819 | lower-level functions provided by the driver (at the bottom of the |
| 1820 | mid-layer). For instance, the |
| 1821 | <function>drm_crtc_helper_set_config</function> function can be used to |
| 1822 | fill the struct <structname>drm_crtc_funcs</structname> |
| 1823 | <structfield>set_config</structfield> field. When called, it will split |
| 1824 | the <methodname>set_config</methodname> operation in smaller, simpler |
| 1825 | operations and call the driver to handle them. |
| 1826 | </para> |
| 1827 | <para> |
| 1828 | To use the mid-layer, drivers call <function>drm_crtc_helper_add</function>, |
| 1829 | <function>drm_encoder_helper_add</function> and |
| 1830 | <function>drm_connector_helper_add</function> functions to install their |
| 1831 | mid-layer bottom operations handlers, and fill the |
| 1832 | <structname>drm_crtc_funcs</structname>, |
| 1833 | <structname>drm_encoder_funcs</structname> and |
| 1834 | <structname>drm_connector_funcs</structname> structures with pointers to |
| 1835 | the mid-layer top API functions. Installing the mid-layer bottom operation |
| 1836 | handlers is best done right after registering the corresponding KMS object. |
| 1837 | </para> |
| 1838 | <para> |
| 1839 | The mid-layer is not split between CRTC, encoder and connector operations. |
| 1840 | To use it, a driver must provide bottom functions for all of the three KMS |
| 1841 | entities. |
| 1842 | </para> |
| 1843 | <sect2> |
| 1844 | <title>Helper Functions</title> |
| 1845 | <itemizedlist> |
| 1846 | <listitem> |
| 1847 | <synopsis>int drm_crtc_helper_set_config(struct drm_mode_set *set);</synopsis> |
| 1848 | <para> |
| 1849 | The <function>drm_crtc_helper_set_config</function> helper function |
| 1850 | is a CRTC <methodname>set_config</methodname> implementation. It |
| 1851 | first tries to locate the best encoder for each connector by calling |
| 1852 | the connector <methodname>best_encoder</methodname> helper |
| 1853 | operation. |
| 1854 | </para> |
| 1855 | <para> |
| 1856 | After locating the appropriate encoders, the helper function will |
| 1857 | call the <methodname>mode_fixup</methodname> encoder and CRTC helper |
| 1858 | operations to adjust the requested mode, or reject it completely in |
| 1859 | which case an error will be returned to the application. If the new |
| 1860 | configuration after mode adjustment is identical to the current |
| 1861 | configuration the helper function will return without performing any |
| 1862 | other operation. |
| 1863 | </para> |
| 1864 | <para> |
| 1865 | If the adjusted mode is identical to the current mode but changes to |
| 1866 | the frame buffer need to be applied, the |
| 1867 | <function>drm_crtc_helper_set_config</function> function will call |
| 1868 | the CRTC <methodname>mode_set_base</methodname> helper operation. If |
| 1869 | the adjusted mode differs from the current mode, or if the |
| 1870 | <methodname>mode_set_base</methodname> helper operation is not |
| 1871 | provided, the helper function performs a full mode set sequence by |
| 1872 | calling the <methodname>prepare</methodname>, |
| 1873 | <methodname>mode_set</methodname> and |
| 1874 | <methodname>commit</methodname> CRTC and encoder helper operations, |
| 1875 | in that order. |
| 1876 | </para> |
| 1877 | </listitem> |
| 1878 | <listitem> |
| 1879 | <synopsis>void drm_helper_connector_dpms(struct drm_connector *connector, int mode);</synopsis> |
| 1880 | <para> |
| 1881 | The <function>drm_helper_connector_dpms</function> helper function |
| 1882 | is a connector <methodname>dpms</methodname> implementation that |
| 1883 | tracks power state of connectors. To use the function, drivers must |
| 1884 | provide <methodname>dpms</methodname> helper operations for CRTCs |
| 1885 | and encoders to apply the DPMS state to the device. |
| 1886 | </para> |
| 1887 | <para> |
| 1888 | The mid-layer doesn't track the power state of CRTCs and encoders. |
| 1889 | The <methodname>dpms</methodname> helper operations can thus be |
| 1890 | called with a mode identical to the currently active mode. |
| 1891 | </para> |
| 1892 | </listitem> |
| 1893 | <listitem> |
| 1894 | <synopsis>int drm_helper_probe_single_connector_modes(struct drm_connector *connector, |
| 1895 | uint32_t maxX, uint32_t maxY);</synopsis> |
| 1896 | <para> |
| 1897 | The <function>drm_helper_probe_single_connector_modes</function> helper |
| 1898 | function is a connector <methodname>fill_modes</methodname> |
| 1899 | implementation that updates the connection status for the connector |
| 1900 | and then retrieves a list of modes by calling the connector |
| 1901 | <methodname>get_modes</methodname> helper operation. |
| 1902 | </para> |
| 1903 | <para> |
| 1904 | The function filters out modes larger than |
| 1905 | <parameter>max_width</parameter> and <parameter>max_height</parameter> |
| 1906 | if specified. It then calls the connector |
| 1907 | <methodname>mode_valid</methodname> helper operation for each mode in |
| 1908 | the probed list to check whether the mode is valid for the connector. |
| 1909 | </para> |
| 1910 | </listitem> |
| 1911 | </itemizedlist> |
| 1912 | </sect2> |
| 1913 | <sect2> |
| 1914 | <title>CRTC Helper Operations</title> |
| 1915 | <itemizedlist> |
| 1916 | <listitem id="drm-helper-crtc-mode-fixup"> |
| 1917 | <synopsis>bool (*mode_fixup)(struct drm_crtc *crtc, |
| 1918 | const struct drm_display_mode *mode, |
| 1919 | struct drm_display_mode *adjusted_mode);</synopsis> |
| 1920 | <para> |
| 1921 | Let CRTCs adjust the requested mode or reject it completely. This |
| 1922 | operation returns true if the mode is accepted (possibly after being |
| 1923 | adjusted) or false if it is rejected. |
| 1924 | </para> |
| 1925 | <para> |
| 1926 | The <methodname>mode_fixup</methodname> operation should reject the |
| 1927 | mode if it can't reasonably use it. The definition of "reasonable" |
| 1928 | is currently fuzzy in this context. One possible behaviour would be |
| 1929 | to set the adjusted mode to the panel timings when a fixed-mode |
| 1930 | panel is used with hardware capable of scaling. Another behaviour |
| 1931 | would be to accept any input mode and adjust it to the closest mode |
| 1932 | supported by the hardware (FIXME: This needs to be clarified). |
| 1933 | </para> |
| 1934 | </listitem> |
| 1935 | <listitem> |
| 1936 | <synopsis>int (*mode_set_base)(struct drm_crtc *crtc, int x, int y, |
| 1937 | struct drm_framebuffer *old_fb)</synopsis> |
| 1938 | <para> |
| 1939 | Move the CRTC on the current frame buffer (stored in |
| 1940 | <literal>crtc->fb</literal>) to position (x,y). Any of the frame |
| 1941 | buffer, x position or y position may have been modified. |
| 1942 | </para> |
| 1943 | <para> |
| 1944 | This helper operation is optional. If not provided, the |
| 1945 | <function>drm_crtc_helper_set_config</function> function will fall |
| 1946 | back to the <methodname>mode_set</methodname> helper operation. |
| 1947 | </para> |
| 1948 | <note><para> |
| 1949 | FIXME: Why are x and y passed as arguments, as they can be accessed |
| 1950 | through <literal>crtc->x</literal> and |
| 1951 | <literal>crtc->y</literal>? |
| 1952 | </para></note> |
| 1953 | </listitem> |
| 1954 | <listitem> |
| 1955 | <synopsis>void (*prepare)(struct drm_crtc *crtc);</synopsis> |
| 1956 | <para> |
| 1957 | Prepare the CRTC for mode setting. This operation is called after |
| 1958 | validating the requested mode. Drivers use it to perform |
| 1959 | device-specific operations required before setting the new mode. |
| 1960 | </para> |
| 1961 | </listitem> |
| 1962 | <listitem> |
| 1963 | <synopsis>int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 1964 | struct drm_display_mode *adjusted_mode, int x, int y, |
| 1965 | struct drm_framebuffer *old_fb);</synopsis> |
| 1966 | <para> |
| 1967 | Set a new mode, position and frame buffer. Depending on the device |
| 1968 | requirements, the mode can be stored internally by the driver and |
| 1969 | applied in the <methodname>commit</methodname> operation, or |
| 1970 | programmed to the hardware immediately. |
| 1971 | </para> |
| 1972 | <para> |
| 1973 | The <methodname>mode_set</methodname> operation returns 0 on success |
| 1974 | or a negative error code if an error occurs. |
| 1975 | </para> |
| 1976 | </listitem> |
| 1977 | <listitem> |
| 1978 | <synopsis>void (*commit)(struct drm_crtc *crtc);</synopsis> |
| 1979 | <para> |
| 1980 | Commit a mode. This operation is called after setting the new mode. |
| 1981 | Upon return the device must use the new mode and be fully |
| 1982 | operational. |
| 1983 | </para> |
| 1984 | </listitem> |
| 1985 | </itemizedlist> |
| 1986 | </sect2> |
| 1987 | <sect2> |
| 1988 | <title>Encoder Helper Operations</title> |
| 1989 | <itemizedlist> |
| 1990 | <listitem> |
| 1991 | <synopsis>bool (*mode_fixup)(struct drm_encoder *encoder, |
| 1992 | const struct drm_display_mode *mode, |
| 1993 | struct drm_display_mode *adjusted_mode);</synopsis> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 1994 | <para> |
| 1995 | Let encoders adjust the requested mode or reject it completely. This |
| 1996 | operation returns true if the mode is accepted (possibly after being |
| 1997 | adjusted) or false if it is rejected. See the |
| 1998 | <link linkend="drm-helper-crtc-mode-fixup">mode_fixup CRTC helper |
| 1999 | operation</link> for an explanation of the allowed adjustments. |
| 2000 | </para> |
| 2001 | </listitem> |
| 2002 | <listitem> |
| 2003 | <synopsis>void (*prepare)(struct drm_encoder *encoder);</synopsis> |
| 2004 | <para> |
| 2005 | Prepare the encoder for mode setting. This operation is called after |
| 2006 | validating the requested mode. Drivers use it to perform |
| 2007 | device-specific operations required before setting the new mode. |
| 2008 | </para> |
| 2009 | </listitem> |
| 2010 | <listitem> |
| 2011 | <synopsis>void (*mode_set)(struct drm_encoder *encoder, |
| 2012 | struct drm_display_mode *mode, |
| 2013 | struct drm_display_mode *adjusted_mode);</synopsis> |
| 2014 | <para> |
| 2015 | Set a new mode. Depending on the device requirements, the mode can |
| 2016 | be stored internally by the driver and applied in the |
| 2017 | <methodname>commit</methodname> operation, or programmed to the |
| 2018 | hardware immediately. |
| 2019 | </para> |
| 2020 | </listitem> |
| 2021 | <listitem> |
| 2022 | <synopsis>void (*commit)(struct drm_encoder *encoder);</synopsis> |
| 2023 | <para> |
| 2024 | Commit a mode. This operation is called after setting the new mode. |
| 2025 | Upon return the device must use the new mode and be fully |
| 2026 | operational. |
| 2027 | </para> |
| 2028 | </listitem> |
| 2029 | </itemizedlist> |
| 2030 | </sect2> |
| 2031 | <sect2> |
| 2032 | <title>Connector Helper Operations</title> |
| 2033 | <itemizedlist> |
| 2034 | <listitem> |
| 2035 | <synopsis>struct drm_encoder *(*best_encoder)(struct drm_connector *connector);</synopsis> |
| 2036 | <para> |
| 2037 | Return a pointer to the best encoder for the connecter. Device that |
| 2038 | map connectors to encoders 1:1 simply return the pointer to the |
| 2039 | associated encoder. This operation is mandatory. |
| 2040 | </para> |
| 2041 | </listitem> |
| 2042 | <listitem> |
| 2043 | <synopsis>int (*get_modes)(struct drm_connector *connector);</synopsis> |
| 2044 | <para> |
| 2045 | Fill the connector's <structfield>probed_modes</structfield> list |
| 2046 | by parsing EDID data with <function>drm_add_edid_modes</function> or |
| 2047 | calling <function>drm_mode_probed_add</function> directly for every |
| 2048 | supported mode and return the number of modes it has detected. This |
| 2049 | operation is mandatory. |
| 2050 | </para> |
| 2051 | <para> |
| 2052 | When adding modes manually the driver creates each mode with a call to |
| 2053 | <function>drm_mode_create</function> and must fill the following fields. |
| 2054 | <itemizedlist> |
| 2055 | <listitem> |
| 2056 | <synopsis>__u32 type;</synopsis> |
| 2057 | <para> |
| 2058 | Mode type bitmask, a combination of |
| 2059 | <variablelist> |
| 2060 | <varlistentry> |
| 2061 | <term>DRM_MODE_TYPE_BUILTIN</term> |
| 2062 | <listitem><para>not used?</para></listitem> |
| 2063 | </varlistentry> |
| 2064 | <varlistentry> |
| 2065 | <term>DRM_MODE_TYPE_CLOCK_C</term> |
| 2066 | <listitem><para>not used?</para></listitem> |
| 2067 | </varlistentry> |
| 2068 | <varlistentry> |
| 2069 | <term>DRM_MODE_TYPE_CRTC_C</term> |
| 2070 | <listitem><para>not used?</para></listitem> |
| 2071 | </varlistentry> |
| 2072 | <varlistentry> |
| 2073 | <term> |
| 2074 | DRM_MODE_TYPE_PREFERRED - The preferred mode for the connector |
| 2075 | </term> |
| 2076 | <listitem> |
| 2077 | <para>not used?</para> |
| 2078 | </listitem> |
| 2079 | </varlistentry> |
| 2080 | <varlistentry> |
| 2081 | <term>DRM_MODE_TYPE_DEFAULT</term> |
| 2082 | <listitem><para>not used?</para></listitem> |
| 2083 | </varlistentry> |
| 2084 | <varlistentry> |
| 2085 | <term>DRM_MODE_TYPE_USERDEF</term> |
| 2086 | <listitem><para>not used?</para></listitem> |
| 2087 | </varlistentry> |
| 2088 | <varlistentry> |
| 2089 | <term>DRM_MODE_TYPE_DRIVER</term> |
| 2090 | <listitem> |
| 2091 | <para> |
| 2092 | The mode has been created by the driver (as opposed to |
| 2093 | to user-created modes). |
| 2094 | </para> |
| 2095 | </listitem> |
| 2096 | </varlistentry> |
| 2097 | </variablelist> |
| 2098 | Drivers must set the DRM_MODE_TYPE_DRIVER bit for all modes they |
| 2099 | create, and set the DRM_MODE_TYPE_PREFERRED bit for the preferred |
| 2100 | mode. |
| 2101 | </para> |
| 2102 | </listitem> |
| 2103 | <listitem> |
| 2104 | <synopsis>__u32 clock;</synopsis> |
| 2105 | <para>Pixel clock frequency in kHz unit</para> |
| 2106 | </listitem> |
| 2107 | <listitem> |
| 2108 | <synopsis>__u16 hdisplay, hsync_start, hsync_end, htotal; |
| 2109 | __u16 vdisplay, vsync_start, vsync_end, vtotal;</synopsis> |
| 2110 | <para>Horizontal and vertical timing information</para> |
| 2111 | <screen><![CDATA[ |
| 2112 | Active Front Sync Back |
| 2113 | Region Porch Porch |
| 2114 | <-----------------------><----------------><-------------><--------------> |
| 2115 | |
| 2116 | //////////////////////| |
| 2117 | ////////////////////// | |
| 2118 | ////////////////////// |.................. ................ |
| 2119 | _______________ |
| 2120 | |
| 2121 | <----- [hv]display -----> |
| 2122 | <------------- [hv]sync_start ------------> |
| 2123 | <--------------------- [hv]sync_end ---------------------> |
| 2124 | <-------------------------------- [hv]total -----------------------------> |
| 2125 | ]]></screen> |
| 2126 | </listitem> |
| 2127 | <listitem> |
| 2128 | <synopsis>__u16 hskew; |
| 2129 | __u16 vscan;</synopsis> |
| 2130 | <para>Unknown</para> |
| 2131 | </listitem> |
| 2132 | <listitem> |
| 2133 | <synopsis>__u32 flags;</synopsis> |
| 2134 | <para> |
| 2135 | Mode flags, a combination of |
| 2136 | <variablelist> |
| 2137 | <varlistentry> |
| 2138 | <term>DRM_MODE_FLAG_PHSYNC</term> |
| 2139 | <listitem><para> |
| 2140 | Horizontal sync is active high |
| 2141 | </para></listitem> |
| 2142 | </varlistentry> |
| 2143 | <varlistentry> |
| 2144 | <term>DRM_MODE_FLAG_NHSYNC</term> |
| 2145 | <listitem><para> |
| 2146 | Horizontal sync is active low |
| 2147 | </para></listitem> |
| 2148 | </varlistentry> |
| 2149 | <varlistentry> |
| 2150 | <term>DRM_MODE_FLAG_PVSYNC</term> |
| 2151 | <listitem><para> |
| 2152 | Vertical sync is active high |
| 2153 | </para></listitem> |
| 2154 | </varlistentry> |
| 2155 | <varlistentry> |
| 2156 | <term>DRM_MODE_FLAG_NVSYNC</term> |
| 2157 | <listitem><para> |
| 2158 | Vertical sync is active low |
| 2159 | </para></listitem> |
| 2160 | </varlistentry> |
| 2161 | <varlistentry> |
| 2162 | <term>DRM_MODE_FLAG_INTERLACE</term> |
| 2163 | <listitem><para> |
| 2164 | Mode is interlaced |
| 2165 | </para></listitem> |
| 2166 | </varlistentry> |
| 2167 | <varlistentry> |
| 2168 | <term>DRM_MODE_FLAG_DBLSCAN</term> |
| 2169 | <listitem><para> |
| 2170 | Mode uses doublescan |
| 2171 | </para></listitem> |
| 2172 | </varlistentry> |
| 2173 | <varlistentry> |
| 2174 | <term>DRM_MODE_FLAG_CSYNC</term> |
| 2175 | <listitem><para> |
| 2176 | Mode uses composite sync |
| 2177 | </para></listitem> |
| 2178 | </varlistentry> |
| 2179 | <varlistentry> |
| 2180 | <term>DRM_MODE_FLAG_PCSYNC</term> |
| 2181 | <listitem><para> |
| 2182 | Composite sync is active high |
| 2183 | </para></listitem> |
| 2184 | </varlistentry> |
| 2185 | <varlistentry> |
| 2186 | <term>DRM_MODE_FLAG_NCSYNC</term> |
| 2187 | <listitem><para> |
| 2188 | Composite sync is active low |
| 2189 | </para></listitem> |
| 2190 | </varlistentry> |
| 2191 | <varlistentry> |
| 2192 | <term>DRM_MODE_FLAG_HSKEW</term> |
| 2193 | <listitem><para> |
| 2194 | hskew provided (not used?) |
| 2195 | </para></listitem> |
| 2196 | </varlistentry> |
| 2197 | <varlistentry> |
| 2198 | <term>DRM_MODE_FLAG_BCAST</term> |
| 2199 | <listitem><para> |
| 2200 | not used? |
| 2201 | </para></listitem> |
| 2202 | </varlistentry> |
| 2203 | <varlistentry> |
| 2204 | <term>DRM_MODE_FLAG_PIXMUX</term> |
| 2205 | <listitem><para> |
| 2206 | not used? |
| 2207 | </para></listitem> |
| 2208 | </varlistentry> |
| 2209 | <varlistentry> |
| 2210 | <term>DRM_MODE_FLAG_DBLCLK</term> |
| 2211 | <listitem><para> |
| 2212 | not used? |
| 2213 | </para></listitem> |
| 2214 | </varlistentry> |
| 2215 | <varlistentry> |
| 2216 | <term>DRM_MODE_FLAG_CLKDIV2</term> |
| 2217 | <listitem><para> |
| 2218 | ? |
| 2219 | </para></listitem> |
| 2220 | </varlistentry> |
| 2221 | </variablelist> |
| 2222 | </para> |
| 2223 | <para> |
| 2224 | Note that modes marked with the INTERLACE or DBLSCAN flags will be |
| 2225 | filtered out by |
| 2226 | <function>drm_helper_probe_single_connector_modes</function> if |
| 2227 | the connector's <structfield>interlace_allowed</structfield> or |
| 2228 | <structfield>doublescan_allowed</structfield> field is set to 0. |
| 2229 | </para> |
| 2230 | </listitem> |
| 2231 | <listitem> |
| 2232 | <synopsis>char name[DRM_DISPLAY_MODE_LEN];</synopsis> |
| 2233 | <para> |
| 2234 | Mode name. The driver must call |
| 2235 | <function>drm_mode_set_name</function> to fill the mode name from |
| 2236 | <structfield>hdisplay</structfield>, |
| 2237 | <structfield>vdisplay</structfield> and interlace flag after |
| 2238 | filling the corresponding fields. |
| 2239 | </para> |
| 2240 | </listitem> |
| 2241 | </itemizedlist> |
| 2242 | </para> |
| 2243 | <para> |
| 2244 | The <structfield>vrefresh</structfield> value is computed by |
| 2245 | <function>drm_helper_probe_single_connector_modes</function>. |
| 2246 | </para> |
| 2247 | <para> |
| 2248 | When parsing EDID data, <function>drm_add_edid_modes</function> fill the |
| 2249 | connector <structfield>display_info</structfield> |
| 2250 | <structfield>width_mm</structfield> and |
| 2251 | <structfield>height_mm</structfield> fields. When creating modes |
| 2252 | manually the <methodname>get_modes</methodname> helper operation must |
| 2253 | set the <structfield>display_info</structfield> |
| 2254 | <structfield>width_mm</structfield> and |
| 2255 | <structfield>height_mm</structfield> fields if they haven't been set |
Daniel Vetter | 065a502 | 2014-01-21 12:01:41 +0100 | [diff] [blame] | 2256 | already (for instance at initialization time when a fixed-size panel is |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2257 | attached to the connector). The mode <structfield>width_mm</structfield> |
| 2258 | and <structfield>height_mm</structfield> fields are only used internally |
| 2259 | during EDID parsing and should not be set when creating modes manually. |
| 2260 | </para> |
| 2261 | </listitem> |
| 2262 | <listitem> |
| 2263 | <synopsis>int (*mode_valid)(struct drm_connector *connector, |
| 2264 | struct drm_display_mode *mode);</synopsis> |
| 2265 | <para> |
| 2266 | Verify whether a mode is valid for the connector. Return MODE_OK for |
| 2267 | supported modes and one of the enum drm_mode_status values (MODE_*) |
| 2268 | for unsupported modes. This operation is mandatory. |
| 2269 | </para> |
| 2270 | <para> |
| 2271 | As the mode rejection reason is currently not used beside for |
| 2272 | immediately removing the unsupported mode, an implementation can |
| 2273 | return MODE_BAD regardless of the exact reason why the mode is not |
| 2274 | valid. |
| 2275 | </para> |
| 2276 | <note><para> |
| 2277 | Note that the <methodname>mode_valid</methodname> helper operation is |
| 2278 | only called for modes detected by the device, and |
| 2279 | <emphasis>not</emphasis> for modes set by the user through the CRTC |
| 2280 | <methodname>set_config</methodname> operation. |
| 2281 | </para></note> |
| 2282 | </listitem> |
| 2283 | </itemizedlist> |
| 2284 | </sect2> |
Daniel Vetter | 0d4ed4c | 2012-11-01 14:45:16 +0100 | [diff] [blame] | 2285 | <sect2> |
| 2286 | <title>Modeset Helper Functions Reference</title> |
| 2287 | !Edrivers/gpu/drm/drm_crtc_helper.c |
| 2288 | </sect2> |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 2289 | <sect2> |
Daniel Vetter | 8d75454 | 2014-04-10 10:51:11 +0200 | [diff] [blame] | 2290 | <title>Output Probing Helper Functions Reference</title> |
| 2291 | !Pdrivers/gpu/drm/drm_probe_helper.c output probing helper overview |
| 2292 | !Edrivers/gpu/drm/drm_probe_helper.c |
| 2293 | </sect2> |
| 2294 | <sect2> |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 2295 | <title>fbdev Helper Functions Reference</title> |
| 2296 | !Pdrivers/gpu/drm/drm_fb_helper.c fbdev helpers |
| 2297 | !Edrivers/gpu/drm/drm_fb_helper.c |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 2298 | !Iinclude/drm/drm_fb_helper.h |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 2299 | </sect2> |
Daniel Vetter | 28164fd | 2012-11-01 14:45:18 +0100 | [diff] [blame] | 2300 | <sect2> |
| 2301 | <title>Display Port Helper Functions Reference</title> |
| 2302 | !Pdrivers/gpu/drm/drm_dp_helper.c dp helpers |
| 2303 | !Iinclude/drm/drm_dp_helper.h |
| 2304 | !Edrivers/gpu/drm/drm_dp_helper.c |
| 2305 | </sect2> |
Thierry Reding | 5e30859 | 2013-01-14 09:00:31 +0100 | [diff] [blame] | 2306 | <sect2> |
| 2307 | <title>EDID Helper Functions Reference</title> |
| 2308 | !Edrivers/gpu/drm/drm_edid.c |
| 2309 | </sect2> |
Ville Syrjälä | 0397353 | 2013-05-08 17:16:45 +0300 | [diff] [blame] | 2310 | <sect2> |
| 2311 | <title>Rectangle Utilities Reference</title> |
| 2312 | !Pinclude/drm/drm_rect.h rect utils |
| 2313 | !Iinclude/drm/drm_rect.h |
| 2314 | !Edrivers/gpu/drm/drm_rect.c |
| 2315 | </sect2> |
David Herrmann | fe3078f | 2013-07-24 21:06:15 +0200 | [diff] [blame] | 2316 | <sect2> |
Rob Clark | cabaafc | 2013-08-07 14:41:54 -0400 | [diff] [blame] | 2317 | <title>Flip-work Helper Reference</title> |
| 2318 | !Pinclude/drm/drm_flip_work.h flip utils |
| 2319 | !Iinclude/drm/drm_flip_work.h |
| 2320 | !Edrivers/gpu/drm/drm_flip_work.c |
| 2321 | </sect2> |
Daniel Vetter | 2d123f4 | 2014-01-22 18:26:16 +0100 | [diff] [blame] | 2322 | <sect2> |
| 2323 | <title>HDMI Infoframes Helper Reference</title> |
| 2324 | <para> |
| 2325 | Strictly speaking this is not a DRM helper library but generally useable |
| 2326 | by any driver interfacing with HDMI outputs like v4l or alsa drivers. |
| 2327 | But it nicely fits into the overall topic of mode setting helper |
| 2328 | libraries and hence is also included here. |
| 2329 | </para> |
| 2330 | !Iinclude/linux/hdmi.h |
| 2331 | !Edrivers/video/hdmi.c |
| 2332 | </sect2> |
Matt Roper | 6efa1f2 | 2014-04-01 15:22:43 -0700 | [diff] [blame] | 2333 | <sect2> |
| 2334 | <title id="drm-kms-planehelpers">Plane Helper Reference</title> |
| 2335 | !Edrivers/gpu/drm/drm_plane_helper.c Plane Helpers |
| 2336 | </sect2> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2337 | </sect1> |
| 2338 | |
Laurent Pinchart | 421cda3 | 2013-06-22 16:10:30 +0200 | [diff] [blame] | 2339 | <!-- Internals: kms properties --> |
| 2340 | |
| 2341 | <sect1 id="drm-kms-properties"> |
| 2342 | <title>KMS Properties</title> |
| 2343 | <para> |
| 2344 | Drivers may need to expose additional parameters to applications than |
| 2345 | those described in the previous sections. KMS supports attaching |
| 2346 | properties to CRTCs, connectors and planes and offers a userspace API to |
| 2347 | list, get and set the property values. |
| 2348 | </para> |
| 2349 | <para> |
| 2350 | Properties are identified by a name that uniquely defines the property |
| 2351 | purpose, and store an associated value. For all property types except blob |
| 2352 | properties the value is a 64-bit unsigned integer. |
| 2353 | </para> |
| 2354 | <para> |
| 2355 | KMS differentiates between properties and property instances. Drivers |
| 2356 | first create properties and then create and associate individual instances |
| 2357 | of those properties to objects. A property can be instantiated multiple |
| 2358 | times and associated with different objects. Values are stored in property |
| 2359 | instances, and all other property information are stored in the propery |
| 2360 | and shared between all instances of the property. |
| 2361 | </para> |
| 2362 | <para> |
| 2363 | Every property is created with a type that influences how the KMS core |
| 2364 | handles the property. Supported property types are |
| 2365 | <variablelist> |
| 2366 | <varlistentry> |
| 2367 | <term>DRM_MODE_PROP_RANGE</term> |
| 2368 | <listitem><para>Range properties report their minimum and maximum |
| 2369 | admissible values. The KMS core verifies that values set by |
| 2370 | application fit in that range.</para></listitem> |
| 2371 | </varlistentry> |
| 2372 | <varlistentry> |
| 2373 | <term>DRM_MODE_PROP_ENUM</term> |
| 2374 | <listitem><para>Enumerated properties take a numerical value that |
| 2375 | ranges from 0 to the number of enumerated values defined by the |
| 2376 | property minus one, and associate a free-formed string name to each |
| 2377 | value. Applications can retrieve the list of defined value-name pairs |
| 2378 | and use the numerical value to get and set property instance values. |
| 2379 | </para></listitem> |
| 2380 | </varlistentry> |
| 2381 | <varlistentry> |
| 2382 | <term>DRM_MODE_PROP_BITMASK</term> |
| 2383 | <listitem><para>Bitmask properties are enumeration properties that |
| 2384 | additionally restrict all enumerated values to the 0..63 range. |
| 2385 | Bitmask property instance values combine one or more of the |
| 2386 | enumerated bits defined by the property.</para></listitem> |
| 2387 | </varlistentry> |
| 2388 | <varlistentry> |
| 2389 | <term>DRM_MODE_PROP_BLOB</term> |
| 2390 | <listitem><para>Blob properties store a binary blob without any format |
| 2391 | restriction. The binary blobs are created as KMS standalone objects, |
| 2392 | and blob property instance values store the ID of their associated |
| 2393 | blob object.</para> |
| 2394 | <para>Blob properties are only used for the connector EDID property |
| 2395 | and cannot be created by drivers.</para></listitem> |
| 2396 | </varlistentry> |
| 2397 | </variablelist> |
| 2398 | </para> |
| 2399 | <para> |
| 2400 | To create a property drivers call one of the following functions depending |
| 2401 | on the property type. All property creation functions take property flags |
| 2402 | and name, as well as type-specific arguments. |
| 2403 | <itemizedlist> |
| 2404 | <listitem> |
| 2405 | <synopsis>struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
| 2406 | const char *name, |
| 2407 | uint64_t min, uint64_t max);</synopsis> |
| 2408 | <para>Create a range property with the given minimum and maximum |
| 2409 | values.</para> |
| 2410 | </listitem> |
| 2411 | <listitem> |
| 2412 | <synopsis>struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
| 2413 | const char *name, |
| 2414 | const struct drm_prop_enum_list *props, |
| 2415 | int num_values);</synopsis> |
| 2416 | <para>Create an enumerated property. The <parameter>props</parameter> |
| 2417 | argument points to an array of <parameter>num_values</parameter> |
| 2418 | value-name pairs.</para> |
| 2419 | </listitem> |
| 2420 | <listitem> |
| 2421 | <synopsis>struct drm_property *drm_property_create_bitmask(struct drm_device *dev, |
| 2422 | int flags, const char *name, |
| 2423 | const struct drm_prop_enum_list *props, |
| 2424 | int num_values);</synopsis> |
| 2425 | <para>Create a bitmask property. The <parameter>props</parameter> |
| 2426 | argument points to an array of <parameter>num_values</parameter> |
| 2427 | value-name pairs.</para> |
| 2428 | </listitem> |
| 2429 | </itemizedlist> |
| 2430 | </para> |
| 2431 | <para> |
| 2432 | Properties can additionally be created as immutable, in which case they |
| 2433 | will be read-only for applications but can be modified by the driver. To |
| 2434 | create an immutable property drivers must set the DRM_MODE_PROP_IMMUTABLE |
| 2435 | flag at property creation time. |
| 2436 | </para> |
| 2437 | <para> |
| 2438 | When no array of value-name pairs is readily available at property |
| 2439 | creation time for enumerated or range properties, drivers can create |
| 2440 | the property using the <function>drm_property_create</function> function |
| 2441 | and manually add enumeration value-name pairs by calling the |
| 2442 | <function>drm_property_add_enum</function> function. Care must be taken to |
| 2443 | properly specify the property type through the <parameter>flags</parameter> |
| 2444 | argument. |
| 2445 | </para> |
| 2446 | <para> |
| 2447 | After creating properties drivers can attach property instances to CRTC, |
| 2448 | connector and plane objects by calling the |
| 2449 | <function>drm_object_attach_property</function>. The function takes a |
| 2450 | pointer to the target object, a pointer to the previously created property |
| 2451 | and an initial instance value. |
| 2452 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2453 | </sect1> |
| 2454 | |
| 2455 | <!-- Internals: vertical blanking --> |
| 2456 | |
| 2457 | <sect1 id="drm-vertical-blank"> |
| 2458 | <title>Vertical Blanking</title> |
| 2459 | <para> |
| 2460 | Vertical blanking plays a major role in graphics rendering. To achieve |
| 2461 | tear-free display, users must synchronize page flips and/or rendering to |
| 2462 | vertical blanking. The DRM API offers ioctls to perform page flips |
| 2463 | synchronized to vertical blanking and wait for vertical blanking. |
| 2464 | </para> |
| 2465 | <para> |
| 2466 | The DRM core handles most of the vertical blanking management logic, which |
| 2467 | involves filtering out spurious interrupts, keeping race-free blanking |
| 2468 | counters, coping with counter wrap-around and resets and keeping use |
| 2469 | counts. It relies on the driver to generate vertical blanking interrupts |
| 2470 | and optionally provide a hardware vertical blanking counter. Drivers must |
| 2471 | implement the following operations. |
| 2472 | </para> |
| 2473 | <itemizedlist> |
| 2474 | <listitem> |
| 2475 | <synopsis>int (*enable_vblank) (struct drm_device *dev, int crtc); |
| 2476 | void (*disable_vblank) (struct drm_device *dev, int crtc);</synopsis> |
| 2477 | <para> |
| 2478 | Enable or disable vertical blanking interrupts for the given CRTC. |
| 2479 | </para> |
| 2480 | </listitem> |
| 2481 | <listitem> |
| 2482 | <synopsis>u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);</synopsis> |
| 2483 | <para> |
| 2484 | Retrieve the value of the vertical blanking counter for the given |
| 2485 | CRTC. If the hardware maintains a vertical blanking counter its value |
| 2486 | should be returned. Otherwise drivers can use the |
| 2487 | <function>drm_vblank_count</function> helper function to handle this |
| 2488 | operation. |
| 2489 | </para> |
| 2490 | </listitem> |
| 2491 | </itemizedlist> |
| 2492 | <para> |
| 2493 | Drivers must initialize the vertical blanking handling core with a call to |
| 2494 | <function>drm_vblank_init</function> in their |
| 2495 | <methodname>load</methodname> operation. The function will set the struct |
| 2496 | <structname>drm_device</structname> |
| 2497 | <structfield>vblank_disable_allowed</structfield> field to 0. This will |
| 2498 | keep vertical blanking interrupts enabled permanently until the first mode |
| 2499 | set operation, where <structfield>vblank_disable_allowed</structfield> is |
| 2500 | set to 1. The reason behind this is not clear. Drivers can set the field |
| 2501 | to 1 after <function>calling drm_vblank_init</function> to make vertical |
| 2502 | blanking interrupts dynamically managed from the beginning. |
| 2503 | </para> |
| 2504 | <para> |
| 2505 | Vertical blanking interrupts can be enabled by the DRM core or by drivers |
| 2506 | themselves (for instance to handle page flipping operations). The DRM core |
| 2507 | maintains a vertical blanking use count to ensure that the interrupts are |
| 2508 | not disabled while a user still needs them. To increment the use count, |
| 2509 | drivers call <function>drm_vblank_get</function>. Upon return vertical |
| 2510 | blanking interrupts are guaranteed to be enabled. |
| 2511 | </para> |
| 2512 | <para> |
| 2513 | To decrement the use count drivers call |
| 2514 | <function>drm_vblank_put</function>. Only when the use count drops to zero |
| 2515 | will the DRM core disable the vertical blanking interrupts after a delay |
| 2516 | by scheduling a timer. The delay is accessible through the vblankoffdelay |
| 2517 | module parameter or the <varname>drm_vblank_offdelay</varname> global |
| 2518 | variable and expressed in milliseconds. Its default value is 5000 ms. |
| 2519 | </para> |
| 2520 | <para> |
| 2521 | When a vertical blanking interrupt occurs drivers only need to call the |
| 2522 | <function>drm_handle_vblank</function> function to account for the |
| 2523 | interrupt. |
| 2524 | </para> |
| 2525 | <para> |
| 2526 | Resources allocated by <function>drm_vblank_init</function> must be freed |
| 2527 | with a call to <function>drm_vblank_cleanup</function> in the driver |
| 2528 | <methodname>unload</methodname> operation handler. |
| 2529 | </para> |
| 2530 | </sect1> |
| 2531 | |
| 2532 | <!-- Internals: open/close, file operations and ioctls --> |
| 2533 | |
| 2534 | <sect1> |
| 2535 | <title>Open/Close, File Operations and IOCTLs</title> |
| 2536 | <sect2> |
| 2537 | <title>Open and Close</title> |
| 2538 | <synopsis>int (*firstopen) (struct drm_device *); |
| 2539 | void (*lastclose) (struct drm_device *); |
| 2540 | int (*open) (struct drm_device *, struct drm_file *); |
| 2541 | void (*preclose) (struct drm_device *, struct drm_file *); |
| 2542 | void (*postclose) (struct drm_device *, struct drm_file *);</synopsis> |
| 2543 | <abstract>Open and close handlers. None of those methods are mandatory. |
| 2544 | </abstract> |
| 2545 | <para> |
| 2546 | The <methodname>firstopen</methodname> method is called by the DRM core |
Daniel Vetter | 7d14bb6b | 2013-08-08 15:41:15 +0200 | [diff] [blame] | 2547 | for legacy UMS (User Mode Setting) drivers only when an application |
| 2548 | opens a device that has no other opened file handle. UMS drivers can |
| 2549 | implement it to acquire device resources. KMS drivers can't use the |
| 2550 | method and must acquire resources in the <methodname>load</methodname> |
| 2551 | method instead. |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2552 | </para> |
| 2553 | <para> |
Daniel Vetter | 7d14bb6b | 2013-08-08 15:41:15 +0200 | [diff] [blame] | 2554 | Similarly the <methodname>lastclose</methodname> method is called when |
| 2555 | the last application holding a file handle opened on the device closes |
| 2556 | it, for both UMS and KMS drivers. Additionally, the method is also |
| 2557 | called at module unload time or, for hot-pluggable devices, when the |
| 2558 | device is unplugged. The <methodname>firstopen</methodname> and |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2559 | <methodname>lastclose</methodname> calls can thus be unbalanced. |
| 2560 | </para> |
| 2561 | <para> |
| 2562 | The <methodname>open</methodname> method is called every time the device |
| 2563 | is opened by an application. Drivers can allocate per-file private data |
| 2564 | in this method and store them in the struct |
| 2565 | <structname>drm_file</structname> <structfield>driver_priv</structfield> |
| 2566 | field. Note that the <methodname>open</methodname> method is called |
| 2567 | before <methodname>firstopen</methodname>. |
| 2568 | </para> |
| 2569 | <para> |
| 2570 | The close operation is split into <methodname>preclose</methodname> and |
| 2571 | <methodname>postclose</methodname> methods. Drivers must stop and |
| 2572 | cleanup all per-file operations in the <methodname>preclose</methodname> |
| 2573 | method. For instance pending vertical blanking and page flip events must |
| 2574 | be cancelled. No per-file operation is allowed on the file handle after |
| 2575 | returning from the <methodname>preclose</methodname> method. |
| 2576 | </para> |
| 2577 | <para> |
| 2578 | Finally the <methodname>postclose</methodname> method is called as the |
| 2579 | last step of the close operation, right before calling the |
| 2580 | <methodname>lastclose</methodname> method if no other open file handle |
| 2581 | exists for the device. Drivers that have allocated per-file private data |
| 2582 | in the <methodname>open</methodname> method should free it here. |
| 2583 | </para> |
| 2584 | <para> |
| 2585 | The <methodname>lastclose</methodname> method should restore CRTC and |
| 2586 | plane properties to default value, so that a subsequent open of the |
Daniel Vetter | 7d14bb6b | 2013-08-08 15:41:15 +0200 | [diff] [blame] | 2587 | device will not inherit state from the previous user. It can also be |
| 2588 | used to execute delayed power switching state changes, e.g. in |
| 2589 | conjunction with the vga-switcheroo infrastructure. Beyond that KMS |
| 2590 | drivers should not do any further cleanup. Only legacy UMS drivers might |
| 2591 | need to clean up device state so that the vga console or an independent |
| 2592 | fbdev driver could take over. |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2593 | </para> |
| 2594 | </sect2> |
| 2595 | <sect2> |
| 2596 | <title>File Operations</title> |
| 2597 | <synopsis>const struct file_operations *fops</synopsis> |
| 2598 | <abstract>File operations for the DRM device node.</abstract> |
| 2599 | <para> |
| 2600 | Drivers must define the file operations structure that forms the DRM |
| 2601 | userspace API entry point, even though most of those operations are |
| 2602 | implemented in the DRM core. The <methodname>open</methodname>, |
| 2603 | <methodname>release</methodname> and <methodname>ioctl</methodname> |
| 2604 | operations are handled by |
| 2605 | <programlisting> |
| 2606 | .owner = THIS_MODULE, |
| 2607 | .open = drm_open, |
| 2608 | .release = drm_release, |
| 2609 | .unlocked_ioctl = drm_ioctl, |
| 2610 | #ifdef CONFIG_COMPAT |
| 2611 | .compat_ioctl = drm_compat_ioctl, |
| 2612 | #endif |
| 2613 | </programlisting> |
| 2614 | </para> |
| 2615 | <para> |
| 2616 | Drivers that implement private ioctls that requires 32/64bit |
| 2617 | compatibility support must provide their own |
| 2618 | <methodname>compat_ioctl</methodname> handler that processes private |
| 2619 | ioctls and calls <function>drm_compat_ioctl</function> for core ioctls. |
| 2620 | </para> |
| 2621 | <para> |
| 2622 | The <methodname>read</methodname> and <methodname>poll</methodname> |
| 2623 | operations provide support for reading DRM events and polling them. They |
| 2624 | are implemented by |
| 2625 | <programlisting> |
| 2626 | .poll = drm_poll, |
| 2627 | .read = drm_read, |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2628 | .llseek = no_llseek, |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2629 | </programlisting> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2630 | </para> |
| 2631 | <para> |
| 2632 | The memory mapping implementation varies depending on how the driver |
| 2633 | manages memory. Pre-GEM drivers will use <function>drm_mmap</function>, |
| 2634 | while GEM-aware drivers will use <function>drm_gem_mmap</function>. See |
| 2635 | <xref linkend="drm-gem"/>. |
| 2636 | <programlisting> |
| 2637 | .mmap = drm_gem_mmap, |
| 2638 | </programlisting> |
| 2639 | </para> |
| 2640 | <para> |
| 2641 | No other file operation is supported by the DRM API. |
| 2642 | </para> |
| 2643 | </sect2> |
| 2644 | <sect2> |
| 2645 | <title>IOCTLs</title> |
| 2646 | <synopsis>struct drm_ioctl_desc *ioctls; |
| 2647 | int num_ioctls;</synopsis> |
| 2648 | <abstract>Driver-specific ioctls descriptors table.</abstract> |
| 2649 | <para> |
| 2650 | Driver-specific ioctls numbers start at DRM_COMMAND_BASE. The ioctls |
| 2651 | descriptors table is indexed by the ioctl number offset from the base |
| 2652 | value. Drivers can use the DRM_IOCTL_DEF_DRV() macro to initialize the |
| 2653 | table entries. |
| 2654 | </para> |
| 2655 | <para> |
| 2656 | <programlisting>DRM_IOCTL_DEF_DRV(ioctl, func, flags)</programlisting> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2657 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2658 | <parameter>ioctl</parameter> is the ioctl name. Drivers must define |
| 2659 | the DRM_##ioctl and DRM_IOCTL_##ioctl macros to the ioctl number |
| 2660 | offset from DRM_COMMAND_BASE and the ioctl number respectively. The |
| 2661 | first macro is private to the device while the second must be exposed |
| 2662 | to userspace in a public header. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2663 | </para> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2664 | <para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2665 | <parameter>func</parameter> is a pointer to the ioctl handler function |
| 2666 | compatible with the <type>drm_ioctl_t</type> type. |
| 2667 | <programlisting>typedef int drm_ioctl_t(struct drm_device *dev, void *data, |
| 2668 | struct drm_file *file_priv);</programlisting> |
| 2669 | </para> |
| 2670 | <para> |
| 2671 | <parameter>flags</parameter> is a bitmask combination of the following |
| 2672 | values. It restricts how the ioctl is allowed to be called. |
Michael Witten | 65ffef5 | 2011-08-25 20:55:58 +0000 | [diff] [blame] | 2673 | <itemizedlist> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2674 | <listitem><para> |
| 2675 | DRM_AUTH - Only authenticated callers allowed |
| 2676 | </para></listitem> |
| 2677 | <listitem><para> |
| 2678 | DRM_MASTER - The ioctl can only be called on the master file |
| 2679 | handle |
| 2680 | </para></listitem> |
| 2681 | <listitem><para> |
| 2682 | DRM_ROOT_ONLY - Only callers with the SYSADMIN capability allowed |
| 2683 | </para></listitem> |
| 2684 | <listitem><para> |
| 2685 | DRM_CONTROL_ALLOW - The ioctl can only be called on a control |
| 2686 | device |
| 2687 | </para></listitem> |
| 2688 | <listitem><para> |
| 2689 | DRM_UNLOCKED - The ioctl handler will be called without locking |
| 2690 | the DRM global mutex |
| 2691 | </para></listitem> |
Michael Witten | 65ffef5 | 2011-08-25 20:55:58 +0000 | [diff] [blame] | 2692 | </itemizedlist> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2693 | </para> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2694 | </para> |
| 2695 | </sect2> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2696 | </sect1> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2697 | <sect1> |
Daniel Vetter | 4c6e2df | 2014-01-22 16:46:44 +0100 | [diff] [blame] | 2698 | <title>Legacy Support Code</title> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2699 | <para> |
Daniel Vetter | 4c6e2df | 2014-01-22 16:46:44 +0100 | [diff] [blame] | 2700 | The section very brievely covers some of the old legacy support code which |
| 2701 | is only used by old DRM drivers which have done a so-called shadow-attach |
| 2702 | to the underlying device instead of registering as a real driver. This |
| 2703 | also includes some of the old generic buffer mangement and command |
| 2704 | submission code. Do not use any of this in new and modern drivers. |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2705 | </para> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2706 | |
Daniel Vetter | 4c6e2df | 2014-01-22 16:46:44 +0100 | [diff] [blame] | 2707 | <sect2> |
| 2708 | <title>Legacy Suspend/Resume</title> |
| 2709 | <para> |
| 2710 | The DRM core provides some suspend/resume code, but drivers wanting full |
| 2711 | suspend/resume support should provide save() and restore() functions. |
| 2712 | These are called at suspend, hibernate, or resume time, and should perform |
| 2713 | any state save or restore required by your device across suspend or |
| 2714 | hibernate states. |
| 2715 | </para> |
| 2716 | <synopsis>int (*suspend) (struct drm_device *, pm_message_t state); |
| 2717 | int (*resume) (struct drm_device *);</synopsis> |
| 2718 | <para> |
| 2719 | Those are legacy suspend and resume methods which |
| 2720 | <emphasis>only</emphasis> work with the legacy shadow-attach driver |
| 2721 | registration functions. New driver should use the power management |
| 2722 | interface provided by their bus type (usually through |
| 2723 | the struct <structname>device_driver</structname> dev_pm_ops) and set |
| 2724 | these methods to NULL. |
| 2725 | </para> |
| 2726 | </sect2> |
| 2727 | |
| 2728 | <sect2> |
| 2729 | <title>Legacy DMA Services</title> |
| 2730 | <para> |
| 2731 | This should cover how DMA mapping etc. is supported by the core. |
| 2732 | These functions are deprecated and should not be used. |
| 2733 | </para> |
| 2734 | </sect2> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2735 | </sect1> |
| 2736 | </chapter> |
| 2737 | |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2738 | <!-- TODO |
| 2739 | |
| 2740 | - Add a glossary |
| 2741 | - Document the struct_mutex catch-all lock |
| 2742 | - Document connector properties |
| 2743 | |
| 2744 | - Why is the load method optional? |
| 2745 | - What are drivers supposed to set the initial display state to, and how? |
| 2746 | Connector's DPMS states are not initialized and are thus equal to |
| 2747 | DRM_MODE_DPMS_ON. The fbcon compatibility layer calls |
| 2748 | drm_helper_disable_unused_functions(), which disables unused encoders and |
| 2749 | CRTCs, but doesn't touch the connectors' DPMS state, and |
| 2750 | drm_helper_connector_dpms() in reaction to fbdev blanking events. Do drivers |
| 2751 | that don't implement (or just don't use) fbcon compatibility need to call |
| 2752 | those functions themselves? |
| 2753 | - KMS drivers must call drm_vblank_pre_modeset() and drm_vblank_post_modeset() |
| 2754 | around mode setting. Should this be done in the DRM core? |
| 2755 | - vblank_disable_allowed is set to 1 in the first drm_vblank_post_modeset() |
| 2756 | call and never set back to 0. It seems to be safe to permanently set it to 1 |
| 2757 | in drm_vblank_init() for KMS driver, and it might be safe for UMS drivers as |
| 2758 | well. This should be investigated. |
| 2759 | - crtc and connector .save and .restore operations are only used internally in |
| 2760 | drivers, should they be removed from the core? |
| 2761 | - encoder mid-layer .save and .restore operations are only used internally in |
| 2762 | drivers, should they be removed from the core? |
| 2763 | - encoder mid-layer .detect operation is only used internally in drivers, |
| 2764 | should it be removed from the core? |
| 2765 | --> |
| 2766 | |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2767 | <!-- External interfaces --> |
| 2768 | |
| 2769 | <chapter id="drmExternals"> |
| 2770 | <title>Userland interfaces</title> |
| 2771 | <para> |
| 2772 | The DRM core exports several interfaces to applications, |
| 2773 | generally intended to be used through corresponding libdrm |
Michael Witten | a5294e0 | 2011-08-29 18:05:52 +0000 | [diff] [blame] | 2774 | wrapper functions. In addition, drivers export device-specific |
Michael Witten | 7f0925a | 2011-08-29 18:07:13 +0000 | [diff] [blame] | 2775 | interfaces for use by userspace drivers & device-aware |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2776 | applications through ioctls and sysfs files. |
| 2777 | </para> |
| 2778 | <para> |
| 2779 | External interfaces include: memory mapping, context management, |
| 2780 | DMA operations, AGP management, vblank control, fence |
| 2781 | management, memory management, and output management. |
| 2782 | </para> |
| 2783 | <para> |
Michael Witten | bcd3cfc | 2011-08-29 19:29:16 +0000 | [diff] [blame] | 2784 | Cover generic ioctls and sysfs layout here. We only need high-level |
| 2785 | info, since man pages should cover the rest. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2786 | </para> |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2787 | |
David Herrmann | 1793126 | 2013-08-25 18:29:00 +0200 | [diff] [blame] | 2788 | <!-- External: render nodes --> |
| 2789 | |
| 2790 | <sect1> |
| 2791 | <title>Render nodes</title> |
| 2792 | <para> |
| 2793 | DRM core provides multiple character-devices for user-space to use. |
| 2794 | Depending on which device is opened, user-space can perform a different |
| 2795 | set of operations (mainly ioctls). The primary node is always created |
Daniel Vetter | 00153ae | 2014-01-21 12:51:43 +0100 | [diff] [blame] | 2796 | and called card<num>. Additionally, a currently |
| 2797 | unused control node, called controlD<num> is also |
David Herrmann | 1793126 | 2013-08-25 18:29:00 +0200 | [diff] [blame] | 2798 | created. The primary node provides all legacy operations and |
| 2799 | historically was the only interface used by userspace. With KMS, the |
| 2800 | control node was introduced. However, the planned KMS control interface |
| 2801 | has never been written and so the control node stays unused to date. |
| 2802 | </para> |
| 2803 | <para> |
| 2804 | With the increased use of offscreen renderers and GPGPU applications, |
| 2805 | clients no longer require running compositors or graphics servers to |
| 2806 | make use of a GPU. But the DRM API required unprivileged clients to |
| 2807 | authenticate to a DRM-Master prior to getting GPU access. To avoid this |
| 2808 | step and to grant clients GPU access without authenticating, render |
| 2809 | nodes were introduced. Render nodes solely serve render clients, that |
| 2810 | is, no modesetting or privileged ioctls can be issued on render nodes. |
| 2811 | Only non-global rendering commands are allowed. If a driver supports |
Daniel Vetter | 00153ae | 2014-01-21 12:51:43 +0100 | [diff] [blame] | 2812 | render nodes, it must advertise it via the DRIVER_RENDER |
David Herrmann | 1793126 | 2013-08-25 18:29:00 +0200 | [diff] [blame] | 2813 | DRM driver capability. If not supported, the primary node must be used |
| 2814 | for render clients together with the legacy drmAuth authentication |
| 2815 | procedure. |
| 2816 | </para> |
| 2817 | <para> |
| 2818 | If a driver advertises render node support, DRM core will create a |
Daniel Vetter | 00153ae | 2014-01-21 12:51:43 +0100 | [diff] [blame] | 2819 | separate render node called renderD<num>. There will |
David Herrmann | 1793126 | 2013-08-25 18:29:00 +0200 | [diff] [blame] | 2820 | be one render node per device. No ioctls except PRIME-related ioctls |
Daniel Vetter | 00153ae | 2014-01-21 12:51:43 +0100 | [diff] [blame] | 2821 | will be allowed on this node. Especially GEM_OPEN will be |
David Herrmann | 1793126 | 2013-08-25 18:29:00 +0200 | [diff] [blame] | 2822 | explicitly prohibited. Render nodes are designed to avoid the |
| 2823 | buffer-leaks, which occur if clients guess the flink names or mmap |
| 2824 | offsets on the legacy interface. Additionally to this basic interface, |
| 2825 | drivers must mark their driver-dependent render-only ioctls as |
Daniel Vetter | 00153ae | 2014-01-21 12:51:43 +0100 | [diff] [blame] | 2826 | DRM_RENDER_ALLOW so render clients can use them. Driver |
David Herrmann | 1793126 | 2013-08-25 18:29:00 +0200 | [diff] [blame] | 2827 | authors must be careful not to allow any privileged ioctls on render |
| 2828 | nodes. |
| 2829 | </para> |
| 2830 | <para> |
| 2831 | With render nodes, user-space can now control access to the render node |
| 2832 | via basic file-system access-modes. A running graphics server which |
| 2833 | authenticates clients on the privileged primary/legacy node is no longer |
| 2834 | required. Instead, a client can open the render node and is immediately |
| 2835 | granted GPU access. Communication between clients (or servers) is done |
| 2836 | via PRIME. FLINK from render node to legacy node is not supported. New |
| 2837 | clients must not use the insecure FLINK interface. |
| 2838 | </para> |
| 2839 | <para> |
| 2840 | Besides dropping all modeset/global ioctls, render nodes also drop the |
| 2841 | DRM-Master concept. There is no reason to associate render clients with |
| 2842 | a DRM-Master as they are independent of any graphics server. Besides, |
| 2843 | they must work without any running master, anyway. |
| 2844 | Drivers must be able to run without a master object if they support |
| 2845 | render nodes. If, on the other hand, a driver requires shared state |
| 2846 | between clients which is visible to user-space and accessible beyond |
| 2847 | open-file boundaries, they cannot support render nodes. |
| 2848 | </para> |
| 2849 | </sect1> |
| 2850 | |
Laurent Pinchart | 9cad9c9 | 2012-07-13 00:57:26 +0200 | [diff] [blame] | 2851 | <!-- External: vblank handling --> |
| 2852 | |
| 2853 | <sect1> |
| 2854 | <title>VBlank event handling</title> |
| 2855 | <para> |
| 2856 | The DRM core exposes two vertical blank related ioctls: |
| 2857 | <variablelist> |
| 2858 | <varlistentry> |
| 2859 | <term>DRM_IOCTL_WAIT_VBLANK</term> |
| 2860 | <listitem> |
| 2861 | <para> |
| 2862 | This takes a struct drm_wait_vblank structure as its argument, |
| 2863 | and it is used to block or request a signal when a specified |
| 2864 | vblank event occurs. |
| 2865 | </para> |
| 2866 | </listitem> |
| 2867 | </varlistentry> |
| 2868 | <varlistentry> |
| 2869 | <term>DRM_IOCTL_MODESET_CTL</term> |
| 2870 | <listitem> |
| 2871 | <para> |
| 2872 | This should be called by application level drivers before and |
| 2873 | after mode setting, since on many devices the vertical blank |
| 2874 | counter is reset at that time. Internally, the DRM snapshots |
| 2875 | the last vblank count when the ioctl is called with the |
| 2876 | _DRM_PRE_MODESET command, so that the counter won't go backwards |
| 2877 | (which is dealt with when _DRM_POST_MODESET is used). |
| 2878 | </para> |
| 2879 | </listitem> |
| 2880 | </varlistentry> |
| 2881 | </variablelist> |
| 2882 | <!--!Edrivers/char/drm/drm_irq.c--> |
| 2883 | </para> |
| 2884 | </sect1> |
| 2885 | |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2886 | </chapter> |
Daniel Vetter | 3519f70 | 2014-01-22 12:21:16 +0100 | [diff] [blame] | 2887 | </part> |
| 2888 | <part id="drmDrivers"> |
| 2889 | <title>DRM Drivers</title> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2890 | |
Daniel Vetter | 3519f70 | 2014-01-22 12:21:16 +0100 | [diff] [blame] | 2891 | <partintro> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2892 | <para> |
Daniel Vetter | 3519f70 | 2014-01-22 12:21:16 +0100 | [diff] [blame] | 2893 | This second part of the DRM Developer's Guide documents driver code, |
| 2894 | implementation details and also all the driver-specific userspace |
| 2895 | interfaces. Especially since all hardware-acceleration interfaces to |
| 2896 | userspace are driver specific for efficiency and other reasons these |
| 2897 | interfaces can be rather substantial. Hence every driver has its own |
| 2898 | chapter. |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2899 | </para> |
Daniel Vetter | 3519f70 | 2014-01-22 12:21:16 +0100 | [diff] [blame] | 2900 | </partintro> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2901 | |
Daniel Vetter | 3519f70 | 2014-01-22 12:21:16 +0100 | [diff] [blame] | 2902 | <chapter id="drmI915"> |
| 2903 | <title>drm/i915 Intel GFX Driver</title> |
| 2904 | <para> |
| 2905 | The drm/i915 driver supports all (with the exception of some very early |
| 2906 | models) integrated GFX chipsets with both Intel display and rendering |
| 2907 | blocks. This excludes a set of SoC platforms with an SGX rendering unit, |
| 2908 | those have basic support through the gma500 drm driver. |
| 2909 | </para> |
| 2910 | <sect1> |
| 2911 | <title>Display Hardware Handling</title> |
| 2912 | <para> |
| 2913 | This section covers everything related to the display hardware including |
| 2914 | the mode setting infrastructure, plane, sprite and cursor handling and |
| 2915 | display, output probing and related topics. |
| 2916 | </para> |
| 2917 | <sect2> |
| 2918 | <title>Mode Setting Infrastructure</title> |
| 2919 | <para> |
| 2920 | The i915 driver is thus far the only DRM driver which doesn't use the |
| 2921 | common DRM helper code to implement mode setting sequences. Thus it |
| 2922 | has its own tailor-made infrastructure for executing a display |
| 2923 | configuration change. |
| 2924 | </para> |
| 2925 | </sect2> |
| 2926 | <sect2> |
| 2927 | <title>Plane Configuration</title> |
| 2928 | <para> |
| 2929 | This section covers plane configuration and composition with the |
| 2930 | primary plane, sprites, cursors and overlays. This includes the |
| 2931 | infrastructure to do atomic vsync'ed updates of all this state and |
| 2932 | also tightly coupled topics like watermark setup and computation, |
| 2933 | framebuffer compression and panel self refresh. |
| 2934 | </para> |
| 2935 | </sect2> |
| 2936 | <sect2> |
| 2937 | <title>Output Probing</title> |
| 2938 | <para> |
| 2939 | This section covers output probing and related infrastructure like the |
| 2940 | hotplug interrupt storm detection and mitigation code. Note that the |
| 2941 | i915 driver still uses most of the common DRM helper code for output |
| 2942 | probing, so those sections fully apply. |
| 2943 | </para> |
| 2944 | </sect2> |
| 2945 | </sect1> |
| 2946 | |
| 2947 | <sect1> |
| 2948 | <title>Memory Management and Command Submission</title> |
| 2949 | <para> |
| 2950 | This sections covers all things related to the GEM implementation in the |
| 2951 | i915 driver. |
| 2952 | </para> |
| 2953 | </sect1> |
| 2954 | </chapter> |
| 2955 | </part> |
Jesse Barnes | 2d2ef82 | 2009-10-26 13:06:31 -0700 | [diff] [blame] | 2956 | </book> |