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