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